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 --- .../main/java/org/onap/cps/api/CpsModuleService.java | 14 +++++++++++--- .../org/onap/cps/api/impl/CpsModuleServiceImpl.java | 20 +++++++++++++++++++- .../onap/cps/spi/CpsModulePersistenceService.java | 10 +++++++++- .../java/org/onap/cps/spi/utils/CpsValidator.java | 9 ++++++++- 4 files changed, 47 insertions(+), 6 deletions(-) (limited to 'cps-service/src/main/java') 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 b1f90d686b..5ff08c9ac8 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 ccd0fcc289..e71e6ce662 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 f5dc8ac3a3..40d4002b97 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 c7ce8fc926..231094cf16 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); } -- cgit 1.2.3-korg