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.dmaap;
26 import org.onap.blueprintgenerator.constants.Constants;
27 import org.onap.blueprintgenerator.exception.BlueprintException;
28 import org.onap.blueprintgenerator.model.common.Input;
29 import org.onap.blueprintgenerator.model.common.Node;
30 import org.onap.blueprintgenerator.model.common.OnapBlueprint;
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.onap.blueprintgenerator.service.base.BlueprintService;
36 import org.onap.blueprintgenerator.service.common.ImportsService;
37 import org.onap.blueprintgenerator.service.common.NodeService;
38 import org.onap.blueprintgenerator.service.common.PgaasNodeService;
39 import org.onap.blueprintgenerator.service.common.PolicyNodeService;
40 import org.onap.blueprintgenerator.service.common.QuotationService;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.stereotype.Service;
43 import org.springframework.util.StringUtils;
45 import java.util.LinkedHashMap;
47 import java.util.TreeMap;
50 * @author : Ravi Mantena
52 * Application: ONAP - Blueprint Generator
53 * Service to create DMAAP Blueprint
57 public class DmaapBlueprintService extends BlueprintService {
60 protected ImportsService importsService;
63 private NodeService nodeService;
66 private PolicyNodeService policyNodeService;
69 private PgaasNodeService pgaasNodeService;
72 private QuotationService quotationService;
75 private BlueprintHelperService blueprintHelperService;
77 // method to generate Dmaap Blueprint
78 public OnapBlueprint createBlueprint(OnapComponentSpec onapComponentSpec, Input input) {
80 OnapBlueprint blueprint = new OnapBlueprint();
81 blueprint.setTosca_definitions_version(Constants.TOSCA_DEF_VERSION);
82 blueprint.setDescription(onapComponentSpec.getSelf().getDescription());
84 Map<String, LinkedHashMap<String, Object>> inputs = new TreeMap<>();
86 //if (!"".equals(input.getImportPath()))
87 if (!StringUtils.isEmpty(input.getImportPath()) )
88 blueprint.setImports(importsService.createImportsFromFile(input.getImportPath()));
90 blueprint.setImports(importsService.createImports(input.getBpType()));
92 Map<String, Node> nodeTemplate = new TreeMap();
94 Map<String, Object> dmaapNodeResponse = nodeService.createDmaapNode(onapComponentSpec, inputs, input.getServiceNameOverride());
95 inputs = (Map<String, LinkedHashMap<String, Object>>) dmaapNodeResponse.get("inputs");
96 nodeTemplate.put(onapComponentSpec.getSelf().getName(), (Node) dmaapNodeResponse.get("dmaapNode"));
98 if (onapComponentSpec.getStreams() != null) {
99 if (onapComponentSpec.getStreams().getPublishes() != null) {
100 for (Publishes publishes : onapComponentSpec.getStreams().getPublishes()) {
101 if (blueprintHelperService.isMessageRouterType(publishes.getType())) {
102 String topic = publishes.getConfig_key() + Constants._TOPIC;
103 Map<String, Object> topicNodeResponse = nodeService.createTopicNode(inputs, topic);
104 inputs = (Map<String, LinkedHashMap<String, Object>>) topicNodeResponse.get("inputs");
105 nodeTemplate.put(topic, (Node) topicNodeResponse.get("topicNode"));
106 } else if (blueprintHelperService.isDataRouterType(publishes.getType())) {
107 String feed = publishes.getConfig_key() + Constants._FEED;
108 Map<String, Object> feedNodeResponse = nodeService.createFeedNode(inputs, feed);
109 inputs = (Map<String, LinkedHashMap<String, Object>>) feedNodeResponse.get("inputs");
110 nodeTemplate.put(feed, (Node) feedNodeResponse.get("feedNode"));
114 if (onapComponentSpec.getStreams().getSubscribes() != null) {
115 for (Subscribes s : onapComponentSpec.getStreams().getSubscribes()) {
116 if (blueprintHelperService.isMessageRouterType(s.getType())) {
117 String topic = s.getConfig_key() + Constants._TOPIC;
118 Map<String, Object> topicNodeResponse = nodeService.createTopicNode(inputs, topic);
119 inputs = (Map<String, LinkedHashMap<String, Object>>) topicNodeResponse.get("inputs");
120 nodeTemplate.put(topic, (Node) topicNodeResponse.get("topicNode"));
121 } else if (blueprintHelperService.isDataRouterType(s.getType())) {
122 String feed = s.getConfig_key() + Constants._FEED;
123 Map<String, Object> feedNodeResponse = nodeService.createFeedNode(inputs, feed);
124 inputs = (Map<String, LinkedHashMap<String, Object>>) feedNodeResponse.get("inputs");
125 nodeTemplate.put(feed, (Node) feedNodeResponse.get("feedNode"));
131 if (onapComponentSpec.getPolicyInfo() != null)
132 policyNodeService.addPolicyNodesAndInputs(onapComponentSpec, nodeTemplate, inputs);
134 if (onapComponentSpec.getAuxilary() != null && onapComponentSpec.getAuxilary().getDatabases() != null)
135 pgaasNodeService.addPgaasNodesAndInputs(onapComponentSpec, nodeTemplate, inputs);
137 blueprint.setNode_templates(nodeTemplate);
138 blueprint.setInputs(inputs);
139 return quotationService.setQuotations(blueprint);
140 } catch (Exception ex) {
141 throw new BlueprintException("Unable to create ONAP DMAAP Blueprint Object from given input parameters", ex);