From 4ae7c5e7af5a4b91f7586e8244359430607da3b3 Mon Sep 17 00:00:00 2001 From: "Mnushkin, Dmitry" Date: Sat, 16 May 2020 12:11:13 -0400 Subject: add null check for server HostName/Name/Flavor add null check for server HostName/Name/Flavor maven format file after build failure include relationship empty string verification add unit test to verify null/empty string update empty string validation code Issue-ID: SO-2912 Signed-off-by: Benjamin, Max (mb388a) Change-Id: If308469cd4ec0008a6d1a480641da890d67b4259 Signed-off-by: Mnushkin, Dmitry (dm4252) --- .../org/onap/so/heatbridge/helpers/AaiHelper.java | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'adapters/mso-openstack-adapters/src/main/java/org') diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java index 727cdccff5..f18279d5d3 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java @@ -41,6 +41,7 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.onap.aai.domain.yang.Flavor; import org.onap.aai.domain.yang.Image; import org.onap.aai.domain.yang.PInterface; @@ -75,11 +76,12 @@ public class AaiHelper { List relationships = relationshipList.getRelationship(); // vserver to pserver relationship - Relationship pserverRelationship = - buildRelationship(HeatBridgeConstants.AAI_PSERVER, ImmutableMap.builder() - .put(HeatBridgeConstants.AAI_PSERVER_HOSTNAME, server.getHypervisorHostname()).build()); - relationships.add(pserverRelationship); - + if (!StringUtils.isEmpty(server.getHypervisorHostname())) { + Relationship pserverRelationship = + buildRelationship(HeatBridgeConstants.AAI_PSERVER, ImmutableMap.builder() + .put(HeatBridgeConstants.AAI_PSERVER_HOSTNAME, server.getHypervisorHostname()).build()); + relationships.add(pserverRelationship); + } // vserver to vf-module relationship Relationship vfModuleRelationship = buildRelationship(HeatBridgeConstants.AAI_VF_MODULE, ImmutableMap.builder().put(HeatBridgeConstants.AAI_GENERIC_VNF_ID, genericVnfId) @@ -96,11 +98,13 @@ public class AaiHelper { } // vserver to flavor relationship - Relationship flavorRel = buildRelationship(HeatBridgeConstants.AAI_FLAVOR, - ImmutableMap.builder().put(HeatBridgeConstants.AAI_CLOUD_OWNER, cloudOwner) - .put(HeatBridgeConstants.AAI_CLOUD_REGION_ID, cloudRegionId) - .put(HeatBridgeConstants.AAI_FLAVOR_ID, server.getFlavor().getId()).build()); - relationships.add(flavorRel); + if (server.getFlavor() != null) { + Relationship flavorRel = buildRelationship(HeatBridgeConstants.AAI_FLAVOR, + ImmutableMap.builder().put(HeatBridgeConstants.AAI_CLOUD_OWNER, cloudOwner) + .put(HeatBridgeConstants.AAI_CLOUD_REGION_ID, cloudRegionId) + .put(HeatBridgeConstants.AAI_FLAVOR_ID, server.getFlavor().getId()).build()); + relationships.add(flavorRel); + } return relationshipList; } -- cgit 1.2.3-korg