3 * * ============LICENSE_START=======================================================
5 * * ================================================================================
6 * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
7 * * ================================================================================
8 * * Licensed under the Apache License, Version 2.0 (the "License");
9 * * you may not use this file except in compliance with the License.
10 * * You may obtain a copy of the License at
12 * * http://www.apache.org/licenses/LICENSE-2.0
14 * * Unless required by applicable law or agreed to in writing, software
15 * * distributed under the License is distributed on an "AS IS" BASIS,
16 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * * See the License for the specific language governing permissions and
18 * * limitations under the License.
19 * * ============LICENSE_END=========================================================
24 package org.onap.blueprintgenerator.service.common;
26 import org.onap.blueprintgenerator.constants.Constants;
27 import org.onap.blueprintgenerator.model.common.Appconfig;
28 import org.onap.blueprintgenerator.model.common.GetInput;
29 import org.onap.blueprintgenerator.model.common.ResourceConfig;
30 import org.onap.blueprintgenerator.model.componentspec.OnapAuxilary;
31 import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
32 import org.onap.blueprintgenerator.model.componentspec.common.Publishes;
33 import org.onap.blueprintgenerator.model.componentspec.common.Subscribes;
34 import org.onap.blueprintgenerator.model.dmaap.Streams;
35 import org.onap.blueprintgenerator.model.dmaap.TlsInfo;
36 import org.onap.blueprintgenerator.service.base.BlueprintHelperService;
37 import org.onap.blueprintgenerator.service.dmaap.StreamsService;
38 import org.onap.blueprintgenerator.model.common.Properties;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.stereotype.Service;
42 import java.util.LinkedHashMap;
44 import java.util.HashMap;
45 import java.util.ArrayList;
46 import java.util.List;
49 * @author : Ravi Mantena
50 * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service to create Properties
53 @Service("onapPropertiesService")
54 public class PropertiesService {
57 private AppConfigService appConfigService;
60 private ResourceConfigService resourceConfigService;
63 private StreamsService streamsService;
66 private ExternalTlsInfoFactoryService externalTlsInfoFactoryService;
69 private BlueprintHelperService blueprintHelperService;
72 * Creates ONAP properties
74 * @param inputs Inputs
75 * @param onapComponentSpec OnapComponentSpec
76 * @param override Override
79 public Map<String, Object> createOnapProperties(
80 Map<String, LinkedHashMap<String, Object>> inputs,
81 OnapComponentSpec onapComponentSpec,
83 Map<String, Object> response = new HashMap<>();
84 org.onap.blueprintgenerator.model.common.Properties properties =
85 new org.onap.blueprintgenerator.model.common.Properties();
87 GetInput image = new GetInput();
88 image.setBpInputName("image");
89 properties.setImage(image);
91 LinkedHashMap<String, Object> img = new LinkedHashMap<>();
94 blueprintHelperService.createStringInput(onapComponentSpec.getArtifacts()[0].getUri()));
96 GetInput location = new GetInput();
97 location.setBpInputName("location_id");
98 properties.setLocation_id(location);
100 LinkedHashMap<String, Object> locMap = new LinkedHashMap();
101 inputs.put("location_id", blueprintHelperService.createStringInput(Constants.EMPTY_VALUE));
103 properties.setLog_info(onapComponentSpec.getAuxilary().getLog_info());
105 GetInput replica = new GetInput();
106 replica.setBpInputName("replicas");
107 properties.setReplicas(replica);
109 LinkedHashMap<String, Object> replicas =
110 blueprintHelperService.createIntegerInput("number of instances", 1);
111 inputs.put("replicas", replicas);
113 OnapAuxilary onapAuxilary = onapComponentSpec.getAuxilary();
115 properties.setDocker_config(onapAuxilary);
117 Map<String, Object> appConfigResponse =
118 appConfigService.createAppconfig(inputs, onapComponentSpec, override, false);
119 inputs = (Map<String, LinkedHashMap<String, Object>>) appConfigResponse.get("inputs");
120 properties.setApplication_config((Appconfig) appConfigResponse.get("appconfig"));
122 GetInput always_pull_image = new GetInput();
123 always_pull_image.setBpInputName("always_pull_image");
125 properties.setAlways_pull_image(always_pull_image);
127 LinkedHashMap<String, Object> inputAlwaysPullImage =
128 blueprintHelperService.createBooleanInput(
129 "Set to true if the image should always be pulled", true);
130 inputs.put("always_pull_image", inputAlwaysPullImage);
132 String sType = onapComponentSpec.getSelf().getName();
133 sType = sType.replace('.', '-');
134 properties.setService_component_type(sType);
136 Map<String, Object> tls_info = onapComponentSpec.getAuxilary().getTls_info();
137 if (tls_info != null) {
138 addTlsInfo(onapComponentSpec, inputs, properties);
139 if (tls_info.get(Constants.USE_EXTERNAL_TLS_FIELD) != null) {
140 inputs.putAll(addExternalTlsInfo(onapComponentSpec, properties));
144 Map<String, Object> resourceConfigResponse =
145 resourceConfigService
146 .createResourceConfig(inputs, onapComponentSpec.getSelf().getName());
147 inputs = (Map<String, LinkedHashMap<String, Object>>) resourceConfigResponse.get("inputs");
149 .setResource_config((ResourceConfig) resourceConfigResponse.get("resourceConfig"));
151 response.put("properties", properties);
152 response.put("inputs", inputs);
157 * Creates Dmaap properties
159 * @param inputs Inputs
160 * @param onapComponentSpec OnapComponentSpec
161 * @param override Override
164 public Map<String, Object> createDmaapProperties(
165 Map<String, LinkedHashMap<String, Object>> inputs,
166 OnapComponentSpec onapComponentSpec,
168 Map<String, Object> response = new HashMap<>();
169 org.onap.blueprintgenerator.model.common.Properties properties =
170 new org.onap.blueprintgenerator.model.common.Properties();
172 GetInput image = new GetInput();
173 image.setBpInputName("tag_version");
174 properties.setImage(image);
176 LinkedHashMap<String, Object> img = new LinkedHashMap<>();
179 blueprintHelperService.createStringInput(onapComponentSpec.getArtifacts()[0].getUri()));
181 GetInput location = new GetInput();
182 location.setBpInputName("location_id");
183 properties.setLocation_id(location);
185 LinkedHashMap<String, Object> locMap = new LinkedHashMap();
186 inputs.put("location_id", blueprintHelperService.createStringInput(Constants.EMPTY_VALUE));
188 properties.setLog_info(onapComponentSpec.getAuxilary().getLog_info());
190 String sType = onapComponentSpec.getSelf().getName();
191 sType = sType.replace('.', '-');
192 properties.setService_component_type(sType);
194 Map<String, Object> tls_info = onapComponentSpec.getAuxilary().getTls_info();
195 if (tls_info != null) {
196 addTlsInfo(onapComponentSpec, inputs, properties);
197 if (tls_info.get(Constants.USE_EXTERNAL_TLS_FIELD) != null) {
198 inputs.putAll(addExternalTlsInfo(onapComponentSpec, properties));
202 GetInput replica = new GetInput();
203 replica.setBpInputName("replicas");
204 properties.setReplicas(replica);
206 LinkedHashMap<String, Object> rep =
207 blueprintHelperService.createIntegerInput("number of instances", 1);
208 inputs.put("replicas", rep);
210 OnapAuxilary onapAuxilary = onapComponentSpec.getAuxilary();
212 properties.setDocker_config(onapAuxilary);
214 Map<String, Object> appConfigResponse =
215 appConfigService.createAppconfig(inputs, onapComponentSpec, override, true);
216 inputs = (Map<String, LinkedHashMap<String, Object>>) appConfigResponse.get("inputs");
217 properties.setApplication_config((Appconfig) appConfigResponse.get("appconfig"));
219 List<Streams> pubStreams = new ArrayList();
220 if (onapComponentSpec.getStreams() != null) {
221 if (onapComponentSpec.getStreams().getPublishes() != null) {
222 for (Publishes publishes : onapComponentSpec.getStreams().getPublishes()) {
223 if (blueprintHelperService.isMessageRouterType(publishes.getType())) {
224 String topic = publishes.getConfig_key() + Constants._TOPIC;
225 Map<String, Object> streamsMessageRouterResponse =
226 streamsService.createStreams(
230 publishes.getConfig_key(),
231 publishes.getRoute(),
234 (Map<String, LinkedHashMap<String, Object>>)
235 streamsMessageRouterResponse.get("inputs");
236 pubStreams.add((Streams) streamsMessageRouterResponse.get("streams"));
237 } else if (blueprintHelperService.isDataRouterType(publishes.getType())) {
238 String feed = publishes.getConfig_key() + Constants._FEED;
239 Map<String, Object> streamsDataRouterResponse =
240 streamsService.createStreams(
244 publishes.getConfig_key(),
245 publishes.getRoute(),
248 (Map<String, LinkedHashMap<String, Object>>)
249 streamsDataRouterResponse.get("inputs");
250 pubStreams.add((Streams) streamsDataRouterResponse.get("streams"));
256 ArrayList<Streams> subStreams = new ArrayList();
257 if (onapComponentSpec.getStreams() != null) {
258 if (onapComponentSpec.getStreams().getSubscribes() != null) {
259 for (Subscribes subscribes : onapComponentSpec.getStreams().getSubscribes()) {
260 if (blueprintHelperService.isMessageRouterType(subscribes.getType())) {
261 String topic = subscribes.getConfig_key() + Constants._TOPIC;
262 Map<String, Object> streamsMessageRouterResponse =
263 streamsService.createStreams(
266 subscribes.getType(),
267 subscribes.getConfig_key(),
268 subscribes.getRoute(),
271 (Map<String, LinkedHashMap<String, Object>>)
272 streamsMessageRouterResponse.get("inputs");
273 subStreams.add((Streams) streamsMessageRouterResponse.get("streams"));
274 } else if (blueprintHelperService.isDataRouterType(subscribes.getType())) {
275 String feed = subscribes.getConfig_key() + Constants._FEED;
276 Map<String, Object> streamsDataRouterResponse =
277 streamsService.createStreams(
280 subscribes.getType(),
281 subscribes.getConfig_key(),
282 subscribes.getRoute(),
285 (Map<String, LinkedHashMap<String, Object>>)
286 streamsDataRouterResponse.get("inputs");
287 subStreams.add((Streams) streamsDataRouterResponse.get("streams"));
293 if (!pubStreams.isEmpty()) {
294 properties.setStreams_publishes(pubStreams);
297 if (!subStreams.isEmpty()) {
298 properties.setStreams_subscribes(subStreams);
301 Map<String, Object> resourceConfigResponse =
302 resourceConfigService
303 .createResourceConfig(inputs, onapComponentSpec.getSelf().getName());
304 inputs = (Map<String, LinkedHashMap<String, Object>>) resourceConfigResponse.get("inputs");
306 .setResource_config((ResourceConfig) resourceConfigResponse.get("resourceConfig"));
308 response.put("properties", properties);
309 response.put("inputs", inputs);
313 private void addTlsInfo(
314 OnapComponentSpec onapComponentSpec,
315 Map<String, LinkedHashMap<String, Object>> inputs,
316 Properties properties) {
317 TlsInfo tlsInfo = new TlsInfo();
318 tlsInfo.setCertDirectory(
319 (String) onapComponentSpec.getAuxilary().getTls_info().get("cert_directory"));
320 GetInput useTLSFlag = new GetInput();
321 useTLSFlag.setBpInputName("use_tls");
322 tlsInfo.setUseTls(useTLSFlag);
323 properties.setTls_info(tlsInfo);
324 LinkedHashMap<String, Object> useTlsFlagInput =
325 blueprintHelperService.createBooleanInput(
326 "flag to indicate tls enable/disable",
327 onapComponentSpec.getAuxilary().getTls_info().get("use_tls"));
328 inputs.put("use_tls", useTlsFlagInput);
331 private Map<String, LinkedHashMap<String, Object>> addExternalTlsInfo(
332 OnapComponentSpec onapComponentSpec, Properties properties) {
333 properties.setExternal_cert(
334 externalTlsInfoFactoryService.createFromComponentSpec(onapComponentSpec));
335 return externalTlsInfoFactoryService.createInputListFromComponentSpec(onapComponentSpec);