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 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();
73 LinkedHashMap<String, Object> logInp = new LinkedHashMap<String, Object>();
74 logInp.put("type", "string");
76 logInp.put("default", logger);
78 retInputs.put("log_directory", logInp);
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);
91 this.setDns_name(cs.getSelf().getName());
94 this.setName(cs.getSelf().getName());
96 //set the docker config
97 this.setDocker_config(cs.getAuxilary().getHealthcheck());
100 Appconfig app = new Appconfig();
101 retInputs = app.createOnapAppconfig(retInputs, cs);
102 this.setApplication_config(app);
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>>();
112 // GetInput image = new GetInput();
113 // image.setGet_input("tag_version");
114 // this.setImage(image);
116 // //set the log info
117 // LogDirectory log = new LogDirectory();
118 // log.setLog_directory("Log directory");
119 // this.setLog_info(log);
121 // //set the replicas
122 // GetInput replica = new GetInput();
123 // replica.setGet_input("replicas");
124 // this.setReplicas(replica);
126 // //set the dns name
127 // this.setDns_name("blueprint_template");
129 // //set the docker config
130 // this.setDocker_config(cs.getAuxilary().getHealthcheck());
132 // //set the app config
133 // Appconfig app = new Appconfig();
134 // app.createTemplateAppconfig();
135 // this.setApplication_config(app);