Application-Hub
The Application Hub provides a unified Cloud infrastructure to manage and deliver work environments and tools for a variety of user tasks. These tasks include developing, hosting, executing, and performing exploratory analysis of Earth Observation (EO) applications. The hub simplifies the management of these tasks within a single, cohesive platform.
Configuration Overview
There are many approach for deployment and one of them is using python based approach. Indeed, the user can generate, and apply the kubernetes objects using python instead of old-fashion approaches. In this tutorial, the user will configure The Application Hub using a Python script, jupyterhub_config.py
. It customizes Application Hub's behavior by defining hooks, authentication, spawner settings, and other configurations.
The key features of the python script are: - Read the configuration - Pre-spawn hook - Post-stop hook
Read the configuration
The configuration file for the Application Hub is located at:
config_path = "/usr/local/etc/applicationhub/config.yml"
Profile list
This method provides the Application pods spawn options. It is a map with one or more Application pod definitions.
A profile is an option shown on the JupyterHub landing page and it defines what container image is used in the pod to spawn.
It also includes the CPU and RAM limits to assign to the pod to spawn.
The profile slug is the key of the selected profile.
Based on the profile slug, the contextualization may include different elements: volumes, config maps or environment variables.
from application_hub_context.app_hub_context import DefaultApplicationHubContext
namespace_prefix = "jupyter"
def custom_options_form(spawner):
spawner.log.info("Configure profile list")
namespace = f"{namespace_prefix}-{spawner.user.name}"
workspace = DefaultApplicationHubContext(
namespace=namespace,
spawner=spawner,
config_path=config_path,
)
spawner.profile_list = workspace.get_profile_list()
return spawner._options_form_default()
Pre-spawn hook
The pre_spawn_hook
is an optional hook function that can be implemented to do bootstrapping work before the spawner starts.
This hook contextualises the Application pod to spawn and:
- may mount config maps
- may mount volumes
- may set pod environment variables
def pre_spawn_hook(spawner):
spawner.http_timeout = 600
profile_slug = spawner.user_options.get("profile", None)
env = os.environ["JUPYTERHUB_ENV"].lower()
spawner.environment["CALRISSIAN_POD_NAME"] = f"jupyter-{spawner.user.name}-{env}"
spawner.log.info(f"Using profile slug {profile_slug}")
namespace = f"{namespace_prefix}-{spawner.user.name}"
workspace = DefaultApplicationHubContext(
namespace=namespace, spawner=spawner, config_path=config_path, skip_namespace_check=False,
)
workspace.initialise()
profile_id = workspace.config_parser.get_profile_by_slug(slug=profile_slug).id
default_url = workspace.config_parser.get_profile_default_url(profile_id=profile_id)
if default_url:
spawner.log.info(f"Setting default url to {default_url}")
spawner.default_url = default_url
Post-stop hook
The post_stop_hook
is an optional hook function that can be implemented to do work after the spawner stops.
This hook does clean-up tasks:
- may delete temporary volumes
- may delete temporary config maps
def post_stop_hook(spawner):
namespace = f"jupyter-{spawner.user.name}"
workspace = DefaultApplicationHubContext(
namespace=namespace, spawner=spawner, config_path=config_path
)
spawner.log.info("Dispose in post stop hook")
workspace.dispose()