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