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.JsonInclude;
26 import com.fasterxml.jackson.annotation.JsonInclude.Include;
27 import java.util.ArrayList;
28 import java.util.LinkedHashMap;
30 import java.util.TreeMap;
33 import org.onap.blueprintgenerator.common.blueprint.BlueprintHelper;
34 import org.onap.blueprintgenerator.models.blueprint.tls.ExternalCertificateParametersFactory;
35 import org.onap.blueprintgenerator.models.blueprint.tls.ExternalTlsInfoFactory;
36 import org.onap.blueprintgenerator.models.blueprint.tls.TlsInfo;
37 import org.onap.blueprintgenerator.models.blueprint.tls.impl.ExternalTlsInfo;
38 import org.onap.blueprintgenerator.models.componentspec.Auxilary;
39 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
40 import org.onap.blueprintgenerator.models.componentspec.Publishes;
41 import org.onap.blueprintgenerator.models.componentspec.Subscribes;
42 import org.onap.blueprintgenerator.models.dmaapbp.DmaapStreams;
46 @JsonInclude(value = Include.NON_NULL)
47 public class Properties {
49 private Appconfig application_config;
50 private Auxilary docker_config;
52 private GetInput location_id;
53 private String service_component_type;
54 private TreeMap<String, Object> log_info;
55 private String dns_name;
56 private Object replicas;
58 private GetInput topic_name;
59 private GetInput feed_name;
60 ArrayList<DmaapStreams> streams_publishes;
61 ArrayList<DmaapStreams> streams_subscribes;
62 private TlsInfo tls_info;
63 private ExternalTlsInfo external_cert;
64 private ResourceConfig resource_config;
65 private GetInput always_pull_image;
66 //private boolean useExisting;
67 private ExternalTlsInfoFactory externalCertFactory;
70 ExternalCertificateParametersFactory externalCertificateDataFactory = new ExternalCertificateParametersFactory();
71 externalCertFactory = new ExternalTlsInfoFactory(externalCertificateDataFactory);
74 public TreeMap<String, LinkedHashMap<String, Object>> createOnapProperties(
75 TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) {
76 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
79 GetInput image = new GetInput();
80 image.setBpInputName("image");
82 LinkedHashMap<String, Object> img = new LinkedHashMap<String, Object>();
83 img.put("type", "string");
84 img.put("default", cs.getArtifacts()[0].getUri());
85 retInputs.put("image", img);
88 GetInput location = new GetInput();
89 location.setBpInputName("location_id");
90 this.setLocation_id(location);
91 LinkedHashMap<String, Object> locMap = new LinkedHashMap();
92 locMap.put("type", "string");
93 locMap.put("default", "");
94 retInputs.put("location_id", locMap);
97 this.setLog_info(cs.getAuxilary().getLog_info());
100 GetInput replica = new GetInput();
101 replica.setBpInputName("replicas");
102 this.setReplicas(replica);
103 LinkedHashMap<String, Object> rep = BlueprintHelper.createInputValue("integer", "number of instances", 1);
104 retInputs.put("replicas", rep);
107 //this.setDns_name(cs.getSelf().getName());
110 //this.setName(cs.getSelf().getName());
112 //set the docker config
113 Auxilary aux = cs.getAuxilary();
114 // if(aux.getPorts() != null) {
115 // retInputs = aux.createPorts(retInputs);
117 this.setDocker_config(aux);
120 Appconfig app = new Appconfig();
121 retInputs = app.createAppconfig(retInputs, cs, override, false);
122 this.setApplication_config(app);
124 // set always_pull_image
125 this.always_pull_image = new GetInput();
126 this.always_pull_image.setBpInputName("always_pull_image");
127 LinkedHashMap<String, Object> inputAlwaysPullImage = BlueprintHelper.createInputValue("boolean",
128 "Set to true if the image should always be pulled",
130 retInputs.put("always_pull_image", inputAlwaysPullImage);
132 //set service component type
133 String sType = cs.getSelf().getName();
134 sType = sType.replace('.', '-');
135 this.setService_component_type(sType);
137 //set the tls info for internal and external communication
138 TreeMap<String, Object> tls_info = cs.getAuxilary().getTls_info();
139 if (tls_info != null) {
140 addTlsInfo(cs, retInputs);
141 if (tls_info.get(USE_EXTERNAL_TLS_FIELD) != null) {
142 retInputs.putAll(addExternalTlsInfo(cs));
146 //set the reource config
147 ResourceConfig resource = new ResourceConfig();
148 retInputs = resource.createResourceConfig(retInputs, cs.getSelf().getName());
149 this.setResource_config(resource);
154 public TreeMap<String, LinkedHashMap<String, Object>> createDmaapProperties(
155 TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) {
156 TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>();
160 GetInput image = new GetInput();
161 image.setBpInputName("tag_version");
162 this.setImage(image);
163 LinkedHashMap<String, Object> img = new LinkedHashMap<String, Object>();
164 img.put("type", "string");
165 img.put("default", cs.getArtifacts()[0].getUri());
166 retInputs.put("tag_version", img);
168 //set the location id
169 GetInput location = new GetInput();
170 location.setBpInputName("location_id");
171 this.setLocation_id(location);
172 LinkedHashMap<String, Object> locMap = new LinkedHashMap();
173 locMap.put("type", "string");
174 locMap.put("default", "");
175 retInputs.put("location_id", locMap);
178 this.setLog_info(cs.getAuxilary().getLog_info());
180 //set service component type
181 String sType = cs.getSelf().getName();
182 sType = sType.replace('.', '-');
183 this.setService_component_type(sType);
185 //set the tls info for internal and external communication
186 TreeMap<String, Object> tls_info = cs.getAuxilary().getTls_info();
187 if (tls_info != null) {
188 addTlsInfo(cs, retInputs);
189 if (tls_info.get(USE_EXTERNAL_TLS_FIELD) != null) {
190 retInputs.putAll(addExternalTlsInfo(cs));
195 GetInput replica = new GetInput();
196 replica.setBpInputName("replicas");
197 this.setReplicas(replica);
198 LinkedHashMap<String, Object> rep = BlueprintHelper.createInputValue("integer", "number of instances", 1);
199 retInputs.put("replicas", rep);
201 // //set the dns name
202 // this.setDns_name(cs.getSelf().getName());
205 // this.setName(cs.getSelf().getName());
207 //set the docker config
208 Auxilary aux = cs.getAuxilary();
209 // if(aux.getPorts() != null) {
210 // retInputs = aux.createPorts(retInputs);
212 this.setDocker_config(aux);
215 Appconfig app = new Appconfig();
216 retInputs = app.createAppconfig(retInputs, cs, override, true);
217 this.setApplication_config(app);
219 //set the stream publishes
220 ArrayList<DmaapStreams> pubStreams = new ArrayList();
221 if (cs.getStreams().getPublishes() != null) {
222 for (Publishes p : cs.getStreams().getPublishes()) {
223 if (p.getType().equals("message_router") || p.getType().equals("message router")) {
224 String topic = p.getConfig_key() + "_topic";
225 DmaapStreams mrStreams = new DmaapStreams();
226 retInputs = mrStreams
227 .createStreams(inps, cs, topic, p.getType(), p.getConfig_key(), p.getRoute(), 'p');
228 pubStreams.add(mrStreams);
229 } else if (p.getType().equals("data_router") || p.getType().equals("data router")) {
230 String feed = p.getConfig_key() + "_feed";
231 DmaapStreams drStreams = new DmaapStreams();
232 retInputs = drStreams
233 .createStreams(inps, cs, feed, p.getType(), p.getConfig_key(), p.getRoute(), 'p');
234 pubStreams.add(drStreams);
239 //set the stream subscribes
240 ArrayList<DmaapStreams> subStreams = new ArrayList();
241 if (cs.getStreams().getSubscribes() != null) {
242 for (Subscribes s : cs.getStreams().getSubscribes()) {
243 if (s.getType().equals("message_router") || s.getType().equals("message router")) {
244 String topic = s.getConfig_key() + "_topic";
245 DmaapStreams mrStreams = new DmaapStreams();
246 retInputs = mrStreams
247 .createStreams(inps, cs, topic, s.getType(), s.getConfig_key(), s.getRoute(), 's');
248 subStreams.add(mrStreams);
249 } else if (s.getType().equals("data_router") || s.getType().equals("data router")) {
250 String feed = s.getConfig_key() + "_feed";
251 DmaapStreams drStreams = new DmaapStreams();
252 retInputs = drStreams
253 .createStreams(inps, cs, feed, s.getType(), s.getConfig_key(), s.getRoute(), 's');
254 subStreams.add(drStreams);
259 if (pubStreams.size() != 0) {
260 this.setStreams_publishes(pubStreams);
262 if (subStreams.size() != 0) {
263 this.setStreams_subscribes(subStreams);
266 //set the reource config
267 ResourceConfig resource = new ResourceConfig();
268 retInputs = resource.createResourceConfig(retInputs, cs.getSelf().getName());
269 this.setResource_config(resource);
274 private void addTlsInfo(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> retInputs) {
275 TlsInfo tlsInfo = new TlsInfo();
276 tlsInfo.setCertDirectory((String) cs.getAuxilary().getTls_info().get("cert_directory"));
277 GetInput useTLSFlag = new GetInput();
278 useTLSFlag.setBpInputName("use_tls");
279 tlsInfo.setUseTls(useTLSFlag);
280 this.setTls_info(tlsInfo);
281 LinkedHashMap<String, Object> useTlsFlagInput = BlueprintHelper.createInputValue("boolean",
282 "flag to indicate tls enable/disable",
283 cs.getAuxilary().getTls_info().get("use_tls"));
284 retInputs.put("use_tls", useTlsFlagInput);
287 private Map<String, LinkedHashMap<String, Object>> addExternalTlsInfo(ComponentSpec cs) {
288 this.setExternal_cert(externalCertFactory.createFromComponentSpec(cs));
289 return externalCertFactory.createInputListFromComponentSpec(cs);