aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpCachedResourceRequestHandler.java12
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminer.java56
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java10
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java28
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java2
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java8
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryService.java10
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java11
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncWatchdog.java2
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/AlternateIdMatcher.java26
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminerSpec.groovy27
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy10
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy4
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/utils/AlternateIdMatcherSpec.groovy16
14 files changed, 133 insertions, 89 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpCachedResourceRequestHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpCachedResourceRequestHandler.java
index 2d33234478..1b5dd2f853 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpCachedResourceRequestHandler.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpCachedResourceRequestHandler.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2024 Nordix Foundation
+ * Copyright (C) 2022-2025 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,7 +47,8 @@ public class NcmpCachedResourceRequestHandler extends NcmpDatastoreRequestHandle
*/
public Collection<DataNode> executeRequest(final String cmHandleId, final String resourceIdentifier,
final boolean includeDescendants) {
- final FetchDescendantsOption fetchDescendantsOption = getFetchDescendantsOption(includeDescendants);
+ final FetchDescendantsOption fetchDescendantsOption
+ = FetchDescendantsOption.getFetchDescendantsOption(includeDescendants);
return networkCmProxyQueryService.queryResourceDataOperational(cmHandleId, resourceIdentifier,
fetchDescendantsOption);
}
@@ -59,7 +60,8 @@ public class NcmpCachedResourceRequestHandler extends NcmpDatastoreRequestHandle
final String requestId,
final boolean includeDescendants,
final String authorization) {
- final FetchDescendantsOption fetchDescendantsOption = getFetchDescendantsOption(includeDescendants);
+ final FetchDescendantsOption fetchDescendantsOption
+ = FetchDescendantsOption.getFetchDescendantsOption(includeDescendants);
final DataNode dataNode = cpsDataService.getDataNodes(cmResourceAddress.getDatastoreName(),
cmResourceAddress.resolveCmHandleReferenceToId(),
@@ -68,8 +70,4 @@ public class NcmpCachedResourceRequestHandler extends NcmpDatastoreRequestHandle
return Mono.justOrEmpty(dataNode);
}
- private static FetchDescendantsOption getFetchDescendantsOption(final boolean includeDescendants) {
- return includeDescendants ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
- : FetchDescendantsOption.OMIT_DESCENDANTS;
- }
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminer.java
index 429a3790d4..f200aa2ad7 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminer.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminer.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2024 Nordix Foundation
+ * Copyright (C) 2024-2025 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,8 +21,8 @@
package org.onap.cps.ncmp.impl.datajobs;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
@@ -31,7 +31,9 @@ import org.onap.cps.ncmp.api.datajobs.models.DataJobWriteRequest;
import org.onap.cps.ncmp.api.datajobs.models.DmiWriteOperation;
import org.onap.cps.ncmp.api.datajobs.models.ProducerKey;
import org.onap.cps.ncmp.api.datajobs.models.WriteOperation;
-import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle;
+import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle;
+import org.onap.cps.ncmp.impl.dmi.DmiServiceNameResolver;
+import org.onap.cps.ncmp.impl.inventory.ParameterizedCmHandleQueryService;
import org.onap.cps.ncmp.impl.models.RequiredDmiService;
import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher;
import org.springframework.stereotype.Service;
@@ -42,6 +44,7 @@ import org.springframework.stereotype.Service;
public class WriteRequestExaminer {
private final AlternateIdMatcher alternateIdMatcher;
+ private final ParameterizedCmHandleQueryService parameterizedCmHandleQueryService;
private static final String PATH_SEPARATOR = "/";
/**
@@ -52,25 +55,35 @@ public class WriteRequestExaminer {
* @return {@code Map} map of Dmi Write Operations per Producer Key
*/
public Map<ProducerKey, List<DmiWriteOperation>> splitDmiWriteOperationsFromRequest(
- final String dataJobId,
- final DataJobWriteRequest dataJobWriteRequest) {
+ final String dataJobId, final DataJobWriteRequest dataJobWriteRequest) {
final Map<ProducerKey, List<DmiWriteOperation>> dmiWriteOperationsPerProducerKey = new HashMap<>();
+ final Map<String, NcmpServiceCmHandle> cmHandlePerAlternateId = getAllNcmpServiceCmHandlesWithoutProperties();
for (final WriteOperation writeOperation : dataJobWriteRequest.data()) {
- examineWriteOperation(dataJobId, dmiWriteOperationsPerProducerKey, writeOperation);
+ examineWriteOperation(dataJobId, dmiWriteOperationsPerProducerKey, writeOperation, cmHandlePerAlternateId);
}
return dmiWriteOperationsPerProducerKey;
}
+ private Map<String, NcmpServiceCmHandle> getAllNcmpServiceCmHandlesWithoutProperties() {
+ final Map<String, NcmpServiceCmHandle> ncmpServiceCmHandles = new HashMap<>();
+ for (final NcmpServiceCmHandle ncmpServiceCmHandle
+ : parameterizedCmHandleQueryService.getAllCmHandlesWithoutProperties()) {
+ ncmpServiceCmHandles.put(ncmpServiceCmHandle.getAlternateId(), ncmpServiceCmHandle);
+ }
+ return ncmpServiceCmHandles;
+ }
+
private void examineWriteOperation(final String dataJobId,
final Map<ProducerKey, List<DmiWriteOperation>> dmiWriteOperationsPerProducerKey,
- final WriteOperation writeOperation) {
+ final WriteOperation writeOperation,
+ final Map<String, NcmpServiceCmHandle> cmHandlePerAlternateId) {
log.debug("data job id for write operation is: {}", dataJobId);
- final YangModelCmHandle yangModelCmHandle = alternateIdMatcher
- .getYangModelCmHandleByLongestMatchingAlternateId(writeOperation.path(), PATH_SEPARATOR);
+ final NcmpServiceCmHandle ncmpServiceCmHandle = alternateIdMatcher
+ .getCmHandleByLongestMatchingAlternateId(writeOperation.path(), PATH_SEPARATOR, cmHandlePerAlternateId);
- final DmiWriteOperation dmiWriteOperation = createDmiWriteOperation(writeOperation, yangModelCmHandle);
+ final DmiWriteOperation dmiWriteOperation = createDmiWriteOperation(writeOperation, ncmpServiceCmHandle);
- final ProducerKey producerKey = createProducerKey(yangModelCmHandle);
+ final ProducerKey producerKey = createProducerKey(ncmpServiceCmHandle);
final List<DmiWriteOperation> dmiWriteOperations;
if (dmiWriteOperationsPerProducerKey.containsKey(producerKey)) {
dmiWriteOperations = dmiWriteOperationsPerProducerKey.get(producerKey);
@@ -81,27 +94,20 @@ public class WriteRequestExaminer {
dmiWriteOperations.add(dmiWriteOperation);
}
- private ProducerKey createProducerKey(final YangModelCmHandle yangModelCmHandle) {
- return new ProducerKey(yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA),
- yangModelCmHandle.getDataProducerIdentifier());
+ private ProducerKey createProducerKey(final NcmpServiceCmHandle ncmpServiceCmHandle) {
+ final String dmiDataServiceName =
+ DmiServiceNameResolver.resolveDmiServiceName(RequiredDmiService.DATA, ncmpServiceCmHandle);
+ return new ProducerKey(dmiDataServiceName, ncmpServiceCmHandle.getDataProducerIdentifier());
}
private DmiWriteOperation createDmiWriteOperation(final WriteOperation writeOperation,
- final YangModelCmHandle yangModelCmHandle) {
+ final NcmpServiceCmHandle ncmpServiceCmHandle) {
return new DmiWriteOperation(
writeOperation.path(),
writeOperation.op(),
- yangModelCmHandle.getModuleSetTag(),
+ ncmpServiceCmHandle.getModuleSetTag(),
writeOperation.value(),
writeOperation.operationId(),
- getPrivatePropertiesFromDataNode(yangModelCmHandle));
+ Collections.emptyMap()); // TODO: Private properties will be removed as part of CPS-2693.
}
-
- private Map<String, String> getPrivatePropertiesFromDataNode(final YangModelCmHandle yangModelCmHandle) {
- final Map<String, String> cmHandleDmiProperties = new LinkedHashMap<>();
- yangModelCmHandle.getDmiProperties()
- .forEach(dmiProperty -> cmHandleDmiProperties.put(dmiProperty.getName(), dmiProperty.getValue()));
- return cmHandleDmiProperties;
- }
-
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java
index f1f71dc57c..9cbc6b0650 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java
@@ -84,6 +84,16 @@ public interface CmHandleQueryService {
Collection<DataNode> queryNcmpRegistryByCpsPath(String cpsPath, FetchDescendantsOption fetchDescendantsOption);
/**
+ * Method to return data nodes representing the cm handles.
+ *
+ * @param cpsPath cps path for which the cmHandle is requested
+ * @param queryResultLimit the maximum number of data nodes to return; if less than 1, returns all matching nodes
+ * @return a list of data nodes representing the cm handles.
+ */
+ Collection<DataNode> queryNcmpRegistryByCpsPath(String cpsPath, FetchDescendantsOption fetchDescendantsOption,
+ int queryResultLimit);
+
+ /**
* Method to check the state of a cm handle with given id.
*
* @param cmHandleId cm handle id
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java
index 890522ca60..74e862691a 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java
@@ -26,6 +26,7 @@ import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DATASPACE_NA
import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR;
import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT;
+import com.hazelcast.map.IMap;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@@ -54,6 +55,7 @@ import org.springframework.stereotype.Component;
public class CmHandleQueryServiceImpl implements CmHandleQueryService {
private static final String ANCESTOR_CM_HANDLES = "/ancestor::cm-handles";
private static final String ALTERNATE_ID = "alternate-id";
+ private static final Integer NO_LIMIT = 0;
private final CpsDataService cpsDataService;
private final CpsQueryService cpsQueryService;
@@ -61,7 +63,7 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
private final Map<String, TrustLevel> trustLevelPerDmiPlugin;
@Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_CM_HANDLE)
- private final Map<String, TrustLevel> trustLevelPerCmHandleId;
+ private final IMap<String, TrustLevel> trustLevelPerCmHandleId;
private final CpsValidator cpsValidator;
@@ -99,8 +101,15 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
@Override
public Collection<DataNode> queryNcmpRegistryByCpsPath(final String cpsPath,
final FetchDescendantsOption fetchDescendantsOption) {
+ return queryNcmpRegistryByCpsPath(cpsPath, fetchDescendantsOption, NO_LIMIT);
+ }
+
+ @Override
+ public Collection<DataNode> queryNcmpRegistryByCpsPath(final String cpsPath,
+ final FetchDescendantsOption fetchDescendantsOption,
+ final int queryResultLimit) {
return cpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cpsPath,
- fetchDescendantsOption);
+ fetchDescendantsOption, queryResultLimit);
}
@Override
@@ -144,14 +153,15 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
final TrustLevel dmiTrustLevel = mapEntry.getValue();
final Collection<String> candidateCmHandleIds = getCmHandleReferencesByDmiPluginIdentifier(
dmiPluginIdentifier, false);
- for (final String candidateCmHandleId : candidateCmHandleIds) {
- final TrustLevel candidateCmHandleTrustLevel = trustLevelPerCmHandleId.get(candidateCmHandleId);
- final TrustLevel effectiveTrustlevel =
- candidateCmHandleTrustLevel.getEffectiveTrustLevel(dmiTrustLevel);
- if (targetTrustLevel.equals(effectiveTrustlevel)) {
- selectedCmHandleReferences.add(candidateCmHandleId);
+ final Set<String> candidateCmHandleIdsSet = new HashSet<>(candidateCmHandleIds);
+ final Map<String, TrustLevel> trustLevelPerCmHandleIdInBatch =
+ trustLevelPerCmHandleId.getAll(candidateCmHandleIdsSet);
+ trustLevelPerCmHandleIdInBatch.forEach((cmHandleId, trustLevel) -> {
+ final TrustLevel effectiveTrustLevel = trustLevel.getEffectiveTrustLevel(dmiTrustLevel);
+ if (targetTrustLevel.equals(effectiveTrustLevel)) {
+ selectedCmHandleReferences.add(cmHandleId);
}
- }
+ });
}
if (outputAlternateId) {
return getAlternateIdsByCmHandleIds(selectedCmHandleReferences);
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java
index 75c52f3c60..ea8c3ca78d 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java
@@ -71,7 +71,7 @@ import org.springframework.stereotype.Service;
@RequiredArgsConstructor
public class CmHandleRegistrationService {
- private static final int DELETE_BATCH_SIZE = 100;
+ private static final int DELETE_BATCH_SIZE = 300;
private final CmHandleRegistrationServicePropertyHandler cmHandleRegistrationServicePropertyHandler;
private final InventoryPersistence inventoryPersistence;
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java
index 7f6fe76dcc..cf98b31614 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java
@@ -59,7 +59,7 @@ import org.springframework.stereotype.Component;
@Component
public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements InventoryPersistence {
- private static final int CMHANDLE_BATCH_SIZE = 100;
+ private static final int CMHANDLE_BATCH_SIZE = 300;
private final CpsModuleService cpsModuleService;
private final CpsValidator cpsValidator;
@@ -145,7 +145,7 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv
final Collection<DataNode> cmHandlesAsDataNodes =
cmHandleQueryService.queryNcmpRegistryByCpsPath(
- cpsPathForCmHandlesByReferences, INCLUDE_ALL_DESCENDANTS);
+ cpsPathForCmHandlesByReferences, INCLUDE_ALL_DESCENDANTS, cmHandleReferences.size());
return YangDataConverter.toYangModelCmHandles(cmHandlesAsDataNodes);
}
@@ -195,7 +195,7 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv
public YangModelCmHandle getYangModelCmHandleByAlternateId(final String alternateId) {
final String cpsPathForCmHandleByAlternateId = getCpsPathForCmHandleByAlternateId(alternateId);
final Collection<DataNode> dataNodes = cmHandleQueryService
- .queryNcmpRegistryByCpsPath(cpsPathForCmHandleByAlternateId, OMIT_DESCENDANTS);
+ .queryNcmpRegistryByCpsPath(cpsPathForCmHandleByAlternateId, OMIT_DESCENDANTS, 1);
if (dataNodes.isEmpty()) {
throw new CmHandleNotFoundException(alternateId);
}
@@ -209,7 +209,7 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv
}
final String cpsPathForCmHandlesByAlternateIds = getCpsPathForCmHandlesByAlternateIds(alternateIds);
final Collection<DataNode> dataNodes = cmHandleQueryService.queryNcmpRegistryByCpsPath(
- cpsPathForCmHandlesByAlternateIds, INCLUDE_ALL_DESCENDANTS);
+ cpsPathForCmHandlesByAlternateIds, INCLUDE_ALL_DESCENDANTS, alternateIds.size());
return YangDataConverter.toYangModelCmHandles(dataNodes);
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryService.java
index 3db4920d3e..fc8884433c 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryService.java
@@ -75,4 +75,14 @@ public interface ParameterizedCmHandleQueryService {
* @return collection of cm handles
*/
Collection<NcmpServiceCmHandle> getAllCmHandles();
+
+ /**
+ * Retrieves all {@code NcmpServiceCmHandle} instances without their associated properties.
+ * This method fetches the relevant data nodes from the inventory persistence layer and
+ * converts them into {@code NcmpServiceCmHandle} objects. Only the handles are returned,
+ * without any additional properties.
+ *
+ * @return a collection of {@code NcmpServiceCmHandle} instances without properties.
+ */
+ Collection<NcmpServiceCmHandle> getAllCmHandlesWithoutProperties();
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java
index 4c1032efad..c44234d28c 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java
@@ -97,7 +97,16 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
@Override
public Collection<NcmpServiceCmHandle> getAllCmHandles() {
- final DataNode dataNode = inventoryPersistence.getDataNode(NCMP_DMI_REGISTRY_PARENT).iterator().next();
+ return toNcmpServiceCmHandles(inventoryPersistence.getDataNode(NCMP_DMI_REGISTRY_PARENT));
+ }
+
+ @Override
+ public Collection<NcmpServiceCmHandle> getAllCmHandlesWithoutProperties() {
+ return toNcmpServiceCmHandles(inventoryPersistence.getDataNode(NCMP_DMI_REGISTRY_PARENT, DIRECT_CHILDREN_ONLY));
+ }
+
+ private Collection<NcmpServiceCmHandle> toNcmpServiceCmHandles(final Collection<DataNode> dataNodes) {
+ final DataNode dataNode = dataNodes.iterator().next();
return dataNode.getChildDataNodes().stream().map(this::createNcmpServiceCmHandle).collect(Collectors.toSet());
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncWatchdog.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncWatchdog.java
index 6eefedb633..8c9ec03dd9 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncWatchdog.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncWatchdog.java
@@ -44,7 +44,7 @@ public class ModuleSyncWatchdog {
private final ModuleSyncTasks moduleSyncTasks;
private final IMap<String, String> cpsAndNcmpLock;
- private static final int MODULE_SYNC_BATCH_SIZE = 100;
+ private static final int MODULE_SYNC_BATCH_SIZE = 300;
private static final String VALUE_FOR_HAZELCAST_IN_PROGRESS_MAP = "Started";
/**
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/AlternateIdMatcher.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/AlternateIdMatcher.java
index 750a5050f2..b8e4e7feda 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/AlternateIdMatcher.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/AlternateIdMatcher.java
@@ -20,12 +20,12 @@
package org.onap.cps.ncmp.impl.utils;
+import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
-import org.onap.cps.ncmp.api.exceptions.CmHandleNotFoundException;
+import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle;
import org.onap.cps.ncmp.exceptions.NoAlternateIdMatchFoundException;
import org.onap.cps.ncmp.impl.inventory.InventoryPersistence;
-import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle;
import org.onap.cps.utils.CpsValidator;
import org.springframework.stereotype.Service;
@@ -37,24 +37,26 @@ public class AlternateIdMatcher {
private final CpsValidator cpsValidator;
/**
- * Get yang model cm handle that matches longest alternate id by removing elements
+ * Get cm handle that matches longest alternate id by removing elements
* (as defined by the separator string) from right to left.
* If alternate id contains a hash then all elements after that hash are ignored.
*
- * @param alternateId alternate ID
- * @param separator a string that separates each element from the next.
- * @return yang model cm handle
+ * @param alternateId alternate ID
+ * @param separator a string that separates each element from the next.
+ * @param cmHandlePerAlternateId all CM-handles by alternate ID
+ * @return ncmp service cm handle
*/
- public YangModelCmHandle getYangModelCmHandleByLongestMatchingAlternateId(final String alternateId,
- final String separator) {
+ public NcmpServiceCmHandle getCmHandleByLongestMatchingAlternateId(
+ final String alternateId, final String separator,
+ final Map<String, NcmpServiceCmHandle> cmHandlePerAlternateId) {
final String[] splitPath = alternateId.split("#", 2);
String bestMatch = splitPath[0];
while (StringUtils.isNotEmpty(bestMatch)) {
- try {
- return inventoryPersistence.getYangModelCmHandleByAlternateId(bestMatch);
- } catch (final CmHandleNotFoundException ignored) {
- bestMatch = getParentPath(bestMatch, separator);
+ final NcmpServiceCmHandle ncmpServiceCmHandle = cmHandlePerAlternateId.get(bestMatch);
+ if (ncmpServiceCmHandle != null) {
+ return ncmpServiceCmHandle;
}
+ bestMatch = getParentPath(bestMatch, separator);
}
throw new NoAlternateIdMatchFoundException(alternateId);
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminerSpec.groovy
index 6aa84d1c7f..d051927b3d 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminerSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminerSpec.groovy
@@ -23,24 +23,27 @@ package org.onap.cps.ncmp.impl.datajobs
import org.onap.cps.ncmp.api.datajobs.models.DataJobWriteRequest
import org.onap.cps.ncmp.api.datajobs.models.WriteOperation
import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle
-import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle
+import org.onap.cps.ncmp.impl.inventory.ParameterizedCmHandleQueryService
import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher
import spock.lang.Specification
class WriteRequestExaminerSpec extends Specification {
def mockAlternateIdMatcher = Mock(AlternateIdMatcher)
- def objectUnderTest = new WriteRequestExaminer(mockAlternateIdMatcher)
+ def mockParameterizedCmHandleQueryService = Mock(ParameterizedCmHandleQueryService)
+ def objectUnderTest = new WriteRequestExaminer(mockAlternateIdMatcher, mockParameterizedCmHandleQueryService)
def setup() {
- def ch1 = new YangModelCmHandle(id: 'ch1', dmiServiceName: 'dmiA', dataProducerIdentifier: 'p1', dmiProperties: [])
- def ch2 = new YangModelCmHandle(id: 'ch2', dmiServiceName: 'dmiA', dataProducerIdentifier: 'p1', dmiProperties: [])
- def ch3 = new YangModelCmHandle(id: 'ch3', dmiServiceName: 'dmiA', dataProducerIdentifier: 'p2', dmiProperties: [])
- def ch4 = new YangModelCmHandle(id: 'ch4', dmiServiceName: 'dmiB', dataProducerIdentifier: 'p1', dmiProperties: [])
- mockAlternateIdMatcher.getYangModelCmHandleByLongestMatchingAlternateId('fdn1', '/') >> ch1
- mockAlternateIdMatcher.getYangModelCmHandleByLongestMatchingAlternateId('fdn2', '/') >> ch2
- mockAlternateIdMatcher.getYangModelCmHandleByLongestMatchingAlternateId('fdn3', '/') >> ch3
- mockAlternateIdMatcher.getYangModelCmHandleByLongestMatchingAlternateId('fdn4', '/') >> ch4
+ def ch1 = new NcmpServiceCmHandle(cmHandleId: 'ch1', dmiServiceName: 'dmiA', moduleSetTag: 'someModuleSetTag', alternateId: 'fdn1', dataProducerIdentifier: 'p1')
+ def ch2 = new NcmpServiceCmHandle(cmHandleId: 'ch2', dmiServiceName: 'dmiA', moduleSetTag: 'someModuleSetTag', alternateId: 'fdn2', dataProducerIdentifier: 'p1')
+ def ch3 = new NcmpServiceCmHandle(cmHandleId: 'ch3', dmiServiceName: 'dmiA', moduleSetTag: 'someModuleSetTag', alternateId: 'fdn3', dataProducerIdentifier: 'p2')
+ def ch4 = new NcmpServiceCmHandle(cmHandleId: 'ch4', dmiServiceName: 'dmiB', moduleSetTag: 'someModuleSetTag', alternateId: 'fdn4', dataProducerIdentifier: 'p1')
+ def cmHandlePerAlternateId = ['fdn1': ch1, 'fdn2': ch2, 'fdn3': ch3, 'fdn4': ch4]
+ mockAlternateIdMatcher.getCmHandleByLongestMatchingAlternateId('fdn1', '/', cmHandlePerAlternateId) >> ch1
+ mockAlternateIdMatcher.getCmHandleByLongestMatchingAlternateId('fdn2', '/', cmHandlePerAlternateId) >> ch2
+ mockAlternateIdMatcher.getCmHandleByLongestMatchingAlternateId('fdn3', '/', cmHandlePerAlternateId) >> ch3
+ mockAlternateIdMatcher.getCmHandleByLongestMatchingAlternateId('fdn4', '/', cmHandlePerAlternateId) >> ch4
+ mockParameterizedCmHandleQueryService.getAllCmHandlesWithoutProperties() >> [ch1, ch2, ch3, ch4]
}
def 'Create a map of dmi write requests per producer key with #scenario.'() {
@@ -83,9 +86,9 @@ class WriteRequestExaminerSpec extends Specification {
def 'Validate the creation of a ProducerKey with correct dmiservicename.'() {
given: 'yangModelCmHandles with service name: "#dmiServiceName" and data service name: "#dataServiceName"'
- def yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(dmiServiceName, dataServiceName, '', new NcmpServiceCmHandle(cmHandleId: 'cm-handle-id-1'), '', '', 'dpi1')
+ def ncmpServiceCmHandle = new NcmpServiceCmHandle(dmiServiceName: dmiServiceName, dmiDataServiceName: dataServiceName, dataProducerIdentifier: 'dpi1')
when: 'the ProducerKey is created'
- def result = objectUnderTest.createProducerKey(yangModelCmHandle).toString()
+ def result = objectUnderTest.createProducerKey(ncmpServiceCmHandle).toString()
then: 'we get the ProducerKey with the correct service name'
assert result == expectedProducerKey
where: 'the following services are registered'
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy
index 884d968c4f..12e4d6b85d 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy
@@ -131,7 +131,7 @@ class CmHandleQueryServiceImplSpec extends Specification {
def cmHandleState = CmHandleState.ADVISED
and: 'the persistence service returns a list of data nodes'
mockCpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- "//state[@cm-handle-state='ADVISED']", OMIT_DESCENDANTS) >> sampleDataNodes
+ "//state[@cm-handle-state='ADVISED']", OMIT_DESCENDANTS, 0) >> sampleDataNodes
when: 'cm handles are fetched by state'
def result = objectUnderTest.queryCmHandleIdsByState(cmHandleState)
then: 'the returned result matches the result from the persistence service'
@@ -171,7 +171,7 @@ class CmHandleQueryServiceImplSpec extends Specification {
def 'Retrieve Cm Handles By Operational Sync State : UNSYNCHRONIZED'() {
given: 'cps data service returns a list of data nodes'
mockCpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- '//state/datastores/operational[@sync-state="'+'UNSYNCHRONIZED'+'"]/ancestor::cm-handles', OMIT_DESCENDANTS) >> sampleDataNodes
+ '//state/datastores/operational[@sync-state="'+'UNSYNCHRONIZED'+'"]/ancestor::cm-handles', OMIT_DESCENDANTS, 0) >> sampleDataNodes
when: 'cm handles are fetched by the UNSYNCHRONIZED operational sync state'
def result = objectUnderTest.queryCmHandlesByOperationalSyncState(DataStoreSyncState.UNSYNCHRONIZED)
then: 'the returned result is a list of data nodes returned by cps data service'
@@ -184,7 +184,7 @@ class CmHandleQueryServiceImplSpec extends Specification {
def cpsPath = "//state[@cm-handle-state='LOCKED']"
and: 'cps data service returns a valid data node for cm handle ancestor'
mockCpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- cpsPath + '/ancestor::cm-handles', INCLUDE_ALL_DESCENDANTS)
+ cpsPath + '/ancestor::cm-handles', INCLUDE_ALL_DESCENDANTS, 0)
>> Arrays.asList(cmHandleDataNode)
when: 'get cm handles by cps path is invoked'
def result = objectUnderTest.queryCmHandleAncestorsByCpsPath(cpsPath, INCLUDE_ALL_DESCENDANTS)
@@ -198,7 +198,7 @@ class CmHandleQueryServiceImplSpec extends Specification {
def cpsPath = "//cm-handles[@alternate-id='1']"
and: 'cps data service returns a valid data node'
mockCpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- cpsPath, INCLUDE_ALL_DESCENDANTS)
+ cpsPath, INCLUDE_ALL_DESCENDANTS, 0)
>> Arrays.asList(cmHandleDataNode)
when: 'get cm handles by cps path is invoked'
def result = objectUnderTest.queryCmHandleAncestorsByCpsPath(cpsPath, INCLUDE_ALL_DESCENDANTS)
@@ -241,7 +241,7 @@ class CmHandleQueryServiceImplSpec extends Specification {
mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@dmi-data-service-name=\'my-dmi-plugin-identifier\']/@alternate-id', _) >> [pnfDemo.getLeaves().get('alternate-id'), pnfDemo4.getLeaves().get('alternate-id')]
mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@dmi-model-service-name=\'my-dmi-plugin-identifier\']/@alternate-id', _) >> [pnfDemo2.getLeaves().get('alternate-id'), pnfDemo4.getLeaves().get('alternate-id')]
mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@id=\'PNFDemo\']/@alternate-id', _) >> [pnfDemo.getLeaves().get('alternate-id')]
- mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@id=\'PNFDemo2\' or @id=\'PNFDemo\' or @id=\'PNFDemo4\']/@alternate-id', _) >> [pnfDemo2.getLeaves().get('alternate-id'), pnfDemo.getLeaves().get('alternate-id'), pnfDemo4.getLeaves().get('alternate-id')]
+ mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@id=\'PNFDemo2\' or @id=\'PNFDemo4\' or @id=\'PNFDemo\']/@alternate-id', _) >> [pnfDemo2.getLeaves().get('alternate-id'), pnfDemo.getLeaves().get('alternate-id'), pnfDemo4.getLeaves().get('alternate-id')]
mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '//public-properties[@name=\'Contact\' and @value=\'newemailforstore@bookstore.com\']/ancestor::cm-handles/@id',_) >> [pnfDemo.getLeaves().get('id'), pnfDemo2.getLeaves().get('id'), pnfDemo4.getLeaves().get('id')]
mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '//public-properties[@name=\'Contact\' and @value=\'newemailforstore@bookstore.com\']/ancestor::cm-handles/@alternate-id',_) >> [pnfDemo.getLeaves().get('alternate-id'), pnfDemo2.getLeaves().get('alternate-id'), pnfDemo4.getLeaves().get('alternate-id')]
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy
index 2ba8505aaa..5619c5ac57 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy
@@ -164,7 +164,7 @@ class InventoryPersistenceImplSpec extends Specification {
def "Retrieve multiple YangModelCmHandles using cm handle references"() {
given: 'the cps data service returns 2 data nodes from the DMI registry'
def dataNodes = [new DataNode(xpath: xpath, leaves: ['id': cmHandleId, 'alternate-id':alternateId]), new DataNode(xpath: xpath2, leaves: ['id': cmHandleId2,'alternate-id':alternateId2])]
- mockCmHandleQueries.queryNcmpRegistryByCpsPath(_, INCLUDE_ALL_DESCENDANTS) >> dataNodes
+ mockCmHandleQueries.queryNcmpRegistryByCpsPath(_, INCLUDE_ALL_DESCENDANTS, _) >> dataNodes
when: 'retrieving the yang modelled cm handle'
def results = objectUnderTest.getYangModelCmHandlesFromCmHandleReferences([cmHandleId, cmHandleId2])
then: 'verify both have returned and cmhandleIds are correct'
@@ -311,7 +311,7 @@ class InventoryPersistenceImplSpec extends Specification {
def expectedXPath = '/dmi-registry/cm-handles[@alternate-id=\'alternate id\']'
def expectedDataNode = new DataNode(xpath: expectedXPath, leaves: [id: 'id', alternateId: 'alternate id'])
and: 'query service is invoked with expected xpath'
- mockCmHandleQueries.queryNcmpRegistryByCpsPath(expectedXPath, OMIT_DESCENDANTS) >> [expectedDataNode]
+ mockCmHandleQueries.queryNcmpRegistryByCpsPath(expectedXPath, OMIT_DESCENDANTS, _) >> [expectedDataNode]
mockYangDataConverter.toYangModelCmHandle(expectedDataNode) >> new YangModelCmHandle(id: 'id')
expect: 'getting the yang model cm handle'
assert objectUnderTest.getYangModelCmHandleByAlternateId('alternate id') == new YangModelCmHandle(id: 'id')
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/utils/AlternateIdMatcherSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/utils/AlternateIdMatcherSpec.groovy
index b59dd1a55f..098e88a644 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/utils/AlternateIdMatcherSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/utils/AlternateIdMatcherSpec.groovy
@@ -20,7 +20,7 @@
package org.onap.cps.ncmp.impl.utils
-import org.onap.cps.ncmp.api.exceptions.CmHandleNotFoundException
+import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle
import org.onap.cps.ncmp.exceptions.NoAlternateIdMatchFoundException
import org.onap.cps.ncmp.impl.inventory.InventoryPersistence
import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle
@@ -37,16 +37,12 @@ class AlternateIdMatcherSpec extends Specification {
def objectUnderTest = new AlternateIdMatcher(mockInventoryPersistence, new CpsValidatorImpl())
- def setup() {
- given: 'cm handle in the registry with alternate id /a/b'
- mockInventoryPersistence.getYangModelCmHandleByAlternateId('/a/b') >> new YangModelCmHandle()
- and: 'no other cm handle'
- mockInventoryPersistence.getYangModelCmHandleByAlternateId(_) >> { throw new CmHandleNotFoundException('') }
- }
-
def 'Finding longest alternate id matches.'() {
+ given: 'a cm handle with alternate id /a/b in the cached map of all cm handles'
+ def ch1 = new NcmpServiceCmHandle(cmHandleId: 'ch1', alternateId: '/a/b')
+ def cmHandlePerAlternateId = ['/a/b': ch1]
expect: 'querying for alternate id a matching result found'
- assert objectUnderTest.getYangModelCmHandleByLongestMatchingAlternateId(targetAlternateId, '/') != null
+ assert objectUnderTest.getCmHandleByLongestMatchingAlternateId(targetAlternateId, '/', cmHandlePerAlternateId) != null
where: 'the following parameters are used'
scenario | targetAlternateId
'exact match' | '/a/b'
@@ -61,7 +57,7 @@ class AlternateIdMatcherSpec extends Specification {
def 'Attempt to find longest alternate id match without any matches.'() {
when: 'attempt to find alternateId'
- objectUnderTest.getYangModelCmHandleByLongestMatchingAlternateId(targetAlternateId, '/')
+ objectUnderTest.getCmHandleByLongestMatchingAlternateId(targetAlternateId, '/', [:])
then: 'no alternate id match found exception thrown'
def thrown = thrown(NoAlternateIdMatchFoundException)
and: 'the exception has the relevant details from the error response'