From 4ad951ee4c3ed41ca58a240e8b9193416c304b20 Mon Sep 17 00:00:00 2001 From: Oleg Mitsura Date: Wed, 8 Jul 2020 03:07:07 -0400 Subject: cmd-exec server-side timeout. Issue-ID: CCSDK-2535 Signed-off-by: Oleg Mitsura Change-Id: I897678a5a8a23503a878f2d3eb836ba4597a6e6e --- ms/command-executor/src/main/python/utils.py | 33 +++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'ms/command-executor/src/main/python/utils.py') diff --git a/ms/command-executor/src/main/python/utils.py b/ms/command-executor/src/main/python/utils.py index 180cd8c12..54c5ceafa 100644 --- a/ms/command-executor/src/main/python/utils.py +++ b/ms/command-executor/src/main/python/utils.py @@ -17,6 +17,7 @@ from google.protobuf.timestamp_pb2 import Timestamp import proto.CommandExecutor_pb2 as CommandExecutor_pb2 import json +import email.parser CDS_IS_SUCCESSFUL_KEY = "cds_is_successful" ERR_MSG_KEY = "err_msg" @@ -29,6 +30,9 @@ def get_blueprint_id(request): blueprint_version = request.identifiers.blueprintVersion return blueprint_name + '/' + blueprint_version +def get_blueprint_timeout(request): + return request.timeOut + # Create a response for grpc. Fills in the timestamp as well as removes cds_is_successful element def build_grpc_response(request_id, response): if response[CDS_IS_SUCCESSFUL_KEY]: @@ -71,4 +75,31 @@ def truncate_execution_output(execution_output): removed_item = execution_output.response.pop() sum_truncated_chars += len(removed_item) execution_output.response.append("[...] TRUNCATED CHARS : {}".format(sum_truncated_chars)) - return execution_output \ No newline at end of file + return execution_output + + +# Read temp file 'outputfile' into results_log and split out the returned payload into payload_result +def parse_cmd_exec_output(outputfile, logger, payload_result, results_log): + payload_section = [] + is_payload_section = False + outputfile.seek(0) + while True: + output = outputfile.readline() + if output == '': + break + if output.startswith('BEGIN_EXTRA_PAYLOAD'): + is_payload_section = True + output = outputfile.readline() + if output.startswith('END_EXTRA_PAYLOAD'): + is_payload_section = False + output = '' + payload = '\n'.join(payload_section) + msg = email.parser.Parser().parsestr(payload) + for part in msg.get_payload(): + payload_result.update(json.loads(part.get_payload())) + if output and not is_payload_section: + logger.info(output.strip()) + results_log.append(output.strip()) + else: + payload_section.append(output.strip()) + -- cgit 1.2.3-korg