diff options
author | 2019-11-08 15:59:50 +0000 | |
---|---|---|
committer | 2019-11-11 12:02:14 +0000 | |
commit | 44b967ef19f5aec3a92db3026c7113ad816d682a (patch) | |
tree | 5f5916bf73a6e7ed4b0701b27385af101c8a27da | |
parent | 32b25b04e604a804616a1193087eeec4740ebc6a (diff) |
Update Blueprint Generator run procedure
Issue-ID: DCAEGEN2-1914
Signed-off-by: JoeOLeary <joseph.o.leary@est.tech>
Change-Id: I37855b0610f4c260edea5cd0e7222955ec0818a8
9 files changed, 228 insertions, 268 deletions
diff --git a/blueprint-generator/README.md b/blueprint-generator/README.md index 55ffad9..2e81745 100644 --- a/blueprint-generator/README.md +++ b/blueprint-generator/README.md @@ -3,22 +3,13 @@ This tool allows the user to create a blueprint from a component spec json file # Instructions for building the tool locally -- cd into the root directory of the project (where the pom is located) -- Run the command: mvn clean install +- Change directory into the root directory of the project (where the pom is located) +- Run the command: `mvn clean install` - This will create a jar file and a tar file -- Unzip the tar file within this target directory -- cd into the folder that was created -- Instructions on how to run the tool from this folder are below -- If you're on windows type this out before you add your flags +- To execute the application ```bash -java -cp "lib/blueprint-generator-1.0.0-SNAPSHOT.jar;lib/*" org.onap.blueprintgenerator.core.BlueprintGenerator -``` - --If you're on linux type this out before you add your flags - -```bash -java -cp blueprint-generator/lib/blueprint-generator-1.0.0-SNAPSHOT.jar:blueprint-generator/lib/* org.onap.blueprintgenerator.core.BlueprintGenerator +java -jar target/blueprint-generator-1.2.1-SNAPSHOT-executable.jar ``` @@ -37,19 +28,13 @@ OPTIONS: - -o: The service component name override (optional) -If you're on windows it will look like this: - -```bash -java -cp "lib/blueprint-generator-onap-0.0.1-SNAPSHOT.jar;lib/*" org.onap.blueprintgenerator.core.BlueprintGenerator -p Blueprints -i ComponentSpecs/TestComponentSpec.json -n HelloWorld -d -``` - -If you're on linux it will look like this +it will look like this: ```bash -java -cp blueprint-generator/lib/blueprint-generator-0.0.1-SNAPSHOT.jar:blueprint-generator/lib/* org.onap.blueprintgenerator.core.BlueprintGenerator -p Blueprints -i ComponentSpecs/TestComponentSpec.json -n HelloWorld -d +java -jar target/blueprint-generator-1.2.1-SNAPSHOT-executable.jar blueprint -p Blueprints -i ComponentSpecs/TestComponentSpec.json -n HelloWorld -d ``` -This command will create a blueprint from the component spec TestComponentSpec. The blueprint file name will be called HelloWorld.yaml and it will be in the directory Blueprints.THe blueprint will also contain the dmaap plugin. +This command will create a blueprint from the component spec TestComponentSpec. The blueprint file name will be called HelloWorld.yaml and it will be in the directory Blueprints. The blueprint will also contain the DMaaP plugin. ## Extra information: - The component spec must be of the same format as stated in the onap [readthedocs](https://onap.readthedocs.io/en/latest/submodules/dcaegen2.git/docs/sections/components/component-specification/common-specification.html#working-with-component-specs) page @@ -67,16 +52,10 @@ OPTIONS: - -i: The path to the JSON spec file (required) - -p: The output path for all of the models (required) -If you're on windows it will look like this: - -```bash -java -cp "lib/blueprint-generator-onap-0.0.1-SNAPSHOT.jar;lib/*" org.onap.blueprintgenerator.core.PolicyCreate -p models -i ComponentSpecs/TestComponentSpec.json -``` - -If you're on linux it will look like this +it will look like this: ```bash -java -cp blueprint-generator/lib/blueprint-generator-0.0.1-SNAPSHOT.jar:blueprint-generator/lib/* org.onap.blueprintgenerator.core.PolicyCreate -i ComponentSpecs/TestComponentSpec.json +java -jar target/blueprint-generator-1.2.1-SNAPSHOT-executable.jar policy -p models -i ComponentSpecs/TestComponentSpec.json ``` This command will create a directory called models and put the policy models created from the component spec given in that directory. (A component spec may generate multiple policy models)
\ No newline at end of file diff --git a/blueprint-generator/pom.xml b/blueprint-generator/pom.xml index cb798d2..680473e 100644 --- a/blueprint-generator/pom.xml +++ b/blueprint-generator/pom.xml @@ -29,7 +29,7 @@ </parent> <groupId>org.onap.dcaegen2.platform.cli</groupId> <artifactId>blueprint-generator</artifactId> - <version>1.2.0-SNAPSHOT</version> + <version>1.2.1-SNAPSHOT</version> <properties> <maven.compiler.source>1.6</maven.compiler.source> <maven.compiler.target>1.6</maven.compiler.target> @@ -40,7 +40,8 @@ <sonar.junit.reportsPath>${project.basedir}/target/surefire-reports</sonar.junit.reportsPath> <sonar.surefire.reportsPath>${project.basedir}/target/surefire-reports</sonar.surefire.reportsPath> <sonar.cobertura.reportPath>${project.basedir}/target/site/cobertura/coverage.xml</sonar.cobertura.reportPath> - + <shade.main>org.onap.blueprintgenerator.core.App</shade.main> + <shade.transformer>org.apache.maven.plugins.shade.resource.ManifestResourceTransformer</shade.transformer> </properties> <build> @@ -66,7 +67,6 @@ </execution> </executions> - </plugin> <plugin> @@ -115,7 +115,36 @@ <artifactId>sonar-maven-plugin</artifactId> <version>3.0.2</version> </plugin> - + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.2.1</version> + <executions> + <execution> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <shadedArtifactAttached>true</shadedArtifactAttached> + <shadedClassifierName>executable</shadedClassifierName> + <transformers> + <transformer + implementation="${shade.transformer}"> + <mainClass>${shade.main}</mainClass> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>8</source> + <target>8</target> + </configuration> + </plugin> </plugins> </build> @@ -139,26 +168,30 @@ <dependencies> <dependency> - <groupId>org.projectlombok</groupId> - <artifactId>lombok</artifactId> - <version>1.18.2</version> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>commons-cli</groupId> - <artifactId>commons-cli</artifactId> - <version>1.2</version> - </dependency> - - <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>3.1.0</version> + <scope>test</scope> + </dependency> <dependency> + <groupId>info.picocli</groupId> + <artifactId>picocli</artifactId> + <version>3.9.6</version> + </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>1.18.2</version> + <scope>provided</scope> + </dependency> + <dependency> <groupId>com.fasterxml.jackson.dataformat</groupId> <artifactId>jackson-dataformat-yaml</artifactId> <version>2.9.8</version> diff --git a/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/App.java b/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/App.java new file mode 100644 index 0000000..4775825 --- /dev/null +++ b/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/App.java @@ -0,0 +1,40 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + + +package org.onap.blueprintgenerator.core; + +import picocli.CommandLine; +import picocli.CommandLine.Command; + +@Command(subcommands = { + BlueprintCommand.class, + PolicyCommand.class +}) +public class App implements Runnable { + public static void main(String...args) { + CommandLine.run(new App(), args); + } + + @Override + public void run() { + CommandLine.usage(this, System.out); + } +} diff --git a/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/BlueprintCommand.java b/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/BlueprintCommand.java new file mode 100644 index 0000000..7627930 --- /dev/null +++ b/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/BlueprintCommand.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.blueprintgenerator.core; + +import org.onap.blueprintgenerator.models.blueprint.Blueprint; +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +@Command(name = "blueprint", description = "Command used to generate blueprints from component spec") +public class BlueprintCommand implements Runnable { + private static final char STANDARD_BLUEPRINT = 'o'; + private static final char DMAAP_BLUEPRINT = 'd'; + + @Option(names = {"-i", "--component-spec"}, description = "Path to component spec file", required = true) + private String componentSpecPath; + + @Option(names = {"-p", "--blueprint-path"}, description = "Path to directory that blueprints are output to", required = true) + private String blueprintOutputPath; + + @Option(names = {"-n", "--blueprint-name"}, description = "Name of the blueprint", defaultValue = "") + private String blueprintName; + + @Option(names = {"-t", "--imports"}, description = "Path to the import file", defaultValue = "") + private String importsPath; + + @Option(names={"-o", "--service-name-override"}, description="Value used to override the service name", defaultValue = "") + private String serviceNameOverride; + + @Option(names={"-d", "--dmaap-plugin"}, description = "Flag used to indicate blueprint uses the DMaaP plugin.") + private boolean dmaapPlugin; + + @Override + public void run() { + ComponentSpec inboundComponentSpec = new ComponentSpec(); + inboundComponentSpec.createComponentSpecFromFile(componentSpecPath); + System.out.println(dmaapPlugin ? DMAAP_BLUEPRINT : STANDARD_BLUEPRINT); + Blueprint generatedBlueprint = new Blueprint().createBlueprint(inboundComponentSpec, this.blueprintName, + dmaapPlugin ? DMAAP_BLUEPRINT : STANDARD_BLUEPRINT, importsPath, serviceNameOverride); + generatedBlueprint.blueprintToYaml(blueprintOutputPath, this.blueprintName, inboundComponentSpec); + } +} diff --git a/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/BlueprintGenerator.java b/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/BlueprintGenerator.java deleted file mode 100644 index b2e6996..0000000 --- a/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/BlueprintGenerator.java +++ /dev/null @@ -1,119 +0,0 @@ -/**============LICENSE_START======================================================= - org.onap.dcae - ================================================================================ - Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. - ================================================================================ - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ============LICENSE_END========================================================= - - */ - -package org.onap.blueprintgenerator.core; - - - -import org.apache.commons.cli.BasicParser; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Options; -import org.onap.blueprintgenerator.models.blueprint.Blueprint; -import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; - - - -@SuppressWarnings("deprecation") -public class BlueprintGenerator { - - private static String componentSpecPath = ""; - - private static String bluePrintName = ""; - - private static String outputPath = ""; - - private static char bpType = 'o'; - - private static String importPath = ""; - - private static String override = ""; - - - public static void main(String[] args) throws Exception { - - printInstructions(); - - parseInputs(args); - - //create the component Spec we are going to be working with - ComponentSpec cs = new ComponentSpec(); - cs.createComponentSpecFromFile(componentSpecPath); - - //create the blueprint and convert it to a yaml file - Blueprint bp = new Blueprint(); - bp = bp.createBlueprint(cs, bluePrintName, bpType, importPath, override); - bp.blueprintToYaml(outputPath, bluePrintName, cs); - } - - - public static void printInstructions() { - System.out.println("OPTIONS:"); - System.out.println("-i: The path to the JSON spec file (required)"); - System.out.println("-n: Name of the blueprint (optional)"); - System.out.println("-p: The path to the final blueprint (required)"); - System.out.println("-t: The path to the yaml import file (optional)"); - System.out.println("-d: With this flag present the blueprint will be created with the dmaap plugin enables"); - System.out.println("-o: The value you want for service_component_name_override (optional)"); - } - - public static void parseInputs(String[] args) throws Exception { - //convert the arguments array to a string to make it easier - String commands = ""; - for(String s: args) { - if(commands.length() == 0) { - commands = s; - } - else { - commands = commands + " " + s; - } - } - - //check if it has the required inputs - if(!commands.contains("-p") || !commands.contains("-i")) { - System.out.println("did not enter the required inputs"); - } - else { - BasicParser parser = new BasicParser(); - Options options = new Options(); - options.addOption("i", "Spec", true, "ComponentSpec import file"); - options.addOption("p", "Path", true, "Path to the final blueprint"); - options.addOption("n", "Name", true, "Name of the blueprint"); - options.addOption("t", "imports", true, "Path to the import file"); - options.addOption("d", "Dmaap", false, "Enable the dmaap plugin"); - options.addOption("o", "Override", true, "service component name override"); - - CommandLine commandLine = parser.parse(options, args); - componentSpecPath = commandLine.getOptionValue("i"); - outputPath = commandLine.getOptionValue("p"); - override = commandLine.getOptionValue("o"); - if(!(commandLine.getOptionValue("n") == null)){ - bluePrintName = commandLine.getOptionValue("n"); - } - if(!(commandLine.getOptionValue("t") == null)) { - importPath = commandLine.getOptionValue("t"); - } - if(commands.contains("-d")) { - bpType = 'd'; - } - } - - } -} - diff --git a/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/PolicyCommand.java b/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/PolicyCommand.java new file mode 100644 index 0000000..81a7911 --- /dev/null +++ b/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/PolicyCommand.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.blueprintgenerator.core; + +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; +import org.onap.blueprintgenerator.models.policymodel.PolicyModel; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +@Command(name = "policy", description = "Command used to generate policy model from component spec") +public class PolicyCommand implements Runnable{ + @Option(names = {"-i", "--component-spec"}, description = "Path to component spec file", required = true) + private String componentSpecPath; + + @Option(names = {"-p", "--model-path"}, description = "Path to directory that models are output to", required = true) + private String modelOutputPath; + + @Override + public void run() { + ComponentSpec inboundComponentSpec = new ComponentSpec(); + inboundComponentSpec.createComponentSpecFromFile(componentSpecPath); + new PolicyModel().createPolicyModels(inboundComponentSpec, this.modelOutputPath); + } +} diff --git a/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/PolicyCreate.java b/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/PolicyCreate.java deleted file mode 100644 index 3210a2f..0000000 --- a/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/PolicyCreate.java +++ /dev/null @@ -1,85 +0,0 @@ -/**============LICENSE_START======================================================= - org.onap.dcae - ================================================================================ - Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. - ================================================================================ - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ============LICENSE_END========================================================= - -*/ - -package org.onap.blueprintgenerator.core; - -import java.util.ArrayList; - -import org.apache.commons.cli.BasicParser; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Options; -import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; -import org.onap.blueprintgenerator.models.policymodel.PolicyModel; - -public class PolicyCreate { - - private static String componentSpecPath = ""; - - private static String outputPath = ""; - - - - public static void main(String[] args) throws Exception { - printInstructions(); - parseInputs(args); - - ComponentSpec cs = new ComponentSpec(); - cs.createComponentSpecFromFile(componentSpecPath); - - PolicyModel p = new PolicyModel(); - ArrayList<PolicyModel> models = p.createPolicyModels(cs, outputPath); - } - - public static void printInstructions() { - System.out.println("OPTIONS:"); - System.out.println("-i: The path to the JSON spec file (required)"); - System.out.println("-p: The output path for all of the models (required)"); - } - - public static void parseInputs(String[] args) throws Exception { - //convert the arguments array to a string to make it easier - String commands = ""; - for(String s: args) { - if(commands.length() == 0) { - commands = s; - } - else { - commands = commands + " " + s; - } - } - - //check if it has the required inputs - if(!commands.contains("-p") || !commands.contains("-i")) { - System.out.println("did not enter the required inputs"); - System.exit(0); - } - else { - BasicParser parser = new BasicParser(); - Options options = new Options(); - options.addOption("i", "Spec", true, "ComponentSpec import file"); - options.addOption("p", "Path", true, "Path to the final blueprint"); - - CommandLine commandLine = parser.parse(options, args); - componentSpecPath = commandLine.getOptionValue("i"); - outputPath = commandLine.getOptionValue("p"); - - } - } -} diff --git a/blueprint-generator/src/test/java/org/onap/blueprintgenerator/core/BlueprintGeneratorTest.java b/blueprint-generator/src/test/java/org/onap/blueprintgenerator/core/BlueprintGeneratorTest.java index 3eeffec..404b899 100644 --- a/blueprint-generator/src/test/java/org/onap/blueprintgenerator/core/BlueprintGeneratorTest.java +++ b/blueprint-generator/src/test/java/org/onap/blueprintgenerator/core/BlueprintGeneratorTest.java @@ -21,23 +21,21 @@ package org.onap.blueprintgenerator.core; import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import java.io.IOException; +import java.io.PrintStream; import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.TreeMap; import org.junit.Test; -import org.onap.blueprintgenerator.core.BlueprintGenerator; +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; import org.onap.blueprintgenerator.models.blueprint.Blueprint; -import org.onap.blueprintgenerator.models.blueprint.ConcatObj; -import org.onap.blueprintgenerator.models.blueprint.DmaapObj; import org.onap.blueprintgenerator.models.blueprint.GetInput; -import org.onap.blueprintgenerator.models.blueprint.Interfaces; -import org.onap.blueprintgenerator.models.blueprint.Start; -import org.onap.blueprintgenerator.models.blueprint.StartInputs; import org.onap.blueprintgenerator.models.componentspec.Artifacts; import org.onap.blueprintgenerator.models.componentspec.Auxilary; import org.onap.blueprintgenerator.models.componentspec.CallsObj; @@ -60,8 +58,7 @@ import org.onap.blueprintgenerator.models.policymodel.PolicyModel; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; - -import junit.framework.Assert; +import picocli.CommandLine; // TODO: Auto-generated Javadoc @@ -413,13 +410,26 @@ public class BlueprintGeneratorTest { } assertEquals(true, d); } + + @Test + public void testPrintInstructionsBlueprintCommand() { + BlueprintCommand objUnderTest = new BlueprintCommand(); + CommandLine cli = new CommandLine(objUnderTest); + PrintStream mockStdOutWriter = Mockito.mock(PrintStream.class); + ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); + cli.usage(mockStdOutWriter); + verify(mockStdOutWriter, times(1)).print(any(Object.class)); + + } + @Test - public void testPrintInstructions() { - //check if the instructions are pritns correctly and if the print statement comes out then its correct - BlueprintGenerator bp = new BlueprintGenerator(); - bp.printInstructions(); - boolean t = true; - assertEquals(true, t); + public void testPrintInstructionsPolicyCommand() { + PolicyCommand objUnderTest = new PolicyCommand(); + CommandLine cli = new CommandLine(objUnderTest); + PrintStream mockStdOutWriter = Mockito.mock(PrintStream.class); + ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); + cli.usage(mockStdOutWriter); + verify(mockStdOutWriter, times(1)).print(any(Object.class)); } @Test diff --git a/blueprint-generator/version.properties b/blueprint-generator/version.properties index 00ef564..755adf7 100644 --- a/blueprint-generator/version.properties +++ b/blueprint-generator/version.properties @@ -1,6 +1,6 @@ major=1 minor=2 -patch=0 +patch=1 base_version=${major}.${minor}.${patch} release_version=${base_version} snapshot_version=${base_version}-SNAPSHOT |