From ba35723f0d0022489074b8ac4b6c68d2fd4ecebf Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Tue, 19 Feb 2019 10:02:00 -0500 Subject: Add support for commit confirmed capability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I3608a6a62469d4b5dfc5fc69f610f9da186156c2 Issue-ID: CCSDK-790 Signed-off-by: Alexis de Talhouët --- .../netconf/executor/api/NetconfRpcService.kt | 22 ++++- .../netconf/executor/core/NetconfRpcServiceImpl.kt | 18 +++- .../netconf/executor/utils/NetconfMessageUtils.kt | 34 ++++++- .../netconf/executor/utils/RpcMessageUtilsTest.kt | 103 ++++++++++++++++++++- 4 files changed, 168 insertions(+), 9 deletions(-) (limited to 'ms') diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfRpcService.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfRpcService.kt index e2c9bf90..55085216 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfRpcService.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfRpcService.kt @@ -67,9 +67,29 @@ interface NetconfRpcService { /** * Commit * + * @param confirmed Perform a confirmed operation. If flag set to true, + * then it is expected to have a follow-up operation to confirm the request + * @param confirmTimeout Timeout period for confirmed commit, in seconds. + * @param persist Make the confirmed commit survive a session termination, and + * set a token on the ongoing confirmed commit. + * @param persistId Used to issue a follow-up confirmed commit or a confirming + * commit from any session, with the token from the previous operation. + * If unspecified, the confirm timeout defaults to 600 seconds. * @return Device response */ - fun commit(): DeviceResponse + fun commit(confirmed: Boolean = false, confirmTimeout: Int = 60, persist: String = "", + persistId: String = ""): DeviceResponse + + /** + * Cancels an ongoing confirmed commit. If the parameter is not given, + * the operation MUST be issued on the same session that issued + * the confirmed commit. + * + * @param persistId Cancels a persistent confirmed commit. The value MUST be equal + * to the value given in the parameter to the operation. + * If the value does not match, the operation fails with an "invalid-value" error. + */ + fun cancelCommit(persistId: String = ""): DeviceResponse /** * Unlock diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt index be835557..8d8e0ea4 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt @@ -101,12 +101,12 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ return output } - override fun commit(): DeviceResponse { + override fun commit(confirmed: Boolean, confirmTimeout: Int, persist: String, persistId: String): DeviceResponse { var output = DeviceResponse() val messageId = messageIdInteger.getAndIncrement().toString() log.info("$deviceInfo: commit: messageId($messageId)") try { - val messageContent = NetconfMessageUtils.commit(messageId) + val messageContent = NetconfMessageUtils.commit(messageId, confirmed, confirmTimeout, persist, persistId) output = asyncRpc(messageContent, messageId) } catch (e: Exception) { output.status = RpcStatus.FAILURE @@ -115,6 +115,20 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ return output } + override fun cancelCommit(persistId: String): DeviceResponse { + var output = DeviceResponse() + val messageId = messageIdInteger.getAndIncrement().toString() + log.info("$deviceInfo: cancelCommit: messageId($messageId)") + try { + val messageContent = NetconfMessageUtils.cancelCommit(messageId, persistId) + output = asyncRpc(messageContent, messageId) + } catch (e: Exception) { + output.status = RpcStatus.FAILURE + output.errorMessage = "$deviceInfo: failed in cancelCommit command $e.message" + } + return output + } + override fun discardConfig(): DeviceResponse { var output = DeviceResponse() val messageId = messageIdInteger.getAndIncrement().toString() diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtils.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtils.kt index 7e48912d..4de3860c 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtils.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtils.kt @@ -115,15 +115,45 @@ class NetconfMessageUtils { return doWrappedRpc(messageId, request.toString()) } - fun commit(messageId: String): String { - val request = StringBuilder() + fun commit(messageId: String, confirmed: Boolean, confirmTimeout: Int, persist: String, + persistId: String): String { + + if (!persist.isEmpty() && !persistId.isEmpty()) { + throw NetconfException("Can't proceed with both persist($persist) and " + + "persistId($persistId) specified. Only one should be specified.") + } + if (confirmed && !persistId.isEmpty()) { + throw NetconfException("Can't proceed with both confirmed flag and " + + "persistId($persistId) specified. Only one should be specified.") + } + val request = StringBuilder() request.append("").append(NEW_LINE) + if (confirmed) { + request.append("") + request.append("$confirmTimeout") + if (!persist.isEmpty()) { + request.append("$persist") + } + } + if (!persistId.isEmpty()) { + request.append("$persistId") + } request.append("").append(NEW_LINE) return doWrappedRpc(messageId, request.toString()) } + fun cancelCommit(messageId: String, persistId: String): String { + val request = StringBuilder() + request.append("").append(NEW_LINE) + if (!persistId.isEmpty()) { + request.append("$persistId") + } + request.append("").append(NEW_LINE) + + return doWrappedRpc(messageId, request.toString()) + } fun unlock(messageId: String, configType: String): String { val request = StringBuilder() diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt index 2cd2d109..d4c27b1c 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt @@ -18,6 +18,8 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils import org.junit.Assert import org.junit.Assert.assertTrue import org.junit.Test +import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.NetconfException +import kotlin.test.fail class RpcMessageUtilsTest { @@ -32,14 +34,14 @@ class RpcMessageUtilsTest { val configType = NetconfDatastore.CANDIDATE.datastore val filterContent = "Test-Filter-Content" - val result = NetconfMessageUtils.getConfig(messageId, configType, filterContent).replace("[\n\r\t]".toRegex(), "") + val result = + NetconfMessageUtils.getConfig(messageId, configType, filterContent).replace("[\n\r\t]".toRegex(), "") assertTrue(NetconfMessageUtils.validateRPCXML(result)) Assert.assertEquals(checkString, result) } - @Test fun editConfig() { val checkString = ("" @@ -51,7 +53,8 @@ class RpcMessageUtilsTest { val configType = NetconfDatastore.CANDIDATE.datastore val filterContent = "Test-Filter-Content" - val result = NetconfMessageUtils.getConfig(messageId, configType, filterContent).replace("[\n\r\t]".toRegex(), "") + val result = + NetconfMessageUtils.getConfig(messageId, configType, filterContent).replace("[\n\r\t]".toRegex(), "") assertTrue(NetconfMessageUtils.validateRPCXML(result)) Assert.assertEquals(checkString, result) @@ -72,6 +75,40 @@ class RpcMessageUtilsTest { Assert.assertEquals(checkString, result) } + @Test + fun cancelCommit() { + val checkString = + ("" + + "" + + "" + + "1234" + + "") + + val messageId = "Test-Message-ID" + + val cancelCommitPersistId = + NetconfMessageUtils.cancelCommit(messageId, "1234").replace("[\n\r\t]".toRegex(), "") + + assertTrue(NetconfMessageUtils.validateRPCXML(cancelCommitPersistId)) + Assert.assertEquals(checkString, cancelCommitPersistId) + } + + @Test + fun cancelCommitNoPersistId() { + val checkString = + ("" + + "" + + "" + + "") + + val messageId = "Test-Message-ID" + + val cancelCommitNoPersistId = NetconfMessageUtils.cancelCommit(messageId, "").replace("[\n\r\t]".toRegex(), "") + + assertTrue(NetconfMessageUtils.validateRPCXML(cancelCommitNoPersistId)) + Assert.assertEquals(checkString, cancelCommitNoPersistId) + } + @Test fun commit() { val checkString = ("" @@ -80,11 +117,69 @@ class RpcMessageUtilsTest { val messageId = "Test-Message-ID" - val result = NetconfMessageUtils.commit(messageId).replace("[\n\r\t]".toRegex(), "") + val commit = NetconfMessageUtils.commit(messageId, false, 0, "", "").replace("[\n\r\t]".toRegex(), "") + + val commitWithPersistButNotConfirmed = + NetconfMessageUtils.commit(messageId, false, 0, "1234", "").replace("[\n\r\t]".toRegex(), "") + + assertTrue(NetconfMessageUtils.validateRPCXML(commit)) + Assert.assertEquals(checkString, commit) + Assert.assertEquals(checkString, commitWithPersistButNotConfirmed) + + } + + @Test + fun commitPersistId() { + val checkString = + ("" + + "" + + "" + + "1234" + + "") + + val messageId = "Test-Message-ID" + + val result = NetconfMessageUtils.commit(messageId, false, 30, "", "1234").replace("[\n\r\t]".toRegex(), "") + assertTrue(NetconfMessageUtils.validateRPCXML(result)) + Assert.assertEquals(checkString, result) + + try { + NetconfMessageUtils.commit(messageId, true, 30, "", "1234").replace("[\n\r\t]".toRegex(), "") + } catch (e: NetconfException) { + Assert.assertEquals("Can't proceed with both confirmed flag and persistId(1234) specified. Only one should be specified.", + e.message) + return + } + + fail() + } + + @Test + fun commitPersist() { + val checkString = + ("" + + "" + + "" + + "" + + "30" + + "1234" + + "") + + val messageId = "Test-Message-ID" + + val result = NetconfMessageUtils.commit(messageId, true, 30, "1234", "").replace("[\n\r\t]".toRegex(), "") assertTrue(NetconfMessageUtils.validateRPCXML(result)) Assert.assertEquals(checkString, result) + try { + NetconfMessageUtils.commit(messageId, false, 30, "1234", "1234").replace("[\n\r\t]".toRegex(), "") + } catch (e: NetconfException) { + Assert.assertEquals("Can't proceed with both persist(1234) and persistId(1234) specified. Only one should be specified.", + e.message) + return + } + fail() } @Test -- cgit 1.2.3-korg