diff options
author | Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com> | 2019-02-12 15:26:19 -0500 |
---|---|---|
committer | Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com> | 2019-02-12 15:26:19 -0500 |
commit | 0928983b9875877e06eae506043f289e334f91a0 (patch) | |
tree | 4197ba3f357aba9c70d68af5dfaf8e41cba10c93 /ms/blueprintsprocessor/functions/netconf-executor/src | |
parent | 22861e62057c835b6bb3ac18308a98abc3c79715 (diff) |
Add netconf script component function
Change-Id: I094025fba5626bae0b4b13320f1cbbb76cda3bfd
Issue-ID: CCSDK-790
Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/blueprintsprocessor/functions/netconf-executor/src')
10 files changed, 133 insertions, 103 deletions
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt index c007914a..ab3372e9 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt @@ -19,33 +19,42 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintPythonService -import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.interfaces.DeviceInfo -import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.ComponentJythonExecutor +import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService +import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction import org.slf4j.LoggerFactory import org.springframework.beans.factory.config.ConfigurableBeanFactory -import org.springframework.context.ApplicationContext import org.springframework.context.annotation.Scope import org.springframework.stereotype.Component @Component("component-netconf-executor") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class ComponentNetconfExecutor(private var applicationContext: ApplicationContext, private val netconfExecutorConfiguration: NetconfExecutorConfiguration, - private val blueprintPythonService: BlueprintPythonService) - : ComponentJythonExecutor(applicationContext, blueprintPythonService) { +open class ComponentNetconfExecutor(private val blueprintJythonService: BlueprintJythonService) + : AbstractComponentFunction() { private val log = LoggerFactory.getLogger(ComponentNetconfExecutor::class.java) - lateinit var deviceInfo: DeviceInfo + lateinit var scriptComponent: NetconfComponentFunction override fun process(executionServiceInput: ExecutionServiceInput) { - super.process(executionServiceInput) + scriptComponent = blueprintJythonService.jythonComponentInstance(this) as NetconfComponentFunction + checkNotNull(scriptComponent) { "failed to get netconf script component" } + scriptComponent.bluePrintRuntimeService = bluePrintRuntimeService + scriptComponent.processId = processId + scriptComponent.workflowName = workflowName + scriptComponent.stepName = stepName + scriptComponent.interfaceName = interfaceName + scriptComponent.operationName = operationName + scriptComponent.nodeTemplateName = nodeTemplateName + scriptComponent.operationInputs = operationInputs + scriptComponent.process(executionServiceInput) } - fun setdeviceInfo(deviceInfo: DeviceInfo) { - this.deviceInfo = deviceInfo + override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { + scriptComponent.recover(runtimeException, executionRequest) } + + }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt new file mode 100644 index 00000000..d480bdd4 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt @@ -0,0 +1,63 @@ +/* + * Copyright © 2018 IBM. + * + * 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.apps.blueprintsprocessor.functions.netconf.executor + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.interfaces.DeviceInfo +import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.interfaces.NetconfRpcClientService +import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils + + +abstract class NetconfComponentFunction : AbstractComponentFunction() { + + fun deviceProperties(requirementName: String): DeviceInfo { + + val blueprintContext = bluePrintRuntimeService.bluePrintContext() + + val requirement = blueprintContext.nodeTemplateRequirement(nodeTemplateName, requirementName) + + val capabilityProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties(requirement + .node!!, requirement.capability!!) + + return deviceProperties(capabilityProperties) + } + + fun deviceProperties(capabilityProperty: MutableMap<String, JsonNode>): DeviceInfo { + return JacksonUtils.getInstanceFromMap(capabilityProperty, DeviceInfo::class.java) + } + + fun netconfRpcClientService(): NetconfRpcClientService { + return NetconfRpcService() + } + + fun netconfRpcClientService(requirementName: String): NetconfRpcClientService { + val deviceProperties = deviceProperties(requirementName) + val netconfRpcClientService = NetconfRpcService() + netconfRpcClientService.connect(deviceProperties) + return netconfRpcClientService + } + + fun generateMessage(): String { + TODO() + } + + fun resolveAndGenerateMesssage(): String { + TODO() + } + +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfRpcService.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfRpcService.kt index d5385054..0e264bcb 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfRpcService.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfRpcService.kt @@ -16,8 +16,6 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor -import com.fasterxml.jackson.databind.JsonNode -import com.google.common.base.Preconditions import org.apache.commons.collections.CollectionUtils import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core.NetconfSessionFactory import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.data.DeviceResponse @@ -26,7 +24,6 @@ import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.interf import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.interfaces.NetconfRpcClientService import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.interfaces.NetconfSession import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.RpcMessageUtils -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.slf4j.LoggerFactory import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope @@ -48,37 +45,20 @@ class NetconfRpcService : NetconfRpcClientService { private val recordedApplyConfigIds = ArrayList<String>() private val DEFAULT_MESSAGE_TIME_OUT = 30 - @Throws(NetconfException::class) - fun NetconfRpcService(capabilityProperty: MutableMap<String, JsonNode> ) { + + override fun connect(deviceInfo: DeviceInfo): NetconfSession { try { - Preconditions.checkNotNull(capabilityProperty, "missing netconfDeviceInfo in netconf rpc client") - connect(getNetconfDeviceInfo(capabilityProperty)) - log.info("NetconfRpcService initialised with deviceInfo {}", deviceInfo) - //configPersistService = ConfigPersistService(configResourceService) + this.deviceInfo = deviceInfo + + log.info("Connecting Netconf Device .....") + this.netconfSession = NetconfSessionFactory.instance("DEFAULT_NETCONF_SESSION", deviceInfo) + publishMessage("Netconf Device Connection Established") + return this.netconfSession } catch (e: NetconfException) { publishMessage(String.format("Netconf Device Connection Failed, %s", e.message)) throw NetconfException("Netconf Device Connection Failed,$deviceInfo",e) } - - } - - fun setdeviceInfo(deviceInfo: DeviceInfo) { - this.deviceInfo = deviceInfo - } - - fun getNetconfDeviceInfo(capabilityProperty: MutableMap<String, JsonNode> ):DeviceInfo{ - val netconfDeviceInfo = JacksonUtils.getInstanceFromMap(capabilityProperty, DeviceInfo::class.java) - this.deviceInfo = netconfDeviceInfo - return netconfDeviceInfo - } - - fun connect(netconfDeviceInfo: DeviceInfo) { - log.info("in the connect method") - setdeviceInfo(netconfDeviceInfo) - netconfSession = NetconfSessionFactory.instance("DEFAULT_NETCONF_SESSION", netconfDeviceInfo) - publishMessage("Netconf Device Connection Established"); - } override fun disconnect() { diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/data/NetconfExecutionData.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/data/NetconfExecutionData.kt index 0b63ea58..f66c14a5 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/data/NetconfExecutionData.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/data/NetconfExecutionData.kt @@ -17,25 +17,9 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.data import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.interfaces.DeviceInfo -import java.io.IOException import java.util.* - - -class NetconfExecutionRequest { - lateinit var requestId: String - val action: String? = null - val source: String? = null - val loginKey: String? = null - val loginAccount: String? = null - val targetIP: String? = null - val port: Int = 0 - val connectionTimeoutSec: Int = 0 - val implementationScript: String? = null - val context: MutableMap<String, Any> = mutableMapOf() -} - class DeviceResponse { lateinit var deviceInfo: DeviceInfo lateinit var status: String @@ -52,13 +36,6 @@ class DeviceResponse { } } -class NetconfExecutionResponse { - val status: String? = null - val errorMessage: String? = null - val responseData: Any = Any() -} - - class NetconfDeviceOutputEvent { private var type: NetconfDeviceOutputEvent.Type diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/data/NetconfSshClientLib.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/data/NetconfSshClientLib.kt index 0a517871..f21cce4a 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/data/NetconfSshClientLib.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/data/NetconfSshClientLib.kt @@ -16,8 +16,8 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.data enum class NetconfSshClientLib(val sshClientString :String) { - APACHE_MINA("apache-mina"), - ETHZ_SSH2("ethz-ssh2"); + APACHE_MINA("apache-mina"), + ETHZ_SSH2("ethz-ssh2"); fun getEnum(valueOf: String): NetconfSshClientLib { return NetconfSshClientLib.valueOf(valueOf.toUpperCase().replace('-', '_')) diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/interfaces/DeviceInfo.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/interfaces/DeviceInfo.kt index ca67b341..f4360c7e 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/interfaces/DeviceInfo.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/interfaces/DeviceInfo.kt @@ -19,27 +19,25 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.inter import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonProperty -data class DeviceInfo ( - @get:JsonProperty("login-account") - var name: String? = null, - @get:JsonProperty("login-key") - var pass: String? = null, - @get:JsonProperty("target-ip-address") - var ipAddress: String? = null, - @get:JsonProperty("port-number") - var port: Int = 0, - @get:JsonIgnore - var key: String? = null, - @get:JsonProperty("source") - var source: String? = null, - // var sshClientLib: NetconfSshClientLib = NetconfSshClientLib, - @get:JsonProperty("connection-time-out") - var connectTimeoutSec: Long = 30, - @get:JsonIgnore - var replyTimeout: Int = 60, - @get:JsonIgnore - var idleTimeout: Int = 45, - @get:JsonIgnore - var deviceId: String = ipAddress + ":" + port -){ - }
\ No newline at end of file +class DeviceInfo { + @get:JsonProperty("login-account") + var name: String? = null + @get:JsonProperty("login-key") + var pass: String? = null + @get:JsonProperty("target-ip-address") + var ipAddress: String? = null + @get:JsonProperty("port-number") + var port: Int = 0 + @get:JsonIgnore + var key: String? = null + @get:JsonProperty("source") + var source: String? = null + @get:JsonProperty("connection-time-out") + var connectTimeoutSec: Long = 30 + @get:JsonIgnore + var replyTimeout: Int = 60 + @get:JsonIgnore + var idleTimeout: Int = 45 + @get:JsonIgnore + var deviceId: String = "$ipAddress:$port" +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/interfaces/NetconfRpcClientService.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/interfaces/NetconfRpcClientService.kt index 17a24488..668fb552 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/interfaces/NetconfRpcClientService.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/interfaces/NetconfRpcClientService.kt @@ -19,6 +19,13 @@ import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.data.D interface NetconfRpcClientService { + /** + * @param deviceProperties deviceProperties + * @return NetconfSession + */ + fun connect(deviceInfo: DeviceInfo): NetconfSession + + fun disconnect() diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/NetconfDeviceProperties.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/NetconfDeviceProperties.kt deleted file mode 100644 index 4073351c..00000000 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/NetconfDeviceProperties.kt +++ /dev/null @@ -1,7 +0,0 @@ -package org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.utils - -data class NetconfDeviceProperties(val loginKey:String,val loginAccount:String,val targetIpAddress:String,val portNumber:Int,val connectiontimeOut:Int) { - - - -}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt index c33bfcfa..d6f737fd 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt @@ -22,7 +22,7 @@ import com.fasterxml.jackson.databind.JsonNode import org.junit.Test import org.junit.runner.RunWith import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintPythonService +import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.PythonExecutorProperty import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode @@ -35,10 +35,10 @@ import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [NetconfExecutorConfiguration::class, BlueprintPythonService::class, +@ContextConfiguration(classes = [NetconfExecutorConfiguration::class, BlueprintJythonService::class, PythonExecutorProperty::class]) @TestPropertySource(properties = -["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_netconf;./../../../../components/scripts/python/ccsdk_blueprints", +["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_netconf,./../../../../components/scripts/python/ccsdk_blueprints", "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_netconf"]) class ComponentNetconfExecutorTest { @@ -70,9 +70,7 @@ class ComponentNetconfExecutorTest { componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService componentNetconfExecutor.stepName = "activate-netconf" - - //TODO to fix build issue - //componentNetconfExecutor.apply(executionServiceInput) + componentNetconfExecutor.apply(executionServiceInput) } } diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt index eefead21..4ee48bc8 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt @@ -18,7 +18,6 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor import org.junit.After import org.junit.Assert import org.junit.Before -import org.junit.Test import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core.NetconfSessionImpl import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.interfaces.DeviceInfo import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.NetconfDeviceSimulator @@ -31,7 +30,13 @@ class NetconfSessionImplTest { @Before fun before() { - deviceInfo =DeviceInfo("name", "password", "localhost", 2224, "10") + deviceInfo = DeviceInfo().apply { + name = "name" + pass = "password" + ipAddress = "localhost" + port = 2224 + connectTimeoutSec = 10 + } device = NetconfDeviceSimulator(deviceInfo!!.port) device!!.start() |