From c9275522f95f6cd94f28286f5e86f86dd451a19b Mon Sep 17 00:00:00 2001 From: emaclee Date: Wed, 23 Mar 2022 11:02:03 +0000 Subject: Add Start and Stop sessions on JAVA API Issue-ID: CPS-899 Signed-off-by: emaclee Change-Id: Idbeb922790824b1ca601d6d4798df45efa57d685 --- .../src/main/java/org/onap/cps/api/CpsDataService.java | 15 +++++++++++++++ .../java/org/onap/cps/api/impl/CpsDataServiceImpl.java | 11 +++++++++++ .../java/org/onap/cps/spi/CpsDataPersistenceService.java | 13 +++++++++++++ .../org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy | 16 ++++++++++++++++ 4 files changed, 55 insertions(+) (limited to 'cps-service') 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 cdd417bd8d..35caf95153 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 @@ -174,4 +174,19 @@ public interface CpsDataService { */ void updateNodeLeavesAndExistingDescendantLeaves(String dataspaceName, String anchorName, String parentNodeXpath, String dataNodeUpdatesAsJson, OffsetDateTime observedTimestamp); + + /** + * Starts a session which allows use of locks and batch interaction with the persistence service. + * + * @return Session ID string + */ + String startSession(); + + /** + * Close session. + * + * @param sessionId session ID + * + */ + void closeSession(String sessionId); } 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 aae355d507..643614f4fb 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 @@ -108,6 +108,17 @@ public class CpsDataServiceImpl implements CpsDataService { processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, parentNodeXpath, Operation.UPDATE); } + @Override + public String startSession() { + final String sessionId = cpsDataPersistenceService.startSession(); + return sessionId; + } + + @Override + public void closeSession(final String sessionId) { + cpsDataPersistenceService.closeSession(sessionId); + } + @Override public void replaceNodeTree(final String dataspaceName, final String anchorName, final String parentNodeXpath, final String jsonData, final OffsetDateTime observedTimestamp) { 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 fd658861c2..fdcf15bee6 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 @@ -148,4 +148,17 @@ public interface CpsDataPersistenceService { Collection queryDataNodes(String dataspaceName, String anchorName, String cpsPath, FetchDescendantsOption fetchDescendantsOption); + /** + * Starts a session which allows use of locks and batch interaction with the persistence service. + * + * @return Session ID string + */ + String startSession(); + + /** + * Close session. + * + * @param sessionId session ID + */ + void closeSession(String sessionId); } 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 785788be90..eb06199d1b 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 @@ -254,4 +254,20 @@ class CpsDataServiceImplSpec extends Specification { def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext() mockYangTextSchemaSourceSet.getSchemaContext() >> schemaContext } + + def 'start session'() { + when: 'start session method is called' + objectUnderTest.startSession() + then: 'the persistence service method to start session is invoked' + 1 * mockCpsDataPersistenceService.startSession() + } + + def 'close session'(){ + given: 'session Id from calling the start session method' + def sessionId = objectUnderTest.startSession() + when: 'close session method is called' + objectUnderTest.closeSession(sessionId) + then: 'the persistence service method to close session is invoked' + 1 * mockCpsDataPersistenceService.closeSession(sessionId) + } } -- cgit 1.2.3-korg