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