3 * * ============LICENSE_START=======================================================
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
12 * * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
24 package org.onap.blueprintgenerator;
26 import org.onap.blueprintgenerator.model.base.Blueprint;
27 import org.onap.blueprintgenerator.model.common.Input;
28 import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
29 import org.onap.blueprintgenerator.model.componentspec.base.ComponentSpec;
30 import org.onap.blueprintgenerator.service.OnapBlueprintService;
31 import org.onap.blueprintgenerator.service.common.CommonUtils;
32 import org.onap.blueprintgenerator.service.common.ComponentSpecService;
33 import org.onap.blueprintgenerator.service.dmaap.DmaapBlueprintService;
34 import org.onap.policycreate.service.PolicyModelService;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.boot.CommandLineRunner;
37 import org.springframework.boot.SpringApplication;
38 import org.springframework.boot.autoconfigure.SpringBootApplication;
39 import org.springframework.context.annotation.ComponentScan;
41 import static java.lang.System.exit;
44 * @author : Ravi Mantena
45 * @date 10/16/2020 Application: ONAP - Blueprint Generator ONAP - Blueprint Generator Main
46 * Application to create Policy Models or Blueprints
48 @ComponentScan({"org.onap.blueprintgenerator", "org.onap.policycreate"})
49 @SpringBootApplication
50 public class BlueprintGeneratorMainApplication implements CommandLineRunner {
53 private ComponentSpecService componentSpecService;
56 private PolicyModelService policyModelService;
59 private CommonUtils commonUtils;
62 private PolicyModelService onapPolicyModelNodeService;
65 private ComponentSpecService onapComponentSpecService;
68 private CommonUtils onapCommonUtils;
71 private OnapBlueprintService onapBlueprintService;
74 private DmaapBlueprintService dmaapBlueprintService;
77 * Main Application to run BPGen to generate Policies/Blueprint based on Input Arguments values
79 * @param args Input Arguments
81 public static void main(String[] args) {
82 SpringApplication.run(BlueprintGeneratorMainApplication.class, args);
86 * Creates Policies/Blueprint based on Input Arguments values
88 * @param args Input Arguments
91 public void run(String... args) {
92 if (args.length >= 2 && args[0].equals("app") && args[1].equals("ONAP")) {
93 onapCommonUtils.printInstructions();
94 if (args.length >= 4 && args[2].equals("-type") && args[3].equals("policycreate")) {
95 Input input = onapCommonUtils.parseInputs(args);
96 ComponentSpec componentSpec =
97 componentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
98 onapPolicyModelNodeService.createPolicyModels(
99 componentSpec.getParameters(), input.getOutputPath());
101 Input input = onapCommonUtils.parseInputs(args);
102 OnapComponentSpec onapComponentSpec =
103 onapComponentSpecService
104 .createComponentSpecFromFile(input.getComponentSpecPath());
105 if (input.getBpType().equals("o")) {
106 Blueprint blueprint = onapBlueprintService
107 .createBlueprint(onapComponentSpec, input);
108 onapBlueprintService.blueprintToYaml(onapComponentSpec, blueprint, input);
111 .blueprintToString(onapComponentSpec, blueprint, input));
112 } else if (input.getBpType().equals("d")) {
113 Blueprint blueprint = dmaapBlueprintService
114 .createBlueprint(onapComponentSpec, input);
115 dmaapBlueprintService.blueprintToYaml(onapComponentSpec, blueprint, input);
117 dmaapBlueprintService
118 .blueprintToString(onapComponentSpec, blueprint, input));