Skip to content

Commit

Permalink
Support managing gx-it-proxy via gravity
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Mar 2, 2022
1 parent af545d9 commit 5a5b87a
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
18 changes: 17 additions & 1 deletion gravity/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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:
Expand All @@ -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 = []
Expand All @@ -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)
Expand All @@ -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):
Expand All @@ -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", {})
Expand Down
3 changes: 3 additions & 0 deletions gravity/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@
"concurrency": 2,
"extra_args": ""
}
GXIT_DEFAULT_IP = "localhost"
GXIT_DEFAULT_PORT = 4002
GXIT_DEFAULT_SESSIONS = "database/interactivetools_map.sqlite"
21 changes: 21 additions & 0 deletions gravity/process_manager/supervisor_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
;
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions gravity/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -164,5 +171,6 @@ def service_for_service_type(service_type):
"unicornherder": GalaxyUnicornHerderService,
"celery": GalaxyCeleryService,
"celery-beat": GalaxyCeleryBeatService,
"gx-it-proxy": GalaxyGxItProxyService,
"standalone": GalaxyStandaloneService,
}
24 changes: 24 additions & 0 deletions tests/test_process_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down Expand Up @@ -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()

0 comments on commit 5a5b87a

Please sign in to comment.