summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java31
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy4
2 files changed, 20 insertions, 15 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java
index d64dfb4a63..000627bec9 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java
@@ -55,7 +55,7 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
private static final String PROPERTY_QUERY_NAME = "hasAllProperties";
private static final String MODULE_QUERY_NAME = "hasAllModules";
- private static final Object NO_QUERY_EXECUTED = null;
+ private static final Map<String, NcmpServiceCmHandle> NO_QUERY_EXECUTED = null;
private final CpsDataPersistenceService cpsDataPersistenceService;
private final CpsAdminPersistenceService cpsAdminPersistenceService;
@@ -80,7 +80,7 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
combineWithModuleNameQuery(cmHandleQueryServiceParameters, publicPropertyQueryResult);
return combinedQueryResult == NO_QUERY_EXECUTED
- ? Collections.emptySet() : new HashSet<NcmpServiceCmHandle>(combinedQueryResult.values());
+ ? Collections.emptySet() : new HashSet<>(combinedQueryResult.values());
}
/**
@@ -121,14 +121,14 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
final Map<String, String> publicPropertyQueryPairs =
getPublicPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
if (publicPropertyQueryPairs.isEmpty()) {
- return null;
+ return NO_QUERY_EXECUTED;
}
Map<String, NcmpServiceCmHandle> cmHandleIdToNcmpServiceCmHandles = null;
for (final Map.Entry<String, String> entry : publicPropertyQueryPairs.entrySet()) {
- final String cmHandlePath = "//public-properties[@name='" + entry.getKey() + "' and @value='"
+ final String cpsPath = "//public-properties[@name='" + entry.getKey() + "' and @value='"
+ entry.getValue() + "']/ancestor::cm-handles";
- final Collection<DataNode> dataNodes = queryDataNodes(cmHandlePath);
+ final Collection<DataNode> dataNodes = queryDataNodes(cpsPath);
if (cmHandleIdToNcmpServiceCmHandles == NO_QUERY_EXECUTED) {
cmHandleIdToNcmpServiceCmHandles = collectDataNodesToNcmpServiceCmHandles(dataNodes);
} else {
@@ -157,12 +157,10 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
}
final Map<String, NcmpServiceCmHandle> queryResult = new HashMap<>(cmHandleIdsByModuleName.size());
if (previousQueryResult == NO_QUERY_EXECUTED) {
- //TODO Discuss performance/scaling of getting ALL cmHandles here
- getAllCmHandles().forEach(ncmpServiceCmHandle -> {
- if (cmHandleIdsByModuleName.contains(ncmpServiceCmHandle.getCmHandleId())) {
- queryResult.put(ncmpServiceCmHandle.getCmHandleId(), ncmpServiceCmHandle);
- }
- });
+ cmHandleIdsByModuleName.forEach(cmHandleId ->
+ queryResult.put(cmHandleId, createNcmpServiceCmHandle(
+ getDataNode("/dmi-registry/cm-handles[@id='" + cmHandleId + "']")))
+ );
return queryResult;
}
previousQueryResult.keySet().retainAll(cmHandleIdsByModuleName);
@@ -214,7 +212,7 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
}
private Set<NcmpServiceCmHandle> getAllCmHandles() {
- return queryDataNodes("/dmi-registry/cm-handles").stream()
+ return getDataNode("/dmi-registry").getChildDataNodes().stream()
.map(this::createNcmpServiceCmHandle).collect(Collectors.toSet());
}
@@ -223,9 +221,14 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
.parallelStream().map(Anchor::getName).collect(Collectors.toSet());
}
- private List<DataNode> queryDataNodes(final String cmHandlePath) {
+ private List<DataNode> queryDataNodes(final String cpsPath) {
return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- cmHandlePath, INCLUDE_ALL_DESCENDANTS);
+ cpsPath, INCLUDE_ALL_DESCENDANTS);
+ }
+
+ private DataNode getDataNode(final String cpsPath) {
+ return cpsDataPersistenceService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ cpsPath, INCLUDE_ALL_DESCENDANTS);
}
private NcmpServiceCmHandle createNcmpServiceCmHandle(final DataNode dataNode) {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy
index 6e60979c34..c121ce076f 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy
@@ -128,12 +128,14 @@ class NetworkCmProxyCmHandlerQueryServiceSpec extends Specification {
def pNFDemo2 = new DataNode(xpath: '/dmi-registry/cm-handles[@id=\'PNFDemo2\']', leaves: ['id':'PNFDemo2'])
def pNFDemo3 = new DataNode(xpath: '/dmi-registry/cm-handles[@id=\'PNFDemo3\']', leaves: ['id':'PNFDemo3'])
def pNFDemo4 = new DataNode(xpath: '/dmi-registry/cm-handles[@id=\'PNFDemo4\']', leaves: ['id':'PNFDemo4'])
+ def dmiRegistry = new DataNode(xpath: '/dmi-registry', childDataNodes: [pNFDemo1, pNFDemo2, pNFDemo3, pNFDemo4])
cpsDataPersistenceService.queryDataNodes(_, _, '//public-properties[@name=\'Contact\' and @value=\'newemailforstore@bookstore.com\']/ancestor::cm-handles', _) >> [pNFDemo1, pNFDemo2, pNFDemo4]
cpsDataPersistenceService.queryDataNodes(_, _, '//public-properties[@name=\'wont_match\' and @value=\'wont_match\']/ancestor::cm-handles', _) >> []
cpsDataPersistenceService.queryDataNodes(_, _, '//public-properties[@name=\'Contact2\' and @value=\'newemailforstore2@bookstore.com\']/ancestor::cm-handles', _) >> [pNFDemo4]
cpsDataPersistenceService.queryDataNodes(_, _, '//public-properties[@name=\'Contact2\' and @value=\'\']/ancestor::cm-handles', _) >> []
- cpsDataPersistenceService.queryDataNodes(_, _, '/dmi-registry/cm-handles', _) >> [pNFDemo1, pNFDemo2, pNFDemo3, pNFDemo4]
+
+ cpsDataPersistenceService.getDataNode(_, _, '/dmi-registry', _) >> dmiRegistry
cpsDataPersistenceService.getDataNode(_, _, '/dmi-registry/cm-handles[@id=\'PNFDemo1\']', _) >> pNFDemo1
cpsDataPersistenceService.getDataNode(_, _, '/dmi-registry/cm-handles[@id=\'PNFDemo2\']', _) >> pNFDemo2