aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/restful-executor
diff options
context:
space:
mode:
authorHuang Cheng <duke.huangcheng@huawei.com>2020-02-04 03:53:15 +0000
committerHuang Cheng <duke.huangcheng@huawei.com>2020-03-06 01:21:14 +0000
commitfdfeef7ae2f543553e2f7a7cf322b6d075599e20 (patch)
tree9bb5488db6a724c7a70bcf182df8f609456b4ff6 /ms/blueprintsprocessor/functions/restful-executor
parentc2c379246a6d231e9424308c398a15fcb6618fc3 (diff)
Add the executor and the component function to support 5G NRM CM
The executor and the component function are designed to invoke the 5G NRM CM opertions: createMOI getMOIAttributes modifyMOIAttributes and deleteMOI Issue-ID: CCSDK-2003 Signed-off-by: Huang Cheng <duke.huangcheng@huawei.com> Change-Id: I20d3e97c01f6499e73ab0ec77abbc24775f428b7
Diffstat (limited to 'ms/blueprintsprocessor/functions/restful-executor')
-rw-r--r--ms/blueprintsprocessor/functions/restful-executor/pom.xml56
-rw-r--r--ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/internal/scripts/TestRestfulConfigure.kt42
-rw-r--r--ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/ComponentRestfulExecutor.kt69
-rw-r--r--ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/RestfulCMComponentFunction.kt126
-rw-r--r--ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/nrmfunction/RestfulNRMServiceClient.kt111
-rw-r--r--ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/ComponentRestfulExecutorTest.kt105
-rw-r--r--ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/nrmfunction/RestfulNRMServiceClientTest.kt150
7 files changed, 659 insertions, 0 deletions
diff --git a/ms/blueprintsprocessor/functions/restful-executor/pom.xml b/ms/blueprintsprocessor/functions/restful-executor/pom.xml
new file mode 100644
index 000000000..4ac52c4b8
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restful-executor/pom.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright © 2017-2018 AT&T Intellectual Property.
+ ~
+ ~ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
+ <artifactId>functions</artifactId>
+ <version>0.7.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
+ <artifactId>restful-executor</artifactId>
+
+ <name>Blueprints Processor Function - NRM Restful executor</name>
+ <description>Blueprints Processor Function - NRM Restful executor</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
+ <artifactId>processor-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>${apache.httpcomponents.client.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/internal/scripts/TestRestfulConfigure.kt b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/internal/scripts/TestRestfulConfigure.kt
new file mode 100644
index 000000000..5f867b93f
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/internal/scripts/TestRestfulConfigure.kt
@@ -0,0 +1,42 @@
+/*
+ * Copyright © 2020 Huawei.
+ *
+ * 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.
+ */
+@file:Suppress("unused")
+
+package internal.scripts
+
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.restful.executor.RestfulCMComponentFunction
+import org.slf4j.LoggerFactory
+
+/**
+ * This is for used for Testing only
+ */
+open class TestRestfulConfigure : RestfulCMComponentFunction() {
+
+ val log = LoggerFactory.getLogger(TestRestfulConfigure::class.java)!!
+
+ override fun getName(): String {
+ return "TestRestfulConfigure"
+ }
+
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
+ log.info("processing request..")
+ }
+
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ log.info("recovering..")
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/ComponentRestfulExecutor.kt b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/ComponentRestfulExecutor.kt
new file mode 100644
index 000000000..e1643b576
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/ComponentRestfulExecutor.kt
@@ -0,0 +1,69 @@
+/*
+ * Copyright © 2020 Huawei Intellectual Property.
+ *
+ * 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.restful.executor
+
+import com.fasterxml.jackson.databind.node.ArrayNode
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestLibConstants
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
+import org.onap.ccsdk.cds.controllerblueprints.core.getAsString
+import org.springframework.beans.factory.config.ConfigurableBeanFactory
+import org.springframework.context.annotation.Scope
+import org.springframework.stereotype.Component
+
+@Component("component-restful-executor")
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+open class ComponentRestfulExecutor(private var componentFunctionScriptingService: ComponentFunctionScriptingService) : AbstractComponentFunction() {
+
+ lateinit var scriptComponent: RestfulCMComponentFunction
+
+ companion object {
+ const val SCRIPT_TYPE = "script-type"
+ const val SCRIPT_CLASS_REFERENCE = "script-class-reference"
+ const val INSTANCE_DEPENDENCIES = "instance-dependencies"
+ }
+
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
+
+ val scriptType = operationInputs.getAsString(SCRIPT_TYPE)
+ val scriptClassReference = operationInputs.getAsString(SCRIPT_CLASS_REFERENCE)
+ val instanceDependenciesNode = operationInputs.get(INSTANCE_DEPENDENCIES) as? ArrayNode
+
+ val scriptDependencies: MutableList<String> = arrayListOf()
+ scriptDependencies.add(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
+
+ instanceDependenciesNode?.forEach { instanceName ->
+ scriptDependencies.add(instanceName.textValue())
+ }
+ /**
+ * Populate the Script Instance based on the Type
+ */
+ scriptComponent = componentFunctionScriptingService
+ .scriptInstance<RestfulCMComponentFunction>(this, scriptType,
+ scriptClassReference, scriptDependencies)
+
+ checkNotNull(scriptComponent) { "failed to get restfulCM script component" }
+
+ // Handles both script processing and error handling
+ scriptComponent.executeScript(executionServiceInput)
+ }
+
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ bluePrintRuntimeService.getBluePrintError()
+ .addError("Failed in ComponentRestfulExecutor : ${runtimeException.message}")
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/RestfulCMComponentFunction.kt b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/RestfulCMComponentFunction.kt
new file mode 100644
index 000000000..46fec3126
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/RestfulCMComponentFunction.kt
@@ -0,0 +1,126 @@
+/*
+ * Copyright © 2020 Huawei.
+ *
+ * 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.restful.executor
+
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.fasterxml.jackson.databind.node.ObjectNode
+import com.fasterxml.jackson.databind.node.ArrayNode
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestLibConstants
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.restful.executor.nrmfunction.RestfulNRMServiceClient
+import org.slf4j.LoggerFactory
+
+abstract class RestfulCMComponentFunction : AbstractScriptComponentFunction() {
+
+ private val log = LoggerFactory.getLogger(RestfulCMComponentFunction::class.java)
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
+ throw BluePrintException("Not Implemented required")
+ }
+
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ throw BluePrintException("Not Implemented required")
+ }
+
+ open fun bluePrintRestLibPropertyService(): BluePrintRestLibPropertyService =
+ functionDependencyInstanceAsType(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
+
+ fun restClientService(clientInfo: JsonNode): BlueprintWebClientService {
+ return bluePrintRestLibPropertyService().blueprintWebClientService(clientInfo)
+ }
+
+ fun processNRM(executionRequest: ExecutionServiceInput, input_params: ArrayNode): String {
+ // process the managed object instances
+ log.info("Processing NRM Object")
+ operationInputs = executionServiceInput.stepData!!.properties
+ val dynamic_properties = operationInputs.get("dynamic-properties")
+ // instantiate one restClientService instance
+ val hostname = dynamic_properties?.get("hostname").toString().replace("\"", "")
+ val port = dynamic_properties?.get("port").toString().replace("\"", "")
+ val username = dynamic_properties?.get("username").toString().replace("\"", "")
+ val password = dynamic_properties?.get("password").toString().replace("\"", "")
+ val url = "http://" + hostname + ":" + port
+ val RestInfo: String = "{\n" +
+ " \"type\" : \"basic-auth\",\n" +
+ " \"url\" : \"" + url + "\",\n" +
+ " \"username\" : \"" + username + "\",\n" +
+ " \"password\" : \"" + password + "\"\n" +
+ "}"
+ val mapper = ObjectMapper()
+ val jsonRestInfo: JsonNode = mapper.readTree(RestInfo)
+ val web_client_service = restClientService(jsonRestInfo)
+ val managed_object_instances = input_params
+ var response = JacksonUtils.jsonNode("{}") as ObjectNode
+ // Invoke the corresponding function according to the workflowname
+ when (this.workflowName) {
+ "config-deploy" -> {
+ for (managed_object_instance in managed_object_instances) {
+ // invoke createMOI for each managed-object-instance
+ log.info("invoke createMOI for each managed-object-instance")
+ var NRM_Restful_client = RestfulNRMServiceClient()
+ val MOI_id = NRM_Restful_client.generateMOIid()
+ var httpresponse = NRM_Restful_client.createMOI(web_client_service, MOI_id, managed_object_instance)
+ var MOIname = managed_object_instance.get("className").toString().replace("\"", "")
+ response.put("/$MOIname/$MOI_id", httpresponse)
+ }
+ }
+ "config-get" -> {
+ for (managed_object_instance in managed_object_instances) {
+ // invoke getMOIAttributes for each managed-object-instance
+ log.info("invoke getMOIAttributes for each managed-object-instance")
+ var NRM_Restful_client = RestfulNRMServiceClient()
+ val MOI_id = managed_object_instance.get("id").toString().replace("\"", "")
+ var httpresponse = NRM_Restful_client.getMOIAttributes(web_client_service, MOI_id, managed_object_instance)
+ var MOIname = managed_object_instance.get("className").toString().replace("\"", "")
+ response.put("/$MOIname/$MOI_id", httpresponse)
+ }
+ }
+ "config-modify" -> {
+ for (managed_object_instance in managed_object_instances) {
+ // invoke modifyMOIAttributes for each managed-object-instance
+ log.info("invoke modifyMOIAttributes for each managed-object-instance")
+ var NRM_Restful_client = RestfulNRMServiceClient()
+ val MOI_id = managed_object_instance.get("id").toString().replace("\"", "")
+ var httpresponse = NRM_Restful_client.modifyMOIAttributes(web_client_service, MOI_id, managed_object_instance)
+ var MOIname = managed_object_instance.get("className").toString().replace("\"", "")
+ response.put("/$MOIname/$MOI_id", httpresponse)
+ }
+ }
+ "config-delete" -> {
+ for (managed_object_instance in managed_object_instances) {
+ // invoke deleteMOI for each managed-object-instance
+ log.info("invoke deleteMOI for each managed-object-instance")
+ var NRM_Restful_client = RestfulNRMServiceClient()
+ val MOI_id = managed_object_instance.get("id").toString().replace("\"", "")
+ var httpresponse = NRM_Restful_client.deleteMOI(web_client_service, MOI_id, managed_object_instance)
+ var MOIname = managed_object_instance.get("className").toString().replace("\"", "")
+ response.put("/$MOIname/$MOI_id", httpresponse)
+ }
+ }
+ else -> {
+ print("not Implemented")
+ response.put(this.workflowName, "Not Implemented")
+ }
+ }
+ val strresponse = "$response"
+ return strresponse
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/nrmfunction/RestfulNRMServiceClient.kt b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/nrmfunction/RestfulNRMServiceClient.kt
new file mode 100644
index 000000000..31ad377c9
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/nrmfunction/RestfulNRMServiceClient.kt
@@ -0,0 +1,111 @@
+/*
+ * Copyright © 2019 Huawei.
+ *
+ * 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.restful.executor.nrmfunction
+
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.fasterxml.jackson.databind.node.ObjectNode
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
+import org.springframework.http.HttpMethod
+import org.onap.ccsdk.cds.controllerblueprints.core.logger
+import java.util.UUID
+import org.springframework.web.util.UriComponentsBuilder
+
+class RestfulNRMServiceClient() {
+
+ private val log = logger(RestfulNRMServiceClient::class.java)
+
+ fun createMOI(web_client_service: BlueprintWebClientService, idStr: String, managed_object_instance: JsonNode): ObjectNode {
+ val classNameStr = managed_object_instance.get("className").toString().replace("\"", "")
+ val pathStr = "/ProvisioningMnS/v1500/$classNameStr/$idStr"
+ log.info("MOI Path: " + pathStr)
+ var request_object_value = JacksonUtils.jsonNode("{}") as ObjectNode
+ request_object_value.put("attributes", managed_object_instance.get("data"))
+ request_object_value.put("href", "/" + classNameStr + "/" + idStr)
+ request_object_value.put("class", classNameStr)
+ request_object_value.put("id", idStr)
+ var request_object = JacksonUtils.jsonNode("{}") as ObjectNode
+ request_object.put("data", request_object_value)
+ val requestBodystr = request_object.toString()
+ log.info("MOI request body: " + requestBodystr)
+ val response = web_client_service.exchangeResource(HttpMethod.PUT.name, pathStr, requestBodystr)
+ var response_object = generateResponse(response.status, response.body)
+ log.info("MOI response status: " + response.status)
+ return response_object
+ }
+
+ fun getMOIAttributes(web_client_service: BlueprintWebClientService, idStr: String, managed_object_instance: JsonNode): ObjectNode {
+ val classNameStr = managed_object_instance.get("className").toString().replace("\"", "")
+ var pathStr = "/ProvisioningMnS/v1500/$classNameStr/$idStr"
+ pathStr = addQueryParameters(pathStr, "scope", managed_object_instance.get("scope").toString().replace("\"", ""))
+ pathStr = addQueryParameters(pathStr, "filter", managed_object_instance.get("filter").toString().replace("\"", ""))
+ for (attribute_value in managed_object_instance.get("fields")) {
+ pathStr = addQueryParameters(pathStr, "fields", attribute_value.toString().replace("\"", ""))
+ }
+ log.info("MOI Path: " + pathStr)
+ val response = web_client_service.exchangeResource(HttpMethod.GET.name, pathStr, "")
+ log.info("MOI response status: " + response.status)
+ var response_object = generateResponse(response.status, response.body)
+ return response_object
+ }
+
+ fun modifyMOIAttributes(web_client_service: BlueprintWebClientService, idStr: String, managed_object_instance: JsonNode): ObjectNode {
+ val classNameStr = managed_object_instance.get("className").toString().replace("\"", "")
+ var pathStr = "/ProvisioningMnS/v1500/$classNameStr/$idStr"
+ pathStr = addQueryParameters(pathStr, "scope", managed_object_instance.get("scope").toString().replace("\"", ""))
+ pathStr = addQueryParameters(pathStr, "filter", managed_object_instance.get("filter").toString().replace("\"", ""))
+ log.info("MOI Path: " + pathStr)
+ var request_object = JacksonUtils.jsonNode("{}") as ObjectNode
+ request_object.put("data", managed_object_instance.get("data"))
+ val requestBodystr = request_object.toString()
+ log.info("MOI request body: " + requestBodystr)
+ val response = web_client_service.exchangeResource(HttpMethod.PATCH.name, pathStr, requestBodystr)
+ log.info("MOI response status: " + response.status)
+ var response_object = generateResponse(response.status, response.body)
+ return response_object
+ }
+
+ fun deleteMOI(web_client_service: BlueprintWebClientService, idStr: String, managed_object_instance: JsonNode): ObjectNode {
+ val classNameStr = managed_object_instance.get("className").toString().replace("\"", "")
+ var pathStr = "/ProvisioningMnS/v1500/$classNameStr/$idStr"
+ pathStr = addQueryParameters(pathStr, "scope", managed_object_instance.get("scope").toString().replace("\"", ""))
+ pathStr = addQueryParameters(pathStr, "filter", managed_object_instance.get("filter").toString().replace("\"", ""))
+ log.info("MOI Path: " + pathStr)
+ val response = web_client_service.exchangeResource(HttpMethod.DELETE.name, pathStr, "")
+ log.info("MOI response status: " + response.status)
+ var response_object = generateResponse(response.status, response.body)
+ return response_object
+ }
+
+ fun generateResponse(status: Int, body: String): ObjectNode {
+ var response_object = JacksonUtils.jsonNode("{}") as ObjectNode
+ response_object.put("status", status)
+ val mapper = ObjectMapper()
+ val response_body: JsonNode = mapper.readTree(body)
+ response_object.put("body", response_body)
+ return response_object
+ }
+
+ fun generateMOIid(): String {
+ return UUID.randomUUID().toString()
+ }
+
+ fun addQueryParameters(old_uri: String, key: String, value: String): String {
+ return UriComponentsBuilder.fromUriString(old_uri).queryParam(key, value).build().toString()
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/ComponentRestfulExecutorTest.kt b/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/ComponentRestfulExecutorTest.kt
new file mode 100644
index 000000000..ad70ac021
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/ComponentRestfulExecutorTest.kt
@@ -0,0 +1,105 @@
+/*
+ * Copyright © 2020 Huawei Intellectual Property.
+ *
+ * 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.restful.executor
+
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.node.ObjectNode
+import io.mockk.every
+import io.mockk.mockk
+import kotlinx.coroutines.runBlocking
+import org.junit.Test
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
+import org.onap.ccsdk.cds.controllerblueprints.core.data.Implementation
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
+import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.springframework.context.ApplicationContext
+
+class ComponentRestfulExecutorTest {
+
+ @Test
+ fun testComponentRestfulExecutor() {
+ runBlocking {
+
+ val applicationContext = mockk<ApplicationContext>()
+ every { applicationContext.getBean(any()) } returns mockk()
+
+ val componentFunctionScriptingService = ComponentFunctionScriptingService(applicationContext, mockk())
+
+ val componentRestfulExecutor = ComponentRestfulExecutor(componentFunctionScriptingService)
+
+ val executionServiceInput = ExecutionServiceInput().apply {
+ commonHeader = CommonHeader().apply {
+ requestId = "1234"
+ }
+ actionIdentifiers = ActionIdentifiers().apply {
+ actionName = "config-deploy"
+ }
+ payload = JacksonUtils.jsonNode("{}") as ObjectNode
+ }
+
+ val blueprintContext = mockk<BluePrintContext>()
+ every {
+ blueprintContext.nodeTemplateOperationImplementation(
+ any(), any(), any()
+ )
+ } returns Implementation()
+
+ val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234")
+ every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
+
+ componentRestfulExecutor.bluePrintRuntimeService = bluePrintRuntime
+ componentRestfulExecutor.stepName = "sample-step"
+
+ val operationInputs = hashMapOf<String, JsonNode>()
+ operationInputs[BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = "config-deploy-process".asJsonPrimitive()
+ operationInputs[BluePrintConstants.PROPERTY_CURRENT_INTERFACE] = "interfaceName".asJsonPrimitive()
+ operationInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] = "operationName".asJsonPrimitive()
+ operationInputs["script-type"] = BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive()
+ operationInputs["script-class-reference"] = "internal.scripts.TestRestfulConfigure".asJsonPrimitive()
+
+ val stepInputData = StepData().apply {
+ name = "call-config-deploy-process"
+ properties = operationInputs
+ }
+ executionServiceInput.stepData = stepInputData
+
+ every {
+ bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs(
+ "config-deploy-process",
+ "interfaceName", "operationName"
+ )
+ } returns operationInputs
+
+ val operationOutputs = hashMapOf<String, JsonNode>()
+ every {
+ bluePrintRuntime.resolveNodeTemplateInterfaceOperationOutputs(
+ "config-deploy-process",
+ "interfaceName", "operationName"
+ )
+ } returns operationOutputs
+
+ componentRestfulExecutor.applyNB(executionServiceInput)
+ }
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/nrmfunction/RestfulNRMServiceClientTest.kt b/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/nrmfunction/RestfulNRMServiceClientTest.kt
new file mode 100644
index 000000000..e7f04a5d4
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/nrmfunction/RestfulNRMServiceClientTest.kt
@@ -0,0 +1,150 @@
+/*
+ * Copyright © 2019 Huawei.
+ *
+ * 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.restful.executor.nrmfunction
+
+import com.fasterxml.jackson.databind.node.ObjectNode
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.junit.Test
+import org.junit.Ignore
+import org.springframework.beans.factory.annotation.Autowired
+import org.junit.runner.RunWith
+import org.springframework.test.context.junit4.SpringRunner
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
+import org.springframework.boot.test.context.SpringBootTest
+import org.springframework.test.context.ContextConfiguration
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.BluePrintRestLibConfiguration
+import org.springframework.test.context.TestPropertySource
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
+import kotlin.test.assertNotNull
+import kotlin.test.assertEquals
+import org.springframework.web.bind.annotation.RestController
+import org.springframework.web.bind.annotation.RequestMapping
+import org.springframework.web.bind.annotation.PutMapping
+import org.springframework.web.bind.annotation.GetMapping
+import org.springframework.web.bind.annotation.PatchMapping
+import org.springframework.web.bind.annotation.DeleteMapping
+import org.springframework.http.ResponseEntity
+import org.springframework.http.HttpStatus
+
+@RunWith(SpringRunner::class)
+@EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class])
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
+@ContextConfiguration(classes = [BluePrintRestLibConfiguration::class, NrmTestController::class])
+@TestPropertySource(properties = [
+ "blueprintsprocessor.restclient.nrm.type=basic-auth",
+ "blueprintsprocessor.restclient.nrm.url=http://127.0.0.1:8080",
+ "blueprintsprocessor.restclient.nrm.username=admin",
+ "blueprintsprocessor.restclient.nrm.password=admin"
+])
+
+@Ignore
+class RestfulNRMServiceClientTest {
+
+ @Autowired
+ lateinit var restfulNRMServiceClient: RestfulNRMServiceClient
+ lateinit var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService
+
+ @Test
+ fun testCreateMOI() {
+ val restClientService = bluePrintRestLibPropertyService.blueprintWebClientService("nrm")
+ val idStr = restfulNRMServiceClient.generateMOIid()
+ var test_moi_data = JacksonUtils.jsonNode("{}") as ObjectNode
+ test_moi_data.put("className", "TestMangedObjectInstance")
+ var test_attributes_data = JacksonUtils.jsonNode("{}") as ObjectNode
+ test_attributes_data.put("test_attribute_key", "test_attribute_value")
+ test_moi_data.put("data", test_attributes_data)
+ val response = restfulNRMServiceClient.createMOI(restClientService, idStr, test_moi_data)
+ assertNotNull(response, "failed to get createMOI response")
+ assertEquals("Create MOI object successfully", response.get("body").get("data").toString(), "failed to get createMOI response")
+ }
+
+ @Test
+ fun testGetMOIAttributes() {
+ val restClientService = bluePrintRestLibPropertyService.blueprintWebClientService("nrm")
+ val idStr = restfulNRMServiceClient.generateMOIid()
+ var test_moi_data = JacksonUtils.jsonNode("{}") as ObjectNode
+ test_moi_data.put("className", "TestMangedObjectInstance")
+ test_moi_data.put("scope", "BASE_ONLY")
+ test_moi_data.put("filter", "TestMangedObjectInstance")
+ test_moi_data.put("fields", "test_attribute_key")
+ val response = restfulNRMServiceClient.getMOIAttributes(restClientService, idStr, test_moi_data)
+ assertNotNull(response, "failed to get getMOIAttributes response")
+ assertEquals("Get MOI object attributes successfully", response.get("body").get("data").toString(), "failed to get getMOIAttributes response")
+ }
+
+ @Test
+ fun testModifyMOIAttributes() {
+ val restClientService = bluePrintRestLibPropertyService.blueprintWebClientService("nrm")
+ val idStr = restfulNRMServiceClient.generateMOIid()
+ var test_moi_data = JacksonUtils.jsonNode("{}") as ObjectNode
+ test_moi_data.put("className", "TestMangedObjectInstance")
+ test_moi_data.put("scope", "BASE_ONLY")
+ test_moi_data.put("filter", "TestMangedObjectInstance")
+ var test_attributes_data = JacksonUtils.jsonNode("{}") as ObjectNode
+ test_attributes_data.put("test_attribute_key", "modified_attribute_value")
+ test_moi_data.put("data", test_attributes_data)
+ val response = restfulNRMServiceClient.modifyMOIAttributes(restClientService, idStr, test_moi_data)
+ assertNotNull(response, "failed to get modifyMOIAttributes response")
+ assertEquals("Modify MOI object attributes successfully", response.get("body").get("data").toString(), "failed to get modifyMOIAttributes response")
+ }
+
+ @Test
+ fun testDeleteMOI() {
+ val restClientService = bluePrintRestLibPropertyService.blueprintWebClientService("nrm")
+ val idStr = restfulNRMServiceClient.generateMOIid()
+ var test_moi_data = JacksonUtils.jsonNode("{}") as ObjectNode
+ test_moi_data.put("className", "TestMangedObjectInstance")
+ test_moi_data.put("scope", "BASE_ONLY")
+ test_moi_data.put("filter", "TestMangedObjectInstance")
+ val response = restfulNRMServiceClient.deleteMOI(restClientService, idStr, test_moi_data)
+ assertNotNull(response, "failed to get delete response")
+ assertEquals("Delete MOI object attributes successfully", response.get("body").get("data").toString(), "failed to get delete response")
+ }
+}
+
+/**
+ * Sample controller code for testing the above four functions.
+ */
+@RestController
+@RequestMapping("/ProvisioningMnS/v1500")
+open class NrmTestController {
+
+ @PutMapping("/TestMangedObjectInstance")
+ fun putMOI(): ResponseEntity<Any> {
+ var a = "{\n" + "\"data\" : \"Create MOI object successfully" + "}"
+ return ResponseEntity(a, HttpStatus.OK)
+ }
+
+ @GetMapping("/TestMangedObjectInstance")
+ fun getMOI(): ResponseEntity<Any> {
+ var a = "{\n" + "\"data\" : \"Get MOI object attributes successfully" + "}"
+ return ResponseEntity(a, HttpStatus.OK)
+ }
+
+ @PatchMapping("/TestMangedObjectInstance")
+ fun patchMOI(): ResponseEntity<Any> {
+ var a = "{\n" + "\"data\" : \"Modify MOI object attributes successfully" + "}"
+ return ResponseEntity(a, HttpStatus.OK)
+ }
+
+ @DeleteMapping("/TestMangedObjectInstance")
+ fun deleteMOI(): ResponseEntity<Any> {
+ var a = "{\n" + "\"data\" : \"Delete MOI object attributes successfully" + "}"
+ return ResponseEntity(a, HttpStatus.OK)
+ }
+}