Add external tls info to bpgenerator and component spec schema
[dcaegen2/platform.git] / mod / bpgenerator / src / main / java / org / onap / blueprintgenerator / models / dmaapbp / DmaapNode.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.core.PgaasNodeBuilder;
28 import org.onap.blueprintgenerator.core.PolicyNodeBuilder;
29 import org.onap.blueprintgenerator.models.blueprint.GetInput;
30 import org.onap.blueprintgenerator.models.blueprint.Interfaces;
31 import org.onap.blueprintgenerator.models.blueprint.Node;
32 import org.onap.blueprintgenerator.models.blueprint.Properties;
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 import org.onap.blueprintgenerator.models.onapbp.OnapNode;
37
38 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
39 import com.fasterxml.jackson.annotation.JsonInclude;
40 import com.fasterxml.jackson.annotation.JsonInclude.Include;
41
42 import lombok.EqualsAndHashCode;
43 import lombok.Getter;
44 import lombok.NoArgsConstructor;
45 import lombok.Setter;
46
47 @JsonIgnoreProperties(ignoreUnknown = true)
48 @Getter @Setter
49 @EqualsAndHashCode(callSuper=false)
50 @NoArgsConstructor
51 @JsonInclude(value=Include.NON_NULL)
52
53 public class DmaapNode extends Node{
54
55         public TreeMap<String, LinkedHashMap<String, Object>> createDmaapNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String override) {
56                 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
57
58                 //set the type
59                 this.setType("dcae.nodes.ContainerizedServiceComponentUsingDmaap");
60
61                 //create the interface
62                 Interfaces inter = new Interfaces();
63                 retInputs = inter.createInterface(retInputs, cs);
64                 TreeMap<String, Interfaces> interfaces = new TreeMap<String, Interfaces>();
65                 interfaces.put("cloudify.interfaces.lifecycle", inter);
66                 this.setInterfaces(interfaces);
67
68                 //create and set the relationships
69                 ArrayList<LinkedHashMap<String, String>> rets = new ArrayList();
70
71                 //go through the streams publishes
72                 if(cs.getStreams().getPublishes() != null) {
73                         for(Publishes p: cs.getStreams().getPublishes()) {
74                                 LinkedHashMap<String, String> pubRelations = new LinkedHashMap();
75                                 if(p.getType().equals("message_router") || p.getType().equals("message router")) {
76                                         pubRelations.put("type", "ccsdk.relationships.publish_events");
77                                         pubRelations.put("target", p.getConfig_key() + "_topic");
78                                 } else if(p.getType().equals("data_router") || p.getType().equals("data router")) {
79                                         pubRelations.put("type", "ccsdk.relationships.publish_files");
80                                         pubRelations.put("target", p.getConfig_key() + "_feed");
81                                 }
82                                 rets.add(pubRelations);
83                         }
84                 }
85                 //go through the stream subscribes
86                 if(cs.getStreams().getSubscribes() != null) {
87                         for(Subscribes s: cs.getStreams().getSubscribes()) {
88                                 LinkedHashMap<String, String> subRelations = new LinkedHashMap();
89                                 if(s.getType().equals("message_router") || s.getType().equals("message router")) {
90                                         subRelations.put("type", "ccsdk.relationships.subscribe_to_events");
91                                         subRelations.put("target", s.getConfig_key() + "_topic");
92                                 } else if(s.getType().equals("data_router") || s.getType().equals("data router")) {
93                                         subRelations.put("type", "ccsdk.relationships.subscribe_to_files");
94                                         subRelations.put("target", s.getConfig_key() + "_feed");
95                                 }
96                                 rets.add(subRelations);
97                         }
98                 }
99
100                 //add relationship for policy if exist
101                 if(cs.getPolicyInfo() != null){
102                         ArrayList<LinkedHashMap<String, String>> policyRelationshipsList = PolicyNodeBuilder.getPolicyRelationships(cs);
103                         rets.addAll(policyRelationshipsList);
104                 }
105
106                 //add relationships and env_variables for pgaas dbs if exist
107                 if(cs.getAuxilary().getDatabases() != null){
108                         ArrayList<LinkedHashMap<String, String>> pgaasRelationshipsList = PgaasNodeBuilder.getPgaasNodeRelationships(cs);
109                         rets.addAll(pgaasRelationshipsList);
110                 }
111                 
112                 this.setRelationships(rets);
113
114                 //create and set the properties
115                 Properties props = new Properties();
116                 retInputs = props.createDmaapProperties(retInputs, cs, override);
117                 this.setProperties(props);
118
119                 return retInputs;
120         }
121         public TreeMap<String, LinkedHashMap<String, Object>> createFeedNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String name){
122                 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
123                 LinkedHashMap<String, Object> stringType = new LinkedHashMap();
124                 stringType.put("type", "string");
125
126                 //set the type
127                 this.setType("ccsdk.nodes.Feed");
128
129                 //create and set the properties
130                 Properties props = new Properties();
131                 GetInput topicInput = new GetInput();
132                 topicInput.setGet_input(name + "_name");
133                 props.setFeed_name(topicInput);
134                 //props.setUseExisting(true);
135                 retInputs.put(name + "_name", stringType);
136                 this.setProperties(props);
137
138                 return retInputs;
139         }
140
141         public TreeMap<String, LinkedHashMap<String, Object>> createTopicNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String name){
142                 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
143                 LinkedHashMap<String, Object> stringType = new LinkedHashMap();
144                 stringType.put("type", "string");
145
146                 //set the type
147                 this.setType("ccsdk.nodes.Topic");
148
149                 //create and set the properties
150                 Properties props = new Properties();
151                 GetInput topicInput = new GetInput();
152                 topicInput.setGet_input(name + "_name");
153                 props.setTopic_name(topicInput);
154                 //props.setUseExisting(true);
155                 retInputs.put(name + "_name", stringType);
156                 this.setProperties(props);
157
158                 return retInputs;
159         }
160 }