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 private TreeMap<String, Interfaces> interfaces;
56 private Properties properties;
57 private ArrayList<LinkedHashMap<String, String>> relationships;
59 public TreeMap<String, LinkedHashMap<String, Object>> createDmaapNode(ComponentSpec cs, 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, cs);
68 TreeMap<String, Interfaces> interfaces = new TreeMap<String, Interfaces>();
69 interfaces.put("cloudify.interfaces.lifecycle", inter);
70 this.setInterfaces(interfaces);
72 //create and set the relationships
73 ArrayList<LinkedHashMap<String, String>> rets = new ArrayList();
75 //go through the streams publishes
76 if(cs.getStreams().getPublishes() != null) {
77 for(Publishes p: cs.getStreams().getPublishes()) {
78 LinkedHashMap<String, String> pubRelations = new LinkedHashMap();
79 if(p.getType().equals("message_router") || p.getType().equals("message router")) {
80 pubRelations.put("type", "ccsdk.relationships.publish_events");
81 pubRelations.put("target", p.getConfig_key() + "_topic");
82 } else if(p.getType().equals("data_router") || p.getType().equals("data router")) {
83 pubRelations.put("type", "ccsdk.relationships.publish_files");
84 pubRelations.put("target", p.getConfig_key() + "_feed");
86 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", s.getConfig_key() + "_topic");
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", s.getConfig_key() + "_feed");
100 rets.add(subRelations);
104 //add relationship for policy if exist
105 if(cs.getPolicyInfo() != null){
106 ArrayList<LinkedHashMap<String, String>> policyRelationshipsList = PolicyNodeBuilder.getPolicyRelationships(cs);
107 rets.addAll(policyRelationshipsList);
110 //add relationships and env_variables for pgaas dbs if exist
111 if(cs.getAuxilary().getDatabases() != null){
112 ArrayList<LinkedHashMap<String, String>> pgaasRelationshipsList = PgaasNodeBuilder.getPgaasNodeRelationships(cs);
113 rets.addAll(pgaasRelationshipsList);
116 this.setRelationships(rets);
118 //create and set the properties
119 Properties props = new Properties();
120 retInputs = props.createDmaapProperties(retInputs, cs, override);
121 this.setProperties(props);
125 public TreeMap<String, LinkedHashMap<String, Object>> createFeedNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String name){
126 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
127 LinkedHashMap<String, Object> stringType = new LinkedHashMap();
128 stringType.put("type", "string");
131 this.setType("ccsdk.nodes.Feed");
133 //create and set the properties
134 Properties props = new Properties();
135 GetInput topicInput = new GetInput();
136 topicInput.setGet_input(name + "_name");
137 props.setFeed_name(topicInput);
138 //props.setUseExisting(true);
139 retInputs.put(name + "_name", stringType);
140 this.setProperties(props);
145 public TreeMap<String, LinkedHashMap<String, Object>> createTopicNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String name){
146 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
147 LinkedHashMap<String, Object> stringType = new LinkedHashMap();
148 stringType.put("type", "string");
151 this.setType("ccsdk.nodes.Topic");
153 //create and set the properties
154 Properties props = new Properties();
155 GetInput topicInput = new GetInput();
156 topicInput.setGet_input(name + "_name");
157 props.setTopic_name(topicInput);
158 //props.setUseExisting(true);
159 retInputs.put(name + "_name", stringType);
160 this.setProperties(props);