Пример #1
0
    def submit(
        cls: 'CromwellAPI',
        auth: CromwellAuth,
        wdl_file: Union[str, io.BytesIO],
        inputs_files: Union[List[Union[str, io.BytesIO]], str,
                            io.BytesIO] = None,
        options_file: Union[str, io.BytesIO] = None,
        dependencies: Union[str, List[str], io.BytesIO] = None,
        label_file: Union[str, io.BytesIO] = None,
        collection_name: str = None,
        on_hold: bool = False,
        validate_labels: bool = False,
        raise_for_status: bool = False,
    ) -> requests.Response:
        """ Submits a workflow to Cromwell.

        Args:
            auth: authentication class holding auth information to a
                Cromwell server.
            wdl_file: The workflow source file to submit for execution. Could be either the
                path to the file (str) or the file content in io.BytesIO.
            inputs_files: The input data in JSON
                format. Could be either the path to the file (str) or the file content in io.BytesIO. This could also
                be a list of unlimited input file paths/contents, each of them should have a type of
                Union[str, io.BytesIO].
            options_file: The Cromwell options file for workflows. Could be either
                the path to the file (str) or the file content in io.BytesIO.
            dependencies: Workflow dependency files. Could be the path to
                the zipped file (str) containing dependencies, a list of paths(List[str]) to all dependency files to be
                zipped or a zipped file in io.BytesIO.
            label_file: A collection of key/value pairs for workflow labels in JSON
                format, could be either the path to the JSON file (str) or the file content in io.BytesIO.
            collection_name: Collection in SAM that the workflow should belong to, if use CaaS.
            on_hold: Whether to submit the workflow in "On Hold" status.
            validate_labels: If True, validate cromwell labels.
            raise_for_status: Whether to check and raise for status based on the response.

        Raises:
            requests.exceptions.HTTPError: This will be raised when raise_for_status is True and Cromwell returns
                a response that satisfies 400 <= response.status_code < 600.

        Returns:
            HTTP response from Cromwell.
        """
        submission_manifest = utilities.prepare_workflow_manifest(
            wdl_file=wdl_file,
            inputs_files=inputs_files,
            options_file=options_file,
            dependencies=dependencies,
            label_file=label_file,
            collection_name=collection_name,
            on_hold=on_hold,
        )

        if auth.service_key_content:
            submission_manifest[
                'workflowOptions'] = utilities.compose_oauth_options_for_jes_backend_cromwell(
                    auth, submission_manifest.get('workflowOptions'))

        if validate_labels and label_file is not None:
            validate_cromwell_label(submission_manifest['labels'])

        response = requests.post(
            auth.url + cls._submit_endpoint,
            files=submission_manifest,
            auth=auth.auth,
            headers=auth.header,
        )

        if raise_for_status:
            cls._check_and_raise_status(response)
        return response
Пример #2
0
 def test_validate_cromwell_label_on_valid_labels_str_object(self):
     self.assertIsNone(
         utils.validate_cromwell_label(json.dumps(self.valid_labels)))
Пример #3
0
 def test_validate_cromwell_label_on_valid_labels_bytes_object(self):
     self.assertIsNone(
         utils.validate_cromwell_label(
             json.dumps(self.valid_labels).encode('utf-8')))
Пример #4
0
 def test_validate_cromwell_label_on_valid_labels_object(self):
     self.assertIsNone(utils.validate_cromwell_label(self.valid_labels))