summaryrefslogtreecommitdiffstats
path: root/cps-service/src/main
diff options
context:
space:
mode:
authoremaclee <lee.anjella.macabuhay@est.tech>2022-04-04 15:38:26 +0100
committerLee Anjella Macabuhay <lee.anjella.macabuhay@est.tech>2022-04-27 15:56:11 +0000
commit7f227628678c660b0db3a2da43123d2b531018af (patch)
tree939eda8239de8c6580d1e23e89b09d78fee155a7 /cps-service/src/main
parentd07a5e3cfd74357c626d099dc5d5812ecd8e33ea (diff)
Add methods to Lock Anchor entity
Added separate integration and mock-based unit tests Issue-ID: CPS-898 Signed-off-by: emaclee <lee.anjella.macabuhay@est.tech> Change-Id: I14d1d1c41759ce028e2417fdd2df001280e19ab2
Diffstat (limited to 'cps-service/src/main')
-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
5 files changed, 126 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);
+ }
+}