From 6dec3fb775386767a7b4008b0862e6a32247bb97 Mon Sep 17 00:00:00 2001 From: Steve Siani Date: Tue, 27 Aug 2019 14:58:30 -0400 Subject: Add Get function in Netconf execution service for operational commands Issue-ID: CCSDK-1657 Signed-off-by: Steve Siani Change-Id: I12b82a7f1233fce256190ec0d35a5b85ad937b7b --- .../functions/netconf/executor/api/NetconfRpcService.kt | 9 +++++++++ .../netconf/executor/core/NetconfRpcServiceImpl.kt | 15 +++++++++++++++ .../netconf/executor/utils/NetconfMessageUtils.kt | 15 +++++++++++++++ 3 files changed, 39 insertions(+) (limited to 'ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin') 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 60345b5a6..ecb6267f5 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 @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright (c) 2019 IBM, Bell Canada * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -139,4 +140,12 @@ interface NetconfRpcService { * @return Device response */ fun asyncRpc(request: String, messageId: String): DeviceResponse + + /** + * Get + * + * @param filter filter content for operational command + * @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/core/NetconfRpcServiceImpl.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt index e4e3ffe4a..6fa167a95 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 @@ -1,5 +1,6 @@ /* * Copyright © 2017-2019 AT&T, Bell Canada + * Modifications Copyright (c) 2019 IBM, Bell Canada * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,6 +55,20 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ return output } + override fun get(filter: String): DeviceResponse { + var output = DeviceResponse() + val messageId = messageIdInteger.getAndIncrement().toString() + log.info("$deviceInfo: get operational config: messageId($messageId)") + try { + val message = NetconfMessageUtils.get(messageId, filter) + output = asyncRpc(message, messageId) + } catch (e: Exception) { + output.status = RpcStatus.FAILURE + output.errorMessage = "$deviceInfo: failed in 'get' command ${e.message}" + } + return output + } + override fun getConfig(filter: String, configTarget: String): DeviceResponse { var output = DeviceResponse() val messageId = messageIdInteger.getAndIncrement().toString() 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 bb5cdb0b5..37ff67433 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 @@ -1,5 +1,6 @@ /* * Copyright © 2017-2019 AT&T, Bell Canada + * Modifications Copyright (c) 2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,6 +45,20 @@ class NetconfMessageUtils { private val CHUNKED_SIZE_PATTERN: Pattern = Pattern.compile("\\n#([1-9][0-9]*)\\n") private val MSG_ID_STRING_PATTERN = Pattern.compile("${RpcMessageUtils.MESSAGE_ID_STRING}=\"(.*?)\"") + fun get(messageId: String, filterContent: String): String { + val request = StringBuilder() + + request.append("").append(NEW_LINE) + if (!filterContent.isNullOrEmpty()) { + request.append(RpcMessageUtils.SUBTREE_FILTER_OPEN).append(NEW_LINE) + request.append(filterContent).append(NEW_LINE) + request.append(RpcMessageUtils.SUBTREE_FILTER_CLOSE).append(NEW_LINE) + } + request.append("").append(NEW_LINE) + + return doWrappedRpc(messageId, request.toString()) + } + fun getConfig(messageId: String, configType: String, filterContent: String?): String { val request = StringBuilder() -- cgit 1.2.3-korg