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 import static org.onap.blueprintgenerator.models.blueprint.BpConstants.CONTENERIZED_SERVICE_COMPONENT_USING_DMAAP;
50 import static org.onap.blueprintgenerator.models.blueprint.BpConstants.FEED;
51 import static org.onap.blueprintgenerator.models.blueprint.BpConstants.TOPIC;
52 import static org.onap.blueprintgenerator.models.blueprint.BpConstants.PUBLISH_EVENTS;
53 import static org.onap.blueprintgenerator.models.blueprint.BpConstants.PUBLISH_FILES;
54 import static org.onap.blueprintgenerator.models.blueprint.BpConstants.SUBSCRIBE_TO_EVENTS;
55 import static org.onap.blueprintgenerator.models.blueprint.BpConstants.SUBSCRIBE_TO_FILES;
57 @JsonIgnoreProperties(ignoreUnknown = true)
60 @EqualsAndHashCode(callSuper = false)
62 @JsonInclude(value = Include.NON_NULL)
64 public class DmaapNode extends Node {
66 public TreeMap<String, LinkedHashMap<String, Object>> createDmaapNode(ComponentSpec componentSpec,
67 TreeMap<String, LinkedHashMap<String, Object>> inps, String override) {
68 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
71 this.setType(CONTENERIZED_SERVICE_COMPONENT_USING_DMAAP);
73 //create the interface
74 Interfaces inter = new Interfaces();
75 retInputs = inter.createInterface(retInputs, componentSpec);
76 TreeMap<String, Interfaces> interfaces = new TreeMap<>();
77 interfaces.put("cloudify.interfaces.lifecycle", inter);
78 this.setInterfaces(interfaces);
80 //create and set the relationships
81 ArrayList<LinkedHashMap<String, String>> relationships = new ArrayList<>();
83 //go through the streams publishes
84 if (componentSpec.getStreams().getPublishes() != null) {
85 for (Publishes publishes : componentSpec.getStreams().getPublishes()) {
86 relationships.add(createTypeAndTargetPubRelations(publishes));
89 //go through the stream subscribes
90 if (componentSpec.getStreams().getSubscribes() != null) {
91 for (Subscribes subscribes : componentSpec.getStreams().getSubscribes()) {
92 relationships.add(createTypeAndTargetSubRelations(subscribes));
96 //add relationship for policy if exist
97 if (componentSpec.getPolicyInfo() != null) {
98 ArrayList<LinkedHashMap<String, String>> policyRelationshipsList = PolicyNodeBuilder
99 .getPolicyRelationships(componentSpec);
100 relationships.addAll(policyRelationshipsList);
103 //add relationships and env_variables for pgaas dbs if exist
104 if (componentSpec.getAuxilary().getDatabases() != null) {
105 ArrayList<LinkedHashMap<String, String>> pgaasRelationshipsList = PgaasNodeBuilder
106 .getPgaasNodeRelationships(componentSpec);
107 relationships.addAll(pgaasRelationshipsList);
110 this.setRelationships(relationships);
112 //create and set the properties
113 Properties props = new Properties();
114 retInputs = props.createDmaapProperties(retInputs, componentSpec, override);
115 this.setProperties(props);
120 public TreeMap<String, LinkedHashMap<String, Object>> createFeedNode(ComponentSpec cs,
121 TreeMap<String, LinkedHashMap<String, Object>> inps, String name) {
122 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
123 LinkedHashMap<String, Object> stringType = new LinkedHashMap<>();
124 stringType.put("type", "string");
129 //create and set the properties
130 Properties props = new Properties();
131 GetInput topicInput = new GetInput();
132 topicInput.setBpInputName(name + "_name");
133 props.setFeed_name(topicInput);
134 //props.setUseExisting(true);
135 retInputs.put(name + "_name", stringType);
136 this.setProperties(props);
141 public TreeMap<String, LinkedHashMap<String, Object>> createTopicNode(ComponentSpec cs,
142 TreeMap<String, LinkedHashMap<String, Object>> inps, String name) {
143 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
144 LinkedHashMap<String, Object> stringType = new LinkedHashMap<>();
145 stringType.put("type", "string");
150 //create and set the properties
151 Properties props = new Properties();
152 GetInput topicInput = new GetInput();
153 topicInput.setBpInputName(name + "_name");
154 props.setTopic_name(topicInput);
155 //props.setUseExisting(true);
156 retInputs.put(name + "_name", stringType);
157 this.setProperties(props);
162 private LinkedHashMap<String, String> createTypeAndTargetPubRelations(Publishes publishes) {
163 LinkedHashMap<String, String> pubRelations = new LinkedHashMap<>();
164 if (isMessageRouterType(publishes.getType())) {
165 pubRelations.put("type", PUBLISH_EVENTS);
166 pubRelations.put("target", publishes.getConfig_key() + "_topic");
167 } else if (isDataRouterType(publishes.getType())) {
168 pubRelations.put("type", PUBLISH_FILES);
169 pubRelations.put("target", publishes.getConfig_key() + "_feed");
174 private LinkedHashMap<String, String> createTypeAndTargetSubRelations(Subscribes subscribes) {
175 LinkedHashMap<String, String> subRelations = new LinkedHashMap<>();
176 if (isMessageRouterType(subscribes.getType())) {
177 subRelations.put("type", SUBSCRIBE_TO_EVENTS);
178 subRelations.put("target", subscribes.getConfig_key() + "_topic");
179 } else if (isDataRouterType(subscribes.getType())) {
180 subRelations.put("type", SUBSCRIBE_TO_FILES);
181 subRelations.put("target", subscribes.getConfig_key() + "_feed");