re base code
[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  */
20
21 package org.openecomp.sdc.asdctool.main;
22
23 import org.openecomp.sdc.asdctool.impl.TitanGraphInitializer;
24 import org.openecomp.sdc.be.config.ConfigurationManager;
25 import org.openecomp.sdc.be.dao.cassandra.schema.SdcSchemaBuilder;
26 import org.openecomp.sdc.common.api.ConfigurationSource;
27 import org.openecomp.sdc.common.impl.ExternalConfiguration;
28 import org.openecomp.sdc.common.impl.FSConfigurationSource;
29 import org.openecomp.sdc.common.log.wrappers.Logger;
30
31 public class DataSchemaMenu {
32
33         private static Logger log = Logger.getLogger(DataSchemaMenu.class.getName());
34
35     public static void main(String[] args) {
36
37         String operation = args[0];
38
39         String appConfigDir = args[1];
40
41         if (args == null || args.length < 2) {
42             usageAndExit();
43         }
44
45         ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
46         ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
47
48         switch (operation.toLowerCase()) {
49             case "create-cassandra-structures":
50                 log.debug("Start create cassandra keyspace, tables and indexes");
51                 if (SdcSchemaBuilder.createSchema()) {
52                     log.debug("create cassandra keyspace, tables and indexes successfull");
53                     System.exit(0);
54                 } else {
55                     log.debug("create cassandra keyspace, tables and indexes failed");
56                     System.exit(2);
57                 }
58                 break;
59             case "create-titan-structures":
60                 log.debug("Start create titan keyspace");
61                 String titanCfg = 2 == args.length ? configurationManager.getConfiguration().getTitanCfgFile() : args[2];
62                 if (TitanGraphInitializer.createGraph(titanCfg)) {
63                     log.debug("create titan keyspace successfull");
64                     System.exit(0);
65                 } else {
66                     log.debug("create titan keyspace failed");
67                     System.exit(2);
68                 }
69                 break;
70             case "clean-cassndra":
71                 log.debug("Start clean keyspace, tables");
72                 if (SdcSchemaBuilder.deleteSchema()) {
73                     log.debug(" successfull");
74                     System.exit(0);
75                 } else {
76                     log.debug(" failed");
77                     System.exit(2);
78                 }
79                 break;
80             default:
81                 usageAndExit();
82                 break;
83         }
84     }
85
86     private static void usageAndExit() {
87         DataSchemeUsage();
88         System.exit(1);
89     }
90
91     private static void DataSchemeUsage() {
92         System.out.println("Usage: create-cassandra-structures <configuration dir> ");
93         System.out.println("Usage: create-titan-structures <configuration dir> ");
94     }
95 }