diff options
4 files changed, 108 insertions, 25 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 27814c35..84918ab1 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 @@ -250,12 +250,18 @@ public class SdncBaseModel { protected void insertGroupData (NodeTemplate nodeTemplate, NodeTemplate targetNode, String groupType) throws IOException { - // Get the NetworkCollection groups of the node - Map<String, String> groupParams = new HashMap<String, String>(); - List<Group> groupList = sdcCsarHelper.getGroupsOfOriginOfNodeTemplateByToscaGroupType(nodeTemplate, groupType); - //List<Group> groupList2 = sdcCsarHelper.getGroupsOfTopologyTemplateByToscaGroupType(groupType); // returns nothing + // Get the Groups on a node - Convert to use getEntity in 19.08 + EntityQuery entityQuery = EntityQuery.newBuilder(groupType).build(); + String customizationUuid = getCustomizationUUIDNoQuotes(); + SdcTypes nodeTemplateSdcType = SdcTypes.valueOf(extractValue(nodeTemplate.getMetaData(), SdcPropertyNames.PROPERTY_NAME_TYPE)); + TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(nodeTemplateSdcType) + .customizationUUID(customizationUuid).build(); + List<IEntityDetails> groupList = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false); + if (groupList == null) { + return; + } - for (Group group : groupList) { + for (IEntityDetails group : groupList){ // Insert into RESOURCE_GROUP/ATTRIBUTE_VALUE_PAIR and RESOURCE_GROUP_TO_TARGET_NODE_MAPPING // RESOURCE_GROUP (group metadata): resource_uuid (CR node UUID), uuid, customization_uuid, invariant_uuid, name, version @@ -269,13 +275,13 @@ public class SdncBaseModel { try { Map<String, String> mappingCleanupParams = new HashMap<String, String>(); addParameter("group_uuid", groupModel.getUUID(), mappingCleanupParams); - addParameter("parent_uuid", extractValue(nodeTemplate.getMetaData(), "UUID"), mappingCleanupParams); - addParameter("target_node_uuid", extractValue(targetNode.getMetaData(), "UUID"), mappingCleanupParams); + addParameter("parent_uuid", extractValue(nodeTemplate.getMetaData(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingCleanupParams); + addParameter("target_node_uuid", extractValue(targetNode.getMetaData(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingCleanupParams); cleanupExistingToscaData("RESOURCE_GROUP_TO_TARGET_NODE_MAPPING", mappingCleanupParams); Map<String, String> mappingParams = new HashMap<String, String>(); - addParameter("parent_uuid", extractValue(nodeTemplate.getMetaData(), "UUID"), mappingParams); - addParameter("target_node_uuid", extractValue(targetNode.getMetaData(), "UUID"), mappingParams); + addParameter("parent_uuid", extractValue(nodeTemplate.getMetaData(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingParams); + addParameter("target_node_uuid", extractValue(targetNode.getMetaData(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingParams); String targetType = extractValue(targetNode.getMetaData(), PARAM_TYPE_KEY); addParameter("target_type", targetType, mappingParams); String tableName = ""; @@ -495,6 +501,68 @@ public class SdncBaseModel { } } + protected void insertNodeCapabilitiesEntityData (Map<String, CapabilityAssignment> capabilities) throws IOException { + + // Process the capabilities + for (Map.Entry<String, CapabilityAssignment> entry : capabilities.entrySet()) { + CapabilityAssignment capability = entry.getValue(); + + // Insert into NODE_CAPABILITY: + // capability_id (generated) + // capability_provider_uuid - UUID of this node + // capability_provider_customization_uuid - customization UUID of this node + // capability_name - capability.getName() + // capability_type - ? + + // Check capability name against relevant capabilities + boolean capabilityIsRelevant = false; + /*List<String> relevantCapabilities = config.getRelevantCapabilityNames(); + for (String relevantCapabilityName : relevantCapabilities ) { + + if (capability.getName().toLowerCase().contains(relevantCapabilityName.toLowerCase())) { + capabilityIsRelevant = true; + } + }*/ + + if (capabilityIsRelevant == false){ + continue; + } + + String capabilityProviderUuid = getUUID(); + + Map<String, String> cleanupParams = new HashMap<String, String>(); + addParameter("capability_provider_uuid", capabilityProviderUuid, cleanupParams); // node customization UUID + addParameter("capability_provider_customization_uuid", getCustomizationUUIDNoQuotes(), cleanupParams); // node customization UUID + addParameter("capability_name", capability.getName(), cleanupParams); + + Map<String, String> nodeCapabilityParams = new HashMap<String, String>(); + addParameter("capability_provider_customization_uuid", getCustomizationUUIDNoQuotes(), nodeCapabilityParams); // node customization UUID + addParameter("capability_name", capability.getName(), nodeCapabilityParams); + addParameter("capability_type", extractValue(capability, PARAM_TYPE_KEY), nodeCapabilityParams); + + // Insert NODE_CAPABILITY data for each capability + String capabilityId = ""; + try { + + cleanupExistingToscaData("NODE_CAPABILITY", cleanupParams); // will also delete NODE_CAPABILITY_PROPERTY with same capability_id + LOG.info("Call insertToscaData for NODE_CAPABILITY where capability_provider_uuid = " + capabilityProviderUuid + " and capability_name = " + capability.getName()); + insertToscaData(buildSql("NODE_CAPABILITY", "capability_provider_uuid", capabilityProviderUuid, model_yaml, nodeCapabilityParams), null); + + // Get capabilityId for capability just inserted + CachedRowSet rowData = getToscaData("NODE_CAPABILITY", nodeCapabilityParams); + rowData.first(); + int capabilityIdint = rowData.getInt("capability_id"); + capabilityId = capabilityId.valueOf(capabilityIdint); + + } catch (IOException | SQLException e) { + LOG.error("Could not insert Tosca CSAR data into the NODE_CAPABILITY table"); + throw new IOException (e); + } + + insertNodeCapabilityPropertyData (capability, capabilityId); + } + } + protected void insertNodeCapabilityPropertyData(CapabilityAssignment capability, String capabilityId) throws IOException { // Insert property name / value into NODE_CAPABILITY_PROPERTY 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 dedaa9a2..268590fe 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 @@ -25,6 +25,7 @@ package org.onap.ccsdk.sli.northbound.uebclient; import java.io.IOException; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; +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.sdc.toscaparser.api.NodeTemplate; @@ -39,28 +40,33 @@ public class SdncGroupModel extends SdncBaseModel { private static final String groupType = "group_type"; - public SdncGroupModel(ISdcCsarHelper sdcCsarHelper, Group group, NodeTemplate nodeTemplate, SdncUebConfiguration config, DBResourceManager jdbcDataSource) throws IOException { + public SdncGroupModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails group, NodeTemplate nodeTemplate, SdncUebConfiguration config, DBResourceManager jdbcDataSource) throws IOException { super(sdcCsarHelper, group); // Metadata for Resource group is not extracted in base class due to inconsistency in TOSCA model Group object Metadata metadata = group.getMetadata(); + params.remove("invariant_uuid"); // remove invariant_uuid which is added by base class, it does not apply for groups invariantUUID = extractValue (metadata, "invariantUUID"); addParameter("group_invariant_uuid", invariantUUID); + params.remove("uuid"); // remove uuid which is added by base class, it does not apply for groups UUID = extractValue (metadata, "UUID"); addParameter("group_uuid", UUID); addParameter("group_name", extractValue (metadata, "name")); - addParameter(groupType, group.getType()); + addParameter(groupType, group.getToscaType()); addParameter("version", extractValue (metadata, "version")); // extract properties addParameter("vfc_parent_port_role", extractValue(group, "vfc_parent_port_role"), attributeValueParams); addParameter("subinterface_role", extractValue(group, "subinterface_role"), attributeValueParams); - // relevant complex group properties are extracted and inserted into ATTRIBUTE_VALUE_PAIR - addParameter(extractGetInputName (group, groupType), extractGetInputValue(group, nodeTemplate, groupType), attributeValueParams); - addParameter(extractGetInputName (group, "group_role"), extractGetInputValue(group, nodeTemplate, "group_role"), attributeValueParams); - addParameter(extractGetInputName (group, "group_function"), extractGetInputValue(group, nodeTemplate, "group_function"), attributeValueParams); + // relevant complex group properties are extracted and inserted into ATTRIBUTE_VALUE_PAIR + String extractedGroupType = extractValue (group, groupType); + String extractedGroupRole = extractValue (group, "group_role"); + String extractedGroupFunction = extractValue (group, "group_function"); + addParameter(groupType, extractedGroupType, attributeValueParams); + addParameter("group_role", extractedGroupRole, attributeValueParams); + addParameter("group_function", extractedGroupFunction, attributeValueParams); } public void insertGroupData(NodeTemplate resourceNodeTemplate) throws IOException { 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 750cb72a..2b2d078f 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 @@ -370,24 +370,32 @@ public class SdncVFModel extends SdncBaseModel { // Insert Group data in RESOURCE_GROUP // Store group capabilities and capability properties in NODE_CAPABILITY and NODE_CAPABILITY_PROPERTY table - // For each VF, insert CFVC data - 1806 - List<Group> vfcInstanceGroupListForVf = sdcCsarHelper.getGroupsOfOriginOfNodeTemplateByToscaGroupType(nodeTemplate, "org.openecomp.groups.VfcInstanceGroup"); - for (Group group : vfcInstanceGroupListForVf){ + // For each VF, insert VFC Instance Group data (convert to use getEntity in 19.08) + EntityQuery entityQuery = EntityQuery.newBuilder("org.openecomp.groups.VfcInstanceGroup").build(); + String vfCustomizationUuid = getCustomizationUUIDNoQuotes(); + TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF) + .customizationUUID(vfCustomizationUuid).build(); + List<IEntityDetails> vfcInstanceGroupListForVf = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false); + if (vfcInstanceGroupListForVf == null) { + return; + } + + for (IEntityDetails group : vfcInstanceGroupListForVf){ SdncGroupModel groupModel = new SdncGroupModel (sdcCsarHelper, group, nodeTemplate, config, jdbcDataSource); groupModel.insertGroupData(nodeTemplate); // For each group, populate NODE_CAPABILITY/NODE_CAPABILITY_PROPERTY - insertNodeCapabilitiesData(group.getCapabilities()); + insertNodeCapabilitiesEntityData(group.getCapabilities()); // Store relationship between VfcInstanceGroup and node-type=VFC in RESOURCE_GROUP_TO_TARGET_NODE_MAPPING table // target is each VFC in targets section of group - List<NodeTemplate> targetNodeList = group.getMemberNodes(); - for (NodeTemplate targetNode : targetNodeList) { + List<IEntityDetails> targetNodeList = group.getMemberNodes(); + for (IEntityDetails targetNode : targetNodeList) { - String targetNodeUuid = extractValue(targetNode.getMetaData(), SdcPropertyNames.PROPERTY_NAME_UUID); - String targetNodeCustomizationUuid = extractValue(targetNode.getMetaData(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); - String targetNodeType = extractValue(targetNode.getMetaData(), SdcPropertyNames.PROPERTY_NAME_TYPE); + String targetNodeUuid = extractValue(targetNode.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID); + String targetNodeCustomizationUuid = extractValue(targetNode.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); + String targetNodeType = extractValue(targetNode.getMetadata(), SdcPropertyNames.PROPERTY_NAME_TYPE); // insert RESOURCE_GROUP_TO_TARGET_NODE_MAPPING try { diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModelTest.java index 0c6030b4..8bf3c914 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModelTest.java @@ -6,6 +6,7 @@ import static org.mockito.Mockito.*; import java.io.IOException; 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.NodeTemplate; import org.onap.sdc.toscaparser.api.Group; @@ -17,7 +18,7 @@ import org.onap.ccsdk.sli.core.dblib.DBResourceManager; public void testSdncGroupModelConstructor() { ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); NodeTemplate nodeTemplate = mock(NodeTemplate.class); - Group group = mock(Group.class); + IEntityDetails group = mock(IEntityDetails.class); DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); SdncUebConfiguration mockSdncUebConfiguration = mock(SdncUebConfiguration.class); SdncGroupModel testSdncGroupModel = null; |