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
51 * @date 10/16/2020 Application: ONAP - Blueprint Generator Service to create DMAAP Blueprint
54 public class DmaapBlueprintService extends BlueprintService {
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, LinkedHashMap<String, Object>> inputs = new TreeMap<>();
89 // if (!"".equals(input.getImportPath()))
90 if (!StringUtils.isEmpty(input.getImportPath())) {
91 blueprint.setImports(importsService.createImportsFromFile(input.getImportPath()));
93 blueprint.setImports(importsService.createImports(input.getBpType()));
96 Map<String, Node> nodeTemplate = new TreeMap();
98 Map<String, Object> dmaapNodeResponse =
100 .createDmaapNode(onapComponentSpec, inputs, input.getServiceNameOverride());
101 inputs = (Map<String, LinkedHashMap<String, Object>>) dmaapNodeResponse.get("inputs");
103 onapComponentSpec.getSelf().getName(), (Node) dmaapNodeResponse.get("dmaapNode"));
105 if (onapComponentSpec.getStreams() != null) {
106 if (onapComponentSpec.getStreams().getPublishes() != null) {
107 for (Publishes publishes : onapComponentSpec.getStreams().getPublishes()) {
108 if (blueprintHelperService.isMessageRouterType(publishes.getType())) {
109 String topic = publishes.getConfig_key() + Constants._TOPIC;
110 Map<String, Object> topicNodeResponse = nodeService
111 .createTopicNode(inputs, topic);
112 inputs = (Map<String, LinkedHashMap<String, Object>>) topicNodeResponse
114 nodeTemplate.put(topic, (Node) topicNodeResponse.get("topicNode"));
115 } else if (blueprintHelperService.isDataRouterType(publishes.getType())) {
116 String feed = publishes.getConfig_key() + Constants._FEED;
117 Map<String, Object> feedNodeResponse = nodeService
118 .createFeedNode(inputs, feed);
119 inputs = (Map<String, LinkedHashMap<String, Object>>) feedNodeResponse
121 nodeTemplate.put(feed, (Node) feedNodeResponse.get("feedNode"));
125 if (onapComponentSpec.getStreams().getSubscribes() != null) {
126 for (Subscribes s : onapComponentSpec.getStreams().getSubscribes()) {
127 if (blueprintHelperService.isMessageRouterType(s.getType())) {
128 String topic = s.getConfig_key() + Constants._TOPIC;
129 Map<String, Object> topicNodeResponse = nodeService
130 .createTopicNode(inputs, topic);
131 inputs = (Map<String, LinkedHashMap<String, Object>>) topicNodeResponse
133 nodeTemplate.put(topic, (Node) topicNodeResponse.get("topicNode"));
134 } else if (blueprintHelperService.isDataRouterType(s.getType())) {
135 String feed = s.getConfig_key() + Constants._FEED;
136 Map<String, Object> feedNodeResponse = nodeService
137 .createFeedNode(inputs, feed);
138 inputs = (Map<String, LinkedHashMap<String, Object>>) feedNodeResponse
140 nodeTemplate.put(feed, (Node) feedNodeResponse.get("feedNode"));
146 if (onapComponentSpec.getPolicyInfo() != null) {
147 policyNodeService.addPolicyNodesAndInputs(onapComponentSpec, nodeTemplate, inputs);
150 if (onapComponentSpec.getAuxilary() != null
151 && onapComponentSpec.getAuxilary().getDatabases() != null) {
152 pgaasNodeService.addPgaasNodesAndInputs(onapComponentSpec, nodeTemplate, inputs);
155 blueprint.setNode_templates(nodeTemplate);
156 blueprint.setInputs(inputs);
157 return quotationService.setQuotations(blueprint);
158 } catch (Exception ex) {
159 throw new BlueprintException(
160 "Unable to create ONAP DMAAP Blueprint Object from given input parameters", ex);