From 926d40875fecb3c11e4103dfdaf00ac615de3cdc Mon Sep 17 00:00:00 2001 From: danielhanrahan Date: Fri, 4 Aug 2023 11:22:43 +0100 Subject: Remove inefficient saveListElementsBatch API CpsDataService::saveListElementsBatch method is not needed as saveListElements supports saving multiple list elements in a single operation. This both simplifies implementation and greatly improves performance when saving list elements, as the Yang parser need only run once for the whole batch. - Change InventoryPersistence to save CM-handles in batches of 100 using existing CpsDataService::saveListElements method. - Remove not needed CpsDataService::saveListElementBatch. Issue-ID: CPS-2019 Signed-off-by: danielhanrahan Change-Id: I8b74dda2917e094d064b42f2c0e4d57029b90395 --- .../main/java/org/onap/cps/api/CpsDataService.java | 15 +---------- .../org/onap/cps/api/impl/CpsDataServiceImpl.java | 29 +++------------------- .../onap/cps/spi/CpsDataPersistenceService.java | 13 +--------- 3 files changed, 6 insertions(+), 51 deletions(-) mode change 100755 => 100644 cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java (limited to 'cps-service/src/main/java/org') diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java index c9879595a8..0abcc05f9c 100644 --- a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java +++ b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020-2023 Nordix Foundation + * Copyright (C) 2020-2024 Nordix Foundation * Modifications Copyright (C) 2021 Pantheon.tech * Modifications Copyright (C) 2021-2022 Bell Canada * Modifications Copyright (C) 2022 Deutsche Telekom AG @@ -99,19 +99,6 @@ public interface CpsDataService { void saveListElements(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData, OffsetDateTime observedTimestamp); - /** - * Persists child data fragment representing one or more list elements under existing data node for the - * given anchor and dataspace. - * - * @param dataspaceName dataspace name - * @param anchorName anchor name - * @param parentNodeXpath parent node xpath - * @param jsonDataList collection of json data representing list element(s) - * @param observedTimestamp observedTimestamp - */ - void saveListElementsBatch(String dataspaceName, String anchorName, String parentNodeXpath, - Collection jsonDataList, OffsetDateTime observedTimestamp); - /** * Retrieves all the datanodes by XPath for given dataspace and anchor. * diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java old mode 100755 new mode 100644 index a1bae6a441..e49714b66d --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation + * Copyright (C) 2021-2024 Nordix Foundation * Modifications Copyright (C) 2020-2022 Bell Canada. * Modifications Copyright (C) 2021 Pantheon.tech * Modifications Copyright (C) 2022-2023 TechMahindra Ltd. @@ -105,9 +105,9 @@ public class CpsDataServiceImpl implements CpsDataService { @Override @Timed(value = "cps.data.service.list.element.save", - description = "Time taken to save a list element") - public void saveListElements(final String dataspaceName, final String anchorName, - final String parentNodeXpath, final String jsonData, final OffsetDateTime observedTimestamp) { + description = "Time taken to save list elements") + public void saveListElements(final String dataspaceName, final String anchorName, final String parentNodeXpath, + final String jsonData, final OffsetDateTime observedTimestamp) { cpsValidator.validateNameCharacters(dataspaceName, anchorName); final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName); final Collection listElementDataNodeCollection = @@ -120,19 +120,6 @@ public class CpsDataServiceImpl implements CpsDataService { } } - @Override - @Timed(value = "cps.data.service.list.element.batch.save", - description = "Time taken to save a batch of list elements") - public void saveListElementsBatch(final String dataspaceName, final String anchorName, final String parentNodeXpath, - final Collection jsonDataList, final OffsetDateTime observedTimestamp) { - cpsValidator.validateNameCharacters(dataspaceName, anchorName); - final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName); - final Collection> listElementDataNodeCollections = - buildDataNodes(anchor, parentNodeXpath, jsonDataList, ContentType.JSON); - cpsDataPersistenceService.addMultipleLists(dataspaceName, anchorName, parentNodeXpath, - listElementDataNodeCollections); - } - @Override @Timed(value = "cps.data.service.datanode.get", description = "Time taken to get data nodes for an xpath") @@ -347,14 +334,6 @@ public class CpsDataServiceImpl implements CpsDataService { return dataNodes; } - private Collection> buildDataNodes(final Anchor anchor, final String parentNodeXpath, - final Collection nodeDataList, - final ContentType contentType) { - return nodeDataList.stream() - .map(nodeData -> buildDataNodes(anchor, parentNodeXpath, nodeData, contentType)) - .collect(Collectors.toList()); - } - private SchemaContext getSchemaContext(final Anchor anchor) { return yangTextSchemaSourceSetCache .get(anchor.getDataspaceName(), anchor.getSchemaSetName()).getSchemaContext(); diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java index 1baca4ea7d..bc819163bc 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java +++ b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020-2023 Nordix Foundation. + * Copyright (C) 2020-2024 Nordix Foundation. * Modifications Copyright (C) 2021 Pantheon.tech * Modifications Copyright (C) 2022 Bell Canada * Modifications Copyright (C) 2022-2023 TechMahindra Ltd. @@ -66,17 +66,6 @@ public interface CpsDataPersistenceService { void addListElements(String dataspaceName, String anchorName, String parentNodeXpath, Collection listElementsCollection); - /** - * Add multiple lists of data nodes to a parent node at the same time. - * - * @param dataspaceName dataspace name - * @param anchorName anchor name - * @param parentNodeXpath parent node xpath - * @param newLists collections of lists of data nodes representing list elements - */ - void addMultipleLists(String dataspaceName, String anchorName, String parentNodeXpath, - Collection> newLists); - /** * Retrieves multiple datanodes for a single XPath for given dataspace and anchor. * Multiple data nodes are returned when xPath is set to root '/', otherwise single data node -- cgit 1.2.3-korg