summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/python-executor/src
diff options
context:
space:
mode:
authorAlexis de Talhouët <adetalhouet89@gmail.com>2019-04-12 22:25:17 -0400
committerAlexis de Talhouët <adetalhouet89@gmail.com>2019-04-16 10:38:51 -0400
commit6fcfbc12e20e5a853c9204469dac6867b7eb6ccb (patch)
tree22b09b1636831c9c30c672101e46b8e8a81978ae /ms/blueprintsprocessor/functions/python-executor/src
parent5a47fe8d6a7c665db048e1959f484af297a74315 (diff)
Integration Test - Component Executor
Change-Id: Icbe745b30c7bbb973bc9bb29bf547340b32f1b0f Issue-ID: CCSDK-1164 Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
Diffstat (limited to 'ms/blueprintsprocessor/functions/python-executor/src')
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt47
1 files changed, 34 insertions, 13 deletions
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 feadfbbd4..a243f44bf 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
@@ -20,16 +20,20 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.*
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ExecutionServiceConstant
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.RemoteScriptExecutionService
+import org.onap.ccsdk.cds.controllerblueprints.command.api.ResponseStatus
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode
import org.onap.ccsdk.cds.controllerblueprints.core.checkFileExists
import org.onap.ccsdk.cds.controllerblueprints.core.checkNotBlank
import org.onap.ccsdk.cds.controllerblueprints.core.data.OperationAssignment
import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.config.ConfigurableBeanFactory
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean
import org.springframework.context.annotation.Scope
import org.springframework.stereotype.Component
+import java.lang.Exception
@ConditionalOnBean(name = [ExecutionServiceConstant.SERVICE_GRPC_REMOTE_SCRIPT_EXECUTION])
@Component("component-remote-python-executor")
@@ -53,12 +57,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)
+ val artifactDefinition =
+ bluePrintRuntimeService.resolveNodeTemplateArtifactDefinition(nodeTemplateName, artifactName)
checkNotBlank(artifactDefinition.file) { "couldn't get python script path($artifactName)" }
@@ -70,7 +75,7 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic
val dynamicProperties = getOperationInput(INPUT_DYNAMIC_PROPERTIES)
// TODO("Python execution command and Resolve some expressions with dynamic properties")
- val scriptCommand = "${pythonScript.absolutePath}"
+ val scriptCommand = pythonScript.absolutePath
val dependencies = operationAssignment.implementation?.dependencies
@@ -78,34 +83,50 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic
// Open GRPC Connection
remoteScriptExecutionService.init(endPointSelector.asText())
+ var executionLogs = ""
+
// If dependencies are defined, then install in remote server
if (dependencies != null && dependencies.isNotEmpty()) {
val prepareEnvInput = PrepareRemoteEnvInput(requestId = processId,
- remoteScriptType = RemoteScriptType.PYTHON,
- packages = dependencies
+ remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName,
+ blueprintVersion = blueprintVersion),
+ remoteScriptType = RemoteScriptType.PYTHON,
+ packages = dependencies
)
val prepareEnvOutput = remoteScriptExecutionService.prepareEnv(prepareEnvInput)
- checkNotNull(prepareEnvOutput.status) {
+ executionLogs = prepareEnvOutput.response
+ setOutput(executionLogs)
+ check(prepareEnvOutput.status == StatusType.SUCCESS) {
"failed to get prepare remote env response status for requestId(${prepareEnvInput.requestId})"
}
}
val remoteExecutionInput = RemoteScriptExecutionInput(
- requestId = processId,
- remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName, blueprintVersion = blueprintVersion),
- remoteScriptType = RemoteScriptType.PYTHON,
- command = scriptCommand)
+ requestId = processId,
+ remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName, blueprintVersion = blueprintVersion),
+ remoteScriptType = RemoteScriptType.PYTHON,
+ command = scriptCommand)
val remoteExecutionOutput = remoteScriptExecutionService.executeCommand(remoteExecutionInput)
- checkNotNull(remoteExecutionOutput.status) {
+ executionLogs += remoteExecutionOutput.response
+ setOutput(executionLogs)
+ check(remoteExecutionOutput.status == StatusType.SUCCESS) {
"failed to get prepare remote command response status for requestId(${remoteExecutionOutput.requestId})"
}
+
+ } catch (e: Exception) {
+ log.error("", e)
} finally {
remoteScriptExecutionService.close()
}
}
+ private fun setOutput(executionLogs: String) {
+ bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName,
+ "execution-logs", JacksonUtils.jsonNodeFromObject(executionLogs))
+ }
+
override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
bluePrintRuntimeService.getBluePrintError()
- .addError("Failed in ComponentJythonExecutor : ${runtimeException.message}")
+ .addError("Failed in ComponentJythonExecutor : ${runtimeException.message}")
}
} \ No newline at end of file