From 55dcf3197958c76b1622a0c26489e68fe77e0314 Mon Sep 17 00:00:00 2001 From: Ravi Mantena Date: Wed, 21 Oct 2020 15:47:38 -0400 Subject: Blueprint Generator Refactored Code Issue-ID: DCAEGEN2-2472 Change-Id: I2ade7fb3b4196554eb4ecadd918fd45cb6ba8a52 Signed-off-by: Ravi Mantena --- .../service/common/NodeService.java | 222 +++++++++++++++++++++ 1 file changed, 222 insertions(+) create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/NodeService.java (limited to 'mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/NodeService.java') diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/NodeService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/NodeService.java new file mode 100644 index 0000000..b8da0d7 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/NodeService.java @@ -0,0 +1,222 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END========================================================= + * + * + */ + +package org.onap.blueprintgenerator.service.common; + +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.model.common.GetInput; +import org.onap.blueprintgenerator.model.common.Interfaces; +import org.onap.blueprintgenerator.model.common.Node; +import org.onap.blueprintgenerator.model.common.Properties; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; +import org.onap.blueprintgenerator.model.componentspec.common.Publishes; +import org.onap.blueprintgenerator.model.componentspec.common.Subscribes; +import org.onap.blueprintgenerator.service.base.BlueprintHelperService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.TreeMap; +import java.util.List; + + +/** + * @author : Ravi Mantena + * @date 10/16/2020 + * Application: ONAP - Blueprint Generator + * Common ONAP Service used by ONAP and DMAAP Blueprint to add ONAP/DMAAP/Feed/Topic Nodes + */ + + +@Service +public class NodeService { + + @Autowired + private InterfacesService interfacesService; + + @Autowired + private PolicyNodeService policyNodeService; + + @Autowired + private PgaasNodeService pgaasNodeService; + + @Autowired + private PropertiesService propertiesService; + + @Autowired + private BlueprintHelperService blueprintHelperService; + + // method to create Onap Node to include interface + public Map createOnapNode(Map> inputs, OnapComponentSpec onapComponentSpec, String override) { + + Map response = new HashMap<>(); + Node onapNode = new Node(); + + Map onapResponse = interfacesService.createInterface(inputs, onapComponentSpec); + inputs = (Map>) onapResponse.get("inputs"); + + Map interfaces = new TreeMap<>(); + interfaces.put(Constants.CLOUDIFY_INTERFACES_LEFECYCLE, (Interfaces) onapResponse.get("interfaces")); + onapNode.setInterfaces(interfaces); + + onapNode.setType(Constants.DCAE_NODES_CONTAINERIZED_SERVICE_COMPONENT); + + List> relationships = new ArrayList(); + + if(onapComponentSpec.getPolicyInfo() != null){ + List> policyRelationshipsList = policyNodeService.getPolicyRelationships(onapComponentSpec); + relationships.addAll(policyRelationshipsList); + } + + if(onapComponentSpec.getAuxilary().getDatabases() != null){ + List> pgaasRelationshipsList = pgaasNodeService.getPgaasNodeRelationships(onapComponentSpec); + relationships.addAll(pgaasRelationshipsList); + } + + onapNode.setRelationships(relationships); + + Map propertiesResponse = propertiesService.createOnapProperties(inputs, onapComponentSpec, override); + inputs = (Map>) propertiesResponse.get("inputs"); + onapNode.setProperties((org.onap.blueprintgenerator.model.common.Properties)propertiesResponse.get("properties")); + + response.put("onapNode", onapNode); + response.put("inputs", inputs); + return response; + } + + // method to create Dmaap Node to include interface + public Map createDmaapNode(OnapComponentSpec onapComponentSpec, Map> inputs, String override) { + + Map response = new HashMap<>(); + Node dmaapNode = new Node(); + + dmaapNode.setType(Constants.DCAE_NODES_CONTAINERIZED_SERVICE_COMPONENT_USING_DMAAP); + + Map dmaapResponse = interfacesService.createInterface(inputs, onapComponentSpec); + inputs = (Map>) dmaapResponse.get("inputs"); + + Map interfaces = new TreeMap<>(); + interfaces.put(Constants.CLOUDIFY_INTERFACES_LEFECYCLE, (Interfaces) dmaapResponse.get("interfaces")); + dmaapNode.setInterfaces(interfaces); + + List> relationships = new ArrayList(); + + if(onapComponentSpec.getStreams().getPublishes() != null) { + for(Publishes publishes: onapComponentSpec.getStreams().getPublishes()) { + Map pubRelations = new LinkedHashMap(); + if(blueprintHelperService.isMessageRouterType(publishes.getType())){ + pubRelations.put("type", Constants.PUBLISH_EVENTS); + pubRelations.put("target", publishes.getConfig_key() + Constants._TOPIC); + } else if(blueprintHelperService.isDataRouterType(publishes.getType())){ + pubRelations.put("type", Constants.PUBLISH_FILES); + pubRelations.put("target", publishes.getConfig_key() + Constants._FEED); + } + relationships.add(pubRelations); + } + } + + if(onapComponentSpec.getStreams().getSubscribes() != null) { + for(Subscribes subscribes: onapComponentSpec.getStreams().getSubscribes()) { + Map subRelations = new LinkedHashMap(); + if(blueprintHelperService.isMessageRouterType(subscribes.getType())){ + subRelations.put("type", Constants.SUBSCRIBE_TO_EVENTS); + subRelations.put("target", subscribes.getConfig_key() + Constants._TOPIC); + } else if(blueprintHelperService.isDataRouterType(subscribes.getType())){ + subRelations.put("type", Constants.SUBSCRIBE_TO_FILES); + subRelations.put("target", subscribes.getConfig_key() + Constants._FEED); + } + relationships.add(subRelations); + } + } + + if(onapComponentSpec.getPolicyInfo() != null){ + List> policyRelationshipsList = policyNodeService.getPolicyRelationships(onapComponentSpec); + relationships.addAll(policyRelationshipsList); + } + + if(onapComponentSpec.getAuxilary().getDatabases() != null){ + List> pgaasRelationshipsList = pgaasNodeService.getPgaasNodeRelationships(onapComponentSpec); + relationships.addAll(pgaasRelationshipsList); + } + + dmaapNode.setRelationships(relationships); + + Map propertiesResponse = propertiesService.createDmaapProperties(inputs, onapComponentSpec, override); + inputs = (Map>) propertiesResponse.get("inputs"); + dmaapNode.setProperties((org.onap.blueprintgenerator.model.common.Properties)propertiesResponse.get("properties")); + + response.put("dmaapNode", dmaapNode); + response.put("inputs", inputs); + return response; + } + + // method to create Feed Node for Streams + public Map createFeedNode(Map> inputs, String name){ + Map response = new HashMap<>(); + Node feedNode = new Node(); + + LinkedHashMap stringType = new LinkedHashMap(); + stringType.put("type", "string"); + + feedNode.setType(Constants.FEED); + + org.onap.blueprintgenerator.model.common.Properties props = new org.onap.blueprintgenerator.model.common.Properties(); + GetInput topicInput = new GetInput(); + topicInput.setBpInputName(name + "_name"); + props.setFeed_name(topicInput); + props.setUseExisting(true); + inputs.put(name + "_name", stringType); + feedNode.setProperties(props); + + response.put("feedNode", feedNode); + response.put("inputs", inputs); + return response; + } + + // method to create Topic Node for Streams + public Map createTopicNode(Map> inputs, String name){ + Map response = new HashMap<>(); + Node topicNode = new Node(); + + LinkedHashMap stringType = new LinkedHashMap(); + stringType.put("type", "string"); + + topicNode.setType(Constants.TOPIC); + + org.onap.blueprintgenerator.model.common.Properties props = new Properties(); + GetInput topicInput = new GetInput(); + topicInput.setBpInputName(name + "_name"); + props.setTopic_name(topicInput); + inputs.put(name + "_name", stringType); + topicNode.setProperties(props); + + response.put("topicNode", topicNode); + response.put("inputs", inputs); + return response; + } + + +} -- cgit 1.2.3-korg