summaryrefslogtreecommitdiffstats
path: root/cps-service
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsDataService.java22
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java12
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java14
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/exceptions/SessionManagerException.java48
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/exceptions/SessionTimeoutException.java31
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy17
6 files changed, 143 insertions, 1 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 fdcf15bee6..43cfffee70 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
* ================================================================================
@@ -161,4 +161,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)
+ }
}