summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main
diff options
context:
space:
mode:
authorlukegleeson <luke.gleeson@est.tech>2022-08-18 17:47:24 +0100
committerlukegleeson <luke.gleeson@est.tech>2022-08-25 13:48:11 +0100
commited6c05157f60328b0215bde544f7a4e9894fd15f (patch)
treed58edf7c57f0641b755e70766c60e844b321e5a4 /cps-ncmp-service/src/main
parentf71863640945153a163c1f51f88f9a799733e24e (diff)
Performance Improvement: Batch Update DataNodes
Implemented methods to perform a batch operation on updating datanodes Refactored replace data node(s) tree methods to update data node(s) and descendants Issue-ID: CPS-1203 Signed-off-by: lukegleeson <luke.gleeson@est.tech> Change-Id: I365d657422b19c9ce384110c9a23d041eaed06f4
Diffstat (limited to 'cps-ncmp-service/src/main')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java19
1 files changed, 18 insertions, 1 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java
index 14fc6d698a..c059ece0d3 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java
@@ -28,6 +28,8 @@ import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS;
import java.time.OffsetDateTime;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.CpsDataService;
@@ -91,12 +93,27 @@ public class InventoryPersistence {
public void saveCmHandleState(final String cmHandleId, final CompositeState compositeState) {
final String cmHandleJsonData = String.format("{\"state\":%s}",
jsonObjectMapper.asJsonString(compositeState));
- cpsDataService.replaceNodeTree(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ cpsDataService.updateDataNodeAndDescendants(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId),
cmHandleJsonData, OffsetDateTime.now());
}
/**
+ * Save all cm handles states in batch.
+ *
+ * @param cmHandleStates contains cm handle id and updated state
+ */
+ public void saveCmHandleStates(final Map<String, CompositeState> cmHandleStates) {
+ final Map<String, String> cmHandlesJsonDataMap = new HashMap<>();
+ cmHandleStates.entrySet().stream().forEach(cmHandleEntry ->
+ cmHandlesJsonDataMap.put(String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleEntry.getKey()),
+ String.format("{\"state\":%s}",
+ jsonObjectMapper.asJsonString(cmHandleEntry.getValue()))));
+ cpsDataService.updateDataNodesAndDescendants(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ cmHandlesJsonDataMap, OffsetDateTime.now());
+ }
+
+ /**
* This method retrieves DMI service name, DMI properties and the state for a given cm handle.
* @param cmHandleId the id of the cm handle
* @return yang model cm handle