aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service/src/main/java/org/onap
diff options
context:
space:
mode:
authorSourabh Sourabh <sourabh.sourabh@est.tech>2025-01-17 09:49:36 +0000
committerGerrit Code Review <gerrit@onap.org>2025-01-17 09:49:36 +0000
commit76a3bddc4494b6856084b02f49e37e7ab7c5d27a (patch)
tree795ff8592b2a7d745dbba1ca0682626a59b96839 /cps-service/src/main/java/org/onap
parentd5c0c3aef85915cbdd1fd67ecd058b53e77467cc (diff)
parent9df4a57a05e3ee67ff96284a4f7b1b07c94600b1 (diff)
Merge "One SchemaSet per moduleSetTag"
Diffstat (limited to 'cps-service/src/main/java/org/onap')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java53
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/impl/CpsAnchorServiceImpl.java7
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java34
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/impl/YangTextSchemaSourceSetCache.java9
-rw-r--r--cps-service/src/main/java/org/onap/cps/init/DbCleaner.java48
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java35
6 files changed, 48 insertions, 138 deletions
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 e71b44c40f..81b6439efc 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-2024 Nordix Foundation
+ * Copyright (C) 2020-2025 Nordix Foundation
* Modifications Copyright (C) 2020-2021 Pantheon.tech
* Modifications Copyright (C) 2022 TechMahindra Ltd.
* ================================================================================
@@ -58,6 +58,15 @@ public interface CpsModuleService {
Collection<ModuleReference> allModuleReferences);
/**
+ * Check if a schema set exist in the given dataspace.
+ *
+ * @param dataspaceName Dataspace name
+ * @param schemaSetName Schema set name
+ * @return boolean, true if a schema set with the given name exist in the given dataspace
+ */
+ boolean schemaSetExists(String dataspaceName, String schemaSetName);
+
+ /**
* Read schema set in the given dataspace.
*
* @param dataspaceName dataspace name
@@ -150,47 +159,13 @@ public interface CpsModuleService {
* The system will ignore the namespace of all module references.
*
* @param moduleReferencesToCheck the moduleReferencesToCheck
- * @returns collection of module references (namespace will be always blank)
- */
- Collection<ModuleReference> identifyNewModuleReferences(
- Collection<ModuleReference> moduleReferencesToCheck);
-
- /**
- * Retrieves module references based on the provided dataspace name, anchor name and attribute filters
- * for both parent and child fragments.
-
- * This method constructs and executes a SQL query to find module references from a database, using
- * the specified `dataspaceName`, `anchorName` and two sets of attribute filters: one for parent fragments
- * and one for child fragments. The method applies these filters to identify the appropriate fragments
- * and schema sets, and then retrieves the corresponding module references.
-
- * The SQL query is dynamically built based on the provided attribute filters:
- * - The `parentAttributes` map is used to filter the parent fragments. The entries in this map are
- * converted into a WHERE clause for the parent fragments.
- * - The `childAttributes` map is used to filter the child fragments. This is applied to the child fragments
- * after filtering the parent fragments.
- *
- * @param dataspaceName the name of the dataspace to filter on. It is used to locate the relevant dataspace
- * in the database.
- * @param anchorName the name of the anchor to filter on. It is used to locate the relevant anchor within
- * the dataspace.
- * @param parentAttributes a map of attributes to filter parent fragments. Each entry in this map represents
- * an attribute key-value pair used in the WHERE clause for parent fragments.
- * @param childAttributes a map of attributes to filter child fragments. Each entry in this map represents
- * an attribute key-value pair used in the WHERE clause for child fragments.
- * @return a collection of {@link ModuleReference} objects that match the given criteria.
- * Each {@code ModuleReference} contains information about a module's name and revision.
- * @implNote The method assumes that both `parentAttributes` and `childAttributes` maps contain at least
- * one entry. The first entry from `parentAttributes` is used to filter parent fragments,
- * and the first entry from `childAttributes` is used to filter child fragments.
+ * @return collection of module references (namespace will be always blank)
*/
- Collection<ModuleReference> getModuleReferencesByAttribute(final String dataspaceName, final String anchorName,
- final Map<String, String> parentAttributes,
- final Map<String, String> childAttributes);
+ Collection<ModuleReference> identifyNewModuleReferences(Collection<ModuleReference> moduleReferencesToCheck);
/**
- * Remove any Yang Resource Modules from the DB that are no longer referenced by any schema set.
+ * Remove any Yang Resource Modules and Schema Sets from the DB that are no longer referenced by any anchor.
*/
- void deleteUnusedYangResourceModules();
+ void deleteAllUnusedYangModuleData();
}
diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsAnchorServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsAnchorServiceImpl.java
index 1bd2b6af56..2a2ddc6c11 100644
--- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsAnchorServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsAnchorServiceImpl.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2023-2024 Nordix Foundation
+ * Copyright (C) 2023-2025 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,7 +39,7 @@ public class CpsAnchorServiceImpl implements CpsAnchorService {
@Override
public void createAnchor(final String dataspaceName, final String schemaSetName, final String anchorName) {
- cpsValidator.validateNameCharacters(dataspaceName, schemaSetName, anchorName);
+ cpsValidator.validateNameCharacters(dataspaceName, anchorName);
cpsAdminPersistenceService.createAnchor(dataspaceName, schemaSetName, anchorName);
}
@@ -64,7 +64,7 @@ public class CpsAnchorServiceImpl implements CpsAnchorService {
@Override
public Collection<Anchor> getAnchorsBySchemaSetName(final String dataspaceName, final String schemaSetName) {
- cpsValidator.validateNameCharacters(dataspaceName, schemaSetName);
+ cpsValidator.validateNameCharacters(dataspaceName);
return cpsAdminPersistenceService.getAnchorsBySchemaSetName(dataspaceName, schemaSetName);
}
@@ -72,7 +72,6 @@ public class CpsAnchorServiceImpl implements CpsAnchorService {
public Collection<Anchor> getAnchorsBySchemaSetNames(final String dataspaceName,
final Collection<String> schemaSetNames) {
cpsValidator.validateNameCharacters(dataspaceName);
- cpsValidator.validateNameCharacters(schemaSetNames);
return cpsAdminPersistenceService.getAnchorsBySchemaSetNames(dataspaceName, schemaSetNames);
}
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 9f5c0a3853..6740262bcc 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
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2020-2024 Nordix Foundation
+ * Copyright (C) 2020-2025 Nordix Foundation
* Modifications Copyright (C) 2020-2021 Pantheon.tech
* Modifications Copyright (C) 2022 Bell Canada
* Modifications Copyright (C) 2022 TechMahindra Ltd
@@ -58,7 +58,7 @@ public class CpsModuleServiceImpl implements CpsModuleService {
description = "Time taken to create (and store) a schemaset")
public void createSchemaSet(final String dataspaceName, final String schemaSetName,
final Map<String, String> yangResourcesNameToContentMap) {
- cpsValidator.validateNameCharacters(dataspaceName, schemaSetName);
+ cpsValidator.validateNameCharacters(dataspaceName);
cpsModulePersistenceService.storeSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap);
final YangTextSchemaSourceSet yangTextSchemaSourceSet =
timedYangTextSchemaSourceSetBuilder.getYangTextSchemaSourceSet(yangResourcesNameToContentMap);
@@ -69,14 +69,20 @@ public class CpsModuleServiceImpl implements CpsModuleService {
public void createSchemaSetFromModules(final String dataspaceName, final String schemaSetName,
final Map<String, String> newModuleNameToContentMap,
final Collection<ModuleReference> allModuleReferences) {
- cpsValidator.validateNameCharacters(dataspaceName, schemaSetName);
+ cpsValidator.validateNameCharacters(dataspaceName);
cpsModulePersistenceService.storeSchemaSetFromModules(dataspaceName, schemaSetName,
newModuleNameToContentMap, allModuleReferences);
}
@Override
+ public boolean schemaSetExists(final String dataspaceName, final String schemaSetName) {
+ cpsValidator.validateNameCharacters(dataspaceName);
+ return cpsModulePersistenceService.schemaSetExists(dataspaceName, schemaSetName);
+ }
+
+ @Override
public SchemaSet getSchemaSet(final String dataspaceName, final String schemaSetName) {
- cpsValidator.validateNameCharacters(dataspaceName, schemaSetName);
+ cpsValidator.validateNameCharacters(dataspaceName);
final var yangTextSchemaSourceSet = yangTextSchemaSourceSetCache
.get(dataspaceName, schemaSetName);
return SchemaSet.builder().name(schemaSetName).dataspaceName(dataspaceName)
@@ -96,7 +102,7 @@ public class CpsModuleServiceImpl implements CpsModuleService {
@Transactional
public void deleteSchemaSet(final String dataspaceName, final String schemaSetName,
final CascadeDeleteAllowed cascadeDeleteAllowed) {
- cpsValidator.validateNameCharacters(dataspaceName, schemaSetName);
+ cpsValidator.validateNameCharacters(dataspaceName);
final Collection<Anchor> anchors = cpsAnchorService.getAnchorsBySchemaSetName(dataspaceName, schemaSetName);
if (!anchors.isEmpty() && isCascadeDeleteProhibited(cascadeDeleteAllowed)) {
throw new SchemaSetInUseException(dataspaceName, schemaSetName);
@@ -112,7 +118,6 @@ public class CpsModuleServiceImpl implements CpsModuleService {
@Transactional
public void deleteSchemaSetsWithCascade(final String dataspaceName, final Collection<String> schemaSetNames) {
cpsValidator.validateNameCharacters(dataspaceName);
- cpsValidator.validateNameCharacters(schemaSetNames);
final Collection<String> anchorNames =
cpsAnchorService.getAnchorsBySchemaSetNames(dataspaceName, schemaSetNames)
.stream().map(Anchor::getName).collect(Collectors.toSet());
@@ -127,7 +132,7 @@ public class CpsModuleServiceImpl implements CpsModuleService {
public void upgradeSchemaSetFromModules(final String dataspaceName, final String schemaSetName,
final Map<String, String> newModuleNameToContentMap,
final Collection<ModuleReference> allModuleReferences) {
- cpsValidator.validateNameCharacters(dataspaceName, schemaSetName);
+ cpsValidator.validateNameCharacters(dataspaceName);
cpsModulePersistenceService.updateSchemaSetFromModules(dataspaceName, schemaSetName,
newModuleNameToContentMap, allModuleReferences);
yangTextSchemaSourceSetCache.removeFromCache(dataspaceName, schemaSetName);
@@ -169,20 +174,9 @@ public class CpsModuleServiceImpl implements CpsModuleService {
return cpsModulePersistenceService.identifyNewModuleReferences(moduleReferencesToCheck);
}
- @Timed(value = "cps.module.service.module.reference.query.by.attribute",
- description = "Time taken to query list of module references by attribute (e.g moduleSetTag)")
- @Override
- public Collection<ModuleReference> getModuleReferencesByAttribute(final String dataspaceName,
- final String anchorName,
- final Map<String, String> parentAttributes,
- final Map<String, String> childAttributes) {
- return cpsModulePersistenceService.getModuleReferencesByAttribute(dataspaceName, anchorName, parentAttributes,
- childAttributes);
- }
-
@Override
- public void deleteUnusedYangResourceModules() {
- cpsModulePersistenceService.deleteUnusedYangResourceModules();
+ public void deleteAllUnusedYangModuleData() {
+ cpsModulePersistenceService.deleteAllUnusedYangModuleData();
}
private boolean isCascadeDeleteProhibited(final CascadeDeleteAllowed cascadeDeleteAllowed) {
diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/YangTextSchemaSourceSetCache.java b/cps-service/src/main/java/org/onap/cps/api/impl/YangTextSchemaSourceSetCache.java
index 8b85dfca32..b893bcea09 100644
--- a/cps-service/src/main/java/org/onap/cps/api/impl/YangTextSchemaSourceSetCache.java
+++ b/cps-service/src/main/java/org/onap/cps/api/impl/YangTextSchemaSourceSetCache.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2021 Pantheon.tech
* Modifications Copyright (C) 2022 Bell Canada
- * Modifications Copyright (C) 2022-2023 Nordix Foundation
+ * Modifications Copyright (C) 2022-2025 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,7 +60,7 @@ public class YangTextSchemaSourceSetCache {
*/
@Cacheable(key = "#p0.concat('-').concat(#p1)")
public YangTextSchemaSourceSet get(final String dataspaceName, final String schemaSetName) {
- cpsValidator.validateNameCharacters(dataspaceName, schemaSetName);
+ cpsValidator.validateNameCharacters(dataspaceName);
final Map<String, String> yangResourceNameToContent =
cpsModulePersistenceService.getYangSchemaResources(dataspaceName, schemaSetName);
return YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent);
@@ -78,7 +78,7 @@ public class YangTextSchemaSourceSetCache {
@CanIgnoreReturnValue
public YangTextSchemaSourceSet updateCache(final String dataspaceName, final String schemaSetName,
final YangTextSchemaSourceSet yangTextSchemaSourceSet) {
- cpsValidator.validateNameCharacters(dataspaceName, schemaSetName);
+ cpsValidator.validateNameCharacters(dataspaceName);
yangSchemaCacheCounter.incrementAndGet();
return yangTextSchemaSourceSet;
}
@@ -91,9 +91,8 @@ public class YangTextSchemaSourceSetCache {
*/
@CacheEvict(key = "#p0.concat('-').concat(#p1)")
public void removeFromCache(final String dataspaceName, final String schemaSetName) {
- cpsValidator.validateNameCharacters(dataspaceName, schemaSetName);
+ cpsValidator.validateNameCharacters(dataspaceName);
yangSchemaCacheCounter.decrementAndGet();
- // Spring provides implementation for removing object from cache
}
}
diff --git a/cps-service/src/main/java/org/onap/cps/init/DbCleaner.java b/cps-service/src/main/java/org/onap/cps/init/DbCleaner.java
deleted file mode 100644
index 6bd3e1f204..0000000000
--- a/cps-service/src/main/java/org/onap/cps/init/DbCleaner.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2024 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.cps.init;
-
-import java.util.concurrent.TimeUnit;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.api.CpsModuleService;
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.stereotype.Service;
-
-@Slf4j
-@RequiredArgsConstructor
-@Service
-public class DbCleaner {
-
- private final CpsModuleService cpsModuleService;
-
- /**
- * This method will clean up the db during application start up.
- * It wil run once and currently only removes unused yang resource modules.
- *
- */
- @Scheduled(initialDelay = 1, timeUnit = TimeUnit.SECONDS)
- public void cleanDbAtStartUp() {
- log.info("CPS Application started, commencing DB clean up");
- cpsModuleService.deleteUnusedYangResourceModules();
- log.info("DB clean up completed");
- }
-}
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 4cfc287a5d..b1f8aad88f 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-2024 Nordix Foundation
+ * Copyright (C) 2020-2025 Nordix Foundation
* Modifications Copyright (C) 2020-2022 Bell Canada.
* Modifications Copyright (C) 2022 TechMahindra Ltd.
* ================================================================================
@@ -65,6 +65,14 @@ public interface CpsModulePersistenceService {
final Map<String, String> newModuleNameToContentMap,
final Collection<ModuleReference> allModuleReferences);
+ /**
+ * Checks whether a schema set exists in the specified dataspace.
+ *
+ * @param dataspaceName dataspace name
+ * @param schemaSetName schema set name
+ * @return {@code true} if the schema set exists in the given dataspace; {@code false} otherwise
+ */
+ boolean schemaSetExists(String dataspaceName, String schemaSetName);
/**
* Get all schema sets for a given dataspace.
@@ -138,35 +146,18 @@ public interface CpsModulePersistenceService {
String moduleName, String moduleRevision);
/**
- * Remove unused Yang Resource Modules.
+ * Remove any unused Yang Resource Modules and Schema Sets.
*/
- void deleteUnusedYangResourceModules();
+ void deleteAllUnusedYangModuleData();
/**
* Identify new module references from those returned by a node compared to what is in CPS already.
* The system will ignore the namespace of all module references.
*
* @param moduleReferencesToCheck the module references ot check
- * @returns Collection of {@link ModuleReference} (namespace will be always blank)
- *
- */
- Collection<ModuleReference> identifyNewModuleReferences(
- Collection<ModuleReference> moduleReferencesToCheck);
-
- /**
- * Retrieves module references based on the specified dataspace, anchor, and attribute filters.
-
- * Constructs and executes a SQL query to find module references by applying filters for parent and child fragments.
- * Uses `parentAttributes` for filtering parent fragments and `childAttributes` for filtering child fragments.
+ * @return Collection of {@link ModuleReference} (namespace will be always blank)
*
- * @param dataspaceName the name of the dataspace to filter on.
- * @param anchorName the name of the anchor to filter on.
- * @param parentAttributes a map of attributes for filtering parent fragments.
- * @param childAttributes a map of attributes for filtering child fragments.
- * @return a collection of {@link ModuleReference} objects matching the criteria.
*/
- Collection<ModuleReference> getModuleReferencesByAttribute(final String dataspaceName, final String anchorName,
- final Map<String, String> parentAttributes,
- final Map<String, String> childAttributes);
+ Collection<ModuleReference> identifyNewModuleReferences(Collection<ModuleReference> moduleReferencesToCheck);
}