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 if(cs.getAuxilary().getTls_info() != null){
123 addTlsInfo(cs,retInputs);
126 //set the reource config
127 ResourceConfig resource = new ResourceConfig();
128 retInputs = resource.createResourceConfig(retInputs, cs.getSelf().getName());
129 this.setResource_config(resource);
134 public TreeMap<String, LinkedHashMap<String, Object>> createDmaapProperties(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) {
135 TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>();
139 GetInput image = new GetInput();
140 image.setGet_input("tag_version");
141 this.setImage(image);
142 LinkedHashMap<String, Object> img = new LinkedHashMap<String, Object>();
143 img.put("type", "string");
144 img.put("default", cs.getArtifacts()[0].getUri());
145 retInputs.put("tag_version", img);
148 this.setLog_info(cs.getAuxilary().getLog_info());
150 //set service component type
151 String sType = cs.getSelf().getName();
152 sType = sType.replace('.', '-');
153 this.setService_component_type(sType);
156 if(cs.getAuxilary().getTls_info() != null){
157 addTlsInfo(cs,retInputs);
161 GetInput replica = new GetInput();
162 replica.setGet_input("replicas");
163 this.setReplicas(replica);
164 LinkedHashMap<String, Object> rep = new LinkedHashMap<String, Object>();
165 rep.put("type", "integer");
166 rep.put("description", "number of instances");
167 rep.put("default", 1);
168 retInputs.put("replicas", rep);
170 // //set the dns name
171 // this.setDns_name(cs.getSelf().getName());
174 // this.setName(cs.getSelf().getName());
176 //set the docker config
177 Auxilary aux = cs.getAuxilary();
178 // if(aux.getPorts() != null) {
179 // retInputs = aux.createPorts(retInputs);
181 this.setDocker_config(aux);
184 Appconfig app = new Appconfig();
185 retInputs = app.createAppconfig(retInputs, cs, override, true);
186 this.setApplication_config(app);
188 //set the stream publishes
189 ArrayList<DmaapStreams> pubStreams = new ArrayList();
190 if(cs.getStreams().getPublishes() != null) {
191 for(Publishes p: cs.getStreams().getPublishes()) {
192 if(p.getType().equals("message_router") || p.getType().equals("message router")) {
193 String topic = p.getConfig_key() + "_topic";
194 DmaapStreams mrStreams = new DmaapStreams();
195 retInputs = mrStreams.createStreams(inps, cs, topic, p.getType(), p.getConfig_key(), p.getRoute(), 'p');
196 pubStreams.add(mrStreams);
198 else if(p.getType().equals("data_router") || p.getType().equals("data router")){
199 String feed = p.getConfig_key() + "_feed";
200 DmaapStreams drStreams = new DmaapStreams();
201 retInputs = drStreams.createStreams(inps, cs, feed, p.getType(), p.getConfig_key(), p.getRoute(), 'p');
202 pubStreams.add(drStreams);
207 //set the stream subscribes
208 ArrayList<DmaapStreams> subStreams = new ArrayList();
209 if(cs.getStreams().getSubscribes() != null) {
210 for(Subscribes s: cs.getStreams().getSubscribes()) {
211 if(s.getType().equals("message_router") || s.getType().equals("message router")) {
212 String topic = s.getConfig_key() + "_topic";
213 DmaapStreams mrStreams = new DmaapStreams();
214 retInputs = mrStreams.createStreams(inps, cs, topic, s.getType(), s.getConfig_key(), s.getRoute(), 's');
215 subStreams.add(mrStreams);
217 else if(s.getType().equals("data_router") || s.getType().equals("data router")){
218 String feed = s.getConfig_key() + "_feed";
219 DmaapStreams drStreams = new DmaapStreams();
220 retInputs = drStreams.createStreams(inps, cs, feed, s.getType(), s.getConfig_key(), s.getRoute(), 's');
221 subStreams.add(drStreams);
226 if(pubStreams.size() != 0) {
227 this.setStreams_publishes(pubStreams);
229 if(subStreams.size() != 0) {
230 this.setStreams_subscribes(subStreams);
233 //set the reource config
234 ResourceConfig resource = new ResourceConfig();
235 retInputs = resource.createResourceConfig(retInputs, cs.getSelf().getName());
236 this.setResource_config(resource);
242 private void addTlsInfo(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> retInputs) {
243 TlsInfo tlsInfo = new TlsInfo();
244 tlsInfo.setCertDirectory((String) cs.getAuxilary().getTls_info().get("cert_directory"));
245 GetInput useTLSFlag = new GetInput();
246 useTLSFlag.setGet_input("use_tls");
247 tlsInfo.setUseTls(useTLSFlag);
248 this.setTls_info(tlsInfo);
249 LinkedHashMap<String, Object> useTlsFlagInput = new LinkedHashMap<String, Object>();
250 useTlsFlagInput.put("type", "boolean");
251 useTlsFlagInput.put("description", "flag to indicate tls enable/disable");
252 useTlsFlagInput.put("default", cs.getAuxilary().getTls_info().get("use_tls"));
253 retInputs.put("use_tls", useTlsFlagInput);