From 50518ca2035ec6d50e7aeadcc0f44b6d0c35fbb2 Mon Sep 17 00:00:00 2001 From: sourabh_sourabh Date: Mon, 12 Aug 2024 10:38:39 +0100 Subject: CPS-NCMP: Slow cmHandle registration when we use moduleSetTag, alternateId and dataProducerIdentifier - Created a new repo. service for fragment table that executes a native sql query to find first ready cm handle id based on moduleset tag and then returns list of module references. - Exposed a new interface into module service that is used by module sync service to get list of midule refs by module set tag. Issue-ID: CPS-2353 Change-Id: I438dbd1ed37c1ff4e15f792e93a095aa604120bc Signed-off-by: sourabh_sourabh --- .../java/org/onap/cps/api/CpsModuleService.java | 33 ++++++++++++++++++++++ .../onap/cps/api/impl/CpsModuleServiceImpl.java | 11 ++++++++ .../onap/cps/spi/CpsModulePersistenceService.java | 16 +++++++++++ 3 files changed, 60 insertions(+) (limited to 'cps-service/src/main') 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 bdd361458e..931209c998 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 @@ -155,4 +155,37 @@ public interface CpsModuleService { Collection identifyNewModuleReferences( Collection 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. + */ + Collection getModuleReferencesByAttribute(final String dataspaceName, final String anchorName, + final Map parentAttributes, + final Map childAttributes); + } 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 e6ad9a8bb8..34610f3455 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 @@ -171,6 +171,17 @@ public class CpsModuleServiceImpl implements CpsModuleService { return cpsModulePersistenceService.identifyNewModuleReferences(moduleReferencesToCheck); } + @Timed(value = "cps.module.service.module.reference.query", + description = "Time taken to query list of module references") + @Override + public Collection getModuleReferencesByAttribute(final String dataspaceName, + final String anchorName, + final Map parentAttributes, + final Map childAttributes) { + return cpsModulePersistenceService.getModuleReferencesByAttribute(dataspaceName, anchorName, parentAttributes, + childAttributes); + } + private boolean isCascadeDeleteProhibited(final CascadeDeleteAllowed cascadeDeleteAllowed) { return CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED == cascadeDeleteAllowed; } 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 eeaaa47991..793f38e4bc 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 @@ -153,4 +153,20 @@ public interface CpsModulePersistenceService { Collection identifyNewModuleReferences( Collection 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. + * + * @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 getModuleReferencesByAttribute(final String dataspaceName, final String anchorName, + final Map parentAttributes, + final Map childAttributes); + } -- cgit 1.2.3-korg