Add external tls info to bpgenerator and component spec schema
[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  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
11  
12       http://www.apache.org/licenses/LICENSE-2.0
13  
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=========================================================
20  
21  */
22
23 package org.onap.blueprintgenerator.models.dmaapbp;
24
25 import java.util.LinkedHashMap;
26 import java.util.TreeMap;
27
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.Imports;
32 import org.onap.blueprintgenerator.models.blueprint.Node;
33 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
34 import org.onap.blueprintgenerator.models.componentspec.Publishes;
35 import org.onap.blueprintgenerator.models.componentspec.Subscribes;
36
37 public class DmaapBlueprint extends Blueprint{
38         public Blueprint createDmaapBlueprint(ComponentSpec cs, String importPath, String override) {
39                 Blueprint bp = new Blueprint();
40
41                 //set tosca definition
42                 bp.setTosca_definitions_version("cloudify_dsl_1_3");
43
44                 //set the description
45                 bp.setDescription(cs.getSelf().getDescription());
46
47                 //create the inpus object that will be added to over the creation of the blueprint
48                 TreeMap<String, LinkedHashMap<String, Object>> inps = new TreeMap<String, LinkedHashMap<String, Object>>();
49
50                 //set the imports
51                 Imports imps = new Imports();
52                 if(importPath.equals("")) {
53                         bp.setImports(imps.createDmaapImports());
54                 }
55                 else {
56                         bp.setImports(imps.createImportsFromFile(importPath));
57                 }
58
59                 //bp.setImports(imps.getImports());
60
61                 //set and create the node templates
62                 TreeMap<String, Node> nodeTemplate = new TreeMap();
63
64                 //create and add the main dmaap node
65                 DmaapNode dmaap = new DmaapNode();
66                 inps = dmaap.createDmaapNode(cs, inps, override);
67                 nodeTemplate.put(cs.getSelf().getName(), dmaap);
68
69                 //create and add the topic/feed nodes
70
71                 //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 = p.getConfig_key() + "_topic";
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 = p.getConfig_key() + "_feed";
81                                         DmaapNode feedNode = new DmaapNode();
82                                         inps = feedNode.createFeedNode(cs, inps, feed);
83                                         nodeTemplate.put(feed, feedNode);
84                                 }
85                         }
86                 }
87                 //go through the stream subscribes
88                 if(cs.getStreams().getSubscribes() != null) {
89                         for(Subscribes s: cs.getStreams().getSubscribes()) {
90                                 if(s.getType().equals("message_router") || s.getType().equals("message router")) {
91                                         String topic = s.getConfig_key() + "_topic";
92                                         DmaapNode topicNode = new DmaapNode();
93                                         inps = topicNode.createTopicNode(cs, inps, topic);
94                                         nodeTemplate.put(topic, topicNode);
95                                 } else if(s.getType().equals("data_router") || s.getType().equals("data router")) {
96                                         String feed = s.getConfig_key() + "_feed";
97                                         DmaapNode feedNode = new DmaapNode();
98                                         inps = feedNode.createFeedNode(cs, inps, feed);
99                                         nodeTemplate.put(feed, feedNode);
100                                 }
101                         }
102                 }
103
104                 //if present in component spec, populate policyNodes information in the blueprint
105                 if(cs.getPolicyInfo() != null){
106                         PolicyNodeBuilder.addPolicyNodesAndInputs(cs, nodeTemplate, inps);
107                 }
108
109                 //if present in component spec, populate pgaasNodes information in the blueprint
110                 if(cs.getAuxilary().getDatabases() != null){
111                         PgaasNodeBuilder.addPgaasNodesAndInputs(cs, nodeTemplate, inps);
112                 }
113
114                 bp.setNode_templates(nodeTemplate);
115
116                 bp.setInputs(inps);
117                 return bp;
118         }
119 }