From c5e746a4d028b4e1c4ca93d0d7ce43ab34214344 Mon Sep 17 00:00:00 2001 From: Oleg Mitsura Date: Thu, 31 Oct 2019 17:01:28 -0400 Subject: netconf lib bugfixes: invoke_rpc + timeouts. Issue-ID: CCSDK-1886 Signed-off-by: Oleg Mitsura Change-Id: I0a33199d4b4cbd5e3355d1e7596d22bd7cdbd075 --- .../functions/netconf/executor/api/DeviceInfo.kt | 6 +- .../executor/core/NetconfDeviceCommunicator.kt | 2 +- .../netconf/executor/core/NetconfRpcServiceImpl.kt | 64 +++++++++++++++++----- .../netconf/executor/core/NetconfSessionImpl.kt | 1 + .../netconf/executor/utils/NetconfMessageUtils.kt | 12 +++- 5 files changed, 64 insertions(+), 21 deletions(-) (limited to 'ms/blueprintsprocessor/functions/netconf-executor/src/main') diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/DeviceInfo.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/DeviceInfo.kt index f5567b7a2..2395dddb8 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/DeviceInfo.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/DeviceInfo.kt @@ -29,11 +29,11 @@ class DeviceInfo { @get:JsonProperty("port-number") var port: Int = 0 @get:JsonProperty("connection-time-out") - var connectTimeout: Long = 5 + var connectTimeout: Long = 30 @get:JsonIgnore var source: String? = null @get:JsonIgnore - var replyTimeout: Int = 5 + var replyTimeout: Int = 20 @get:JsonIgnore var idleTimeout: Int = 99999 @@ -50,4 +50,4 @@ class DeviceInfo { override fun hashCode(): Int { return javaClass.hashCode() } -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicator.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicator.kt index bc91b7d92..06a71cad3 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicator.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicator.kt @@ -195,7 +195,7 @@ class NetconfDeviceCommunicator(private var inputStream: InputStream, } fun sendMessage(request: String, messageId: String): CompletableFuture { - log.info("$deviceInfo: Sending message: \n $request") + log.info("$deviceInfo: Sending message with message-id: $messageId: message: \n $request") val future = CompletableFuture() replies.put(messageId, future) val outputStream = OutputStreamWriter(out, StandardCharsets.UTF_8) diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt index 6a045e365..2e33b9aa2 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt @@ -38,15 +38,36 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ this.netconfSession = netconfSession } + /** + * accept a user-supplied RPC message WITH HEADER + * + * ..... + * ..... + * + * + * and replace the user-supplied message-id with the one that is passed. + * Used by NetconfRpcServiceImpl.invokeRpc to keep the message-id consistent + * with auto-incremented numbering scheme. + * @param rpc: Complete custom RPC call including the header + * @param updatedMessageID new message-id to substitute + * @return updated RPC message with message-id replaced. + */ + private fun replaceUserSuppliedNetconfMessageID(rpc: String, updatedMessageID: String): String { + return rpc.replaceFirst("message-id=\".+\"".toRegex(), "message-id=\"$updatedMessageID\"") + } + override fun invokeRpc(rpc: String): DeviceResponse { var output = DeviceResponse() - val messageId = messageIdInteger.getAndIncrement().toString() - log.info("$deviceInfo: invokeRpc: messageId($messageId)") + //Attempt to extract the message-id field from the for current session + //or #### + //as long as session ID is not the same as the current session. + + //Juniperhttps://www.juniper.net/documentation/en_US/junos/topics/task/operational/netconf-session-terminating.html + //will accept only with session-id if (force) { request.append("") } else { @@ -413,4 +421,4 @@ class NetconfMessageUtils { } } -} \ No newline at end of file +} -- cgit 1.2.3-korg