diff options
author | Agarwal, Ruchira (ra1926) <ra1926@att.com> | 2019-05-20 22:02:34 +0000 |
---|---|---|
committer | Agarwal, Ruchira (ra1926) <lalena.aria@att.com> | 2019-05-20 22:08:28 +0000 |
commit | 3a86df02c0c53b9c4c1138084a18bb724d22c4ef (patch) | |
tree | 5b14d94f62945c66755633d559f48ea2e3c440bf /ueb-listener | |
parent | 39b9cb6e48052a5fe474e056fa867e5b9bd59ca9 (diff) |
Use getEntity to populate VF Module tables
Changes made:
Update SdncVFModel.insertVFModuleData to use getEntity.
Update SdncVFModule to use IEntityDetails instead of Group.
Issue-ID: CCSDK-1347
Change-Id: I319d4b56b7d1e9bfb6a2d7601a24cd5c192477d7
Signed-off-by: Aria, Lalena (la505a) <lalena.aria@att.com>
Diffstat (limited to 'ueb-listener')
5 files changed, 127 insertions, 36 deletions
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 4824d9f2d..a5de97fc2 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 @@ -58,6 +58,7 @@ public class SdncBaseModel { protected String name = null; protected String PARAM_INVARIANT_UUID_KEY = "invariant_uuid"; + protected String PARAM_CUSTOMIZATION_UUID_KEY = "customization_uuid"; protected String PARAM_UUID_KEY = "uuid"; protected String PARAM_VERSION_KEY = "version"; protected String PARAM_NAME_KEY = "name"; diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java index ea62abe9c..dedaa9a2a 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java @@ -35,7 +35,7 @@ import org.slf4j.LoggerFactory; public class SdncGroupModel extends SdncBaseModel { private static final Logger LOG = LoggerFactory - .getLogger(SdncVFModuleModel.class); + .getLogger(SdncGroupModel.class); private static final String groupType = "group_type"; 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 a42f03d8e..12eccf213 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 @@ -22,6 +22,7 @@ package org.onap.ccsdk.sli.northbound.uebclient; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -94,7 +95,7 @@ public class SdncVFModel extends SdncBaseModel { public void insertData() throws IOException { insertVFModelData(); - insertVFModuleData(nodeTemplate, jdbcDataSource); + insertVFModuleData(); insertVFtoNetworkRoleMappingData(); insertVFCData(); insertVFCInstanceGroupData(); @@ -125,12 +126,29 @@ public class SdncVFModel extends SdncBaseModel { } - private void insertVFModuleData (NodeTemplate nodeTemplate, DBResourceManager jdbcDataSource) throws IOException { + private void insertVFModuleData () throws IOException { - List<Group> vfModules = sdcCsarHelper.getVfModulesByVf(getCustomizationUUIDNoQuotes()); - for (Group group : vfModules){ - SdncVFModuleModel vfModuleModel = new SdncVFModuleModel(sdcCsarHelper, group, this); - + // Step 1: Get all the VF Module groups (entities) in this Service + EntityQuery entityQuery = EntityQuery.newBuilder("org.openecomp.groups.VfModule").build(); + String vfCustomizationUuid = getCustomizationUUIDNoQuotes(); + TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE) + .build(); + List<IEntityDetails> vfModules = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false); + if (vfModules == null) { + return; + } + + // Insert each VF Module group (entity) into VF_MODULE_MODEL if its name is prefixed with the VF name + for (IEntityDetails vfModule : vfModules){ + + // If this vfModule name is prefixed with the VF name of the VF bing processed, insert this VF Module in VF_MODULE_MODEL + String normailizedVfName = nodeTemplate.getName().toLowerCase().replace(" ", ""); + if (!vfModule.getName().startsWith(normailizedVfName)) { + continue; + } + + SdncVFModuleModel vfModuleModel = new SdncVFModuleModel(sdcCsarHelper, vfModule, this); + try { cleanUpExistingToscaData("VF_MODULE_MODEL", "customization_uuid", vfModuleModel.getCustomizationUUID()); cleanUpExistingToscaData("VF_MODULE_TO_VFC_MAPPING", "vf_module_customization_uuid", vfModuleModel.getCustomizationUUID()); @@ -140,28 +158,95 @@ public class SdncVFModel extends SdncBaseModel { LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_MODEL table "); throw new IOException (e); } - - // For each VF Module, get the VFC list, insert VF_MODULE_TO_VFC_MAPPING data - // List<NodeTemplate> groupMembers = sdcCsarHelper.getMembersOfGroup(group); - old version - // For each vfcNode (group member) in the groupMembers list, extract vm_type and vm_count. - // Insert vf_module.customizationUUID, vfcNode.customizationUUID and vm_type and vm_count into VF_MODULE_TO_VFC_MAPPING - List<NodeTemplate> groupMembers = sdcCsarHelper.getMembersOfVfModule(nodeTemplate, group); - for (NodeTemplate vfcNode : groupMembers){ - SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, vfcNode, jdbcDataSource); - - try { - LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING where vf_module_customization_uuid = " + vfModuleModel.getCustomizationUUID()); - insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" + - vfModuleModel.getCustomizationUUID() + ", " + vfcModel.getCustomizationUUID() + ", \"" + vfcModel.getVmType() + "\", \"" + vfcModel.getVmCount() + "\")", null); - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_TO_VFC_MAPPING table"); - throw new IOException (e); - } - + + // Step 2: Get the non-catalog VF Module in order to get the group members + String vfModuleUuid = vfModuleModel.getUUID().replace("\"", ""); + EntityQuery entityQuery2 = EntityQuery.newBuilder("org.openecomp.groups.VfModule") + .uUID(vfModuleUuid) + .build(); + TopologyTemplateQuery topologyTemplateQuery2 = TopologyTemplateQuery.newBuilder(SdcTypes.VF) + .customizationUUID(vfCustomizationUuid) // customization UUID of the VF if exists + .build(); + List<IEntityDetails> vfModulesNonCatalog = sdcCsarHelper.getEntity(entityQuery2, topologyTemplateQuery2, false); + if (vfModulesNonCatalog == null || vfModulesNonCatalog.isEmpty()) { + LOG.info("insertVFModuleDataGetEntity2: Could not find the non-catelog VF Module for: " + vfModuleModel.getCustomizationUUID() + ". Unable to insert members into VF_MODULE_TO_VFC_MAPPING"); + continue; + } + + List<IEntityDetails> vfModuleMembers = vfModulesNonCatalog.get(0).getMemberNodes(); + + // Find all members for each VF Module that are of type CVFC and insert it and any nested CFVCs into VF_MODULE_TO_VFC_MAPPING + for (IEntityDetails vfModuleMember: vfModuleMembers) { + if (vfModuleMember.getMetadata().getValue("type").equals(SdcTypes.CVFC.getValue())) { + + // Insert this CVFC data into VF_MODULE_TO_VFC_MAPPING + String cvfcCustomizationUuid = extractValue(vfModuleMember.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); + String vfcVmType = extractValue (vfModuleMember, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG); // extracted as vm_type_tag + String vfcVmCount = ""; + if (vfModuleMember.getProperties().containsKey("service_template_filter")) { + Property property = vfModuleMember.getProperties().get("service_template_filter"); + if (property != null && property.getLeafPropertyValue("count") != null) { + vfcVmCount = property.getLeafPropertyValue("count").get(0); + } + } + if (vfcVmCount.isEmpty()) { + vfcVmCount = "0"; // vm_count can not be null + } + + try { + LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING where vf_module_customization_uuid = " + vfModuleModel.getCustomizationUUID()); + insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" + + vfModuleModel.getCustomizationUUID() + ", \"" + cvfcCustomizationUuid + "\", \"" + vfcVmType + "\", \"" + vfcVmCount + "\")", null); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_TO_VFC_MAPPING table"); + throw new IOException (e); + } + + // Step 3: Get any nested CVFCs under this CVFC + EntityQuery entityQuery3 = EntityQuery.newBuilder(SdcTypes.CVFC) + .build(); + TopologyTemplateQuery topologyTemplateQuery3 = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC) + .customizationUUID(cvfcCustomizationUuid) // customization UUID of the CVFC if exists + .build(); + List<IEntityDetails> nestedCvfcs = sdcCsarHelper.getEntity(entityQuery3, topologyTemplateQuery3, true); // true allows for nested search + if (nestedCvfcs == null || nestedCvfcs.isEmpty()) { + LOG.info("insertVFModuleDataGetEntity2: Could not find the nested CVFCs for: " + cvfcCustomizationUuid); + continue; + } + + for (IEntityDetails nestedCvfc: nestedCvfcs) { + + // Insert this CVFC data into VF_MODULE_TO_VFC_MAPPING + String nestedCvfcCustomizationUuid = extractValue(nestedCvfc.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); + String nestedVfcVmType = extractValue (nestedCvfc, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG); // extracted as vm_type_tag + String nestedVfcVmCount = ""; + if (nestedCvfc.getProperties().containsKey("service_template_filter")) { + Property property = nestedCvfc.getProperties().get("service_template_filter"); + if (property != null && property.getLeafPropertyValue("count") != null) { + nestedVfcVmCount = property.getLeafPropertyValue("count").get(0); + } + } + if (nestedVfcVmCount.isEmpty()) { + nestedVfcVmCount = "0"; // vm_count can not be null + } + + try { + LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING where vf_module_customization_uuid = " + vfModuleModel.getCustomizationUUID()); + insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" + + vfModuleModel.getCustomizationUUID() + ", \"" + nestedCvfcCustomizationUuid + "\", \"" + nestedVfcVmType + "\", \"" + nestedVfcVmCount + "\")", null); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_TO_VFC_MAPPING table"); + throw new IOException (e); + } + + } + + } + } - + } - + } private void insertVFtoNetworkRoleMappingData () throws IOException { diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java index 914401ff1..f9a03b3f3 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java @@ -22,22 +22,26 @@ package org.onap.ccsdk.sli.northbound.uebclient; +import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; import org.onap.sdc.toscaparser.api.Group; public class SdncVFModuleModel extends SdncBaseModel { - public SdncVFModuleModel(ISdcCsarHelper sdcCsarHelper, Group group, SdncVFModel vfNodeModel) { + public SdncVFModuleModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails vfModule, SdncVFModel vfNodeModel) { - super(sdcCsarHelper, group); + super(sdcCsarHelper, vfModule); + // override base implementation for setting customizationUUID because customizationUUID is called differently for Groups + customizationUUID = extractValue (vfModule.getMetadata(), "vfModuleModelCustomizationUUID"); + UUID = extractValue (vfModule.getMetadata(), "vfModuleModelUUID"); addParameter("vf_customization_uuid", vfNodeModel.getCustomizationUUIDNoQuotes()); // extract properties - addParameter("vf_module_type", extractValue(group, SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE)); - addParameter("vf_module_label", extractValue(group, "vf_module_label")); - addIntParameter("availability_zone_count", extractValue(group, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)); - addParameter("ecomp_generated_vm_assignments", extractBooleanValue(group, SdcPropertyNames.PROPERTY_NAME_ECOMPGENERATEDVMASSIGNMENTS)); + addParameter("vf_module_type", extractValue(vfModule, SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE)); + addParameter("vf_module_label", extractValue(vfModule, "vf_module_label")); + addIntParameter("availability_zone_count", extractValue(vfModule, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)); + addParameter("ecomp_generated_vm_assignments", extractBooleanValue(vfModule, SdcPropertyNames.PROPERTY_NAME_ECOMPGENERATEDVMASSIGNMENTS)); } } diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java index 1fd10104c..846b79b49 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java @@ -3,7 +3,8 @@ package org.onap.ccsdk.sli.northbound.uebclient; import static org.junit.Assert.*; import static org.mockito.Mockito.mock; -import org.junit.Test; +import org.junit.Test; +import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.toscaparser.api.Group; import org.onap.ccsdk.sli.northbound.uebclient.SdncVFModel; @@ -12,10 +13,10 @@ public class SdncVFModuleModelTest { @Test public void testSdncVFModuleModelConstructor() { - Group mockGroup = mock(Group.class); + IEntityDetails mockEntity = mock(IEntityDetails.class); ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); SdncVFModel mockSdncVFModel = mock(SdncVFModel.class); - SdncVFModuleModel testSdncVFModel = new SdncVFModuleModel(mockCsarHelper, mockGroup, mockSdncVFModel); + SdncVFModuleModel testSdncVFModel = new SdncVFModuleModel(mockCsarHelper, mockEntity, mockSdncVFModel); assertNotNull(testSdncVFModel); } |