From 230b1119dec71e301ba462246c3fc53d0fc0281a Mon Sep 17 00:00:00 2001 From: danielhanrahan Date: Tue, 24 Jan 2023 11:23:02 +0000 Subject: Create plural version of deleteDataNode - Add method to CpsDataService to batch delete data nodes and lists - Use native queries to batch delete fragment entities by xpaths, for data nodes and lists - Add performance tests for batch delete - Refactor FragmentNativeRepository - Add single-column version of createTemporaryTable - Renamed metric cps.data.service.datanode.batch.delete to cps.data.service.datanode.all.delete Issue-ID: CPS-1438 Signed-off-by: danielhanrahan Change-Id: I1851f9c7ef0b1be4bd421b3352d9697a2dd23f79 --- .../main/java/org/onap/cps/api/CpsDataService.java | 21 ++++++++++++++++----- .../org/onap/cps/api/impl/CpsDataServiceImpl.java | 13 ++++++++++++- .../org/onap/cps/spi/CpsDataPersistenceService.java | 13 +++++++++++-- .../onap/cps/api/impl/CpsDataServiceImplSpec.groovy | 13 +++++++++++++ 4 files changed, 52 insertions(+), 8 deletions(-) (limited to 'cps-service/src') 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 6332f09109..174d71f64d 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-2022 Nordix Foundation + * Copyright (C) 2020-2023 Nordix Foundation * Modifications Copyright (C) 2021 Pantheon.tech * Modifications Copyright (C) 2021-2022 Bell Canada * Modifications Copyright (C) 2022 Deutsche Telekom AG @@ -199,19 +199,30 @@ public interface CpsDataService { /** * Deletes data node for given anchor and dataspace. * - * @param dataspaceName dataspace name - * @param anchorName anchor name - * @param dataNodeXpath data node xpath + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @param dataNodeXpath data node xpath * @param observedTimestamp observed timestamp */ void deleteDataNode(String dataspaceName, String anchorName, String dataNodeXpath, OffsetDateTime observedTimestamp); + /** + * Deletes multiple data nodes for given anchor and dataspace. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @param dataNodeXpaths data node xpaths + * @param observedTimestamp observed timestamp + */ + void deleteDataNodes(String dataspaceName, String anchorName, Collection dataNodeXpaths, + OffsetDateTime observedTimestamp); + /** * Deletes all data nodes for a given anchor in a dataspace. * * @param dataspaceName dataspace name - * @param anchorName anchor name + * @param anchorName anchor name * @param observedTimestamp observed timestamp */ void deleteDataNodes(String dataspaceName, String anchorName, OffsetDateTime observedTimestamp); 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 index 53fab2916f..06a0845385 100755 --- 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 @@ -264,7 +264,18 @@ public class CpsDataServiceImpl implements CpsDataService { @Timed(value = "cps.data.service.datanode.batch.delete", description = "Time taken to delete a batch of datanodes") public void deleteDataNodes(final String dataspaceName, final String anchorName, - final OffsetDateTime observedTimestamp) { + final Collection dataNodeXpaths, final OffsetDateTime observedTimestamp) { + cpsValidator.validateNameCharacters(dataspaceName, anchorName); + cpsDataPersistenceService.deleteDataNodes(dataspaceName, anchorName, dataNodeXpaths); + dataNodeXpaths.forEach(dataNodeXpath -> + processDataUpdatedEventAsync(dataspaceName, anchorName, dataNodeXpath, DELETE, observedTimestamp)); + } + + @Override + @Timed(value = "cps.data.service.datanode.all.delete", + description = "Time taken to delete all datanodes") + public void deleteDataNodes(final String dataspaceName, final String anchorName, + final OffsetDateTime observedTimestamp) { cpsValidator.validateNameCharacters(dataspaceName, anchorName); processDataUpdatedEventAsync(dataspaceName, anchorName, ROOT_NODE_XPATH, DELETE, observedTimestamp); cpsDataPersistenceService.deleteDataNodes(dataspaceName, anchorName); 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 0989ccae2d..3e0b4475e8 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-2022 Nordix Foundation. + * Copyright (C) 2020-2023 Nordix Foundation. * Modifications Copyright (C) 2021 Pantheon.tech * Modifications Copyright (C) 2022 Bell Canada * Modifications Copyright (C) 2022 TechMahindra Ltd. @@ -173,6 +173,15 @@ public interface CpsDataPersistenceService { */ void deleteDataNode(String dataspaceName, String anchorName, String targetXpath); + /** + * Deletes multiple dataNode, yang container or yang list or yang list element. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @param targetXpaths xpaths of nodes to delete + */ + void deleteDataNodes(String dataspaceName, String anchorName, Collection targetXpaths); + /** * Deletes all dataNodes in a given anchor. * @@ -182,7 +191,7 @@ public interface CpsDataPersistenceService { void deleteDataNodes(String dataspaceName, String anchorName); /** - * Deletes existing a single list element or the whole list. + * Deletes a single existing list element or the whole list. * * @param dataspaceName dataspace name * @param anchorName anchor name diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy index 01dc0bde42..8bbf4e5715 100644 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy @@ -325,6 +325,19 @@ class CpsDataServiceImplSpec extends Specification { 1 * mockNotificationService.processDataUpdatedEvent(dataspaceName, anchorName, '/test-tree/branch', Operation.DELETE, observedTimestamp) } + def 'Delete multiple list elements under existing node.'() { + given: 'schema set for given anchor and dataspace references test-tree model' + setupSchemaSetMocks('test-tree.yang') + when: 'delete multiple list data method is invoked with list element json data' + objectUnderTest.deleteDataNodes(dataspaceName, anchorName, ['/test-tree/branch[@name="A"]', '/test-tree/branch[@name="B"]'], observedTimestamp) + then: 'the persistence service method is invoked with correct parameters' + 1 * mockCpsDataPersistenceService.deleteDataNodes(dataspaceName, anchorName, ['/test-tree/branch[@name="A"]', '/test-tree/branch[@name="B"]']) + and: 'the CpsValidator is called on the dataspaceName and AnchorName' + 1 * mockCpsValidator.validateNameCharacters(dataspaceName, anchorName) + and: 'two data updated events are sent to notification service' + 2 * mockNotificationService.processDataUpdatedEvent(dataspaceName, anchorName, _, Operation.DELETE, observedTimestamp) + } + def 'Delete data node under anchor and dataspace.'() { given: 'schema set for given anchor and dataspace references test tree model' setupSchemaSetMocks('test-tree.yang') -- cgit 1.2.3-korg