From d08286491038484b55474ee038e032e008309708 Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Wed, 17 Jul 2019 13:12:57 -0400 Subject: Enable dynamic remote python executor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I77a60de87acec862ce47256557a1223fefe82a12 Issue-ID: CCSDK-1497 Signed-off-by: Alexis de Talhouët --- .../executor/ComponentRemotePythonExecutor.kt | 31 +++++++++++++--------- .../executor/ComponentRemotePythonExecutorTest.kt | 2 +- 2 files changed, 20 insertions(+), 13 deletions(-) (limited to 'ms/blueprintsprocessor/functions') diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt index fa5d882b0..0f35e6338 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt @@ -44,6 +44,7 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic const val INPUT_ARGUMENT_PROPERTIES = "argument-properties" const val INPUT_COMMAND = "command" const val INPUT_PACKAGES = "packages" + const val DEFAULT_SELECTOR = "remote-python" const val ATTRIBUTE_PREPARE_ENV_LOG = "prepare-environment-logs" const val ATTRIBUTE_EXEC_CMD_LOG = "execute-command-logs" @@ -58,13 +59,13 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic val blueprintVersion = bluePrintContext.version() val operationAssignment: OperationAssignment = bluePrintContext - .nodeTemplateInterfaceOperation(nodeTemplateName, interfaceName, operationName) + .nodeTemplateInterfaceOperation(nodeTemplateName, interfaceName, operationName) val artifactName: String = operationAssignment.implementation?.primary - ?: throw BluePrintProcessorException("missing primary field to get artifact name for node template ($nodeTemplateName)") + ?: throw BluePrintProcessorException("missing primary field to get artifact name for node template ($nodeTemplateName)") val artifactDefinition = - bluePrintRuntimeService.resolveNodeTemplateArtifactDefinition(nodeTemplateName, artifactName) + bluePrintRuntimeService.resolveNodeTemplateArtifactDefinition(nodeTemplateName, artifactName) checkNotBlank(artifactDefinition.file) { "couldn't get python script path($artifactName)" } @@ -90,14 +91,20 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic try { // Open GRPC Connection - remoteScriptExecutionService.init(endPointSelector.asText()) + if (DEFAULT_SELECTOR == endPointSelector.asText()) { + remoteScriptExecutionService.init(endPointSelector.asText()) + } else { + // Get endpoint from DSL + val endPointSelectorJson = bluePrintRuntimeService.resolveDSLExpression(endPointSelector.asText()) + remoteScriptExecutionService.init(endPointSelectorJson) + } // If packages are defined, then install in remote server if (packages != null) { val prepareEnvInput = PrepareRemoteEnvInput(requestId = processId, - remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName, - blueprintVersion = blueprintVersion), - packages = packages + remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName, + blueprintVersion = blueprintVersion), + packages = packages ) val prepareEnvOutput = remoteScriptExecutionService.prepareEnv(prepareEnvInput) log.info("$ATTRIBUTE_PREPARE_ENV_LOG - ${prepareEnvOutput.response}") @@ -111,10 +118,10 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic val properties = dynamicProperties?.returnNullIfMissing()?.rootFieldsToMap() ?: hashMapOf() val remoteExecutionInput = RemoteScriptExecutionInput( - requestId = processId, - remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName, blueprintVersion = blueprintVersion), - command = scriptCommand, - properties = properties) + requestId = processId, + remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName, blueprintVersion = blueprintVersion), + command = scriptCommand, + properties = properties) val remoteExecutionOutput = remoteScriptExecutionService.executeCommand(remoteExecutionInput) log.info("$ATTRIBUTE_EXEC_CMD_LOG - ${remoteExecutionOutput.response}") setAttribute(ATTRIBUTE_EXEC_CMD_LOG, JacksonUtils.jsonNodeFromObject(remoteExecutionOutput.response)) @@ -131,7 +138,7 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { bluePrintRuntimeService.getBluePrintError() - .addError("Failed in ComponentJythonExecutor : ${runtimeException.message}") + .addError("Failed in ComponentJythonExecutor : ${runtimeException.message}") } private fun formatNestedJsonNode(node: JsonNode): String { diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorTest.kt b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorTest.kt index 31aa7c7c1..13202c6ea 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorTest.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorTest.kt @@ -185,7 +185,7 @@ class ComponentRemotePythonExecutorTest { } class MockRemoteScriptExecutionService : RemoteScriptExecutionService { - override suspend fun init(selector: String) { + override suspend fun init(selector: Any) { } override suspend fun prepareEnv(prepareEnvInput: PrepareRemoteEnvInput): RemoteScriptExecutionOutput { -- cgit 1.2.3-korg