aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ri/src
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ri/src')
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/ri/CpsAdminPersistenceServiceImpl.java18
-rw-r--r--cps-ri/src/main/java/org/onap/cps/ri/CpsDataPersistenceServiceImpl.java38
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/ri/CpsModulePersistenceServiceImpl.java188
-rw-r--r--cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentQueryBuilder.java19
-rw-r--r--cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentRepositoryCpsPathQuery.java4
-rw-r--r--cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentRepositoryCpsPathQueryImpl.java9
-rw-r--r--cps-ri/src/main/java/org/onap/cps/ri/repository/SchemaSetRepository.java6
-rw-r--r--cps-ri/src/main/java/org/onap/cps/ri/repository/SchemaSetYangResourceRepository.java36
-rw-r--r--cps-ri/src/main/java/org/onap/cps/ri/repository/SchemaSetYangResourceRepositoryImpl.java58
-rw-r--r--cps-ri/src/main/java/org/onap/cps/ri/repository/YangResourceNativeRepository.java31
-rw-r--r--cps-ri/src/main/java/org/onap/cps/ri/repository/YangResourceNativeRepositoryImpl.java69
-rw-r--r--cps-ri/src/main/java/org/onap/cps/ri/repository/YangResourceRepository.java10
-rw-r--r--cps-ri/src/main/java/org/onap/cps/ri/utils/CpsValidatorImpl.java2
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/ri/CpsDataPersistenceServiceImplSpec.groovy2
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/ri/CpsModulePersistenceServiceConcurrencySpec.groovy145
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/ri/CpsModulePersistenceServiceImplSpec.groovy6
16 files changed, 171 insertions, 470 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/ri/CpsAdminPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/ri/CpsAdminPersistenceServiceImpl.java
index 494d6919da..588a639ab8 100755
--- a/cps-ri/src/main/java/org/onap/cps/ri/CpsAdminPersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/ri/CpsAdminPersistenceServiceImpl.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) 2021 Pantheon.tech
* Modifications Copyright (C) 2022 TechMahindra Ltd.
@@ -91,10 +91,10 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
@Override
public void createAnchor(final String dataspaceName, final String schemaSetName, final String anchorName) {
- final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
- final var schemaSetEntity =
- schemaSetRepository.getByDataspaceAndName(dataspaceEntity, schemaSetName);
- final var anchorEntity = AnchorEntity.builder()
+ final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ final SchemaSetEntity schemaSetEntity = schemaSetRepository
+ .getByDataspaceAndName(dataspaceEntity, schemaSetName);
+ final AnchorEntity anchorEntity = AnchorEntity.builder()
.name(anchorName)
.dataspace(dataspaceEntity)
.schemaSet(schemaSetEntity)
@@ -114,7 +114,7 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
@Override
public Collection<Anchor> getAnchors(final String dataspaceName) {
- final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
final Collection<AnchorEntity> anchorEntities = anchorRepository.findAllByDataspace(dataspaceEntity);
return anchorEntities.stream().map(CpsAdminPersistenceServiceImpl::toAnchor).collect(Collectors.toSet());
}
@@ -154,14 +154,14 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
@Transactional
@Override
public void deleteAnchor(final String dataspaceName, final String anchorName) {
- final var anchorEntity = getAnchorEntity(dataspaceName, anchorName);
+ final AnchorEntity anchorEntity = getAnchorEntity(dataspaceName, anchorName);
anchorRepository.delete(anchorEntity);
}
@Transactional
@Override
public void deleteAnchors(final String dataspaceName, final Collection<String> anchorNames) {
- final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
anchorRepository.deleteAllByDataspaceAndNameIn(dataspaceEntity, anchorNames);
}
@@ -178,7 +178,7 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
}
private AnchorEntity getAnchorEntity(final String dataspaceName, final String anchorName) {
- final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
return anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);
}
diff --git a/cps-ri/src/main/java/org/onap/cps/ri/CpsDataPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/ri/CpsDataPersistenceServiceImpl.java
index c43c8e2999..e102765a64 100644
--- a/cps-ri/src/main/java/org/onap/cps/ri/CpsDataPersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/ri/CpsDataPersistenceServiceImpl.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2024 Nordix Foundation
+ * Copyright (C) 2021-2025 Nordix Foundation
* Modifications Copyright (C) 2021 Pantheon.tech
* Modifications Copyright (C) 2020-2022 Bell Canada.
* Modifications Copyright (C) 2022-2023 TechMahindra Ltd.
@@ -23,6 +23,7 @@
package org.onap.cps.ri;
+import static org.onap.cps.api.CpsQueryService.NO_LIMIT;
import static org.onap.cps.api.parameters.PaginationOption.NO_PAGINATION;
import com.google.common.collect.ImmutableSet;
@@ -37,6 +38,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;
@@ -50,12 +52,12 @@ import org.onap.cps.api.exceptions.CpsPathException;
import org.onap.cps.api.exceptions.DataNodeNotFoundException;
import org.onap.cps.api.exceptions.DataNodeNotFoundExceptionBatch;
import org.onap.cps.api.model.DataNode;
-import org.onap.cps.api.model.DataNodeBuilder;
import org.onap.cps.api.parameters.FetchDescendantsOption;
import org.onap.cps.api.parameters.PaginationOption;
import org.onap.cps.cpspath.parser.CpsPathQuery;
import org.onap.cps.cpspath.parser.CpsPathUtil;
import org.onap.cps.cpspath.parser.PathParsingException;
+import org.onap.cps.impl.DataNodeBuilder;
import org.onap.cps.ri.models.AnchorEntity;
import org.onap.cps.ri.models.DataspaceEntity;
import org.onap.cps.ri.models.FragmentEntity;
@@ -222,14 +224,44 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
description = "Time taken to query data nodes")
public List<DataNode> queryDataNodes(final String dataspaceName, final String anchorName, final String cpsPath,
final FetchDescendantsOption fetchDescendantsOption) {
+ return queryDataNodes(dataspaceName, anchorName, cpsPath, fetchDescendantsOption, NO_LIMIT);
+ }
+
+ @Override
+ public List<DataNode> queryDataNodes(final String dataspaceName,
+ final String anchorName,
+ final String cpsPath,
+ final FetchDescendantsOption fetchDescendantsOption,
+ final int queryResultLimit) {
final AnchorEntity anchorEntity = getAnchorEntity(dataspaceName, anchorName);
final CpsPathQuery cpsPathQuery = getCpsPathQuery(cpsPath);
final Collection<FragmentEntity> fragmentEntities =
- fragmentRepository.findByAnchorAndCpsPath(anchorEntity, cpsPathQuery);
+ fragmentRepository.findByAnchorAndCpsPath(anchorEntity, cpsPathQuery, queryResultLimit);
return createDataNodesFromFragmentEntities(fetchDescendantsOption, fragmentEntities);
}
@Override
+ public <T> Set<T> queryDataLeaf(final String dataspaceName, final String anchorName, final String cpsPath,
+ final Class<T> targetClass) {
+ final CpsPathQuery cpsPathQuery = getCpsPathQuery(cpsPath);
+ if (!cpsPathQuery.hasAttributeAxis()) {
+ throw new IllegalArgumentException(
+ "Only Cps Path Queries with attribute-axis are supported by queryDataLeaf");
+ }
+
+ final String attributeName = cpsPathQuery.getAttributeAxisAttributeName();
+ final List<DataNode> dataNodes = queryDataNodes(dataspaceName, anchorName, cpsPath,
+ FetchDescendantsOption.OMIT_DESCENDANTS);
+ return dataNodes.stream()
+ .map(dataNode -> {
+ final Object attributeValue = dataNode.getLeaves().get(attributeName);
+ return targetClass.isInstance(attributeValue) ? targetClass.cast(attributeValue) : null;
+ })
+ .filter(Objects::nonNull)
+ .collect(Collectors.toSet());
+ }
+
+ @Override
@Timed(value = "cps.data.persistence.service.datanode.query.anchors",
description = "Time taken to query data nodes across all anchors or list of anchors")
public List<DataNode> queryDataNodesAcrossAnchors(final String dataspaceName, final String cpsPath,
diff --git a/cps-ri/src/main/java/org/onap/cps/ri/CpsModulePersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/ri/CpsModulePersistenceServiceImpl.java
index cf9fb021a6..dbc6c28ec5 100755
--- a/cps-ri/src/main/java/org/onap/cps/ri/CpsModulePersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/ri/CpsModulePersistenceServiceImpl.java
@@ -36,7 +36,6 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -70,10 +69,6 @@ import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo;
import org.springframework.dao.DataIntegrityViolationException;
-import org.springframework.retry.RetryContext;
-import org.springframework.retry.annotation.Backoff;
-import org.springframework.retry.annotation.Retryable;
-import org.springframework.retry.support.RetrySynchronizationManager;
import org.springframework.stereotype.Component;
@Slf4j
@@ -107,10 +102,9 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
@Override
public Collection<ModuleReference> getYangResourceModuleReferences(final String dataspaceName) {
- final Set<YangResourceModuleReference> yangResourceModuleReferenceList =
+ final Collection<YangResourceModuleReference> yangResourceModuleReferences =
yangResourceRepository.findAllModuleReferencesByDataspace(dataspaceName);
- return yangResourceModuleReferenceList.stream().map(CpsModulePersistenceServiceImpl::toModuleReference)
- .collect(Collectors.toList());
+ return yangResourceModuleReferences.stream().map(CpsModulePersistenceServiceImpl::toModuleReference).toList();
}
@Override
@@ -154,23 +148,24 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
@Override
@Transactional
- // A retry is made to store the schema set if it fails because of duplicated yang resource exception that
- // can occur in case of specific concurrent requests.
- @Retryable(retryFor = DuplicatedYangResourceException.class, maxAttempts = 5, backoff =
- @Backoff(random = true, delay = 200, maxDelay = 2000, multiplier = 2))
- public void storeSchemaSet(final String dataspaceName, final String schemaSetName,
- final Map<String, String> moduleReferenceNameToContentMap) {
- final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
- final Set<YangResourceEntity> yangResourceEntities = synchronizeYangResources(moduleReferenceNameToContentMap);
- final SchemaSetEntity schemaSetEntity = new SchemaSetEntity();
- schemaSetEntity.setName(schemaSetName);
- schemaSetEntity.setDataspace(dataspaceEntity);
- schemaSetEntity.setYangResources(yangResourceEntities);
- try {
- schemaSetRepository.save(schemaSetEntity);
- } catch (final DataIntegrityViolationException e) {
- throw AlreadyDefinedException.forSchemaSet(schemaSetName, dataspaceName, e);
- }
+ @Timed(value = "cps.module.persistence.schemaset.create",
+ description = "Time taken to store a schemaset (list of module references)")
+ public void createSchemaSet(final String dataspaceName, final String schemaSetName,
+ final Map<String, String> yangResourceContentPerName) {
+ final Set<YangResourceEntity> yangResourceEntities = synchronizeYangResources(yangResourceContentPerName);
+ createAndSaveSchemaSetEntity(dataspaceName, schemaSetName, yangResourceEntities);
+ }
+
+ @Override
+ @Transactional
+ @Timed(value = "cps.module.persistence.schemaset.createFromNewAndExistingModules",
+ description = "Time taken to store a schemaset (from new and existing)")
+ public void createSchemaSetFromNewAndExistingModules(final String dataspaceName, final String schemaSetName,
+ final Map<String, String> newYangResourceContentPerName,
+ final Collection<ModuleReference> allModuleReferences) {
+ synchronizeYangResources(newYangResourceContentPerName);
+ final Set<YangResourceEntity> allYangResourceEntities = getYangResourceEntities(allModuleReferences);
+ createAndSaveSchemaSetEntity(dataspaceName, schemaSetName, allYangResourceEntities);
}
@Override
@@ -189,26 +184,6 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
@Override
@Transactional
- // A retry is made to store the schema set if it fails because of duplicated yang resource exception that
- // can occur in case of specific concurrent requests.
- @Retryable(retryFor = DuplicatedYangResourceException.class, maxAttempts = 5, backoff =
- @Backoff(random = true, delay = 200, maxDelay = 2000, multiplier = 2))
- @Timed(value = "cps.module.persistence.schemaset.store",
- description = "Time taken to store a schemaset (list of module references")
- public void storeSchemaSetFromModules(final String dataspaceName, final String schemaSetName,
- final Map<String, String> newModuleNameToContentMap,
- final Collection<ModuleReference> allModuleReferences) {
- storeSchemaSet(dataspaceName, schemaSetName, newModuleNameToContentMap);
- final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
- final SchemaSetEntity schemaSetEntity =
- schemaSetRepository.getByDataspaceAndName(dataspaceEntity, schemaSetName);
- final List<Integer> allYangResourceIds =
- yangResourceRepository.getResourceIdsByModuleReferences(allModuleReferences);
- yangResourceRepository.insertSchemaSetIdYangResourceId(schemaSetEntity.getId(), allYangResourceIds);
- }
-
- @Override
- @Transactional
public void deleteSchemaSet(final String dataspaceName, final String schemaSetName) {
final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
final SchemaSetEntity schemaSetEntity =
@@ -225,20 +200,23 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
@Override
@Transactional
- public void updateSchemaSetFromModules(final String dataspaceName, final String schemaSetName,
- final Map<String, String> newModuleNameToContentMap,
- final Collection<ModuleReference> allModuleReferences) {
+ public void updateSchemaSetFromNewAndExistingModules(final String dataspaceName, final String schemaSetName,
+ final Map<String, String> newYangResourcesPerName,
+ final Collection<ModuleReference> allModuleReferences) {
final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
final SchemaSetEntity schemaSetEntity =
schemaSetRepository.getByDataspaceAndName(dataspaceEntity, schemaSetName);
- storeAndLinkNewModules(newModuleNameToContentMap, schemaSetEntity);
- updateAllModuleReferences(allModuleReferences, schemaSetEntity.getId());
+ synchronizeYangResources(newYangResourcesPerName);
+ final Set<YangResourceEntity> allYangResourceEntities = getYangResourceEntities(allModuleReferences);
+ schemaSetEntity.setYangResources(allYangResourceEntities);
+ schemaSetRepository.save(schemaSetEntity);
}
@Override
@Transactional
- public void deleteAllUnusedYangModuleData() {
- schemaSetRepository.deleteOrphanedSchemaSets();
+ public void deleteAllUnusedYangModuleData(final String dataspaceName) {
+ final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ schemaSetRepository.deleteOrphanedSchemaSets(dataspaceEntity.getId());
yangResourceRepository.deleteOrphanedYangResources();
}
@@ -248,9 +226,35 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
return moduleReferenceRepository.identifyNewModuleReferences(moduleReferencesToCheck);
}
- private Set<YangResourceEntity> synchronizeYangResources(
- final Map<String, String> moduleReferenceNameToContentMap) {
- final Map<String, YangResourceEntity> checksumToEntityMap = moduleReferenceNameToContentMap.entrySet().stream()
+ private Set<YangResourceEntity> synchronizeYangResources(final Map<String, String> yangResourceContentPerName) {
+ final Map<String, YangResourceEntity> yangResourceEntitiesPerChecksum =
+ getYangResourceEntityPerChecksum(yangResourceContentPerName);
+
+ final List<YangResourceEntity> existingYangResourceEntities =
+ yangResourceRepository.findAllByChecksumIn(yangResourceEntitiesPerChecksum.keySet());
+
+ existingYangResourceEntities.forEach(exist -> yangResourceEntitiesPerChecksum.remove(exist.getChecksum()));
+ final Collection<YangResourceEntity> newYangResourceEntities = yangResourceEntitiesPerChecksum.values();
+
+ if (!newYangResourceEntities.isEmpty()) {
+ try {
+ yangResourceRepository.saveAll(newYangResourceEntities);
+ } catch (final DataIntegrityViolationException dataIntegrityViolationException) {
+ convertExceptionIfNeeded(dataIntegrityViolationException, newYangResourceEntities);
+ }
+ }
+
+ // return ALL yang resourceEntities
+ return ImmutableSet.<YangResourceEntity>builder()
+ .addAll(existingYangResourceEntities)
+ .addAll(newYangResourceEntities)
+ .build();
+ }
+
+ private static Map<String, YangResourceEntity> getYangResourceEntityPerChecksum(
+ final Map<String, String> yangResourceContentPerName) {
+ final Map<String, YangResourceEntity> yangResourceEntityPerChecksum =
+ yangResourceContentPerName.entrySet().stream()
.map(entry -> {
final String checksum = DigestUtils.sha256Hex(entry.getValue().getBytes(StandardCharsets.UTF_8));
final Map<String, String> moduleNameAndRevisionMap = createModuleNameAndRevisionMap(entry.getKey(),
@@ -267,37 +271,22 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
YangResourceEntity::getChecksum,
entity -> entity
));
+ return yangResourceEntityPerChecksum;
+ }
- final List<YangResourceEntity> existingYangResourceEntities =
- yangResourceRepository.findAllByChecksumIn(checksumToEntityMap.keySet());
- existingYangResourceEntities.forEach(yangFile -> checksumToEntityMap.remove(yangFile.getChecksum()));
-
- final Collection<YangResourceEntity> newYangResourceEntities = checksumToEntityMap.values();
- if (!newYangResourceEntities.isEmpty()) {
- try {
- yangResourceRepository.saveAll(newYangResourceEntities);
- } catch (final DataIntegrityViolationException dataIntegrityViolationException) {
- // Throw a CPS duplicated Yang resource exception if the cause of the error is a yang checksum
- // database constraint violation.
- // If it is not, then throw the original exception
- final Optional<DuplicatedYangResourceException> convertedException =
- convertToDuplicatedYangResourceException(
- dataIntegrityViolationException, newYangResourceEntities);
- convertedException.ifPresent(
- e -> {
- final RetryContext retryContext = RetrySynchronizationManager.getContext();
- int retryCount = retryContext == null ? 0 : retryContext.getRetryCount();
- log.warn("Cannot persist duplicated yang resource. System will attempt this method "
- + "up to 5 times. Current retry count : {}", ++retryCount, e);
- });
- throw convertedException.isPresent() ? convertedException.get() : dataIntegrityViolationException;
- }
+ private void createAndSaveSchemaSetEntity(final String dataspaceName,
+ final String schemaSetName,
+ final Set<YangResourceEntity> yangResourceEntities) {
+ final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ final SchemaSetEntity schemaSetEntity = new SchemaSetEntity();
+ schemaSetEntity.setName(schemaSetName);
+ schemaSetEntity.setDataspace(dataspaceEntity);
+ schemaSetEntity.setYangResources(yangResourceEntities);
+ try {
+ schemaSetRepository.save(schemaSetEntity);
+ } catch (final DataIntegrityViolationException e) {
+ throw AlreadyDefinedException.forSchemaSet(schemaSetName, dataspaceName, e);
}
-
- return ImmutableSet.<YangResourceEntity>builder()
- .addAll(existingYangResourceEntities)
- .addAll(newYangResourceEntities)
- .build();
}
private static Map<String, String> createModuleNameAndRevisionMap(final String sourceName, final String source) {
@@ -342,6 +331,14 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
return RevisionSourceIdentifier.create(sourceName);
}
+ private void convertExceptionIfNeeded(final DataIntegrityViolationException dataIntegrityViolationException,
+ final Collection<YangResourceEntity> newYangResourceEntities) {
+ final Optional<DuplicatedYangResourceException> convertedException =
+ convertToDuplicatedYangResourceException(
+ dataIntegrityViolationException, newYangResourceEntities);
+ throw convertedException.isPresent() ? convertedException.get() : dataIntegrityViolationException;
+ }
+
/**
* Convert the specified data integrity violation exception into a CPS duplicated Yang resource exception
* if the cause of the error is a yang checksum database constraint violation.
@@ -391,6 +388,13 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
return "no checksum found";
}
+ private Set<YangResourceEntity> getYangResourceEntities(final Collection<ModuleReference> moduleReferences) {
+ return moduleReferences.stream().map(moduleReference ->
+ yangResourceRepository
+ .findByModuleNameAndRevision(moduleReference.getModuleName(), moduleReference.getRevision()))
+ .collect(Collectors.toSet());
+ }
+
private static ModuleReference toModuleReference(
final YangResourceModuleReference yangResourceModuleReference) {
return ModuleReference.builder()
@@ -411,20 +415,4 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
.dataspaceName(schemaSetEntity.getDataspace().getName()).build();
}
- private void storeAndLinkNewModules(final Map<String, String> newModuleNameToContentMap,
- final SchemaSetEntity schemaSetEntity) {
- final Set<YangResourceEntity> yangResourceEntities
- = new HashSet<>(synchronizeYangResources(newModuleNameToContentMap));
- schemaSetEntity.setYangResources(yangResourceEntities);
- schemaSetRepository.save(schemaSetEntity);
- }
-
- private void updateAllModuleReferences(final Collection<ModuleReference> allModuleReferences,
- final Integer schemaSetEntityId) {
- yangResourceRepository.deleteSchemaSetYangResourceForSchemaSetId(schemaSetEntityId);
- final List<Integer> allYangResourceIds =
- yangResourceRepository.getResourceIdsByModuleReferences(allModuleReferences);
- yangResourceRepository.insertSchemaSetIdYangResourceId(schemaSetEntityId, allYangResourceIds);
- }
-
}
diff --git a/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentQueryBuilder.java b/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentQueryBuilder.java
index 3f3ca79900..bf354be024 100644
--- a/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentQueryBuilder.java
+++ b/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentQueryBuilder.java
@@ -51,13 +51,18 @@ public class FragmentQueryBuilder {
private EntityManager entityManager;
/**
- * Create a sql query to retrieve by anchor(id) and cps path.
+ * Create a sql query to retrieve by anchor(id) and cps path with an optional queryResultLimit on results.
*
* @param anchorEntity the anchor
* @param cpsPathQuery the cps path query to be transformed into a sql query
+ * @param queryResultLimit queryResultLimit number of returned entities
+ * (if the queryResultLimit is less than 1 the method returns all related entities)
+ *
* @return a executable query object
*/
- public Query getQueryForAnchorAndCpsPath(final AnchorEntity anchorEntity, final CpsPathQuery cpsPathQuery) {
+ public Query getQueryForAnchorAndCpsPath(final AnchorEntity anchorEntity,
+ final CpsPathQuery cpsPathQuery,
+ final int queryResultLimit) {
final StringBuilder sqlStringBuilder = new StringBuilder();
final Map<String, Object> queryParameters = new HashMap<>();
@@ -65,6 +70,7 @@ public class FragmentQueryBuilder {
addWhereClauseForAnchor(anchorEntity, sqlStringBuilder, queryParameters);
addNodeSearchConditions(cpsPathQuery, sqlStringBuilder, queryParameters, false);
addSearchSuffix(cpsPathQuery, sqlStringBuilder, queryParameters);
+ addLimitClause(sqlStringBuilder, queryParameters, queryResultLimit);
return getQuery(sqlStringBuilder.toString(), queryParameters, FragmentEntity.class);
}
@@ -219,6 +225,15 @@ public class FragmentQueryBuilder {
}
}
+ private static void addLimitClause(final StringBuilder sqlStringBuilder,
+ final Map<String, Object> queryParameters,
+ final int queryResultLimit) {
+ if (queryResultLimit > 0) {
+ sqlStringBuilder.append(" LIMIT :queryResultLimit");
+ queryParameters.put("queryResultLimit", queryResultLimit);
+ }
+ }
+
private static Integer getTextValueAsInt(final CpsPathQuery cpsPathQuery) {
try {
return Integer.parseInt(cpsPathQuery.getTextFunctionConditionValue());
diff --git a/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentRepositoryCpsPathQuery.java b/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentRepositoryCpsPathQuery.java
index 9c1929eaf7..4ee6555b79 100644
--- a/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentRepositoryCpsPathQuery.java
+++ b/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentRepositoryCpsPathQuery.java
@@ -29,7 +29,9 @@ import org.onap.cps.ri.models.DataspaceEntity;
import org.onap.cps.ri.models.FragmentEntity;
public interface FragmentRepositoryCpsPathQuery {
- List<FragmentEntity> findByAnchorAndCpsPath(AnchorEntity anchorEntity, CpsPathQuery cpsPathQuery);
+
+ List<FragmentEntity> findByAnchorAndCpsPath(AnchorEntity anchorEntity, CpsPathQuery cpsPathQuery,
+ int queryResultLimit);
List<FragmentEntity> findByDataspaceAndCpsPath(DataspaceEntity dataspaceEntity,
CpsPathQuery cpsPathQuery, List<Long> anchorIds);
diff --git a/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentRepositoryCpsPathQueryImpl.java b/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentRepositoryCpsPathQueryImpl.java
index e8c2725670..80fbe9b6cd 100644
--- a/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentRepositoryCpsPathQueryImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentRepositoryCpsPathQueryImpl.java
@@ -41,10 +41,15 @@ public class FragmentRepositoryCpsPathQueryImpl implements FragmentRepositoryCps
@Override
@Transactional
public List<FragmentEntity> findByAnchorAndCpsPath(final AnchorEntity anchorEntity,
- final CpsPathQuery cpsPathQuery) {
- final Query query = fragmentQueryBuilder.getQueryForAnchorAndCpsPath(anchorEntity, cpsPathQuery);
+ final CpsPathQuery cpsPathQuery,
+ final int queryResultLimit) {
+ final Query query = fragmentQueryBuilder
+ .getQueryForAnchorAndCpsPath(anchorEntity, cpsPathQuery, queryResultLimit);
final List<FragmentEntity> fragmentEntities = query.getResultList();
log.debug("Fetched {} fragment entities by anchor and cps path.", fragmentEntities.size());
+ if (queryResultLimit > 0) {
+ log.debug("Result limited to {} entries", queryResultLimit);
+ }
return fragmentEntities;
}
diff --git a/cps-ri/src/main/java/org/onap/cps/ri/repository/SchemaSetRepository.java b/cps-ri/src/main/java/org/onap/cps/ri/repository/SchemaSetRepository.java
index b8dd7b755c..fdd72624ba 100644
--- a/cps-ri/src/main/java/org/onap/cps/ri/repository/SchemaSetRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/ri/repository/SchemaSetRepository.java
@@ -83,8 +83,8 @@ public interface SchemaSetRepository extends JpaRepository<SchemaSetEntity, Inte
*/
@Modifying
@Query(value = """
- DELETE FROM schema_set WHERE NOT EXISTS
- (SELECT 1 FROM anchor WHERE anchor.schema_set_id = schema_set.id)
+ DELETE FROM schema_set WHERE schema_set.dataspace_id = :dataspaceId AND
+ NOT EXISTS (SELECT 1 FROM anchor WHERE anchor.schema_set_id = schema_set.id)
""", nativeQuery = true)
- void deleteOrphanedSchemaSets();
+ void deleteOrphanedSchemaSets(@Param("dataspaceId") final int dataspaceId);
}
diff --git a/cps-ri/src/main/java/org/onap/cps/ri/repository/SchemaSetYangResourceRepository.java b/cps-ri/src/main/java/org/onap/cps/ri/repository/SchemaSetYangResourceRepository.java
deleted file mode 100644
index 410dcc2e26..0000000000
--- a/cps-ri/src/main/java/org/onap/cps/ri/repository/SchemaSetYangResourceRepository.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021-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.
- * 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.ri.repository;
-
-import java.util.List;
-
-public interface SchemaSetYangResourceRepository {
-
-
- /**
- * Link yang resources (ids) with a schema set (id).
- *
- * @param schemaSetId the schema set id
- * @param yangResourceIds list of yang resource ids
- */
- void insertSchemaSetIdYangResourceId(final Integer schemaSetId, final List<Integer> yangResourceIds);
-
-}
diff --git a/cps-ri/src/main/java/org/onap/cps/ri/repository/SchemaSetYangResourceRepositoryImpl.java b/cps-ri/src/main/java/org/onap/cps/ri/repository/SchemaSetYangResourceRepositoryImpl.java
deleted file mode 100644
index 989809af5b..0000000000
--- a/cps-ri/src/main/java/org/onap/cps/ri/repository/SchemaSetYangResourceRepositoryImpl.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021-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.
- * 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.ri.repository;
-
-import jakarta.persistence.EntityManager;
-import jakarta.persistence.PersistenceContext;
-import java.sql.PreparedStatement;
-import java.util.List;
-import org.hibernate.Session;
-import org.springframework.transaction.annotation.Transactional;
-
-@Transactional
-public class SchemaSetYangResourceRepositoryImpl implements SchemaSetYangResourceRepository {
-
- private static final int MAX_INSERT_BATCH_SIZE = 100;
-
- @PersistenceContext
- private EntityManager entityManager;
-
- @Override
- public void insertSchemaSetIdYangResourceId(final Integer schemaSetId, final List<Integer> yangResourceIds) {
- final Session session = entityManager.unwrap(Session.class);
- session.doWork(connection -> {
- try (PreparedStatement preparedStatement = connection.prepareStatement(
- "INSERT INTO SCHEMA_SET_YANG_RESOURCES (SCHEMA_SET_ID, YANG_RESOURCE_ID) VALUES ( ?, ?)")) {
- int sqlQueryCount = 1;
- for (final int yangResourceId : yangResourceIds) {
- preparedStatement.setInt(1, schemaSetId);
- preparedStatement.setInt(2, yangResourceId);
- preparedStatement.addBatch();
- if (sqlQueryCount % MAX_INSERT_BATCH_SIZE == 0 || sqlQueryCount == yangResourceIds.size()) {
- preparedStatement.executeBatch();
- }
- sqlQueryCount++;
- }
- }
- });
- }
-}
-
diff --git a/cps-ri/src/main/java/org/onap/cps/ri/repository/YangResourceNativeRepository.java b/cps-ri/src/main/java/org/onap/cps/ri/repository/YangResourceNativeRepository.java
deleted file mode 100644
index 2875511c1e..0000000000
--- a/cps-ri/src/main/java/org/onap/cps/ri/repository/YangResourceNativeRepository.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * 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.
- * 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.ri.repository;
-
-import java.util.Collection;
-import java.util.List;
-import org.onap.cps.api.model.ModuleReference;
-
-public interface YangResourceNativeRepository {
-
- List<Integer> getResourceIdsByModuleReferences(Collection<ModuleReference> moduleReferences);
-
-}
diff --git a/cps-ri/src/main/java/org/onap/cps/ri/repository/YangResourceNativeRepositoryImpl.java b/cps-ri/src/main/java/org/onap/cps/ri/repository/YangResourceNativeRepositoryImpl.java
deleted file mode 100644
index 34f1ee362a..0000000000
--- a/cps-ri/src/main/java/org/onap/cps/ri/repository/YangResourceNativeRepositoryImpl.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * 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.
- * 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.ri.repository;
-
-import jakarta.persistence.EntityManager;
-import jakarta.persistence.PersistenceContext;
-import jakarta.persistence.Query;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.StringJoiner;
-import lombok.extern.slf4j.Slf4j;
-import org.hibernate.type.StandardBasicTypes;
-import org.onap.cps.api.model.ModuleReference;
-import org.springframework.stereotype.Repository;
-import org.springframework.transaction.annotation.Transactional;
-
-@Slf4j
-@Repository
-public class YangResourceNativeRepositoryImpl implements YangResourceNativeRepository {
-
- @PersistenceContext
- private EntityManager entityManager;
-
- @Override
- @Transactional
- public List<Integer> getResourceIdsByModuleReferences(final Collection<ModuleReference> moduleReferences) {
- if (moduleReferences.isEmpty()) {
- return Collections.emptyList();
- }
- final Query query = entityManager.createNativeQuery(getCombinedSelectSqlQuery(moduleReferences))
- .unwrap(org.hibernate.query.NativeQuery.class)
- .addScalar("id", StandardBasicTypes.INTEGER);
- final List<Integer> yangResourceIds = query.getResultList();
- if (yangResourceIds.size() != moduleReferences.size()) {
- log.warn("ModuleReferences size : {} and QueryResult size : {}", moduleReferences.size(),
- yangResourceIds.size());
- }
- return yangResourceIds;
- }
-
- private String getCombinedSelectSqlQuery(final Collection<ModuleReference> moduleReferences) {
- final StringJoiner sqlQueryJoiner = new StringJoiner(" UNION ALL ");
- moduleReferences.forEach(moduleReference ->
- sqlQueryJoiner.add(String.format("SELECT id FROM yang_resource WHERE module_name='%s' and revision='%s'",
- moduleReference.getModuleName(),
- moduleReference.getRevision()))
- );
- return sqlQueryJoiner.toString();
- }
-}
diff --git a/cps-ri/src/main/java/org/onap/cps/ri/repository/YangResourceRepository.java b/cps-ri/src/main/java/org/onap/cps/ri/repository/YangResourceRepository.java
index 628502f846..e36e376bc6 100644
--- a/cps-ri/src/main/java/org/onap/cps/ri/repository/YangResourceRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/ri/repository/YangResourceRepository.java
@@ -32,8 +32,10 @@ import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
@Repository
-public interface YangResourceRepository extends JpaRepository<YangResourceEntity, Integer>,
- YangResourceNativeRepository, SchemaSetYangResourceRepository {
+public interface YangResourceRepository extends JpaRepository<YangResourceEntity, Integer> {
+
+ YangResourceEntity findByModuleNameAndRevision(@Param("moduleName") String moduleName,
+ @Param("revision") String revision);
List<YangResourceEntity> findAllByChecksumIn(Collection<String> checksums);
@@ -88,10 +90,6 @@ public interface YangResourceRepository extends JpaRepository<YangResourceEntity
@Param("moduleName") String moduleName, @Param("revision") String revision);
@Modifying
- @Query(value = "DELETE FROM schema_set_yang_resources WHERE schema_set_id = :schemaSetId", nativeQuery = true)
- void deleteSchemaSetYangResourceForSchemaSetId(@Param("schemaSetId") int schemaSetId);
-
- @Modifying
@Query(value = """
DELETE FROM yang_resource WHERE NOT EXISTS (SELECT 1 FROM schema_set_yang_resources
WHERE schema_set_yang_resources.yang_resource_id = yang_resource.id)
diff --git a/cps-ri/src/main/java/org/onap/cps/ri/utils/CpsValidatorImpl.java b/cps-ri/src/main/java/org/onap/cps/ri/utils/CpsValidatorImpl.java
index fa9feee1e7..9e89c8aed9 100644
--- a/cps-ri/src/main/java/org/onap/cps/ri/utils/CpsValidatorImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/ri/utils/CpsValidatorImpl.java
@@ -27,7 +27,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.exceptions.DataValidationException;
import org.onap.cps.api.parameters.PaginationOption;
-import org.onap.cps.impl.utils.CpsValidator;
+import org.onap.cps.utils.CpsValidator;
import org.springframework.stereotype.Component;
@Slf4j
diff --git a/cps-ri/src/test/groovy/org/onap/cps/ri/CpsDataPersistenceServiceImplSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/ri/CpsDataPersistenceServiceImplSpec.groovy
index c818f3ba1f..e927922acf 100644
--- a/cps-ri/src/test/groovy/org/onap/cps/ri/CpsDataPersistenceServiceImplSpec.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/ri/CpsDataPersistenceServiceImplSpec.groovy
@@ -33,7 +33,7 @@ import org.onap.cps.api.parameters.FetchDescendantsOption
import org.onap.cps.api.exceptions.ConcurrencyException
import org.onap.cps.api.exceptions.DataValidationException
import org.onap.cps.api.model.DataNode
-import org.onap.cps.api.model.DataNodeBuilder
+import org.onap.cps.impl.DataNodeBuilder
import org.onap.cps.utils.JsonObjectMapper
import org.springframework.dao.DataIntegrityViolationException
import spock.lang.Specification
diff --git a/cps-ri/src/test/groovy/org/onap/cps/ri/CpsModulePersistenceServiceConcurrencySpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/ri/CpsModulePersistenceServiceConcurrencySpec.groovy
deleted file mode 100644
index 28a615b0e8..0000000000
--- a/cps-ri/src/test/groovy/org/onap/cps/ri/CpsModulePersistenceServiceConcurrencySpec.groovy
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022 Bell Canada.
- * Modifications Copyright (C) 2021-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.
- * 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.ri
-
-import org.hibernate.exception.ConstraintViolationException
-import org.onap.cps.ri.models.DataspaceEntity
-import org.onap.cps.ri.models.SchemaSetEntity
-import org.onap.cps.ri.repository.DataspaceRepository
-import org.onap.cps.ri.repository.ModuleReferenceRepository
-import org.onap.cps.ri.repository.SchemaSetRepository
-import org.onap.cps.ri.repository.YangResourceRepository
-import org.onap.cps.spi.CpsAdminPersistenceService
-import org.onap.cps.spi.CpsModulePersistenceService
-import org.onap.cps.api.exceptions.DuplicatedYangResourceException
-import org.onap.cps.api.model.ModuleReference
-import org.spockframework.spring.SpringBean
-import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.boot.test.context.SpringBootTest
-import org.springframework.dao.DataIntegrityViolationException
-import org.springframework.retry.annotation.EnableRetry
-import spock.lang.Specification
-
-import java.sql.SQLException
-
-@SpringBootTest(classes=[CpsModulePersistenceServiceImpl])
-@EnableRetry
-class CpsModulePersistenceServiceConcurrencySpec extends Specification {
-
- @Autowired
- CpsModulePersistenceService objectUnderTest
-
- @SpringBean
- DataspaceRepository dataspaceRepository = Mock()
-
- @SpringBean
- YangResourceRepository yangResourceRepository = Mock()
-
- @SpringBean
- SchemaSetRepository schemaSetRepository = Mock()
-
- @SpringBean
- CpsAdminPersistenceService cpsAdminPersistenceService = Mock()
-
- @SpringBean
- ModuleReferenceRepository moduleReferenceRepository = Mock()
-
- def NEW_RESOURCE_NAME = 'some new resource'
- def NEW_RESOURCE_CONTENT = 'module stores {\n' +
- ' yang-version 1.1;\n' +
- ' namespace "org:onap:ccsdk:sample";\n' +
- '}'
-
- def newYangResourcesNameToContentMap = [(NEW_RESOURCE_NAME):NEW_RESOURCE_CONTENT]
-
- def yangResourceChecksum = 'b13faef573ed1374139d02c40d8ce09c80ea1dc70e63e464c1ed61568d48d539'
-
- def yangResourceChecksumDbConstraint = 'yang_resource_checksum_key'
-
- def sqlExceptionMessage = String.format('(checksum)=(%s)', yangResourceChecksum)
-
- def checksumIntegrityException = new DataIntegrityViolationException("checksum integrity exception",
- new ConstraintViolationException('', new SQLException(sqlExceptionMessage), yangResourceChecksumDbConstraint))
-
- def 'Store new schema set, maximum retries.'() {
- given: 'no pre-existing schemaset in database'
- dataspaceRepository.getByName(_) >> new DataspaceEntity()
- yangResourceRepository.findAllByChecksumIn(_) >> Collections.emptyList()
- when: 'a new schemaset is stored'
- objectUnderTest.storeSchemaSet('some dataspace', 'some new schema set', newYangResourcesNameToContentMap)
- then: 'a duplicated yang resource exception is thrown '
- thrown(DuplicatedYangResourceException)
- and: 'the system will attempt to save the data 5 times (because checksum integrity exception is thrown each time)'
- 5 * yangResourceRepository.saveAll(_) >> { throw checksumIntegrityException }
- }
-
- def 'Store new schema set, succeed on third attempt.'() {
- given: 'no pre-existing schemaset in database'
- dataspaceRepository.getByName(_) >> new DataspaceEntity()
- yangResourceRepository.findAllByChecksumIn(_) >> Collections.emptyList()
- when: 'a new schemaset is stored'
- objectUnderTest.storeSchemaSet('some dataspace', 'some new schema set', newYangResourcesNameToContentMap)
- then: 'no exception is thrown '
- noExceptionThrown()
- and: 'the system will attempt to save the data 2 times with checksum integrity exception but then succeed'
- 2 * yangResourceRepository.saveAll(_) >> { throw checksumIntegrityException }
- 1 * yangResourceRepository.saveAll(_) >> []
- }
-
- def 'Store schema set using modules, maximum retries.'() {
- given: 'map of new modules, a list of existing modules, module reference'
- def mapOfNewModules = [newModule1: 'module newmodule { yang-version 1.1; revision "2021-10-12" { } }']
- def moduleReferenceForExistingModule = new ModuleReference("test","2021-10-12")
- def listOfExistingModulesModuleReference = [moduleReferenceForExistingModule]
- and: 'no pre-existing schemaset in database'
- dataspaceRepository.getByName(_) >> new DataspaceEntity()
- yangResourceRepository.findAllByChecksumIn(_) >> Collections.emptyList()
- when: 'a new schemaset is stored from a module'
- objectUnderTest.storeSchemaSetFromModules('some dataspace', 'some new schema set' , mapOfNewModules, listOfExistingModulesModuleReference)
- then: 'a duplicated yang resource exception is thrown '
- thrown(DuplicatedYangResourceException)
- and: 'the system will attempt to save the data 5 times (because checksum integrity exception is thrown each time)'
- 5 * yangResourceRepository.saveAll(_) >> { throw checksumIntegrityException }
- }
-
- def 'Store schema set using modules, succeed on third attempt.'() {
- given: 'map of new modules, a list of existing modules, module reference'
- def mapOfNewModules = [newModule1: 'module newmodule { yang-version 1.1; revision "2021-10-12" { } }']
- def moduleReferenceForExistingModule = new ModuleReference("test","2021-10-12")
- def listOfExistingModulesModuleReference = [moduleReferenceForExistingModule]
- and: 'no pre-existing schemaset in database'
- def dataspaceEntity = new DataspaceEntity()
- dataspaceRepository.getByName(_) >> new DataspaceEntity()
- yangResourceRepository.findAllByChecksumIn(_) >> Collections.emptyList()
- yangResourceRepository.getResourceIdsByModuleReferences(_) >> []
- and: 'can retrieve schemaset details after storing it'
- def schemaSetEntity = new SchemaSetEntity()
- schemaSetRepository.getByDataspaceAndName(dataspaceEntity, 'new schema set') >> schemaSetEntity
- when: 'a new schemaset is stored from a module'
- objectUnderTest.storeSchemaSetFromModules('some dataspace', 'new schema set' , mapOfNewModules, listOfExistingModulesModuleReference)
- then: 'no exception is thrown '
- noExceptionThrown()
- and: 'the system will attempt to save the data 2 times with checksum integrity exception but then succeed'
- 2 * yangResourceRepository.saveAll(_) >> { throw checksumIntegrityException }
- 1 * yangResourceRepository.saveAll(_) >> []
- }
-
-}
diff --git a/cps-ri/src/test/groovy/org/onap/cps/ri/CpsModulePersistenceServiceImplSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/ri/CpsModulePersistenceServiceImplSpec.groovy
index 2915bc8e8c..9abfdbeb33 100644
--- a/cps-ri/src/test/groovy/org/onap/cps/ri/CpsModulePersistenceServiceImplSpec.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/ri/CpsModulePersistenceServiceImplSpec.groovy
@@ -78,8 +78,8 @@ class CpsModulePersistenceServiceImplSpec extends Specification {
and: 'persisting yang resource raises db constraint exception (in case of concurrent requests for example)'
mockYangResourceRepository.saveAll(_) >> { throw dbException }
when: 'attempt to store schema set '
- def newYangResourcesNameToContentMap = [(yangResourceName):yangResourceContent]
- objectUnderTest.storeSchemaSet('my-dataspace', 'my-schema-set', newYangResourcesNameToContentMap)
+ def newYangResourceContentPerName = [(yangResourceName):yangResourceContent]
+ objectUnderTest.createSchemaSet('my-dataspace', 'my-schema-set', newYangResourceContentPerName)
then: 'an #expectedThrownException is thrown'
def e = thrown(expectedThrownException)
assert e.getMessage().contains(expectedThrownExceptionMessage)
@@ -96,7 +96,7 @@ class CpsModulePersistenceServiceImplSpec extends Specification {
def schemaSetEntity = new SchemaSetEntity(id: 1)
mockSchemaSetRepository.getByDataspaceAndName(_, _) >> schemaSetEntity
when: 'schema set update is requested'
- objectUnderTest.updateSchemaSetFromModules('my-dataspace', 'my-schemaset', [:], [new ModuleReference('some module name', 'some revision name')])
+ objectUnderTest.updateSchemaSetFromNewAndExistingModules('my-dataspace', 'my-schemaset', [:], [new ModuleReference('some module name', 'some revision name')])
then: 'no exception is thrown '
noExceptionThrown()
}