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.blueprint;
23 import java.util.ArrayList;
24 import java.util.LinkedHashMap;
25 import java.util.TreeMap;
27 import org.onap.blueprintgenerator.models.componentspec.Auxilary;
28 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
29 import org.onap.blueprintgenerator.models.componentspec.Publishes;
30 import org.onap.blueprintgenerator.models.componentspec.Subscribes;
31 import org.onap.blueprintgenerator.models.dmaapbp.DmaapStreams;
33 import com.fasterxml.jackson.annotation.JsonInclude;
34 import com.fasterxml.jackson.annotation.JsonInclude.Include;
36 import lombok.Getter; import lombok.Setter;
39 @JsonInclude(value=Include.NON_NULL)
40 public class Properties {
41 private Appconfig application_config;
42 private Auxilary docker_config;
44 private GetInput location_id;
45 private String service_component_type;
46 private TreeMap<String, Object> log_info;
47 private String dns_name;
48 private Object replicas;
50 private GetInput topic_name;
51 private GetInput feed_name;
52 ArrayList<DmaapStreams> streams_publishes;
53 ArrayList<DmaapStreams> streams_subscribes;
54 private TlsInfo tls_info;
55 private ResourceConfig resource_config;
56 private GetInput always_pull_image;
57 //private boolean useExisting;
59 public TreeMap<String, LinkedHashMap<String, Object>> createOnapProperties(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) {
60 TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>();
64 GetInput image = new GetInput();
65 image.setGet_input("image");
67 LinkedHashMap<String, Object> img = new LinkedHashMap<String, Object>();
68 img.put("type", "string");
69 img.put("default", cs.getArtifacts()[0].getUri());
70 retInputs.put("image", img);
73 GetInput location = new GetInput();
74 location.setGet_input("location_id");
75 this.setLocation_id(location);
76 LinkedHashMap<String, Object> locMap = new LinkedHashMap();
77 locMap.put("type", "string");
78 locMap.put("default", "");
79 retInputs.put("location_id", locMap);
82 this.setLog_info(cs.getAuxilary().getLog_info());
85 GetInput replica = new GetInput();
86 replica.setGet_input("replicas");
87 this.setReplicas(replica);
88 LinkedHashMap<String, Object> rep = new LinkedHashMap<String, Object>();
89 rep.put("type", "integer");
90 rep.put("description", "number of instances");
91 rep.put("default", 1);
92 retInputs.put("replicas", rep);
95 //this.setDns_name(cs.getSelf().getName());
98 //this.setName(cs.getSelf().getName());
100 //set the docker config
101 Auxilary aux = cs.getAuxilary();
102 // if(aux.getPorts() != null) {
103 // retInputs = aux.createPorts(retInputs);
105 this.setDocker_config(aux);
108 Appconfig app = new Appconfig();
109 retInputs = app.createAppconfig(retInputs, cs, override, false);
110 this.setApplication_config(app);
112 // set always_pull_image
113 this.always_pull_image = new GetInput();
114 this.always_pull_image.setGet_input("always_pull_image");
115 LinkedHashMap<String, Object> inputAlwaysPullImage = new LinkedHashMap<String, Object>();
116 inputAlwaysPullImage.put("type", "boolean");
117 inputAlwaysPullImage.put("description", "Set to true if the image should always be pulled");
118 inputAlwaysPullImage.put("default", true);
119 retInputs.put("always_pull_image", inputAlwaysPullImage);
122 //set service component type
123 String sType = cs.getSelf().getName();
124 sType = sType.replace('.', '-');
125 this.setService_component_type(sType);
128 if(cs.getAuxilary().getTls_info() != null){
129 addTlsInfo(cs,retInputs);
132 //set the reource config
133 ResourceConfig resource = new ResourceConfig();
134 retInputs = resource.createResourceConfig(retInputs, cs.getSelf().getName());
135 this.setResource_config(resource);
140 public TreeMap<String, LinkedHashMap<String, Object>> createDmaapProperties(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) {
141 TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>();
145 GetInput image = new GetInput();
146 image.setGet_input("tag_version");
147 this.setImage(image);
148 LinkedHashMap<String, Object> img = new LinkedHashMap<String, Object>();
149 img.put("type", "string");
150 img.put("default", cs.getArtifacts()[0].getUri());
151 retInputs.put("tag_version", img);
154 //set the location id
155 GetInput location = new GetInput();
156 location.setGet_input("location_id");
157 this.setLocation_id(location);
158 LinkedHashMap<String, Object> locMap = new LinkedHashMap();
159 locMap.put("type", "string");
160 locMap.put("default", "");
161 retInputs.put("location_id", locMap);
164 this.setLog_info(cs.getAuxilary().getLog_info());
166 //set service component type
167 String sType = cs.getSelf().getName();
168 sType = sType.replace('.', '-');
169 this.setService_component_type(sType);
172 if(cs.getAuxilary().getTls_info() != null){
173 addTlsInfo(cs,retInputs);
177 GetInput replica = new GetInput();
178 replica.setGet_input("replicas");
179 this.setReplicas(replica);
180 LinkedHashMap<String, Object> rep = new LinkedHashMap<String, Object>();
181 rep.put("type", "integer");
182 rep.put("description", "number of instances");
183 rep.put("default", 1);
184 retInputs.put("replicas", rep);
186 // //set the dns name
187 // this.setDns_name(cs.getSelf().getName());
190 // this.setName(cs.getSelf().getName());
192 //set the docker config
193 Auxilary aux = cs.getAuxilary();
194 // if(aux.getPorts() != null) {
195 // retInputs = aux.createPorts(retInputs);
197 this.setDocker_config(aux);
200 Appconfig app = new Appconfig();
201 retInputs = app.createAppconfig(retInputs, cs, override, true);
202 this.setApplication_config(app);
204 //set the stream publishes
205 ArrayList<DmaapStreams> pubStreams = new ArrayList();
206 if(cs.getStreams().getPublishes() != null) {
207 for(Publishes p: cs.getStreams().getPublishes()) {
208 if(p.getType().equals("message_router") || p.getType().equals("message router")) {
209 String topic = p.getConfig_key() + "_topic";
210 DmaapStreams mrStreams = new DmaapStreams();
211 retInputs = mrStreams.createStreams(inps, cs, topic, p.getType(), p.getConfig_key(), p.getRoute(), 'p');
212 pubStreams.add(mrStreams);
214 else if(p.getType().equals("data_router") || p.getType().equals("data router")){
215 String feed = p.getConfig_key() + "_feed";
216 DmaapStreams drStreams = new DmaapStreams();
217 retInputs = drStreams.createStreams(inps, cs, feed, p.getType(), p.getConfig_key(), p.getRoute(), 'p');
218 pubStreams.add(drStreams);
223 //set the stream subscribes
224 ArrayList<DmaapStreams> subStreams = new ArrayList();
225 if(cs.getStreams().getSubscribes() != null) {
226 for(Subscribes s: cs.getStreams().getSubscribes()) {
227 if(s.getType().equals("message_router") || s.getType().equals("message router")) {
228 String topic = s.getConfig_key() + "_topic";
229 DmaapStreams mrStreams = new DmaapStreams();
230 retInputs = mrStreams.createStreams(inps, cs, topic, s.getType(), s.getConfig_key(), s.getRoute(), 's');
231 subStreams.add(mrStreams);
233 else if(s.getType().equals("data_router") || s.getType().equals("data router")){
234 String feed = s.getConfig_key() + "_feed";
235 DmaapStreams drStreams = new DmaapStreams();
236 retInputs = drStreams.createStreams(inps, cs, feed, s.getType(), s.getConfig_key(), s.getRoute(), 's');
237 subStreams.add(drStreams);
242 if(pubStreams.size() != 0) {
243 this.setStreams_publishes(pubStreams);
245 if(subStreams.size() != 0) {
246 this.setStreams_subscribes(subStreams);
249 //set the reource config
250 ResourceConfig resource = new ResourceConfig();
251 retInputs = resource.createResourceConfig(retInputs, cs.getSelf().getName());
252 this.setResource_config(resource);
258 private void addTlsInfo(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> retInputs) {
259 TlsInfo tlsInfo = new TlsInfo();
260 tlsInfo.setCertDirectory((String) cs.getAuxilary().getTls_info().get("cert_directory"));
261 GetInput useTLSFlag = new GetInput();
262 useTLSFlag.setGet_input("use_tls");
263 tlsInfo.setUseTls(useTLSFlag);
264 this.setTls_info(tlsInfo);
265 LinkedHashMap<String, Object> useTlsFlagInput = new LinkedHashMap<String, Object>();
266 useTlsFlagInput.put("type", "boolean");
267 useTlsFlagInput.put("description", "flag to indicate tls enable/disable");
268 useTlsFlagInput.put("default", cs.getAuxilary().getTls_info().get("use_tls"));
269 retInputs.put("use_tls", useTlsFlagInput);