1 /**============LICENSE_START=======================================================
3 ================================================================================
4 Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
5 ================================================================================
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ============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;
36 import org.onap.blueprintgenerator.models.onapbp.OnapNode;
38 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
39 import com.fasterxml.jackson.annotation.JsonInclude;
40 import com.fasterxml.jackson.annotation.JsonInclude.Include;
42 import lombok.EqualsAndHashCode;
44 import lombok.NoArgsConstructor;
47 @JsonIgnoreProperties(ignoreUnknown = true)
49 @EqualsAndHashCode(callSuper=false)
51 @JsonInclude(value=Include.NON_NULL)
53 public class DmaapNode extends Node{
55 public TreeMap<String, LinkedHashMap<String, Object>> createDmaapNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String override) {
56 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
59 this.setType("dcae.nodes.ContainerizedServiceComponentUsingDmaap");
61 //create the interface
62 Interfaces inter = new Interfaces();
63 retInputs = inter.createInterface(retInputs, cs);
64 TreeMap<String, Interfaces> interfaces = new TreeMap<String, Interfaces>();
65 interfaces.put("cloudify.interfaces.lifecycle", inter);
66 this.setInterfaces(interfaces);
68 //create and set the relationships
69 ArrayList<LinkedHashMap<String, String>> rets = new ArrayList();
71 //go through the streams publishes
72 if(cs.getStreams().getPublishes() != null) {
73 for(Publishes p: cs.getStreams().getPublishes()) {
74 LinkedHashMap<String, String> pubRelations = new LinkedHashMap();
75 if(p.getType().equals("message_router") || p.getType().equals("message router")) {
76 pubRelations.put("type", "ccsdk.relationships.publish_events");
77 pubRelations.put("target", p.getConfig_key() + "_topic");
78 } else if(p.getType().equals("data_router") || p.getType().equals("data router")) {
79 pubRelations.put("type", "ccsdk.relationships.publish_files");
80 pubRelations.put("target", p.getConfig_key() + "_feed");
82 rets.add(pubRelations);
85 //go through the stream subscribes
86 if(cs.getStreams().getSubscribes() != null) {
87 for(Subscribes s: cs.getStreams().getSubscribes()) {
88 LinkedHashMap<String, String> subRelations = new LinkedHashMap();
89 if(s.getType().equals("message_router") || s.getType().equals("message router")) {
90 subRelations.put("type", "ccsdk.relationships.subscribe_to_events");
91 subRelations.put("target", s.getConfig_key() + "_topic");
92 } else if(s.getType().equals("data_router") || s.getType().equals("data router")) {
93 subRelations.put("type", "ccsdk.relationships.subscribe_to_files");
94 subRelations.put("target", s.getConfig_key() + "_feed");
96 rets.add(subRelations);
100 //add relationship for policy if exist
101 if(cs.getPolicyInfo() != null){
102 ArrayList<LinkedHashMap<String, String>> policyRelationshipsList = PolicyNodeBuilder.getPolicyRelationships(cs);
103 rets.addAll(policyRelationshipsList);
106 //add relationships and env_variables for pgaas dbs if exist
107 if(cs.getAuxilary().getDatabases() != null){
108 ArrayList<LinkedHashMap<String, String>> pgaasRelationshipsList = PgaasNodeBuilder.getPgaasNodeRelationships(cs);
109 rets.addAll(pgaasRelationshipsList);
112 this.setRelationships(rets);
114 //create and set the properties
115 Properties props = new Properties();
116 retInputs = props.createDmaapProperties(retInputs, cs, override);
117 this.setProperties(props);
121 public TreeMap<String, LinkedHashMap<String, Object>> createFeedNode(ComponentSpec cs, 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");
127 this.setType("ccsdk.nodes.Feed");
129 //create and set the properties
130 Properties props = new Properties();
131 GetInput topicInput = new GetInput();
132 topicInput.setGet_input(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, TreeMap<String, LinkedHashMap<String, Object>> inps, String name){
142 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
143 LinkedHashMap<String, Object> stringType = new LinkedHashMap();
144 stringType.put("type", "string");
147 this.setType("ccsdk.nodes.Topic");
149 //create and set the properties
150 Properties props = new Properties();
151 GetInput topicInput = new GetInput();
152 topicInput.setGet_input(name + "_name");
153 props.setTopic_name(topicInput);
154 //props.setUseExisting(true);
155 retInputs.put(name + "_name", stringType);
156 this.setProperties(props);