Exemple #1
0
 def __init__(self, app):
     super(HistoryContentsController, self).__init__(app)
     self.hda_manager = hdas.HDAManager(app)
     self.history_manager = histories.HistoryManager(app)
     self.folder_manager = folders.FolderManager()
     self.hda_serializer = hdas.HDASerializer(app)
     self.hda_deserializer = hdas.HDADeserializer(app)
def _get_target_history(trans, workflow, payload, param_keys=None, index=0):
    param_keys = param_keys or []
    history_name = payload.get('new_history_name', None)
    history_id = payload.get('history_id', None)
    history_param = payload.get('history', None)
    if [history_name, history_id, history_param].count(None) < 2:
        raise exceptions.RequestParameterInvalidException("Specified workflow target history multiple ways - at most one of 'history', 'history_id', and 'new_history_name' may be specified.")
    if history_param:
        if history_param.startswith('hist_id='):
            history_id = history_param[8:]
        else:
            history_name = history_param
    if history_id:
        history_manager = histories.HistoryManager(trans.app)
        target_history = history_manager.get_owned(trans.security.decode_id(history_id), trans.user, current_history=trans.history)
    else:
        if history_name:
            nh_name = history_name
        else:
            nh_name = 'History from %s workflow' % workflow.name
        if len(param_keys) <= index:
            raise exceptions.MessageException("Incorrect expansion of workflow batch parameters.")
        ids = param_keys[index]
        nids = len(ids)
        if nids == 1:
            nh_name = '%s on %s' % (nh_name, ids[0])
        elif nids > 1:
            nh_name = '%s on %s and %s' % (nh_name, ', '.join(ids[0:-1]), ids[-1])
        new_history = trans.app.model.History(user=trans.user, name=nh_name)
        trans.sa_session.add(new_history)
        target_history = new_history
    return target_history
 def __init__(self, app):
     super(HistoriesController, self).__init__(app)
     self.citations_manager = citations.CitationsManager(app)
     self.user_manager = users.UserManager(app)
     self.history_manager = histories.HistoryManager(app)
     self.history_serializer = histories.HistorySerializer(app)
     self.history_deserializer = histories.HistoryDeserializer(app)
     self.history_filters = histories.HistoryFilters(app)
Exemple #4
0
 def __init__( self, app ):
     self.type_registry = DatasetCollectionTypesRegistry( app )
     self.collection_type_descriptions = CollectionTypeDescriptionFactory( self.type_registry )
     self.model = app.model
     self.security = app.security
     self.hda_manager = hdas.HDAManager()
     self.history_manager = histories.HistoryManager()
     self.tag_manager = tags.TagsManager( app )
     self.ldda_manager = lddas.LDDAManager( )
Exemple #5
0
 def __init__(self, app):
     super(HistoriesController, self).__init__(app)
     self.citations_manager = citations.CitationsManager(app)
     self.user_manager = users.UserManager(app)
     self.workflow_manager = workflows.WorkflowsManager(app)
     self.manager = histories.HistoryManager(app)
     self.serializer = histories.HistorySerializer(app)
     self.deserializer = histories.HistoryDeserializer(app)
     self.filters = histories.HistoryFilters(app)
Exemple #6
0
    def __init__(self, app):
        self.type_registry = DATASET_COLLECTION_TYPES_REGISTRY
        self.collection_type_descriptions = COLLECTION_TYPE_DESCRIPTION_FACTORY
        self.model = app.model
        self.security = app.security

        self.hda_manager = hdas.HDAManager(app)
        self.history_manager = histories.HistoryManager(app)
        self.tag_handler = tags.GalaxyTagHandler(app.model.context)
        self.ldda_manager = lddas.LDDAManager(app)
Exemple #7
0
 def __init__(self, app):
     super().__init__(app)
     self.citations_manager = citations.CitationsManager(app)
     self.user_manager = users.UserManager(app)
     self.workflow_manager = workflows.WorkflowsManager(app)
     self.manager = histories.HistoryManager(app)
     self.history_export_view = histories.HistoryExportView(app)
     self.serializer = histories.HistorySerializer(app)
     self.deserializer = histories.HistoryDeserializer(app)
     self.filters = histories.HistoryFilters(app)
Exemple #8
0
 def __init__(self, app):
     super(WorkflowsAPIController, self).__init__(app)
     self.history_manager = histories.HistoryManager(app)
     self.workflow_manager = workflows.WorkflowsManager(app)
     self.workflow_contents_manager = workflows.WorkflowContentsManager()
Exemple #9
0
def build_workflow_run_config(trans, workflow, payload):
    app = trans.app
    history_manager = histories.HistoryManager(app)

    # Pull other parameters out of payload.
    param_map = payload.get('parameters', {})
    param_map = normalize_step_parameters(workflow.steps, param_map)
    inputs = payload.get('inputs', None)
    inputs_by = payload.get('inputs_by', None)
    if inputs is None:
        # Default to legacy behavior - read ds_map and reference steps
        # by unencoded step id (a raw database id).
        inputs = payload.get('ds_map', {})
        inputs_by = inputs_by or 'step_id|step_uuid'
    else:
        inputs = inputs or {}
        # New default is to reference steps by index of workflow step
        # which is intrinsic to the workflow and independent of the state
        # of Galaxy at the time of workflow import.
        inputs_by = inputs_by or 'step_index|step_uuid'

    add_to_history = 'no_add_to_history' not in payload
    history_param = payload.get('history', '')
    allow_tool_state_corrections = payload.get('allow_tool_state_corrections',
                                               False)

    # Sanity checks.
    if len(workflow.steps) == 0:
        raise exceptions.MessageException(
            "Workflow cannot be run because it does not have any steps")
    if workflow.has_cycles:
        raise exceptions.MessageException(
            "Workflow cannot be run because it contains cycles")
    if workflow.has_errors:
        message = "Workflow cannot be run because of validation errors in some steps"
        raise exceptions.MessageException(message)

    # Get target history.
    if history_param.startswith('hist_id='):
        # Passing an existing history to use.
        encoded_history_id = history_param[8:]
        history_id = __decode_id(trans,
                                 encoded_history_id,
                                 model_type="history")
        history = history_manager.get_owned(history_id,
                                            trans.user,
                                            current_history=trans.history)
    else:
        # Send workflow outputs to new history.
        history = app.model.History(name=history_param, user=trans.user)
        trans.sa_session.add(history)
        trans.sa_session.flush()

    # Set workflow inputs.
    for input_dict in inputs.itervalues():
        if 'src' not in input_dict:
            message = "Not input source type defined for input '%s'." % input_dict
            raise exceptions.RequestParameterInvalidException(message)
        if 'id' not in input_dict:
            message = "Not input id defined for input '%s'." % input_dict
            raise exceptions.RequestParameterInvalidException(message)
        if 'content' in input_dict:
            message = "Input cannot specify explicit 'content' attribute %s'." % input_dict
            raise exceptions.RequestParameterInvalidException(message)
        input_source = input_dict['src']
        input_id = input_dict['id']
        try:
            if input_source == 'ldda':
                ldda = trans.sa_session.query(
                    app.model.LibraryDatasetDatasetAssociation).get(
                        trans.security.decode_id(input_id))
                assert trans.user_is_admin(
                ) or trans.app.security_agent.can_access_dataset(
                    trans.get_current_user_roles(), ldda.dataset)
                content = ldda.to_history_dataset_association(
                    history, add_to_history=add_to_history)
            elif input_source == 'ld':
                ldda = trans.sa_session.query(app.model.LibraryDataset).get(
                    trans.security.decode_id(
                        input_id)).library_dataset_dataset_association
                assert trans.user_is_admin(
                ) or trans.app.security_agent.can_access_dataset(
                    trans.get_current_user_roles(), ldda.dataset)
                content = ldda.to_history_dataset_association(
                    history, add_to_history=add_to_history)
            elif input_source == 'hda':
                # Get dataset handle, add to dict and history if necessary
                content = trans.sa_session.query(
                    app.model.HistoryDatasetAssociation).get(
                        trans.security.decode_id(input_id))
                assert trans.user_is_admin(
                ) or trans.app.security_agent.can_access_dataset(
                    trans.get_current_user_roles(), content.dataset)
            elif input_source == 'uuid':
                dataset = trans.sa_session.query(app.model.Dataset).filter(
                    app.model.Dataset.uuid == input_id).first()
                if dataset is None:
                    # this will need to be changed later. If federation code is avalible, then a missing UUID
                    # could be found amoung fereration partners
                    message = "Input cannot find UUID: %s." % input_id
                    raise exceptions.RequestParameterInvalidException(message)
                assert trans.user_is_admin(
                ) or trans.app.security_agent.can_access_dataset(
                    trans.get_current_user_roles(), dataset)
                content = history.add_dataset(dataset)
            elif input_source == 'hdca':
                content = app.dataset_collections_service.get_dataset_collection_instance(
                    trans, 'history', input_id)
            else:
                message = "Unknown workflow input source '%s' specified." % input_source
                raise exceptions.RequestParameterInvalidException(message)
            if add_to_history and content.history != history:
                content = content.copy()
                if isinstance(content, app.model.HistoryDatasetAssociation):
                    history.add_dataset(content)
                else:
                    history.add_dataset_collection(content)
            input_dict['content'] = content
        except AssertionError:
            message = "Invalid workflow input '%s' specified" % input_id
            raise exceptions.ItemAccessibilityException(message)

    normalized_inputs = normalize_inputs(workflow.steps, inputs, inputs_by)

    # Run each step, connecting outputs to inputs
    replacement_dict = payload.get('replacement_params', {})

    run_config = WorkflowRunConfig(
        target_history=history,
        replacement_dict=replacement_dict,
        inputs=normalized_inputs,
        param_map=param_map,
        allow_tool_state_corrections=allow_tool_state_corrections)
    return run_config
 def __init__(self, app):
     super(HistoriesController, self).__init__(app)
     self.citations_manager = citations.CitationsManager(app)
     self.mgrs = util.bunch.Bunch(histories=histories.HistoryManager())
Exemple #11
0
 def set_up_managers(self):
     super(CurrentUserSerializerTestCase, self).set_up_managers()
     self.history_manager = histories.HistoryManager(self.app)
     self.user_serializer = users.CurrentUserSerializer(self.app)
Exemple #12
0
 def __init__(self, app):
     super(PluginsController, self).__init__(app)
     self.hda_manager = hdas.HDAManager(app)
     self.history_manager = histories.HistoryManager(app)
Exemple #13
0
 def __init__(self, app):
     super(HistoryContentsController, self).__init__(app)
     self.mgrs = util.bunch.Bunch(histories=histories.HistoryManager(),
                                  hdas=hdas.HDAManager())
Exemple #14
0
 def __init__(self):
     """
     Set up and initialize other managers needed by hdas.
     """
     self.histories_mgr = history_manager.HistoryManager()
Exemple #15
0
 def __init__(self, app):
     super().__init__(app)
     self.hda_manager = hdas.HDAManager(app)
     self.history_manager = histories.HistoryManager(app)
    def run(self, trans, workflow_id, payload, **kwd):
        """
        POST /api_internal/workflows/{encoded_workflow_id}/run

        Run a workflow with a dictionary of prefixed_name/value pairs e.g.
            payload = { inputs: { step_0: { parameter_0|parameter_1 : value_0, ... }, ... } }
        """
        workflow = self.__get_stored_accessible_workflow(
            trans, workflow_id).latest_workflow
        trans.workflow_building_mode = workflow_building_modes.USE_HISTORY
        module_injector = WorkflowModuleInjector(trans)
        params, param_keys = expand_workflow_inputs(payload.get('inputs', []))
        errors = {}
        for workflow_args in params:
            for step in workflow.steps:
                step_args = workflow_args.get(str(step.id), {})
                step_errors = module_injector.inject(step, step_args)
                if step_errors:
                    errors[step.id] = step_errors
        if errors:
            log.exception(errors)
            raise exceptions.MessageException(err_data=errors)
        invocations = []
        for index, workflow_args in enumerate(params):
            for step in workflow.steps:
                step_args = workflow_args.get(str(step.id), {})
                module_injector.inject(step, step_args)
            new_history = None
            if 'new_history_name' in payload:
                if payload['new_history_name']:
                    nh_name = payload['new_history_name']
                else:
                    nh_name = 'History from %s workflow' % workflow.name
                if index in param_keys:
                    ids = param_keys[index]
                    nids = len(ids)
                    if nids == 1:
                        nh_name = '%s on %s' % (nh_name, ids[0])
                    elif nids > 1:
                        nh_name = '%s on %s and %s' % (nh_name, ', '.join(
                            ids[0:-1]), ids[-1])
                new_history = trans.app.model.History(user=trans.user,
                                                      name=nh_name)
                new_history.copy_tags_from(trans.user, trans.history)
                trans.sa_session.add(new_history)
                target_history = new_history
            elif 'history_id' in payload:
                target_history = histories.HistoryManager(trans.app).get_owned(
                    trans.security.decode_id(payload.get('history_id'),
                                             trans.user,
                                             current_history=trans.history))
            else:
                target_history = trans.history
            run_config = WorkflowRunConfig(target_history=target_history,
                                           replacement_dict=payload.get(
                                               'replacement_params', {}),
                                           copy_inputs_to_history=new_history
                                           is not None)
            invocation = queue_invoke(trans=trans,
                                      workflow=workflow,
                                      workflow_run_config=run_config,
                                      populate_state=False)
            invocations.append({
                'history': {
                    'id': trans.app.security.encode_id(new_history.id),
                    'name': new_history.name
                } if new_history else None,
                'scheduled':
                invocation.state ==
                trans.app.model.WorkflowInvocation.states.SCHEDULED
            })
            trans.sa_session.flush()
        return invocations