diff --git a/gravity/config_manager.py b/gravity/config_manager.py index e6e1dbe..6ad9688 100644 --- a/gravity/config_manager.py +++ b/gravity/config_manager.py @@ -16,6 +16,9 @@ CELERY_DEFAULT_CONFIG, DEFAULT_INSTANCE_NAME, GUNICORN_DEFAULT_CONFIG, + GXIT_DEFAULT_IP, + GXIT_DEFAULT_PORT, + GXIT_DEFAULT_SESSIONS, ) from gravity.io import debug, error, exception, info, warn from gravity.state import ( @@ -85,6 +88,7 @@ def get_config(self, conf, defaults=None): "app_server": "gunicorn", "gunicorn": GUNICORN_DEFAULT_CONFIG, "celery": CELERY_DEFAULT_CONFIG, + "gx_it_proxy": {}, "handlers": {}, } if defaults is not None: @@ -109,6 +113,7 @@ def get_config(self, conf, defaults=None): config.attribs["gunicorn"] = gravity_config["gunicorn"] config.attribs["celery"] = gravity_config["celery"] config.attribs["handlers"] = gravity_config["handlers"] + config.attribs["gx_it_proxy"] = gravity_config["gx_it_proxy"] # Store gravity version, in case we need to convert old setting config.attribs['gravity_version'] = __version__ webapp_service_names = [] @@ -129,7 +134,6 @@ def get_config(self, conf, defaults=None): config.services.append(service_for_service_type("celery")(config_type=config.config_type)) config.services.append(service_for_service_type("celery-beat")(config_type=config.config_type)) # If this is a Galaxy config, parse job_conf.xml for any *static* standalone handlers - # Marius: Don't think that's gonna work if job config file not defined! # TODO: use galaxy config parsing ? # TODO: if not, need yaml job config parsing job_conf_xml = app_config.get("job_config_file", DEFAULT_JOB_CONFIG_FILE) @@ -149,6 +153,7 @@ def get_config(self, conf, defaults=None): # doesn't parse that part of the job config. See logic in lib/galaxy/web_stack/handlers.py _get_is_handler() to # see how this is determined. self.create_handler_services(gravity_config, config) + self.create_gxit_services(gravity_config, app_config, config) return config def create_handler_services(self, gravity_config, config): @@ -158,6 +163,17 @@ def create_handler_services(self, gravity_config, config): config.services.append( service_for_service_type("standalone")(config_type=config.config_type, service_name=service_name, server_pools=pools)) + def create_gxit_services(self, gravity_config, app_config, config): + if app_config.get("interactivetools_enable") and gravity_config["gx_it_proxy"].get("enable"): + # TODO: resolve against data_dir, or bring in galaxy-config ? + # CWD in supervisor template is galaxy_root, so this should work for simple cases as is + gxit_config = gravity_config['gx_it_proxy'] + gxit_config["sessions"] = app_config.get("interactivetools_map", GXIT_DEFAULT_SESSIONS) + gxit_config["ip"] = gxit_config.get("ip", GXIT_DEFAULT_IP) + gxit_config["port"] = gxit_config.get("port", GXIT_DEFAULT_PORT) + gxit_config["verbose"] = '--verbose' if gxit_config.get("verbose") else '' + config.services.append(service_for_service_type("gx-it-proxy")(config_type=config.config_type, gxit=gxit_config)) + @staticmethod def expand_handlers(gravity_config, config): handlers = gravity_config.get("handlers", {}) diff --git a/gravity/defaults.py b/gravity/defaults.py index 5c6ee24..229f6f4 100644 --- a/gravity/defaults.py +++ b/gravity/defaults.py @@ -14,3 +14,6 @@ "concurrency": 2, "extra_args": "" } +GXIT_DEFAULT_IP = "localhost" +GXIT_DEFAULT_PORT = 4002 +GXIT_DEFAULT_SESSIONS = "database/interactivetools_map.sqlite" diff --git a/gravity/process_manager/supervisor_manager.py b/gravity/process_manager/supervisor_manager.py index d3befbb..1608f80 100644 --- a/gravity/process_manager/supervisor_manager.py +++ b/gravity/process_manager/supervisor_manager.py @@ -116,6 +116,26 @@ {process_name_opt} """ + +SUPERVISORD_SERVICE_TEMPLATES["gx-it-proxy"] = """; +; This file is maintained by Galaxy - CHANGES WILL BE OVERWRITTEN +; + +[program:{program_name}] +command = {command} +directory = {galaxy_root} +umask = {galaxy_umask} +autostart = true +autorestart = true +startsecs = 10 +stopwaitsecs = 10 +numprocs = 1 +stdout_logfile = {log_file} +redirect_stderr = true +{process_name_opt} +""" + + SUPERVISORD_SERVICE_TEMPLATES["standalone"] = """; ; This file is maintained by Galaxy - CHANGES WILL BE OVERWRITTEN ; @@ -237,6 +257,7 @@ def __update_service(self, config_file, config, attribs, service, instance_conf_ "attach_to_pool_opt": attach_to_pool_opt, "gunicorn": attribs["gunicorn"], "celery": attribs["celery"], + "gx_it_proxy": attribs["gx_it_proxy"], "galaxy_umask": service.get("umask", "022"), "program_name": program_name, "process_name_opt": process_name_opt, diff --git a/gravity/state.py b/gravity/state.py index f2d80bf..992fbc1 100644 --- a/gravity/state.py +++ b/gravity/state.py @@ -81,6 +81,13 @@ class GalaxyCeleryBeatService(Service): command_template = "{virtualenv_bin}celery --app galaxy.celery beat --loglevel {celery[loglevel]}" +class GalaxyGxItProxyService(Service): + service_type = "gx-it-proxy" + service_name = "gx-it-proxy" + command_template = "{virtualenv_bin}npx gx-it-proxy --ip {gx_it_proxy[ip]} --port {gx_it_proxy[port]}" \ + " --sessions {gx_it_proxy[sessions]} {gx_it_proxy[verbose]}" + + class GalaxyStandaloneService(Service): service_type = "standalone" service_name = "standalone" @@ -164,5 +171,6 @@ def service_for_service_type(service_type): "unicornherder": GalaxyUnicornHerderService, "celery": GalaxyCeleryService, "celery-beat": GalaxyCeleryBeatService, + "gx-it-proxy": GalaxyGxItProxyService, "standalone": GalaxyStandaloneService, } diff --git a/tests/test_process_manager.py b/tests/test_process_manager.py index 39de9c3..77a310c 100644 --- a/tests/test_process_manager.py +++ b/tests/test_process_manager.py @@ -46,6 +46,19 @@ - job-handler.special """ +GXIT_CONFIG = """ +gravity: + gx_it_proxy: + enable: true + proxy_port: 4002 +galaxy: + interactivetools_enable: true + interactivetools_map: database/interactivetools_map.sqlite + galaxy_infrastructure_url: http://localhost:8080 + interactivetools_upstream_proxy: false + interactivetools_proxy_host: localhost:4002 +""" + def test_update(galaxy_yml, default_config_manager): default_config_manager.add([str(galaxy_yml)]) @@ -97,3 +110,14 @@ def test_static_handlers(default_config_manager, galaxy_yml, job_conf): handler1_config_path = instance_conf_dir / 'galaxy_standalone_handler1.conf' assert handler1_config_path.exists() assert 'galaxy.yml --server-name=handler1 --pid-file=' in handler1_config_path.open().read() + + +def test_gxit_handler(default_config_manager, galaxy_yml): + galaxy_yml.write(GXIT_CONFIG) + default_config_manager.add([str(galaxy_yml)]) + with process_manager.process_manager(state_dir=default_config_manager.state_dir) as pm: + pm.update() + instance_conf_dir = Path(default_config_manager.state_dir) / 'supervisor' / 'supervisord.conf.d' / '_default_.d' + gxit_config_path = instance_conf_dir / 'galaxy_gx-it-proxy_gx-it-proxy.conf' + assert gxit_config_path.exists() + assert 'npx gx-it-proxy --ip localhost --port 4002 --sessions database/interactivetools_map.sqlite' in gxit_config_path.read_text()