Upgrade SDC from Titan to Janus Graph
[sdc.git] / asdctool / src / main / java / org / openecomp / sdc / asdctool / main / DataSchemaMenu.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  * Modifications copyright (c) 2018 Nokia
20  * ================================================================================
21  */
22
23 package org.openecomp.sdc.asdctool.main;
24
25 import org.openecomp.sdc.asdctool.impl.JanusGraphInitializer;
26 import org.openecomp.sdc.be.config.ConfigurationManager;
27 import org.openecomp.sdc.be.dao.cassandra.schema.SdcSchemaBuilder;
28 import org.openecomp.sdc.be.dao.cassandra.schema.SdcSchemaUtils;
29 import org.openecomp.sdc.common.api.ConfigurationSource;
30 import org.openecomp.sdc.common.impl.ExternalConfiguration;
31 import org.openecomp.sdc.common.impl.FSConfigurationSource;
32 import org.openecomp.sdc.common.log.wrappers.Logger;
33
34 public class DataSchemaMenu {
35
36         private static Logger log = Logger.getLogger(DataSchemaMenu.class.getName());
37
38     public static void main(String[] args) {
39
40                 String operation = args[0];
41
42         String appConfigDir = args[1];
43
44         if (args == null || args.length < 2) {
45             usageAndExit();
46         }
47
48         ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
49         ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
50
51         SdcSchemaBuilder sdcSchemaBuilder = new SdcSchemaBuilder(new SdcSchemaUtils(),
52             ConfigurationManager.getConfigurationManager().getConfiguration()::getCassandraConfig);
53
54         switch (operation.toLowerCase()) {
55             case "create-cassandra-structures":
56                 log.debug("Start create cassandra keyspace, tables and indexes");
57                 if (sdcSchemaBuilder.createSchema()) {
58                     log.debug("create cassandra keyspace, tables and indexes successfull");
59                     System.exit(0);
60                 } else {
61                     log.debug("create cassandra keyspace, tables and indexes failed");
62                     System.exit(2);
63                 }
64                 break;
65             case "create-janusgraph-structures":
66                 log.debug("Start create janusgraph keyspace");
67                 String janusGraphCfg = 2 == args.length ? configurationManager.getConfiguration().getJanusGraphCfgFile() : args[2];
68                 if (JanusGraphInitializer.createGraph(janusGraphCfg)) {
69                     log.debug("create janusgraph keyspace successfull");
70                     System.exit(0);
71                 } else {
72                     log.debug("create janusgraph keyspace failed");
73                     System.exit(2);
74                 }
75                 break;
76             case "clean-cassndra":
77                 log.debug("Start clean keyspace, tables");
78                 if (sdcSchemaBuilder.deleteSchema()) {
79                     log.debug(" successfull");
80                     System.exit(0);
81                 } else {
82                     log.debug(" failed");
83                     System.exit(2);
84                 }
85                 break;
86             default:
87                 usageAndExit();
88                 break;
89         }
90     }
91
92     private static void usageAndExit() {
93         DataSchemeUsage();
94         System.exit(1);
95     }
96
97     private static void DataSchemeUsage() {
98         System.out.println("Usage: create-cassandra-structures <configuration dir> ");
99         System.out.println("Usage: create-janusgraph-structures <configuration dir> ");
100     }
101 }