diff options
author | Oleg Mitsura <oleg.mitsura@amdocs.com> | 2019-12-19 16:47:14 -0500 |
---|---|---|
committer | Oleg Mitsura <oleg.mitsura@amdocs.com> | 2019-12-23 10:20:40 -0500 |
commit | 3f56fcfec7d14e7351280b9e2a1d220638626693 (patch) | |
tree | 121c3c6451bf594eea12d80070b16bc1be970664 /ms/blueprintsprocessor/functions/python-executor | |
parent | 88ccf0099a32076dc9a1f63c5748fbb83a67fb1a (diff) |
execution timeout not respected...
Issue-ID: CCSDK-2012
rev1: initial commit
rev2: reworked + added grpc deadline
rev3: wrong err msg..
rev4: timeouts in millis
rev5: timeout defaulting was after logging...
Signed-off-by: Oleg Mitsura <oleg.mitsura@amdocs.com>
Change-Id: I02eb414904cc5dfcf51ff7b7552dafe54857ed1e
Diffstat (limited to 'ms/blueprintsprocessor/functions/python-executor')
-rw-r--r-- | ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt | 33 |
1 files changed, 28 insertions, 5 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 6b1f186c9..3250cd3a2 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 @@ -17,6 +17,10 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor import com.fasterxml.jackson.databind.JsonNode +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.TimeoutCancellationException +import kotlinx.coroutines.async +import kotlinx.coroutines.withTimeout 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 @@ -128,17 +132,36 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic requestId = processId, remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName, blueprintVersion = blueprintVersion), command = scriptCommand, - properties = properties) - val remoteExecutionOutput = remoteScriptExecutionService.executeCommand(remoteExecutionInput) + properties = properties, + timeOut = timeout.toLong()) + + + val remoteExecutionOutputDeferred = GlobalScope.async { + remoteScriptExecutionService.executeCommand(remoteExecutionInput) + } + + val remoteExecutionOutput = withTimeout(timeout * 1000L) { + remoteExecutionOutputDeferred.await() + } + + checkNotNull(remoteExecutionOutput) { + "Error: Request-id $processId did not return a restul from remote command execution." + } val logs = JacksonUtils.jsonNodeFromObject(remoteExecutionOutput.response) if (remoteExecutionOutput.status != StatusType.SUCCESS) { - setNodeOutputErrors(remoteExecutionOutput.status.name,logs, remoteExecutionOutput.payload) + setNodeOutputErrors(remoteExecutionOutput.status.name, logs, remoteExecutionOutput.payload) } else { setNodeOutputProperties(remoteExecutionOutput.status.name.asJsonPrimitive(), logs, - remoteExecutionOutput.payload) + remoteExecutionOutput.payload) } + } catch (timeoutEx: TimeoutCancellationException) { + setNodeOutputErrors(status = "Command executor timed out after $timeout seconds", message = "".asJsonPrimitive()) + log.error("Command executor timed out after $timeout seconds", timeoutEx) + } catch (grpcEx: io.grpc.StatusRuntimeException) { + setNodeOutputErrors(status = "Command executor timed out in GRPC call", message = "${grpcEx.status}".asJsonPrimitive()) + log.error("Command executor time out during GRPC call", grpcEx) } catch (e: Exception) { log.error("Failed to process on remote executor", e) } finally { @@ -176,7 +199,7 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic /** * Utility function to set the output properties and errors of the executor node, in cas of errors */ - private fun setNodeOutputErrors(status: String, message: JsonNode, artifacts: JsonNode = "".asJsonPrimitive() ) { + private fun setNodeOutputErrors(status: String, message: JsonNode, artifacts: JsonNode = "".asJsonPrimitive()) { setAttribute(ATTRIBUTE_EXEC_CMD_STATUS, status.asJsonPrimitive()) setAttribute(ATTRIBUTE_EXEC_CMD_LOG, message) setAttribute(ATTRIBUTE_RESPONSE_DATA, artifacts) |