3 * * ============LICENSE_START=======================================================
5 * * ================================================================================
6 * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
7 * * Copyright (c) 2020 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.dmaap;
27 import org.onap.blueprintgenerator.constants.Constants;
28 import org.onap.blueprintgenerator.exception.BlueprintException;
29 import org.onap.blueprintgenerator.model.common.Input;
30 import org.onap.blueprintgenerator.model.common.Node;
31 import org.onap.blueprintgenerator.model.common.OnapBlueprint;
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.onap.blueprintgenerator.service.base.BlueprintService;
37 import org.onap.blueprintgenerator.service.common.ImportsService;
38 import org.onap.blueprintgenerator.service.common.NodeService;
39 import org.onap.blueprintgenerator.service.common.PgaasNodeService;
40 import org.onap.blueprintgenerator.service.common.PolicyNodeService;
41 import org.onap.blueprintgenerator.service.common.QuotationService;
42 import org.springframework.beans.factory.annotation.Autowired;
43 import org.springframework.stereotype.Service;
44 import org.springframework.util.StringUtils;
46 import java.util.LinkedHashMap;
48 import java.util.TreeMap;
51 * @author : Ravi Mantena
52 * @date 10/16/2020 Application: ONAP - Blueprint Generator Service to create DMAAP Blueprint
55 public class DmaapBlueprintCreatorService {
58 protected ImportsService importsService;
61 private NodeService nodeService;
64 private PolicyNodeService policyNodeService;
67 private PgaasNodeService pgaasNodeService;
70 private QuotationService quotationService;
73 private BlueprintHelperService blueprintHelperService;
76 * Creates Dmaap Blueprint
78 * @param onapComponentSpec OnapComponentSpec
82 public OnapBlueprint createBlueprint(OnapComponentSpec onapComponentSpec, Input input) {
84 OnapBlueprint blueprint = new OnapBlueprint();
85 blueprint.setTosca_definitions_version(Constants.TOSCA_DEF_VERSION);
86 blueprint.setDescription(onapComponentSpec.getSelf().getDescription());
88 Map<String, LinkedHashMap<String, Object>> inputs = new TreeMap<>();
90 // if (!"".equals(input.getImportPath()))
91 if (!StringUtils.isEmpty(input.getImportPath())) {
92 blueprint.setImports(importsService.createImportsFromFile(input.getImportPath()));
94 blueprint.setImports(importsService.createImports(input.getBpType()));
97 Map<String, Node> nodeTemplate = new TreeMap();
99 Map<String, Object> dmaapNodeResponse =
101 .createDmaapNode(onapComponentSpec, inputs, input.getServiceNameOverride());
102 inputs = (Map<String, LinkedHashMap<String, Object>>) dmaapNodeResponse.get("inputs");
104 onapComponentSpec.getSelf().getName(), (Node) dmaapNodeResponse.get("dmaapNode"));
106 if (onapComponentSpec.getStreams() != null) {
107 if (onapComponentSpec.getStreams().getPublishes() != null) {
108 for (Publishes publishes : onapComponentSpec.getStreams().getPublishes()) {
109 if (blueprintHelperService.isMessageRouterType(publishes.getType())) {
110 String topic = publishes.getConfig_key() + Constants._TOPIC;
111 Map<String, Object> topicNodeResponse = nodeService
112 .createTopicNode(inputs, topic);
113 inputs = (Map<String, LinkedHashMap<String, Object>>) topicNodeResponse
115 nodeTemplate.put(topic, (Node) topicNodeResponse.get("topicNode"));
116 } else if (blueprintHelperService.isDataRouterType(publishes.getType())) {
117 String feed = publishes.getConfig_key() + Constants._FEED;
118 Map<String, Object> feedNodeResponse = nodeService
119 .createFeedNode(inputs, feed);
120 inputs = (Map<String, LinkedHashMap<String, Object>>) feedNodeResponse
122 nodeTemplate.put(feed, (Node) feedNodeResponse.get("feedNode"));
126 if (onapComponentSpec.getStreams().getSubscribes() != null) {
127 for (Subscribes s : onapComponentSpec.getStreams().getSubscribes()) {
128 if (blueprintHelperService.isMessageRouterType(s.getType())) {
129 String topic = s.getConfig_key() + Constants._TOPIC;
130 Map<String, Object> topicNodeResponse = nodeService
131 .createTopicNode(inputs, topic);
132 inputs = (Map<String, LinkedHashMap<String, Object>>) topicNodeResponse
134 nodeTemplate.put(topic, (Node) topicNodeResponse.get("topicNode"));
135 } else if (blueprintHelperService.isDataRouterType(s.getType())) {
136 String feed = s.getConfig_key() + Constants._FEED;
137 Map<String, Object> feedNodeResponse = nodeService
138 .createFeedNode(inputs, feed);
139 inputs = (Map<String, LinkedHashMap<String, Object>>) feedNodeResponse
141 nodeTemplate.put(feed, (Node) feedNodeResponse.get("feedNode"));
147 if (onapComponentSpec.getPolicyInfo() != null) {
148 policyNodeService.addPolicyNodesAndInputs(onapComponentSpec, nodeTemplate, inputs);
151 if (onapComponentSpec.getAuxilary() != null
152 && onapComponentSpec.getAuxilary().getDatabases() != null) {
153 pgaasNodeService.addPgaasNodesAndInputs(onapComponentSpec, nodeTemplate, inputs);
156 blueprint.setNode_templates(nodeTemplate);
157 blueprint.setInputs(inputs);
158 return quotationService.setQuotations(blueprint);
159 } catch (Exception ex) {
160 throw new BlueprintException(
161 "Unable to create ONAP DMAAP Blueprint Object from given input parameters", ex);