Example #1
0
 def set_up_managers(self):
     super().set_up_managers()
     self.hda_manager = hdas.HDAManager(self.app)
     self.history_manager = HistoryManager(self.app)
     self.dataset_manager = DatasetManager(self.app)
     self.tag_handler = GalaxyTagHandler(self.trans.sa_session)
     self.user = self.user_manager.create(**user2_data)
Example #2
0
 def __init__(self, config: GalaxyDataTestConfig = None, **kwd):
     config = config or GalaxyDataTestConfig(**kwd)
     self.config = config
     self.security = config.security
     self.object_store = objectstore.build_object_store_from_config(
         self.config)
     self.model = init("/tmp",
                       self.config.database_connection,
                       create_tables=True,
                       object_store=self.object_store)
     self.security_agent = self.model.security_agent
     self.tag_handler = GalaxyTagHandler(self.model.context)
     self.init_datatypes()
Example #3
0
    def __init__(
        self,
        model: GalaxyModelMapping,
        security: IdEncodingHelper,
        hda_manager: HDAManager,
        history_manager: HistoryManager,
        tag_handler: GalaxyTagHandler,
        ldda_manager: LDDAManager,
    ):
        self.type_registry = DATASET_COLLECTION_TYPES_REGISTRY
        self.collection_type_descriptions = COLLECTION_TYPE_DESCRIPTION_FACTORY
        self.model = model
        self.security = security

        self.hda_manager = hda_manager
        self.history_manager = history_manager
        self.tag_handler = tag_handler.create_tag_handler_session()
        self.ldda_manager = ldda_manager
Example #4
0
    def __init__(self, **kwargs):
        if not log.handlers:
            # Paste didn't handle it, so we need a temporary basic log
            # configured.  The handler added here gets dumped and replaced with
            # an appropriately configured logger in configure_logging below.
            logging.basicConfig(level=logging.DEBUG)
        log.debug("python path is: %s", ", ".join(sys.path))
        self.name = 'galaxy'
        self.startup_timer = ExecutionTimer()
        self.new_installation = False
        # Read config file and check for errors
        self.config = config.Configuration(**kwargs)
        self.config.check()
        config.configure_logging(self.config)
        self.configure_fluent_log()
        # A lot of postfork initialization depends on the server name, ensure it is set immediately after forking before other postfork functions
        self.application_stack = application_stack_instance(app=self)
        self.application_stack.register_postfork_function(
            self.application_stack.set_postfork_server_name, self)
        self.config.reload_sanitize_whitelist(
            explicit='sanitize_whitelist_file' in kwargs)
        self.amqp_internal_connection_obj = galaxy.queues.connection_from_config(
            self.config)
        # control_worker *can* be initialized with a queue, but here we don't
        # want to and we'll allow postfork to bind and start it.
        self.control_worker = GalaxyQueueWorker(self)

        self._configure_tool_shed_registry()
        self._configure_object_store(fsmon=True)
        # Setup the database engine and ORM
        config_file = kwargs.get('global_conf', {}).get('__file__', None)
        if config_file:
            log.debug('Using "galaxy.ini" config file: %s', config_file)
        check_migrate_tools = self.config.check_migrate_tools
        self._configure_models(
            check_migrate_databases=self.config.check_migrate_databases,
            check_migrate_tools=check_migrate_tools,
            config_file=config_file)

        # Manage installed tool shed repositories.
        self.installed_repository_manager = installed_repository_manager.InstalledRepositoryManager(
            self)

        self._configure_datatypes_registry(self.installed_repository_manager)
        galaxy.model.set_datatypes_registry(self.datatypes_registry)

        # Security helper
        self._configure_security()
        # Tag handler
        self.tag_handler = GalaxyTagHandler(self.model.context)
        self.dataset_collections_service = DatasetCollectionManager(self)
        self.history_manager = HistoryManager(self)
        self.dependency_resolvers_view = DependencyResolversView(self)
        self.test_data_resolver = test_data.TestDataResolver(
            file_dirs=self.config.tool_test_data_directories)
        self.library_folder_manager = FolderManager()
        self.library_manager = LibraryManager()
        self.dynamic_tool_manager = DynamicToolManager(self)

        # Tool Data Tables
        self._configure_tool_data_tables(from_shed_config=False)
        # Load dbkey / genome build manager
        self._configure_genome_builds(data_table_name="__dbkeys__",
                                      load_old_style=True)

        # Genomes
        self.genomes = Genomes(self)
        # Data providers registry.
        self.data_provider_registry = DataProviderRegistry()

        # Initialize job metrics manager, needs to be in place before
        # config so per-destination modifications can be made.
        self.job_metrics = job_metrics.JobMetrics(
            self.config.job_metrics_config_file, app=self)

        # Initialize error report plugins.
        self.error_reports = ErrorReports(self.config.error_report_file,
                                          app=self)

        # Initialize the job management configuration
        self.job_config = jobs.JobConfiguration(self)

        # Setup a Tool Cache
        self.tool_cache = ToolCache()
        self.tool_shed_repository_cache = ToolShedRepositoryCache(self)
        # Watch various config files for immediate reload
        self.watchers = ConfigWatchers(self)
        self._configure_toolbox()

        # Load Data Manager
        self.data_managers = DataManagers(self)
        # Load the update repository manager.
        self.update_repository_manager = update_repository_manager.UpdateRepositoryManager(
            self)
        # Load proprietary datatype converters and display applications.
        self.installed_repository_manager.load_proprietary_converters_and_display_applications(
        )
        # Load datatype display applications defined in local datatypes_conf.xml
        self.datatypes_registry.load_display_applications(self)
        # Load datatype converters defined in local datatypes_conf.xml
        self.datatypes_registry.load_datatype_converters(self.toolbox)
        # Load external metadata tool
        self.datatypes_registry.load_external_metadata_tool(self.toolbox)
        # Load history import/export tools.
        load_lib_tools(self.toolbox)
        # visualizations registry: associates resources with visualizations, controls how to render
        self.visualizations_registry = VisualizationsRegistry(
            self,
            directories_setting=self.config.visualization_plugins_directory,
            template_cache_dir=self.config.template_cache)
        # Tours registry
        self.tour_registry = ToursRegistry(self.config.tour_config_dir)
        # Webhooks registry
        self.webhooks_registry = WebhooksRegistry(self.config.webhooks_dirs)
        # Load security policy.
        self.security_agent = self.model.security_agent
        self.host_security_agent = galaxy.model.security.HostAgent(
            model=self.security_agent.model,
            permitted_actions=self.security_agent.permitted_actions)
        # Load quota management.
        if self.config.enable_quotas:
            self.quota_agent = galaxy.quota.QuotaAgent(self.model)
        else:
            self.quota_agent = galaxy.quota.NoQuotaAgent(self.model)
        # Heartbeat for thread profiling
        self.heartbeat = None
        from galaxy import auth
        self.auth_manager = auth.AuthManager(self)
        # Start the heartbeat process if configured and available (wait until
        # postfork if using uWSGI)
        if self.config.use_heartbeat:
            if heartbeat.Heartbeat:
                self.heartbeat = heartbeat.Heartbeat(
                    self.config,
                    period=self.config.heartbeat_interval,
                    fname=self.config.heartbeat_log)
                self.heartbeat.daemon = True
                self.application_stack.register_postfork_function(
                    self.heartbeat.start)

        if self.config.enable_oidc:
            from galaxy.authnz import managers
            self.authnz_manager = managers.AuthnzManager(
                self, self.config.oidc_config,
                self.config.oidc_backends_config)

        self.sentry_client = None
        if self.config.sentry_dsn:

            def postfork_sentry_client():
                import raven
                self.sentry_client = raven.Client(
                    self.config.sentry_dsn,
                    transport=raven.transport.HTTPTransport)

            self.application_stack.register_postfork_function(
                postfork_sentry_client)

        # Transfer manager client
        if self.config.get_bool('enable_beta_job_managers', False):
            from galaxy.jobs import transfer_manager
            self.transfer_manager = transfer_manager.TransferManager(self)
        # Start the job manager
        from galaxy.jobs import manager
        self.job_manager = manager.JobManager(self)
        self.application_stack.register_postfork_function(
            self.job_manager.start)
        self.proxy_manager = ProxyManager(self.config)

        from galaxy.workflow import scheduling_manager
        # Must be initialized after job_config.
        self.workflow_scheduling_manager = scheduling_manager.WorkflowSchedulingManager(
            self)

        # Must be initialized after any component that might make use of stack messaging is configured. Alternatively if
        # it becomes more commonly needed we could create a prefork function registration method like we do with
        # postfork functions.
        self.application_stack.init_late_prefork()

        self.containers = {}
        if self.config.enable_beta_containers_interface:
            self.containers = build_container_interfaces(
                self.config.containers_config_file,
                containers_conf=self.config.containers_conf)

        # Configure handling of signals
        handlers = {}
        if self.heartbeat:
            handlers[signal.SIGUSR1] = self.heartbeat.dump_signal_handler
        self._configure_signal_handlers(handlers)

        self.database_heartbeat = DatabaseHeartbeat(
            application_stack=self.application_stack)
        self.application_stack.register_postfork_function(
            self.database_heartbeat.start)

        # Start web stack message handling
        self.application_stack.register_postfork_function(
            self.application_stack.start)

        self.model.engine.dispose()

        # Inject url_for for components to more easily optionally depend
        # on url_for.
        self.url_for = url_for

        self.server_starttime = int(time.time())  # used for cachebusting
        log.info("Galaxy app startup finished %s" % self.startup_timer)
Example #5
0
class TagHandlerTestCase(BaseTestCase):
    def set_up_managers(self):
        super().set_up_managers()
        self.hda_manager = hdas.HDAManager(self.app)
        self.history_manager = HistoryManager(self.app)
        self.dataset_manager = DatasetManager(self.app)
        self.tag_handler = GalaxyTagHandler(self.trans.sa_session)
        self.user = self.user_manager.create(**user2_data)

    def _create_vanilla_hda(self, user=None):
        owner = user or self.user
        history1 = self.history_manager.create(name='history1', user=owner)
        dataset1 = self.dataset_manager.create()
        return self.hda_manager.create(history=history1, dataset=dataset1)

    def _check_tag_list(self, tags, expected_tags):
        self.assertEqual(len(tags), len(expected_tags))
        actual_tags = []
        for tag in tags:
            if tag.user_value:
                tag = f"{tag.user_tname}:{tag.user_value}"
            else:
                tag = tag.user_tname
            actual_tags.append(tag)
        expected = [unicodify(e) for e in expected_tags]
        assert sorted(expected) == sorted(
            actual_tags), f"{expected} vs {actual_tags}"

    def test_apply_item_tags(self):
        tag_strings = [
            'tag1',
            'tag1:value1',
            'tag1:value1:value11',
            '\x00tag1',
            'tag1:\x00value1',
            'tag1,tag2',
            '...',
            '.test',
            'test.a.b',
        ]
        expected_tags = [
            ['tag1'],
            ['tag1:value1'],
            ['tag1:value1:value11'],
            ['tag1'],
            ['tag1:value1'],
            ['tag1', 'tag2'],
            [],
            ['test'],
            ['test.a.b'],
        ]
        for tag_string, expected_tag in zip(tag_strings, expected_tags):
            hda = self._create_vanilla_hda()
            self.tag_handler.apply_item_tags(user=self.user,
                                             item=hda,
                                             tags_str=tag_string)
            self._check_tag_list(hda.tags, expected_tag)

    def test_set_tag_from_list(self):
        hda = self._create_vanilla_hda()
        tags = ['tag1', 'tag2']
        self.tag_handler.set_tags_from_list(self.user, hda, tags)
        self._check_tag_list(hda.tags, tags)
        # Setting tags should erase previous tags
        self.tag_handler.set_tags_from_list(self.user, hda, ['tag1'])
        self._check_tag_list(hda.tags, expected_tags=['tag1'])

    def test_add_tag_from_list(self):
        hda = self._create_vanilla_hda()
        tags = ['tag1', 'tag2']
        self.tag_handler.add_tags_from_list(self.user, hda, tags)
        self._check_tag_list(tags=hda.tags, expected_tags=tags)
        # Adding tags should keep previous tags
        self.tag_handler.add_tags_from_list(self.user, hda, ['tag3'])
        self._check_tag_list(hda.tags, expected_tags=['tag1', 'tag2', 'tag3'])

    def test_remove_tag_from_list(self):
        hda = self._create_vanilla_hda()
        tags = ['tag1', 'tag2', 'tag3']
        self.tag_handler.set_tags_from_list(self.user, hda, tags)
        self._check_tag_list(hda.tags, tags)
        self.tag_handler.remove_tags_from_list(self.user, hda,
                                               ['tag1', 'tag3'])
        self._check_tag_list(hda.tags, ['tag2'])

    def test_delete_item_tags(self):
        hda = self._create_vanilla_hda()
        tags = ['tag1']
        self.tag_handler.set_tags_from_list(self.user, hda, tags)
        self.tag_handler.delete_item_tags(user=self.user, item=hda)
        self.assertEqual(hda.tags, [])

    def test_item_has_tag(self):
        hda = self._create_vanilla_hda()
        tags = ['tag1']
        self.tag_handler.set_tags_from_list(self.user, hda, tags)
        self.assertTrue(
            self.tag_handler.item_has_tag(self.user, item=hda, tag='tag1'))
        # ItemTagAssociation
        self.assertTrue(
            self.tag_handler.item_has_tag(self.user, item=hda,
                                          tag=hda.tags[0]))
        # Tag
        self.assertTrue(
            self.tag_handler.item_has_tag(self.user,
                                          item=hda,
                                          tag=hda.tags[0].tag))
        self.assertFalse(
            self.tag_handler.item_has_tag(self.user, item=hda, tag='tag2'))