1 /**============LICENSE_START=======================================================
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
10 http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.blueprintgenerator.core;
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;
33 @SuppressWarnings("deprecation")
34 public class BlueprintGenerator {
36 private static String componentSpecPath = "";
38 private static String bluePrintName = "";
40 private static String outputPath = "";
42 private static char bpType = 'o';
44 private static String importPath = "";
46 private static String override = "";
49 public static void main(String[] args) throws Exception {
55 //create the component Spec we are going to be working with
56 ComponentSpec cs = new ComponentSpec();
57 cs.createComponentSpecFromFile(componentSpecPath);
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);
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)");
76 public static void parseInputs(String[] args) throws Exception {
77 //convert the arguments array to a string to make it easier
80 if(commands.length() == 0) {
84 commands = commands + " " + s;
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");
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");
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");
109 if(!(commandLine.getOptionValue("t") == null)) {
110 importPath = commandLine.getOptionValue("t");
112 if(commands.contains("-d")) {