1 /*============LICENSE_START=======================================================
3 ================================================================================
4 Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
5 Copyright (c) 2020 Nokia. All rights reserved.
6 ================================================================================
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 ============LICENSE_END=========================================================
21 package org.onap.blueprintgenerator.models.dmaapbp;
23 import java.util.ArrayList;
24 import java.util.LinkedHashMap;
25 import java.util.TreeMap;
27 import org.onap.blueprintgenerator.core.PgaasNodeBuilder;
28 import org.onap.blueprintgenerator.core.PolicyNodeBuilder;
29 import org.onap.blueprintgenerator.models.blueprint.GetInput;
30 import org.onap.blueprintgenerator.models.blueprint.Interfaces;
31 import org.onap.blueprintgenerator.models.blueprint.Node;
32 import org.onap.blueprintgenerator.models.blueprint.Properties;
33 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
34 import org.onap.blueprintgenerator.models.componentspec.Publishes;
35 import org.onap.blueprintgenerator.models.componentspec.Subscribes;
37 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
38 import com.fasterxml.jackson.annotation.JsonInclude;
39 import com.fasterxml.jackson.annotation.JsonInclude.Include;
41 import lombok.EqualsAndHashCode;
43 import lombok.NoArgsConstructor;
46 import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.isDataRouterType;
47 import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.isMessageRouterType;
49 @JsonIgnoreProperties(ignoreUnknown = true)
52 @EqualsAndHashCode(callSuper = false)
54 @JsonInclude(value = Include.NON_NULL)
56 public class DmaapNode extends Node {
58 public TreeMap<String, LinkedHashMap<String, Object>> createDmaapNode(ComponentSpec componentSpec,
59 TreeMap<String, LinkedHashMap<String, Object>> inps, String override) {
60 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
63 this.setType("dcae.nodes.ContainerizedServiceComponentUsingDmaap");
65 //create the interface
66 Interfaces inter = new Interfaces();
67 retInputs = inter.createInterface(retInputs, componentSpec);
68 TreeMap<String, Interfaces> interfaces = new TreeMap<>();
69 interfaces.put("cloudify.interfaces.lifecycle", inter);
70 this.setInterfaces(interfaces);
72 //create and set the relationships
73 ArrayList<LinkedHashMap<String, String>> relationships = new ArrayList<>();
75 //go through the streams publishes
76 if (componentSpec.getStreams().getPublishes() != null) {
77 for (Publishes publishes : componentSpec.getStreams().getPublishes()) {
78 relationships.add(createTypeAndTargetPubRelations(publishes));
81 //go through the stream subscribes
82 if (componentSpec.getStreams().getSubscribes() != null) {
83 for (Subscribes subscribes : componentSpec.getStreams().getSubscribes()) {
84 relationships.add(createTypeAndTargetSubRelations(subscribes));
88 //add relationship for policy if exist
89 if (componentSpec.getPolicyInfo() != null) {
90 ArrayList<LinkedHashMap<String, String>> policyRelationshipsList = PolicyNodeBuilder
91 .getPolicyRelationships(componentSpec);
92 relationships.addAll(policyRelationshipsList);
95 //add relationships and env_variables for pgaas dbs if exist
96 if (componentSpec.getAuxilary().getDatabases() != null) {
97 ArrayList<LinkedHashMap<String, String>> pgaasRelationshipsList = PgaasNodeBuilder
98 .getPgaasNodeRelationships(componentSpec);
99 relationships.addAll(pgaasRelationshipsList);
102 this.setRelationships(relationships);
104 //create and set the properties
105 Properties props = new Properties();
106 retInputs = props.createDmaapProperties(retInputs, componentSpec, override);
107 this.setProperties(props);
112 public TreeMap<String, LinkedHashMap<String, Object>> createFeedNode(ComponentSpec cs,
113 TreeMap<String, LinkedHashMap<String, Object>> inps, String name) {
114 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
115 LinkedHashMap<String, Object> stringType = new LinkedHashMap<>();
116 stringType.put("type", "string");
119 this.setType("ccsdk.nodes.Feed");
121 //create and set the properties
122 Properties props = new Properties();
123 GetInput topicInput = new GetInput();
124 topicInput.setBpInputName(name + "_name");
125 props.setFeed_name(topicInput);
126 //props.setUseExisting(true);
127 retInputs.put(name + "_name", stringType);
128 this.setProperties(props);
133 public TreeMap<String, LinkedHashMap<String, Object>> createTopicNode(ComponentSpec cs,
134 TreeMap<String, LinkedHashMap<String, Object>> inps, String name) {
135 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
136 LinkedHashMap<String, Object> stringType = new LinkedHashMap<>();
137 stringType.put("type", "string");
140 this.setType("ccsdk.nodes.Topic");
142 //create and set the properties
143 Properties props = new Properties();
144 GetInput topicInput = new GetInput();
145 topicInput.setBpInputName(name + "_name");
146 props.setTopic_name(topicInput);
147 //props.setUseExisting(true);
148 retInputs.put(name + "_name", stringType);
149 this.setProperties(props);
154 private LinkedHashMap<String, String> createTypeAndTargetPubRelations(Publishes publishes) {
155 LinkedHashMap<String, String> pubRelations = new LinkedHashMap<>();
156 if (isMessageRouterType(publishes.getType())) {
157 pubRelations.put("type", "ccsdk.relationships.publish_events");
158 pubRelations.put("target", publishes.getConfig_key() + "_topic");
159 } else if (isDataRouterType(publishes.getType())) {
160 pubRelations.put("type", "ccsdk.relationships.publish_files");
161 pubRelations.put("target", publishes.getConfig_key() + "_feed");
166 private LinkedHashMap<String, String> createTypeAndTargetSubRelations(Subscribes subscribes) {
167 LinkedHashMap<String, String> subRelations = new LinkedHashMap<>();
168 if (isMessageRouterType(subscribes.getType())) {
169 subRelations.put("type", "ccsdk.relationships.subscribe_to_events");
170 subRelations.put("target", subscribes.getConfig_key() + "_topic");
171 } else if (isDataRouterType(subscribes.getType())) {
172 subRelations.put("type", "ccsdk.relationships.subscribe_to_files");
173 subRelations.put("target", subscribes.getConfig_key() + "_feed");