Commit for the blueprint generator java tool
[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                 for(Volumes v: cs.getAuxilary().getVolumes()) {
66                         if(v.getContainer().getBind().contains("/opt/app/") && v.getContainer().getBind().contains("logs")) {
67                                 logger = v.getContainer().getBind();
68                         }
69                 }
70                 LinkedHashMap<String, Object> logInp = new LinkedHashMap<String, Object>();
71                 logInp.put("type", "string");
72                 if(logger != "") {
73                         logInp.put("default", logger);
74                 }
75                 retInputs.put("log_directory", logInp);
76                 
77                 //set the replicas
78                 GetInput replica = new GetInput();
79                 replica.setGet_input("replicas");
80                 this.setReplicas(replica);
81                 LinkedHashMap<String, Object> rep = new LinkedHashMap<String, Object>();
82                 rep.put("type", "integer");
83                 rep.put("description", "number of instances");
84                 rep.put("default", 1);
85                 retInputs.put("replicas", rep);
86
87                 //set the dns name
88                 this.setDns_name(cs.getSelf().getName());
89                 
90                 //set the name
91                 this.setName(cs.getSelf().getName());
92
93                 //set the docker config
94                 this.setDocker_config(cs.getAuxilary().getHealthcheck());
95
96                 //set the app config
97                 Appconfig app = new Appconfig();
98                 retInputs = app.createOnapAppconfig(retInputs, cs);
99                 this.setApplication_config(app);
100
101                 return retInputs;
102         }
103
104 //      public void createTemplateProperties(ComponentSpec cs) {
105 //              //create dummy inputs just for methods
106 //              TreeMap<String, LinkedHashMap<String, Object>> inps = new TreeMap<String, LinkedHashMap<String, Object>>();
107 //              
108 //              //set the image
109 //              GetInput image = new GetInput();
110 //              image.setGet_input("tag_version");
111 //              this.setImage(image);
112 //              
113 //              //set the log info
114 //              LogDirectory log = new LogDirectory();
115 //              log.setLog_directory("Log directory");
116 //              this.setLog_info(log);
117 //
118 //              //set the replicas
119 //              GetInput replica = new GetInput();
120 //              replica.setGet_input("replicas");
121 //              this.setReplicas(replica);
122 //
123 //              //set the dns name
124 //              this.setDns_name("blueprint_template");
125 //              
126 //              //set the docker config
127 //              this.setDocker_config(cs.getAuxilary().getHealthcheck());
128 //              
129 //              //set the app config
130 //              Appconfig app = new Appconfig();
131 //              app.createTemplateAppconfig();
132 //              this.setApplication_config(app);
133 //      }
134
135 }