Skip to content

mag_superset

cli(ctx, verbose)

magasin client is the glue between magasin components, it makes easier common tasks

Source code in mag/mag.py
39
40
41
42
43
44
45
46
@click.group(cls=ClickAliasedGroup)
@click.option('-v', '--verbose', count=True)
@click.option('--version', is_flag=True, callback=print_version,
              expose_value=False, is_eager=True)
@click.pass_context
def cli(ctx, verbose):
    """magasin client is the glue between magasin components, it makes easier common tasks"""
    ctx.ensure_object(dict)

get_namespace(component_name, realm='magasin')

Generate a namespace based on the component name and realm.

Parameters:

Name Type Description Default
component_name str

The magasin component name (superset, daskhub, drill, ...)

required
realm str

The realm. Defaults to 'magasin'.

'magasin'
Example
  • get_namespace("superset", "magasin") -> "magasin-superset"
  • get_namespace("superset", "magasin-postfix") -> "magasin-superset-postfix"
Reference

For more information about magasin realms, please see the magasin realms documentation.

Source code in mag/mag_core/realm.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def get_namespace(component_name: str, realm='magasin') -> str:
    """
    Generate a namespace based on the component name and realm.


    Args:
        component_name (str): The magasin component name (superset, daskhub, drill, ...)
        realm (str, optional): The realm. Defaults to 'magasin'.

    Example:
        * `get_namespace("superset", "magasin")` -> "magasin-superset"
        * `get_namespace("superset", "magasin-postfix")` -> "magasin-superset-postfix"

    Reference:
        For more information about magasin realms, please see the [magasin realms documentation](https://unicef.github.io/magasin/install/advanced.html#magasin-realms).
    """
    prefix, suffix = split_realm(realm)
    namespace = ""
    if prefix:
        namespace = prefix + '-' + component_name
    if suffix:
        namespace = namespace + "-" + suffix
    return namespace

launch_ui(realm, component, service_name, ports, protocol='http', verbose=False)

Launches the user interface for a given realm, component, and service.

Parameters:

Name Type Description Default
realm str

The realm of the magasin instance.

required
component str

The magasin component (f.i superset, daskhub, drill, ...)

required
service_name str

The name of the kubernetes service to forward.

required
ports str

The ports to forward, using the format "local_port:remote_port".

required
protocol str

The protocol to use (default is "http").

'http'
verbose bool

Whether to display verbose output (default is False).

False

Returns:

Name Type Description
None None

Nothing

Source code in mag/mag_core/launch.py
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
def launch_ui(realm: str, component: str, service_name: str, ports: str, protocol: str = "http", verbose=False) -> None:
    """
    Launches the user interface for a given realm, component, and service.

    Args:
        realm (str): The realm of the magasin instance.
        component (str): The magasin component (f.i superset, daskhub, drill, ...)
        service_name (str): The name of the kubernetes service to forward.
        ports (str): The ports to forward, using the format "local_port:remote_port".
        protocol (str, optional): The protocol to use (default is "http").
        verbose (bool, optional): Whether to display verbose output (default is False).

    Returns:
        None: Nothing
    """    
    forward_port(realm=realm, component=component,
                 service_name=service_name, ports=ports, verbose=verbose)

    localhost_port, _ = split_ports(ports)
    url = f"{protocol}://localhost:{localhost_port}"
    click.echo(f"Open browser at: {url}")
    click.launch(url)
    click.echo("launch ui")

    try:
        # Wait for user to press Ctrl+C
        signal.pause()
    except KeyboardInterrupt:
        # Handle Ctrl+C: terminate the server and clean up
        process.terminate()
        os.waitpid(process.pid, 0)
        click.echo("\nServer terminated. Exiting.")

superset(realm)

Apache Superset commands

Source code in mag_superset/superset.py
 8
 9
10
11
12
13
14
@cli.group('superset', cls=ClickAliasedGroup, aliases=['ss'])
@options.realm
def superset(realm):
  """Apache Superset commands"""

  namespace = get_namespace(component_name=COMPONENT, realm=realm)
  click.echo("namespace: " + namespace)

ui(realm, ports)

Launch Superset user interface

Source code in mag_superset/superset.py
16
17
18
19
20
21
@click.command
@options.realm
@options.ports(default="8088:8088")
def ui(realm, ports):
  """Launch Superset user interface"""
  launch_ui(realm, component=COMPONENT, service_name=f"service/superset", ports=ports)