diff options
author | 2020-09-21 12:28:51 +0200 | |
---|---|---|
committer | 2020-09-22 14:24:56 +0200 | |
commit | 9e72a68a16d4a7aaeb093e23e288585f9aebd220 (patch) | |
tree | 88b3cc20220473ef6fd15cf94763d35e939f57e2 /mod/bpgenerator/src/main | |
parent | a608125a5cb02a9eca3b146ab41fbdac7cbf706e (diff) |
Refactor DmaapBlueprint class
- Refactor DmaapBluepritn class
- Add UT
Issue-ID: DCAEGEN2-2289
Signed-off-by: Tomasz Wrobel <tomasz.wrobel@nokia.com>
Change-Id: Ia847388cf7f4d23c7aa7cfc76c1c8983dc79b069
Diffstat (limited to 'mod/bpgenerator/src/main')
2 files changed, 102 insertions, 87 deletions
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"); + } } |