3 * * ============LICENSE_START=======================================================
5 * * ================================================================================
6 * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
7 * * Copyright (c) 2020-2021 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;
47 import java.util.TreeMap;
50 * @author : Ravi Mantena
51 * @date 10/16/2020 Application: ONAP - Blueprint Generator Service to create DMAAP Blueprint
54 public class DmaapBlueprintCreatorService {
57 protected ImportsService importsService;
60 private NodeService nodeService;
63 private PolicyNodeService policyNodeService;
66 private PgaasNodeService pgaasNodeService;
69 private QuotationService quotationService;
72 private BlueprintHelperService blueprintHelperService;
75 * Creates Dmaap Blueprint
77 * @param onapComponentSpec OnapComponentSpec
81 public OnapBlueprint createBlueprint(OnapComponentSpec onapComponentSpec, Input input) {
83 OnapBlueprint blueprint = new OnapBlueprint();
84 blueprint.setTosca_definitions_version(Constants.TOSCA_DEF_VERSION);
85 blueprint.setDescription(onapComponentSpec.getSelf().getDescription());
87 Map<String, Map<String, Object>> inputs = new TreeMap<>();
89 if (!StringUtils.isEmpty(input.getImportPath())) {
90 blueprint.setImports(importsService.createImportsFromFile(input.getImportPath()));
92 blueprint.setImports(importsService.createImports(input.getBpType()));
95 Map<String, Node> nodeTemplate = new TreeMap();
97 Map<String, Object> dmaapNodeResponse =
99 .createDmaapNode(onapComponentSpec, inputs, input.getServiceNameOverride());
100 inputs = (Map<String, Map<String, Object>>) dmaapNodeResponse.get("inputs");
102 onapComponentSpec.getSelf().getName(), (Node) dmaapNodeResponse.get("dmaapNode"));
104 if (onapComponentSpec.getStreams() != null) {
105 if (onapComponentSpec.getStreams().getPublishes() != null) {
106 for (Publishes publishes : onapComponentSpec.getStreams().getPublishes()) {
107 if (blueprintHelperService.isMessageRouterType(publishes.getType())) {
108 String topic = publishes.getConfig_key() + Constants.A_TOPIC;
109 Map<String, Object> topicNodeResponse = nodeService
110 .createTopicNode(inputs, topic);
111 inputs = (Map<String, Map<String, Object>>) topicNodeResponse
113 nodeTemplate.put(topic, (Node) topicNodeResponse.get("topicNode"));
114 } else if (blueprintHelperService.isDataRouterType(publishes.getType())) {
115 String feed = publishes.getConfig_key() + Constants.A_FEED;
116 Map<String, Object> feedNodeResponse = nodeService
117 .createFeedNode(inputs, feed);
118 inputs = (Map<String, Map<String, Object>>) feedNodeResponse
120 nodeTemplate.put(feed, (Node) feedNodeResponse.get("feedNode"));
124 if (onapComponentSpec.getStreams().getSubscribes() != null) {
125 for (Subscribes s : onapComponentSpec.getStreams().getSubscribes()) {
126 if (blueprintHelperService.isMessageRouterType(s.getType())) {
127 String topic = s.getConfig_key() + Constants.A_TOPIC;
128 Map<String, Object> topicNodeResponse = nodeService
129 .createTopicNode(inputs, topic);
130 inputs = (Map<String, Map<String, Object>>) topicNodeResponse
132 nodeTemplate.put(topic, (Node) topicNodeResponse.get("topicNode"));
133 } else if (blueprintHelperService.isDataRouterType(s.getType())) {
134 String feed = s.getConfig_key() + Constants.A_FEED;
135 Map<String, Object> feedNodeResponse = nodeService
136 .createFeedNode(inputs, feed);
137 inputs = (Map<String, Map<String, Object>>) feedNodeResponse
139 nodeTemplate.put(feed, (Node) feedNodeResponse.get("feedNode"));
145 if (onapComponentSpec.getPolicyInfo() != null) {
146 policyNodeService.addPolicyNodesAndInputs(onapComponentSpec, nodeTemplate, inputs);
149 if (onapComponentSpec.getAuxilary() != null
150 && onapComponentSpec.getAuxilary().getDatabases() != null) {
151 pgaasNodeService.addPgaasNodesAndInputs(onapComponentSpec, nodeTemplate, inputs);
154 blueprint.setNode_templates(nodeTemplate);
155 blueprint.setInputs(inputs);
156 return quotationService.setQuotations(blueprint);
157 } catch (Exception ex) {
158 throw new BlueprintException(
159 "Unable to create ONAP DMAAP Blueprint Object from given input parameters", ex);