3 * * ============LICENSE_START=======================================================
5 * * ================================================================================
6 * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
7 * * Copyright (c) 2021 Nokia. All rights reserved.
8 * * ================================================================================
9 * * Licensed under the Apache License, Version 2.0 (the "License");
10 * * you may not use this file except in compliance with the License.
11 * * You may obtain a copy of the License at
13 * * http://www.apache.org/licenses/LICENSE-2.0
15 * * Unless required by applicable law or agreed to in writing, software
16 * * distributed under the License is distributed on an "AS IS" BASIS,
17 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * * See the License for the specific language governing permissions and
19 * * limitations under the License.
20 * * ============LICENSE_END=========================================================
25 package org.onap.blueprintgenerator.service.common;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.LinkedHashMap;
30 import java.util.List;
32 import org.onap.blueprintgenerator.constants.Constants;
33 import org.onap.blueprintgenerator.model.common.Appconfig;
34 import org.onap.blueprintgenerator.model.common.GetInput;
35 import org.onap.blueprintgenerator.model.common.Properties;
36 import org.onap.blueprintgenerator.model.common.ResourceConfig;
37 import org.onap.blueprintgenerator.model.componentspec.OnapAuxilary;
38 import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
39 import org.onap.blueprintgenerator.model.componentspec.common.Publishes;
40 import org.onap.blueprintgenerator.model.componentspec.common.Subscribes;
41 import org.onap.blueprintgenerator.model.dmaap.Streams;
42 import org.onap.blueprintgenerator.model.dmaap.TlsInfo;
43 import org.onap.blueprintgenerator.service.base.BlueprintHelperService;
44 import org.onap.blueprintgenerator.service.dmaap.StreamsService;
45 import org.springframework.beans.factory.annotation.Autowired;
46 import org.springframework.stereotype.Service;
49 * @author : Ravi Mantena
50 * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service to create Properties Node
52 @Service("onapPropertiesService")
53 public class PropertiesService {
56 private AppConfigService appConfigService;
59 private ResourceConfigService resourceConfigService;
62 private StreamsService streamsService;
65 private ExternalTlsInfoFactoryService externalTlsInfoFactoryService;
68 private BlueprintHelperService blueprintHelperService;
71 * Creates ONAP properties
73 * @param inputs Inputs
74 * @param onapComponentSpec OnapComponentSpec
75 * @param override Override
78 public Map<String, Object> createOnapProperties(
79 Map<String, Map<String, Object>> inputs,
80 OnapComponentSpec onapComponentSpec,
82 Map<String, Object> response = new HashMap<>();
83 org.onap.blueprintgenerator.model.common.Properties properties =
84 new org.onap.blueprintgenerator.model.common.Properties();
86 GetInput image = new GetInput();
87 image.setBpInputName("image");
88 properties.setImage(image);
92 blueprintHelperService.createStringInput(onapComponentSpec.getArtifacts()[0].getUri()));
94 GetInput location = new GetInput();
95 location.setBpInputName("location_id");
96 properties.setLocation_id(location);
98 inputs.put("location_id", blueprintHelperService.createStringInput(Constants.EMPTY_VALUE));
100 properties.setLog_info(onapComponentSpec.getAuxilary().getLog_info());
102 GetInput replica = new GetInput();
103 replica.setBpInputName("replicas");
104 properties.setReplicas(replica);
106 Map<String, Object> replicas =
107 blueprintHelperService.createIntegerInput("number of instances", 1);
108 inputs.put("replicas", replicas);
110 OnapAuxilary onapAuxilary = onapComponentSpec.getAuxilary();
112 properties.setDocker_config(onapAuxilary);
114 Map<String, Object> appConfigResponse =
115 appConfigService.createAppconfig(inputs, onapComponentSpec, false);
116 inputs = (Map<String, Map<String, Object>>) appConfigResponse.get("inputs");
117 properties.setApplication_config((Appconfig) appConfigResponse.get("appconfig"));
119 GetInput always_pull_image = new GetInput();
120 always_pull_image.setBpInputName("always_pull_image");
122 properties.setAlways_pull_image(always_pull_image);
124 Map<String, Object> inputAlwaysPullImage =
125 blueprintHelperService.createBooleanInput(
126 "Set to true if the image should always be pulled", true);
127 inputs.put("always_pull_image", inputAlwaysPullImage);
129 String sType = onapComponentSpec.getSelf().getName();
130 sType = sType.replace('.', '-');
131 properties.setService_component_type(sType);
133 inputs.put(Constants.SERVICE_COMPONENT_NAME_OVERRIDE,
134 addServiceComponentNameOverride(override, properties));
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, Map<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, Map<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 Map<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 Map<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 inputs.put(Constants.SERVICE_COMPONENT_NAME_OVERRIDE,
195 addServiceComponentNameOverride(override, properties));
197 Map<String, Object> tls_info = onapComponentSpec.getAuxilary().getTls_info();
198 if (tls_info != null) {
199 addTlsInfo(onapComponentSpec, inputs, properties);
200 if (tls_info.get(Constants.USE_EXTERNAL_TLS_FIELD) != null) {
201 inputs.putAll(addExternalTlsInfo(onapComponentSpec, properties));
205 GetInput replica = new GetInput();
206 replica.setBpInputName("replicas");
207 properties.setReplicas(replica);
209 Map<String, Object> rep =
210 blueprintHelperService.createIntegerInput("number of instances", 1);
211 inputs.put("replicas", rep);
213 OnapAuxilary onapAuxilary = onapComponentSpec.getAuxilary();
215 properties.setDocker_config(onapAuxilary);
217 Map<String, Object> appConfigResponse =
218 appConfigService.createAppconfig(inputs, onapComponentSpec, true);
219 inputs = (Map<String, Map<String, Object>>) appConfigResponse.get("inputs");
220 properties.setApplication_config((Appconfig) appConfigResponse.get("appconfig"));
222 List<Streams> pubStreams = new ArrayList();
223 if (onapComponentSpec.getStreams() != null) {
224 if (onapComponentSpec.getStreams().getPublishes() != null) {
225 for (Publishes publishes : onapComponentSpec.getStreams().getPublishes()) {
226 if (blueprintHelperService.isMessageRouterType(publishes.getType())) {
227 String topic = publishes.getConfig_key() + Constants.A_TOPIC;
228 Map<String, Object> streamsMessageRouterResponse =
229 streamsService.createStreams(
233 publishes.getConfig_key(),
234 publishes.getRoute(),
237 (Map<String, Map<String, Object>>)
238 streamsMessageRouterResponse.get("inputs");
239 pubStreams.add((Streams) streamsMessageRouterResponse.get("streams"));
240 } else if (blueprintHelperService.isDataRouterType(publishes.getType())) {
241 String feed = publishes.getConfig_key() + Constants.A_FEED;
242 Map<String, Object> streamsDataRouterResponse =
243 streamsService.createStreams(
247 publishes.getConfig_key(),
248 publishes.getRoute(),
251 (Map<String, Map<String, Object>>)
252 streamsDataRouterResponse.get("inputs");
253 pubStreams.add((Streams) streamsDataRouterResponse.get("streams"));
259 ArrayList<Streams> subStreams = new ArrayList();
260 if (onapComponentSpec.getStreams() != null) {
261 if (onapComponentSpec.getStreams().getSubscribes() != null) {
262 for (Subscribes subscribes : onapComponentSpec.getStreams().getSubscribes()) {
263 if (blueprintHelperService.isMessageRouterType(subscribes.getType())) {
264 String topic = subscribes.getConfig_key() + Constants.A_TOPIC;
265 Map<String, Object> streamsMessageRouterResponse =
266 streamsService.createStreams(
269 subscribes.getType(),
270 subscribes.getConfig_key(),
271 subscribes.getRoute(),
274 (Map<String, Map<String, Object>>)
275 streamsMessageRouterResponse.get("inputs");
276 subStreams.add((Streams) streamsMessageRouterResponse.get("streams"));
277 } else if (blueprintHelperService.isDataRouterType(subscribes.getType())) {
278 String feed = subscribes.getConfig_key() + Constants.A_FEED;
279 Map<String, Object> streamsDataRouterResponse =
280 streamsService.createStreams(
283 subscribes.getType(),
284 subscribes.getConfig_key(),
285 subscribes.getRoute(),
288 (Map<String, Map<String, Object>>)
289 streamsDataRouterResponse.get("inputs");
290 subStreams.add((Streams) streamsDataRouterResponse.get("streams"));
296 if (!pubStreams.isEmpty()) {
297 properties.setStreams_publishes(pubStreams);
300 if (!subStreams.isEmpty()) {
301 properties.setStreams_subscribes(subStreams);
304 Map<String, Object> resourceConfigResponse =
305 resourceConfigService
306 .createResourceConfig(inputs, onapComponentSpec.getSelf().getName());
307 inputs = (Map<String, Map<String, Object>>) resourceConfigResponse.get("inputs");
309 .setResource_config((ResourceConfig) resourceConfigResponse.get("resourceConfig"));
311 response.put("properties", properties);
312 response.put("inputs", inputs);
316 private Map<String, Object> addServiceComponentNameOverride(String override, Properties properties) {
317 GetInput overrideGetInput = new GetInput();
318 overrideGetInput.setBpInputName(Constants.SERVICE_COMPONENT_NAME_OVERRIDE);
319 properties.setService_component_name_override(overrideGetInput);
320 return blueprintHelperService.createStringInput(override != null ? override : "");
323 private void addTlsInfo(
324 OnapComponentSpec onapComponentSpec,
325 Map<String, Map<String, Object>> inputs,
326 Properties properties) {
327 TlsInfo tlsInfo = new TlsInfo();
328 tlsInfo.setCertDirectory(
329 (String) onapComponentSpec.getAuxilary().getTls_info().get("cert_directory"));
330 GetInput useTLSFlag = new GetInput();
331 useTLSFlag.setBpInputName("use_tls");
332 tlsInfo.setUseTls(useTLSFlag);
333 properties.setTls_info(tlsInfo);
334 Map<String, Object> useTlsFlagInput =
335 blueprintHelperService.createBooleanInput(
336 "flag to indicate tls enable/disable",
337 onapComponentSpec.getAuxilary().getTls_info().get("use_tls"));
338 inputs.put("use_tls", useTlsFlagInput);
341 private Map<String, Map<String, Object>> addExternalTlsInfo(
342 OnapComponentSpec onapComponentSpec, Properties properties) {
343 properties.setExternal_cert(
344 externalTlsInfoFactoryService.createFromComponentSpec(onapComponentSpec));
345 return externalTlsInfoFactoryService.createInputListFromComponentSpec(onapComponentSpec);