Remove dead code asdctool
[sdc.git] / asdctool / src / main / java / org / openecomp / sdc / asdctool / main / EsToCassandraDataMigrationMenu.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.DataMigration;
24 import org.openecomp.sdc.asdctool.impl.EsToCassandraDataMigrationConfig;
25 import org.openecomp.sdc.be.config.ConfigurationManager;
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.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
32
33 public class EsToCassandraDataMigrationMenu {
34
35         private static Logger log = LoggerFactory.getLogger(EsToCassandraDataMigrationMenu.class.getName());
36
37         public static void main(String[] args) {
38
39                 if (args == null || args.length < 2) {
40                         usageAndExit();
41                 }
42                 String operation = args[0];
43
44                 String appConfigDir = args[1];
45                 System.setProperty("config.home", appConfigDir);
46                 ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
47                                 appConfigDir);
48                 ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
49
50                 AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
51                                 EsToCassandraDataMigrationConfig.class);
52                 DataMigration dataMigration = null;
53                 try {
54                         switch (operation.toLowerCase()) {
55                         case "es-to-cassndra-migration":
56                                 dataMigration = (DataMigration) context.getBean("DataMigrationBean");
57                                 log.debug("Start migration from ES to C* ");
58                                 if (dataMigration.migrateDataEsToCassandra(appConfigDir, true, true)) {
59                                         log.debug("migration from ES to C* was finished successfull");
60                                         System.exit(0);
61                                 } else {
62                                         log.debug("migration from ES to C* failed");
63                                         System.exit(2);
64                                 }
65                                 break;
66                         case "es-to-cassndra-migration-export-only":
67                                 dataMigration = (DataMigration) context.getBean("DataMigrationBean");
68                                 log.debug("Start migration export only from ES to C* ");
69                                 if (dataMigration.migrateDataEsToCassandra(appConfigDir, true, false)) {
70                                         log.debug("migration export only from ES to C* was finished successfull");
71                                         System.exit(0);
72                                 } else {
73                                         log.debug("migration export only from ES to C* failed");
74                                         System.exit(2);
75                                 }
76                                 break;
77                         case "es-to-cassndra-migration-import-only":
78                                 dataMigration = (DataMigration) context.getBean("DataMigrationBean");
79                                 log.debug("Start migration import only from ES to C* ");
80                                 if (dataMigration.migrateDataEsToCassandra(appConfigDir, false, true)) {
81                                         log.debug("migration import only from ES to C* was finished successfull");
82                                         System.exit(0);
83                                 } else {
84                                         log.debug("migration import only from ES to C* failed");
85                                         System.exit(2);
86                                 }
87                                 break;
88                         default:
89                                 usageAndExit();
90                         }
91                 } catch (Throwable t) {
92                         t.printStackTrace();
93                         System.exit(3);
94                 }
95         }
96
97         private static void usageAndExit() {
98                 MigrationUsage();
99                 System.exit(1);
100         }
101
102         private static void MigrationUsage() {
103                 System.out.println(
104                                 "Usage: es-to-cassndra-migration/es-to-cassndra-migration-import-only/es-to-cassndra-migration-export-only <configuration dir>");
105         }
106 }