1 /*============LICENSE_START=======================================================
3 ================================================================================
4 Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
5 ================================================================================
6 Modifications Copyright (c) 2020 Nokia. All rights reserved.
7 ================================================================================
8 Licensed under the Apache License, Version 2.0 (the "License");
9 you may not use this file except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19 ============LICENSE_END=========================================================
23 package org.onap.blueprintgenerator.models.dmaapbp;
25 import java.util.LinkedHashMap;
26 import java.util.TreeMap;
28 import org.onap.blueprintgenerator.core.PgaasNodeBuilder;
29 import org.onap.blueprintgenerator.core.PolicyNodeBuilder;
30 import org.onap.blueprintgenerator.models.blueprint.Blueprint;
31 import org.onap.blueprintgenerator.models.blueprint.Node;
32 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
33 import org.onap.blueprintgenerator.models.componentspec.Publishes;
34 import org.onap.blueprintgenerator.models.componentspec.Subscribes;
36 import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.joinUnderscore;
37 import static org.onap.blueprintgenerator.models.blueprint.Imports.createDmaapImports;
38 import static org.onap.blueprintgenerator.models.blueprint.Imports.createImportsFromFile;
40 public class DmaapBlueprint extends Blueprint {
42 private static final String TOPIC = "topic";
43 private static final String FEED = "feed";
45 public Blueprint createDmaapBlueprint(ComponentSpec componentSpec, String importPath, String override) {
46 Blueprint blueprint = new Blueprint();
48 //set tosca definition
49 blueprint.setTosca_definitions_version("cloudify_dsl_1_3");
52 blueprint.setDescription(componentSpec.getSelf().getDescription());
54 //create the inpus object that will be added to over the creation of the blueprint
55 TreeMap<String, LinkedHashMap<String, Object>> inps = new TreeMap<>();
58 if (importPath.equals("")) {
59 blueprint.setImports(createDmaapImports());
61 blueprint.setImports(createImportsFromFile(importPath));
64 //set and create the node templates
65 TreeMap<String, Node> nodeTemplate = new TreeMap();
67 //create and add the main dmaap node
68 DmaapNode dmaap = new DmaapNode();
69 inps = dmaap.createDmaapNode(componentSpec, inps, override);
70 nodeTemplate.put(componentSpec.getSelf().getName(), dmaap);
72 //create and add the topic/feed nodes
74 //go through the streams publishes
75 if (componentSpec.getStreams().getPublishes() != null) {
76 for (Publishes publisher : componentSpec.getStreams().getPublishes()) {
77 if (isMessageRouter(publisher.getType())) {
78 String topic = joinUnderscore(publisher.getConfig_key(), TOPIC);
79 DmaapNode topicNode = new DmaapNode();
80 inps = topicNode.createTopicNode(componentSpec, inps, topic);
81 nodeTemplate.put(topic, topicNode);
82 } else if (isDataRouter(publisher.getType())) {
83 String feed = joinUnderscore(publisher.getConfig_key(), FEED);
84 DmaapNode feedNode = new DmaapNode();
85 inps = feedNode.createFeedNode(componentSpec, inps, feed);
86 nodeTemplate.put(feed, feedNode);
90 //go through the stream subscribes
91 if (componentSpec.getStreams().getSubscribes() != null) {
92 for (Subscribes subscriber : componentSpec.getStreams().getSubscribes()) {
93 if (isMessageRouter(subscriber.getType())) {
94 String topic = joinUnderscore(subscriber.getConfig_key(), TOPIC);
95 DmaapNode topicNode = new DmaapNode();
96 inps = topicNode.createTopicNode(componentSpec, inps, topic);
97 nodeTemplate.put(topic, topicNode);
98 } else if (isDataRouter(subscriber.getType())) {
99 String feed = joinUnderscore(subscriber.getConfig_key(), FEED);
100 DmaapNode feedNode = new DmaapNode();
101 inps = feedNode.createFeedNode(componentSpec, inps, feed);
102 nodeTemplate.put(feed, feedNode);
107 //if present in component spec, populate policyNodes information in the blueprint
108 if (componentSpec.getPolicyInfo() != null) {
109 PolicyNodeBuilder.addPolicyNodesAndInputs(componentSpec, nodeTemplate, inps);
112 //if present in component spec, populate pgaasNodes information in the blueprint
113 if (componentSpec.getAuxilary().getDatabases() != null) {
114 PgaasNodeBuilder.addPgaasNodesAndInputs(componentSpec, nodeTemplate, inps);
117 blueprint.setNode_templates(nodeTemplate);
119 blueprint.setInputs(inps);
123 private boolean isDataRouter(String type) {
124 return type.equals("data_router") || type.equals("data router");
127 private boolean isMessageRouter(String type) {
128 return type.equals("message_router") || type.equals("message router");