def get_task_meta(username, m_wf_id, wf_id, task_id): """ Returns a collection of task's metadata. :query int start-index: Return results starting from record <start-index> (0 indexed) :query int max-results: Return a maximum of <max-results> records :query string query: Search criteria :query string order: Sorting criteria :query boolean pretty-print: Return formatted JSON response :statuscode 200: OK :statuscode 204: No content; when no workflow metadata found. :statuscode 400: Bad request :statuscode 401: Authentication failure :statuscode 403: Authorization failure :return type: Collection :return resource: TaskMeta """ queries = StampedeWorkflowQueries(g.stampede_db_url) paged_response = queries.get_task_meta(task_id, **g.query_args) if paged_response.total_records == 0: log.debug("Total records is 0; returning HTTP 204 No content") return make_response("", 204, JSON_HEADER) # # Generate JSON Response # response_json = jsonify(paged_response) return make_response(response_json, 200, JSON_HEADER)
def workflow_metadata(recursive=False, submit_dir=".", *args, **kwargs): logging.debug("workflow_metadata") try: root_wf_uuid, wf_uuid = get_workflow_uuid(submit_dir) logging.debug("Workflow UUID: %s" % wf_uuid) db_uri = get_workflow_uri(submit_dir) queries = StampedeWorkflowQueries(db_uri) if recursive: wfs = queries.get_workflows(root_wf_uuid, order="w.root_wf_id, w.parent_wf_id") for wf in wfs.records: print("Workflow %s" % wf.wf_uuid) workflow_metas = queries.get_workflow_meta(wf_uuid).records render_metas(workflow_metas, " ") else: workflow_metas = queries.get_workflow_meta(wf_uuid).records print("Workflow %s" % wf_uuid) render_metas(workflow_metas, " ") except ValueError as e: logging.error(e) sys.exit(1) except ConnectionError as e: logging.error(e) sys.exit(2) except StampedeDBNotFoundError as e: logging.error(e) sys.exit(3)
def get_job_instance_invocations(username, m_wf_id, wf_id, job_id, job_instance_id): queries = StampedeWorkflowQueries(g.stampede_db_url) paged_response = queries.get_job_instance_invocations( wf_id, job_id, job_instance_id, **g.query_args) if paged_response.total_records == 0: log.debug("Total records is 0; returning HTTP 204 No content") return make_response("", 204, JSON_HEADER) # # Generate JSON Response # response_json = jsonify(paged_response) return make_response(response_json, 200, JSON_HEADER)
def task_metadata(abs_task_id=None, submit_dir=".", *args, **kwargs): logging.debug("task_metadata") if not abs_task_id: logging.error("task_id is required") sys.exit(1) try: root_wf_uuid, wf_uuid = get_workflow_uuid(submit_dir) logging.debug("Workflow UUID: %s" % wf_uuid) db_uri = get_workflow_uri(submit_dir) queries = StampedeWorkflowQueries(db_uri) logging.debug("Get task metadata for abs_task_id %s" % abs_task_id) workflow = queries.get_workflow_tasks(wf_uuid, query="t.abs_task_id == %r" % abs_task_id) if workflow.total_filtered == 0: raise ValueError("Invalid task_name %r" % abs_task_id) task_id = workflow.records[0].task_id task_metas = queries.get_task_meta(task_id).records print("Task", abs_task_id) render_metas(task_metas, " ") except ValueError as e: logging.error(e) sys.exit(1) except ConnectionError as e: logging.error(e) sys.exit(2) except StampedeDBNotFoundError as e: logging.error(e) sys.exit(3)
def get_job_instance(username, m_wf_id, wf_id, job_instance_id): """ Returns job instance identified by m_wf_id, wf_id, job_id, job_instance_id. :query boolean pretty-print: Return formatted JSON response :statuscode 200: OK :statuscode 401: Authentication failure :statuscode 403: Authorization failure :statuscode 404: Not found :return type: Record :return resource: JobInstance """ queries = StampedeWorkflowQueries(g.stampede_db_url) record = queries.get_job_instance(job_instance_id) # # Generate JSON Response # response_json = jsonify(record) return make_response(response_json, 200, JSON_HEADER)
def file_metadata(file_name=None, list_files=False, trace=False, submit_dir=".", *args, **kwargs): logging.debug("task_metadata") if trace and not file_name: logging.error("file_name is required when trace is True") sys.exit(1) if not file_name: list_files = True logging.info( "file_name not provided, will list metadata for all files") try: root_wf_uuid, wf_uuid = get_workflow_uuid(submit_dir) logging.debug("Workflow UUID: %s" % wf_uuid) db_uri = get_workflow_uri(submit_dir) queries = StampedeWorkflowQueries(db_uri) if list_files: logging.debug("Get file metadata for all files") workflow_files = queries.get_workflow_files(wf_uuid) if workflow_files.total_filtered == 0: print("No files found") else: logging.debug("Get file metadata for lfn %r" % file_name) workflow_files = queries.get_workflow_files(wf_uuid, query="l.lfn == %r" % file_name) if workflow_files.total_filtered == 0: raise ValueError("Invalid file %r" % file_name) if trace: wf_file = workflow_files.records.values()[0] wf_id = wf_file.extras.wf_id task_id = wf_file.extras.task_id # Get workflow information root_wf = None wf = queries.get_workflow(wf_id) # If workflow is hierarchical workflow, get root workflow information if wf_id != wf.root_wf_id: root_wf = queries.get_workflow(wf.root_wf_id) if root_wf: root_wf_metas = queries.get_workflow_meta( root_wf.wf_id).records print("Root Workflow %s" % root_wf.wf_uuid) render_metas(root_wf_metas, " ") print() wf_metas = queries.get_workflow_meta(wf_id).records print("Workflow %s" % wf.wf_uuid) render_metas(wf_metas, " ") print() task = queries.get_task(task_id) task_metas = queries.get_task_meta(task_id).records print("Task %s" % task.abs_task_id) render_metas(task_metas, " ") print() for wf_file in workflow_files.records: print("File %s" % wf_file.lfn) render_metas(wf_file.meta, " ") except ValueError as e: logging.error(e) sys.exit(1) except ConnectionError as e: logging.error(e) sys.exit(2) except StampedeDBNotFoundError as e: logging.error(e) sys.exit(3)