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.common.blueprint.BlueprintHelper.createBooleanInput;
24 import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.createIntegerInput;
25 import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.isMessageRouterType;
26 import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.isDataRouterType;
27 import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.USE_EXTERNAL_TLS_FIELD;
29 import com.fasterxml.jackson.annotation.JsonIgnore;
30 import com.fasterxml.jackson.annotation.JsonInclude;
31 import com.fasterxml.jackson.annotation.JsonInclude.Include;
32 import java.util.ArrayList;
33 import java.util.LinkedHashMap;
35 import java.util.TreeMap;
38 import org.onap.blueprintgenerator.models.blueprint.tls.ExternalCertificateParametersFactory;
39 import org.onap.blueprintgenerator.models.blueprint.tls.ExternalTlsInfoFactory;
40 import org.onap.blueprintgenerator.models.blueprint.tls.TlsInfo;
41 import org.onap.blueprintgenerator.models.blueprint.tls.impl.ExternalTlsInfo;
42 import org.onap.blueprintgenerator.models.componentspec.Auxilary;
43 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
44 import org.onap.blueprintgenerator.models.componentspec.Publishes;
45 import org.onap.blueprintgenerator.models.componentspec.Subscribes;
46 import org.onap.blueprintgenerator.models.dmaapbp.DmaapStreams;
51 @JsonInclude(value = Include.NON_NULL)
52 public class Properties {
54 private Appconfig application_config;
55 private Auxilary docker_config;
57 private GetInput location_id;
58 private String service_component_type;
59 private TreeMap<String, Object> log_info;
60 private String dns_name;
61 private Object replicas;
63 private GetInput topic_name;
64 private GetInput feed_name;
65 ArrayList<DmaapStreams> streams_publishes;
66 ArrayList<DmaapStreams> streams_subscribes;
67 private TlsInfo tls_info;
68 private ExternalTlsInfo external_cert;
69 private ResourceConfig resource_config;
70 private GetInput always_pull_image;
71 //private boolean useExisting;
73 private ExternalTlsInfoFactory externalCertFactory;
76 ExternalCertificateParametersFactory externalCertificateDataFactory = new ExternalCertificateParametersFactory();
77 externalCertFactory = new ExternalTlsInfoFactory(externalCertificateDataFactory);
80 public TreeMap<String, LinkedHashMap<String, Object>> createOnapProperties(
81 TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) {
82 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
85 GetInput image = new GetInput();
86 image.setBpInputName("image");
88 LinkedHashMap<String, Object> img = new LinkedHashMap<String, Object>();
89 img.put("type", "string");
90 img.put("default", cs.getArtifacts()[0].getUri());
91 retInputs.put("image", img);
94 GetInput location = new GetInput();
95 location.setBpInputName("location_id");
96 this.setLocation_id(location);
97 LinkedHashMap<String, Object> locMap = new LinkedHashMap();
98 locMap.put("type", "string");
99 locMap.put("default", "");
100 retInputs.put("location_id", locMap);
103 this.setLog_info(cs.getAuxilary().getLog_info());
106 GetInput replica = new GetInput();
107 replica.setBpInputName("replicas");
108 this.setReplicas(replica);
109 LinkedHashMap<String, Object> rep = createIntegerInput("number of instances", 1);
110 retInputs.put("replicas", rep);
113 //this.setDns_name(cs.getSelf().getName());
116 //this.setName(cs.getSelf().getName());
118 //set the docker config
119 Auxilary aux = cs.getAuxilary();
120 // if(aux.getPorts() != null) {
121 // retInputs = aux.createPorts(retInputs);
123 this.setDocker_config(aux);
126 Appconfig app = new Appconfig();
127 retInputs = app.createAppconfig(retInputs, cs, override, false);
128 this.setApplication_config(app);
130 // set always_pull_image
131 this.always_pull_image = new GetInput();
132 this.always_pull_image.setBpInputName("always_pull_image");
133 LinkedHashMap<String, Object> inputAlwaysPullImage = createBooleanInput(
134 "Set to true if the image should always be pulled",
136 retInputs.put("always_pull_image", inputAlwaysPullImage);
138 //set service component type
139 String sType = cs.getSelf().getName();
140 sType = sType.replace('.', '-');
141 this.setService_component_type(sType);
143 //set the tls info for internal and external communication
144 TreeMap<String, Object> tls_info = cs.getAuxilary().getTls_info();
145 if (tls_info != null) {
146 addTlsInfo(cs, retInputs);
147 if (tls_info.get(USE_EXTERNAL_TLS_FIELD) != null) {
148 retInputs.putAll(addExternalTlsInfo(cs));
152 //set the reource config
153 ResourceConfig resource = new ResourceConfig();
154 retInputs = resource.createResourceConfig(retInputs, cs.getSelf().getName());
155 this.setResource_config(resource);
160 public TreeMap<String, LinkedHashMap<String, Object>> createDmaapProperties(
161 TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) {
162 TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>();
166 GetInput image = new GetInput();
167 image.setBpInputName("tag_version");
168 this.setImage(image);
169 LinkedHashMap<String, Object> img = new LinkedHashMap<String, Object>();
170 img.put("type", "string");
171 img.put("default", cs.getArtifacts()[0].getUri());
172 retInputs.put("tag_version", img);
174 //set the location id
175 GetInput location = new GetInput();
176 location.setBpInputName("location_id");
177 this.setLocation_id(location);
178 LinkedHashMap<String, Object> locMap = new LinkedHashMap();
179 locMap.put("type", "string");
180 locMap.put("default", "");
181 retInputs.put("location_id", locMap);
184 this.setLog_info(cs.getAuxilary().getLog_info());
186 //set service component type
187 String sType = cs.getSelf().getName();
188 sType = sType.replace('.', '-');
189 this.setService_component_type(sType);
191 //set the tls info for internal and external communication
192 TreeMap<String, Object> tls_info = cs.getAuxilary().getTls_info();
193 if (tls_info != null) {
194 addTlsInfo(cs, retInputs);
195 if (tls_info.get(USE_EXTERNAL_TLS_FIELD) != null) {
196 retInputs.putAll(addExternalTlsInfo(cs));
201 GetInput replica = new GetInput();
202 replica.setBpInputName("replicas");
203 this.setReplicas(replica);
204 LinkedHashMap<String, Object> rep = createIntegerInput( "number of instances", 1);
205 retInputs.put("replicas", rep);
207 // //set the dns name
208 // this.setDns_name(cs.getSelf().getName());
211 // this.setName(cs.getSelf().getName());
213 //set the docker config
214 Auxilary aux = cs.getAuxilary();
215 // if(aux.getPorts() != null) {
216 // retInputs = aux.createPorts(retInputs);
218 this.setDocker_config(aux);
221 Appconfig app = new Appconfig();
222 retInputs = app.createAppconfig(retInputs, cs, override, true);
223 this.setApplication_config(app);
225 //set the stream publishes
226 ArrayList<DmaapStreams> pubStreams = new ArrayList();
227 if (cs.getStreams().getPublishes() != null) {
228 for (Publishes publishes : cs.getStreams().getPublishes()) {
229 if (isMessageRouterType(publishes.getType())) {
230 String topic = publishes.getConfig_key() + "_topic";
231 DmaapStreams mrStreams = new DmaapStreams();
232 retInputs = mrStreams
233 .createStreams(inps, cs, topic, publishes.getType(), publishes.getConfig_key(),
234 publishes.getRoute(), 'p');
235 pubStreams.add(mrStreams);
236 } else if (isDataRouterType(publishes.getType())) {
237 String feed = publishes.getConfig_key() + "_feed";
238 DmaapStreams drStreams = new DmaapStreams();
239 retInputs = drStreams
240 .createStreams(inps, cs, feed, publishes.getType(), publishes.getConfig_key(),
241 publishes.getRoute(), 'p');
242 pubStreams.add(drStreams);
247 //set the stream subscribes
248 ArrayList<DmaapStreams> subStreams = new ArrayList();
249 if (cs.getStreams().getSubscribes() != null) {
250 for (Subscribes subscribes : cs.getStreams().getSubscribes()) {
251 if (isMessageRouterType(subscribes.getType())) {
252 String topic = subscribes.getConfig_key() + "_topic";
253 DmaapStreams mrStreams = new DmaapStreams();
254 retInputs = mrStreams
255 .createStreams(inps, cs, topic, subscribes.getType(), subscribes.getConfig_key(),
256 subscribes.getRoute(), 's');
257 subStreams.add(mrStreams);
258 } else if (isDataRouterType(subscribes.getType())) {
259 String feed = subscribes.getConfig_key() + "_feed";
260 DmaapStreams drStreams = new DmaapStreams();
261 retInputs = drStreams
262 .createStreams(inps, cs, feed, subscribes.getType(), subscribes.getConfig_key(),
263 subscribes.getRoute(), 's');
264 subStreams.add(drStreams);
269 if (pubStreams.size() != 0) {
270 this.setStreams_publishes(pubStreams);
272 if (subStreams.size() != 0) {
273 this.setStreams_subscribes(subStreams);
276 //set the reource config
277 ResourceConfig resource = new ResourceConfig();
278 retInputs = resource.createResourceConfig(retInputs, cs.getSelf().getName());
279 this.setResource_config(resource);
284 private void addTlsInfo(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> retInputs) {
285 TlsInfo tlsInfo = new TlsInfo();
286 tlsInfo.setCertDirectory((String) cs.getAuxilary().getTls_info().get("cert_directory"));
287 GetInput useTLSFlag = new GetInput();
288 useTLSFlag.setBpInputName("use_tls");
289 tlsInfo.setUseTls(useTLSFlag);
290 this.setTls_info(tlsInfo);
291 LinkedHashMap<String, Object> useTlsFlagInput = createBooleanInput(
292 "flag to indicate tls enable/disable",
293 cs.getAuxilary().getTls_info().get("use_tls"));
294 retInputs.put("use_tls", useTlsFlagInput);
297 private Map<String, LinkedHashMap<String, Object>> addExternalTlsInfo(ComponentSpec cs) {
298 this.setExternal_cert(externalCertFactory.createFromComponentSpec(cs));
299 return externalCertFactory.createInputListFromComponentSpec(cs);