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 @JsonIgnoreProperties(ignoreUnknown = true)
48 @EqualsAndHashCode(callSuper=false)
50 @JsonInclude(value=Include.NON_NULL)
52 public class DmaapNode extends Node{
54 public TreeMap<String, LinkedHashMap<String, Object>> createDmaapNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String override) {
55 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
58 this.setType("dcae.nodes.ContainerizedServiceComponentUsingDmaap");
60 //create the interface
61 Interfaces inter = new Interfaces();
62 retInputs = inter.createInterface(retInputs, cs);
63 TreeMap<String, Interfaces> interfaces = new TreeMap<String, Interfaces>();
64 interfaces.put("cloudify.interfaces.lifecycle", inter);
65 this.setInterfaces(interfaces);
67 //create and set the relationships
68 ArrayList<LinkedHashMap<String, String>> rets = new ArrayList();
70 //go through the streams publishes
71 if(cs.getStreams().getPublishes() != null) {
72 for(Publishes p: cs.getStreams().getPublishes()) {
73 LinkedHashMap<String, String> pubRelations = new LinkedHashMap();
74 if(p.getType().equals("message_router") || p.getType().equals("message router")) {
75 pubRelations.put("type", "ccsdk.relationships.publish_events");
76 pubRelations.put("target", p.getConfig_key() + "_topic");
77 } else if(p.getType().equals("data_router") || p.getType().equals("data router")) {
78 pubRelations.put("type", "ccsdk.relationships.publish_files");
79 pubRelations.put("target", p.getConfig_key() + "_feed");
81 rets.add(pubRelations);
84 //go through the stream subscribes
85 if(cs.getStreams().getSubscribes() != null) {
86 for(Subscribes s: cs.getStreams().getSubscribes()) {
87 LinkedHashMap<String, String> subRelations = new LinkedHashMap();
88 if(s.getType().equals("message_router") || s.getType().equals("message router")) {
89 subRelations.put("type", "ccsdk.relationships.subscribe_to_events");
90 subRelations.put("target", s.getConfig_key() + "_topic");
91 } else if(s.getType().equals("data_router") || s.getType().equals("data router")) {
92 subRelations.put("type", "ccsdk.relationships.subscribe_to_files");
93 subRelations.put("target", s.getConfig_key() + "_feed");
95 rets.add(subRelations);
99 //add relationship for policy if exist
100 if(cs.getPolicyInfo() != null){
101 ArrayList<LinkedHashMap<String, String>> policyRelationshipsList = PolicyNodeBuilder.getPolicyRelationships(cs);
102 rets.addAll(policyRelationshipsList);
105 //add relationships and env_variables for pgaas dbs if exist
106 if(cs.getAuxilary().getDatabases() != null){
107 ArrayList<LinkedHashMap<String, String>> pgaasRelationshipsList = PgaasNodeBuilder.getPgaasNodeRelationships(cs);
108 rets.addAll(pgaasRelationshipsList);
111 this.setRelationships(rets);
113 //create and set the properties
114 Properties props = new Properties();
115 retInputs = props.createDmaapProperties(retInputs, cs, override);
116 this.setProperties(props);
120 public TreeMap<String, LinkedHashMap<String, Object>> createFeedNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String name){
121 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
122 LinkedHashMap<String, Object> stringType = new LinkedHashMap();
123 stringType.put("type", "string");
126 this.setType("ccsdk.nodes.Feed");
128 //create and set the properties
129 Properties props = new Properties();
130 GetInput topicInput = new GetInput();
131 topicInput.setBpInputName(name + "_name");
132 props.setFeed_name(topicInput);
133 //props.setUseExisting(true);
134 retInputs.put(name + "_name", stringType);
135 this.setProperties(props);
140 public TreeMap<String, LinkedHashMap<String, Object>> createTopicNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String name){
141 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
142 LinkedHashMap<String, Object> stringType = new LinkedHashMap();
143 stringType.put("type", "string");
146 this.setType("ccsdk.nodes.Topic");
148 //create and set the properties
149 Properties props = new Properties();
150 GetInput topicInput = new GetInput();
151 topicInput.setBpInputName(name + "_name");
152 props.setTopic_name(topicInput);
153 //props.setUseExisting(true);
154 retInputs.put(name + "_name", stringType);
155 this.setProperties(props);