37d7d2d35be097cf1e3ed7fbb5ee2d80578fb914
[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  Copyright (c) 2020 Nokia. All rights reserved.
6  ================================================================================
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10
11       http://www.apache.org/licenses/LICENSE-2.0
12
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18  ============LICENSE_END=========================================================
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
37 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
38 import com.fasterxml.jackson.annotation.JsonInclude;
39 import com.fasterxml.jackson.annotation.JsonInclude.Include;
40
41 import lombok.EqualsAndHashCode;
42 import lombok.Getter;
43 import lombok.NoArgsConstructor;
44 import lombok.Setter;
45
46 @JsonIgnoreProperties(ignoreUnknown = true)
47 @Getter @Setter
48 @EqualsAndHashCode(callSuper=false)
49 @NoArgsConstructor
50 @JsonInclude(value=Include.NON_NULL)
51
52 public class DmaapNode extends Node{
53
54         public TreeMap<String, LinkedHashMap<String, Object>> createDmaapNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String override) {
55                 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
56
57                 //set the type
58                 this.setType("dcae.nodes.ContainerizedServiceComponentUsingDmaap");
59
60                 //create the interface
61                 Interfaces inter = new Interfaces();
62                 retInputs = inter.createInterface(retInputs, cs);
63                 TreeMap<String, Interfaces> interfaces = new TreeMap<String, Interfaces>();
64                 interfaces.put("cloudify.interfaces.lifecycle", inter);
65                 this.setInterfaces(interfaces);
66
67                 //create and set the relationships
68                 ArrayList<LinkedHashMap<String, String>> rets = new ArrayList();
69
70                 //go through the streams publishes
71                 if(cs.getStreams().getPublishes() != null) {
72                         for(Publishes p: cs.getStreams().getPublishes()) {
73                                 LinkedHashMap<String, String> pubRelations = new LinkedHashMap();
74                                 if(p.getType().equals("message_router") || p.getType().equals("message router")) {
75                                         pubRelations.put("type", "ccsdk.relationships.publish_events");
76                                         pubRelations.put("target", p.getConfig_key() + "_topic");
77                                 } else if(p.getType().equals("data_router") || p.getType().equals("data router")) {
78                                         pubRelations.put("type", "ccsdk.relationships.publish_files");
79                                         pubRelations.put("target", p.getConfig_key() + "_feed");
80                                 }
81                                 rets.add(pubRelations);
82                         }
83                 }
84                 //go through the stream subscribes
85                 if(cs.getStreams().getSubscribes() != null) {
86                         for(Subscribes s: cs.getStreams().getSubscribes()) {
87                                 LinkedHashMap<String, String> subRelations = new LinkedHashMap();
88                                 if(s.getType().equals("message_router") || s.getType().equals("message router")) {
89                                         subRelations.put("type", "ccsdk.relationships.subscribe_to_events");
90                                         subRelations.put("target", s.getConfig_key() + "_topic");
91                                 } else if(s.getType().equals("data_router") || s.getType().equals("data router")) {
92                                         subRelations.put("type", "ccsdk.relationships.subscribe_to_files");
93                                         subRelations.put("target", s.getConfig_key() + "_feed");
94                                 }
95                                 rets.add(subRelations);
96                         }
97                 }
98
99                 //add relationship for policy if exist
100                 if(cs.getPolicyInfo() != null){
101                         ArrayList<LinkedHashMap<String, String>> policyRelationshipsList = PolicyNodeBuilder.getPolicyRelationships(cs);
102                         rets.addAll(policyRelationshipsList);
103                 }
104
105                 //add relationships and env_variables for pgaas dbs if exist
106                 if(cs.getAuxilary().getDatabases() != null){
107                         ArrayList<LinkedHashMap<String, String>> pgaasRelationshipsList = PgaasNodeBuilder.getPgaasNodeRelationships(cs);
108                         rets.addAll(pgaasRelationshipsList);
109                 }
110                 
111                 this.setRelationships(rets);
112
113                 //create and set the properties
114                 Properties props = new Properties();
115                 retInputs = props.createDmaapProperties(retInputs, cs, override);
116                 this.setProperties(props);
117
118                 return retInputs;
119         }
120         public TreeMap<String, LinkedHashMap<String, Object>> createFeedNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String name){
121                 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
122                 LinkedHashMap<String, Object> stringType = new LinkedHashMap();
123                 stringType.put("type", "string");
124
125                 //set the type
126                 this.setType("ccsdk.nodes.Feed");
127
128                 //create and set the properties
129                 Properties props = new Properties();
130                 GetInput topicInput = new GetInput();
131                 topicInput.setBpInputName(name + "_name");
132                 props.setFeed_name(topicInput);
133                 //props.setUseExisting(true);
134                 retInputs.put(name + "_name", stringType);
135                 this.setProperties(props);
136
137                 return retInputs;
138         }
139
140         public TreeMap<String, LinkedHashMap<String, Object>> createTopicNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String name){
141                 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
142                 LinkedHashMap<String, Object> stringType = new LinkedHashMap();
143                 stringType.put("type", "string");
144
145                 //set the type
146                 this.setType("ccsdk.nodes.Topic");
147
148                 //create and set the properties
149                 Properties props = new Properties();
150                 GetInput topicInput = new GetInput();
151                 topicInput.setBpInputName(name + "_name");
152                 props.setTopic_name(topicInput);
153                 //props.setUseExisting(true);
154                 retInputs.put(name + "_name", stringType);
155                 this.setProperties(props);
156
157                 return retInputs;
158         }
159 }