diff options
author | Lee Anjella Macabuhay <lee.anjella.macabuhay@est.tech> | 2024-08-14 12:38:59 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2024-08-14 12:38:59 +0000 |
commit | 1de8a6e451c47c66a6d0ecc7a5585e2f3e8420b5 (patch) | |
tree | add9f1af27ca9a9e0a2473b25c3d0bf7b4907bed /cps-ncmp-service/src/main | |
parent | 8c5d2ed507d762320006f060e51234ffe6590977 (diff) | |
parent | 50518ca2035ec6d50e7aeadcc0f44b6d0c35fbb2 (diff) |
Merge "CPS-NCMP: Slow cmHandle registration when we use moduleSetTag, alternateId and dataProducerIdentifier"
Diffstat (limited to 'cps-ncmp-service/src/main')
-rw-r--r-- | cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncService.java | 31 |
1 files changed, 8 insertions, 23 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncService.java index d2bc3ada86..ca0f1c6a6d 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncService.java @@ -29,23 +29,17 @@ import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NFP_OPERATIONAL_D import java.time.OffsetDateTime; import java.util.Collection; import java.util.Collections; -import java.util.List; import java.util.Map; import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.onap.cps.api.CpsAnchorService; import org.onap.cps.api.CpsDataService; import org.onap.cps.api.CpsModuleService; -import org.onap.cps.ncmp.impl.inventory.CmHandleQueryService; import org.onap.cps.ncmp.impl.inventory.models.CmHandleState; import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle; -import org.onap.cps.ncmp.impl.utils.YangDataConverter; import org.onap.cps.spi.CascadeDeleteAllowed; -import org.onap.cps.spi.FetchDescendantsOption; import org.onap.cps.spi.exceptions.SchemaSetNotFoundException; -import org.onap.cps.spi.model.DataNode; import org.onap.cps.spi.model.ModuleReference; import org.onap.cps.utils.ContentType; import org.onap.cps.utils.JsonObjectMapper; @@ -58,7 +52,6 @@ public class ModuleSyncService { private final DmiModelOperations dmiModelOperations; private final CpsModuleService cpsModuleService; - private final CmHandleQueryService cmHandleQueryService; private final CpsDataService cpsDataService; private final CpsAnchorService cpsAnchorService; private final JsonObjectMapper jsonObjectMapper; @@ -113,34 +106,25 @@ public class ModuleSyncService { } private ModuleDelta getModuleDelta(final YangModelCmHandle yangModelCmHandle, final String targetModuleSetTag) { - final Collection<ModuleReference> allModuleReferences; final Map<String, String> newYangResources; - - final YangModelCmHandle cmHandleWithSameModuleSetTag = getAnyReadyCmHandleByModuleSetTag(targetModuleSetTag); - if (cmHandleWithSameModuleSetTag == null) { + Collection<ModuleReference> allModuleReferences = getModuleReferencesByModuleSetTag(targetModuleSetTag); + if (allModuleReferences.isEmpty()) { allModuleReferences = dmiModelOperations.getModuleReferences(yangModelCmHandle); newYangResources = dmiModelOperations.getNewYangResourcesFromDmi(yangModelCmHandle, cpsModuleService.identifyNewModuleReferences(allModuleReferences)); } else { log.info("Found other cm handle having same module set tag: {}", targetModuleSetTag); - allModuleReferences = cpsModuleService.getYangResourcesModuleReferences( - NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleWithSameModuleSetTag.getId()); newYangResources = NO_NEW_MODULES; } return new ModuleDelta(allModuleReferences, newYangResources); } - private YangModelCmHandle getAnyReadyCmHandleByModuleSetTag(final String moduleSetTag) { - if (StringUtils.isBlank(moduleSetTag)) { - return null; + private Collection<ModuleReference> getModuleReferencesByModuleSetTag(final String moduleSetTag) { + if (moduleSetTag == null || moduleSetTag.trim().isEmpty()) { + return Collections.emptyList(); } - final String escapedModuleSetTag = moduleSetTag.replace("'", "''"); - final List<DataNode> dataNodes = cmHandleQueryService.queryNcmpRegistryByCpsPath( - NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@module-set-tag='" + escapedModuleSetTag + "']", - FetchDescendantsOption.DIRECT_CHILDREN_ONLY); - return dataNodes.stream().map(YangDataConverter::toYangModelCmHandle) - .filter(cmHandle -> cmHandle.getCompositeState().getCmHandleState() == CmHandleState.READY) - .findFirst().orElse(null); + return cpsModuleService.getModuleReferencesByAttribute(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, + Map.of("module-set-tag", moduleSetTag), Map.of("cm-handle-state", CmHandleState.READY.name())); } private void setCmHandleModuleSetTag(final YangModelCmHandle yangModelCmHandle, final String newModuleSetTag) { @@ -149,4 +133,5 @@ public class ModuleSyncService { cpsDataService.updateNodeLeaves(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NCMP_DMI_REGISTRY_PARENT, jsonForUpdate, OffsetDateTime.now(), ContentType.JSON); } + } |