Exemplo n.º 1
0
    def cancel_workflow(self, project_id, branch_id):
        """Cancel execution for all running and pending modules in the head
        workflow of a given project branch.

        Returns a handle for the resulting workflow.

        Parameters
        ----------
        project_id : string
            Unique project identifier
        branch_id: string
            Unique workflow branch identifier

        Returns
        -------
        dict()
        """
        # Retrieve the project and branch from the repository to ensure that
        # they exist.
        project = self.engine.projects.get_project(project_id)
        if project is None:
            return None
        branch = project.viztrail.get_branch(branch_id)
        if branch is None:
            return None
        # Cancel excecution and return the workflow handle
        self.engine.cancel_exec(project_id=project_id, branch_id=branch_id)
        return serialwf.WORKFLOW_HANDLE(project=project,
                                        branch=branch,
                                        workflow=branch.head,
                                        urls=self.urls)
Exemplo n.º 2
0
    def insert_workflow_module(self, project_id, branch_id, before_module_id,
                               package_id, command_id, arguments):
        """Append a new module to the head of the identified project branch.
        The module command is identified by the package and command identifier.
        Arguments is a list of command arguments.

        Raises ValueError if the command is unknown or the command arguments
        cannot be validated.

        Parameters
        ----------
        project_id : string
            Unique project identifier
        branch_id: string
            Unique workflow branch identifier
        package_id: string
            Unique package identifier
        command_id: string
            Unique command identifier
        arguments: list
            List of dictionaries representing the user-provided command
            arguments

        Returns
        -------
        dict()
        """
        # Retrieve the project and branch from the repository to ensure that
        # they exist. Run this part first to ensure that all requested resources
        # exist before validating the command.
        project = self.engine.projects.get_project(project_id)
        if project is None:
            return None
        branch = project.viztrail.get_branch(branch_id)
        if branch is None:
            return None
        # Create module command (will ensure that it is a valid command) and
        # insert it into the workflow at the branch head. The result is the list
        # of affected modules.
        modules = self.engine.insert_workflow_module(
            project_id=project_id,
            branch_id=branch_id,
            before_module_id=before_module_id,
            command=ModuleCommand(package_id=package_id,
                                  command_id=command_id,
                                  arguments=arguments,
                                  packages=self.engine.packages),
        )
        if not modules is None:
            return serialwf.WORKFLOW_HANDLE(project=project,
                                            branch=branch,
                                            workflow=branch.head,
                                            urls=self.urls)
        return None
Exemplo n.º 3
0
    def get_workflow(self, project_id, branch_id, workflow_id=None):
        """Retrieve a workflow from a given project branch. If the workflow
        identifier is omitted, the handle for the head of the branch is
        returned.

        Returns None if the project, branch, or workflow do not exist.

        Parameters
        ----------
        project_id : string
            Unique project identifier
        branch_id: string
            Unique workflow branch identifier
        workflow_id: string, optional
            Unique identifier for workflow

        Returns
        -------
        dict
        """
        # Retrieve the project and branch from the repository to ensure that
        # they exist.
        project = self.engine.projects.get_project(project_id)
        if project is None:
            return None
        branch = project.viztrail.get_branch(branch_id)
        if branch is None:
            return None
        # If the branch is empty we return a special empty workflow handle
        if branch.head is None:
            return serialwf.EMPTY_WORKFLOW_HANDLE(project=project,
                                                  branch=branch,
                                                  urls=self.urls)
        else:
            if workflow_id is None:
                workflow = branch.head
            else:
                workflow = branch.get_workflow(workflow_id)
            if workflow is not None:
                return serialwf.WORKFLOW_HANDLE(project=project,
                                                branch=branch,
                                                workflow=workflow,
                                                urls=self.urls)
        return None
Exemplo n.º 4
0
    def delete_workflow_module(self, project_id, branch_id, module_id):
        """Delete a module in the head workflow of the identified project
        branch.

        Returns the handle for the modified head of the workflow branch. The
        result is None if either of the identified resources is unknown.

        Parameters
        ----------
        project_id : string
            Unique project identifier
        branch_id: string
            Unique workflow branch identifier
        module_id: string, optional
            Unique identifier for module

        Returns
        -------
        dict
        """
        # Retrieve the project and branch from the repository to ensure that
        # they exist.
        project = self.engine.projects.get_project(project_id)
        if project is None:
            return None
        branch = project.viztrail.get_branch(branch_id)
        if branch is None:
            return None
        # Delete the module
        modules = self.engine.delete_workflow_module(project_id=project_id,
                                                     branch_id=branch_id,
                                                     module_id=module_id)
        if not modules is None:
            return serialwf.WORKFLOW_HANDLE(project=project,
                                            branch=branch,
                                            workflow=branch.head,
                                            urls=self.urls)
        return None