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.GetInput;
28 import org.onap.blueprintgenerator.model.common.Interfaces;
29 import org.onap.blueprintgenerator.model.common.Node;
30 import org.onap.blueprintgenerator.model.common.Properties;
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.service.base.BlueprintHelperService;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Service;
38 import java.util.LinkedHashMap;
40 import java.util.ArrayList;
41 import java.util.HashMap;
42 import java.util.TreeMap;
43 import java.util.List;
46 * @author : Ravi Mantena
47 * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service to add
48 * ONAP/DMAAP/Feed/Topic Nodes
51 public class NodeService {
54 private InterfacesService interfacesService;
57 private PolicyNodeService policyNodeService;
60 private PgaasNodeService pgaasNodeService;
63 private PropertiesService propertiesService;
66 private BlueprintHelperService blueprintHelperService;
69 * Creates Onap Node to include interface
71 * @param inputs Inputs
72 * @param onapComponentSpec OnapComponentSpec
73 * @param override Service Name Override
76 public Map<String, Object> createOnapNode(
77 Map<String, LinkedHashMap<String, Object>> inputs,
78 OnapComponentSpec onapComponentSpec,
81 Map<String, Object> response = new HashMap<>();
82 Node onapNode = new Node();
84 Map<String, Object> onapResponse = interfacesService
85 .createInterface(inputs, onapComponentSpec);
86 inputs = (Map<String, LinkedHashMap<String, Object>>) onapResponse.get("inputs");
88 Map<String, Interfaces> interfaces = new TreeMap<>();
90 Constants.CLOUDIFY_INTERFACES_LEFECYCLE, (Interfaces) onapResponse.get("interfaces"));
91 onapNode.setInterfaces(interfaces);
93 onapNode.setType(Constants.DCAE_NODES_CONTAINERIZED_SERVICE_COMPONENT);
95 List<Map<String, String>> relationships = new ArrayList();
97 if (onapComponentSpec.getPolicyInfo() != null) {
98 List<Map<String, String>> policyRelationshipsList =
99 policyNodeService.getPolicyRelationships(onapComponentSpec);
100 relationships.addAll(policyRelationshipsList);
103 if (onapComponentSpec.getAuxilary().getDatabases() != null) {
104 List<Map<String, String>> pgaasRelationshipsList =
105 pgaasNodeService.getPgaasNodeRelationships(onapComponentSpec);
106 relationships.addAll(pgaasRelationshipsList);
109 onapNode.setRelationships(relationships);
111 Map<String, Object> propertiesResponse =
112 propertiesService.createOnapProperties(inputs, onapComponentSpec, override);
113 inputs = (Map<String, LinkedHashMap<String, Object>>) propertiesResponse.get("inputs");
114 onapNode.setProperties(
115 (org.onap.blueprintgenerator.model.common.Properties) propertiesResponse
118 response.put("onapNode", onapNode);
119 response.put("inputs", inputs);
124 * Creates Dmaap Node to include interface
126 * @param inputs Inputs
127 * @param onapComponentSpec OnapComponentSpec
128 * @param override Service Name Override
131 public Map<String, Object> createDmaapNode(
132 OnapComponentSpec onapComponentSpec,
133 Map<String, LinkedHashMap<String, Object>> inputs,
136 Map<String, Object> response = new HashMap<>();
137 Node dmaapNode = new Node();
139 dmaapNode.setType(Constants.DCAE_NODES_CONTAINERIZED_SERVICE_COMPONENT_USING_DMAAP);
141 Map<String, Object> dmaapResponse =
142 interfacesService.createInterface(inputs, onapComponentSpec);
143 inputs = (Map<String, LinkedHashMap<String, Object>>) dmaapResponse.get("inputs");
145 Map<String, Interfaces> interfaces = new TreeMap<>();
147 Constants.CLOUDIFY_INTERFACES_LEFECYCLE, (Interfaces) dmaapResponse.get("interfaces"));
148 dmaapNode.setInterfaces(interfaces);
150 List<Map<String, String>> relationships = new ArrayList();
152 if (onapComponentSpec.getStreams().getPublishes() != null) {
153 for (Publishes publishes : onapComponentSpec.getStreams().getPublishes()) {
154 Map<String, String> pubRelations = new LinkedHashMap();
155 if (blueprintHelperService.isMessageRouterType(publishes.getType())) {
156 pubRelations.put("type", Constants.PUBLISH_EVENTS);
157 pubRelations.put("target", publishes.getConfig_key() + Constants._TOPIC);
158 } else if (blueprintHelperService.isDataRouterType(publishes.getType())) {
159 pubRelations.put("type", Constants.PUBLISH_FILES);
160 pubRelations.put("target", publishes.getConfig_key() + Constants._FEED);
162 relationships.add(pubRelations);
166 if (onapComponentSpec.getStreams().getSubscribes() != null) {
167 for (Subscribes subscribes : onapComponentSpec.getStreams().getSubscribes()) {
168 Map<String, String> subRelations = new LinkedHashMap();
169 if (blueprintHelperService.isMessageRouterType(subscribes.getType())) {
170 subRelations.put("type", Constants.SUBSCRIBE_TO_EVENTS);
171 subRelations.put("target", subscribes.getConfig_key() + Constants._TOPIC);
172 } else if (blueprintHelperService.isDataRouterType(subscribes.getType())) {
173 subRelations.put("type", Constants.SUBSCRIBE_TO_FILES);
174 subRelations.put("target", subscribes.getConfig_key() + Constants._FEED);
176 relationships.add(subRelations);
180 if (onapComponentSpec.getPolicyInfo() != null) {
181 List<Map<String, String>> policyRelationshipsList =
182 policyNodeService.getPolicyRelationships(onapComponentSpec);
183 relationships.addAll(policyRelationshipsList);
186 if (onapComponentSpec.getAuxilary().getDatabases() != null) {
187 List<Map<String, String>> pgaasRelationshipsList =
188 pgaasNodeService.getPgaasNodeRelationships(onapComponentSpec);
189 relationships.addAll(pgaasRelationshipsList);
192 dmaapNode.setRelationships(relationships);
194 Map<String, Object> propertiesResponse =
195 propertiesService.createDmaapProperties(inputs, onapComponentSpec, override);
196 inputs = (Map<String, LinkedHashMap<String, Object>>) propertiesResponse.get("inputs");
197 dmaapNode.setProperties(
198 (org.onap.blueprintgenerator.model.common.Properties) propertiesResponse
201 response.put("dmaapNode", dmaapNode);
202 response.put("inputs", inputs);
207 * Creates Feed Node for Streams
209 * @param inputs Inputs
213 public Map<String, Object> createFeedNode(
214 Map<String, LinkedHashMap<String, Object>> inputs, String name) {
215 Map<String, Object> response = new HashMap<>();
216 Node feedNode = new Node();
218 LinkedHashMap<String, Object> stringType = new LinkedHashMap();
219 stringType.put("type", "string");
221 feedNode.setType(Constants.FEED);
223 org.onap.blueprintgenerator.model.common.Properties props =
224 new org.onap.blueprintgenerator.model.common.Properties();
225 GetInput topicInput = new GetInput();
226 topicInput.setBpInputName(name + "_name");
227 props.setFeed_name(topicInput);
228 props.setUseExisting(true);
229 inputs.put(name + "_name", stringType);
230 feedNode.setProperties(props);
232 response.put("feedNode", feedNode);
233 response.put("inputs", inputs);
238 * Creates Topic Node for Streams
240 * @param inputs Inpts
244 public Map<String, Object> createTopicNode(
245 Map<String, LinkedHashMap<String, Object>> inputs, String name) {
246 Map<String, Object> response = new HashMap<>();
247 Node topicNode = new Node();
249 LinkedHashMap<String, Object> stringType = new LinkedHashMap();
250 stringType.put("type", "string");
252 topicNode.setType(Constants.TOPIC);
254 org.onap.blueprintgenerator.model.common.Properties props = new Properties();
255 GetInput topicInput = new GetInput();
256 topicInput.setBpInputName(name + "_name");
257 props.setTopic_name(topicInput);
258 inputs.put(name + "_name", stringType);
259 topicNode.setProperties(props);
261 response.put("topicNode", topicNode);
262 response.put("inputs", inputs);