aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorleventecsanyi <levente.csanyi@est.tech>2025-03-06 13:33:12 +0100
committerleventecsanyi <levente.csanyi@est.tech>2025-03-06 14:24:06 +0100
commita0591f8876706785580ce6071e2b23fc3641b943 (patch)
tree10cc46e31d5bd75ad7cd05eea467574438bd51fe
parent1337752d3175309a66a50fe04aa9b289a33e4290 (diff)
Added query limits to NCMP service methods
- modified CmHandleQueryService if - added limits to certain Impl methods Issue-ID: CPS-2678 Change-Id: Ia5fd58afcd6f48404aeafba08ee2977c3efc6dcc Signed-off-by: leventecsanyi <levente.csanyi@est.tech>
-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.java10
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java6
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy8
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy4
5 files changed, 28 insertions, 10 deletions
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..8b6934b54c 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
@@ -54,6 +54,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;
@@ -99,8 +100,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
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 e145c62921..f331d608bd 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
@@ -144,7 +144,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);
}
@@ -193,7 +193,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);
}
@@ -207,7 +207,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/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..6ac42db782 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)
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 0ed9dd8aae..0d7722f450 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
@@ -165,7 +165,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'
@@ -312,7 +312,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')