aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/netconf-executor/src/main
diff options
context:
space:
mode:
authorSingal, Kapil (ks220y) <ks220y@att.com>2019-11-22 18:06:08 -0500
committerKAPIL SINGAL <ks220y@att.com>2019-11-26 21:32:38 +0000
commit341db21b2ac0a14a1ed2b8bf7930914dda054bfe (patch)
tree113bba965b06cfe3a8af3a0a527d1a41c9faf0f9 /ms/blueprintsprocessor/functions/netconf-executor/src/main
parentd274e5fc552cf9ae25500f504f0434981cf3accf (diff)
Formatting Code base with ktlint
No Business logic change, just the code format. Competible with IntelliJ: https://github.com/pinterest/ktlint#option-3 To format run: mvn process-sources -P format Issue-ID: CCSDK-1947 Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com> Change-Id: Ic9e9209fb7023d77f434693ad5a01229f8d09331
Diffstat (limited to 'ms/blueprintsprocessor/functions/netconf-executor/src/main')
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt16
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/JsonParserService.kt4
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt60
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfDevice.kt2
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfExecutorConfiguration.kt2
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfExecutorExtensions.kt11
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/DeviceInfo.kt3
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfException.kt3
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfMessage.kt23
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfRpcService.kt17
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfSession.kt3
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicator.kt88
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt17
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt77
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionListenerImpl.kt3
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtils.kt83
16 files changed, 263 insertions, 149 deletions
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt
index cdee3903b..1262e8500 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt
@@ -31,8 +31,8 @@ import org.springframework.stereotype.Component
@Component("component-netconf-executor")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-open class ComponentNetconfExecutor(private var componentFunctionScriptingService: ComponentFunctionScriptingService)
- : AbstractComponentFunction() {
+open class ComponentNetconfExecutor(private var componentFunctionScriptingService: ComponentFunctionScriptingService) :
+ AbstractComponentFunction() {
companion object {
const val SCRIPT_TYPE = "script-type"
@@ -56,9 +56,10 @@ open class ComponentNetconfExecutor(private var componentFunctionScriptingServic
}
scriptComponent = componentFunctionScriptingService
- .scriptInstance<AbstractScriptComponentFunction>(this, scriptType,
- scriptClassReference, scriptDependencies)
-
+ .scriptInstance<AbstractScriptComponentFunction>(
+ this, scriptType,
+ scriptClassReference, scriptDependencies
+ )
checkNotNull(scriptComponent) { "failed to get netconf script component" }
@@ -68,7 +69,6 @@ open class ComponentNetconfExecutor(private var componentFunctionScriptingServic
override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
bluePrintRuntimeService.getBluePrintError()
- .addError("Failed in ComponentNetconfExecutor : ${runtimeException.message}")
-
+ .addError("Failed in ComponentNetconfExecutor : ${runtimeException.message}")
}
-} \ 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/JsonParserService.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/JsonParserService.kt
index 73c82acb2..abaa7fed1 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/JsonParserService.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/JsonParserService.kt
@@ -19,6 +19,4 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor
import org.springframework.stereotype.Service
@Service("json-parser-service")
-class JsonParserService {
-
-} \ No newline at end of file
+class JsonParserService
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt
index 5e0b4a117..58e6151f0 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt
@@ -25,40 +25,62 @@ import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptC
@Deprecated("Methods defined as extension function of AbstractComponentFunction")
abstract class NetconfComponentFunction : AbstractScriptComponentFunction() {
- @Deprecated(" Use resourceResolutionService method directly",
- replaceWith = ReplaceWith("resourceResolutionService()",
- "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.resourceResolutionService"))
+ @Deprecated(
+ " Use resourceResolutionService method directly",
+ replaceWith = ReplaceWith(
+ "resourceResolutionService()",
+ "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.resourceResolutionService"
+ )
+ )
open fun resourceResolutionService(): ResourceResolutionService =
- functionDependencyInstanceAsType(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
+ functionDependencyInstanceAsType(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
// Called from python script
- @Deprecated(" Use netconfDeviceInfo method directly",
- replaceWith = ReplaceWith("netconfDeviceInfo(requirementName)",
- "org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.netconfDeviceInfo"))
+ @Deprecated(
+ " Use netconfDeviceInfo method directly",
+ replaceWith = ReplaceWith(
+ "netconfDeviceInfo(requirementName)",
+ "org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.netconfDeviceInfo"
+ )
+ )
fun initializeNetconfConnection(requirementName: String): NetconfDevice {
val deviceInfo = netconfDeviceInfo(requirementName)
return NetconfDevice(deviceInfo)
}
- @Deprecated(" Use artifactContent method directly",
- replaceWith = ReplaceWith("artifactContent(artifactName)",
- "org.onap.ccsdk.cds.blueprintsprocessor.services.execution.artifactContent"))
+ @Deprecated(
+ " Use artifactContent method directly",
+ replaceWith = ReplaceWith(
+ "artifactContent(artifactName)",
+ "org.onap.ccsdk.cds.blueprintsprocessor.services.execution.artifactContent"
+ )
+ )
fun generateMessage(artifactName: String): String {
return bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactName)
}
- @Deprecated(" Use storedContentFromResolvedArtifact method directly",
- replaceWith = ReplaceWith("storedContentFromResolvedArtifact(resolutionKey, artifactName)",
- "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.storedContentFromResolvedArtifact"))
+ @Deprecated(
+ " Use storedContentFromResolvedArtifact method directly",
+ replaceWith = ReplaceWith(
+ "storedContentFromResolvedArtifact(resolutionKey, artifactName)",
+ "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.storedContentFromResolvedArtifact"
+ )
+ )
fun resolveFromDatabase(resolutionKey: String, artifactName: String): String = runBlocking {
resourceResolutionService().resolveFromDatabase(bluePrintRuntimeService, artifactName, resolutionKey)
}
- @Deprecated(" Use contentFromResolvedArtifact method directly",
- replaceWith = ReplaceWith("resolveAndGenerateMessage(artifactPrefix)",
- "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.resolveAndGenerateMessage"))
+ @Deprecated(
+ " Use contentFromResolvedArtifact method directly",
+ replaceWith = ReplaceWith(
+ "resolveAndGenerateMessage(artifactPrefix)",
+ "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.resolveAndGenerateMessage"
+ )
+ )
fun resolveAndGenerateMessage(artifactPrefix: String): String = runBlocking {
- resourceResolutionService().resolveResources(bluePrintRuntimeService, nodeTemplateName,
- artifactPrefix, mapOf())
+ resourceResolutionService().resolveResources(
+ bluePrintRuntimeService, nodeTemplateName,
+ artifactPrefix, mapOf()
+ )
}
-} \ 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/NetconfDevice.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfDevice.kt
index 61090f485..a69e4d9d6 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfDevice.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfDevice.kt
@@ -28,4 +28,4 @@ data class NetconfDevice(val deviceInfo: DeviceInfo) {
netconfSession = NetconfSessionImpl(deviceInfo, netconfRpcService)
netconfRpcService.setNetconfSession(netconfSession)
}
-} \ 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/NetconfExecutorConfiguration.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfExecutorConfiguration.kt
index 214969346..f9aa38f8c 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfExecutorConfiguration.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfExecutorConfiguration.kt
@@ -25,4 +25,4 @@ import org.springframework.context.annotation.Configuration
@ComponentScan
@EnableConfigurationProperties
@ConditionalOnProperty(name = ["blueprintsprocessor.netconfExecutor.enabled"], havingValue = "true")
-open class NetconfExecutorConfiguration \ No newline at end of file
+open class NetconfExecutorConfiguration
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfExecutorExtensions.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfExecutorExtensions.kt
index 510621b2e..f52cb0a62 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfExecutorExtensions.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfExecutorExtensions.kt
@@ -29,8 +29,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
* Register the Netconf module exposed dependency
*/
fun BluePrintDependencyService.netconfClientService(): ResourceResolutionService =
- instance(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
-
+ instance(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
fun AbstractComponentFunction.netconfDevice(requirementName: String): NetconfDevice {
val deviceInfo = netconfDeviceInfo(requirementName)
@@ -43,8 +42,10 @@ fun AbstractComponentFunction.netconfDeviceInfo(requirementName: String): Device
val requirement = blueprintContext.nodeTemplateRequirement(nodeTemplateName, requirementName)
- val capabilityProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties(requirement
- .node!!, requirement.capability!!)
+ val capabilityProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties(
+ requirement
+ .node!!, requirement.capability!!
+ )
return netconfDeviceInfo(capabilityProperties)
}
@@ -55,4 +56,4 @@ private fun AbstractComponentFunction.netconfDeviceInfo(capabilityProperty: Muta
/**
* Blocking Methods called from Jython Scripts
- */ \ 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/api/DeviceInfo.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/DeviceInfo.kt
index 2395dddb8..2f10bb56b 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
@@ -40,7 +40,8 @@ class DeviceInfo {
override fun toString(): String {
return "$ipAddress:$port"
}
- //TODO: should this be a data class instead? Is anything using the JSON serdes?
+
+ // TODO: should this be a data class instead? Is anything using the JSON serdes?
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfException.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfException.kt
index 7e6a88b48..62a6ac3e3 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfException.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfException.kt
@@ -20,5 +20,4 @@ class NetconfException : Exception {
constructor(cause: Throwable) : super(cause)
constructor(message: String) : super(message)
constructor(message: String, cause: Throwable) : super(message, cause)
-
-} \ 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/api/NetconfMessage.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfMessage.kt
index 1d5f515d0..744476c2a 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfMessage.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfMessage.kt
@@ -18,17 +18,18 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api
import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.RpcStatus
-data class DeviceResponse(var status: String? = null,
- var errorMessage: String? = null,
- var responseMessage: String? = null,
- var requestMessage: String? = null) {
+data class DeviceResponse(
+ var status: String? = null,
+ var errorMessage: String? = null,
+ var responseMessage: String? = null,
+ var requestMessage: String? = null
+) {
fun isSuccess(): Boolean {
return this.status == RpcStatus.SUCCESS && this.errorMessage.isNullOrEmpty()
}
}
-
/**
* Creates an event of a given type and for the specified subject and the current time.
*
@@ -37,10 +38,12 @@ data class DeviceResponse(var status: String? = null,
* @param messageId id of the message related to the event
* @param deviceInfo device of event
*/
-class NetconfReceivedEvent(val type: Type,
- val messagePayload: String = "",
- val messageId: String = "",
- val deviceInfo: DeviceInfo) {
+class NetconfReceivedEvent(
+ val type: Type,
+ val messagePayload: String = "",
+ val messageId: String = "",
+ val deviceInfo: DeviceInfo
+) {
enum class Type {
DEVICE_REPLY,
@@ -48,4 +51,4 @@ class NetconfReceivedEvent(val type: Type,
DEVICE_ERROR,
SESSION_CLOSED
}
-} \ 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/api/NetconfRpcService.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfRpcService.kt
index ecb6267f5..ea93ebd40 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfRpcService.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfRpcService.kt
@@ -54,8 +54,11 @@ interface NetconfRpcService {
* @param editDefaultOperation, default set to none. Valid values: merge, replace, create, delete, none
* @return Device response
*/
- fun editConfig(messageContent: String, configTarget: String = NetconfDatastore.CANDIDATE.datastore,
- editDefaultOperation: String = ModifyAction.NONE.action): DeviceResponse
+ fun editConfig(
+ messageContent: String,
+ configTarget: String = NetconfDatastore.CANDIDATE.datastore,
+ editDefaultOperation: String = ModifyAction.NONE.action
+ ): DeviceResponse
/**
* Invoke custom RPC as provided as input.
@@ -96,8 +99,12 @@ interface NetconfRpcService {
* If unspecified, the confirm timeout defaults to 600 seconds.
* @return Device response
*/
- fun commit(confirmed: Boolean = false, confirmTimeout: Int = 60, persist: String = "",
- persistId: String = ""): DeviceResponse
+ fun commit(
+ confirmed: Boolean = false,
+ confirmTimeout: Int = 60,
+ persist: String = "",
+ persistId: String = ""
+ ): DeviceResponse
/**
* Cancels an ongoing confirmed commit. If the <persist-id> parameter is not given,
@@ -148,4 +155,4 @@ interface NetconfRpcService {
* @return Device response
*/
fun get(filter: String): DeviceResponse
-} \ 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/api/NetconfSession.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfSession.kt
index 0272d1a19..ceeb444f7 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfSession.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfSession.kt
@@ -25,7 +25,6 @@ interface NetconfSession {
*/
fun connect()
-
/**
* Disconnect netconf session
*/
@@ -83,4 +82,4 @@ interface NetconfSession {
* @return Network capabilities as strings in a Set.
*/
fun getDeviceCapabilitiesSet(): Set<String>
-} \ 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 06a71cad3..8f8fc1463 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
@@ -22,15 +22,26 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.Net
import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.NetconfMessageUtils
import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.RpcMessageUtils
import org.slf4j.LoggerFactory
-import java.io.*
-import java.nio.charset.*
-import java.util.concurrent.*
+import java.io.BufferedReader
+import java.io.IOException
+import java.io.InputStream
+import java.io.InputStreamReader
+import java.io.OutputStream
+import java.io.OutputStreamWriter
+import java.nio.charset.StandardCharsets
+import java.util.concurrent.CancellationException
+import java.util.concurrent.CompletableFuture
+import java.util.concurrent.ExecutionException
+import java.util.concurrent.TimeUnit
+import java.util.concurrent.TimeoutException
-class NetconfDeviceCommunicator(private var inputStream: InputStream,
- private var out: OutputStream,
- private val deviceInfo: DeviceInfo,
- private val sessionListener: NetconfSessionListener,
- private var replies: MutableMap<String, CompletableFuture<String>>) : Thread() {
+class NetconfDeviceCommunicator(
+ private var inputStream: InputStream,
+ private var out: OutputStream,
+ private val deviceInfo: DeviceInfo,
+ private val sessionListener: NetconfSessionListener,
+ private var replies: MutableMap<String, CompletableFuture<String>>
+) : Thread() {
private val log = LoggerFactory.getLogger(NetconfDeviceCommunicator::class.java)
private var state = NetconfMessageState.NO_MATCHING_PATTERN
@@ -62,9 +73,12 @@ class NetconfDeviceCommunicator(private var inputStream: InputStream,
if (deviceReply == RpcMessageUtils.END_PATTERN) {
socketClosed = true
bufferReader.close()
- sessionListener.accept(NetconfReceivedEvent(
- NetconfReceivedEvent.Type.DEVICE_UNREGISTERED,
- deviceInfo = deviceInfo))
+ sessionListener.accept(
+ NetconfReceivedEvent(
+ NetconfReceivedEvent.Type.DEVICE_UNREGISTERED,
+ deviceInfo = deviceInfo
+ )
+ )
} else {
deviceReply = deviceReply.replace(RpcMessageUtils.END_PATTERN, "")
receivedMessage(deviceReply)
@@ -75,9 +89,12 @@ class NetconfDeviceCommunicator(private var inputStream: InputStream,
if (!NetconfMessageUtils.validateChunkedFraming(deviceReply)) {
log.debug("$deviceInfo: Received badly framed message $deviceReply")
socketClosed = true
- sessionListener.accept(NetconfReceivedEvent(
- NetconfReceivedEvent.Type.DEVICE_ERROR,
- deviceInfo = deviceInfo))
+ sessionListener.accept(
+ NetconfReceivedEvent(
+ NetconfReceivedEvent.Type.DEVICE_ERROR,
+ deviceInfo = deviceInfo
+ )
+ )
} else {
deviceReply = deviceReply.replace(RpcMessageUtils.MSGLEN_REGEX_PATTERN.toRegex(), "")
deviceReply = deviceReply.replace(NetconfMessageUtils.CHUNKED_END_REGEX_PATTERN.toRegex(), "")
@@ -86,20 +103,22 @@ class NetconfDeviceCommunicator(private var inputStream: InputStream,
}
}
}
-
} catch (e: IOException) {
log.warn("$deviceInfo: Fail while reading from channel", e)
- sessionListener.accept(NetconfReceivedEvent(
- NetconfReceivedEvent.Type.DEVICE_ERROR,
- deviceInfo = deviceInfo))
+ sessionListener.accept(
+ NetconfReceivedEvent(
+ NetconfReceivedEvent.Type.DEVICE_ERROR,
+ deviceInfo = deviceInfo
+ )
+ )
}
-
}
/**
* State machine for the Netconf message parser
*/
internal enum class NetconfMessageState {
+
NO_MATCHING_PATTERN {
override fun evaluateChar(c: Char): NetconfMessageState {
return when (c) {
@@ -207,25 +226,29 @@ class NetconfDeviceCommunicator(private var inputStream: InputStream,
log.error("$deviceInfo: Failed to send message : \n $request", e)
future.completeExceptionally(e)
}
-
}
return future
}
private fun receivedMessage(deviceReply: String) {
- if (deviceReply.contains(RpcMessageUtils.RPC_REPLY) || deviceReply.contains(RpcMessageUtils.RPC_ERROR)
- || deviceReply.contains(RpcMessageUtils.HELLO)) {
- log.info("$deviceInfo: Received message with messageId: {} \n $deviceReply",
- NetconfMessageUtils.getMsgId(deviceReply))
-
+ if (deviceReply.contains(RpcMessageUtils.RPC_REPLY) || deviceReply.contains(RpcMessageUtils.RPC_ERROR) ||
+ deviceReply.contains(RpcMessageUtils.HELLO)
+ ) {
+ log.info(
+ "$deviceInfo: Received message with messageId: {} \n $deviceReply",
+ NetconfMessageUtils.getMsgId(deviceReply)
+ )
} else {
log.error("$deviceInfo: Invalid message received: \n $deviceReply")
}
- sessionListener.accept(NetconfReceivedEvent(
- NetconfReceivedEvent.Type.DEVICE_REPLY,
- deviceReply,
- NetconfMessageUtils.getMsgId(deviceReply),
- deviceInfo))
+ sessionListener.accept(
+ NetconfReceivedEvent(
+ NetconfReceivedEvent.Type.DEVICE_REPLY,
+ deviceReply,
+ NetconfMessageUtils.getMsgId(deviceReply),
+ deviceInfo
+ )
+ )
}
/**
@@ -241,7 +264,10 @@ class NetconfDeviceCommunicator(private var inputStream: InputStream,
* @throws TimeoutException if the wait timed outStream
*/
internal fun getFutureFromSendMessage(
- fut: CompletableFuture<String>, timeout: Long, timeUnit: TimeUnit): String {
+ fut: CompletableFuture<String>,
+ timeout: Long,
+ timeUnit: TimeUnit
+ ): String {
return fut.get(timeout, timeUnit)
}
}
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 2e33b9aa2..b9fab06b1 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
@@ -17,7 +17,11 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.core
-import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.*
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.DeviceResponse
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfException
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfRpcService
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfSession
import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.NetconfMessageUtils
import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.RpcStatus
import org.slf4j.LoggerFactory
@@ -58,7 +62,7 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ
override fun invokeRpc(rpc: String): DeviceResponse {
var output = DeviceResponse()
- //Attempt to extract the message-id field from the <rpc call
+ // Attempt to extract the message-id field from the <rpc call
val updatedMessageId = messageIdInteger.getAndIncrement().toString()
val origMessageId = NetconfMessageUtils.getMsgId(rpc)
log.info("$deviceInfo: invokeRpc: updating rpc original message-id:($origMessageId) to messageId($updatedMessageId)")
@@ -197,8 +201,11 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ
return output
}
- override fun editConfig(messageContent: String, configTarget: String,
- editDefaultOperation: String): DeviceResponse {
+ override fun editConfig(
+ messageContent: String,
+ configTarget: String,
+ editDefaultOperation: String
+ ): DeviceResponse {
var response = DeviceResponse()
val messageId = messageIdInteger.getAndIncrement().toString()
log.info("$deviceInfo: editConfig: messageId($messageId)")
@@ -252,7 +259,7 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ
response.requestMessage = request
val rpcResponse = netconfSession.asyncRpc(request, messageId).get(responseTimeout.toLong(), TimeUnit.SECONDS)
- //TODO catch TimeoutException and ExecutionException
+ // TODO catch TimeoutException and ExecutionException
if (!NetconfMessageUtils.checkReply(rpcResponse)) {
log.error("RPC response didn't pass validation... $rpcResponse")
throw NetconfException(rpcResponse)
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 6be93179f..3d3eee8f0 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
@@ -22,14 +22,22 @@ import org.apache.sshd.client.SshClient
import org.apache.sshd.client.channel.ClientChannel
import org.apache.sshd.client.session.ClientSession
import org.apache.sshd.common.FactoryManager
-import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.*
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfException
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfRpcService
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfSession
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfSessionListener
import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.NetconfMessageUtils
import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.RpcMessageUtils
import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.RpcStatus
import org.slf4j.LoggerFactory
import java.io.IOException
-import java.util.*
-import java.util.concurrent.*
+import java.util.Collections
+import java.util.concurrent.CompletableFuture
+import java.util.concurrent.ConcurrentHashMap
+import java.util.concurrent.ExecutionException
+import java.util.concurrent.TimeUnit
+import java.util.concurrent.TimeoutException
class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcService: NetconfRpcService) :
NetconfSession {
@@ -55,8 +63,10 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
override fun connect() {
try {
- log.info("$deviceInfo: Connecting to Netconf Device with timeouts C:${deviceInfo.connectTimeout}, " +
- "R:${deviceInfo.replyTimeout}, I:${deviceInfo.idleTimeout}")
+ log.info(
+ "$deviceInfo: Connecting to Netconf Device with timeouts C:${deviceInfo.connectTimeout}, " +
+ "R:${deviceInfo.replyTimeout}, I:${deviceInfo.idleTimeout}"
+ )
startConnection()
log.info("$deviceInfo: Connected to Netconf Device")
} catch (e: NetconfException) {
@@ -67,13 +77,14 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
override fun disconnect() {
var retryNum = 3
- while(rpcService.closeSession(false).status
- .equals(RpcStatus.FAILURE, true) &&retryNum>0) {
+ while (rpcService.closeSession(false).status
+ .equals(RpcStatus.FAILURE, true) && retryNum > 0
+ ) {
log.error("disconnect: graceful disconnect failed, retrying $retryNum times...")
- retryNum--;
+ retryNum--
}
- //if we can't close the session, try to force terminate.
- if(retryNum == 0) {
+ // if we can't close the session, try to force terminate.
+ if (retryNum == 0) {
log.error("disconnect: trying to force-terminate the session.")
rpcService.closeSession(true)
}
@@ -95,13 +106,17 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
checkAndReestablish()
try {
- return streamHandler.getFutureFromSendMessage(streamHandler.sendMessage(formattedRequest, messageId),
- replyTimeout.toLong(), TimeUnit.SECONDS)
+ return streamHandler.getFutureFromSendMessage(
+ streamHandler.sendMessage(formattedRequest, messageId),
+ replyTimeout.toLong(), TimeUnit.SECONDS
+ )
} catch (e: InterruptedException) {
throw NetconfException("$deviceInfo: Interrupted while waiting for reply for request: $formattedRequest", e)
} catch (e: TimeoutException) {
- throw NetconfException("$deviceInfo: Timed out while waiting for reply for request $formattedRequest after $replyTimeout sec.",
- e)
+ throw NetconfException(
+ "$deviceInfo: Timed out while waiting for reply for request $formattedRequest after $replyTimeout sec.",
+ e
+ )
} catch (e: ExecutionException) {
log.warn("$deviceInfo: Closing session($sessionId) due to unexpected Error", e)
try {
@@ -179,10 +194,9 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
} catch (e: Exception) {
throw NetconfException("$deviceInfo: Failed to establish SSH session", e)
}
-
}
- //Needed to unit test connect method interacting with client.start in startClient() below
+ // Needed to unit test connect method interacting with client.start in startClient() below
private fun setupNewSSHClient() {
client = SshClient.setUpDefaultClient()
}
@@ -210,8 +224,12 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
private fun authSession() {
session.addPasswordIdentity(deviceInfo.password)
session.auth().verify(connectionTimeout, TimeUnit.SECONDS)
- val event = session.waitFor(ImmutableSet.of(ClientSession.ClientSessionEvent.WAIT_AUTH,
- ClientSession.ClientSessionEvent.CLOSED, ClientSession.ClientSessionEvent.AUTHED), 0)
+ val event = session.waitFor(
+ ImmutableSet.of(
+ ClientSession.ClientSessionEvent.WAIT_AUTH,
+ ClientSession.ClientSessionEvent.CLOSED, ClientSession.ClientSessionEvent.AUTHED
+ ), 0
+ )
if (!event.contains(ClientSession.ClientSessionEvent.AUTHED)) {
throw NetconfException("$deviceInfo: Failed to authenticate session.")
}
@@ -233,8 +251,10 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
private fun setupHandler() {
val sessionListener: NetconfSessionListener = NetconfSessionListenerImpl(this)
- streamHandler = NetconfDeviceCommunicator(channel.invertedOut, channel.invertedIn, deviceInfo,
- sessionListener, replies)
+ streamHandler = NetconfDeviceCommunicator(
+ channel.invertedOut, channel.invertedIn, deviceInfo,
+ sessionListener, replies
+ )
exchangeHelloMessage()
}
@@ -254,7 +274,7 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
}
val capabilityMatcher = NetconfMessageUtils.CAPABILITY_REGEX_PATTERN.matcher(serverHelloResponse)
- while (capabilityMatcher.find()) { //TODO: refactor to add unit test easily for device capability accumulation.
+ while (capabilityMatcher.find()) { // TODO: refactor to add unit test easily for device capability accumulation.
deviceCapabilities.add(capabilityMatcher.group(1))
}
}
@@ -300,9 +320,18 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
* internal function for accessing errorReplies for testing.
*/
internal fun getErrorReplies() = errorReplies
+
internal fun clearErrorReplies() = errorReplies.clear()
internal fun clearReplies() = replies.clear()
- internal fun setClient(client: SshClient) { this.client = client }
- internal fun setSession(session: ClientSession) { this.session = session }
- internal fun setChannel(channel: ClientChannel) { this.channel = channel }
+ internal fun setClient(client: SshClient) {
+ this.client = client
+ }
+
+ internal fun setSession(session: ClientSession) {
+ this.session = session
+ }
+
+ internal fun setChannel(channel: ClientChannel) {
+ this.channel = channel
+ }
}
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
index c8b9c5543..e27b51d16 100644
--- 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
@@ -28,6 +28,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.Net
*/
internal class NetconfSessionListenerImpl(private val session: NetconfSessionImpl) : NetconfSessionListener {
+
override fun accept(event: NetconfReceivedEvent) {
when (event.type) {
NetconfReceivedEvent.Type.DEVICE_UNREGISTERED -> session.disconnect()
@@ -36,4 +37,4 @@ internal class NetconfSessionListenerImpl(private val session: NetconfSessionImp
NetconfReceivedEvent.Type.DEVICE_REPLY -> session.addDeviceReply(event.messageId, event.messagePayload)
}
}
-} \ 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/utils/NetconfMessageUtils.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtils.kt
index 34816b79b..232dca621 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtils.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtils.kt
@@ -28,7 +28,6 @@ import javax.xml.XMLConstants
import javax.xml.parsers.DocumentBuilderFactory
import kotlin.text.Charsets.UTF_8
-
class NetconfMessageUtils {
companion object {
@@ -91,8 +90,12 @@ class NetconfMessageUtils {
return rpc.toString()
}
- fun editConfig(messageId: String, configType: String, defaultOperation: String?,
- newConfiguration: String): String {
+ fun editConfig(
+ messageId: String,
+ configType: String,
+ defaultOperation: String?,
+ newConfiguration: String
+ ): String {
val request = StringBuilder()
request.append("<edit-config>").append(NEW_LINE)
request.append(RpcMessageUtils.TARGET_OPEN).append(NEW_LINE)
@@ -127,16 +130,25 @@ class NetconfMessageUtils {
return doWrappedRpc(messageId, request.toString())
}
- fun commit(messageId: String, confirmed: Boolean, confirmTimeout: Int, persist: String,
- persistId: String): String {
+ fun commit(
+ messageId: String,
+ confirmed: Boolean,
+ confirmTimeout: Int,
+ persist: String,
+ persistId: String
+ ): String {
if (!persist.isEmpty() && !persistId.isEmpty()) {
- throw NetconfException("Can't proceed <commit> with both persist($persist) and " +
- "persistId($persistId) specified. Only one should be specified.")
+ throw NetconfException(
+ "Can't proceed <commit> with both persist($persist) and " +
+ "persistId($persistId) specified. Only one should be specified."
+ )
}
if (confirmed && !persistId.isEmpty()) {
- throw NetconfException("Can't proceed <commit> with both confirmed flag and " +
- "persistId($persistId) specified. Only one should be specified.")
+ throw NetconfException(
+ "Can't proceed <commit> with both confirmed flag and " +
+ "persistId($persistId) specified. Only one should be specified."
+ )
}
val request = StringBuilder()
@@ -221,15 +233,15 @@ class NetconfMessageUtils {
fun closeSession(messageId: String, force: Boolean): String {
val request = StringBuilder()
- //TODO: kill-session without session-id is a cisco-only variant.
- //will fail on JUNIPER device.
- //netconf RFC for kill-session requires session-id
- //Cisco can accept <kill-session/> for current session
- //or <kill-session><session-id>####</session-id></kill-session>
- //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
+ // TODO: kill-session without session-id is a cisco-only variant.
+ // will fail on JUNIPER device.
+ // netconf RFC for kill-session requires session-id
+ // Cisco can accept <kill-session/> for current session
+ // or <kill-session><session-id>####</session-id></kill-session>
+ // 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("<kill-session/>")
} else {
@@ -254,7 +266,6 @@ class NetconfMessageUtils {
} catch (e: Exception) {
return false
}
-
}
fun getMsgId(message: String): String {
@@ -355,8 +366,8 @@ class NetconfMessageUtils {
if (!message.startsWith(RpcMessageUtils.NEW_LINE + RpcMessageUtils.HASH)) {
// chunk encode message
message =
- (RpcMessageUtils.NEW_LINE + RpcMessageUtils.HASH + message.toByteArray(UTF_8).size + RpcMessageUtils.NEW_LINE + message + RpcMessageUtils.NEW_LINE + RpcMessageUtils.HASH + RpcMessageUtils.HASH
- + RpcMessageUtils.NEW_LINE)
+ (RpcMessageUtils.NEW_LINE + RpcMessageUtils.HASH + message.toByteArray(UTF_8).size + RpcMessageUtils.NEW_LINE + message + RpcMessageUtils.NEW_LINE + RpcMessageUtils.HASH + RpcMessageUtils.HASH +
+ RpcMessageUtils.NEW_LINE)
}
return message
}
@@ -373,7 +384,8 @@ class NetconfMessageUtils {
if (request.startsWith(RpcMessageUtils.NEW_LINE + RpcMessageUtils.HASH)) {
request =
request.split("<".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[0] + RpcMessageUtils.XML_HEADER + request.substring(
- request.split("<".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[0].length)
+ request.split("<".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[0].length
+ )
} else {
request = RpcMessageUtils.XML_HEADER + "\n" + request
}
@@ -385,12 +397,18 @@ class NetconfMessageUtils {
var request = request
if (request.contains(RpcMessageUtils.MESSAGE_ID_STRING)) {
request =
- request.replaceFirst((RpcMessageUtils.MESSAGE_ID_STRING + RpcMessageUtils.EQUAL + RpcMessageUtils.NUMBER_BETWEEN_QUOTES_MATCHER).toRegex(),
- RpcMessageUtils.MESSAGE_ID_STRING + RpcMessageUtils.EQUAL + RpcMessageUtils.QUOTE + messageId + RpcMessageUtils.QUOTE)
+ request.replaceFirst(
+ (RpcMessageUtils.MESSAGE_ID_STRING + RpcMessageUtils.EQUAL + RpcMessageUtils.NUMBER_BETWEEN_QUOTES_MATCHER).toRegex(),
+ RpcMessageUtils.MESSAGE_ID_STRING + RpcMessageUtils.EQUAL + RpcMessageUtils.QUOTE + messageId + RpcMessageUtils.QUOTE
+ )
} else if (!request.contains(RpcMessageUtils.MESSAGE_ID_STRING) && !request.contains(
- RpcMessageUtils.HELLO)) {
- request = request.replaceFirst(RpcMessageUtils.END_OF_RPC_OPEN_TAG.toRegex(),
- RpcMessageUtils.QUOTE_SPACE + RpcMessageUtils.MESSAGE_ID_STRING + RpcMessageUtils.EQUAL + RpcMessageUtils.QUOTE + messageId + RpcMessageUtils.QUOTE + ">")
+ RpcMessageUtils.HELLO
+ )
+ ) {
+ request = request.replaceFirst(
+ RpcMessageUtils.END_OF_RPC_OPEN_TAG.toRegex(),
+ RpcMessageUtils.QUOTE_SPACE + RpcMessageUtils.MESSAGE_ID_STRING + RpcMessageUtils.EQUAL + RpcMessageUtils.QUOTE + messageId + RpcMessageUtils.QUOTE + ">"
+ )
}
return updateRequestLength(request)
}
@@ -398,12 +416,16 @@ class NetconfMessageUtils {
fun updateRequestLength(request: String): String {
if (request.contains(NEW_LINE + RpcMessageUtils.HASH + RpcMessageUtils.HASH + NEW_LINE)) {
val oldLen =
- Integer.parseInt(request.split(RpcMessageUtils.HASH.toRegex()).dropLastWhile({ it.isEmpty() }).toTypedArray()[1].split(
- NEW_LINE.toRegex()).dropLastWhile({ it.isEmpty() }).toTypedArray()[0])
+ Integer.parseInt(
+ request.split(RpcMessageUtils.HASH.toRegex()).dropLastWhile({ it.isEmpty() }).toTypedArray()[1].split(
+ NEW_LINE.toRegex()
+ ).dropLastWhile({ it.isEmpty() }).toTypedArray()[0]
+ )
val rpcWithEnding = request.substring(request.indexOf('<'))
val firstBlock =
request.split(RpcMessageUtils.MSGLEN_REGEX_PATTERN.toRegex()).dropLastWhile({ it.isEmpty() }).toTypedArray()[1].split(
- (NEW_LINE + RpcMessageUtils.HASH + RpcMessageUtils.HASH + NEW_LINE).toRegex()).dropLastWhile(
+ (NEW_LINE + RpcMessageUtils.HASH + RpcMessageUtils.HASH + NEW_LINE).toRegex()
+ ).dropLastWhile(
{ it.isEmpty() }).toTypedArray()[0]
var newLen = 0
newLen = firstBlock.toByteArray(UTF_8).size
@@ -420,5 +442,4 @@ class NetconfMessageUtils {
} else false
}
}
-
}