Enable dynamic remote python executor 20/91620/4
authorAlexis de Talhouët <adetalhouet89@gmail.com>
Wed, 17 Jul 2019 17:12:57 +0000 (13:12 -0400)
committerAlexis de Talhouët <adetalhouet89@gmail.com>
Wed, 17 Jul 2019 19:49:56 +0000 (19:49 +0000)
Change-Id: I77a60de87acec862ce47256557a1223fefe82a12
Issue-ID: CCSDK-1497
Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt
ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorTest.kt
ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/RemoteScriptExecutionService.kt

index fa5d882..0f35e63 100644 (file)
@@ -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 {
index 3af57a2..d4195ae 100644 (file)
@@ -22,6 +22,7 @@ import com.google.protobuf.Timestamp
 import com.google.protobuf.util.JsonFormat
 import io.grpc.ManagedChannel
 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.*
+import org.onap.ccsdk.cds.blueprintsprocessor.grpc.service.BluePrintGrpcClientService
 import org.onap.ccsdk.cds.blueprintsprocessor.grpc.service.BluePrintGrpcLibPropertyService
 import org.onap.ccsdk.cds.controllerblueprints.command.api.*
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
@@ -31,9 +32,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
 import org.springframework.context.annotation.Scope
 import org.springframework.stereotype.Service
 
-
 interface RemoteScriptExecutionService {
-    suspend fun init(selector: String)
+    suspend fun init(selector: Any)
     suspend fun prepareEnv(prepareEnvInput: PrepareRemoteEnvInput): RemoteScriptExecutionOutput
     suspend fun executeCommand(remoteExecutionInput: RemoteScriptExecutionInput): RemoteScriptExecutionOutput
     suspend fun close()
@@ -51,9 +51,14 @@ class GrpcRemoteScriptExecutionService(private val bluePrintGrpcLibPropertyServi
     private var channel: ManagedChannel? = null
     private lateinit var commandExecutorServiceGrpc: CommandExecutorServiceGrpc.CommandExecutorServiceBlockingStub
 
-    override suspend fun init(selector: String) {
+    override suspend fun init(selector: Any) {
         // Get the GRPC Client Service based on selector
-        val grpcClientService = bluePrintGrpcLibPropertyService.blueprintGrpcClientService(selector)
+        val grpcClientService: BluePrintGrpcClientService
+        if (selector is JsonNode) {
+            grpcClientService = bluePrintGrpcLibPropertyService.blueprintGrpcClientService(selector)
+        } else {
+            grpcClientService = bluePrintGrpcLibPropertyService.blueprintGrpcClientService(selector.toString())
+        }
         // Get the GRPC Channel
         channel = grpcClientService.channel()
         // Create Non Blocking Stub