BPGenerator - fix placement of service component name override 41/116941/2
authorRemigiusz Janeczek <remigiusz.janeczek@nokia.com>
Mon, 18 Jan 2021 08:39:44 +0000 (09:39 +0100)
committerRemigiusz Janeczek <remigiusz.janeczek@nokia.com>
Thu, 21 Jan 2021 10:34:46 +0000 (11:34 +0100)
Issue-ID: DCAEGEN2-2481
Signed-off-by: Remigiusz Janeczek <remigiusz.janeczek@nokia.com>
Change-Id: I32c3d2eb1e08dbcfe5b8ec57394a000a76150f00

mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/model/common/Properties.java
mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/AppConfigService.java
mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/common/PropertiesService.java
mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/common/PropertiesServiceTest.java

index a9675f5..dfe02f0 100644 (file)
@@ -4,6 +4,7 @@
  *  *  org.onap.dcae
  *  *  ================================================================================
  *  *  Copyright (c) 2020  AT&T Intellectual Property. All rights reserved.
+ *  *  Copyright (c) 2021  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.
@@ -54,6 +55,8 @@ public class Properties {
 
     private String service_component_type;
 
+    private GetInput service_component_name_override;
+
     private Map<String, Object> log_info;
 
     private String dns_name;
index f0d0e50..494620c 100644 (file)
@@ -4,6 +4,7 @@
  *  *  org.onap.dcae
  *  *  ================================================================================
  *  *  Copyright (c) 2020  AT&T Intellectual Property. All rights reserved.
+ *  *  Copyright (c) 2021  Nokia. All rights reserved.
  *  *  ================================================================================
  *  *  Modifications Copyright (c) 2021 Nokia
  *  *  ================================================================================
 
 package org.onap.blueprintgenerator.service.common;
 
-import org.onap.blueprintgenerator.constants.Constants;
 import org.onap.blueprintgenerator.model.common.Appconfig;
 import org.onap.blueprintgenerator.model.common.Dmaap;
 import org.onap.blueprintgenerator.model.common.GetInput;
 import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
 import org.onap.blueprintgenerator.model.componentspec.common.Calls;
 import org.onap.blueprintgenerator.model.componentspec.common.Parameters;
-import org.onap.blueprintgenerator.model.componentspec.common.Publishes;
-import org.onap.blueprintgenerator.model.componentspec.common.Subscribes;
 import org.onap.blueprintgenerator.service.base.BlueprintHelperService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -66,14 +64,12 @@ public class AppConfigService {
      *
      * @param inputs Inputs
      * @param onapComponentSpec Onap Component Specification
-     * @param override Parameter to Service Component Override
      * @param isDmaap Dmaap Argument
      * @return
      */
     public Map<String, Object> createAppconfig(
         Map<String, LinkedHashMap<String, Object>> inputs,
         OnapComponentSpec onapComponentSpec,
-        String override,
         boolean isDmaap) {
 
         Map<String, Object> response = new HashMap<>();
@@ -119,13 +115,7 @@ public class AppConfigService {
                 }
             }
         }
-        if (override != null) {
-            GetInput ov = new GetInput();
-            ov.setBpInputName(Constants.SERVICE_COMPONENT_NAME_OVERRIDE);
-            parameters.put(Constants.SERVICE_COMPONENT_NAME_OVERRIDE, ov);
-            LinkedHashMap<String, Object> over = blueprintHelperService.createStringInput(override);
-            inputs.put(Constants.SERVICE_COMPONENT_NAME_OVERRIDE, over);
-        }
+
         appconfig.setParams(parameters);
 
         response.put("appconfig", appconfig);
index be79b25..382cc2b 100644 (file)
@@ -4,6 +4,7 @@
  *  *  org.onap.dcae
  *  *  ================================================================================
  *  *  Copyright (c) 2020  AT&T Intellectual Property. All rights reserved.
+ *  *  Copyright (c) 2021  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.
 
 package org.onap.blueprintgenerator.service.common;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
 import org.onap.blueprintgenerator.constants.Constants;
 import org.onap.blueprintgenerator.model.common.Appconfig;
 import org.onap.blueprintgenerator.model.common.GetInput;
+import org.onap.blueprintgenerator.model.common.Properties;
 import org.onap.blueprintgenerator.model.common.ResourceConfig;
 import org.onap.blueprintgenerator.model.componentspec.OnapAuxilary;
 import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
@@ -35,20 +42,12 @@ import org.onap.blueprintgenerator.model.dmaap.Streams;
 import org.onap.blueprintgenerator.model.dmaap.TlsInfo;
 import org.onap.blueprintgenerator.service.base.BlueprintHelperService;
 import org.onap.blueprintgenerator.service.dmaap.StreamsService;
-import org.onap.blueprintgenerator.model.common.Properties;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  * @author : Ravi Mantena
- * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service to create Properties
- * Node
+ * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service to create Properties Node
  */
 @Service("onapPropertiesService")
 public class PropertiesService {
@@ -71,9 +70,9 @@ public class PropertiesService {
     /**
      * Creates ONAP properties
      *
-     * @param inputs Inputs
+     * @param inputs            Inputs
      * @param onapComponentSpec OnapComponentSpec
-     * @param override Override
+     * @param override          Override
      * @return
      */
     public Map<String, Object> createOnapProperties(
@@ -113,7 +112,7 @@ public class PropertiesService {
         properties.setDocker_config(onapAuxilary);
 
         Map<String, Object> appConfigResponse =
-            appConfigService.createAppconfig(inputs, onapComponentSpec, override, false);
+            appConfigService.createAppconfig(inputs, onapComponentSpec, false);
         inputs = (Map<String, LinkedHashMap<String, Object>>) appConfigResponse.get("inputs");
         properties.setApplication_config((Appconfig) appConfigResponse.get("appconfig"));
 
@@ -131,6 +130,9 @@ public class PropertiesService {
         sType = sType.replace('.', '-');
         properties.setService_component_type(sType);
 
+        inputs.put(Constants.SERVICE_COMPONENT_NAME_OVERRIDE,
+            addServiceComponentNameOverride(override, properties));
+
         Map<String, Object> tls_info = onapComponentSpec.getAuxilary().getTls_info();
         if (tls_info != null) {
             addTlsInfo(onapComponentSpec, inputs, properties);
@@ -154,9 +156,9 @@ public class PropertiesService {
     /**
      * Creates Dmaap properties
      *
-     * @param inputs Inputs
+     * @param inputs            Inputs
      * @param onapComponentSpec OnapComponentSpec
-     * @param override Override
+     * @param override          Override
      * @return
      */
     public Map<String, Object> createDmaapProperties(
@@ -189,6 +191,9 @@ public class PropertiesService {
         sType = sType.replace('.', '-');
         properties.setService_component_type(sType);
 
+        inputs.put(Constants.SERVICE_COMPONENT_NAME_OVERRIDE,
+            addServiceComponentNameOverride(override, properties));
+
         Map<String, Object> tls_info = onapComponentSpec.getAuxilary().getTls_info();
         if (tls_info != null) {
             addTlsInfo(onapComponentSpec, inputs, properties);
@@ -210,7 +215,7 @@ public class PropertiesService {
         properties.setDocker_config(onapAuxilary);
 
         Map<String, Object> appConfigResponse =
-            appConfigService.createAppconfig(inputs, onapComponentSpec, override, true);
+            appConfigService.createAppconfig(inputs, onapComponentSpec, true);
         inputs = (Map<String, LinkedHashMap<String, Object>>) appConfigResponse.get("inputs");
         properties.setApplication_config((Appconfig) appConfigResponse.get("appconfig"));
 
@@ -308,6 +313,13 @@ public class PropertiesService {
         return response;
     }
 
+    private LinkedHashMap<String, Object> addServiceComponentNameOverride(String override, Properties properties) {
+        GetInput overrideGetInput = new GetInput();
+        overrideGetInput.setBpInputName(Constants.SERVICE_COMPONENT_NAME_OVERRIDE);
+        properties.setService_component_name_override(overrideGetInput);
+        return blueprintHelperService.createStringInput(override != null ? override : "");
+    }
+
     private void addTlsInfo(
         OnapComponentSpec onapComponentSpec,
         Map<String, LinkedHashMap<String, Object>> inputs,
index 520d2d2..a598315 100644 (file)
@@ -103,7 +103,7 @@ public class PropertiesServiceTest {
     @Test
     public void shouldReturnInputsAndPropertiesForOnap() {
         //given
-        when(appConfigService.createAppconfig(any(), eq(getOnapComponentSpec()), eq(""), eq(false)))
+        when(appConfigService.createAppconfig(any(), eq(getOnapComponentSpec()), eq(false)))
             .thenReturn((Map<String, Object>) resourceConfigResponse);
 
         //when
@@ -278,6 +278,7 @@ public class PropertiesServiceTest {
         expectedProperties.setImage(getGetInput(image));
         expectedProperties.setLocation_id(getGetInput("location_id"));
         expectedProperties.setService_component_type("test-Name");
+        expectedProperties.setService_component_name_override(getGetInput("service_component_name_override"));
         expectedProperties.setLog_info(Collections.emptyMap());
         expectedProperties.setReplicas(getGetInput("replicas"));
         expectedProperties.setTls_info(getTlsInfo());