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 org.onap.blueprintgenerator.constants.Constants;
28 import org.onap.blueprintgenerator.model.common.GetInput;
29 import org.onap.blueprintgenerator.model.common.Interfaces;
30 import org.onap.blueprintgenerator.model.common.Node;
31 import org.onap.blueprintgenerator.model.common.Properties;
32 import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
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.LinkedHashMap;
41 import java.util.ArrayList;
42 import java.util.HashMap;
43 import java.util.TreeMap;
44 import java.util.List;
47 * @author : Ravi Mantena
48 * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service to add
49 * ONAP/DMAAP/Feed/Topic Nodes
52 public class NodeService {
55 private InterfacesService interfacesService;
58 private PolicyNodeService policyNodeService;
61 private PgaasNodeService pgaasNodeService;
64 private PropertiesService propertiesService;
67 private BlueprintHelperService blueprintHelperService;
70 * Creates Onap Node to include interface
72 * @param inputs Inputs
73 * @param onapComponentSpec OnapComponentSpec
74 * @param override Service Name Override
77 public Map<String, Object> createOnapNode(
78 Map<String, Map<String, Object>> inputs,
79 OnapComponentSpec onapComponentSpec,
82 Map<String, Object> response = new HashMap<>();
83 Node onapNode = new Node();
85 Map<String, Object> onapResponse = interfacesService
86 .createInterface(inputs, onapComponentSpec);
87 inputs = (Map<String, Map<String, Object>>) onapResponse.get("inputs");
89 Map<String, Interfaces> interfaces = new TreeMap<>();
91 Constants.CLOUDIFY_INTERFACES_LEFECYCLE, (Interfaces) onapResponse.get("interfaces"));
92 onapNode.setInterfaces(interfaces);
94 onapNode.setType(Constants.DCAE_NODES_CONTAINERIZED_SERVICE_COMPONENT);
96 List<Map<String, String>> relationships = new ArrayList();
98 if (onapComponentSpec.getPolicyInfo() != null) {
99 List<Map<String, String>> policyRelationshipsList =
100 policyNodeService.getPolicyRelationships(onapComponentSpec);
101 relationships.addAll(policyRelationshipsList);
104 if (onapComponentSpec.getAuxilary().getDatabases() != null) {
105 List<Map<String, String>> pgaasRelationshipsList =
106 pgaasNodeService.getPgaasNodeRelationships(onapComponentSpec);
107 relationships.addAll(pgaasRelationshipsList);
110 onapNode.setRelationships(relationships);
112 Map<String, Object> propertiesResponse =
113 propertiesService.createOnapProperties(inputs, onapComponentSpec, override);
114 inputs = (Map<String, Map<String, Object>>) propertiesResponse.get("inputs");
115 onapNode.setProperties(
116 (org.onap.blueprintgenerator.model.common.Properties) propertiesResponse
119 response.put("onapNode", onapNode);
120 response.put("inputs", inputs);
125 * Creates Dmaap Node to include interface
127 * @param inputs Inputs
128 * @param onapComponentSpec OnapComponentSpec
129 * @param override Service Name Override
132 public Map<String, Object> createDmaapNode(
133 OnapComponentSpec onapComponentSpec,
134 Map<String, Map<String, Object>> inputs,
137 Map<String, Object> response = new HashMap<>();
138 Node dmaapNode = new Node();
140 dmaapNode.setType(Constants.DCAE_NODES_CONTAINERIZED_SERVICE_COMPONENT_USING_DMAAP);
142 Map<String, Object> dmaapResponse =
143 interfacesService.createInterface(inputs, onapComponentSpec);
144 inputs = (Map<String, Map<String, Object>>) dmaapResponse.get("inputs");
146 Map<String, Interfaces> interfaces = new TreeMap<>();
148 Constants.CLOUDIFY_INTERFACES_LEFECYCLE, (Interfaces) dmaapResponse.get("interfaces"));
149 dmaapNode.setInterfaces(interfaces);
151 List<Map<String, String>> relationships = new ArrayList();
153 if (onapComponentSpec.getStreams().getPublishes() != null) {
154 for (Publishes publishes : onapComponentSpec.getStreams().getPublishes()) {
155 Map<String, String> pubRelations = new LinkedHashMap();
156 if (blueprintHelperService.isMessageRouterType(publishes.getType())) {
157 pubRelations.put("type", Constants.PUBLISH_EVENTS);
158 pubRelations.put("target", publishes.getConfig_key() + Constants.A_TOPIC);
159 } else if (blueprintHelperService.isDataRouterType(publishes.getType())) {
160 pubRelations.put("type", Constants.PUBLISH_FILES);
161 pubRelations.put("target", publishes.getConfig_key() + Constants.A_FEED);
163 relationships.add(pubRelations);
167 if (onapComponentSpec.getStreams().getSubscribes() != null) {
168 for (Subscribes subscribes : onapComponentSpec.getStreams().getSubscribes()) {
169 Map<String, String> subRelations = new LinkedHashMap();
170 if (blueprintHelperService.isMessageRouterType(subscribes.getType())) {
171 subRelations.put("type", Constants.SUBSCRIBE_TO_EVENTS);
172 subRelations.put("target", subscribes.getConfig_key() + Constants.A_TOPIC);
173 } else if (blueprintHelperService.isDataRouterType(subscribes.getType())) {
174 subRelations.put("type", Constants.SUBSCRIBE_TO_FILES);
175 subRelations.put("target", subscribes.getConfig_key() + Constants.A_FEED);
177 relationships.add(subRelations);
181 if (onapComponentSpec.getPolicyInfo() != null) {
182 List<Map<String, String>> policyRelationshipsList =
183 policyNodeService.getPolicyRelationships(onapComponentSpec);
184 relationships.addAll(policyRelationshipsList);
187 if (onapComponentSpec.getAuxilary().getDatabases() != null) {
188 List<Map<String, String>> pgaasRelationshipsList =
189 pgaasNodeService.getPgaasNodeRelationships(onapComponentSpec);
190 relationships.addAll(pgaasRelationshipsList);
193 dmaapNode.setRelationships(relationships);
195 Map<String, Object> propertiesResponse =
196 propertiesService.createDmaapProperties(inputs, onapComponentSpec, override);
197 inputs = (Map<String, Map<String, Object>>) propertiesResponse.get("inputs");
198 dmaapNode.setProperties(
199 (org.onap.blueprintgenerator.model.common.Properties) propertiesResponse
202 response.put("dmaapNode", dmaapNode);
203 response.put("inputs", inputs);
208 * Creates Feed Node for Streams
210 * @param inputs Inputs
214 public Map<String, Object> createFeedNode(
215 Map<String, Map<String, Object>> inputs, String name) {
216 Map<String, Object> response = new HashMap<>();
217 Node feedNode = new Node();
219 Map<String, Object> stringType = new LinkedHashMap();
220 stringType.put("type", "string");
222 feedNode.setType(Constants.FEED);
224 org.onap.blueprintgenerator.model.common.Properties props =
225 new org.onap.blueprintgenerator.model.common.Properties();
226 GetInput topicInput = new GetInput();
227 topicInput.setBpInputName(name + "_name");
228 props.setFeed_name(topicInput);
229 props.setUseExisting(true);
230 inputs.put(name + "_name", stringType);
231 feedNode.setProperties(props);
233 response.put("feedNode", feedNode);
234 response.put("inputs", inputs);
239 * Creates Topic Node for Streams
241 * @param inputs Inpts
245 public Map<String, Object> createTopicNode(
246 Map<String, Map<String, Object>> inputs, String name) {
247 Map<String, Object> response = new HashMap<>();
248 Node topicNode = new Node();
250 Map<String, Object> stringType = new LinkedHashMap();
251 stringType.put("type", "string");
253 topicNode.setType(Constants.TOPIC);
255 org.onap.blueprintgenerator.model.common.Properties props = new Properties();
256 GetInput topicInput = new GetInput();
257 topicInput.setBpInputName(name + "_name");
258 props.setTopic_name(topicInput);
259 inputs.put(name + "_name", stringType);
260 topicNode.setProperties(props);
262 response.put("topicNode", topicNode);
263 response.put("inputs", inputs);