1 /*============LICENSE_START=======================================================
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
11 http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.blueprintgenerator.models.blueprint;
23 import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.USE_EXTERNAL_TLS_FIELD;
25 import com.fasterxml.jackson.annotation.JsonIgnore;
26 import com.fasterxml.jackson.annotation.JsonInclude;
27 import com.fasterxml.jackson.annotation.JsonInclude.Include;
28 import java.util.ArrayList;
29 import java.util.LinkedHashMap;
31 import java.util.TreeMap;
34 import org.onap.blueprintgenerator.common.blueprint.BlueprintHelper;
35 import org.onap.blueprintgenerator.models.blueprint.tls.ExternalCertificateParametersFactory;
36 import org.onap.blueprintgenerator.models.blueprint.tls.ExternalTlsInfoFactory;
37 import org.onap.blueprintgenerator.models.blueprint.tls.TlsInfo;
38 import org.onap.blueprintgenerator.models.blueprint.tls.impl.ExternalTlsInfo;
39 import org.onap.blueprintgenerator.models.componentspec.Auxilary;
40 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
41 import org.onap.blueprintgenerator.models.componentspec.Publishes;
42 import org.onap.blueprintgenerator.models.componentspec.Subscribes;
43 import org.onap.blueprintgenerator.models.dmaapbp.DmaapStreams;
47 @JsonInclude(value = Include.NON_NULL)
48 public class Properties {
50 private Appconfig application_config;
51 private Auxilary docker_config;
53 private GetInput location_id;
54 private String service_component_type;
55 private TreeMap<String, Object> log_info;
56 private String dns_name;
57 private Object replicas;
59 private GetInput topic_name;
60 private GetInput feed_name;
61 ArrayList<DmaapStreams> streams_publishes;
62 ArrayList<DmaapStreams> streams_subscribes;
63 private TlsInfo tls_info;
64 private ExternalTlsInfo external_cert;
65 private ResourceConfig resource_config;
66 private GetInput always_pull_image;
67 //private boolean useExisting;
69 private ExternalTlsInfoFactory externalCertFactory;
72 ExternalCertificateParametersFactory externalCertificateDataFactory = new ExternalCertificateParametersFactory();
73 externalCertFactory = new ExternalTlsInfoFactory(externalCertificateDataFactory);
76 public TreeMap<String, LinkedHashMap<String, Object>> createOnapProperties(
77 TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) {
78 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
81 GetInput image = new GetInput();
82 image.setBpInputName("image");
84 LinkedHashMap<String, Object> img = new LinkedHashMap<String, Object>();
85 img.put("type", "string");
86 img.put("default", cs.getArtifacts()[0].getUri());
87 retInputs.put("image", img);
90 GetInput location = new GetInput();
91 location.setBpInputName("location_id");
92 this.setLocation_id(location);
93 LinkedHashMap<String, Object> locMap = new LinkedHashMap();
94 locMap.put("type", "string");
95 locMap.put("default", "");
96 retInputs.put("location_id", locMap);
99 this.setLog_info(cs.getAuxilary().getLog_info());
102 GetInput replica = new GetInput();
103 replica.setBpInputName("replicas");
104 this.setReplicas(replica);
105 LinkedHashMap<String, Object> rep = BlueprintHelper.createInputValue("integer", "number of instances", 1);
106 retInputs.put("replicas", rep);
109 //this.setDns_name(cs.getSelf().getName());
112 //this.setName(cs.getSelf().getName());
114 //set the docker config
115 Auxilary aux = cs.getAuxilary();
116 // if(aux.getPorts() != null) {
117 // retInputs = aux.createPorts(retInputs);
119 this.setDocker_config(aux);
122 Appconfig app = new Appconfig();
123 retInputs = app.createAppconfig(retInputs, cs, override, false);
124 this.setApplication_config(app);
126 // set always_pull_image
127 this.always_pull_image = new GetInput();
128 this.always_pull_image.setBpInputName("always_pull_image");
129 LinkedHashMap<String, Object> inputAlwaysPullImage = BlueprintHelper.createInputValue("boolean",
130 "Set to true if the image should always be pulled",
132 retInputs.put("always_pull_image", inputAlwaysPullImage);
134 //set service component type
135 String sType = cs.getSelf().getName();
136 sType = sType.replace('.', '-');
137 this.setService_component_type(sType);
139 //set the tls info for internal and external communication
140 TreeMap<String, Object> tls_info = cs.getAuxilary().getTls_info();
141 if (tls_info != null) {
142 addTlsInfo(cs, retInputs);
143 if (tls_info.get(USE_EXTERNAL_TLS_FIELD) != null) {
144 retInputs.putAll(addExternalTlsInfo(cs));
148 //set the reource config
149 ResourceConfig resource = new ResourceConfig();
150 retInputs = resource.createResourceConfig(retInputs, cs.getSelf().getName());
151 this.setResource_config(resource);
156 public TreeMap<String, LinkedHashMap<String, Object>> createDmaapProperties(
157 TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) {
158 TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>();
162 GetInput image = new GetInput();
163 image.setBpInputName("tag_version");
164 this.setImage(image);
165 LinkedHashMap<String, Object> img = new LinkedHashMap<String, Object>();
166 img.put("type", "string");
167 img.put("default", cs.getArtifacts()[0].getUri());
168 retInputs.put("tag_version", img);
170 //set the location id
171 GetInput location = new GetInput();
172 location.setBpInputName("location_id");
173 this.setLocation_id(location);
174 LinkedHashMap<String, Object> locMap = new LinkedHashMap();
175 locMap.put("type", "string");
176 locMap.put("default", "");
177 retInputs.put("location_id", locMap);
180 this.setLog_info(cs.getAuxilary().getLog_info());
182 //set service component type
183 String sType = cs.getSelf().getName();
184 sType = sType.replace('.', '-');
185 this.setService_component_type(sType);
187 //set the tls info for internal and external communication
188 TreeMap<String, Object> tls_info = cs.getAuxilary().getTls_info();
189 if (tls_info != null) {
190 addTlsInfo(cs, retInputs);
191 if (tls_info.get(USE_EXTERNAL_TLS_FIELD) != null) {
192 retInputs.putAll(addExternalTlsInfo(cs));
197 GetInput replica = new GetInput();
198 replica.setBpInputName("replicas");
199 this.setReplicas(replica);
200 LinkedHashMap<String, Object> rep = BlueprintHelper.createInputValue("integer", "number of instances", 1);
201 retInputs.put("replicas", rep);
203 // //set the dns name
204 // this.setDns_name(cs.getSelf().getName());
207 // this.setName(cs.getSelf().getName());
209 //set the docker config
210 Auxilary aux = cs.getAuxilary();
211 // if(aux.getPorts() != null) {
212 // retInputs = aux.createPorts(retInputs);
214 this.setDocker_config(aux);
217 Appconfig app = new Appconfig();
218 retInputs = app.createAppconfig(retInputs, cs, override, true);
219 this.setApplication_config(app);
221 //set the stream publishes
222 ArrayList<DmaapStreams> pubStreams = new ArrayList();
223 if (cs.getStreams().getPublishes() != null) {
224 for (Publishes p : cs.getStreams().getPublishes()) {
225 if (p.getType().equals("message_router") || p.getType().equals("message router")) {
226 String topic = p.getConfig_key() + "_topic";
227 DmaapStreams mrStreams = new DmaapStreams();
228 retInputs = mrStreams
229 .createStreams(inps, cs, topic, p.getType(), p.getConfig_key(), p.getRoute(), 'p');
230 pubStreams.add(mrStreams);
231 } else if (p.getType().equals("data_router") || p.getType().equals("data router")) {
232 String feed = p.getConfig_key() + "_feed";
233 DmaapStreams drStreams = new DmaapStreams();
234 retInputs = drStreams
235 .createStreams(inps, cs, feed, p.getType(), p.getConfig_key(), p.getRoute(), 'p');
236 pubStreams.add(drStreams);
241 //set the stream subscribes
242 ArrayList<DmaapStreams> subStreams = new ArrayList();
243 if (cs.getStreams().getSubscribes() != null) {
244 for (Subscribes s : cs.getStreams().getSubscribes()) {
245 if (s.getType().equals("message_router") || s.getType().equals("message router")) {
246 String topic = s.getConfig_key() + "_topic";
247 DmaapStreams mrStreams = new DmaapStreams();
248 retInputs = mrStreams
249 .createStreams(inps, cs, topic, s.getType(), s.getConfig_key(), s.getRoute(), 's');
250 subStreams.add(mrStreams);
251 } else if (s.getType().equals("data_router") || s.getType().equals("data router")) {
252 String feed = s.getConfig_key() + "_feed";
253 DmaapStreams drStreams = new DmaapStreams();
254 retInputs = drStreams
255 .createStreams(inps, cs, feed, s.getType(), s.getConfig_key(), s.getRoute(), 's');
256 subStreams.add(drStreams);
261 if (pubStreams.size() != 0) {
262 this.setStreams_publishes(pubStreams);
264 if (subStreams.size() != 0) {
265 this.setStreams_subscribes(subStreams);
268 //set the reource config
269 ResourceConfig resource = new ResourceConfig();
270 retInputs = resource.createResourceConfig(retInputs, cs.getSelf().getName());
271 this.setResource_config(resource);
276 private void addTlsInfo(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> retInputs) {
277 TlsInfo tlsInfo = new TlsInfo();
278 tlsInfo.setCertDirectory((String) cs.getAuxilary().getTls_info().get("cert_directory"));
279 GetInput useTLSFlag = new GetInput();
280 useTLSFlag.setBpInputName("use_tls");
281 tlsInfo.setUseTls(useTLSFlag);
282 this.setTls_info(tlsInfo);
283 LinkedHashMap<String, Object> useTlsFlagInput = BlueprintHelper.createInputValue("boolean",
284 "flag to indicate tls enable/disable",
285 cs.getAuxilary().getTls_info().get("use_tls"));
286 retInputs.put("use_tls", useTlsFlagInput);
289 private Map<String, LinkedHashMap<String, Object>> addExternalTlsInfo(ComponentSpec cs) {
290 this.setExternal_cert(externalCertFactory.createFromComponentSpec(cs));
291 return externalCertFactory.createInputListFromComponentSpec(cs);