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.Dmaap;
29 import org.onap.blueprintgenerator.model.common.GetInput;
30 import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
31 import org.onap.blueprintgenerator.model.componentspec.common.Calls;
32 import org.onap.blueprintgenerator.model.componentspec.common.Parameters;
33 import org.onap.blueprintgenerator.model.componentspec.common.Publishes;
34 import org.onap.blueprintgenerator.model.componentspec.common.Subscribes;
35 import org.onap.blueprintgenerator.service.base.BlueprintHelperService;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.stereotype.Service;
39 import java.util.HashMap;
40 import java.util.LinkedHashMap;
42 import java.util.TreeMap;
45 * @author : Ravi Mantena
46 * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service used to create App
49 @Service("onapAppConfigService")
50 public class AppConfigService {
53 private DmaapService dmaapService;
56 private BlueprintHelperService blueprintHelperService;
59 * Creates Inputs section under App Config with Publishes, Subscribes, Parameters sections by
60 * checking Datarouter/MessageRouter/override/Dmaap values
62 * @param inputs Inputs
63 * @param onapComponentSpec Onap Component Specification
64 * @param override Parameter to Service Component Override
65 * @param isDmaap Dmaap Argument
68 public Map<String, Object> createAppconfig(
69 Map<String, LinkedHashMap<String, Object>> inputs,
70 OnapComponentSpec onapComponentSpec,
74 Map<String, Object> response = new HashMap<>();
75 Appconfig appconfig = new Appconfig();
77 Calls[] call = new Calls[0];
78 appconfig.setService_calls(call);
80 Map<String, Dmaap> streamPublishes = new TreeMap<>();
81 if (onapComponentSpec.getStreams() != null) {
82 if (onapComponentSpec.getStreams().getPublishes() != null) {
83 for (Publishes publishes : onapComponentSpec.getStreams().getPublishes()) {
84 if (blueprintHelperService.isDataRouterType(publishes.getType())) {
85 String config = publishes.getConfig_key();
86 String name = config + Constants._FEED;
87 Map<String, Object> dmaapDataRouterResponse =
88 dmaapService.createDmaapDataRouter(inputs, config, name, isDmaap);
90 (Map<String, LinkedHashMap<String, Object>>) dmaapDataRouterResponse
92 Dmaap dmaap = (Dmaap) dmaapDataRouterResponse.get("dmaap");
93 dmaap.setType(publishes.getType());
94 streamPublishes.put(config, dmaap);
95 } else if (blueprintHelperService.isMessageRouterType(publishes.getType())) {
96 String config = publishes.getConfig_key();
97 String name = config + Constants._TOPIC;
98 Map<String, Object> dmaapDataRouterResponse =
100 .createDmaapMessageRouter(inputs, config, 'p', name, name, isDmaap);
102 (Map<String, LinkedHashMap<String, Object>>) dmaapDataRouterResponse
104 Dmaap dmaap = (Dmaap) dmaapDataRouterResponse.get("dmaap");
105 dmaap.setType(publishes.getType());
106 streamPublishes.put(config, dmaap);
112 Map<String, Dmaap> streamSubscribes = new TreeMap<>();
114 if (onapComponentSpec.getStreams() != null) {
115 if (onapComponentSpec.getStreams().getSubscribes() != null) {
116 for (Subscribes subscribes : onapComponentSpec.getStreams().getSubscribes()) {
117 if (blueprintHelperService.isDataRouterType(subscribes.getType())) {
118 String config = subscribes.getConfig_key();
119 String name = config + Constants._FEED;
120 Map<String, Object> dmaapDataRouterResponse =
121 dmaapService.createDmaapDataRouter(inputs, config, name, isDmaap);
123 (Map<String, LinkedHashMap<String, Object>>) dmaapDataRouterResponse
125 Dmaap dmaap = (Dmaap) dmaapDataRouterResponse.get("dmaap");
126 dmaap.setType(subscribes.getType());
127 streamSubscribes.put(config, dmaap);
128 } else if (blueprintHelperService.isMessageRouterType(subscribes.getType())) {
129 String config = subscribes.getConfig_key();
130 String name = config + Constants._TOPIC;
131 Map<String, Object> dmaapDataRouterResponse =
133 .createDmaapMessageRouter(inputs, config, 's', name, name, isDmaap);
135 (Map<String, LinkedHashMap<String, Object>>) dmaapDataRouterResponse
137 Dmaap dmaap = (Dmaap) dmaapDataRouterResponse.get("dmaap");
138 dmaap.setType(subscribes.getType());
139 streamSubscribes.put(config, dmaap);
145 appconfig.setStreams_publishes(streamPublishes);
146 appconfig.setStreams_subscribes(streamSubscribes);
148 Map<String, Object> parameters = new TreeMap<>();
149 for (Parameters p : onapComponentSpec.getParameters()) {
150 String pName = p.getName();
151 if (p.isSourced_at_deployment()) {
152 GetInput paramInput = new GetInput();
153 paramInput.setBpInputName(pName);
154 parameters.put(pName, paramInput);
155 if (!"".equals(p.getValue())) {
156 LinkedHashMap<String, Object> pInputs =
157 blueprintHelperService.createStringInput(p.getValue());
158 inputs.put(pName, pInputs);
160 LinkedHashMap<String, Object> pInputs = new LinkedHashMap<>();
161 pInputs.put("type", "string");
162 inputs.put(pName, pInputs);
165 if ("string".equals(p.getType())) {
166 String val = (String) p.getValue();
167 val = '"' + val + '"';
168 parameters.put(pName, val);
170 parameters.put(pName, p.getValue());
171 // Updated code to resolve the issue of missing \ for collector.schema.file
172 // parameters.put(pName, pName.equals("collector.schema.file") ?
173 // ((String)p.getValue()).replace("\"", "\\\"") : p.getValue());
177 if (override != null) {
178 GetInput ov = new GetInput();
179 ov.setBpInputName(Constants.SERVICE_COMPONENT_NAME_OVERRIDE);
180 parameters.put(Constants.SERVICE_COMPONENT_NAME_OVERRIDE, ov);
181 LinkedHashMap<String, Object> over = blueprintHelperService.createStringInput(override);
182 inputs.put(Constants.SERVICE_COMPONENT_NAME_OVERRIDE, over);
184 appconfig.setParams(parameters);
186 response.put("appconfig", appconfig);
187 response.put("inputs", inputs);