From d6375ac33711eadd11f08017072e0552f819cac2 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 26 Feb 2019 19:51:20 +0000 Subject: Use getEntity to populate network_role Changes made: Update sdc-tosca version to 1.5.0. Replace getCpListByVf with equivalent getEntity call in SdncVFModel.java. Replace policy.getMetaData with getMetaDataObj to work around parser issue. Change-Id: I1d972f75cc5ca1c8dc0e5d58880a3bb306608ca2 Issue-ID: CCSDK-1089 Signed-off-by: Ubuntu --- ueb-listener/pom.xml | 2 +- .../sli/northbound/uebclient/SdncBaseModel.java | 36 ++++++++----- .../sli/northbound/uebclient/SdncVFModel.java | 61 ++++++++++++++++------ 3 files changed, 69 insertions(+), 30 deletions(-) diff --git a/ueb-listener/pom.xml b/ueb-listener/pom.xml index 87a9dfe9..df20a01c 100755 --- a/ueb-listener/pom.xml +++ b/ueb-listener/pom.xml @@ -18,7 +18,7 @@ 1.3.0 - 1.4.7 + 1.5.0 2.9.4 true /opt/app/ueb-listener diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index 0d5e9d6d..37b100ca 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -278,9 +278,9 @@ public class SdncBaseModel { for (Policy policy : policyList) { // extract policy metadata - String policyUuid = policy.getMetaData().getOrDefault("UUID", "").toString(); - String policyInvariantUuid = policy.getMetaData().getOrDefault("invariantUUID", "").toString(); - String policyCustomizationUuid = policy.getMetaData().getOrDefault("customizationUUID", "").toString(); + String policyUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("UUID", "").toString(); + String policyInvariantUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("invariantUUID", "").toString(); + String policyCustomizationUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("customizationUUID", "").toString(); // cleanup existing RESOURCE_POLICY data Map cleanupParams = new HashMap(); @@ -293,9 +293,9 @@ public class SdncBaseModel { addParameter("policy_uuid", policyUuid, policyParams); addParameter("policy_customization_uuid", policyCustomizationUuid, policyParams); addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams); - addParameter("policy_name", policy.getMetaData().getOrDefault(PARAM_NAME_KEY, "").toString(), policyParams); - addParameter(PARAM_VERSION_KEY, policy.getMetaData().getOrDefault(PARAM_VERSION_KEY, "").toString(), policyParams); - addParameter("policy_type", policy.getMetaData().getOrDefault(PARAM_TYPE_KEY, "").toString(), policyParams); + addParameter("policy_name", policy.getMetaDataObj().getAllProperties().getOrDefault(PARAM_NAME_KEY, "").toString(), policyParams); + addParameter(PARAM_VERSION_KEY, policy.getMetaDataObj().getAllProperties().getOrDefault(PARAM_VERSION_KEY, "").toString(), policyParams); + addParameter("policy_type", policy.getType(), policyParams); // extract properties addParameter("property_type", extractValue(policy, PARAM_TYPE_KEY), policyParams); @@ -350,8 +350,8 @@ public class SdncBaseModel { for (Policy policy : policyList) { // extract policy metadata - String policyUuid = policy.getMetaData().getOrDefault("UUID", "").toString(); - String policyInvariantUuid = policy.getMetaData().getOrDefault("invariantUUID", "").toString(); + String policyUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("UUID", "").toString(); + String policyInvariantUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("invariantUUID", "").toString(); // cleanup existing RESOURCE_POLICY data Map cleanupParams = new HashMap(); @@ -363,8 +363,8 @@ public class SdncBaseModel { Map policyParams = new HashMap(); addParameter("policy_uuid", policyUuid, policyParams); addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams); - addParameter("policy_name", policy.getMetaData().getOrDefault("name", "").toString(), policyParams); - addParameter("version", policy.getMetaData().getOrDefault("version", "").toString(), policyParams); + addParameter("policy_name", policy.getMetaDataObj().getAllProperties().getOrDefault("name", "").toString(), policyParams); + addParameter("version", policy.getMetaDataObj().getAllProperties().getOrDefault("version", "").toString(), policyParams); addParameter("policy_type", policy.getType(), policyParams); // extract properties @@ -386,6 +386,10 @@ public class SdncBaseModel { // insert into RESOURCE_POLICY_TO_TARGET_NODE_MAPPING List policyTargetNameList = policy.getTargets(); + if (policyTargetNameList == null) { + continue; + } + for (String targetName : policyTargetNameList) { NodeTemplate targetNode = sdcCsarHelper.getNodeTemplateByName(targetName); @@ -423,8 +427,8 @@ public class SdncBaseModel { for (Policy policy : policyList) { // extract policy metadata - String policyUuid = policy.getMetaData().getOrDefault("UUID", "").toString(); - String policyInvariantUuid = policy.getMetaData().getOrDefault("invariantUUID", "").toString(); + String policyUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("UUID", "").toString(); + String policyInvariantUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("invariantUUID", "").toString(); // cleanup existing RESOURCE_POLICY data Map cleanupParams = new HashMap(); @@ -436,9 +440,9 @@ public class SdncBaseModel { Map policyParams = new HashMap(); addParameter("policy_uuid", policyUuid, policyParams); addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams); - String policyName = policy.getMetaData().getOrDefault(PARAM_NAME_KEY, "").toString(); + String policyName = policy.getMetaDataObj().getAllProperties().getOrDefault(PARAM_NAME_KEY, "").toString(); addParameter("policy_name", policyName, policyParams); - addParameter(PARAM_VERSION_KEY, policy.getMetaData().getOrDefault(PARAM_VERSION_KEY, "").toString(), policyParams); + addParameter(PARAM_VERSION_KEY, policy.getMetaDataObj().getAllProperties().getOrDefault(PARAM_VERSION_KEY, "").toString(), policyParams); addParameter("policy_type", policy.getType(), policyParams); // extract properties @@ -460,6 +464,10 @@ public class SdncBaseModel { // insert into RESOURCE_POLICY_TO_TARGET_NODE_MAPPING List targetNodeList = sdcCsarHelper.getPolicyTargetsFromOrigin(nodeTemplate, policyName); + if (targetNodeList == null) { + continue; + } + for (NodeTemplate targetNode : targetNodeList) { //NodeTemplate targetNode = sdcCsarHelper.getNodeTemplateByName(targetName); if (targetNode == null) { diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java index 850a34fa..a42f03d8 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java @@ -27,10 +27,14 @@ import java.util.List; import java.util.Map; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.enums.SdcTypes; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; +import org.onap.sdc.tosca.parser.api.IEntityDetails; +import org.onap.sdc.tosca.parser.elements.queries.EntityQuery; +import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery; import org.onap.sdc.toscaparser.api.Group; import org.onap.sdc.toscaparser.api.NodeTemplate; -import org.onap.sdc.toscaparser.api.Policy; +import org.onap.sdc.toscaparser.api.Property; import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; import org.slf4j.Logger; @@ -162,21 +166,48 @@ public class SdncVFModel extends SdncBaseModel { private void insertVFtoNetworkRoleMappingData () throws IOException { - // For each VF, insert VF_TO_NETWORK_ROLE_MAPPING data - List cpNodes = sdcCsarHelper.getCpListByVf(getCustomizationUUIDNoQuotes()); - for (NodeTemplate cpNode : cpNodes){ - - // Insert into VF_TO_NETWORK_ROLE_MAPPING vf_customization_uuid and network_role - String cpNetworkRole = sdcCsarHelper.getNodeTemplatePropertyLeafValue(cpNode, "network_role"); + // Cleanup existing VF_TO_NETWORK_ROLE_MAPPING for this VF + try { + cleanUpExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", "vf_customization_uuid", getCustomizationUUID()); + } catch (IOException e) { + LOG.error("Could not cleanup Tosca CSAR data into the VF_TO_NETWORK_ROLE_MAPPING table"); + throw new IOException (e); + } + + // For this VF, insert VF_TO_NETWORK_ROLE_MAPPING data + EntityQuery entityQueryCP = EntityQuery.newBuilder(SdcTypes.CP).build(); + TopologyTemplateQuery topologyTemplateQueryVF = TopologyTemplateQuery.newBuilder(SdcTypes.VF).customizationUUID(getCustomizationUUIDNoQuotes()).build(); + List cpEntities = sdcCsarHelper.getEntity(entityQueryCP, topologyTemplateQueryVF, true); + + for (IEntityDetails entity: cpEntities ) { + + Map properties = entity.getProperties(); + if (properties.containsKey("network_role")) { - try { - cleanUpExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", "vf_customization_uuid", getCustomizationUUID()); - LOG.info("Call insertToscaData for VF_TO_NETWORK_ROLE_MAPPING where vf_customization_uuid = " + getCustomizationUUID()); - insertToscaData("insert into VF_TO_NETWORK_ROLE_MAPPING (vf_customization_uuid, network_role) values (" + - getCustomizationUUID() + ", \"" + cpNetworkRole + "\")", null); - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the VF_TO_NETWORK_ROLE_MAPPING table"); - throw new IOException (e); + Property networkRoleProperty = properties.get("network_role"); + if (networkRoleProperty != null && networkRoleProperty.getValue() != null) { + String cpNetworkRole = networkRoleProperty.getValue().toString(); + LOG.debug("insertVFtoNetworkRoleMappingData: " + "VF: " + getCustomizationUUID() + ", networkRole = " + cpNetworkRole); + + // Only insert unique network_role values for this VF + boolean networkRoleExists = false; + Map networkRoleyKeys = new HashMap(); + networkRoleyKeys.put("vf_customization_uuid", getCustomizationUUID()); + networkRoleyKeys.put("network_role", "\"" + cpNetworkRole + "\""); + networkRoleExists = checkForExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", networkRoleyKeys); + + if (networkRoleExists == false) { + try { + //cleanUpExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", "vf_customization_uuid", getCustomizationUUID()); + LOG.info("Call insertToscaData for VF_TO_NETWORK_ROLE_MAPPING where vf_customization_uuid = " + getCustomizationUUID()); + insertToscaData("insert into VF_TO_NETWORK_ROLE_MAPPING (vf_customization_uuid, network_role) values (" + + getCustomizationUUID() + ", \"" + cpNetworkRole + "\")", null); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the VF_TO_NETWORK_ROLE_MAPPING table"); + throw new IOException (e); + } + } + } } } // CP loop -- cgit 1.2.3-korg