From e28b62148676d189bdd11b78d8d78419d548e358 Mon Sep 17 00:00:00 2001 From: danielhanrahan Date: Tue, 14 Feb 2023 13:24:40 +0000 Subject: Bulk delete schemasets in CM handle deregistration - Batch delete schema sets in single query - Call deleteUnusedYangResourceModules once per batch, not per CM handle - Results for deregistering 10k: 14 mins before; 6 mins after Issue-ID: CPS-1423 Signed-off-by: danielhanrahan Change-Id: Ia3a86a0dc88677323e2f386253a99022a7f02603 --- .../java/org/onap/cps/api/CpsModuleService.java | 14 +++++++++++--- .../onap/cps/api/impl/CpsModuleServiceImpl.java | 20 +++++++++++++++++++- .../onap/cps/spi/CpsModulePersistenceService.java | 10 +++++++++- .../java/org/onap/cps/spi/utils/CpsValidator.java | 9 ++++++++- .../cps/api/impl/CpsModuleServiceImplSpec.groovy | 22 ++++++++++++++++++++++ 5 files changed, 69 insertions(+), 6 deletions(-) (limited to 'cps-service') diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java b/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java index b1f90d686..5ff08c9ac 100644 --- a/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java +++ b/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020-2022 Nordix Foundation + * Copyright (C) 2020-2023 Nordix Foundation * Modifications Copyright (C) 2020-2021 Pantheon.tech * Modifications Copyright (C) 2022 TechMahindra Ltd. * ================================================================================ @@ -80,12 +80,20 @@ public interface CpsModuleService { * @param dataspaceName dataspace name * @param schemaSetName schema set name * @param cascadeDeleteAllowed indicates the allowance to remove associated anchors and data if exist - * @throws DataInUseException if cascadeDeleteAllowed is set to CASCADE_DELETE_PROHIBITED and there - * is associated anchor record exists in database + * @throws DataInUseException if cascadeDeleteAllowed is set to CASCADE_DELETE_PROHIBITED and there + * is associated anchor record exists in database */ void deleteSchemaSet(String dataspaceName, String schemaSetName, CascadeDeleteAllowed cascadeDeleteAllowed); + /** + * Deletes Schema Sets with cascade. + * + * @param dataspaceName dataspace name + * @param schemaSetNames schema set names + */ + void deleteSchemaSetsWithCascade(String dataspaceName, Collection schemaSetNames); + /** * Retrieve module references for the given dataspace name. * diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java index ccd0fcc28..e71e6ce66 100644 --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java @@ -95,7 +95,7 @@ public class CpsModuleServiceImpl implements CpsModuleService { @Override @Transactional public void deleteSchemaSet(final String dataspaceName, final String schemaSetName, - final CascadeDeleteAllowed cascadeDeleteAllowed) { + final CascadeDeleteAllowed cascadeDeleteAllowed) { cpsValidator.validateNameCharacters(dataspaceName, schemaSetName); final Collection anchors = cpsAdminService.getAnchors(dataspaceName, schemaSetName); if (!anchors.isEmpty() && isCascadeDeleteProhibited(cascadeDeleteAllowed)) { @@ -109,6 +109,24 @@ public class CpsModuleServiceImpl implements CpsModuleService { cpsModulePersistenceService.deleteUnusedYangResourceModules(); } + @Override + @Transactional + public void deleteSchemaSetsWithCascade(final String dataspaceName, final Collection schemaSetNames) { + cpsValidator.validateNameCharacters(dataspaceName); + cpsValidator.validateNameCharacters(schemaSetNames); + for (final String schemaSetName : schemaSetNames) { + final Collection anchors = cpsAdminService.getAnchors(dataspaceName, schemaSetName); + for (final Anchor anchor : anchors) { + cpsAdminService.deleteAnchor(dataspaceName, anchor.getName()); + } + } + cpsModulePersistenceService.deleteUnusedYangResourceModules(); + cpsModulePersistenceService.deleteSchemaSets(dataspaceName, schemaSetNames); + for (final String schemaSetName : schemaSetNames) { + yangTextSchemaSourceSetCache.removeFromCache(dataspaceName, schemaSetName); + } + } + @Override public Collection getYangResourceModuleReferences(final String dataspaceName) { cpsValidator.validateNameCharacters(dataspaceName); diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java index f5dc8ac3a..40d4002b9 100755 --- a/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java +++ b/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020-2022 Nordix Foundation + * Copyright (C) 2020-2023 Nordix Foundation * Modifications Copyright (C) 2020-2022 Bell Canada. * Modifications Copyright (C) 2022 TechMahindra Ltd. * ================================================================================ @@ -69,6 +69,14 @@ public interface CpsModulePersistenceService { */ void deleteSchemaSet(String dataspaceName, String schemaSetName); + /** + * Deletes Schema Sets. + * + * @param dataspaceName dataspace name + * @param schemaSetNames schema set names + */ + void deleteSchemaSets(String dataspaceName, Collection schemaSetNames); + /** * Returns YANG resources per specific dataspace / schemaSetName. * diff --git a/cps-service/src/main/java/org/onap/cps/spi/utils/CpsValidator.java b/cps-service/src/main/java/org/onap/cps/spi/utils/CpsValidator.java index c7ce8fc92..231094cf1 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/utils/CpsValidator.java +++ b/cps-service/src/main/java/org/onap/cps/spi/utils/CpsValidator.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation + * Copyright (C) 2022-2023 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,4 +28,11 @@ public interface CpsValidator { * @param names names of data to be validated */ void validateNameCharacters(final String... names); + + /** + * Validate characters in names within cps. + * + * @param names names of data to be validated + */ + void validateNameCharacters(final Iterable names); } diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy index 2bb0e63ab..615d3af35 100644 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy @@ -167,6 +167,28 @@ class CpsModuleServiceImplSpec extends Specification { return anchors } + def 'Delete multiple schema-sets when cascade is allowed.'() { + given: '#numberOfAnchors anchors are associated with each schemaset' + mockCpsAdminService.getAnchors('my-dataspace', 'my-schemaset1') >> createAnchors(numberOfAnchors) + mockCpsAdminService.getAnchors('my-dataspace', 'my-schemaset2') >> createAnchors(numberOfAnchors) + when: 'schema set deletion is requested with cascade allowed' + objectUnderTest.deleteSchemaSetsWithCascade('my-dataspace', ['my-schemaset1', 'my-schemaset2']) + then: 'anchor deletion is called 2 * #numberOfAnchors times' + (2 * numberOfAnchors) * mockCpsAdminService.deleteAnchor('my-dataspace', _) + and: 'persistence service method is invoked with same parameters' + mockCpsModulePersistenceService.deleteSchemaSets('my-dataspace', _) + and: 'schema sets will be removed from the cache' + 2 * mockYangTextSchemaSourceSetCache.removeFromCache('my-dataspace', _) + and: 'orphan yang resources are deleted' + 1 * mockCpsModulePersistenceService.deleteUnusedYangResourceModules() + and: 'the CpsValidator is called on the dataspaceName' + 1 * mockCpsValidator.validateNameCharacters('my-dataspace') + and: 'the CpsValidator is called on the schemaSetNames' + 1 * mockCpsValidator.validateNameCharacters(_) + where: 'following parameters are used' + numberOfAnchors << [0, 3] + } + def 'Get all yang resources module references.'() { given: 'an already present module reference' def moduleReferences = [new ModuleReference('some module name','some revision name')] -- cgit 1.2.3-korg