1 /**============LICENSE_START=======================================================
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
10 http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.blueprintgenerator.models.blueprint;
23 import java.util.ArrayList;
24 import java.util.LinkedHashMap;
25 import java.util.TreeMap;
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;
36 import com.fasterxml.jackson.annotation.JsonInclude;
37 import com.fasterxml.jackson.annotation.JsonInclude.Include;
39 import lombok.Getter; import lombok.Setter;
42 @JsonInclude(value=Include.NON_NULL)
43 public class Properties {
44 private Appconfig application_config;
45 private Auxilary docker_config;
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;
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;
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>>();
66 GetInput image = new GetInput();
67 image.setGet_input("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);
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");
83 GetInput logD = new GetInput();
84 logD.setGet_input("log_directory");
85 TreeMap<String, Object> l = new TreeMap();
86 l.put("log_directory", logD);
88 LinkedHashMap<String, Object> logMap = new LinkedHashMap();
89 logMap.put("type", "string");
90 logMap.put("default", "''");
91 retInputs.put("log_directory", logMap);
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);
104 this.setDns_name(cs.getSelf().getName());
107 this.setName(cs.getSelf().getName());
109 //set the docker config
110 Auxilary aux = cs.getAuxilary();
111 if(aux.getPorts() != null) {
112 retInputs = aux.createPorts(retInputs);
114 this.setDocker_config(aux);
117 Appconfig app = new Appconfig();
118 retInputs = app.createAppconfig(retInputs, cs, override);
119 this.setApplication_config(app);
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);
131 LinkedHashMap<String, Object> certMap = new LinkedHashMap();
132 certMap.put("type", "string");
133 certMap.put("default", "''");
134 retInputs.put("cert_directory", certMap);
136 LinkedHashMap<String, Object> useMap = new LinkedHashMap();
137 useMap.put("type", "boolean");
138 useMap.put("default", false);
139 retInputs.put("use_tls", useMap);
141 //set the reource config
142 ResourceConfig resource = new ResourceConfig();
143 retInputs = resource.createResourceConfig(retInputs, cs.getSelf().getName());
144 this.setResource_config(resource);
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>>();
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);
163 GetInput logD = new GetInput();
164 logD.setGet_input("log_directory");
165 TreeMap<String, Object> l = new TreeMap();
166 l.put("log_directory", logD);
168 LinkedHashMap<String, Object> logMap = new LinkedHashMap();
169 logMap.put("type", "string");
170 logMap.put("default", "''");
171 retInputs.put("log_directory", logMap);
173 //set service component type
174 String sType = cs.getSelf().getName();
175 sType = sType.replace('.', '-');
176 this.setService_component_type(sType);
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);
188 LinkedHashMap<String, Object> certMap = new LinkedHashMap();
189 certMap.put("type", "string");
190 certMap.put("default", "''");
191 retInputs.put("cert_directory", certMap);
193 LinkedHashMap<String, Object> useMap = new LinkedHashMap();
194 useMap.put("type", "boolean");
195 useMap.put("default", false);
196 retInputs.put("use_tls", useMap);
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);
208 // //set the dns name
209 // this.setDns_name(cs.getSelf().getName());
212 // this.setName(cs.getSelf().getName());
214 //set the docker config
215 Auxilary aux = cs.getAuxilary();
216 if(aux.getPorts() != null) {
217 retInputs = aux.createPorts(retInputs);
219 this.setDocker_config(aux);
222 Appconfig app = new Appconfig();
223 retInputs = app.createAppconfig(retInputs, cs, override);
224 this.setApplication_config(app);
226 //set the stream publishes
227 ArrayList<DmaapStreams> pubStreams = new ArrayList();
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);
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);
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);
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);
267 if(pubStreams.size() != 0) {
268 this.setStreams_publishes(pubStreams);
270 if(subStreams.size() != 0) {
271 this.setStreams_subscribes(subStreams);
274 //set the reource config
275 ResourceConfig resource = new ResourceConfig();
276 retInputs = resource.createResourceConfig(retInputs, cs.getSelf().getName());
277 this.setResource_config(resource);