Skip to content

mag_drill

mag_drill

add()

Add items to Drill

Source code in mag_drill/drill.py
58
59
60
@drill.group('add', cls=ClickAliasedGroup, aliases=std_aliases.add)
def add():
  """Add items to Drill"""

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)

drill(realm)

Apache Drill commands

Source code in mag_drill/drill.py
12
13
14
15
@cli.group('drill', cls=ClickAliasedGroup, aliases=['dr'])
@options.realm
def drill(realm):
  """Apache Drill commands"""

launch_command(realm, component, pod_name, command='/bin/bash')

Launches a command in a Kubernetes pod.

Parameters:

Name Type Description Default
realm str

The magasin realm (e.g., magasin).

required
component str

The name of the magasin component.

required
pod_name str

The name of the pod.

required
command str

The command to be executed in the pod. Defaults to '/bin/bash'.

'/bin/bash'

Returns:

Type Description

None

Example

launch_command('magasin', 'component_name', 'pod-1', 'ls -l') Running: kubectl exec pod-1 --namespace magasin -ti -- ls -l

Note

This function uses the kubectl command-line tool to execute a command in a Kubernetes pod. Make sure you have kubectl installed and configured properly before using this function.

Source code in mag/mag_core/launch.py
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
def launch_command(realm: str, component: str, pod_name: str, command: str = '/bin/bash'):
    """
    Launches a command in a Kubernetes pod.

    Args:
        realm (str): The magasin realm (e.g., magasin).
        component (str): The name of the magasin component.
        pod_name (str): The name of the pod.
        command (str, optional): The command to be executed in the pod. Defaults to '/bin/bash'.

    Returns:
        None

    Raises:
        None

    Example:
        >>> launch_command('magasin', 'component_name', 'pod-1', 'ls -l')
        Running: kubectl exec pod-1 --namespace magasin -ti -- ls -l
        <output of the command>

    Note:
        This function uses the `kubectl` command-line tool to execute a command in a Kubernetes pod.
        Make sure you have `kubectl` installed and configured properly before using this function.
    """
    namespace = get_namespace(component_name=component, realm=realm)
    user_root = ''

    command = f"kubectl exec {pod_name} --namespace {namespace} -ti -- {command}"
    click.echo(f"Running: {command}")
    subprocess.run(command, shell=True)

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.")

shell(realm, pod_name)

Launch a shell

Source code in mag_drill/drill.py
46
47
48
49
50
51
@drill.command(aliases=std_aliases.shell)
@options.realm
@click.option('-n', '--pod-name', help='name of the pod to open the shell', default='drillbit-0', show_default=True, callback=validate_pod_name_callback)
def shell(realm, pod_name):
  """Launch a shell"""
  launch_command(realm=realm, component=COMPONENT, pod_name=pod_name )

store(realm, endpoint, bucket, access_key, secret_key, ports)

Add MinIO/s3 store

Source code in mag_drill/drill.py
65
66
67
68
69
70
71
72
73
74
75
76
77
@add.command
@options.realm
@options.ports(default="8047:8047")
@click.option('-e', '--endpoint', help='MinIO API Endpoint', default='')
@click.option('-b', '--bucket', help='Bucket')
@click.option('-a', '--access-key', help='Access key / username')
@click.option('-s', '--secret-key', help='Secret key / password')
def store(realm, endpoint, bucket, access_key, secret_key, ports):
  """Add MinIO/s3 store """
  click.echo("Add Minio Store")
  if (endpoint == ""):
    # Use the standard for the realm 
    print("hola")

ui(realm, ports)

Launch Drill user interface

Source code in mag_drill/drill.py
24
25
26
27
28
29
@drill.command
@options.realm
@options.ports(default="8047:8047")
def ui(realm, ports):
  """Launch Drill user interface"""
  launch_ui(realm, component=COMPONENT, service_name=f"service/drill-service", ports=ports, protocol="http")

validate_pod_name(name)

Validates if a Kubernetes pod name is valid according to Kubernetes naming conventions.

Parameters: - name (str): The pod name to validate.

Returns: - bool: True if the pod name is valid, False otherwise.

Source code in mag/mag_core/validators.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def validate_pod_name(name: str) -> bool:
    """
    Validates if a Kubernetes pod name is valid according to Kubernetes naming conventions.

    Parameters:
    - name (str): The pod name to validate.

    Returns:
    - bool: True if the pod name is valid, False otherwise.
    """
    if not name:
        return False

    # Pod name must be no more than 253 characters in length
    if len(name) > 253:
        return False

    # Pod name must consist of lower case alphanumeric characters, '-' or '.', and
    # must start and end with an alphanumeric character
    pattern = re.compile(r'^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$')
    return bool(pattern.match(name))

validate_pod_name_callback(ctx, param, value)

Validates if the pod_name argument has a valid value See: https://click.palletsprojects.com/en/8.1.x/options/#callbacks-for-validation Raises: click.BadParameter: If does

Source code in mag_drill/drill.py
33
34
35
36
37
38
39
40
41
def validate_pod_name_callback(ctx, param, value):
  """Validates if the pod_name argument has a valid value
     See: https://click.palletsprojects.com/en/8.1.x/options/#callbacks-for-validation
  Raises:
      click.BadParameter: If does 
  """
  if not validate_pod_name(value):
      raise click.BadParameter("Podname can only contain letters, numbers, '-' and '.'. Must start and end with an alphanumeric character.")
  return value