diff options
author | Alexis de Talhouët <adetalhouet89@gmail.com> | 2019-02-18 08:08:24 -0500 |
---|---|---|
committer | Alexis de Talhouët <adetalhouet89@gmail.com> | 2019-02-18 17:31:41 -0500 |
commit | 48b1bea8c1a636169cb5fecd3d0091064e02145b (patch) | |
tree | fd9d267b6cfbd9ca0f3042aaa787f67560c0327e /ms/blueprintsprocessor | |
parent | 01eff6bc81499a9e41395f6b384a5e893b366505 (diff) |
Simplify NetconfRpcService
Change-Id: I6daac25c272ab6b437c07602167a76a2d61816db
Issue-ID: CCSDK-790
Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
Diffstat (limited to 'ms/blueprintsprocessor')
9 files changed, 117 insertions, 203 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 ecf90a28..06c9b7b2 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 @@ -42,6 +42,7 @@ open class ComponentNetconfExecutor(private val blueprintJythonService: Blueprin scriptComponent = blueprintJythonService.jythonComponentInstance(this) as NetconfComponentFunction checkNotNull(scriptComponent) { "failed to get netconf script component" } + // FIXME("Populate the reference in Abstract Script Instance Injection map") scriptComponent.bluePrintRuntimeService = bluePrintRuntimeService scriptComponent.resourceResolutionService = resourceResolutionService diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfDevice.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfDevice.kt index 54776621..1c07c5e6 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfDevice.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfDevice.kt @@ -20,12 +20,11 @@ import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.Ne import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core.NetconfRpcServiceImpl import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core.NetconfSessionImpl -class NetconfDevice(deviceInfo: DeviceInfo) { - val netconfRpcService: NetconfRpcServiceImpl +data class NetconfDevice(val deviceInfo: DeviceInfo) { + val netconfRpcService = NetconfRpcServiceImpl(deviceInfo) val netconfSession: NetconfSession init { - netconfRpcService = NetconfRpcServiceImpl(deviceInfo) netconfSession = NetconfSessionImpl(deviceInfo, netconfRpcService) netconfRpcService.setNetconfSession(netconfSession) } 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 554368c7..e2c9bf90 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 @@ -15,107 +15,90 @@ */ package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api +import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.ModifyAction +import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.NetconfDatastore + interface NetconfRpcService { /** * Lock - * @param messageId message id of the request. - * @param configTarget datastore ( running or candidate) - * @param messageTimeout message timeout of the request. + * + * @param configTarget running or candidate, default candidate * @return Device response */ - fun lock(messageId: String, configTarget: String, messageTimeout: Int): DeviceResponse + fun lock(configTarget: String = NetconfDatastore.CANDIDATE.datastore): DeviceResponse /** * Get-config - * @param messageId message id of the request. - * @param filter filter content. - * @param configTarget config target ( running or candidate) - * @param messageTimeout message timeout of the request. + * + * @param filter filter content, default empty + * @param configTarget running or candidate, default running * @return Device response */ - fun getConfig(messageId: String, filter: String, configTarget: String, messageTimeout: Int): DeviceResponse + fun getConfig(filter: String = "", configTarget: String = NetconfDatastore.RUNNING.datastore): DeviceResponse /** - * Delete config from datastore - * @param messageId message id of the request. - * @param configTarget config target ( running or candidate) - * @param messageTimeout message timeout of the request. + * Delete config + * + * @param configTarget running or candidate, default candidate * @return Device response */ - fun deleteConfig(messageId: String, configTarget: String, messageTimeout: Int): DeviceResponse + fun deleteConfig(configTarget: String = NetconfDatastore.CANDIDATE.datastore): DeviceResponse /** * Edit-config - * @param messageId message id of the request. + * * @param messageContent edit config content. - * @param lock lock the device before performing edit. - * @param configTarget config target ( running or candidate) - * @param editDefaultOperation edit default operation (merge | replace | create | delete | remove or - * delete) - * @param clearCandidate commit after edit config - * @param commit clear candiate store before edit - * @param discardChanges Rollback on failure - * @param validate validate the config before commit - * @param unlock unlock device after edit - * @param messageTimeout message timeout of the request. + * @param configTarget running or candidate, default candidate + * @param editDefaultOperation, default set to none. Valid values: merge, replace, create, delete, none * @return Device response */ - fun editConfig(messageId: String, messageContent: String, lock: Boolean, configTarget: String, - editDefaultOperation: String, deleteConfig: Boolean, validate: Boolean, commit: Boolean, - discardChanges: Boolean, unlock: Boolean, messageTimeout: Int): DeviceResponse + fun editConfig(messageContent: String, configTarget: String = NetconfDatastore.CANDIDATE.datastore, + editDefaultOperation: String = ModifyAction.NONE.action): DeviceResponse /** * Validate - * @param messageId message id of the request. - * @param configTarget config target ( running or candidate) - * @param messageTimeout message timeout of the request. + * + * @param configTarget running or candidate, default candidate * @return Device response */ - fun validate(messageId: String, configTarget: String, messageTimeout: Int): DeviceResponse + fun validate(configTarget: String = NetconfDatastore.CANDIDATE.datastore): DeviceResponse /** * Commit - * @param messageId message id of the request. - * @param discardChanges Rollback on failure - * @param messageTimeout message timeout of the request. + * * @return Device response */ - fun commit(messageId: String, discardChanges: Boolean, messageTimeout: Int): DeviceResponse + fun commit(): DeviceResponse /** * Unlock - * @param messageId message id of the request. - * @param configTarget config target ( running or candidate) - * @param messageTimeout message timeout of the request. + * + * @param configTarget running or candidate, default candidate * @return Device response */ - fun unLock(messageId: String, configTarget: String, messageTimeout: Int): DeviceResponse + fun unLock(configTarget: String = NetconfDatastore.CANDIDATE.datastore): DeviceResponse /** * Discard config - * @param messageId message id of the request. - * @param messageTimeout message timeout of the request. + * * @return Device response */ - fun discardConfig(messageId: String, messageTimeout: Int): DeviceResponse + fun discardConfig(): DeviceResponse /** * Close session - * @param messageId message id of the request. + * * @param force force closeSession - * @param messageTimeout message timeout of the request. * @return Device response */ - fun closeSession(messageId: String, force: Boolean, messageTimeout: Int): DeviceResponse + fun closeSession(force: Boolean): DeviceResponse /** * Executes an RPC request to the netconf server. * * @param request the XML containing the RPC request for the server. - * @param messageId message id of the request. - * @param messageTimeout message timeout of the request. * @return Device response */ - fun asyncRpc(request: String, messageId: String, messageTimeout: Int): DeviceResponse + fun asyncRpc(request: String, messageId: String): DeviceResponse }
\ 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/core/NetconfRpcServiceImpl.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt index 5c633a5b..be835557 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 @@ -21,29 +21,33 @@ import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.De import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.NetconfException import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.NetconfRpcService import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.NetconfSession -import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.NetconfDatastore import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.NetconfMessageUtils import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.RpcStatus import org.slf4j.LoggerFactory import java.util.concurrent.TimeUnit +import java.util.concurrent.atomic.AtomicInteger -class NetconfRpcServiceImpl(private val deviceInfo: DeviceInfo) : NetconfRpcService { +class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcService { private val log = LoggerFactory.getLogger(NetconfRpcService::class.java) + private var responseTimeout: Int = deviceInfo.replyTimeout + private lateinit var netconfSession: NetconfSession + private val messageIdInteger = AtomicInteger(1) + fun setNetconfSession(netconfSession: NetconfSession) { this.netconfSession = netconfSession } - override fun getConfig(messageId: String, filter: String, configTarget: String, - messageTimeout: Int): DeviceResponse { + override fun getConfig(filter: String, configTarget: String): DeviceResponse { var output = DeviceResponse() + val messageId = messageIdInteger.getAndIncrement().toString() log.info("$deviceInfo: getConfig: messageId($messageId)") try { val message = NetconfMessageUtils.getConfig(messageId, configTarget, filter) - output = asyncRpc(message, messageId, messageTimeout) + output = asyncRpc(message, messageId) } catch (e: Exception) { output.status = RpcStatus.FAILURE output.errorMessage = "$deviceInfo: failed in get-config command $e.message" @@ -51,13 +55,14 @@ class NetconfRpcServiceImpl(private val deviceInfo: DeviceInfo) : NetconfRpcServ return output } - override fun deleteConfig(messageId: String, configTarget: String, messageTimeout: Int): DeviceResponse { + override fun deleteConfig(configTarget: String): DeviceResponse { var output = DeviceResponse() + val messageId = messageIdInteger.getAndIncrement().toString() log.info("$deviceInfo: deleteConfig: messageId($messageId)") try { val deleteConfigMessage = NetconfMessageUtils.deleteConfig(messageId, configTarget) output.requestMessage = deleteConfigMessage - output = asyncRpc(deleteConfigMessage, messageId, messageTimeout) + output = asyncRpc(deleteConfigMessage, messageId) } catch (e: Exception) { output.status = RpcStatus.FAILURE output.errorMessage = "$deviceInfo: failed in delete config command $e.message" @@ -65,13 +70,14 @@ class NetconfRpcServiceImpl(private val deviceInfo: DeviceInfo) : NetconfRpcServ return output } - override fun lock(messageId: String, configTarget: String, messageTimeout: Int): DeviceResponse { + override fun lock(configTarget: String): DeviceResponse { var output = DeviceResponse() + val messageId = messageIdInteger.getAndIncrement().toString() log.info("$deviceInfo: lock: messageId($messageId)") try { val lockMessage = NetconfMessageUtils.lock(messageId, configTarget) output.requestMessage = lockMessage - output = asyncRpc(lockMessage, messageId, messageTimeout) + output = asyncRpc(lockMessage, messageId) } catch (e: Exception) { output.status = RpcStatus.FAILURE output.errorMessage = "$deviceInfo: failed in lock command $e.message" @@ -80,13 +86,14 @@ class NetconfRpcServiceImpl(private val deviceInfo: DeviceInfo) : NetconfRpcServ return output } - override fun unLock(messageId: String, configTarget: String, messageTimeout: Int): DeviceResponse { + override fun unLock(configTarget: String): DeviceResponse { var output = DeviceResponse() + val messageId = messageIdInteger.getAndIncrement().toString() log.info("$deviceInfo: unLock: messageId($messageId)") try { val unlockMessage = NetconfMessageUtils.unlock(messageId, configTarget) output.requestMessage = unlockMessage - output = asyncRpc(unlockMessage, messageId, messageTimeout) + output = asyncRpc(unlockMessage, messageId) } catch (e: Exception) { output.status = RpcStatus.FAILURE output.errorMessage = "$deviceInfo: failed in lock command $e.message" @@ -94,33 +101,28 @@ class NetconfRpcServiceImpl(private val deviceInfo: DeviceInfo) : NetconfRpcServ return output } - override fun commit(messageId: String, discardChanges: Boolean, messageTimeout: Int): DeviceResponse { + override fun commit(): DeviceResponse { var output = DeviceResponse() + val messageId = messageIdInteger.getAndIncrement().toString() log.info("$deviceInfo: commit: messageId($messageId)") try { val messageContent = NetconfMessageUtils.commit(messageId) - output = asyncRpc(messageContent, messageId, messageTimeout) + output = asyncRpc(messageContent, messageId) } catch (e: Exception) { output.status = RpcStatus.FAILURE output.errorMessage = "$deviceInfo: failed in commit command $e.message" - - // If commit failed apply discard changes - if (discardChanges) { - val discardChangesConfigMessageId = "$messageId-discard-changes" - val discardOutput = discardConfig(discardChangesConfigMessageId, deviceInfo.replyTimeout) - output.addSubDeviceResponse(discardChangesConfigMessageId, discardOutput) - } } return output } - override fun discardConfig(messageId: String, messageTimeout: Int): DeviceResponse { + override fun discardConfig(): DeviceResponse { var output = DeviceResponse() + val messageId = messageIdInteger.getAndIncrement().toString() log.info("$deviceInfo: discard: messageId($messageId)") try { val discardChangesMessage = NetconfMessageUtils.discardChanges(messageId) output.requestMessage = discardChangesMessage - output = asyncRpc(discardChangesMessage, messageId, messageTimeout) + output = asyncRpc(discardChangesMessage, messageId) } catch (e: Exception) { output.status = RpcStatus.FAILURE output.errorMessage = "$deviceInfo: failed in discard changes command " + e.message @@ -128,12 +130,44 @@ class NetconfRpcServiceImpl(private val deviceInfo: DeviceInfo) : NetconfRpcServ return output } - override fun closeSession(messageId: String, force: Boolean, messageTimeout: Int): 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)") + try { + val editMessage = + NetconfMessageUtils.editConfig(messageId, configTarget, editDefaultOperation, messageContent) + response.requestMessage = editMessage + response = asyncRpc(editMessage, messageId) + } catch (e: Exception) { + response.status = RpcStatus.FAILURE + response.errorMessage = e.message + } + return response + } + + override fun validate(configTarget: String): DeviceResponse { + var output = DeviceResponse() + val messageId = messageIdInteger.getAndIncrement().toString() + try { + val validateMessage = NetconfMessageUtils.validate(messageId, configTarget) + output.requestMessage = validateMessage + output = asyncRpc(validateMessage, messageId) + } catch (e: Exception) { + output.status = RpcStatus.FAILURE + output.errorMessage = "$deviceInfo: failed in validate command " + e.message + } + return output + } + + override fun closeSession(force: Boolean): DeviceResponse { var output = DeviceResponse() + val messageId = messageIdInteger.getAndIncrement().toString() log.info("$deviceInfo: closeSession: messageId($messageId)") try { val messageContent = NetconfMessageUtils.closeSession(messageId, force) - output = asyncRpc(messageContent, messageId, messageTimeout) + output = asyncRpc(messageContent, messageId) } catch (e: Exception) { output.status = RpcStatus.FAILURE output.errorMessage = "$deviceInfo: failed in closeSession command " + e.message @@ -142,12 +176,12 @@ class NetconfRpcServiceImpl(private val deviceInfo: DeviceInfo) : NetconfRpcServ } @Throws(NetconfException::class) - override fun asyncRpc(request: String, messageId: String, messageTimeout: Int): DeviceResponse { + override fun asyncRpc(request: String, messageId: String): DeviceResponse { val response = DeviceResponse() log.info("$deviceInfo: send asyncRpc with messageId($messageId)") response.requestMessage = request - val rpcResponse = netconfSession.asyncRpc(request, messageId).get(messageTimeout.toLong(), TimeUnit.SECONDS) + val rpcResponse = netconfSession.asyncRpc(request, messageId).get(responseTimeout.toLong(), TimeUnit.SECONDS) if (!NetconfMessageUtils.checkReply(rpcResponse)) { throw NetconfException(rpcResponse) } @@ -156,110 +190,4 @@ class NetconfRpcServiceImpl(private val deviceInfo: DeviceInfo) : NetconfRpcServ response.errorMessage = null return response } - - override fun editConfig(messageId: String, messageContent: String, lock: Boolean, configTarget: String, - editDefaultOperation: String, deleteConfig: Boolean, validate: Boolean, commit: Boolean, - discardChanges: Boolean, unlock: Boolean, messageTimeout: Int): DeviceResponse { - var editConfigDeviceResponse = - DeviceResponse() - - try { - val editMessage = - NetconfMessageUtils.editConfig(messageId, configTarget, editDefaultOperation, messageContent) - editConfigDeviceResponse.requestMessage = editMessage - - if (lock) { - val lockMessageId = "$messageId-lock" - val lockDeviceResponse = lock(lockMessageId, configTarget, deviceInfo.replyTimeout) - editConfigDeviceResponse.addSubDeviceResponse(lockMessageId, lockDeviceResponse) - if (!RpcStatus.SUCCESS.equals(lockDeviceResponse.status, ignoreCase = true)) { - throw NetconfException( - lockDeviceResponse.errorMessage!!) - } - } - - if (deleteConfig) { - val deleteConfigMessageId = "$messageId-delete" - val deleteConfigDeviceResponse = deleteConfig(deleteConfigMessageId, - NetconfDatastore.CANDIDATE, deviceInfo.replyTimeout) - editConfigDeviceResponse.addSubDeviceResponse(deleteConfigMessageId, deleteConfigDeviceResponse) - if (!RpcStatus.SUCCESS.equals(deleteConfigDeviceResponse.status, - ignoreCase = true)) { - throw NetconfException( - deleteConfigDeviceResponse.errorMessage!!) - } - } - - if (discardChanges) { - val discardConfigMessageId = "$messageId-discard" - val discardConfigDeviceResponse = discardConfig(discardConfigMessageId, deviceInfo.replyTimeout) - editConfigDeviceResponse.addSubDeviceResponse(discardConfigMessageId, discardConfigDeviceResponse) - if (!RpcStatus.SUCCESS.equals(discardConfigDeviceResponse.status, - ignoreCase = true)) { - throw NetconfException( - discardConfigDeviceResponse.errorMessage!!) - } - } - - editConfigDeviceResponse = asyncRpc(editMessage, messageId, messageTimeout) - if (!RpcStatus.SUCCESS.equals(editConfigDeviceResponse.status, ignoreCase = true)) { - throw NetconfException( - editConfigDeviceResponse.errorMessage!!) - } - - if (validate) { - val validateMessageId = "$messageId-validate" - val validateDeviceResponse = validate(validateMessageId, - NetconfDatastore.CANDIDATE, deviceInfo.replyTimeout) - editConfigDeviceResponse.addSubDeviceResponse(validateMessageId, validateDeviceResponse) - if (!RpcStatus.SUCCESS.equals(validateDeviceResponse.status, ignoreCase = true)) { - throw NetconfException( - validateDeviceResponse.errorMessage!!) - } - } - - /** - * If Commit is enable, the commit response is treated as Edit config response, If commit failed, we - * need not to throw an exception, until we unlock the device. - */ - if (commit) { - val commitMessageId = "$messageId-commit" - val commitDeviceResponse = - commit(commitMessageId, discardChanges, deviceInfo.replyTimeout) - editConfigDeviceResponse.addSubDeviceResponse(commitMessageId, commitDeviceResponse) - if (!RpcStatus.SUCCESS.equals(commitDeviceResponse.status, ignoreCase = true)) { - throw NetconfException( - commitDeviceResponse.errorMessage!!) - } - } - - } catch (e: Exception) { - editConfigDeviceResponse.status = RpcStatus.FAILURE - editConfigDeviceResponse.errorMessage = e.message - } finally { - if (unlock) { - val unlockMessageId = "$messageId-unlock" - val unlockDeviceResponse = unLock(unlockMessageId, configTarget, deviceInfo.replyTimeout) - editConfigDeviceResponse.addSubDeviceResponse(unlockMessageId, unlockDeviceResponse) - if (!RpcStatus.SUCCESS.equals(unlockDeviceResponse.status, ignoreCase = true)) { - editConfigDeviceResponse.status = RpcStatus.FAILURE - editConfigDeviceResponse.errorMessage = unlockDeviceResponse.errorMessage - } - } - } - return editConfigDeviceResponse - } - - override fun validate(messageId: String, configTarget: String, messageTimeout: Int): DeviceResponse { - var output = DeviceResponse() - try { - val validateMessage = NetconfMessageUtils.validate(messageId, configTarget) - output.requestMessage = validateMessage - output = asyncRpc(validateMessage, messageId, messageTimeout) - } catch (e: Exception) { - output.status = RpcStatus.FAILURE - output.errorMessage = "$deviceInfo: failed in validate command " + e.message - } - return output - } }
\ 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/core/NetconfSessionImpl.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt index 21570a23..cf11cfdd 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt @@ -40,7 +40,6 @@ import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ExecutionException import java.util.concurrent.TimeUnit import java.util.concurrent.TimeoutException -import java.util.concurrent.atomic.AtomicInteger class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcService: NetconfRpcService) : NetconfSession { @@ -61,7 +60,6 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ private lateinit var channel: ClientChannel private lateinit var streamHandler: NetconfDeviceCommunicator - private val messageIdInteger = AtomicInteger(1) private var capabilities = ImmutableList.of(RpcMessageUtils.NETCONF_10_CAPABILITY, RpcMessageUtils.NETCONF_11_CAPABILITY) @@ -78,9 +76,9 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ } override fun disconnect() { - if (rpcService.closeSession(messageIdInteger.incrementAndGet().toString(), false, replyTimeout).status.equals( + if (rpcService.closeSession(false).status.equals( RpcStatus.FAILURE, true)) { - rpcService.closeSession(messageIdInteger.incrementAndGet().toString(), true, replyTimeout) + rpcService.closeSession(true) } session.close() diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/NetconfConstant.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/NetconfConstant.kt index e0cbde53..3b3b0c02 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/NetconfConstant.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/NetconfConstant.kt @@ -15,9 +15,15 @@ */ package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils -object NetconfDatastore { - const val RUNNING = "running" - const val CANDIDATE = "candidate" +enum class NetconfDatastore(val datastore: String) { + RUNNING("running"), + CANDIDATE("candidate"); +} + +enum class ModifyAction(val action: String) { + MERGE("merge"), + REPLACE("replace"), + NONE("none") } object RpcStatus { 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 b0310d78..7e48912d 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 @@ -139,9 +139,9 @@ class NetconfMessageUtils { } @Throws(NetconfException::class) - fun deleteConfig(messageId: String, netconfTargetConfig: String): String { - if (netconfTargetConfig == NetconfDatastore.RUNNING) { - log.warn("Target configuration for delete operation can't be \"running\" {}", netconfTargetConfig) + fun deleteConfig(messageId: String, configType: String): String { + if (configType == NetconfDatastore.RUNNING.datastore) { + log.warn("Target configuration for delete operation can't be \"running\" {}", configType) throw NetconfException("Target configuration for delete operation can't be running") } @@ -149,7 +149,7 @@ class NetconfMessageUtils { request.append("<delete-config>").append(NEW_LINE) request.append(RpcMessageUtils.TARGET_OPEN).append(NEW_LINE) - request.append(RpcMessageUtils.OPEN).append(netconfTargetConfig) + request.append(RpcMessageUtils.OPEN).append(configType) .append(RpcMessageUtils.TAG_CLOSE) .append(NEW_LINE) request.append(RpcMessageUtils.TARGET_CLOSE).append(NEW_LINE) @@ -304,8 +304,6 @@ class NetconfMessageUtils { } if (!message.startsWith(RpcMessageUtils.NEW_LINE + RpcMessageUtils.HASH)) { // chunk encode message - //message = (RpcMessageUtils.NEW_LINE + RpcMessageUtils.HASH + message.getBytes(UTF_8).size + RpcMessageUtils.NEW_LINE + message +RpcMessageUtils. NEW_LINE + RpcMessageUtils.HASH + RpcMessageUtils.HASH - // + RpcMessageUtils.NEW_LINE) 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) 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 20b04fb5..2cd2d109 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 @@ -29,7 +29,7 @@ class RpcMessageUtilsTest { + "</get-config></rpc>") val messageId = "Test-Message-ID" - val configType = "candidate" + val configType = NetconfDatastore.CANDIDATE.datastore val filterContent = "Test-Filter-Content" val result = NetconfMessageUtils.getConfig(messageId, configType, filterContent).replace("[\n\r\t]".toRegex(), "") @@ -48,7 +48,7 @@ class RpcMessageUtilsTest { + "</get-config></rpc>") val messageId = "Test-Message-ID" - val configType = "candidate" + val configType = NetconfDatastore.CANDIDATE.datastore val filterContent = "Test-Filter-Content" val result = NetconfMessageUtils.getConfig(messageId, configType, filterContent).replace("[\n\r\t]".toRegex(), "") @@ -64,7 +64,7 @@ class RpcMessageUtilsTest { + "<validate><source><candidate/></source></validate></rpc>") val messageId = "Test-Message-ID" - val configType = "candidate" + val configType = NetconfDatastore.CANDIDATE.datastore val result = NetconfMessageUtils.validate(messageId, configType).replace("[\n\r\t]".toRegex(), "") @@ -94,7 +94,7 @@ class RpcMessageUtilsTest { + "<unlock><target><candidate/></target></unlock></rpc>") val messageId = "Test-Message-ID" - val configType = "candidate" + val configType = NetconfDatastore.CANDIDATE.datastore val result = NetconfMessageUtils.unlock(messageId, configType).replace("[\n\r\t]".toRegex(), "") @@ -109,7 +109,7 @@ class RpcMessageUtilsTest { + "<delete-config><target><candidate/></target></delete-config></rpc>") val messageId = "Test-Message-ID" - val netconfTargetConfig = "candidate" + val netconfTargetConfig = NetconfDatastore.CANDIDATE.datastore val result = NetconfMessageUtils.deleteConfig(messageId, netconfTargetConfig).replace("[\n\r\t]".toRegex(), "") @@ -138,7 +138,7 @@ class RpcMessageUtilsTest { + "<lock><target><candidate/></target></lock></rpc>") val messageId = "Test-Message-ID" - val configType = "candidate" + val configType = NetconfDatastore.CANDIDATE.datastore val result = NetconfMessageUtils.lock(messageId, configType).replace("[\n\r\t]".toRegex(), "") assertTrue(NetconfMessageUtils.validateRPCXML(result)) diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt index 9bcc23b6..bd055953 100644 --- a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt +++ b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt @@ -68,6 +68,7 @@ open class ComponentRestconfExecutor(private var applicationContext: Application scriptComponent.nodeTemplateName = nodeTemplateName scriptComponent.operationInputs = operationInputs + // FIXME("Populate the reference in Abstract Script Instance Injection map") // Set the Rest Lib Property Service scriptComponent.bluePrintRestLibPropertyService = bluePrintRestLibPropertyService scriptComponent.resourceResolutionService = resourceResolutionService |