def get_data_flow_results(info_str=None): """Ask a TA2 to GetDataflowResults via gRPC""" if info_str is None: err_msg = 'UI Str for PipelineReference is None' return get_failed_precondition_response(err_msg) # -------------------------------- # Is this valid JSON? # -------------------------------- try: raven_dict = json.loads(info_str, object_pairs_hook=OrderedDict) except json.decoder.JSONDecodeError as err_obj: err_msg = 'Failed to convert UI Str to JSON: %s' % (err_obj) return get_failed_precondition_response(err_msg) # -------------------------------- # convert the JSON string to a gRPC request # -------------------------------- try: req = Parse(info_str, dataflow_ext_pb2.PipelineReference()) except ParseError as err_obj: err_msg = 'Failed to convert JSON to gRPC: %s' % (err_obj) return get_failed_precondition_response(err_msg) # In test mode, return canned response # if settings.TA2_STATIC_TEST_MODE: info_dict = dict(pipelineId=raven_dict.get('pipelineId')) return get_grpc_test_json( 'test_responses/get_dataflow_results_ok.json', info_dict) # -------------------------------- # Get the connection, return an error if there are channel issues # -------------------------------- dataflow_stub, err_msg = TA2Connection.get_grpc_dataflow_stub() if err_msg: return get_failed_precondition_sess_response(err_msg) # -------------------------------- # Send the gRPC request # -------------------------------- try: reply = dataflow_stub.GetDataflowResults(req) except Exception as ex: return get_failed_precondition_response(str(ex)) if reply and str(reply) == VAL_GRPC_STATE_CODE_NONE: err_msg = ('Unkown gRPC state.' ' (Was an GetDataflowResults request sent?)') return get_failed_precondition_response(err_msg) # -------------------------------- # Convert the reply to JSON and send it on # -------------------------------- results = map(MessageToJson, reply) result_str = '[' + ', '.join(results) + ']' return result_str
def describe_data_flow(raven_json_str=None): """ Send a PipelineReference to the DescribeDataflow command """ if raven_json_str is None: err_msg = 'No data found for the PipelineReference' return get_failed_precondition_sess_response(err_msg) # -------------------------------- # The UI has sent JSON in string format that contains the PipelineReference # Make sure it's valid JSON # -------------------------------- try: raven_dict = json.loads(raven_json_str) except json.decoder.JSONDecodeError as err_obj: err_msg = 'Failed to convert UI Str to JSON: %s' % (err_obj) return get_failed_precondition_sess_response(err_msg) # -------------------------------- # convert the JSON string to a gRPC request # -------------------------------- try: req = Parse(raven_json_str, dataflow_ext_pb2.PipelineReference()) except ParseError as err_obj: err_msg = 'Failed to convert JSON to gRPC: %s' % (err_obj) return get_failed_precondition_sess_response(err_msg) # In test mode, return canned response # if settings.TA2_STATIC_TEST_MODE: info_dict = dict(pipelineId=raven_dict.get('pipelineId')) return get_grpc_test_json('test_responses/describe_data_flow_ok.json', info_dict) # -------------------------------- # Get the connection, return an error if there are channel issues # -------------------------------- dataflow_stub, err_msg = TA2Connection.get_grpc_dataflow_stub() if err_msg: return get_failed_precondition_sess_response(err_msg) # -------------------------------- # Send the gRPC request # -------------------------------- try: reply = dataflow_stub.DataflowDescription(req) except Exception as ex: return get_failed_precondition_sess_response(str(ex)) # -------------------------------- # Convert the reply to JSON and send it back # -------------------------------- return MessageToJson(reply)