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.ArrayList;
24 import java.util.LinkedHashMap;
25 import java.util.TreeMap;
27 import org.onap.blueprintgenerator.models.blueprint.Blueprint;
28 import org.onap.blueprintgenerator.models.blueprint.Imports;
29 import org.onap.blueprintgenerator.models.blueprint.Interfaces;
30 import org.onap.blueprintgenerator.models.blueprint.Node;
31 import org.onap.blueprintgenerator.models.blueprint.Properties;
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 public class DmaapBlueprint extends Blueprint{
37 public Blueprint createDmaapBlueprint(ComponentSpec cs, String importPath, String override) {
38 Blueprint bp = new Blueprint();
40 //set tosca definition
41 bp.setTosca_definitions_version("cloudify_dsl_1_3");
44 bp.setDescription(cs.getSelf().getDescription());
46 //create the inpus object that will be added to over the creation of the blueprint
47 TreeMap<String, LinkedHashMap<String, Object>> inps = new TreeMap<String, LinkedHashMap<String, Object>>();
50 Imports imps = new Imports();
51 if(importPath.equals("")) {
52 imps.createDmaapImports();
55 imps.createImportsFromFile(importPath);
58 bp.setImports(imps.getImports());
60 //set and create the node templates
61 TreeMap<String, Node> nodeTemplate = new TreeMap();
63 //create and add the main dmaap node
64 DmaapNode dmaap = new DmaapNode();
65 inps = dmaap.createDmaapNode(cs, inps, override);
66 nodeTemplate.put(cs.getSelf().getName(), dmaap);
68 //create and add the topic/feed nodes
70 //go through the streams publishes
72 if(cs.getStreams().getPublishes() != null) {
73 for(Publishes p: cs.getStreams().getPublishes()) {
74 if(p.getType().equals("message_router") || p.getType().equals("message router")) {
75 String topic = "topic" + counter;
76 DmaapNode topicNode = new DmaapNode();
77 inps = topicNode.createTopicNode(cs, inps, topic);
78 nodeTemplate.put(topic, topicNode);
79 } else if(p.getType().equals("data_router") || p.getType().equals("data router")) {
80 String feed = "feed" + counter;
81 DmaapNode feedNode = new DmaapNode();
82 inps = feedNode.createFeedNode(cs, inps, feed);
83 nodeTemplate.put(feed, feedNode);
88 //go through the stream subscribes
89 if(cs.getStreams().getSubscribes() != null) {
90 for(Subscribes s: cs.getStreams().getSubscribes()) {
91 if(s.getType().equals("message_router") || s.getType().equals("message router")) {
92 String topic = "topic" + counter;
93 DmaapNode topicNode = new DmaapNode();
94 inps = topicNode.createTopicNode(cs, inps, topic);
95 nodeTemplate.put(topic, topicNode);
96 } else if(s.getType().equals("data_router") || s.getType().equals("data router")) {
97 String feed = "feed" + counter;
98 DmaapNode feedNode = new DmaapNode();
99 inps = feedNode.createFeedNode(cs, inps, feed);
100 nodeTemplate.put(feed, feedNode);
106 bp.setNode_templates(nodeTemplate);