40770f38a3e9c7b598e55520e8aebb434bfe51df
[dcaegen2/platform/cli.git] / blueprint-generator / src / main / java / org / onap / blueprintgenerator / models / blueprint / Properties.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.LinkedHashMap;
24 import java.util.TreeMap;
25
26 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
27 import org.onap.blueprintgenerator.models.componentspec.HealthCheck;
28 import org.onap.blueprintgenerator.models.componentspec.Volumes;
29 import org.onap.blueprintgenerator.models.onapbp.LogDirectory;
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 Properties {
39         private Appconfig application_config;
40         private HealthCheck docker_config;
41         private Object image;
42         private GetInput log_info;
43         private String dns_name;
44         private Object replicas;
45         private String name;
46
47         public TreeMap<String, LinkedHashMap<String, Object>> createOnapProperties(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs) {
48                 TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>();
49                 retInputs = inps;
50
51                 //set the image
52                 GetInput image = new GetInput();
53                 image.setGet_input("tag_version");
54                 this.setImage(image);
55                 LinkedHashMap<String, Object> img = new LinkedHashMap<String, Object>();
56                 img.put("type", "string");
57                 img.put("default", cs.getArtifacts()[0].getUri());
58                 retInputs.put("tag_version", img);
59
60                 //set the log info
61                 GetInput logD = new GetInput();
62                 logD.setGet_input("log_directory");
63                 this.setLog_info(logD);
64                 String logger = "";
65                 if(cs.getAuxilary().getVolumes() != null) {
66                         for(Volumes v: cs.getAuxilary().getVolumes()) {
67                                 if(v.getContainer().getBind().contains("/opt/app/") && v.getContainer().getBind().contains("logs")) {
68                                         logger = v.getContainer().getBind();
69                                 }
70                         }
71                 }
72
73                 LinkedHashMap<String, Object> logInp = new LinkedHashMap<String, Object>();
74                 logInp.put("type", "string");
75                 if(logger != "") {
76                         logInp.put("default", logger);
77                 }
78                 retInputs.put("log_directory", logInp);
79                 
80                 //set the replicas
81                 GetInput replica = new GetInput();
82                 replica.setGet_input("replicas");
83                 this.setReplicas(replica);
84                 LinkedHashMap<String, Object> rep = new LinkedHashMap<String, Object>();
85                 rep.put("type", "integer");
86                 rep.put("description", "number of instances");
87                 rep.put("default", 1);
88                 retInputs.put("replicas", rep);
89
90                 //set the dns name
91                 this.setDns_name(cs.getSelf().getName());
92                 
93                 //set the name
94                 this.setName(cs.getSelf().getName());
95
96                 //set the docker config
97                 this.setDocker_config(cs.getAuxilary().getHealthcheck());
98
99                 //set the app config
100                 Appconfig app = new Appconfig();
101                 retInputs = app.createOnapAppconfig(retInputs, cs);
102                 this.setApplication_config(app);
103
104                 return retInputs;
105         }
106
107 //      public void createTemplateProperties(ComponentSpec cs) {
108 //              //create dummy inputs just for methods
109 //              TreeMap<String, LinkedHashMap<String, Object>> inps = new TreeMap<String, LinkedHashMap<String, Object>>();
110 //              
111 //              //set the image
112 //              GetInput image = new GetInput();
113 //              image.setGet_input("tag_version");
114 //              this.setImage(image);
115 //              
116 //              //set the log info
117 //              LogDirectory log = new LogDirectory();
118 //              log.setLog_directory("Log directory");
119 //              this.setLog_info(log);
120 //
121 //              //set the replicas
122 //              GetInput replica = new GetInput();
123 //              replica.setGet_input("replicas");
124 //              this.setReplicas(replica);
125 //
126 //              //set the dns name
127 //              this.setDns_name("blueprint_template");
128 //              
129 //              //set the docker config
130 //              this.setDocker_config(cs.getAuxilary().getHealthcheck());
131 //              
132 //              //set the app config
133 //              Appconfig app = new Appconfig();
134 //              app.createTemplateAppconfig();
135 //              this.setApplication_config(app);
136 //      }
137
138 }