Added the dmaap plugin changes needed
[dcaegen2/platform/cli.git] / blueprint-generator / src / main / java / org / onap / blueprintgenerator / core / BlueprintGenerator.java
1 /**============LICENSE_START======================================================= 
2  org.onap.dcae 
3  ================================================================================ 
4  Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. 
5  ================================================================================ 
6  Licensed under the Apache License, Version 2.0 (the "License"); 
7  you may not use this file except in compliance with the License. 
8  You may obtain a copy of the License at 
9
10       http://www.apache.org/licenses/LICENSE-2.0 
11
12  Unless required by applicable law or agreed to in writing, software 
13  distributed under the License is distributed on an "AS IS" BASIS, 
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
15  See the License for the specific language governing permissions and 
16  limitations under the License. 
17  ============LICENSE_END========================================================= 
18
19  */
20
21 package org.onap.blueprintgenerator.core;
22
23
24
25 import org.apache.commons.cli.BasicParser;
26 import org.apache.commons.cli.CommandLine;
27 import org.apache.commons.cli.Options;
28 import org.onap.blueprintgenerator.models.blueprint.Blueprint;
29 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
30
31
32
33 @SuppressWarnings("deprecation")
34 public class BlueprintGenerator {
35
36         private static String componentSpecPath = "";
37
38         private static String bluePrintName = "";
39
40         private static String outputPath = "";
41
42         private static char bpType = 'o';
43
44         private static String importPath = "";
45         
46         private static String override = "";
47
48
49         public static void main(String[] args) throws Exception {
50
51                 printInstructions();
52
53                 parseInputs(args);
54
55                 //create the component Spec we are going to be working with
56                 ComponentSpec cs = new ComponentSpec();
57                 cs.createComponentSpecFromFile(componentSpecPath);
58
59                 //create the blueprint and convert it to a yaml file
60                 Blueprint bp = new Blueprint();
61                 bp = bp.createBlueprint(cs, bluePrintName, bpType, importPath, override);
62                 bp.blueprintToYaml(outputPath, bluePrintName, cs);
63         }
64
65
66         public static void printInstructions() {
67                 System.out.println("OPTIONS:");
68                 System.out.println("-i: The path to the JSON spec file (required)");
69                 System.out.println("-n: Name of the blueprint (optional)");
70                 System.out.println("-p: The path to the final blueprint (required)");
71                 System.out.println("-t: The path to the yaml import file (optional)");
72                 System.out.println("-d: With this flag present the blueprint will be created with the dmaap plugin enables");
73                 System.out.println("-o: The value you want for service_component_name_override (optional)");
74         }
75
76         public static void parseInputs(String[] args) throws Exception {
77                 //convert the arguments array to a string to make it easier
78                 String commands = "";
79                 for(String s: args) {
80                         if(commands.length() == 0) {
81                                 commands = s;
82                         }
83                         else {
84                                 commands = commands + " " + s;
85                         }
86                 }
87
88                 //check if it has the required inputs
89                 if(!commands.contains("-p") || !commands.contains("-i")) {
90                         System.out.println("did not enter the required inputs");
91                 }
92                 else {
93                         BasicParser parser = new BasicParser();
94                         Options options = new Options();
95                         options.addOption("i", "Spec", true, "ComponentSpec import file");
96                         options.addOption("p", "Path", true, "Path to the final blueprint");
97                         options.addOption("n", "Name", true, "Name of the blueprint");
98                         options.addOption("t", "imports", true, "Path to the import file");
99                         options.addOption("d", "Dmaap", false, "Enable the dmaap plugin");
100                         options.addOption("o", "Override", true, "service component name override");
101
102                         CommandLine commandLine = parser.parse(options, args);
103                         componentSpecPath = commandLine.getOptionValue("i");
104                         outputPath = commandLine.getOptionValue("p");
105                         override = commandLine.getOptionValue("o");
106                         if(!(commandLine.getOptionValue("n") == null)){
107                                 bluePrintName = commandLine.getOptionValue("n");
108                         }
109                         if(!(commandLine.getOptionValue("t") == null)) {
110                                 importPath = commandLine.getOptionValue("t");
111                         }
112                         if(commands.contains("-d")) {
113                                 bpType = 'd';
114                         }
115                 }
116
117         }
118 }
119