Merge "Added policyNodes, db, tls support"
[dcaegen2/platform.git] / mod / bpgenerator / src / main / java / org / onap / blueprintgenerator / models / blueprint / StartInputs.java
1 /**============LICENSE_START======================================================= 
2  org.onap.dcae 
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 
9
10       http://www.apache.org/licenses/LICENSE-2.0 
11
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========================================================= 
18
19 */
20
21 package org.onap.blueprintgenerator.models.blueprint;
22
23 import java.util.ArrayList;
24 import java.util.LinkedHashMap;
25 import java.util.TreeMap;
26
27 import org.onap.blueprintgenerator.core.PgaasNodeBuilder;
28 import org.onap.blueprintgenerator.models.componentspec.Auxilary;
29 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
30
31 import com.fasterxml.jackson.annotation.JsonInclude;
32 import com.fasterxml.jackson.annotation.JsonInclude.Include;
33
34 import lombok.Getter; import lombok.Setter;
35
36 @Getter @Setter
37 @JsonInclude(value=Include.NON_NULL)
38 public class StartInputs {
39         private ArrayList<String> ports;
40         private Object envs;
41
42         public TreeMap<String, LinkedHashMap<String, Object>> createOnapStartInputs(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs){
43                 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
44
45                 int count = 0;
46                 ArrayList<String> portList = new ArrayList();
47                 Auxilary aux = cs.getAuxilary();
48
49                 if (aux.getPorts() != null) {
50
51                         for(Object p : aux.getPorts()) {
52                                 String[] ports = p.toString().split(":");
53                                 String internal
54                                                 = String.format("concat: [\"%s:\", {get_input: external_port_%d}]"
55                                                 , ports[0], count);
56                                 portList.add(internal);
57
58                                 LinkedHashMap<String, Object> portType = new LinkedHashMap();
59                                 portType.put("type", "string");
60                                 portType.put("default", ports[1]);
61                                 retInputs.put("external_port_" + count, portType);
62
63                                 count++;
64                         }
65
66                 }
67
68                 this.setPorts(portList);
69 //              ArrayList<String> port = new ArrayList<String>();
70 //              String external = "";
71 //              if(cs.getAuxilary().getPorts() != null) {
72 //                      for(String s: cs.getAuxilary().getPorts()) {
73 //                              //create the ports
74 //                              String portNumber = "";
75 //                              StringBuffer buf = new StringBuffer();
76 //                              for(int i = 0; i < s.length(); i++) {
77 //                                      if(!(s.charAt(i) == ':')) {
78 //                                              buf.append(s.charAt(i));
79 //                                      }
80 //                                      else {
81 //                                              external = s.replace(buf.toString() + ":", "");
82 //                                              break;
83 //                                      }
84 //                              }
85 //                              portNumber = buf.toString();
86 //                              String p = "concat: [" + '"' + portNumber + ":" + '"' +", {get_input: external_port }]";
87 //                              port.add(p);
88 //                      }
89 //              }
90 //              this.setPorts(port);
91 //              //add the external port input
92 //              if(cs.getAuxilary().getPorts() != null) {
93 //                      stringType.put("type", "string");
94 //                      stringType.put("description", "Kubernetes node port on which collector is exposed");
95 //                      stringType.put("default", "'" + external + "'") ;
96 //                      retInputs.put("external_port", stringType);
97 //              }
98
99                 //set the envs
100                 LinkedHashMap<String, Object> eMap = new LinkedHashMap();
101                 if(cs.getAuxilary().getDatabases() != null){
102                         //set db env variables
103                         LinkedHashMap<String, Object> envVars = PgaasNodeBuilder.getEnvVariables(cs.getAuxilary().getDatabases());
104                         this.setEnvs(envVars);
105                         eMap.put("default", "&envs {}");
106                 }
107                 else {
108                         GetInput env = new GetInput();
109                         env.setGet_input("envs");
110                         this.setEnvs(env);
111                         eMap.put("default", "{}");
112                 }
113                 retInputs.put("envs", eMap);
114
115
116                 return retInputs;
117         }
118 }