diff options
Diffstat (limited to 'cps-service')
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/api/CpsDataService.java | 22 | ||||
-rwxr-xr-x | cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java | 12 | ||||
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java | 14 | ||||
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/spi/exceptions/SessionManagerException.java | 48 | ||||
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/spi/exceptions/SessionTimeoutException.java | 31 | ||||
-rw-r--r-- | cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy | 17 | ||||
-rw-r--r-- | cps-service/src/test/groovy/org/onap/cps/yang/YangTextSchemaSourceSetBuilderSpec.groovy (renamed from cps-service/src/test/groovy/org/onap/cps/utils/YangTextSchemaSourceSetSpec.groovy) | 12 |
7 files changed, 150 insertions, 6 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java index 35caf95153..93c96ec650 100644 --- a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java +++ b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java @@ -189,4 +189,26 @@ public interface CpsDataService { * */ void closeSession(String sessionId); + + /** + * Lock anchor with default timeout. + * To release locks(s), the session holding the lock(s) must be closed. + * + * @param sessionID session ID + * @param dataspaceName dataspace name + * @param anchorName anchor name + */ + void lockAnchor(String sessionID, String dataspaceName, String anchorName); + + /** + * Lock anchor with custom timeout. + * To release locks(s), the session holding the lock(s) must be closed. + * + * @param sessionID session ID + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @param timeoutInMilliseconds lock attempt timeout in milliseconds + */ + void lockAnchor(String sessionID, String dataspaceName, String anchorName, Long timeoutInMilliseconds); + } diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java index b95ad051e6..2f1067aafe 100755 --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java @@ -48,6 +48,7 @@ import org.springframework.stereotype.Service; public class CpsDataServiceImpl implements CpsDataService { private static final String ROOT_NODE_XPATH = "/"; + private static final long DEFAULT_LOCK_TIMEOUT_IN_MILLISECONDS = 300L; private final CpsDataPersistenceService cpsDataPersistenceService; private final CpsAdminService cpsAdminService; @@ -126,6 +127,17 @@ public class CpsDataServiceImpl implements CpsDataService { } @Override + public void lockAnchor(final String sessionID, final String dataspaceName, final String anchorName) { + lockAnchor(sessionID, dataspaceName, anchorName, DEFAULT_LOCK_TIMEOUT_IN_MILLISECONDS); + } + + @Override + public void lockAnchor(final String sessionID, final String dataspaceName, + final String anchorName, final Long timeoutInMilliseconds) { + cpsDataPersistenceService.lockAnchor(sessionID, dataspaceName, anchorName, timeoutInMilliseconds); + } + + @Override public void replaceNodeTree(final String dataspaceName, final String anchorName, final String parentNodeXpath, final String jsonData, final OffsetDateTime observedTimestamp) { CpsValidator.validateNameCharacters(dataspaceName, anchorName); diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java index 06da3ffc85..fd660e6756 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java +++ b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. + * Copyright (C) 2020-2022 Nordix Foundation. * Modifications Copyright (C) 2021 Pantheon.tech * Modifications Copyright (C) 2022 Bell Canada * ================================================================================ @@ -162,4 +162,16 @@ public interface CpsDataPersistenceService { * @param sessionId session ID */ void closeSession(String sessionId); + + /** + * Lock anchor. + * To release locks(s), the session holding the lock(s) must be closed. + * + * @param sessionID session ID + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @param timeoutInMilliseconds lock attempt timeout in milliseconds + */ + void lockAnchor(String sessionID, String dataspaceName, String anchorName, Long timeoutInMilliseconds); + } diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/SessionManagerException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/SessionManagerException.java new file mode 100644 index 0000000000..4000bfc51d --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/SessionManagerException.java @@ -0,0 +1,48 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022 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.spi.exceptions; + + +public class SessionManagerException extends CpsException { + + private static final long serialVersionUID = 7957090904519019500L; + + /** + * Constructor. + * + * @param message the error message + * @param details the error details + * @param cause the cause of the exception + */ + public SessionManagerException(final String message, final String details, final Throwable cause) { + super(message, details, cause); + } + + /** + * Constructor. + * + * @param message the error message + * @param details the error details + */ + public SessionManagerException(final String message, final String details) { + super(message, details); + } +} diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/SessionTimeoutException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/SessionTimeoutException.java new file mode 100644 index 0000000000..92b4aa7a8b --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/SessionTimeoutException.java @@ -0,0 +1,31 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022 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.spi.exceptions; + +@SuppressWarnings("squid:S110") // Team agreed to accept 6 levels of inheritance for CPS Exceptions +public class SessionTimeoutException extends SessionManagerException { + + private static final long serialVersionUID = -8809577494038691360L; + + public SessionTimeoutException(final String message, final String details, final Throwable cause) { + super(message, details, cause); + } +} diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy index faeba8d51a..8b9d545295 100644 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy @@ -430,4 +430,21 @@ class CpsDataServiceImplSpec extends Specification { then: 'the persistence service method to close session is invoked' 1 * mockCpsDataPersistenceService.closeSession(sessionId) } + + def 'lock anchor with no timeout parameter'(){ + when: 'lock anchor method with no timeout parameter with details of anchor entity to lock' + objectUnderTest.lockAnchor('some-sessionId', 'some-dataspaceName', 'some-anchorName') + then: 'the persistence service method to lock anchor is invoked with default timeout' + 1 * mockCpsDataPersistenceService.lockAnchor('some-sessionId', 'some-dataspaceName', + 'some-anchorName', 300L) + } + + def 'lock anchor with timeout parameter'(){ + when: 'lock anchor method with timeout parameter is called with details of anchor entity to lock' + objectUnderTest.lockAnchor('some-sessionId', 'some-dataspaceName', + 'some-anchorName', 250L) + then: 'the persistence service method to lock anchor is invoked with the given timeout' + 1 * mockCpsDataPersistenceService.lockAnchor('some-sessionId', 'some-dataspaceName', + 'some-anchorName', 250L) + } } diff --git a/cps-service/src/test/groovy/org/onap/cps/utils/YangTextSchemaSourceSetSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/yang/YangTextSchemaSourceSetBuilderSpec.groovy index b6250612ed..236221aca7 100644 --- a/cps-service/src/test/groovy/org/onap/cps/utils/YangTextSchemaSourceSetSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/yang/YangTextSchemaSourceSetBuilderSpec.groovy @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020-2021 Pantheon.tech - * Modifications Copyright (C) 2020-2021 Nordix Foundation + * Modifications Copyright (C) 2020-2022 Nordix Foundation * Modifications Copyright (C) 2021 Bell Canada. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,22 +20,24 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.utils +package org.onap.cps.yang + import org.onap.cps.TestUtils import org.onap.cps.spi.exceptions.ModelValidationException -import org.onap.cps.yang.YangTextSchemaSourceSetBuilder import org.opendaylight.yangtools.yang.common.Revision import spock.lang.Specification -class YangTextSchemaSourceSetSpec extends Specification { +class YangTextSchemaSourceSetBuilderSpec extends Specification { def 'Building a valid YangTextSchemaSourceSet using #filenameCase filename.'() { given: 'a yang model (file)' def yangResourceNameToContent = [filename: TestUtils.getResourceFileContent('bookstore.yang')] when: 'the content is parsed' def result = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext() - then: 'the result contains 1 module of the correct name and revision' + then: 'it can be validated successfully' + YangTextSchemaSourceSetBuilder.validate(yangResourceNameToContent) + and: 'the result contains 1 module of the correct name and revision' result.modules.size() == 1 def optionalModule = result.findModule('stores', Revision.of('2020-09-15')) optionalModule.isPresent() |