aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main
diff options
context:
space:
mode:
authorseanbeirne <sean.beirne@est.tech>2024-10-21 16:18:27 +0100
committerseanbeirne <sean.beirne@est.tech>2024-11-05 13:44:45 +0000
commita1a71f782f2db1b50a41f095d49c981f5095b4fb (patch)
treef915a69c83d74ce7ecf2f0735cff5951a4f4368c /cps-ncmp-service/src/main
parentc475188530572efedbcb606239da0cdcee48c05b (diff)
Support Alternate-Id for CPS-E05 data batch interface
Issue-ID: CPS-2274 Change-Id: I75163bc7943fca5cbbe8c24601a2dfc184a9e6cc Signed-off-by: seanbeirne <sean.beirne@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/data/models/DataOperationDefinition.java4
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java8
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpPassthroughResourceRequestHandler.java4
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/utils/DmiDataOperationsHelper.java54
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java8
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java24
6 files changed, 75 insertions, 27 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/data/models/DataOperationDefinition.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/data/models/DataOperationDefinition.java
index d1ff1a5815..79da44af8f 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/data/models/DataOperationDefinition.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/data/models/DataOperationDefinition.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation
+ * Copyright (C) 2023-2024 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,5 +45,5 @@ public class DataOperationDefinition {
@JsonProperty("targetIds")
@Valid
- private List<String> cmHandleIds = new ArrayList<>();
+ private List<String> cmHandleReferences = new ArrayList<>();
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java
index 301b8195e4..c4bdc1cf1b 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java
@@ -139,10 +139,10 @@ public class DmiDataOperations {
final String requestId,
final String authorization) {
- final Set<String> cmHandlesIds = getDistinctCmHandleIds(dataOperationRequest);
+ final Set<String> cmHandlesReferences = getDistinctCmHandleReferences(dataOperationRequest);
final Collection<YangModelCmHandle> yangModelCmHandles
- = inventoryPersistence.getYangModelCmHandles(cmHandlesIds);
+ = inventoryPersistence.getYangModelCmHandlesFromCmHandleReferences(cmHandlesReferences);
final Map<String, List<DmiDataOperation>> operationsOutPerDmiServiceName
= DmiDataOperationsHelper.processPerDefinitionInDataOperationsRequest(topicParamInQuery,
@@ -246,10 +246,10 @@ public class DmiDataOperations {
}
}
- private static Set<String> getDistinctCmHandleIds(final DataOperationRequest dataOperationRequest) {
+ private static Set<String> getDistinctCmHandleReferences(final DataOperationRequest dataOperationRequest) {
return dataOperationRequest.getDataOperationDefinitions().stream()
.flatMap(dataOperationDefinition ->
- dataOperationDefinition.getCmHandleIds().stream()).collect(Collectors.toSet());
+ dataOperationDefinition.getCmHandleReferences().stream()).collect(Collectors.toSet());
}
private void asyncSendMultipleRequest(final String requestId, final String topicParamInQuery,
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpPassthroughResourceRequestHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpPassthroughResourceRequestHandler.java
index a21210c376..8920839cd5 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpPassthroughResourceRequestHandler.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpPassthroughResourceRequestHandler.java
@@ -91,10 +91,10 @@ public class NcmpPassthroughResourceRequestHandler extends NcmpDatastoreRequestH
throw new InvalidDatastoreException(dataOperationDefinition.getDatastore()
+ " datastore is not supported");
}
- if (dataOperationDefinition.getCmHandleIds().size() > MAXIMUM_CM_HANDLES_PER_OPERATION) {
+ if (dataOperationDefinition.getCmHandleReferences().size() > MAXIMUM_CM_HANDLES_PER_OPERATION) {
final String errorMessage = String.format(PAYLOAD_TOO_LARGE_TEMPLATE,
dataOperationDefinition.getOperationId(),
- dataOperationDefinition.getCmHandleIds().size());
+ dataOperationDefinition.getCmHandleReferences().size());
throw new PayloadTooLargeException(errorMessage);
}
});
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/utils/DmiDataOperationsHelper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/utils/DmiDataOperationsHelper.java
index 3104be5539..f1dc9af09d 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/utils/DmiDataOperationsHelper.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/utils/DmiDataOperationsHelper.java
@@ -31,7 +31,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -71,8 +70,9 @@ public class DmiDataOperationsHelper {
final Map<String, List<DmiDataOperation>> dmiDataOperationsOutPerDmiServiceName = new HashMap<>();
final MultiValueMap<DmiDataOperation, Map<NcmpResponseStatus,
- List<String>>> cmHandleIdsPerResponseCodesPerOperation = new LinkedMultiValueMap<>();
- final Set<String> nonReadyCmHandleIdsLookup = filterAndGetNonReadyCmHandleIds(yangModelCmHandles);
+ List<String>>> cmHandleReferencesPerResponseCodesPerOperation = new LinkedMultiValueMap<>();
+ final Map<String, String> nonReadyCmHandleReferencesLookup =
+ filterAndGetNonReadyCmHandleReferences(yangModelCmHandles);
final Map<String, Map<String, Map<String, String>>> dmiPropertiesPerCmHandleIdPerServiceName =
DmiServiceNameOrganizer.getDmiPropertiesPerCmHandleIdPerServiceName(yangModelCmHandles);
@@ -84,17 +84,19 @@ public class DmiDataOperationsHelper {
for (final DataOperationDefinition dataOperationDefinitionIn :
dataOperationRequestIn.getDataOperationDefinitions()) {
- final List<String> nonExistingCmHandleIds = new ArrayList<>();
- final List<String> nonReadyCmHandleIds = new ArrayList<>();
- for (final String cmHandleId : dataOperationDefinitionIn.getCmHandleIds()) {
- if (nonReadyCmHandleIdsLookup.contains(cmHandleId)) {
- nonReadyCmHandleIds.add(cmHandleId);
+ final List<String> nonExistingCmHandleReferences = new ArrayList<>();
+ final List<String> nonReadyCmHandleReferences = new ArrayList<>();
+ for (final String cmHandleReference : dataOperationDefinitionIn.getCmHandleReferences()) {
+ if (nonReadyCmHandleReferencesLookup.containsKey(cmHandleReference)
+ || nonReadyCmHandleReferencesLookup.containsValue(cmHandleReference)) {
+ nonReadyCmHandleReferences.add(cmHandleReference);
} else {
+ final String cmHandleId = getCmHandleId(cmHandleReference, yangModelCmHandles);
final String dmiServiceName = dmiServiceNamesPerCmHandleId.get(cmHandleId);
final Map<String, String> cmHandleIdProperties
= dmiPropertiesPerCmHandleIdPerServiceName.get(dmiServiceName).get(cmHandleId);
if (cmHandleIdProperties == null) {
- nonExistingCmHandleIds.add(cmHandleId);
+ nonExistingCmHandleReferences.add(cmHandleReference);
} else {
final DmiDataOperation dmiBatchOperationOut = getOrAddDmiBatchOperation(dmiServiceName,
dataOperationDefinitionIn, dmiDataOperationsOutPerDmiServiceName);
@@ -105,14 +107,14 @@ public class DmiDataOperationsHelper {
}
}
}
- populateCmHandleIdsPerOperationIdPerResponseCode(cmHandleIdsPerResponseCodesPerOperation,
+ populateCmHandleIdsPerOperationIdPerResponseCode(cmHandleReferencesPerResponseCodesPerOperation,
DmiDataOperation.buildDmiDataOperationRequestBodyWithoutCmHandles(dataOperationDefinitionIn),
- CM_HANDLES_NOT_FOUND, nonExistingCmHandleIds);
- populateCmHandleIdsPerOperationIdPerResponseCode(cmHandleIdsPerResponseCodesPerOperation,
+ CM_HANDLES_NOT_FOUND, nonExistingCmHandleReferences);
+ populateCmHandleIdsPerOperationIdPerResponseCode(cmHandleReferencesPerResponseCodesPerOperation,
DmiDataOperation.buildDmiDataOperationRequestBodyWithoutCmHandles(dataOperationDefinitionIn),
- CM_HANDLES_NOT_READY, nonReadyCmHandleIds);
+ CM_HANDLES_NOT_READY, nonReadyCmHandleReferences);
}
- publishErrorMessageToClientTopic(topicParamInQuery, requestId, cmHandleIdsPerResponseCodesPerOperation);
+ publishErrorMessageToClientTopic(topicParamInQuery, requestId, cmHandleReferencesPerResponseCodesPerOperation);
return dmiDataOperationsOutPerDmiServiceName;
}
@@ -182,10 +184,26 @@ public class DmiDataOperationsHelper {
return dmiBatchOperationsOut.get(dmiBatchOperationsOut.size() - 1);
}
- private static Set<String> filterAndGetNonReadyCmHandleIds(final Collection<YangModelCmHandle> yangModelCmHandles) {
- return yangModelCmHandles.stream()
- .filter(yangModelCmHandle -> yangModelCmHandle.getCompositeState().getCmHandleState()
- != CmHandleState.READY).map(YangModelCmHandle::getId).collect(Collectors.toSet());
+ private static Map<String, String> filterAndGetNonReadyCmHandleReferences(
+ final Collection<YangModelCmHandle> yangModelCmHandles) {
+ final Map<String, String> cmHandleReferenceMap = new HashMap<>(yangModelCmHandles.size());
+ for (final YangModelCmHandle yangModelCmHandle: yangModelCmHandles) {
+ if (yangModelCmHandle.getCompositeState().getCmHandleState() != CmHandleState.READY) {
+ cmHandleReferenceMap.put(yangModelCmHandle.getId(), yangModelCmHandle.getAlternateId());
+ }
+ }
+ return cmHandleReferenceMap;
+ }
+
+ private static String getCmHandleId(final String cmHandleReference,
+ final Collection<YangModelCmHandle> yangModelCmHandles) {
+ for (final YangModelCmHandle yangModelCmHandle: yangModelCmHandles) {
+ if (cmHandleReference.equals(yangModelCmHandle.getId())
+ || cmHandleReference.equals(yangModelCmHandle.getAlternateId())) {
+ return yangModelCmHandle.getId();
+ }
+ }
+ return cmHandleReference;
}
private static void populateCmHandleIdsPerOperationIdPerResponseCode(final MultiValueMap<DmiDataOperation,
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java
index 850edf7d57..de8e8e80a7 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java
@@ -72,6 +72,14 @@ public interface InventoryPersistence extends NcmpPersistence {
Collection<YangModelCmHandle> getYangModelCmHandles(Collection<String> cmHandleIds);
/**
+ * This method retrieves DMI service name, DMI properties and the state for a given list of cm handle references.
+ *
+ * @param cmHandleReferences a list of the ids of the cm handles
+ * @return collection of yang model cm handles
+ */
+ Collection<YangModelCmHandle> getYangModelCmHandlesFromCmHandleReferences(Collection<String> cmHandleReferences);
+
+ /**
* Method to return module definitions by cmHandleId.
*
* @param cmHandleId cm handle ID
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 655d8437b1..d73fae9fbc 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
@@ -22,6 +22,7 @@
package org.onap.cps.ncmp.impl.inventory;
+import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS;
import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS;
import com.google.common.collect.Lists;
@@ -33,6 +34,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.CpsAnchorService;
import org.onap.cps.api.CpsDataService;
@@ -133,6 +135,19 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv
}
@Override
+ public Collection<YangModelCmHandle> getYangModelCmHandlesFromCmHandleReferences(
+ final Collection<String> cmHandleReferences) {
+
+ final String cpsPathForCmHandlesByReferences = getCpsPathForCmHandlesByReferences(cmHandleReferences);
+
+ final Collection<DataNode> cmHandlesAsDataNodes =
+ cmHandleQueryService.queryNcmpRegistryByCpsPath(
+ cpsPathForCmHandlesByReferences, INCLUDE_ALL_DESCENDANTS);
+
+ return YangDataConverter.toYangModelCmHandles(cmHandlesAsDataNodes);
+ }
+
+ @Override
public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleId(final String cmHandleId) {
return cpsModuleService.getModuleDefinitionsByAnchorName(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId);
}
@@ -190,7 +205,8 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv
return Collections.emptyList();
}
final String cpsPathForCmHandlesByAlternateIds = getCpsPathForCmHandlesByAlternateIds(alternateIds);
- return cmHandleQueryService.queryNcmpRegistryByCpsPath(cpsPathForCmHandlesByAlternateIds, OMIT_DESCENDANTS);
+ return cmHandleQueryService.queryNcmpRegistryByCpsPath(cpsPathForCmHandlesByAlternateIds,
+ INCLUDE_ALL_DESCENDANTS);
}
@Override
@@ -234,6 +250,12 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv
NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@alternate-id='", "']"));
}
+ private String getCpsPathForCmHandlesByReferences(final Collection<String> cmHandleReferences) {
+ return cmHandleReferences.stream()
+ .flatMap(id -> Stream.of("@id='" + id + "'", "@alternate-id='" + id + "'"))
+ .collect(Collectors.joining(" or ", NCMP_DMI_REGISTRY_PARENT + "/cm-handles[", "]"));
+ }
+
private static String createStateJsonData(final String state) {
return "{\"state\":" + state + "}";
}