diff options
author | Singal, Kapil (ks220y) <ks220y@att.com> | 2019-09-18 11:19:15 -0400 |
---|---|---|
committer | Singal, Kapil (ks220y) <ks220y@att.com> | 2019-09-18 11:20:50 -0400 |
commit | 7f48f7ffe672a307a931465b33a964482593d345 (patch) | |
tree | 88f29dbae37d3849cebbb833482e6083a686e699 /ms/blueprintsprocessor/functions/netconf-executor/src/main | |
parent | 71f561eb81dfa6c777cc296693cd8f69cb58b8b0 (diff) |
Refactoring Netconf NetconfMessageUtils
Appending New Line before and after request body within doWrapRpc and removing new line is child API's which forms the request body
Issue-ID: CCSDK-1743
Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com>
Change-Id: Ic58566e24a21c71d545c45fb95a667c17de2fe66
Diffstat (limited to 'ms/blueprintsprocessor/functions/netconf-executor/src/main')
4 files changed, 27 insertions, 50 deletions
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 aa156e2a8..bc91b7d92 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,9 @@ 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.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.CompletableFuture -import java.util.concurrent.TimeUnit +import java.io.* +import java.nio.charset.* +import java.util.concurrent.* class NetconfDeviceCommunicator(private var inputStream: InputStream, private var out: OutputStream, 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 6fa167a95..6a045e365 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,11 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.core -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.api.* 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 @@ -232,4 +228,4 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ response.errorMessage = null return response } -}
\ 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/NetconfSessionImpl.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt index 4daaceeff..a0f653591 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,24 +22,14 @@ 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.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider -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.NetconfReceivedEvent -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.api.* 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.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 +import java.util.* +import java.util.concurrent.* class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcService: NetconfRpcService) : NetconfSession { @@ -306,4 +296,4 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ internal fun setClient(client: SshClient) { this.client = client } internal fun setSession(session: ClientSession) { this.session = session } internal fun setChannel(channel: ClientChannel) { this.channel = channel } -}
\ 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 37ff67433..4d65d36bb 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 @@ -54,7 +54,7 @@ class NetconfMessageUtils { request.append(filterContent).append(NEW_LINE) request.append(RpcMessageUtils.SUBTREE_FILTER_CLOSE).append(NEW_LINE) } - request.append("</get>").append(NEW_LINE) + request.append("</get>") return doWrappedRpc(messageId, request.toString()) } @@ -73,7 +73,7 @@ class NetconfMessageUtils { request.append(filterContent).append(NEW_LINE) request.append(RpcMessageUtils.SUBTREE_FILTER_CLOSE).append(NEW_LINE) } - request.append("</get-config>").append(NEW_LINE) + request.append("</get-config>") return doWrappedRpc(messageId, request.toString()) } @@ -84,8 +84,7 @@ class NetconfMessageUtils { rpc.append(RpcMessageUtils.MESSAGE_ID_STRING).append(RpcMessageUtils.EQUAL) rpc.append(RpcMessageUtils.QUOTE).append(messageId).append(RpcMessageUtils.QUOTE_SPACE) rpc.append(RpcMessageUtils.NETCONF_BASE_NAMESPACE).append(RpcMessageUtils.CLOSE) - .append(NEW_LINE) - rpc.append(request) + rpc.append(NEW_LINE).append(request).append(NEW_LINE) rpc.append(RpcMessageUtils.RPC_CLOSE) // rpc.append(NEW_LINE).append(END_PATTERN); @@ -94,9 +93,7 @@ class NetconfMessageUtils { 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) request.append(RpcMessageUtils.OPEN).append(configType).append(RpcMessageUtils.TAG_CLOSE) @@ -112,7 +109,7 @@ class NetconfMessageUtils { request.append(RpcMessageUtils.CONFIG_OPEN).append(NEW_LINE) request.append(newConfiguration.trim { it <= ' ' }).append(NEW_LINE) request.append(RpcMessageUtils.CONFIG_CLOSE).append(NEW_LINE) - request.append("</edit-config>").append(NEW_LINE) + request.append("</edit-config>") return doWrappedRpc(messageId, request.toString()) } @@ -125,7 +122,7 @@ class NetconfMessageUtils { request.append(RpcMessageUtils.OPEN).append(configType).append(RpcMessageUtils.TAG_CLOSE) .append(NEW_LINE) request.append(RpcMessageUtils.SOURCE_CLOSE).append(NEW_LINE) - request.append("</validate>").append(NEW_LINE) + request.append("</validate>") return doWrappedRpc(messageId, request.toString()) } @@ -145,16 +142,16 @@ class NetconfMessageUtils { val request = StringBuilder() request.append("<commit>").append(NEW_LINE) if (confirmed) { - request.append("<confirmed/>") - request.append("<confirm-timeout>$confirmTimeout</confirm-timeout>") + request.append("<confirmed/>").append(NEW_LINE) + request.append("<confirm-timeout>$confirmTimeout</confirm-timeout>").append(NEW_LINE) if (!persist.isEmpty()) { - request.append("<persist>$persist</persist>") + request.append("<persist>$persist</persist>").append(NEW_LINE) } } if (!persistId.isEmpty()) { - request.append("<persist-id>$persistId</persist-id>") + request.append("<persist-id>$persistId</persist-id>").append(NEW_LINE) } - request.append("</commit>").append(NEW_LINE) + request.append("</commit>") return doWrappedRpc(messageId, request.toString()) } @@ -163,9 +160,9 @@ class NetconfMessageUtils { val request = StringBuilder() request.append("<cancel-commit>").append(NEW_LINE) if (!persistId.isEmpty()) { - request.append("<persist-id>$persistId</persist-id>") + request.append("<persist-id>$persistId</persist-id>").append(NEW_LINE) } - request.append("</cancel-commit>").append(NEW_LINE) + request.append("</cancel-commit>") return doWrappedRpc(messageId, request.toString()) } @@ -178,7 +175,7 @@ class NetconfMessageUtils { request.append(RpcMessageUtils.OPEN).append(configType).append(RpcMessageUtils.TAG_CLOSE) .append(NEW_LINE) request.append(RpcMessageUtils.TARGET_CLOSE).append(NEW_LINE) - request.append("</unlock>").append(NEW_LINE) + request.append("</unlock>") return doWrappedRpc(messageId, request.toString()) } @@ -198,14 +195,14 @@ class NetconfMessageUtils { .append(RpcMessageUtils.TAG_CLOSE) .append(NEW_LINE) request.append(RpcMessageUtils.TARGET_CLOSE).append(NEW_LINE) - request.append("</delete-config>").append(NEW_LINE) + request.append("</delete-config>") return doWrappedRpc(messageId, request.toString()) } fun discardChanges(messageId: String): String { val request = StringBuilder() - request.append("<discard-changes/>").append(NEW_LINE) + request.append("<discard-changes/>") return doWrappedRpc(messageId, request.toString()) } @@ -217,7 +214,7 @@ class NetconfMessageUtils { request.append(RpcMessageUtils.OPEN).append(configType).append(RpcMessageUtils.TAG_CLOSE) .append(NEW_LINE) request.append(RpcMessageUtils.TARGET_CLOSE).append(NEW_LINE) - request.append("</lock>").append(NEW_LINE) + request.append("</lock>") return doWrappedRpc(messageId, request.toString()) } @@ -226,9 +223,9 @@ class NetconfMessageUtils { val request = StringBuilder() if (force) { - request.append("<kill-session/>").append(NEW_LINE) + request.append("<kill-session/>") } else { - request.append("<close-session/>").append(NEW_LINE) + request.append("<close-session/>") } return doWrappedRpc(messageId, request.toString()) |