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