Exemplo n.º 1
0
    def get_workflow(self, project_id, branch_id, workflow_id=None):
        """Get a workflow resource. If the identifier is None the branch head
        will be returned.

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

        Returns
        -------
        vizier.api.client.resources.workflow.WorkflowResource
        """
        # Fetch workflow handle from server
        if workflow_id is None:
            url = self.urls.get_branch_head(
                project_id=project_id,
                branch_id=branch_id
            )
        else:
            url = self.urls.get_workflow(
                project_id=project_id,
                branch_id=branch_id,
                workflow_id=workflow_id
            )
        response = urllib.request.urlopen(url)
        data = json.loads(response.read())
        # Convert result into instance of a workflow resource
        return WorkflowResource.from_dict(data)
Exemplo n.º 2
0
    def from_dict(obj):
        """Get a branch resource instance from the dictionary representation
        returned by the vizier web service.

        Parameters
        ----------
        obj: dict
            Dictionary serialization of a branch descriptor or handle

        Returns
        -------
        vizier.api.client.resources.branch.BranchResource
        """
        # Get the name from the properties list
        name = None
        for prop in obj['properties']:
            if prop['key'] == 'name':
                name = prop['value']
                break
        workflows = None
        if 'workflows' in obj:
            workflows = [
                WorkflowResource.from_dict(wf) for wf in obj['workflows']
            ]
        return BranchResource(identifier=obj['id'],
                              name=name,
                              created_at=to_datetime(obj['createdAt']),
                              last_modified_at=to_datetime(
                                  obj['lastModifiedAt']),
                              workflows=workflows)
Exemplo n.º 3
0
    def append_cell(self, command):
        """Append a new module to the notebook that executes te given command.

        Parameters
        ----------
        command: vizier.viztrail.command.ModuleCommand

        Returns
        -------
        vizier.api.client.resources.workflow.WorkflowResource
        """
        # Get append url and create request body
        url = self.links[ref.WORKFLOW_APPEND]
        data = {
            labels.COMMAND_PACKAGE: command.package_id,
            labels.COMMAND_ID: command.command_id,
            labels.COMMAND_ARGS: command.arguments.to_list()
        }
        # Send request. Raise exception if status code indicates that the
        # request was not successful
        r = requests.post(url, json=data)
        r.raise_for_status()
        # The returned update statement is a reduced version of the workflow
        # handle that contains the modules that were affected by the append
        # operation
        return WorkflowResource.from_dict(json.loads(r.text))
Exemplo n.º 4
0
    def replace_cell(self, command, module_id):
        """Replace the command for the module with the given identifier.

        Parameters
        ----------
        command: vizier.viztrail.command.ModuleCommand
            The command that is executed in the new notebook cell
        module_id: string
            Unique module identifier

        Returns
        -------
        vizier.api.client.resources.workflow.WorkflowResource
        """
        # Get the module with the given identifier
        module = self.get_module(module_id)
        url = module.links[ref.MODULE_REPLACE]
        data = {
            labels.COMMAND_PACKAGE: command.package_id,
            labels.COMMAND_ID: command.command_id,
            labels.COMMAND_ARGS: command.arguments.to_list()
        }
        # Send request. Raise exception if status code indicates that the
        # request was not successful
        r = requests.put(url, json=data)
        r.raise_for_status()
        # handle that contains the modules that were affected by the replace
        # operation
        return WorkflowResource.from_dict(json.loads(r.text))
Exemplo n.º 5
0
    def cancel_exec(self):
        """Cancel exection of tasks for the notebook.

        Returns
        -------
        vizier.api.client.resources.workflow.WorkflowResource
        """
        url = self.workflow.links[ref.WORKFLOW_CANCEL]
        r = requests.post(url)
        r.raise_for_status()
        # The returned update statement is a reduced version of the workflow
        # handle that contains the modules that were affected by the operation
        return WorkflowResource.from_dict(json.loads(r.text))
Exemplo n.º 6
0
    def delete_module(self, module_id):
        """Delete the notebook module with the given identifier.

        Returns
        -------
        vizier.api.client.resources.workflow.WorkflowResource
        """
        module = self.get_module(module_id)
        url = module.links[ref.MODULE_DELETE]
        r = requests.delete(url)
        r.raise_for_status()
        # The returned update statement is a reduced version of the
        # workflow handle that contains the modules that were affected
        # by the delete operation
        return WorkflowResource.from_dict(json.loads(r.text))