Catalog alignment
[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                 try {
52
53         SdcSchemaBuilder sdcSchemaBuilder = new SdcSchemaBuilder(new SdcSchemaUtils(),
54             ConfigurationManager.getConfigurationManager().getConfiguration()::getCassandraConfig);
55
56                         switch (operation.toLowerCase()) {
57                         case "create-cassandra-structures":
58                                 log.debug("Start create cassandra keyspace, tables and indexes");
59                 if (sdcSchemaBuilder.createSchema()) {
60                                         log.debug("create cassandra keyspace, tables and indexes successfull");
61                                         System.exit(0);
62                                 } else {
63                                         log.debug("create cassandra keyspace, tables and indexes failed");
64                                         System.exit(2);
65                                 }
66             case "create-janusgraph-structures":
67                 log.debug("Start create janusgraph keyspace");
68                 String janusGraphCfg = 2 == args.length ? configurationManager.getConfiguration().getJanusGraphCfgFile() : args[2];
69                 if (JanusGraphInitializer.createGraph(janusGraphCfg)) {
70                     log.debug("create janusgraph keyspace successfull");
71                                         System.exit(0);
72                                 } else {
73                     log.debug("create janusgraph keyspace failed");
74                                         System.exit(2);
75                                 }
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                         default:
86                                 usageAndExit();
87                         }
88                 } catch (Throwable t) {
89                         t.printStackTrace();
90                         log.debug("create cassandra keyspace, tables and indexes failed");
91                         System.exit(3);
92                 }
93         }
94
95         private static void usageAndExit() {
96                 DataSchemeUsage();
97                 System.exit(1);
98         }
99
100         private static void DataSchemeUsage() {
101                 System.out.println("Usage: create-cassandra-structures <configuration dir> ");
102         System.out.println("Usage: create-janusgraph-structures <configuration dir> ");
103         }
104 }