summaryrefslogtreecommitdiffstats
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/api/impl/inventory/InventoryPersistence.java5
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImpl.java28
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImplSpec.groovy10
3 files changed, 23 insertions, 20 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistence.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistence.java
index 09de9a7bf3..9024eac331 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistence.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistence.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 Nordix Foundation
+ * Copyright (C) 2022-2024 Nordix Foundation
* Modifications Copyright (C) 2023 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +22,7 @@
package org.onap.cps.ncmp.api.impl.inventory;
import java.util.Collection;
+import java.util.List;
import java.util.Map;
import org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence;
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
@@ -98,7 +99,7 @@ public interface InventoryPersistence extends NcmpPersistence {
*
* @param yangModelCmHandles cm handle represented as Yang Models
*/
- void saveCmHandleBatch(Collection<YangModelCmHandle> yangModelCmHandles);
+ void saveCmHandleBatch(List<YangModelCmHandle> yangModelCmHandles);
/**
* Get data node of given cm handle.
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImpl.java
index a0aeac3e89..33d6e9a9cc 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImpl.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 Nordix Foundation
+ * Copyright (C) 2022-2024 Nordix Foundation
* Modifications Copyright (C) 2022 Bell Canada
* Modifications Copyright (C) 2023 TechMahindra Ltd.
* ================================================================================
@@ -22,9 +22,11 @@
package org.onap.cps.ncmp.api.impl.inventory;
+import com.google.common.collect.Lists;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -47,6 +49,8 @@ import org.springframework.stereotype.Component;
@Component
public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements InventoryPersistence {
+ private static final int CMHANDLE_BATCH_SIZE = 100;
+
private final CpsModuleService cpsModuleService;
private final CpsAnchorService cpsAnchorService;
private final CpsValidator cpsValidator;
@@ -131,19 +135,17 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv
@Override
public void saveCmHandle(final YangModelCmHandle yangModelCmHandle) {
- final String cmHandleJsonData =
- createCmHandleJsonData(jsonObjectMapper.asJsonString(yangModelCmHandle));
- cpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NCMP_DMI_REGISTRY_PARENT,
- cmHandleJsonData, NO_TIMESTAMP);
+ saveCmHandleBatch(Collections.singletonList(yangModelCmHandle));
}
@Override
- public void saveCmHandleBatch(final Collection<YangModelCmHandle> yangModelCmHandles) {
- final List<String> cmHandlesJsonData = new ArrayList<>();
- yangModelCmHandles.forEach(yangModelCmHandle -> cmHandlesJsonData.add(
- createCmHandleJsonData(jsonObjectMapper.asJsonString(yangModelCmHandle))));
- cpsDataService.saveListElementsBatch(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- NCMP_DMI_REGISTRY_PARENT, cmHandlesJsonData, NO_TIMESTAMP);
+ public void saveCmHandleBatch(final List<YangModelCmHandle> yangModelCmHandles) {
+ for (final List<YangModelCmHandle> yangModelCmHandleBatch :
+ Lists.partition(yangModelCmHandles, CMHANDLE_BATCH_SIZE)) {
+ final String cmHandlesJsonData = createCmHandlesJsonData(yangModelCmHandleBatch);
+ cpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ NCMP_DMI_REGISTRY_PARENT, cmHandlesJsonData, NO_TIMESTAMP);
+ }
}
@Override
@@ -171,7 +173,7 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv
return "{\"state\":" + state + "}";
}
- private static String createCmHandleJsonData(final String yangModelCmHandleAsJson) {
- return "{\"cm-handles\":[" + yangModelCmHandleAsJson + "]}";
+ private String createCmHandlesJsonData(final List<YangModelCmHandle> yangModelCmHandles) {
+ return "{\"cm-handles\":" + jsonObjectMapper.asJsonString(yangModelCmHandles) + "}";
}
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImplSpec.groovy
index 297f18c989..cb2f3fdddd 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImplSpec.groovy
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 Nordix Foundation
+ * Copyright (C) 2022-2024 Nordix Foundation
* Modifications Copyright (C) 2022 Bell Canada
* Modifications Copyright (C) 2023 TechMahindra Ltd.
* ================================================================================
@@ -227,12 +227,12 @@ class InventoryPersistenceImplSpec extends Specification {
when: 'the cm handles are saved'
objectUnderTest.saveCmHandleBatch([yangModelCmHandle1, yangModelCmHandle2])
then: 'CPS Data Service persists both cm handles as a batch'
- 1 * mockCpsDataService.saveListElementsBatch(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ 1 * mockCpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
NCMP_DMI_REGISTRY_PARENT, _,null) >> {
args -> {
- def jsonDataList = (args[3] as List)
- (jsonDataList[0] as String).contains('cmhandle1')
- (jsonDataList[0] as String).contains('cmhandle2')
+ def jsonData = (args[3] as String)
+ jsonData.contains('cmhandle1')
+ jsonData.contains('cmhandle2')
}
}
}