bp-gen code clone from cli repo
[dcaegen2/platform.git] / mod / bpgenerator / src / main / java / org / onap / blueprintgenerator / models / dmaapbp / DmaapBlueprint.java
1 /**============LICENSE_START=======================================================
2  org.onap.dcae
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
9  
10       http://www.apache.org/licenses/LICENSE-2.0
11  
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=========================================================
18  
19  */
20
21 package org.onap.blueprintgenerator.models.dmaapbp;
22
23 import java.util.ArrayList;
24 import java.util.LinkedHashMap;
25 import java.util.TreeMap;
26
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;
35
36 public class DmaapBlueprint extends Blueprint{
37         public Blueprint createDmaapBlueprint(ComponentSpec cs, String importPath, String override) {
38                 Blueprint bp = new Blueprint();
39
40                 //set tosca definition
41                 bp.setTosca_definitions_version("cloudify_dsl_1_3");
42
43                 //set the description
44                 bp.setDescription(cs.getSelf().getDescription());
45
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>>();
48
49                 //set the imports
50                 Imports imps = new Imports();
51                 if(importPath.equals("")) {
52                         bp.setImports(imps.createDmaapImports());
53                 }
54                 else {
55                         bp.setImports(imps.createImportsFromFile(importPath));
56                 }
57
58                 //bp.setImports(imps.getImports());
59
60                 //set and create the node templates
61                 TreeMap<String, Node> nodeTemplate = new TreeMap();
62
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);
67
68                 //create and add the topic/feed nodes
69
70                 //go through the streams publishes
71                 int counter = 0;
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);
84                                 }
85                                 counter++;
86                         }
87                 }
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);
101                                 }
102                                 counter++;
103                         }
104                 }
105
106                 bp.setNode_templates(nodeTemplate);
107
108                 bp.setInputs(inps);
109                 return bp;
110         }
111 }