Added oparent to sdc main
[sdc.git] / asdctool / src / main / java / org / openecomp / sdc / asdctool / migration / main / MigrationMenu.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 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.migration.main;
22
23 import org.apache.commons.cli.Option;
24 import org.apache.commons.cli.Options;
25 import org.openecomp.sdc.asdctool.cli.CLIToolData;
26 import org.openecomp.sdc.asdctool.cli.SpringCLITool;
27 import org.openecomp.sdc.asdctool.migration.config.MigrationSpringConfig;
28 import org.openecomp.sdc.asdctool.migration.core.SdcMigrationTool;
29 import org.openecomp.sdc.common.log.wrappers.Logger;
30 import org.springframework.context.support.AbstractApplicationContext;
31
32 public class MigrationMenu extends SpringCLITool {
33
34     private static final Logger LOGGER = Logger.getLogger(MigrationMenu.class);
35
36     public static void main(String[] args) {
37         MigrationMenu migrationMenu = new MigrationMenu();
38         CLIToolData cliToolData = migrationMenu.init(args);
39         boolean enforceAll = cliToolData.getCommandLine().hasOption("e");
40         migrationMenu.doMigrate(enforceAll, cliToolData.getSpringApplicationContext());
41     }
42
43     private void doMigrate(boolean enforceAll, AbstractApplicationContext context) {
44         SdcMigrationTool migrationTool = context.getBean(SdcMigrationTool.class);
45         boolean migrate = migrationTool.migrate(enforceAll);
46         if (migrate) {
47             LOGGER.info("migration completed successfully");
48             System.exit(0);
49         } else {
50             LOGGER.error("migration failed");
51             System.exit(1);
52         }
53     }
54
55     @Override
56     protected Options buildCmdLineOptions() {
57         Options options = super.buildCmdLineOptions();
58         Option enforceAll = buildEnforceAllOption();
59         options.addOption(enforceAll);
60         return options;
61     }
62
63     @Override
64     protected String commandName() {
65         return "sdc-migration";
66     }
67
68     private static Option buildEnforceAllOption() {
69         return Option.builder("e")
70                 .longOpt("enforceAll")
71                 .desc("enforce running all migration steps for current version")
72                 .build();
73     }
74
75     @Override
76     protected Class<?> getSpringConfigurationClass() {
77         return MigrationSpringConfig.class;
78     }
79 }