Add external tls info to bpgenerator and component spec schema
[dcaegen2/platform.git] / mod / bpgenerator / src / main / java / org / onap / blueprintgenerator / models / blueprint / Properties.java
index 31df9c3..d7947f8 100644 (file)
@@ -1,8 +1,10 @@
-/**============LICENSE_START======================================================= 
- org.onap.dcae 
- ================================================================================ 
+/**============LICENSE_START=======================================================
+ org.onap.dcae
+ ================================================================================
  Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
- ================================================================================ 
+ ================================================================================
+ Modifications Copyright (c) 2020 Nokia. All rights reserved.
+ ================================================================================
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  See the License for the specific language governing permissions and
  limitations under the License.
  ============LICENSE_END=========================================================
-
  */
 
 package org.onap.blueprintgenerator.models.blueprint;
 
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
+import java.util.Map;
 import java.util.TreeMap;
 
 import org.onap.blueprintgenerator.models.componentspec.Auxilary;
@@ -33,10 +35,12 @@ import org.onap.blueprintgenerator.models.dmaapbp.DmaapStreams;
 import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.annotation.JsonInclude.Include;
 
-import lombok.Getter; import lombok.Setter;
+import lombok.Getter;
+import lombok.Setter;
 
-@Getter @Setter
-@JsonInclude(value=Include.NON_NULL)
+@Getter
+@Setter
+@JsonInclude(value = Include.NON_NULL)
 public class Properties {
        private Appconfig application_config;
        private Auxilary docker_config;
@@ -52,6 +56,7 @@ public class Properties {
        ArrayList<DmaapStreams> streams_publishes;
        ArrayList<DmaapStreams> streams_subscribes;
        private TlsInfo tls_info;
+       private ExternalTlsInfo external_cert;
        private ResourceConfig resource_config;
        private GetInput always_pull_image;
        //private boolean useExisting;
@@ -85,17 +90,14 @@ public class Properties {
                GetInput replica = new GetInput();
                replica.setGet_input("replicas");
                this.setReplicas(replica);
-               LinkedHashMap<String, Object> rep = new LinkedHashMap<String, Object>();
-               rep.put("type", "integer");
-               rep.put("description", "number of instances");
-               rep.put("default", 1);
+               LinkedHashMap<String, Object> rep = makeInput("integer", "number of instances", 1);
                retInputs.put("replicas", rep);
 
                //set the dns name
-               this.setDns_name(cs.getSelf().getName());
+               //this.setDns_name(cs.getSelf().getName());
 
                //set the name
-               this.setName(cs.getSelf().getName());
+               //this.setName(cs.getSelf().getName());
 
                //set the docker config
                Auxilary aux = cs.getAuxilary();
@@ -112,15 +114,21 @@ public class Properties {
                // set always_pull_image
                this.always_pull_image = new GetInput();
                this.always_pull_image.setGet_input("always_pull_image");
-               LinkedHashMap<String, Object> inputAlwaysPullImage = new LinkedHashMap<String, Object>();
-               inputAlwaysPullImage.put("type", "boolean");
-               inputAlwaysPullImage.put("description", "Set to true if the image should always be pulled");
-               inputAlwaysPullImage.put("default", true);
+               LinkedHashMap<String, Object> inputAlwaysPullImage = makeInput("boolean",
+                               "Set to true if the image should always be pulled",
+                               true);
                retInputs.put("always_pull_image", inputAlwaysPullImage);
 
-               //set the tls info
-               if(cs.getAuxilary().getTls_info() != null){
-                       addTlsInfo(cs,retInputs);
+
+               //set service component type
+               String sType = cs.getSelf().getName();
+               sType = sType.replace('.', '-');
+               this.setService_component_type(sType);
+               
+               //set the tls info for internal and external communication
+               if (cs.getAuxilary().getTls_info() != null) {
+                       addTlsInfo(cs, retInputs);
+                       addExternalTlsInfo(cs, retInputs);
                }
 
                //set the reource config
@@ -144,6 +152,16 @@ public class Properties {
                img.put("default", cs.getArtifacts()[0].getUri());
                retInputs.put("tag_version", img);
 
+               
+               //set the location id
+               GetInput location = new GetInput();
+               location.setGet_input("location_id");
+               this.setLocation_id(location);
+               LinkedHashMap<String, Object> locMap = new LinkedHashMap();
+               locMap.put("type", "string");
+               locMap.put("default", "");
+               retInputs.put("location_id", locMap);
+               
                //set the log info
                this.setLog_info(cs.getAuxilary().getLog_info());
 
@@ -152,19 +170,17 @@ public class Properties {
                sType = sType.replace('.', '-');
                this.setService_component_type(sType);
 
-               //set the tls info
-               if(cs.getAuxilary().getTls_info() != null){
-                       addTlsInfo(cs,retInputs);
+               //set the tls info for internal and external communication
+               if (cs.getAuxilary().getTls_info() != null) {
+                       addTlsInfo(cs, retInputs);
+                       addExternalTlsInfo(cs, retInputs);
                }
 
                //set the replicas
                GetInput replica = new GetInput();
                replica.setGet_input("replicas");
                this.setReplicas(replica);
-               LinkedHashMap<String, Object> rep = new LinkedHashMap<String, Object>();
-               rep.put("type", "integer");
-               rep.put("description", "number of instances");
-               rep.put("default", 1);
+               LinkedHashMap<String, Object> rep = makeInput("integer", "number of instances", 1);
                retInputs.put("replicas", rep);
 
 //             //set the dns name
@@ -187,15 +203,14 @@ public class Properties {
 
                //set the stream publishes
                ArrayList<DmaapStreams> pubStreams = new ArrayList();
-               if(cs.getStreams().getPublishes() != null) {
-                       for(Publishes p: cs.getStreams().getPublishes()) {
-                               if(p.getType().equals("message_router") || p.getType().equals("message router")) {
+               if (cs.getStreams().getPublishes() != null) {
+                       for (Publishes p : cs.getStreams().getPublishes()) {
+                               if (p.getType().equals("message_router") || p.getType().equals("message router")) {
                                        String topic = p.getConfig_key() + "_topic";
                                        DmaapStreams mrStreams = new DmaapStreams();
                                        retInputs = mrStreams.createStreams(inps, cs, topic, p.getType(), p.getConfig_key(), p.getRoute(), 'p');
                                        pubStreams.add(mrStreams);
-                               }
-                               else if(p.getType().equals("data_router") || p.getType().equals("data router")){
+                               } else if (p.getType().equals("data_router") || p.getType().equals("data router")) {
                                        String feed = p.getConfig_key() + "_feed";
                                        DmaapStreams drStreams = new DmaapStreams();
                                        retInputs = drStreams.createStreams(inps, cs, feed, p.getType(), p.getConfig_key(), p.getRoute(), 'p');
@@ -206,15 +221,14 @@ public class Properties {
 
                //set the stream subscribes
                ArrayList<DmaapStreams> subStreams = new ArrayList();
-               if(cs.getStreams().getSubscribes() != null) {
-                       for(Subscribes s: cs.getStreams().getSubscribes()) {
-                               if(s.getType().equals("message_router") || s.getType().equals("message router")) {
+               if (cs.getStreams().getSubscribes() != null) {
+                       for (Subscribes s : cs.getStreams().getSubscribes()) {
+                               if (s.getType().equals("message_router") || s.getType().equals("message router")) {
                                        String topic = s.getConfig_key() + "_topic";
                                        DmaapStreams mrStreams = new DmaapStreams();
                                        retInputs = mrStreams.createStreams(inps, cs, topic, s.getType(), s.getConfig_key(), s.getRoute(), 's');
                                        subStreams.add(mrStreams);
-                               }
-                               else if(s.getType().equals("data_router") || s.getType().equals("data router")){
+                               } else if (s.getType().equals("data_router") || s.getType().equals("data router")) {
                                        String feed = s.getConfig_key() + "_feed";
                                        DmaapStreams drStreams = new DmaapStreams();
                                        retInputs = drStreams.createStreams(inps, cs, feed, s.getType(), s.getConfig_key(), s.getRoute(), 's');
@@ -223,10 +237,10 @@ public class Properties {
                        }
                }
 
-               if(pubStreams.size() != 0) {
+               if (pubStreams.size() != 0) {
                        this.setStreams_publishes(pubStreams);
                }
-               if(subStreams.size() != 0) {
+               if (subStreams.size() != 0) {
                        this.setStreams_subscribes(subStreams);
                }
 
@@ -246,10 +260,24 @@ public class Properties {
                useTLSFlag.setGet_input("use_tls");
                tlsInfo.setUseTls(useTLSFlag);
                this.setTls_info(tlsInfo);
-               LinkedHashMap<String, Object> useTlsFlagInput = new LinkedHashMap<String, Object>();
-               useTlsFlagInput.put("type", "boolean");
-               useTlsFlagInput.put("description", "flag to indicate tls enable/disable");
-               useTlsFlagInput.put("default", cs.getAuxilary().getTls_info().get("use_tls"));
+               LinkedHashMap<String, Object> useTlsFlagInput = makeInput("boolean",
+                               "flag to indicate tls enable/disable",
+                               cs.getAuxilary().getTls_info().get("use_tls"));
                retInputs.put("use_tls", useTlsFlagInput);
        }
+
+       private void addExternalTlsInfo(ComponentSpec cs, Map<String, LinkedHashMap<String, Object>> retInputs) {
+               if(cs.getAuxilary().getTls_info().get(ExternalTlsInfo.USE_EXTERNAL_TLS_FIELD) == null)
+                       return;
+               this.setExternal_cert(ExternalTlsInfo.createFromComponentSpec(cs));
+               retInputs.putAll(ExternalTlsInfo.createInputMapFromComponentSpec(cs));
+       }
+
+       static LinkedHashMap<String, Object> makeInput(String type, String description, Object defaultValue) {
+               LinkedHashMap<String, Object> inputMap = new LinkedHashMap<>();
+               inputMap.put("type", type);
+               inputMap.put("description", description);
+               inputMap.put("default", defaultValue);
+               return inputMap;
+       }
 }