aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ri/src
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ri/src')
-rw-r--r--cps-ri/src/main/java/org/onap/cps/ri/CpsDataPersistenceServiceImpl.java2
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/ri/CpsModulePersistenceServiceImpl.java29
-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/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
6 files changed, 11 insertions, 175 deletions
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..52fd7f2be1 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
@@ -50,12 +50,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;
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..aaf6165471 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
@@ -70,10 +70,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
@@ -154,10 +150,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))
public void storeSchemaSet(final String dataspaceName, final String schemaSetName,
final Map<String, String> moduleReferenceNameToContentMap) {
final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
@@ -189,12 +181,8 @@ 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")
+ 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) {
@@ -237,8 +225,9 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
@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();
}
@@ -278,18 +267,10 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
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
+ // 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;
}
}
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/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(_) >> []
- }
-
-}