def workflow_run_post_req(workflow_id): """Submits the workflow for execution Parameters ---------- workflow_id : str The workflow id Returns ------- dict of {str: str} A dictionary of the form: {'status': str, 'message': str} in which status is the status of the request ('error' or 'success') and message is a human readable string with the error message in case that status is 'error'. """ try: wf = ProcessingWorkflow(workflow_id) except QiitaDBUnknownIDError: return { 'status': 'error', 'message': 'Workflow %s does not exist' % workflow_id } wf.submit() return {'status': 'success', 'message': ''}
def test_workflow_handler_post_req(self): params = ('{"max_barcode_errors": 1.5, "barcode_type": "golay_12", ' '"max_bad_run_length": 3, "phred_offset": "auto", ' '"rev_comp": false, "phred_quality_threshold": 3, ' '"input_data": 1, "rev_comp_barcode": false, ' '"rev_comp_mapping_barcodes": false, ' '"min_per_read_length_fraction": 0.75, "sequence_max_n": 0}') obs = workflow_handler_post_req("*****@*****.**", 1, params) wf_id = obs['workflow_id'] wf = ProcessingWorkflow(wf_id) nodes = wf.graph.nodes() self.assertEqual(len(nodes), 1) job = nodes[0] exp = { 'status': 'success', 'message': '', 'workflow_id': wf_id, 'job': { 'id': job.id, 'inputs': [1], 'label': "Split libraries FASTQ", 'outputs': [['demultiplexed', 'Demultiplexed']] } } self.assertEqual(obs, exp)
def test_workflow_handler_post_req(self): next_id = get_count('qiita.processing_job_workflow_root') + 1 obs = workflow_handler_post_req("*****@*****.**", 1, '{"input_data": 1}') wf = ProcessingWorkflow(next_id) nodes = wf.graph.nodes() self.assertEqual(len(nodes), 1) job = nodes[0] exp = { 'status': 'success', 'message': '', 'workflow_id': next_id, 'job': { 'id': job.id, 'inputs': [1], 'label': "Split libraries FASTQ", 'outputs': [['demultiplexed', 'Demultiplexed']] } } self.assertEqual(obs, exp)
def workflow_handler_patch_req(req_op, req_path, req_value=None, req_from=None): """Patches a workflow Parameters ---------- req_op : str The operation to perform on the workflow req_path : str Path parameter with the workflow to patch req_value : str, optional The value that needs to be modified req_from : str, optional The original path of the element Returns ------- dict of {str: str} A dictionary of the form: {'status': str, 'message': str} in which status is the status of the request ('error' or 'success') and message is a human readable string with the error message in case that status is 'error'. """ if req_op == 'add': req_path = [v for v in req_path.split('/') if v] if len(req_path) != 1: return {'status': 'error', 'message': 'Incorrect path parameter'} req_path = req_path[0] try: wf = ProcessingWorkflow(req_path) except QiitaDBUnknownIDError: return { 'status': 'error', 'message': 'Workflow %s does not exist' % req_path } req_value = loads(req_value) dflt_params = DefaultParameters(req_value['dflt_params']) req_params = req_value.get('req_params', None) opt_params = req_value.get('opt_params', None) connections = { ProcessingJob(k): v for k, v in req_value['connections'].items() } job = wf.add(dflt_params, connections=connections, req_params=req_params, opt_params=opt_params) job_cmd = job.command return { 'status': 'success', 'message': '', 'job': { 'id': job.id, 'inputs': list(req_value['connections'].keys()), 'label': job_cmd.name, 'outputs': job_cmd.outputs } } elif req_op == 'remove': req_path = [v for v in req_path.split('/') if v] if len(req_path) != 2: return {'status': 'error', 'message': 'Incorrect path parameter'} wf_id = req_path[0] job_id = req_path[1] wf = ProcessingWorkflow(wf_id) job = ProcessingJob(job_id) wf.remove(job, cascade=True) return {'status': 'success', 'message': ''} else: return { 'status': 'error', 'message': 'Operation "%s" not supported. Current supported ' 'operations: add' % req_op }