6c74347cc42cd4d846aa71f6a43f8910e21f6c5d
[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         private TreeMap<String, Interfaces> interfaces;
56         private Properties properties;
57         private ArrayList<LinkedHashMap<String, String>> relationships;
58
59         public TreeMap<String, LinkedHashMap<String, Object>> createDmaapNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String override) {
60                 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
61
62                 //set the type
63                 this.setType("dcae.nodes.ContainerizedServiceComponentUsingDmaap");
64
65                 //create the interface
66                 Interfaces inter = new Interfaces();
67                 retInputs = inter.createInterface(retInputs, cs);
68                 TreeMap<String, Interfaces> interfaces = new TreeMap<String, Interfaces>();
69                 interfaces.put("cloudify.interfaces.lifecycle", inter);
70                 this.setInterfaces(interfaces);
71
72                 //create and set the relationships
73                 ArrayList<LinkedHashMap<String, String>> rets = new ArrayList();
74
75                 //go through the streams publishes
76                 if(cs.getStreams().getPublishes() != null) {
77                         for(Publishes p: cs.getStreams().getPublishes()) {
78                                 LinkedHashMap<String, String> pubRelations = new LinkedHashMap();
79                                 if(p.getType().equals("message_router") || p.getType().equals("message router")) {
80                                         pubRelations.put("type", "ccsdk.relationships.publish_events");
81                                         pubRelations.put("target", p.getConfig_key() + "_topic");
82                                 } else if(p.getType().equals("data_router") || p.getType().equals("data router")) {
83                                         pubRelations.put("type", "ccsdk.relationships.publish_files");
84                                         pubRelations.put("target", p.getConfig_key() + "_feed");
85                                 }
86                                 rets.add(pubRelations);
87                         }
88                 }
89                 //go through the stream subscribes
90                 if(cs.getStreams().getSubscribes() != null) {
91                         for(Subscribes s: cs.getStreams().getSubscribes()) {
92                                 LinkedHashMap<String, String> subRelations = new LinkedHashMap();
93                                 if(s.getType().equals("message_router") || s.getType().equals("message router")) {
94                                         subRelations.put("type", "ccsdk.relationships.subscribe_to_events");
95                                         subRelations.put("target", s.getConfig_key() + "_topic");
96                                 } else if(s.getType().equals("data_router") || s.getType().equals("data router")) {
97                                         subRelations.put("type", "ccsdk.relationships.subscribe_to_files");
98                                         subRelations.put("target", s.getConfig_key() + "_feed");
99                                 }
100                                 rets.add(subRelations);
101                         }
102                 }
103
104                 //add relationship for policy if exist
105                 if(cs.getPolicyInfo() != null){
106                         ArrayList<LinkedHashMap<String, String>> policyRelationshipsList = PolicyNodeBuilder.getPolicyRelationships(cs);
107                         rets.addAll(policyRelationshipsList);
108                 }
109
110                 //add relationships and env_variables for pgaas dbs if exist
111                 if(cs.getAuxilary().getDatabases() != null){
112                         ArrayList<LinkedHashMap<String, String>> pgaasRelationshipsList = PgaasNodeBuilder.getPgaasNodeRelationships(cs);
113                         rets.addAll(pgaasRelationshipsList);
114                 }
115                 
116                 this.setRelationships(rets);
117
118                 //create and set the properties
119                 Properties props = new Properties();
120                 retInputs = props.createDmaapProperties(retInputs, cs, override);
121                 this.setProperties(props);
122
123                 return retInputs;
124         }
125         public TreeMap<String, LinkedHashMap<String, Object>> createFeedNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String name){
126                 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
127                 LinkedHashMap<String, Object> stringType = new LinkedHashMap();
128                 stringType.put("type", "string");
129
130                 //set the type
131                 this.setType("ccsdk.nodes.Feed");
132
133                 //create and set the properties
134                 Properties props = new Properties();
135                 GetInput topicInput = new GetInput();
136                 topicInput.setGet_input(name + "_name");
137                 props.setFeed_name(topicInput);
138                 //props.setUseExisting(true);
139                 retInputs.put(name + "_name", stringType);
140                 this.setProperties(props);
141
142                 return retInputs;
143         }
144
145         public TreeMap<String, LinkedHashMap<String, Object>> createTopicNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String name){
146                 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
147                 LinkedHashMap<String, Object> stringType = new LinkedHashMap();
148                 stringType.put("type", "string");
149
150                 //set the type
151                 this.setType("ccsdk.nodes.Topic");
152
153                 //create and set the properties
154                 Properties props = new Properties();
155                 GetInput topicInput = new GetInput();
156                 topicInput.setGet_input(name + "_name");
157                 props.setTopic_name(topicInput);
158                 //props.setUseExisting(true);
159                 retInputs.put(name + "_name", stringType);
160                 this.setProperties(props);
161
162                 return retInputs;
163         }
164 }