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.LinkedHashMap;
24 import java.util.TreeMap;
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;
31 import com.fasterxml.jackson.annotation.JsonInclude;
32 import com.fasterxml.jackson.annotation.JsonInclude.Include;
34 import lombok.Getter; import lombok.Setter;
37 @JsonInclude(value=Include.NON_NULL)
38 public class Properties {
39 private Appconfig application_config;
40 private HealthCheck docker_config;
42 private GetInput log_info;
43 private String dns_name;
44 private Object replicas;
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>>();
52 GetInput image = new GetInput();
53 image.setGet_input("tag_version");
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);
61 GetInput logD = new GetInput();
62 logD.setGet_input("log_directory");
63 this.setLog_info(logD);
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();
70 LinkedHashMap<String, Object> logInp = new LinkedHashMap<String, Object>();
71 logInp.put("type", "string");
73 logInp.put("default", logger);
75 retInputs.put("log_directory", logInp);
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);
88 this.setDns_name(cs.getSelf().getName());
91 this.setName(cs.getSelf().getName());
93 //set the docker config
94 this.setDocker_config(cs.getAuxilary().getHealthcheck());
97 Appconfig app = new Appconfig();
98 retInputs = app.createOnapAppconfig(retInputs, cs);
99 this.setApplication_config(app);
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>>();
109 // GetInput image = new GetInput();
110 // image.setGet_input("tag_version");
111 // this.setImage(image);
113 // //set the log info
114 // LogDirectory log = new LogDirectory();
115 // log.setLog_directory("Log directory");
116 // this.setLog_info(log);
118 // //set the replicas
119 // GetInput replica = new GetInput();
120 // replica.setGet_input("replicas");
121 // this.setReplicas(replica);
123 // //set the dns name
124 // this.setDns_name("blueprint_template");
126 // //set the docker config
127 // this.setDocker_config(cs.getAuxilary().getHealthcheck());
129 // //set the app config
130 // Appconfig app = new Appconfig();
131 // app.createTemplateAppconfig();
132 // this.setApplication_config(app);