diff options
8 files changed, 120 insertions, 23 deletions
diff --git a/cds-ui/client/src/app/feature-modules/blueprint/select-template/search-template/search-from-database/search-from-database.component.ts b/cds-ui/client/src/app/feature-modules/blueprint/select-template/search-template/search-from-database/search-from-database.component.ts index 47771a7aa..1341b8bd1 100644 --- a/cds-ui/client/src/app/feature-modules/blueprint/select-template/search-template/search-from-database/search-from-database.component.ts +++ b/cds-ui/client/src/app/feature-modules/blueprint/select-template/search-template/search-from-database/search-from-database.component.ts @@ -87,6 +87,8 @@ export class SearchFromDatabaseComponent implements OnInit { editCBA(artifactName: string, artifactVersion: string, option: string) { this.cbEditOption.setCbaOption(option); + this.uploadedFileName = artifactName; + console.log("filename:" + this.uploadedFileName); this.zipFile.generateAsync({ type: "blob" }) .then(blob => { const formData = new FormData(); @@ -101,18 +103,6 @@ export class SearchFromDatabaseComponent implements OnInit { .then((zip) => { if (zip) { this.buildFileViewData(zip); - // console.log("processed"); - let data: IBlueprint = this.activationBlueprint ? JSON.parse(this.activationBlueprint.toString()) : this.activationBlueprint; - let blueprintState = { - blueprint: data, - name: this.blueprintName, - files: this.tree, - filesData: this.paths, - uploadedFileName: this.blueprintName, - entryDefinition: this.entryDefinition - } - this.store.dispatch(new SetBlueprintState(blueprintState)); - // console.log(blueprintState); } }); // this.alertService.success('Blueprint enriched successfully'); @@ -123,14 +113,6 @@ export class SearchFromDatabaseComponent implements OnInit { }); } - create() { - this.filesData.forEach((path) => { - let index = path.name.indexOf("/"); - let name = path.name.slice(index + 1, path.name.length); - this.zipFile.file(name, path.data); - }); - } - async buildFileViewData(zip) { this.validfile = false; this.paths = []; @@ -202,7 +184,8 @@ export class SearchFromDatabaseComponent implements OnInit { }); }); this.loader.hideLoader(); - return tree; + this.filesTree = tree; + this.updateBlueprint(); } fetchTOSACAMetadata() { @@ -219,4 +202,19 @@ export class SearchFromDatabaseComponent implements OnInit { this.blueprintName = (((toscaData['Entry-Definitions']).split('/'))[1]).toString();; // console.log(toscaData); } + + updateBlueprint() { + + let data: IBlueprint = this.activationBlueprint ? JSON.parse(this.activationBlueprint.toString()) : this.activationBlueprint; + let blueprintState = { + blueprint: data, + name: this.blueprintName, + files: this.filesTree, + filesData: this.filesData, + uploadedFileName: this.uploadedFileName, + entryDefinition: this.entryDefinition + } + this.store.dispatch(new SetBlueprintState(blueprintState)); + } + } diff --git a/components/scripts/python/ccsdk_netconf/netconfclient.py b/components/scripts/python/ccsdk_netconf/netconfclient.py index b3aef11f4..97f730081 100644 --- a/components/scripts/python/ccsdk_netconf/netconfclient.py +++ b/components/scripts/python/ccsdk_netconf/netconfclient.py @@ -62,3 +62,10 @@ class NetconfClient: def set_execution_attribute_response_data(self, response_data): self.setAttribute(ATTRIBUTE_RESPONSE_DATA, response_data) + + def get(self, filter_content): + device_response = self.netconf_rpc_client.get(filter_content) + return device_response + + def set_execution_attribute_response_data(self, response_data): + self.component_function.setAttribute(ATTRIBUTE_RESPONSE_DATA, response_data) 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("<get>").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("</get>").append(NEW_LINE) + + return doWrappedRpc(messageId, request.toString()) + } + fun getConfig(messageId: String, configType: String, filterContent: String?): String { val request = StringBuilder() diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt index eb32c546b..7b0b799bc 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt @@ -1,5 +1,6 @@ /* * Copyright © 2019 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. @@ -81,13 +82,34 @@ class NetconfRpcServiceImplTest { } @Test + fun `get completes normally`() { + val netconfRpcService = NetconfRpcServiceImpl(deviceInfo) + netconfRpcService.setNetconfSession(mockNetconfSession) + val spy = spyk(netconfRpcService) + every { spy.asyncRpc(any(), any()) } returns successfulDeviceResponse + val getRpcrResult = spy.get(someString) + assertEquals(successfulDeviceResponse, getRpcrResult) + } + + @Test + fun `get on error sets DeviceResponse status to FAILURE`() { + val netconfRpcService = NetconfRpcServiceImpl(deviceInfo) + netconfRpcService.setNetconfSession(mockNetconfSession) + val spy = spyk(netconfRpcService) + every { spy.asyncRpc(any(), any()) } throws IOException("Some IO exception...") + val getRpcResult = spy.get(someString) + assertEquals(failedDeviceResponse.status, getRpcResult.status) + assertTrue { getRpcResult.errorMessage!!.contains("failed in 'get' command") } + } + + @Test fun `getConfig completes normally`() { val netconfRpcService = NetconfRpcServiceImpl(deviceInfo) netconfRpcService.setNetconfSession(mockNetconfSession) val spy = spyk(netconfRpcService) every { spy.asyncRpc(any(), any()) } returns successfulDeviceResponse - val invokeRpcrResult = spy.getConfig(someString) - assertEquals(successfulDeviceResponse, invokeRpcrResult) + val getConfigRpcResult = spy.getConfig(someString) + assertEquals(successfulDeviceResponse, getConfigRpcResult) } @Test diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtilsTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtilsTest.kt index e24659d1d..33135e30f 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtilsTest.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtilsTest.kt @@ -1,3 +1,19 @@ +/* + * Copyright © 2019 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. + * 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.cds.blueprintsprocessor.functions.netconf.executor.utils import org.junit.Assert.* @@ -16,6 +32,13 @@ class NetconfMessageUtilsTest { } @Test + fun `test get operational`() { + val outcome = NetconfMessageUtils.get("customMessageId", "customConfigType") + val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/get-response.xml") + assertEquals("get return was not correct", expectation, outcome) + } + + @Test fun `test getConfig with filterContent parameter null`() { val outcome = NetconfMessageUtils.getConfig("customMessageId", "customConfigType",null) val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/getConfig-response-filterContent-null.xml") diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/get-response.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/get-response.xml new file mode 100644 index 000000000..d9fd72e9c --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/get-response.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc message-id="customMessageId" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> +<get> +<filter type="subtree"> +customConfigType +</filter> +</get> +</rpc>
\ No newline at end of file |