Fix json parsing of resource input 64/75264/4
authorsubhash kumar singh <subhash.kumar.singh@huawei.com>
Fri, 4 Jan 2019 07:09:08 +0000 (12:39 +0530)
committersubhash kumar singh <subhash.kumar.singh@huawei.com>
Tue, 8 Jan 2019 21:10:09 +0000 (22:10 +0100)
Fix json parsing of resource input by adding escape character.

Change-Id: Ic19bd5dae5eea25faaeae2df3eb0bcc29482ea7c
Issue-ID: SO-1358
Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
13 files changed:
adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQuery.java
adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogDBRestTest.java
adapters/mso-catalog-db-adapter/src/test/resources/db/migration/afterMigrate.sql
asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java
asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInputTest.java
bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/AllottedResource.java
bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/NetworkResource.java
bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceInstance.java
bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/VnfResource.java
bpmn/MSOCoreBPMN/src/test/java/org/onap/so/bpmn/core/domain/AllottedResourceTest.java
bpmn/MSOCoreBPMN/src/test/java/org/onap/so/bpmn/core/domain/NetworkResourceTest.java
bpmn/MSOCoreBPMN/src/test/java/org/onap/so/bpmn/core/domain/ServiceInstanceTest.java
bpmn/MSOCoreBPMN/src/test/java/org/onap/so/bpmn/core/domain/VnfResourceTest.java

index 63ef8e6..cc1b3dd 100644 (file)
@@ -57,7 +57,7 @@ public abstract class CatalogQuery {
                while (m.find()) {
                        String key = template.substring(m.start() + 1, m.end() - 1);
                        logger.debug("CatalogQuery key: {} contains key? {}", key , valueMap.containsKey(key));
-                       m.appendReplacement(result, valueMap.getOrDefault(key, "\"TBD\""));
+                       m.appendReplacement(result, Matcher.quoteReplacement(valueMap.getOrDefault(key, "\"TBD\"")));
                }
                m.appendTail(result);
                logger.debug("CatalogQuery return: {}", result.toString());
index 7ac3c53..663210d 100644 (file)
@@ -108,8 +108,8 @@ insert into heat_environment(artifact_uuid, name, version, description, body, ar
 insert into vnf_resource(orchestration_mode, description, creation_timestamp, model_uuid, aic_version_min, aic_version_max, model_invariant_uuid, model_version, model_name, tosca_node_type, heat_template_artifact_uuid) values
 ('HEAT', '1607 vSAMP10a - inherent network', '2017-04-14 21:46:28', 'ff2ae348-214a-11e7-93ae-92361f002671', '', '', '2fff5b20-214b-11e7-93ae-92361f002671', '1.0', 'vSAMP10a', 'VF', 'ff874603-4222-11e7-9252-005056850d2e');
 
-insert into vnf_resource_customization(model_customization_uuid, model_instance_name, min_instances, max_instances, availability_zone_max_count, nf_type, nf_role, nf_function, nf_naming_code, creation_timestamp, vnf_resource_model_uuid, multi_stage_design) values
-('68dc9a92-214c-11e7-93ae-92361f002671', 'vSAMP10a 1', '0', '0', '0', 'vSAMP', 'vSAMP', 'vSAMP', 'vSAMP', '2017-05-26 15:08:24', 'ff2ae348-214a-11e7-93ae-92361f002671', null);
+insert into vnf_resource_customization(model_customization_uuid, model_instance_name, min_instances, max_instances, availability_zone_max_count, nf_type, nf_role, nf_function, nf_naming_code, creation_timestamp, vnf_resource_model_uuid, multi_stage_design, resource_input) values
+('68dc9a92-214c-11e7-93ae-92361f002671', 'vSAMP10a 1', '0', '0', '0', 'vSAMP', 'vSAMP', 'vSAMP', 'vSAMP', '2017-05-26 15:08:24', 'ff2ae348-214a-11e7-93ae-92361f002671', null, "{\\\"vf_module_id\\\":\\\"vFirewall\\\",\\\"vfw_private_ip_1\\\":\\\"192.168.20.100\\\",\\\"public_net_id\\\":\\\"PUBLIC NET ID\\\",\\\"vfw_private_ip_0\\\":\\\"192.168.10.100\\\",\\\"onap_private_subnet_id\\\":\\\"PRIVATE NETWORK\\\",\\\"sec_group\\\":\\\"SECURITY GROUP\\\",\\\"vfw_private_ip_2\\\":\\\"10.0.100.1\\\",\\\"vfw_name_0\\\":\\\"zdfw1fwl01fwl01\\\",\\\"nexus_artifact_repo\\\":\\\"https://nexus.onap.org\\\",\\\"onap_private_net_cidr\\\":\\\"10.0.0.0/16\\\",\\\"dcae_collector_ip\\\":\\\"10.0.4.1\\\",\\\"vnf_id\\\":\\\"vFirewall_demo_app\\\",\\\"dcae_collector_port\\\":\\\"8081\\\",\\\"vpg_name_0\\\":\\\"zdfw1fwl01pgn01\\\",\\\"vsn_private_ip_0\\\":\\\"192.168.20.250\\\",\\\"vpg_private_ip_1\\\":\\\"10.0.100.2\\\",\\\"vsn_private_ip_1\\\":\\\"10.0.100.3\\\",\\\"vpg_private_ip_0\\\":\\\"192.168.10.200\\\",\\\"protected_private_net_cidr\\\":\\\"192.168.20.0/24\\\",\\\"unprotected_private_net_cidr\\\":\\\"192.168.10.0/24\\\",\\\"nf_naming\\\":\\\"true\\\",\\\"vsn_name_0\\\":\\\"zdfw1fwl01snk01\\\",\\\"multi_stage_design\\\":\\\"false\\\",\\\"onap_private_net_id\\\":\\\"PRIVATE NETWORK\\\",\\\"unprotected_private_net_id\\\":\\\"zdfw1fwl01_unprotected\\\",\\\"availability_zone_max_count\\\":\\\"1\\\",\\\"vfw_flavor_name\\\":\\\"(m1.medium suggested)\\\",\\\"demo_artifacts_version\\\":\\\"1.3.0-SNAPSHOT\\\",\\\"pub_key\\\":\\\"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDQXYJYYi3/OUZXUiCYWdtc7K0m5C0dJKVxPG0eI8EWZrEHYdfYe6WoTSDJCww+1qlBSpA5ac/Ba4Wn9vh+lR1vtUKkyIC/nrYb90ReUd385Glkgzrfh5HdR5y5S2cL/Frh86lAn9r6b3iWTJD8wBwXFyoe1S2nMTOIuG4RPNvfmyCTYVh8XTCCE8HPvh3xv2r4egawG1P4Q4UDwk+hDBXThY2KS8M5/8EMyxHV0ImpLbpYCTBA6KYDIRtqmgS6iKyy8v2D1aSY5mc9J0T5t9S2Gv+VZQNWQDDKNFnxqYaAo1uEoq/i1q63XC5AD3ckXb2VT6dp23BQMdDfbHyUWfJN\\\",\\\"key_name\\\":\\\"vfw_key\\\",\\\"install_script_version\\\":\\\"1.3.0-SNAPSHOT\\\",\\\"vfw_image_name\\\":\\\"(UBUNTU 1404 required)\\\",\\\"protected_private_net_id\\\":\\\"zdfw1fwl01_protected\\\",\\\"cloud_env\\\":\\\"openstack\\\"}");
 
 
 insert into vf_module(model_uuid, model_invariant_uuid, model_version, model_name, description, is_base, heat_template_artifact_uuid, vol_heat_template_artifact_uuid, creation_timestamp, vnf_resource_model_uuid) values
index c26d4ad..51b708d 100644 (file)
@@ -459,6 +459,7 @@ public class ToscaResourceInstaller {
                        ObjectMapper objectMapper = new ObjectMapper();
                        String jsonStr = objectMapper.writeValueAsString(resouceRequest);
 
+                       jsonStr = jsonStr.replace("\"", "\\\"");
                        logger.debug("resource request for resource customization id (" + resourceCustomizationUuid + ") : " + jsonStr);
                        return jsonStr;
                } catch (JsonProcessingException e) {
index cecf70f..e738235 100644 (file)
@@ -104,7 +104,7 @@ public class ToscaResourceInputTest {
         when(property.getValue()).thenReturn("value1");
 
         String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1");
-        assertEquals(resourceInput, "{\"prop1\":\"value1\"}");
+        assertEquals("{\\\"prop1\\\":\\\"value1\\\"}", resourceInput);
     }
 
     @Test
@@ -131,6 +131,6 @@ public class ToscaResourceInputTest {
         when(input.getDefault()).thenReturn("default_value");
 
         String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1");
-        assertEquals(resourceInput, "{\"prop1\":\"res_key|default_value\"}");
+        assertEquals("{\\\"prop1\\\":\\\"res_key|default_value\\\"}", resourceInput);
     }
 }
index f143346..c7c7bba 100644 (file)
@@ -22,6 +22,8 @@ package org.onap.so.bpmn.core.domain;
 
 import java.util.UUID;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonRootName;
 
 /**
@@ -55,6 +57,9 @@ public class AllottedResource extends Resource {
        private String nfNamingCode;
        private String orchestrationStatus;
 
+       @JsonIgnore
+       private String resourceInput;
+
        /*
         * GET and SET
         */
@@ -119,4 +124,13 @@ public class AllottedResource extends Resource {
        public void setOrchestrationStatus(String orchestrationStatus) {
                this.orchestrationStatus = orchestrationStatus;
        }
+
+
+       public String getResourceInput() {
+               return resourceInput;
+       }
+
+       public void setResourceInput(String resourceInput) {
+               this.resourceInput = resourceInput;
+       }
 }
\ No newline at end of file
index 20ab3ec..f0e97f1 100644 (file)
@@ -22,6 +22,8 @@ package org.onap.so.bpmn.core.domain;
 
 import java.util.UUID;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonRootName;
 
 
@@ -47,7 +49,10 @@ public class NetworkResource extends Resource {
        private String networkRole;
        private String networkTechnology;
        private String networkScope;
-       
+
+       @JsonIgnore
+       private String resourceInput;
+
        /*
         * GET and SET
         */
@@ -75,4 +80,12 @@ public class NetworkResource extends Resource {
        public void setNetworkScope(String networkScope) {
                this.networkScope = networkScope;
        }
+
+       public String getResourceInput() {
+               return resourceInput;
+       }
+
+       public void setResourceInput(String resourceInput) {
+               this.resourceInput = resourceInput;
+       }
 }
\ No newline at end of file
index 4295f50..5cdbbcb 100644 (file)
@@ -23,6 +23,8 @@ package org.onap.so.bpmn.core.domain;
 import java.io.Serializable;
 import java.util.Map;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonRootName;
 
 /**
@@ -32,6 +34,7 @@ import com.fasterxml.jackson.annotation.JsonRootName;
  * @author cb645j
  *
  */
+@JsonIgnoreProperties(ignoreUnknown = true)
 public class ServiceInstance extends JsonWrapper implements Serializable {
 
        private static final long serialVersionUID = 1L;
index dc76ab0..a7e5389 100644 (file)
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.UUID;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.annotation.JsonRootName;
 
@@ -59,6 +60,9 @@ public class VnfResource extends Resource {
        private String multiStageDesign;
        private String orchestrationStatus;
 
+       @JsonIgnore
+       private String resourceInput;
+
        /*
         * GET and SET
         */
@@ -123,6 +127,15 @@ public class VnfResource extends Resource {
        public void setOrchestrationStatus(String orchestrationStatus){
                this.orchestrationStatus = orchestrationStatus;
        }
+
+       public String getResourceInput() {
+               return resourceInput;
+       }
+
+       public void setResourceInput(String resourceInput) {
+               this.resourceInput = resourceInput;
+       }
+
        /**
         * Returns a list of all VfModule objects.
         * Base module is first entry in the list
index b1dd865..cca28d4 100644 (file)
@@ -21,8 +21,11 @@ package org.onap.so.bpmn.core.domain;
 
 import static org.junit.Assert.*;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
 import org.junit.Test;
 
+import java.io.IOException;
+
 public class AllottedResourceTest {
        private AllottedResource ar = new AllottedResource();
 
@@ -51,4 +54,13 @@ public class AllottedResourceTest {
 
        }
 
+       @Test
+       public void allottedResourceMapperTest() throws IOException {
+               String jsonStr = "{\"allottedResourceType\": \"code123\", \"resourceInput\": \"sample\"}";
+               ObjectMapper objectMapper = new ObjectMapper();
+               AllottedResource vnfResource = objectMapper.readValue(jsonStr, AllottedResource.class);
+
+               assertTrue(vnfResource != null);
+       }
+
 }
index 6ca9cef..ee23ebd 100644 (file)
@@ -21,8 +21,11 @@ package org.onap.so.bpmn.core.domain;
 
 import static org.junit.Assert.*;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
 import org.junit.Test;
 
+import java.io.IOException;
+
 public class NetworkResourceTest {
        private NetworkResource nr = new NetworkResource();
 
@@ -39,4 +42,13 @@ public class NetworkResourceTest {
                
        }
 
+       @Test
+       public void networkResourceMapperTest() throws IOException {
+               String jsonStr = "{\"networkScope\": \"code123\", \"resourceInput\": \"sample\"}";
+               ObjectMapper objectMapper = new ObjectMapper();
+               NetworkResource networkResource = objectMapper.readValue(jsonStr, NetworkResource.class);
+
+               assertTrue(networkResource != null);
+       }
+
 }
index 7cacc9d..c04dc9d 100644 (file)
@@ -21,8 +21,10 @@ package org.onap.so.bpmn.core.domain;
 
 import static org.junit.Assert.*;
 
+import java.io.IOException;
 import java.util.Map;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
 import org.junit.Test;
 
 public class ServiceInstanceTest {
@@ -58,4 +60,12 @@ public class ServiceInstanceTest {
                
        }
 
+       @Test
+       public void serviceInstanceMapperTest() throws IOException {
+               String jsonStr = "{\"workloadContext\": \"code123\", \"resourceOrder\": \"sample\"}";
+               ObjectMapper objectMapper = new ObjectMapper();
+               ServiceInstance serviceInstance = objectMapper.readValue(jsonStr, ServiceInstance.class);
+               assertTrue(serviceInstance != null);
+       }
+
 }
index 24947e9..a83337f 100644 (file)
@@ -21,8 +21,10 @@ package org.onap.so.bpmn.core.domain;
 
 import static org.junit.Assert.*;
 
+import java.io.IOException;
 import java.util.List;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
 import org.junit.Test;
 
 public class VnfResourceTest {
@@ -52,4 +54,13 @@ public class VnfResourceTest {
                
        }
 
+       @Test
+       public void vnfResourceMapperTest() throws IOException {
+               String jsonStr = "{\"vnfHostname\": \"home\", \"resourceInput\": \"sample\"}";
+               ObjectMapper objectMapper = new ObjectMapper();
+               VnfResource vnfResource = objectMapper.readValue(jsonStr, VnfResource.class);
+
+               assertTrue(vnfResource != null);
+       }
+
 }