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);
93 blueprintHelperService.createStringInput(onapComponentSpec.getArtifacts()[0].getUri()));
95 GetInput location = new GetInput();
96 location.setBpInputName("location_id");
97 properties.setLocation_id(location);
99 inputs.put("location_id", blueprintHelperService.createStringInput(Constants.EMPTY_VALUE));
101 properties.setLog_info(onapComponentSpec.getAuxilary().getLog_info());
103 GetInput replica = new GetInput();
104 replica.setBpInputName("replicas");
105 properties.setReplicas(replica);
107 LinkedHashMap<String, Object> replicas =
108 blueprintHelperService.createIntegerInput("number of instances", 1);
109 inputs.put("replicas", replicas);
111 OnapAuxilary onapAuxilary = onapComponentSpec.getAuxilary();
113 properties.setDocker_config(onapAuxilary);
115 Map<String, Object> appConfigResponse =
116 appConfigService.createAppconfig(inputs, onapComponentSpec, override, false);
117 inputs = (Map<String, LinkedHashMap<String, Object>>) appConfigResponse.get("inputs");
118 properties.setApplication_config((Appconfig) appConfigResponse.get("appconfig"));
120 GetInput always_pull_image = new GetInput();
121 always_pull_image.setBpInputName("always_pull_image");
123 properties.setAlways_pull_image(always_pull_image);
125 LinkedHashMap<String, Object> inputAlwaysPullImage =
126 blueprintHelperService.createBooleanInput(
127 "Set to true if the image should always be pulled", true);
128 inputs.put("always_pull_image", inputAlwaysPullImage);
130 String sType = onapComponentSpec.getSelf().getName();
131 sType = sType.replace('.', '-');
132 properties.setService_component_type(sType);
134 Map<String, Object> tls_info = onapComponentSpec.getAuxilary().getTls_info();
135 if (tls_info != null) {
136 addTlsInfo(onapComponentSpec, inputs, properties);
137 if (tls_info.get(Constants.USE_EXTERNAL_TLS_FIELD) != null) {
138 inputs.putAll(addExternalTlsInfo(onapComponentSpec, properties));
142 Map<String, Object> resourceConfigResponse =
143 resourceConfigService
144 .createResourceConfig(inputs, onapComponentSpec.getSelf().getName());
145 inputs = (Map<String, LinkedHashMap<String, Object>>) resourceConfigResponse.get("inputs");
147 .setResource_config((ResourceConfig) resourceConfigResponse.get("resourceConfig"));
149 response.put("properties", properties);
150 response.put("inputs", inputs);
155 * Creates Dmaap properties
157 * @param inputs Inputs
158 * @param onapComponentSpec OnapComponentSpec
159 * @param override Override
162 public Map<String, Object> createDmaapProperties(
163 Map<String, LinkedHashMap<String, Object>> inputs,
164 OnapComponentSpec onapComponentSpec,
166 Map<String, Object> response = new HashMap<>();
167 org.onap.blueprintgenerator.model.common.Properties properties =
168 new org.onap.blueprintgenerator.model.common.Properties();
170 GetInput image = new GetInput();
171 image.setBpInputName("tag_version");
172 properties.setImage(image);
174 LinkedHashMap<String, Object> img = new LinkedHashMap<>();
177 blueprintHelperService.createStringInput(onapComponentSpec.getArtifacts()[0].getUri()));
179 GetInput location = new GetInput();
180 location.setBpInputName("location_id");
181 properties.setLocation_id(location);
183 LinkedHashMap<String, Object> locMap = new LinkedHashMap();
184 inputs.put("location_id", blueprintHelperService.createStringInput(Constants.EMPTY_VALUE));
186 properties.setLog_info(onapComponentSpec.getAuxilary().getLog_info());
188 String sType = onapComponentSpec.getSelf().getName();
189 sType = sType.replace('.', '-');
190 properties.setService_component_type(sType);
192 Map<String, Object> tls_info = onapComponentSpec.getAuxilary().getTls_info();
193 if (tls_info != null) {
194 addTlsInfo(onapComponentSpec, inputs, properties);
195 if (tls_info.get(Constants.USE_EXTERNAL_TLS_FIELD) != null) {
196 inputs.putAll(addExternalTlsInfo(onapComponentSpec, properties));
200 GetInput replica = new GetInput();
201 replica.setBpInputName("replicas");
202 properties.setReplicas(replica);
204 LinkedHashMap<String, Object> rep =
205 blueprintHelperService.createIntegerInput("number of instances", 1);
206 inputs.put("replicas", rep);
208 OnapAuxilary onapAuxilary = onapComponentSpec.getAuxilary();
210 properties.setDocker_config(onapAuxilary);
212 Map<String, Object> appConfigResponse =
213 appConfigService.createAppconfig(inputs, onapComponentSpec, override, true);
214 inputs = (Map<String, LinkedHashMap<String, Object>>) appConfigResponse.get("inputs");
215 properties.setApplication_config((Appconfig) appConfigResponse.get("appconfig"));
217 List<Streams> pubStreams = new ArrayList();
218 if (onapComponentSpec.getStreams() != null) {
219 if (onapComponentSpec.getStreams().getPublishes() != null) {
220 for (Publishes publishes : onapComponentSpec.getStreams().getPublishes()) {
221 if (blueprintHelperService.isMessageRouterType(publishes.getType())) {
222 String topic = publishes.getConfig_key() + Constants._TOPIC;
223 Map<String, Object> streamsMessageRouterResponse =
224 streamsService.createStreams(
228 publishes.getConfig_key(),
229 publishes.getRoute(),
232 (Map<String, LinkedHashMap<String, Object>>)
233 streamsMessageRouterResponse.get("inputs");
234 pubStreams.add((Streams) streamsMessageRouterResponse.get("streams"));
235 } else if (blueprintHelperService.isDataRouterType(publishes.getType())) {
236 String feed = publishes.getConfig_key() + Constants._FEED;
237 Map<String, Object> streamsDataRouterResponse =
238 streamsService.createStreams(
242 publishes.getConfig_key(),
243 publishes.getRoute(),
246 (Map<String, LinkedHashMap<String, Object>>)
247 streamsDataRouterResponse.get("inputs");
248 pubStreams.add((Streams) streamsDataRouterResponse.get("streams"));
254 ArrayList<Streams> subStreams = new ArrayList();
255 if (onapComponentSpec.getStreams() != null) {
256 if (onapComponentSpec.getStreams().getSubscribes() != null) {
257 for (Subscribes subscribes : onapComponentSpec.getStreams().getSubscribes()) {
258 if (blueprintHelperService.isMessageRouterType(subscribes.getType())) {
259 String topic = subscribes.getConfig_key() + Constants._TOPIC;
260 Map<String, Object> streamsMessageRouterResponse =
261 streamsService.createStreams(
264 subscribes.getType(),
265 subscribes.getConfig_key(),
266 subscribes.getRoute(),
269 (Map<String, LinkedHashMap<String, Object>>)
270 streamsMessageRouterResponse.get("inputs");
271 subStreams.add((Streams) streamsMessageRouterResponse.get("streams"));
272 } else if (blueprintHelperService.isDataRouterType(subscribes.getType())) {
273 String feed = subscribes.getConfig_key() + Constants._FEED;
274 Map<String, Object> streamsDataRouterResponse =
275 streamsService.createStreams(
278 subscribes.getType(),
279 subscribes.getConfig_key(),
280 subscribes.getRoute(),
283 (Map<String, LinkedHashMap<String, Object>>)
284 streamsDataRouterResponse.get("inputs");
285 subStreams.add((Streams) streamsDataRouterResponse.get("streams"));
291 if (!pubStreams.isEmpty()) {
292 properties.setStreams_publishes(pubStreams);
295 if (!subStreams.isEmpty()) {
296 properties.setStreams_subscribes(subStreams);
299 Map<String, Object> resourceConfigResponse =
300 resourceConfigService
301 .createResourceConfig(inputs, onapComponentSpec.getSelf().getName());
302 inputs = (Map<String, LinkedHashMap<String, Object>>) resourceConfigResponse.get("inputs");
304 .setResource_config((ResourceConfig) resourceConfigResponse.get("resourceConfig"));
306 response.put("properties", properties);
307 response.put("inputs", inputs);
311 private void addTlsInfo(
312 OnapComponentSpec onapComponentSpec,
313 Map<String, LinkedHashMap<String, Object>> inputs,
314 Properties properties) {
315 TlsInfo tlsInfo = new TlsInfo();
316 tlsInfo.setCertDirectory(
317 (String) onapComponentSpec.getAuxilary().getTls_info().get("cert_directory"));
318 GetInput useTLSFlag = new GetInput();
319 useTLSFlag.setBpInputName("use_tls");
320 tlsInfo.setUseTls(useTLSFlag);
321 properties.setTls_info(tlsInfo);
322 LinkedHashMap<String, Object> useTlsFlagInput =
323 blueprintHelperService.createBooleanInput(
324 "flag to indicate tls enable/disable",
325 onapComponentSpec.getAuxilary().getTls_info().get("use_tls"));
326 inputs.put("use_tls", useTlsFlagInput);
329 private Map<String, LinkedHashMap<String, Object>> addExternalTlsInfo(
330 OnapComponentSpec onapComponentSpec, Properties properties) {
331 properties.setExternal_cert(
332 externalTlsInfoFactoryService.createFromComponentSpec(onapComponentSpec));
333 return externalTlsInfoFactoryService.createInputListFromComponentSpec(onapComponentSpec);