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.models.dmaapbp;
23 import java.util.LinkedHashMap;
24 import java.util.TreeMap;
26 import org.onap.blueprintgenerator.core.PgaasNodeBuilder;
27 import org.onap.blueprintgenerator.core.PolicyNodeBuilder;
28 import org.onap.blueprintgenerator.models.blueprint.Blueprint;
29 import org.onap.blueprintgenerator.models.blueprint.Imports;
30 import org.onap.blueprintgenerator.models.blueprint.Node;
31 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
32 import org.onap.blueprintgenerator.models.componentspec.Publishes;
33 import org.onap.blueprintgenerator.models.componentspec.Subscribes;
35 public class DmaapBlueprint extends Blueprint{
36 public Blueprint createDmaapBlueprint(ComponentSpec cs, String importPath, String override) {
37 Blueprint bp = new Blueprint();
39 //set tosca definition
40 bp.setTosca_definitions_version("cloudify_dsl_1_3");
43 bp.setDescription(cs.getSelf().getDescription());
45 //create the inpus object that will be added to over the creation of the blueprint
46 TreeMap<String, LinkedHashMap<String, Object>> inps = new TreeMap<String, LinkedHashMap<String, Object>>();
49 Imports imps = new Imports();
50 if(importPath.equals("")) {
51 bp.setImports(imps.createDmaapImports());
54 bp.setImports(imps.createImportsFromFile(importPath));
57 //bp.setImports(imps.getImports());
59 //set and create the node templates
60 TreeMap<String, Node> nodeTemplate = new TreeMap();
62 //create and add the main dmaap node
63 DmaapNode dmaap = new DmaapNode();
64 inps = dmaap.createDmaapNode(cs, inps, override);
65 nodeTemplate.put(cs.getSelf().getName(), dmaap);
67 //create and add the topic/feed nodes
69 //go through the streams publishes
70 if(cs.getStreams().getPublishes() != null) {
71 for(Publishes p: cs.getStreams().getPublishes()) {
72 if(p.getType().equals("message_router") || p.getType().equals("message router")) {
73 String topic = p.getConfig_key() + "_topic";
74 DmaapNode topicNode = new DmaapNode();
75 inps = topicNode.createTopicNode(cs, inps, topic);
76 nodeTemplate.put(topic, topicNode);
77 } else if(p.getType().equals("data_router") || p.getType().equals("data router")) {
78 String feed = p.getConfig_key() + "_feed";
79 DmaapNode feedNode = new DmaapNode();
80 inps = feedNode.createFeedNode(cs, inps, feed);
81 nodeTemplate.put(feed, feedNode);
85 //go through the stream subscribes
86 if(cs.getStreams().getSubscribes() != null) {
87 for(Subscribes s: cs.getStreams().getSubscribes()) {
88 if(s.getType().equals("message_router") || s.getType().equals("message router")) {
89 String topic = s.getConfig_key() + "_topic";
90 DmaapNode topicNode = new DmaapNode();
91 inps = topicNode.createTopicNode(cs, inps, topic);
92 nodeTemplate.put(topic, topicNode);
93 } else if(s.getType().equals("data_router") || s.getType().equals("data router")) {
94 String feed = s.getConfig_key() + "_feed";
95 DmaapNode feedNode = new DmaapNode();
96 inps = feedNode.createFeedNode(cs, inps, feed);
97 nodeTemplate.put(feed, feedNode);
102 //if present in component spec, populate policyNodes information in the blueprint
103 if(cs.getPolicyInfo() != null){
104 PolicyNodeBuilder.addPolicyNodesAndInputs(cs, nodeTemplate, inps);
107 //if present in component spec, populate pgaasNodes information in the blueprint
108 if(cs.getAuxilary().getDatabases() != null){
109 PgaasNodeBuilder.addPgaasNodesAndInputs(cs, nodeTemplate, inps);
112 bp.setNode_templates(nodeTemplate);