diff options
author | Brinda Santh <brindasanth@in.ibm.com> | 2019-04-10 18:14:44 -0400 |
---|---|---|
committer | Alexis de Talhouƫt <adetalhouet89@gmail.com> | 2019-04-16 10:38:50 -0400 |
commit | bc95a55c61685694a930d659bef336989a04df2f (patch) | |
tree | fbe0b9101bc3d6cebf19b5e9d4dd4acb399fdce2 /ms/blueprintsprocessor/functions/python-executor/src | |
parent | 0371cdd595b125da3c10440f6ce5e13fcaa8b0bc (diff) |
Add grpc execution service
Change-Id: Icfbd9cef8775f2f72329ec726309d14377b9188a
Issue-ID: CCSDK-1215
Signed-off-by: Brinda Santh <brindasanth@in.ibm.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.kt | 54 |
1 files changed, 33 insertions, 21 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 d34dbb7e9..31eb38ca4 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 @@ -18,6 +18,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor 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.core.BluePrintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.checkFileExists @@ -26,16 +27,17 @@ import org.onap.ccsdk.cds.controllerblueprints.core.data.OperationAssignment import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile 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 - +@ConditionalOnBean(name = [ExecutionServiceConstant.SERVICE_GRPC_REMOTE_SCRIPT_EXECUTION]) @Component("component-remote-python-executor") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) open class ComponentRemotePythonExecutor(private val remoteScriptExecutionService: RemoteScriptExecutionService) : AbstractComponentFunction() { - private val log = LoggerFactory.getLogger(ComponentRemotePythonExecutor::class.java) + private val log = LoggerFactory.getLogger(ComponentRemotePythonExecutor::class.java)!! companion object { const val INPUT_ENDPOINT_SELECTOR = "endpoint-selector" @@ -63,34 +65,44 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic val pythonScript = normalizedFile(bluePrintContext.rootPath, artifactDefinition.file) checkFileExists(pythonScript) { "python script(${pythonScript.absolutePath}) doesn't exists" } - //TODO ("Get the ENDPOINT SELECTOR and resolve the Remote Server") + val endPointSelector = getOperationInput(INPUT_ENDPOINT_SELECTOR) val dynamicProperties = getOperationInput(INPUT_DYNAMIC_PROPERTIES) // TODO("Python execution command and Resolve some expressions with dynamic properties") val scriptCommand: String = "python ${pythonScript.absolutePath}" - val packages = operationAssignment.implementation?.dependencies - // If dependencies are defined, then install in remote server - if (packages != null && !packages.isEmpty()) { - val prepareEnvInput = PrepareRemoteEnvInput(requestId = processId, + val dependencies = operationAssignment.implementation?.dependencies + + try { + // Open GRPC Connection + remoteScriptExecutionService.init(endPointSelector.asText()) + + // If dependencies are defined, then install in remote server + if (dependencies != null && !dependencies.isEmpty()) { + val prepareEnvInput = PrepareRemoteEnvInput( + requestId = processId, + remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName, blueprintVersion = blueprintVersion), remoteScriptType = RemoteScriptType.PYTHON, - packages = arrayListOf() - ) - val prepareEnvOutput = remoteScriptExecutionService.prepareEnv(prepareEnvInput) - checkNotNull(prepareEnvOutput) { - "failed to get prepare remote env response for requestId(${prepareEnvInput.requestId})" + packages = dependencies + ) + val prepareEnvOutput = remoteScriptExecutionService.prepareEnv(prepareEnvInput) + checkNotNull(prepareEnvOutput) { + "failed to get prepare remote env response for requestId(${prepareEnvInput.requestId})" + } } - } - val remoteExecutionInput = RemoteScriptExecutionInput( - requestId = processId, - remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName, blueprintVersion = blueprintVersion), - remoteScriptType = RemoteScriptType.PYTHON, - command = scriptCommand) - val remoteExecutionOutput = remoteScriptExecutionService.executeCommand(remoteExecutionInput) - checkNotNull(remoteExecutionOutput) { - "failed to get prepare remote command response for requestId(${remoteExecutionOutput.requestId})" + val remoteExecutionInput = RemoteScriptExecutionInput( + requestId = processId, + remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName, blueprintVersion = blueprintVersion), + remoteScriptType = RemoteScriptType.PYTHON, + command = scriptCommand) + val remoteExecutionOutput = remoteScriptExecutionService.executeCommand(remoteExecutionInput) + checkNotNull(remoteExecutionOutput) { + "failed to get prepare remote command response for requestId(${remoteExecutionOutput.requestId})" + } + } finally { + remoteScriptExecutionService.close() } } |