diff options
Diffstat (limited to 'ms/blueprintsprocessor/functions')
7 files changed, 69 insertions, 88 deletions
diff --git a/ms/blueprintsprocessor/functions/ansible-awx-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/ansible/executor/ComponentRemoteAnsibleExecutor.kt b/ms/blueprintsprocessor/functions/ansible-awx-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/ansible/executor/ComponentRemoteAnsibleExecutor.kt index 63998dd29..947a9630d 100644 --- a/ms/blueprintsprocessor/functions/ansible-awx-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/ansible/executor/ComponentRemoteAnsibleExecutor.kt +++ b/ms/blueprintsprocessor/functions/ansible-awx-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/ansible/executor/ComponentRemoteAnsibleExecutor.kt @@ -1,5 +1,6 @@ /* * Copyright © 2019 Bell Canada. + * Modifications Copyright © 2018-2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,21 +19,24 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.ansible.executor import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.databind.node.ObjectNode -import java.net.URI -import java.net.URLEncoder -import java.util.NoSuchElementException -import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.* +import com.fasterxml.jackson.databind.node.TextNode +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction -import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonString +import org.onap.ccsdk.cds.controllerblueprints.core.isNotNull +import org.onap.ccsdk.cds.controllerblueprints.core.rootFieldsToMap import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.slf4j.LoggerFactory import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.http.HttpMethod import org.springframework.stereotype.Component +import java.net.URI +import java.net.URLEncoder +import java.util.* /** * ComponentRemoteAnsibleExecutor @@ -99,7 +103,7 @@ open class ComponentRemoteAnsibleExecutor(private val blueprintRestLibPropertySe override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { val message = "Error in ComponentRemoteAnsibleExecutor : ${runtimeException.message}" - log.error(message,runtimeException) + log.error(message, runtimeException) setNodeOutputErrors(ATTRIBUTE_EXEC_CMD_STATUS_ERROR, message) } @@ -123,7 +127,7 @@ open class ComponentRemoteAnsibleExecutor(private val blueprintRestLibPropertySe try { return blueprintRestLibPropertyService.blueprintWebClientService(endpointSelector) - } catch (e : NoSuchElementException) { + } catch (e: NoSuchElementException) { throw IllegalArgumentException("No value provided for input selector $endpointSelector", e) } } @@ -131,13 +135,13 @@ open class ComponentRemoteAnsibleExecutor(private val blueprintRestLibPropertySe /** * Finds the job template ID based on the job template name provided in the request */ - private fun lookupJobTemplateIDByName(awxClient : BlueprintWebClientService, job_template_name: String?): String { - val encodedJTName = URI(null,null, + private fun lookupJobTemplateIDByName(awxClient: BlueprintWebClientService, job_template_name: String?): String { + val encodedJTName = URI(null, null, "/api/v2/job_templates/${job_template_name}/", - null,null).rawPath + null, null).rawPath // Get Job Template details by name - var response = awxClient.exchangeResource(GET, encodedJTName,"") + var response = awxClient.exchangeResource(GET, encodedJTName, "") val jtDetails: JsonNode = mapper.readTree(response.body) return jtDetails.at("/id").asText() } @@ -148,18 +152,18 @@ open class ComponentRemoteAnsibleExecutor(private val blueprintRestLibPropertySe * its execution. Finally, it retrieves the job results via the stdout api. * The status and output attributes are populated in the process. */ - private fun runJobTemplateOnAWX(awxClient : BlueprintWebClientService, job_template_name: String?, jtId: String) { - setNodeOutputProperties( "preparing".asJsonPrimitive(), "".asJsonPrimitive()) + private fun runJobTemplateOnAWX(awxClient: BlueprintWebClientService, job_template_name: String?, jtId: String) { + setNodeOutputProperties("preparing".asJsonPrimitive(), "".asJsonPrimitive()) // Get Job Template requirements - var response = awxClient.exchangeResource(GET, "/api/v2/job_templates/${jtId}/launch/","") + var response = awxClient.exchangeResource(GET, "/api/v2/job_templates/${jtId}/launch/", "") // FIXME: handle non-successful SC val jtLaunchReqs: JsonNode = mapper.readTree(response.body) - var payload = prepareLaunchPayload(awxClient, jtLaunchReqs) + val payload = prepareLaunchPayload(awxClient, jtLaunchReqs) log.info("Running job with $payload, for requestId $processId.") // Launch the job for the targeted template - var jtLaunched : JsonNode = JacksonUtils.jsonNode("{}") as ObjectNode + var jtLaunched: JsonNode = JacksonUtils.objectMapper.createObjectNode() response = awxClient.exchangeResource(POST, "/api/v2/job_templates/${jtId}/launch/", payload) if (response.status in HTTP_SUCCESS) { jtLaunched = mapper.readTree(response.body) @@ -188,9 +192,9 @@ open class ComponentRemoteAnsibleExecutor(private val blueprintRestLibPropertySe // Get job execution results (stdout) val plainTextHeaders = mutableMapOf<String, String>() plainTextHeaders["Content-Type"] = "text/plain ;utf-8" - response = awxClient.exchangeResource(GET, "/api/v2/jobs/${jobId}/stdout/?format=txt","", plainTextHeaders) + response = awxClient.exchangeResource(GET, "/api/v2/jobs/${jobId}/stdout/?format=txt", "", plainTextHeaders) - setNodeOutputProperties( jobStatus.asJsonPrimitive(), response.body.asJsonPrimitive()) + setNodeOutputProperties(jobStatus.asJsonPrimitive(), response.body.asJsonPrimitive()) } else { // The job template requirements were not fulfilled with the values passed in. The message below will // provide more information via the response, like the ignored_fields, or variables_needed_to_start, @@ -198,7 +202,7 @@ open class ComponentRemoteAnsibleExecutor(private val blueprintRestLibPropertySe val message = "Execution of job template $job_template_name could not be started for requestId $processId." + " (Response: ${response.body}) " log.error(message) - setNodeOutputErrors( ATTRIBUTE_EXEC_CMD_STATUS_ERROR, message) + setNodeOutputErrors(ATTRIBUTE_EXEC_CMD_STATUS_ERROR, message) } } @@ -207,51 +211,49 @@ open class ComponentRemoteAnsibleExecutor(private val blueprintRestLibPropertySe * by applying the overrides that were provided * and allowed by the template definition flags in jtLaunchReqs */ - private fun prepareLaunchPayload(awxClient : BlueprintWebClientService, jtLaunchReqs: JsonNode): String { - val payload = JacksonUtils.jsonNode("{}") as ObjectNode + private fun prepareLaunchPayload(awxClient: BlueprintWebClientService, jtLaunchReqs: JsonNode): String { + val payload = JacksonUtils.objectMapper.createObjectNode() // Parameter defaults - val limitProp = getOptionalOperationInput(INPUT_LIMIT_TO_HOST)?.asText() - val tagsProp = getOptionalOperationInput(INPUT_TAGS)?.asText() - val skipTagsProp = getOptionalOperationInput(INPUT_SKIP_TAGS)?.asText() - val inventoryProp : String? = getOptionalOperationInput(INPUT_INVENTORY)?.asText() - val extraArgs : JsonNode = getOperationInput(INPUT_EXTRA_VARS) - - val askLimitOnLaunch = jtLaunchReqs.at( "/ask_limit_on_launch").asBoolean() - if (askLimitOnLaunch && limitProp!!.isNotEmpty()) { - payload.put(INPUT_LIMIT_TO_HOST, limitProp) + val limitProp = getOptionalOperationInput(INPUT_LIMIT_TO_HOST) + val tagsProp = getOptionalOperationInput(INPUT_TAGS) + val skipTagsProp = getOptionalOperationInput(INPUT_SKIP_TAGS) + val inventoryProp = getOptionalOperationInput(INPUT_INVENTORY) + val extraArgs = getOperationInput(INPUT_EXTRA_VARS) + + val askLimitOnLaunch = jtLaunchReqs.at("/ask_limit_on_launch").asBoolean() + if (askLimitOnLaunch && limitProp.isNotNull()) { + payload.set(INPUT_LIMIT_TO_HOST, limitProp) } val askTagsOnLaunch = jtLaunchReqs.at("/ask_tags_on_launch").asBoolean() - if (askTagsOnLaunch && tagsProp!!.isNotEmpty()) { - payload.put(INPUT_TAGS, tagsProp) + if (askTagsOnLaunch && tagsProp.isNotNull()) { + payload.set(INPUT_TAGS, tagsProp) } - if (askTagsOnLaunch && skipTagsProp!!.isNotEmpty()) { - payload.put("skip_tags", skipTagsProp) + if (askTagsOnLaunch && skipTagsProp.isNotNull()) { + payload.set("skip_tags", skipTagsProp) } val askInventoryOnLaunch = jtLaunchReqs.at("/ask_inventory_on_launch").asBoolean() - if (askInventoryOnLaunch && inventoryProp != null) { - var inventoryKeyId = inventoryProp.toIntOrNull() - if (inventoryKeyId == null) { - inventoryKeyId = resolveInventoryIdByName(awxClient, inventoryProp) + if (askInventoryOnLaunch && inventoryProp.isNotNull()) { + var inventoryKeyId = if (inventoryProp is TextNode) { + resolveInventoryIdByName(awxClient, inventoryProp!!.textValue())?.asJsonPrimitive() + } else { + inventoryProp } - payload.put(INPUT_INVENTORY, inventoryKeyId) + payload.set(INPUT_INVENTORY, inventoryKeyId) } val askVariablesOnLaunch = jtLaunchReqs.at("/ask_variables_on_launch").asBoolean() if (askVariablesOnLaunch && extraArgs != null) { - payload.put("extra_vars", extraArgs) + payload.set("extra_vars", extraArgs) } - - val strPayload = "$payload" - - return strPayload + return payload.asJsonString(false) } - private fun resolveInventoryIdByName(awxClient : BlueprintWebClientService, inventoryProp: String): Int? { - var invId : Int? = null + private fun resolveInventoryIdByName(awxClient: BlueprintWebClientService, inventoryProp: String): Int? { + var invId: Int? = null // Get Inventory by name val encoded = URLEncoder.encode(inventoryProp) - val response = awxClient.exchangeResource(GET,"/api/v2/inventories/?name=$encoded","") + val response = awxClient.exchangeResource(GET, "/api/v2/inventories/?name=$encoded", "") if (response.status in HTTP_SUCCESS) { // Extract the inventory ID from response val invDetails = mapper.readTree(response.body) diff --git a/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/scripts/InternalSimpleCli.cba.kts b/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/internal/scripts/InternalSimpleCli.kt index e62374747..4c1d92ae6 100644 --- a/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/scripts/InternalSimpleCli.cba.kts +++ b/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/internal/scripts/InternalSimpleCli.kt @@ -16,6 +16,8 @@ @file:Suppress("unused") +package internal.scripts + import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentScriptExecutor @@ -26,10 +28,10 @@ import org.slf4j.LoggerFactory open class TestCliScriptFunction : AbstractScriptComponentFunction() { - private val log = LoggerFactory.getLogger(TestCliScriptFunction::class.java.canonicalName)!! + private val log = LoggerFactory.getLogger(TestCliScriptFunction::class.java)!! override fun getName(): String { - return "SimpleCliConfigure" + return "TestCliScriptFunction" } override suspend fun processNB(executionRequest: ExecutionServiceInput) { diff --git a/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/ComponentCliExecutor.kt b/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/ComponentCliExecutor.kt deleted file mode 100644 index e1d8825ba..000000000 --- a/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/ComponentCliExecutor.kt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright © 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.cli.executor - -import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentFunctionScriptingService -import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentScriptExecutor -import org.springframework.beans.factory.config.ConfigurableBeanFactory -import org.springframework.context.annotation.Scope -import org.springframework.stereotype.Component - -@Component("component-cli-executor") -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class ComponentCliExecutor(private var componentFunctionScriptingService: ComponentFunctionScriptingService) - : ComponentScriptExecutor(componentFunctionScriptingService)
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/cli-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/ComponentCliExecutorTest.kt b/ms/blueprintsprocessor/functions/cli-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/ComponentCliExecutorTest.kt index e9cfddc8c..30e7c8906 100644 --- a/ms/blueprintsprocessor/functions/cli-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/ComponentCliExecutorTest.kt +++ b/ms/blueprintsprocessor/functions/cli-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/ComponentCliExecutorTest.kt @@ -56,12 +56,12 @@ import kotlin.test.assertNotNull class ComponentCliExecutorTest { @Autowired - lateinit var componentCliExecutor: ComponentCliExecutor + lateinit var componentScriptExecutor: ComponentScriptExecutor @Test fun `test CLI Component Instance`() { runBlocking { - assertNotNull(componentCliExecutor, "failed to get ComponentCliExecutor instance") + assertNotNull(componentScriptExecutor, "failed to get ComponentCliExecutor instance") val executionServiceInput = ExecutionServiceInput().apply { commonHeader = CommonHeader().apply { requestId = "1234" @@ -72,8 +72,8 @@ class ComponentCliExecutorTest { payload = JacksonUtils.jsonNode("{}") as ObjectNode } val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234") - componentCliExecutor.bluePrintRuntimeService = bluePrintRuntime - componentCliExecutor.stepName = "sample-step" + componentScriptExecutor.bluePrintRuntimeService = bluePrintRuntime + componentScriptExecutor.stepName = "sample-step" val operationInputs = hashMapOf<String, JsonNode>() operationInputs[BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = "activate-cli".asJsonPrimitive() @@ -81,7 +81,7 @@ class ComponentCliExecutorTest { operationInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] = "operationName".asJsonPrimitive() operationInputs[ComponentScriptExecutor.SCRIPT_TYPE] = BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive() operationInputs[ComponentScriptExecutor.SCRIPT_CLASS_REFERENCE] = - "InternalSimpleCli_cba\$TestCliScriptFunction".asJsonPrimitive() + "internal.scripts.TestCliScriptFunction".asJsonPrimitive() val stepInputData = StepData().apply { name = "activate-cli" @@ -102,7 +102,7 @@ class ComponentCliExecutorTest { "interfaceName", "operationName") } returns operationOutputs - componentCliExecutor.applyNB(executionServiceInput) + componentScriptExecutor.applyNB(executionServiceInput) } } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/cli-executor/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/functions/cli-executor/src/test/resources/logback-test.xml index 626b8f911..688a533be 100644 --- a/ms/blueprintsprocessor/functions/cli-executor/src/test/resources/logback-test.xml +++ b/ms/blueprintsprocessor/functions/cli-executor/src/test/resources/logback-test.xml @@ -27,6 +27,7 @@ <logger name="org.springframework" level="warn"/> <logger name="org.hibernate" level="info"/> <logger name="org.onap.ccsdk.cds.blueprintsprocessor" level="info"/> + <logger name="internal.scripts" level="info"/> <root level="warn"> <appender-ref ref="STDOUT"/> diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt index ee7c31ad2..8b7889d6c 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt @@ -36,10 +36,10 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re override suspend fun processNB(executionRequest: ExecutionServiceInput) { val occurrence = getOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE).asInt() - val resolutionKey = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY)?.asText() ?: "" + val resolutionKey = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY)?.textValue() ?: "" val storeResult = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT)?.asBoolean() ?: false - val resourceId = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID)?.asText() ?: "" - val resourceType = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE)?.asText() ?: "" + val resourceId = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID)?.textValue() ?: "" + val resourceType = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE)?.textValue() ?: "" val properties: MutableMap<String, Any> = mutableMapOf() properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = storeResult diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt index 6cf1c0be7..3bf0b359a 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt @@ -88,7 +88,11 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS val response = restClientService.exchangeResource(verb, urlPath, payload) val responseStatusCode = response.status val responseBody = response.body - if (responseStatusCode in 200..299 && !responseBody.isBlank()) { + val outputKeyMapping = sourceProperties.outputKeyMapping + if (responseStatusCode in 200..299 && outputKeyMapping.isNullOrEmpty()) { + logger.info("AS>> outputKeyMapping==null, will not populateResource") + } + else if (responseStatusCode in 200..299 && !responseBody.isBlank()) { populateResource(resourceAssignment, sourceProperties, responseBody, path) } else { val errMsg = |