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;
47 * @author : Ravi Mantena
49 * Application: ONAP - Blueprint Generator
50 * Common ONAP Service used by ONAP and DMAAP Blueprint to add ONAP/DMAAP/Feed/Topic Nodes
55 public class NodeService {
58 private InterfacesService interfacesService;
61 private PolicyNodeService policyNodeService;
64 private PgaasNodeService pgaasNodeService;
67 private PropertiesService propertiesService;
70 private BlueprintHelperService blueprintHelperService;
72 // method to create Onap Node to include interface
73 public Map<String,Object> createOnapNode(Map<String, LinkedHashMap<String, Object>> inputs, OnapComponentSpec onapComponentSpec, String override) {
75 Map<String,Object> response = new HashMap<>();
76 Node onapNode = new Node();
78 Map<String, Object> onapResponse = interfacesService.createInterface(inputs, onapComponentSpec);
79 inputs = (Map<String, LinkedHashMap<String, Object>>) onapResponse.get("inputs");
81 Map<String, Interfaces> interfaces = new TreeMap<>();
82 interfaces.put(Constants.CLOUDIFY_INTERFACES_LEFECYCLE, (Interfaces) onapResponse.get("interfaces"));
83 onapNode.setInterfaces(interfaces);
85 onapNode.setType(Constants.DCAE_NODES_CONTAINERIZED_SERVICE_COMPONENT);
87 List<Map<String, String>> relationships = new ArrayList();
89 if(onapComponentSpec.getPolicyInfo() != null){
90 List<Map<String, String>> policyRelationshipsList = policyNodeService.getPolicyRelationships(onapComponentSpec);
91 relationships.addAll(policyRelationshipsList);
94 if(onapComponentSpec.getAuxilary().getDatabases() != null){
95 List<Map<String, String>> pgaasRelationshipsList = pgaasNodeService.getPgaasNodeRelationships(onapComponentSpec);
96 relationships.addAll(pgaasRelationshipsList);
99 onapNode.setRelationships(relationships);
101 Map<String, Object> propertiesResponse = propertiesService.createOnapProperties(inputs, onapComponentSpec, override);
102 inputs = (Map<String, LinkedHashMap<String, Object>>) propertiesResponse.get("inputs");
103 onapNode.setProperties((org.onap.blueprintgenerator.model.common.Properties)propertiesResponse.get("properties"));
105 response.put("onapNode", onapNode);
106 response.put("inputs", inputs);
110 // method to create Dmaap Node to include interface
111 public Map<String,Object> createDmaapNode(OnapComponentSpec onapComponentSpec, Map<String, LinkedHashMap<String, Object>> inputs, String override) {
113 Map<String,Object> response = new HashMap<>();
114 Node dmaapNode = new Node();
116 dmaapNode.setType(Constants.DCAE_NODES_CONTAINERIZED_SERVICE_COMPONENT_USING_DMAAP);
118 Map<String, Object> dmaapResponse = interfacesService.createInterface(inputs, onapComponentSpec);
119 inputs = (Map<String, LinkedHashMap<String, Object>>) dmaapResponse.get("inputs");
121 Map<String, Interfaces> interfaces = new TreeMap<>();
122 interfaces.put(Constants.CLOUDIFY_INTERFACES_LEFECYCLE, (Interfaces) dmaapResponse.get("interfaces"));
123 dmaapNode.setInterfaces(interfaces);
125 List<Map<String, String>> relationships = new ArrayList();
127 if(onapComponentSpec.getStreams().getPublishes() != null) {
128 for(Publishes publishes: onapComponentSpec.getStreams().getPublishes()) {
129 Map<String, String> pubRelations = new LinkedHashMap();
130 if(blueprintHelperService.isMessageRouterType(publishes.getType())){
131 pubRelations.put("type", Constants.PUBLISH_EVENTS);
132 pubRelations.put("target", publishes.getConfig_key() + Constants._TOPIC);
133 } else if(blueprintHelperService.isDataRouterType(publishes.getType())){
134 pubRelations.put("type", Constants.PUBLISH_FILES);
135 pubRelations.put("target", publishes.getConfig_key() + Constants._FEED);
137 relationships.add(pubRelations);
141 if(onapComponentSpec.getStreams().getSubscribes() != null) {
142 for(Subscribes subscribes: onapComponentSpec.getStreams().getSubscribes()) {
143 Map<String, String> subRelations = new LinkedHashMap();
144 if(blueprintHelperService.isMessageRouterType(subscribes.getType())){
145 subRelations.put("type", Constants.SUBSCRIBE_TO_EVENTS);
146 subRelations.put("target", subscribes.getConfig_key() + Constants._TOPIC);
147 } else if(blueprintHelperService.isDataRouterType(subscribes.getType())){
148 subRelations.put("type", Constants.SUBSCRIBE_TO_FILES);
149 subRelations.put("target", subscribes.getConfig_key() + Constants._FEED);
151 relationships.add(subRelations);
155 if(onapComponentSpec.getPolicyInfo() != null){
156 List<Map<String, String>> policyRelationshipsList = policyNodeService.getPolicyRelationships(onapComponentSpec);
157 relationships.addAll(policyRelationshipsList);
160 if(onapComponentSpec.getAuxilary().getDatabases() != null){
161 List<Map<String, String>> pgaasRelationshipsList = pgaasNodeService.getPgaasNodeRelationships(onapComponentSpec);
162 relationships.addAll(pgaasRelationshipsList);
165 dmaapNode.setRelationships(relationships);
167 Map<String, Object> propertiesResponse = propertiesService.createDmaapProperties(inputs, onapComponentSpec, override);
168 inputs = (Map<String, LinkedHashMap<String, Object>>) propertiesResponse.get("inputs");
169 dmaapNode.setProperties((org.onap.blueprintgenerator.model.common.Properties)propertiesResponse.get("properties"));
171 response.put("dmaapNode", dmaapNode);
172 response.put("inputs", inputs);
176 // method to create Feed Node for Streams
177 public Map<String,Object> createFeedNode(Map<String, LinkedHashMap<String, Object>> inputs, String name){
178 Map<String,Object> response = new HashMap<>();
179 Node feedNode = new Node();
181 LinkedHashMap<String, Object> stringType = new LinkedHashMap();
182 stringType.put("type", "string");
184 feedNode.setType(Constants.FEED);
186 org.onap.blueprintgenerator.model.common.Properties props = new org.onap.blueprintgenerator.model.common.Properties();
187 GetInput topicInput = new GetInput();
188 topicInput.setBpInputName(name + "_name");
189 props.setFeed_name(topicInput);
190 props.setUseExisting(true);
191 inputs.put(name + "_name", stringType);
192 feedNode.setProperties(props);
194 response.put("feedNode", feedNode);
195 response.put("inputs", inputs);
199 // method to create Topic Node for Streams
200 public Map<String,Object> createTopicNode(Map<String, LinkedHashMap<String, Object>> inputs, String name){
201 Map<String,Object> response = new HashMap<>();
202 Node topicNode = new Node();
204 LinkedHashMap<String, Object> stringType = new LinkedHashMap();
205 stringType.put("type", "string");
207 topicNode.setType(Constants.TOPIC);
209 org.onap.blueprintgenerator.model.common.Properties props = new Properties();
210 GetInput topicInput = new GetInput();
211 topicInput.setBpInputName(name + "_name");
212 props.setTopic_name(topicInput);
213 inputs.put(name + "_name", stringType);
214 topicNode.setProperties(props);
216 response.put("topicNode", topicNode);
217 response.put("inputs", inputs);