aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap
diff options
context:
space:
mode:
authorOleg Mitsura <oleg.mitsura@amdocs.com>2019-04-10 09:58:21 -0400
committerOleg Mitsura <oleg.mitsura@amdocs.com>2019-04-10 09:59:50 -0400
commit8b9acafc674a3e9a833e1a1a78583fc78c922b2c (patch)
tree1a698882d86cd86bf950a678a35ec12b43596ca0 /ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap
parent5ef963fcebf2e97fc097837d3993ad0f66885568 (diff)
netconf-executor: Moving NetconfSessionListenerImpl out of NetconfSessionImpl, and adding test for it.
Issue-ID: CCSDK-1126 Change-Id: I8674c247e64efdf48faf35b8d21eae5eaed14d95 Signed-off-by: Oleg Mitsura <oleg.mitsura@amdocs.com>
Diffstat (limited to 'ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap')
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt50
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionListenerImpl.kt39
2 files changed, 75 insertions, 14 deletions
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt
index d0f4a1dfb..12eb43f45 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt
@@ -236,7 +236,7 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
}
private fun setupHandler() {
- val sessionListener: NetconfSessionListener = NetconfSessionListenerImpl()
+ val sessionListener: NetconfSessionListener = NetconfSessionListenerImpl(this)
streamHandler = NetconfDeviceCommunicator(channel.invertedOut, channel.invertedIn, deviceInfo,
sessionListener, replies)
@@ -262,19 +262,6 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
}
}
- inner class NetconfSessionListenerImpl : NetconfSessionListener {
- override fun accept(event: NetconfReceivedEvent) {
- val messageId = event.messageId
-
- when (event.type) {
- NetconfReceivedEvent.Type.DEVICE_UNREGISTERED -> disconnect()
- NetconfReceivedEvent.Type.DEVICE_ERROR -> errorReplies.add(event.messagePayload)
- NetconfReceivedEvent.Type.DEVICE_REPLY -> replies[messageId]?.complete(event.messagePayload)
- NetconfReceivedEvent.Type.SESSION_CLOSED -> disconnect()
- }
- }
- }
-
fun sessionstatus(state:String): Boolean{
return when (state){
"Close" -> channel.isClosed
@@ -282,4 +269,39 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
else -> false
}
}
+
+ internal fun setStreamHandler(streamHandler: NetconfDeviceCommunicator) {
+ this.streamHandler = streamHandler
+ }
+
+ /**
+ * Add an error reply
+ * Used by {@link NetconfSessionListenerImpl}
+ */
+ internal fun addDeviceErrorReply(errReply: String) {
+ println("addDeviceErrorReply (errReply: $errReply") //TODO : get rid of this.
+ errorReplies.add(errReply)
+ }
+
+ /**
+ * Add a reply from the device
+ * Used by {@link NetconfSessionListenerImpl}
+ */
+ internal fun addDeviceReply(messageId: String, replyMsg: String) {
+ println("addDeviceReply (messageId: $messageId replyMsg: $replyMsg") //TODO : get rid of this.
+ replies[messageId]?.complete(replyMsg)
+ }
+
+ /**
+ * Internal function for accessing replies for testing.
+ */
+ internal fun getReplies() = replies
+
+ /**
+ * internal function for accessing errorReplies for testing.
+ */
+ internal fun getErrorReplies() = errorReplies
+
+ internal fun clearErrorReplies() = errorReplies.clear()
+ internal fun clearReplies() = replies.clear()
} \ 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/NetconfSessionListenerImpl.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionListenerImpl.kt
new file mode 100644
index 000000000..c8b9c5543
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionListenerImpl.kt
@@ -0,0 +1,39 @@
+/*
+ * Copyright © 2019 Bell Canada
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.core
+
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfReceivedEvent
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfSessionListener
+
+/**
+ * Implementation of the NetconfSessionListener
+ * Encapsulates logic for type of message received and action that NetconfSessionImpl should take.
+ * TODO: Is there a better way to extract this out of NetconfSession, I'd like to use the NetconfSession as param,
+ * rather than NetconfSessionImpl, but at the same time, addDeviceReply/ErrorReply should not be part of the public
+ * interface....
+ */
+
+internal class NetconfSessionListenerImpl(private val session: NetconfSessionImpl) : NetconfSessionListener {
+ override fun accept(event: NetconfReceivedEvent) {
+ when (event.type) {
+ NetconfReceivedEvent.Type.DEVICE_UNREGISTERED -> session.disconnect()
+ NetconfReceivedEvent.Type.SESSION_CLOSED -> session.disconnect()
+ NetconfReceivedEvent.Type.DEVICE_ERROR -> session.addDeviceErrorReply(event.messagePayload)
+ NetconfReceivedEvent.Type.DEVICE_REPLY -> session.addDeviceReply(event.messageId, event.messagePayload)
+ }
+ }
+} \ No newline at end of file