382964bf6f676f8283383bfb7e9c6a75cafb4088
[dcaegen2/platform.git] / mod / bpgenerator / src / main / java / org / onap / blueprintgenerator / models / blueprint / Properties.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.blueprint;
22
23 import java.util.ArrayList;
24 import java.util.LinkedHashMap;
25 import java.util.TreeMap;
26
27 import org.onap.blueprintgenerator.models.componentspec.Auxilary;
28 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
29 import org.onap.blueprintgenerator.models.componentspec.Publishes;
30 import org.onap.blueprintgenerator.models.componentspec.Subscribes;
31 import org.onap.blueprintgenerator.models.dmaapbp.DmaapStreams;
32
33 import com.fasterxml.jackson.annotation.JsonInclude;
34 import com.fasterxml.jackson.annotation.JsonInclude.Include;
35
36 import lombok.Getter; import lombok.Setter;
37
38 @Getter @Setter
39 @JsonInclude(value=Include.NON_NULL)
40 public class Properties {
41         private Appconfig application_config;
42         private Auxilary docker_config;
43         private Object image;
44         private GetInput location_id;
45         private String service_component_type;
46         private TreeMap<String, Object> log_info;
47         private String dns_name;
48         private Object replicas;
49         private String name;
50         private GetInput topic_name;
51         private GetInput feed_name;
52         ArrayList<DmaapStreams> streams_publishes;
53         ArrayList<DmaapStreams> streams_subscribes;
54         private TlsInfo tls_info;
55         private ResourceConfig resource_config;
56         private GetInput always_pull_image;
57         //private boolean useExisting;
58
59         public TreeMap<String, LinkedHashMap<String, Object>> createOnapProperties(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) {
60                 TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>();
61                 retInputs = inps;
62
63                 //set the image
64                 GetInput image = new GetInput();
65                 image.setGet_input("image");
66                 this.setImage(image);
67                 LinkedHashMap<String, Object> img = new LinkedHashMap<String, Object>();
68                 img.put("type", "string");
69                 img.put("default", cs.getArtifacts()[0].getUri());
70                 retInputs.put("image", img);
71
72                 //set the location id
73                 GetInput location = new GetInput();
74                 location.setGet_input("location_id");
75                 this.setLocation_id(location);
76                 LinkedHashMap<String, Object> locMap = new LinkedHashMap();
77                 locMap.put("type", "string");
78                 locMap.put("default", "");
79                 retInputs.put("location_id", locMap);
80
81                 //set the log info
82                 this.setLog_info(cs.getAuxilary().getLog_info());
83
84                 //set the replicas
85                 GetInput replica = new GetInput();
86                 replica.setGet_input("replicas");
87                 this.setReplicas(replica);
88                 LinkedHashMap<String, Object> rep = new LinkedHashMap<String, Object>();
89                 rep.put("type", "integer");
90                 rep.put("description", "number of instances");
91                 rep.put("default", 1);
92                 retInputs.put("replicas", rep);
93
94                 //set the dns name
95                 //this.setDns_name(cs.getSelf().getName());
96
97                 //set the name
98                 //this.setName(cs.getSelf().getName());
99
100                 //set the docker config
101                 Auxilary aux = cs.getAuxilary();
102 //              if(aux.getPorts() != null) {
103 //                      retInputs = aux.createPorts(retInputs);
104 //              }
105                 this.setDocker_config(aux);
106
107                 //set the app config
108                 Appconfig app = new Appconfig();
109                 retInputs = app.createAppconfig(retInputs, cs, override, false);
110                 this.setApplication_config(app);
111
112                 // set always_pull_image
113                 this.always_pull_image = new GetInput();
114                 this.always_pull_image.setGet_input("always_pull_image");
115                 LinkedHashMap<String, Object> inputAlwaysPullImage = new LinkedHashMap<String, Object>();
116                 inputAlwaysPullImage.put("type", "boolean");
117                 inputAlwaysPullImage.put("description", "Set to true if the image should always be pulled");
118                 inputAlwaysPullImage.put("default", true);
119                 retInputs.put("always_pull_image", inputAlwaysPullImage);
120
121
122                 //set service component type
123                 String sType = cs.getSelf().getName();
124                 sType = sType.replace('.', '-');
125                 this.setService_component_type(sType);
126                 
127                 //set the tls info
128                 if(cs.getAuxilary().getTls_info() != null){
129                         addTlsInfo(cs,retInputs);
130                 }
131
132                 //set the reource config
133                 ResourceConfig resource = new ResourceConfig();
134                 retInputs = resource.createResourceConfig(retInputs, cs.getSelf().getName());
135                 this.setResource_config(resource);
136
137                 return retInputs;
138         }
139
140         public TreeMap<String, LinkedHashMap<String, Object>> createDmaapProperties(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) {
141                 TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>();
142                 retInputs = inps;
143
144                 //set the image
145                 GetInput image = new GetInput();
146                 image.setGet_input("tag_version");
147                 this.setImage(image);
148                 LinkedHashMap<String, Object> img = new LinkedHashMap<String, Object>();
149                 img.put("type", "string");
150                 img.put("default", cs.getArtifacts()[0].getUri());
151                 retInputs.put("tag_version", img);
152
153                 
154                 //set the location id
155                 GetInput location = new GetInput();
156                 location.setGet_input("location_id");
157                 this.setLocation_id(location);
158                 LinkedHashMap<String, Object> locMap = new LinkedHashMap();
159                 locMap.put("type", "string");
160                 locMap.put("default", "");
161                 retInputs.put("location_id", locMap);
162                 
163                 //set the log info
164                 this.setLog_info(cs.getAuxilary().getLog_info());
165
166                 //set service component type
167                 String sType = cs.getSelf().getName();
168                 sType = sType.replace('.', '-');
169                 this.setService_component_type(sType);
170
171                 //set the tls info
172                 if(cs.getAuxilary().getTls_info() != null){
173                         addTlsInfo(cs,retInputs);
174                 }
175
176                 //set the replicas
177                 GetInput replica = new GetInput();
178                 replica.setGet_input("replicas");
179                 this.setReplicas(replica);
180                 LinkedHashMap<String, Object> rep = new LinkedHashMap<String, Object>();
181                 rep.put("type", "integer");
182                 rep.put("description", "number of instances");
183                 rep.put("default", 1);
184                 retInputs.put("replicas", rep);
185
186 //              //set the dns name
187 //              this.setDns_name(cs.getSelf().getName());
188
189 //              //set the name
190 //              this.setName(cs.getSelf().getName());
191
192                 //set the docker config
193                 Auxilary aux = cs.getAuxilary();
194 //              if(aux.getPorts() != null) {
195 //                      retInputs = aux.createPorts(retInputs);
196 //              }
197                 this.setDocker_config(aux);
198
199                 //set the appconfig
200                 Appconfig app = new Appconfig();
201                 retInputs = app.createAppconfig(retInputs, cs, override, true);
202                 this.setApplication_config(app);
203
204                 //set the stream publishes
205                 ArrayList<DmaapStreams> pubStreams = new ArrayList();
206                 if(cs.getStreams().getPublishes() != null) {
207                         for(Publishes p: cs.getStreams().getPublishes()) {
208                                 if(p.getType().equals("message_router") || p.getType().equals("message router")) {
209                                         String topic = p.getConfig_key() + "_topic";
210                                         DmaapStreams mrStreams = new DmaapStreams();
211                                         retInputs = mrStreams.createStreams(inps, cs, topic, p.getType(), p.getConfig_key(), p.getRoute(), 'p');
212                                         pubStreams.add(mrStreams);
213                                 }
214                                 else if(p.getType().equals("data_router") || p.getType().equals("data router")){
215                                         String feed = p.getConfig_key() + "_feed";
216                                         DmaapStreams drStreams = new DmaapStreams();
217                                         retInputs = drStreams.createStreams(inps, cs, feed, p.getType(), p.getConfig_key(), p.getRoute(), 'p');
218                                         pubStreams.add(drStreams);
219                                 }
220                         }
221                 }
222
223                 //set the stream subscribes
224                 ArrayList<DmaapStreams> subStreams = new ArrayList();
225                 if(cs.getStreams().getSubscribes() != null) {
226                         for(Subscribes s: cs.getStreams().getSubscribes()) {
227                                 if(s.getType().equals("message_router") || s.getType().equals("message router")) {
228                                         String topic = s.getConfig_key() + "_topic";
229                                         DmaapStreams mrStreams = new DmaapStreams();
230                                         retInputs = mrStreams.createStreams(inps, cs, topic, s.getType(), s.getConfig_key(), s.getRoute(), 's');
231                                         subStreams.add(mrStreams);
232                                 }
233                                 else if(s.getType().equals("data_router") || s.getType().equals("data router")){
234                                         String feed = s.getConfig_key() + "_feed";
235                                         DmaapStreams drStreams = new DmaapStreams();
236                                         retInputs = drStreams.createStreams(inps, cs, feed, s.getType(), s.getConfig_key(), s.getRoute(), 's');
237                                         subStreams.add(drStreams);
238                                 }
239                         }
240                 }
241
242                 if(pubStreams.size() != 0) {
243                         this.setStreams_publishes(pubStreams);
244                 }
245                 if(subStreams.size() != 0) {
246                         this.setStreams_subscribes(subStreams);
247                 }
248
249                 //set the reource config
250                 ResourceConfig resource = new ResourceConfig();
251                 retInputs = resource.createResourceConfig(retInputs, cs.getSelf().getName());
252                 this.setResource_config(resource);
253
254
255                 return retInputs;
256         }
257
258         private void addTlsInfo(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> retInputs) {
259                 TlsInfo tlsInfo = new TlsInfo();
260                 tlsInfo.setCertDirectory((String) cs.getAuxilary().getTls_info().get("cert_directory"));
261                 GetInput useTLSFlag = new GetInput();
262                 useTLSFlag.setGet_input("use_tls");
263                 tlsInfo.setUseTls(useTLSFlag);
264                 this.setTls_info(tlsInfo);
265                 LinkedHashMap<String, Object> useTlsFlagInput = new LinkedHashMap<String, Object>();
266                 useTlsFlagInput.put("type", "boolean");
267                 useTlsFlagInput.put("description", "flag to indicate tls enable/disable");
268                 useTlsFlagInput.put("default", cs.getAuxilary().getTls_info().get("use_tls"));
269                 retInputs.put("use_tls", useTlsFlagInput);
270         }
271 }