796424f5dfa37ca96ab7eac07c028cf676071703
[dcaegen2/platform.git] / mod / bpgenerator / onap / src / main / java / org / onap / blueprintgenerator / BlueprintGeneratorMainApplication.java
1 /*
2  *
3  *  * ============LICENSE_START=======================================================
4  *  *  org.onap.dcae
5  *  *  ================================================================================
6  *  *  Copyright (c) 2020  AT&T Intellectual Property. All rights reserved.
7  *  *  Copyright (c) 2020  Nokia. All rights reserved.
8  *  *  ================================================================================
9  *  *  Licensed under the Apache License, Version 2.0 (the "License");
10  *  *  you may not use this file except in compliance with the License.
11  *  *  You may obtain a copy of the License at
12  *  *
13  *  *       http://www.apache.org/licenses/LICENSE-2.0
14  *  *
15  *  *  Unless required by applicable law or agreed to in writing, software
16  *  *  distributed under the License is distributed on an "AS IS" BASIS,
17  *  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  *  *  See the License for the specific language governing permissions and
19  *  *  limitations under the License.
20  *  *  ============LICENSE_END=========================================================
21  *
22  *
23  */
24
25 package org.onap.blueprintgenerator;
26
27
28 import static java.lang.System.exit;
29
30 import org.onap.blueprintgenerator.model.base.Blueprint;
31 import org.onap.blueprintgenerator.model.common.Input;
32 import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
33 import org.onap.blueprintgenerator.model.componentspec.base.ComponentSpec;
34 import org.onap.blueprintgenerator.service.BlueprintCreatorService;
35 import org.onap.blueprintgenerator.service.base.BlueprintService;
36 import org.onap.blueprintgenerator.service.common.CommonUtils;
37 import org.onap.blueprintgenerator.service.common.ComponentSpecService;
38 import org.onap.policycreate.service.PolicyModelService;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.boot.CommandLineRunner;
41 import org.springframework.boot.SpringApplication;
42 import org.springframework.boot.autoconfigure.SpringBootApplication;
43 import org.springframework.context.annotation.ComponentScan;
44
45 /**
46  * @author : Ravi Mantena
47  * @date 10/16/2020 Application: ONAP - Blueprint Generator ONAP - Blueprint Generator Main
48  * Application to create Policy Models or Blueprints
49  */
50 @ComponentScan({"org.onap.blueprintgenerator", "org.onap.policycreate"})
51 @SpringBootApplication
52 public class BlueprintGeneratorMainApplication implements CommandLineRunner {
53
54     @Autowired
55     private ComponentSpecService componentSpecService;
56
57     @Autowired
58     private PolicyModelService policyModelService;
59
60     @Autowired
61     private CommonUtils commonUtils;
62
63     @Autowired
64     private PolicyModelService onapPolicyModelNodeService;
65
66     @Autowired
67     private ComponentSpecService onapComponentSpecService;
68
69     @Autowired
70     private CommonUtils onapCommonUtils;
71
72     @Autowired
73     private BlueprintCreatorService blueprintCreatorService;
74
75     @Autowired
76     private BlueprintService blueprintService;
77
78     /**
79      * Main Application to run BPGen to generate Policies/Blueprint based on Input Arguments values
80      *
81      * @param args Input Arguments
82      */
83     public static void main(String[] args) {
84         SpringApplication.run(BlueprintGeneratorMainApplication.class, args);
85     }
86
87     /**
88      * Creates Policies/Blueprint based on Input Arguments values
89      *
90      * @param args Input Arguments
91      */
92     @Override
93     public void run(String... args) {
94         if (args.length >= 2 && args[0].equals("app") && args[1].equals("ONAP")) {
95             onapCommonUtils.printInstructions();
96             if (args.length >= 4 && args[2].equals("-type") && args[3].equals("policycreate")) {
97                 Input input = onapCommonUtils.parseInputs(args);
98                 ComponentSpec componentSpec =
99                     componentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
100                 onapPolicyModelNodeService.createPolicyModels(
101                     componentSpec.getParameters(), input.getOutputPath());
102             } else {
103                 Input input = onapCommonUtils.parseInputs(args);
104                 OnapComponentSpec onapComponentSpec = onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
105                 Blueprint blueprint = blueprintCreatorService.createBlueprint(onapComponentSpec, input);
106                 blueprintService.blueprintToYaml(onapComponentSpec, blueprint, input);
107                 System.out.println(blueprintService.blueprintToString(onapComponentSpec, blueprint, input));
108             }
109         }
110
111         exit(0);
112     }
113 }