Removed redundant timeout handling for executeCommand 86/122886/1
authorJulien Fontaine <julien.fontaine@bell.ca>
Tue, 27 Jul 2021 16:43:24 +0000 (12:43 -0400)
committerJulien Fontaine <julien.fontaine@bell.ca>
Tue, 27 Jul 2021 16:56:17 +0000 (12:56 -0400)
executeCommand was called from a GlobalScope.async coroutine to handle executeCommand timeout.
Execution timeout is already handled on the gRPC side, there's no need to handle this timeout by wrapping the gRPC call with a coroutine timeout.
When a lot of long running processes in executeCommand were running, it was causing process to queue on BP side to get their executeCommand executed because all the capacity of couroutines were being used by some long running process.
This was causing a delay on the execution of prepareEnv and executeCommand and would even some time make those process timeout because of component timeout.

Issue-ID: CCSDK-3386
Signed-off-by: Julien Fontaine <julien.fontaine@bell.ca>
Change-Id: If3aef4b6b65006e874525436bf3f6d1b1a3d8c9a

ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt

index 539e03d..5f6d98f 100644 (file)
@@ -19,10 +19,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor
 
 import com.fasterxml.jackson.databind.JsonNode
 import com.google.protobuf.ByteString
-import kotlinx.coroutines.GlobalScope
-import kotlinx.coroutines.TimeoutCancellationException
-import kotlinx.coroutines.async
-import kotlinx.coroutines.withTimeout
 import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService
 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.PrepareRemoteEnvInput
@@ -205,13 +201,7 @@ open class ComponentRemotePythonExecutor(
                     timeOut = executionTimeout.toLong()
                 )
 
-                val remoteExecutionOutputDeferred = GlobalScope.async {
-                    remoteScriptExecutionService.executeCommand(remoteExecutionInput)
-                }
-
-                val remoteExecutionOutput = withTimeout(executionTimeout * 1000L + TIMEOUT_DELTA) {
-                    remoteExecutionOutputDeferred.await()
-                }
+                val remoteExecutionOutput = remoteScriptExecutionService.executeCommand(remoteExecutionInput)
 
                 checkNotNull(remoteExecutionOutput) {
                     "Error: Request-id $processId did not return a result from remote command execution."
@@ -226,17 +216,11 @@ open class ComponentRemotePythonExecutor(
                 } else {
                     setNodeOutputProperties(remoteExecutionOutput.status, STEP_EXEC_CMD, logs, returnedPayload, isLogResponseEnabled)
                 } // In timeout exception cases, we don't have payload, hence `payload` is empty value.
-            } catch (timeoutEx: TimeoutCancellationException) {
+            } catch (grpcEx: io.grpc.StatusRuntimeException) {
                 val componentLevelWarningMsg =
                     if (timeout < executionTimeout) "Note: component-level timeout ($timeout) is shorter than execution timeout ($executionTimeout). " else ""
                 val timeoutErrMsg =
-                    "Command executor execution timeout. DetailedMessage: (${timeoutEx.message}) requestId ($processId). $componentLevelWarningMsg"
-                setNodeOutputErrors(STEP_EXEC_CMD, listOf(timeoutErrMsg).asJsonType(), logging = isLogResponseEnabled)
-                addError(StatusType.FAILURE.name, STEP_EXEC_CMD, timeoutErrMsg)
-                log.error(timeoutErrMsg, timeoutEx)
-            } catch (grpcEx: io.grpc.StatusRuntimeException) {
-                val timeoutErrMsg =
-                    "Command executor timed out executing after $executionTimeout seconds requestId ($processId) grpcErr: ${grpcEx.status}"
+                    "Command executor timed out executing after $executionTimeout seconds requestId ($processId). $componentLevelWarningMsg grpcErr: ${grpcEx.status}"
                 setNodeOutputErrors(STEP_EXEC_CMD, listOf(timeoutErrMsg).asJsonType(), logging = isLogResponseEnabled)
                 addError(StatusType.FAILURE.name, STEP_EXEC_CMD, timeoutErrMsg)
                 log.error(timeoutErrMsg, grpcEx)