Adjust BP-gen to correctly support DFC component spec - types
[dcaegen2/platform.git] / mod / bpgenerator / src / main / java / org / onap / blueprintgenerator / models / dmaapbp / DmaapBlueprint.java
1 /*============LICENSE_START=======================================================
2  org.onap.dcae
3  ================================================================================
4  Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
5  ================================================================================
6  Modifications Copyright (c) 2020 Nokia. 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
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
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=========================================================
20
21  */
22
23 package org.onap.blueprintgenerator.models.dmaapbp;
24
25 import java.util.LinkedHashMap;
26 import java.util.TreeMap;
27
28 import org.onap.blueprintgenerator.core.PgaasNodeBuilder;
29 import org.onap.blueprintgenerator.core.PolicyNodeBuilder;
30 import org.onap.blueprintgenerator.models.blueprint.Blueprint;
31 import org.onap.blueprintgenerator.models.blueprint.Node;
32 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
33 import org.onap.blueprintgenerator.models.componentspec.Publishes;
34 import org.onap.blueprintgenerator.models.componentspec.Subscribes;
35
36 import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.isDataRouterType;
37 import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.isMessageRouterType;
38 import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.joinUnderscore;
39 import static org.onap.blueprintgenerator.models.blueprint.Imports.createDmaapImports;
40 import static org.onap.blueprintgenerator.models.blueprint.Imports.createImportsFromFile;
41 import static org.onap.blueprintgenerator.models.blueprint.BpConstants.CLOUDIFY_DSL_1_3;
42
43 public class DmaapBlueprint extends Blueprint {
44
45     private static final String TOPIC = "topic";
46     private static final String FEED = "feed";
47
48     public Blueprint createDmaapBlueprint(ComponentSpec componentSpec, String importPath, String override) {
49         Blueprint blueprint = new Blueprint();
50
51         //set tosca definition
52         blueprint.setTosca_definitions_version(CLOUDIFY_DSL_1_3);
53
54         //set the description
55         blueprint.setDescription(componentSpec.getSelf().getDescription());
56
57         //create the inpus object that will be added to over the creation of the blueprint
58         TreeMap<String, LinkedHashMap<String, Object>> inps = new TreeMap<>();
59
60         //set the imports
61         if (importPath.equals("")) {
62             blueprint.setImports(createDmaapImports());
63         } else {
64             blueprint.setImports(createImportsFromFile(importPath));
65         }
66
67         //set and create the node templates
68         TreeMap<String, Node> nodeTemplate = new TreeMap();
69
70         //create and add the main dmaap node
71         DmaapNode dmaap = new DmaapNode();
72         inps = dmaap.createDmaapNode(componentSpec, inps, override);
73         nodeTemplate.put(componentSpec.getSelf().getName(), dmaap);
74
75         //create and add the topic/feed nodes
76
77         //go through the streams publishes
78         if (componentSpec.getStreams().getPublishes() != null) {
79             for (Publishes publisher : componentSpec.getStreams().getPublishes()) {
80                 if (isMessageRouterType(publisher.getType())) {
81                     String topic = joinUnderscore(publisher.getConfig_key(), TOPIC);
82                     DmaapNode topicNode = new DmaapNode();
83                     inps = topicNode.createTopicNode(componentSpec, inps, topic);
84                     nodeTemplate.put(topic, topicNode);
85                 } else if (isDataRouterType(publisher.getType())) {
86                     String feed = joinUnderscore(publisher.getConfig_key(), FEED);
87                     DmaapNode feedNode = new DmaapNode();
88                     inps = feedNode.createFeedNode(componentSpec, inps, feed);
89                     nodeTemplate.put(feed, feedNode);
90                 }
91             }
92         }
93         //go through the stream subscribes
94         if (componentSpec.getStreams().getSubscribes() != null) {
95             for (Subscribes subscriber : componentSpec.getStreams().getSubscribes()) {
96                 if (isMessageRouterType(subscriber.getType())) {
97                     String topic = joinUnderscore(subscriber.getConfig_key(), TOPIC);
98                     DmaapNode topicNode = new DmaapNode();
99                     inps = topicNode.createTopicNode(componentSpec, inps, topic);
100                     nodeTemplate.put(topic, topicNode);
101                 } else if (isDataRouterType(subscriber.getType())) {
102                     String feed = joinUnderscore(subscriber.getConfig_key(), FEED);
103                     DmaapNode feedNode = new DmaapNode();
104                     inps = feedNode.createFeedNode(componentSpec, inps, feed);
105                     nodeTemplate.put(feed, feedNode);
106                 }
107             }
108         }
109
110         //if present in component spec, populate policyNodes information in the blueprint
111         if (componentSpec.getPolicyInfo() != null) {
112             PolicyNodeBuilder.addPolicyNodesAndInputs(componentSpec, nodeTemplate, inps);
113         }
114
115         //if present in component spec, populate pgaasNodes information in the blueprint
116         if (componentSpec.getAuxilary().getDatabases() != null) {
117             PgaasNodeBuilder.addPgaasNodesAndInputs(componentSpec, nodeTemplate, inps);
118         }
119
120         blueprint.setNode_templates(nodeTemplate);
121
122         blueprint.setInputs(inps);
123         return blueprint;
124     }
125
126 }