summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mod/bpgenerator/pom.xml2
-rw-r--r--mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/common/blueprint/BlueprintHelper.java4
-rw-r--r--mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprint.java185
-rw-r--r--mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprintTest.java244
-rw-r--r--mod/bpgenerator/version.properties2
5 files changed, 348 insertions, 89 deletions
diff --git a/mod/bpgenerator/pom.xml b/mod/bpgenerator/pom.xml
index 8960d69..aaf9713 100644
--- a/mod/bpgenerator/pom.xml
+++ b/mod/bpgenerator/pom.xml
@@ -29,7 +29,7 @@
</parent>
<groupId>org.onap.dcaegen2.platform.mod</groupId>
<artifactId>blueprint-generator</artifactId>
- <version>1.5.0-SNAPSHOT</version>
+ <version>1.5.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.junit.reportsPath>${project.basedir}/target/surefire-reports</sonar.junit.reportsPath>
diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/common/blueprint/BlueprintHelper.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/common/blueprint/BlueprintHelper.java
index 16eca51..451988f 100644
--- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/common/blueprint/BlueprintHelper.java
+++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/common/blueprint/BlueprintHelper.java
@@ -34,4 +34,8 @@ public class BlueprintHelper {
inputMap.put("default", defaultValue);
return inputMap;
}
+
+ public static String joinUnderscore(String firstValue, String secondValue){
+ return firstValue + "_" + secondValue;
+ }
}
diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprint.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprint.java
index c4cc663..2774abb 100644
--- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprint.java
+++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprint.java
@@ -1,4 +1,4 @@
-/**============LICENSE_START=======================================================
+/*============LICENSE_START=======================================================
org.onap.dcae
================================================================================
Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
@@ -8,16 +8,16 @@
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.models.dmaapbp;
@@ -28,92 +28,103 @@ import java.util.TreeMap;
import org.onap.blueprintgenerator.core.PgaasNodeBuilder;
import org.onap.blueprintgenerator.core.PolicyNodeBuilder;
import org.onap.blueprintgenerator.models.blueprint.Blueprint;
-import org.onap.blueprintgenerator.models.blueprint.Imports;
import org.onap.blueprintgenerator.models.blueprint.Node;
import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
import org.onap.blueprintgenerator.models.componentspec.Publishes;
import org.onap.blueprintgenerator.models.componentspec.Subscribes;
-public class DmaapBlueprint extends Blueprint{
- public Blueprint createDmaapBlueprint(ComponentSpec cs, String importPath, String override) {
- Blueprint bp = new Blueprint();
-
- //set tosca definition
- bp.setTosca_definitions_version("cloudify_dsl_1_3");
-
- //set the description
- bp.setDescription(cs.getSelf().getDescription());
-
- //create the inpus object that will be added to over the creation of the blueprint
- TreeMap<String, LinkedHashMap<String, Object>> inps = new TreeMap<String, LinkedHashMap<String, Object>>();
-
- //set the imports
- Imports imps = new Imports();
- if(importPath.equals("")) {
- bp.setImports(imps.createDmaapImports());
- }
- else {
- bp.setImports(imps.createImportsFromFile(importPath));
- }
-
- //bp.setImports(imps.getImports());
-
- //set and create the node templates
- TreeMap<String, Node> nodeTemplate = new TreeMap();
-
- //create and add the main dmaap node
- DmaapNode dmaap = new DmaapNode();
- inps = dmaap.createDmaapNode(cs, inps, override);
- nodeTemplate.put(cs.getSelf().getName(), dmaap);
-
- //create and add the topic/feed nodes
-
- //go through the streams publishes
- if(cs.getStreams().getPublishes() != null) {
- for(Publishes p: cs.getStreams().getPublishes()) {
- if(p.getType().equals("message_router") || p.getType().equals("message router")) {
- String topic = p.getConfig_key() + "_topic";
- DmaapNode topicNode = new DmaapNode();
- inps = topicNode.createTopicNode(cs, inps, topic);
- nodeTemplate.put(topic, topicNode);
- } else if(p.getType().equals("data_router") || p.getType().equals("data router")) {
- String feed = p.getConfig_key() + "_feed";
- DmaapNode feedNode = new DmaapNode();
- inps = feedNode.createFeedNode(cs, inps, feed);
- nodeTemplate.put(feed, feedNode);
- }
- }
- }
- //go through the stream subscribes
- if(cs.getStreams().getSubscribes() != null) {
- for(Subscribes s: cs.getStreams().getSubscribes()) {
- if(s.getType().equals("message_router") || s.getType().equals("message router")) {
- String topic = s.getConfig_key() + "_topic";
- DmaapNode topicNode = new DmaapNode();
- inps = topicNode.createTopicNode(cs, inps, topic);
- nodeTemplate.put(topic, topicNode);
- } else if(s.getType().equals("data_router") || s.getType().equals("data router")) {
- String feed = s.getConfig_key() + "_feed";
- DmaapNode feedNode = new DmaapNode();
- inps = feedNode.createFeedNode(cs, inps, feed);
- nodeTemplate.put(feed, feedNode);
- }
- }
- }
-
- //if present in component spec, populate policyNodes information in the blueprint
- if(cs.getPolicyInfo() != null){
- PolicyNodeBuilder.addPolicyNodesAndInputs(cs, nodeTemplate, inps);
- }
-
- //if present in component spec, populate pgaasNodes information in the blueprint
- if(cs.getAuxilary().getDatabases() != null){
- PgaasNodeBuilder.addPgaasNodesAndInputs(cs, nodeTemplate, inps);
- }
-
- bp.setNode_templates(nodeTemplate);
-
- bp.setInputs(inps);
- return bp;
- }
+import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.joinUnderscore;
+import static org.onap.blueprintgenerator.models.blueprint.Imports.createDmaapImports;
+import static org.onap.blueprintgenerator.models.blueprint.Imports.createImportsFromFile;
+
+public class DmaapBlueprint extends Blueprint {
+
+ private static final String TOPIC = "topic";
+ private static final String FEED = "feed";
+
+ public Blueprint createDmaapBlueprint(ComponentSpec componentSpec, String importPath, String override) {
+ Blueprint blueprint = new Blueprint();
+
+ //set tosca definition
+ blueprint.setTosca_definitions_version("cloudify_dsl_1_3");
+
+ //set the description
+ blueprint.setDescription(componentSpec.getSelf().getDescription());
+
+ //create the inpus object that will be added to over the creation of the blueprint
+ TreeMap<String, LinkedHashMap<String, Object>> inps = new TreeMap<>();
+
+ //set the imports
+ if (importPath.equals("")) {
+ blueprint.setImports(createDmaapImports());
+ } else {
+ blueprint.setImports(createImportsFromFile(importPath));
+ }
+
+ //set and create the node templates
+ TreeMap<String, Node> nodeTemplate = new TreeMap();
+
+ //create and add the main dmaap node
+ DmaapNode dmaap = new DmaapNode();
+ inps = dmaap.createDmaapNode(componentSpec, inps, override);
+ nodeTemplate.put(componentSpec.getSelf().getName(), dmaap);
+
+ //create and add the topic/feed nodes
+
+ //go through the streams publishes
+ if (componentSpec.getStreams().getPublishes() != null) {
+ for (Publishes publisher : componentSpec.getStreams().getPublishes()) {
+ if (isMessageRouter(publisher.getType())) {
+ String topic = joinUnderscore(publisher.getConfig_key(), TOPIC);
+ DmaapNode topicNode = new DmaapNode();
+ inps = topicNode.createTopicNode(componentSpec, inps, topic);
+ nodeTemplate.put(topic, topicNode);
+ } else if (isDataRouter(publisher.getType())) {
+ String feed = joinUnderscore(publisher.getConfig_key(), FEED);
+ DmaapNode feedNode = new DmaapNode();
+ inps = feedNode.createFeedNode(componentSpec, inps, feed);
+ nodeTemplate.put(feed, feedNode);
+ }
+ }
+ }
+ //go through the stream subscribes
+ if (componentSpec.getStreams().getSubscribes() != null) {
+ for (Subscribes subscriber : componentSpec.getStreams().getSubscribes()) {
+ if (isMessageRouter(subscriber.getType())) {
+ String topic = joinUnderscore(subscriber.getConfig_key(), TOPIC);
+ DmaapNode topicNode = new DmaapNode();
+ inps = topicNode.createTopicNode(componentSpec, inps, topic);
+ nodeTemplate.put(topic, topicNode);
+ } else if (isDataRouter(subscriber.getType())) {
+ String feed = joinUnderscore(subscriber.getConfig_key(), FEED);
+ DmaapNode feedNode = new DmaapNode();
+ inps = feedNode.createFeedNode(componentSpec, inps, feed);
+ nodeTemplate.put(feed, feedNode);
+ }
+ }
+ }
+
+ //if present in component spec, populate policyNodes information in the blueprint
+ if (componentSpec.getPolicyInfo() != null) {
+ PolicyNodeBuilder.addPolicyNodesAndInputs(componentSpec, nodeTemplate, inps);
+ }
+
+ //if present in component spec, populate pgaasNodes information in the blueprint
+ if (componentSpec.getAuxilary().getDatabases() != null) {
+ PgaasNodeBuilder.addPgaasNodesAndInputs(componentSpec, nodeTemplate, inps);
+ }
+
+ blueprint.setNode_templates(nodeTemplate);
+
+ blueprint.setInputs(inps);
+ return blueprint;
+ }
+
+ private boolean isDataRouter(String type) {
+ return type.equals("data_router") || type.equals("data router");
+ }
+
+ private boolean isMessageRouter(String type) {
+ return type.equals("message_router") || type.equals("message router");
+ }
}
diff --git a/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprintTest.java b/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprintTest.java
new file mode 100644
index 0000000..820082e
--- /dev/null
+++ b/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprintTest.java
@@ -0,0 +1,244 @@
+/*============LICENSE_START=======================================================
+ org.onap.dcae
+ ================================================================================
+ Copyright (c) 2020 Nokia. 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.models.dmaapbp;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Test;
+import org.onap.blueprintgenerator.models.blueprint.Blueprint;
+import org.onap.blueprintgenerator.models.componentspec.Artifacts;
+import org.onap.blueprintgenerator.models.componentspec.Auxilary;
+import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
+import org.onap.blueprintgenerator.models.componentspec.Parameters;
+import org.onap.blueprintgenerator.models.componentspec.Publishes;
+import org.onap.blueprintgenerator.models.componentspec.Self;
+import org.onap.blueprintgenerator.models.componentspec.Streams;
+import org.onap.blueprintgenerator.models.componentspec.Subscribes;
+
+public class DmaapBlueprintTest {
+
+ private static final String MOCKED_NAME = "sample.name";
+ private static final String MESSAGE_ROUTER_TYPE_1 = "message_router";
+ private static final String MESSAGE_ROUTER_TYPE_2 = "message router";
+ private static final String DATA_ROUTER_TYPE_1 = "data_router";
+ private static final String DATA_ROUTER_TYPE_2 = "data router";
+ private static final String CONFIG_KEY_1 = "Configkey1";
+ private static final String CONFIG_KEY_2 = "Configkey2";
+
+ private static final String TOPIC_NODE_1 = CONFIG_KEY_1 + "_topic";
+ private static final String TOPIC_NODE_2 = CONFIG_KEY_2 + "_topic";
+ private static final String FEED_NODE_1 = CONFIG_KEY_1 + "_feed";
+ private static final String FEED_NODE_2 = CONFIG_KEY_2 + "_feed";
+
+ private static final String SAMPLE_FORMAT = "Format";
+ private static final String SAMPLE_VERSION = "1.0.0";
+ private static final String SAMPLE_ROUTE = "SampleRoute";
+ private static final String SAMPLE_DESCRIPTION = "sample description";
+ private static final String SAMPLE_PORTS = "8080:8080";
+ private static final String SAMPLE_ARTIFACT_TYPE = "test";
+ private static final String SAMPLE_ARTIFACT_URI = "test_uri";
+
+ @Test
+ public void dmaapBlueprintShouldHaveNodeTemplateWithDmaapNode() {
+
+ //given
+ ComponentSpec componentSpec = getMockedComponentSpec();
+ DmaapBlueprint dmaapBlueprint = new DmaapBlueprint();
+
+ //when
+ Blueprint resultBlueprint = dmaapBlueprint.createDmaapBlueprint(componentSpec, "", "");
+
+ //then
+ assertTrue(resultBlueprint.getNode_templates().get(MOCKED_NAME) instanceof DmaapNode);
+ }
+
+ @Test
+ public void nodeTemplateHasTopicNodeWhenAddMessageRouterAsPublishes() {
+ //given
+ ComponentSpec componentSpec = getMockedComponentSpec();
+ Streams streams = new Streams();
+ streams.setPublishes(getMessageRouterPublishes());
+ streams.setSubscribes(new Subscribes[0]);
+
+ when(componentSpec.getStreams()).thenReturn(streams);
+ DmaapBlueprint dmaapBlueprint = new DmaapBlueprint();
+
+ //when
+ Blueprint resultBlueprint = dmaapBlueprint.createDmaapBlueprint(componentSpec, "", "");
+
+ //then
+ assertNotNull(resultBlueprint.getNode_templates().get(TOPIC_NODE_1));
+ assertNotNull(resultBlueprint.getNode_templates().get(TOPIC_NODE_2));
+
+ }
+
+ @Test
+ public void nodeTemplateHasTopicNodeWhenAddMessageRouterAsSubscribes() {
+ //given
+ ComponentSpec componentSpec = getMockedComponentSpec();
+ Streams streams = new Streams();
+ streams.setPublishes(new Publishes[0]);
+ streams.setSubscribes(getMessageRouterSubscribes());
+
+ when(componentSpec.getStreams()).thenReturn(streams);
+ DmaapBlueprint dmaapBlueprint = new DmaapBlueprint();
+
+ //when
+ Blueprint resultBlueprint = dmaapBlueprint.createDmaapBlueprint(componentSpec, "", "");
+
+ //then
+ assertNotNull(resultBlueprint.getNode_templates().get(TOPIC_NODE_1));
+ assertNotNull(resultBlueprint.getNode_templates().get(TOPIC_NODE_2));
+
+ }
+
+ @Test
+ public void nodeTemplateHasFeedNodeWhenAddDataRouterAsPublishes() {
+ //given
+ ComponentSpec componentSpec = getMockedComponentSpec();
+ Streams streams = new Streams();
+ streams.setPublishes(getDataRouterPublishes());
+ streams.setSubscribes(new Subscribes[0]);
+
+ when(componentSpec.getStreams()).thenReturn(streams);
+ DmaapBlueprint dmaapBlueprint = new DmaapBlueprint();
+
+ //when
+ Blueprint resultBlueprint = dmaapBlueprint.createDmaapBlueprint(componentSpec, "", "");
+
+ //then
+ assertNotNull(resultBlueprint.getNode_templates().get(FEED_NODE_1));
+ assertNotNull(resultBlueprint.getNode_templates().get(FEED_NODE_2));
+
+ }
+
+ @Test
+ public void nodeTemplateHasFeedNodeWhenAddDataRouterAsSubscribes() {
+ //given
+ ComponentSpec componentSpec = getMockedComponentSpec();
+ Streams streams = new Streams();
+ streams.setPublishes(new Publishes[0]);
+ streams.setSubscribes(getDataRouterSubscribes());
+
+ when(componentSpec.getStreams()).thenReturn(streams);
+ DmaapBlueprint dmaapBlueprint = new DmaapBlueprint();
+
+ //when
+ Blueprint resultBlueprint = dmaapBlueprint.createDmaapBlueprint(componentSpec, "", "");
+
+ //then
+ assertNotNull(resultBlueprint.getNode_templates().get(FEED_NODE_1));
+ assertNotNull(resultBlueprint.getNode_templates().get(FEED_NODE_2));
+
+ }
+
+ private Publishes[] getMessageRouterPublishes() {
+ List<Publishes> publishesList = new ArrayList<>();
+
+ publishesList.add(createSamplePublishes(MESSAGE_ROUTER_TYPE_1, CONFIG_KEY_1));
+ publishesList.add(createSamplePublishes(MESSAGE_ROUTER_TYPE_2, CONFIG_KEY_2));
+ return publishesList.toArray(new Publishes[0]);
+ }
+
+ private Subscribes[] getMessageRouterSubscribes() {
+ List<Subscribes> subscribesList = new ArrayList<>();
+
+ subscribesList.add(createSampleSubscribes(MESSAGE_ROUTER_TYPE_1, CONFIG_KEY_1));
+ subscribesList.add(createSampleSubscribes(MESSAGE_ROUTER_TYPE_2, CONFIG_KEY_2));
+ return subscribesList.toArray(new Subscribes[0]);
+ }
+
+ private Publishes[] getDataRouterPublishes() {
+ List<Publishes> publishesList = new ArrayList<>();
+
+ publishesList.add(createSamplePublishes(DATA_ROUTER_TYPE_1, CONFIG_KEY_1));
+ publishesList.add(createSamplePublishes(DATA_ROUTER_TYPE_2, CONFIG_KEY_2));
+ return publishesList.toArray(new Publishes[0]);
+ }
+
+ private Subscribes[] getDataRouterSubscribes() {
+ List<Subscribes> subscribesList = new ArrayList<>();
+
+ subscribesList.add(createSampleSubscribes(DATA_ROUTER_TYPE_1, CONFIG_KEY_1));
+ subscribesList.add(createSampleSubscribes(DATA_ROUTER_TYPE_2, CONFIG_KEY_2));
+ return subscribesList.toArray(new Subscribes[0]);
+ }
+
+ private Publishes createSamplePublishes(String type, String key) {
+ Publishes publishes = new Publishes();
+
+ publishes.setType(type);
+ publishes.setConfig_key(key);
+ publishes.setFormat(SAMPLE_FORMAT);
+ publishes.setVersion(SAMPLE_VERSION);
+ publishes.setRoute(SAMPLE_ROUTE);
+
+ return publishes;
+ }
+
+ private Subscribes createSampleSubscribes(String type, String key) {
+ Subscribes subscribes = new Subscribes();
+
+ subscribes.setType(type);
+ subscribes.setConfig_key(key);
+ subscribes.setFormat(SAMPLE_FORMAT);
+ subscribes.setVersion(SAMPLE_FORMAT);
+ subscribes.setRoute(SAMPLE_ROUTE);
+
+ return subscribes;
+ }
+
+ private ComponentSpec getMockedComponentSpec() {
+ Self self = mock(Self.class);
+ when(self.getDescription()).thenReturn(SAMPLE_DESCRIPTION);
+ when(self.getName()).thenReturn(MOCKED_NAME);
+
+ Auxilary auxilary = mock(Auxilary.class);
+ ArrayList<Object> ports = new ArrayList<>();
+ ports.add(SAMPLE_PORTS);
+ when(auxilary.getPorts()).thenReturn(ports);
+
+ Streams streams = mock(Streams.class);
+ when(streams.getPublishes()).thenReturn(new Publishes[0]);
+ when(streams.getSubscribes()).thenReturn(new Subscribes[0]);
+
+ Artifacts artifact = new Artifacts();
+ artifact.setType(SAMPLE_ARTIFACT_TYPE);
+ artifact.setUri(SAMPLE_ARTIFACT_URI);
+
+ Artifacts[] arrayArtifacts = new Artifacts[10];
+ arrayArtifacts[0] = artifact;
+
+ ComponentSpec componentSpec = mock(ComponentSpec.class);
+ when(componentSpec.getSelf()).thenReturn(self);
+ when(componentSpec.getAuxilary()).thenReturn(auxilary);
+ when(componentSpec.getStreams()).thenReturn(streams);
+ when(componentSpec.getArtifacts()).thenReturn(arrayArtifacts);
+ when(componentSpec.getParameters()).thenReturn(new Parameters[0]);
+ return componentSpec;
+ }
+}
diff --git a/mod/bpgenerator/version.properties b/mod/bpgenerator/version.properties
index 68bc8f5..303a703 100644
--- a/mod/bpgenerator/version.properties
+++ b/mod/bpgenerator/version.properties
@@ -1,6 +1,6 @@
major=1
minor=5
-patch=0
+patch=1
base_version=${major}.${minor}.${patch}
release_version=${base_version}
snapshot_version=${base_version}-SNAPSHOT