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.models.blueprint.GetInput;
28 import org.onap.blueprintgenerator.models.blueprint.Interfaces;
29 import org.onap.blueprintgenerator.models.blueprint.Node;
30 import org.onap.blueprintgenerator.models.blueprint.Properties;
31 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
32 import org.onap.blueprintgenerator.models.componentspec.Publishes;
33 import org.onap.blueprintgenerator.models.componentspec.Subscribes;
34 import org.onap.blueprintgenerator.models.onapbp.OnapNode;
36 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
37 import com.fasterxml.jackson.annotation.JsonInclude;
38 import com.fasterxml.jackson.annotation.JsonInclude.Include;
40 import lombok.EqualsAndHashCode;
42 import lombok.NoArgsConstructor;
45 @JsonIgnoreProperties(ignoreUnknown = true)
47 @EqualsAndHashCode(callSuper=false)
49 @JsonInclude(value=Include.NON_NULL)
51 public class DmaapNode extends Node{
53 private TreeMap<String, Interfaces> interfaces;
54 private Properties properties;
55 private ArrayList<LinkedHashMap<String, String>> relationships;
57 public TreeMap<String, LinkedHashMap<String, Object>> createDmaapNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String override) {
58 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
61 this.setType("dcae.nodes.ContainerizedServiceComponentUsingDmaap");
63 //create the interface
64 Interfaces inter = new Interfaces();
65 retInputs = inter.createInterface(retInputs, cs);
66 TreeMap<String, Interfaces> interfaces = new TreeMap<String, Interfaces>();
67 interfaces.put("cloudify.interfaces.lifecycle", inter);
68 this.setInterfaces(interfaces);
70 //create and set the relationships
71 ArrayList<LinkedHashMap<String, String>> rets = new ArrayList();
73 //go through the streams publishes
75 if(cs.getStreams().getPublishes() != null) {
76 for(Publishes p: cs.getStreams().getPublishes()) {
77 LinkedHashMap<String, String> pubRelations = new LinkedHashMap();
78 if(p.getType().equals("message_router") || p.getType().equals("message router")) {
79 pubRelations.put("type", "ccsdk.relationships.publish_events");
80 pubRelations.put("target", "topic" + counter);
81 } else if(p.getType().equals("data_router") || p.getType().equals("data router")) {
82 pubRelations.put("type", "ccsdk.relationships.publish_files");
83 pubRelations.put("target", "feed" + counter);
85 rets.add(pubRelations);
89 //go through the stream subscribes
90 if(cs.getStreams().getSubscribes() != null) {
91 for(Subscribes s: cs.getStreams().getSubscribes()) {
92 LinkedHashMap<String, String> subRelations = new LinkedHashMap();
93 if(s.getType().equals("message_router") || s.getType().equals("message router")) {
94 subRelations.put("type", "ccsdk.relationships.subscribe_to_events");
95 subRelations.put("target", "topic" + counter);
96 } else if(s.getType().equals("data_router") || s.getType().equals("data router")) {
97 subRelations.put("type", "ccsdk.relationships.subscribe_to_files");
98 subRelations.put("target", "feed" + counter);
100 rets.add(subRelations);
105 this.setRelationships(rets);
107 //create and set the properties
108 Properties props = new Properties();
109 retInputs = props.createDmaapProperties(retInputs, cs, override);
110 this.setProperties(props);
114 public TreeMap<String, LinkedHashMap<String, Object>> createFeedNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String name){
115 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
116 LinkedHashMap<String, Object> stringType = new LinkedHashMap();
117 stringType.put("type", "string");
120 this.setType("ccsdk.nodes.Feed");
122 //create and set the properties
123 Properties props = new Properties();
124 GetInput topicInput = new GetInput();
125 topicInput.setGet_input(name + "_name");
126 props.setFeed_name(topicInput);
127 //props.setUseExisting(true);
128 retInputs.put(name + "_name", stringType);
129 this.setProperties(props);
134 public TreeMap<String, LinkedHashMap<String, Object>> createTopicNode(ComponentSpec cs, 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.setGet_input(name + "_name");
146 props.setTopic_name(topicInput);
147 //props.setUseExisting(true);
148 retInputs.put(name + "_name", stringType);
149 this.setProperties(props);