diff options
author | Lee Anjella Macabuhay <lee.anjella.macabuhay@est.tech> | 2024-01-10 15:05:30 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2024-01-10 15:05:30 +0000 |
commit | 958248ec5b935c6608a0f74c8aaf9627a16e2534 (patch) | |
tree | 380ab22aa69f0297cc7279c900ab29d42b6154f3 /cps-ncmp-service/src/main/java | |
parent | 34ac8e767246788afb5eeefa221acb5e587f568d (diff) | |
parent | 926d40875fecb3c11e4103dfdaf00ac615de3cdc (diff) |
Merge "Remove inefficient saveListElementsBatch API"
Diffstat (limited to 'cps-ncmp-service/src/main/java')
2 files changed, 18 insertions, 15 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) + "}"; } } |