Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cli commands #977

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions beeflow/client/bee_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from beeflow.common.parser import CwlParser
from beeflow.common.wf_data import generate_workflow_id
from beeflow.client import core
from beeflow.client import remote_client
from beeflow.wf_manager.resources import wf_utils
from beeflow.common.db import client_db
from beeflow.common.db import bdb
Expand Down Expand Up @@ -291,6 +292,7 @@ def get_wf_status(wf_id):

app = typer.Typer(no_args_is_help=True, add_completion=False, cls=NaturalOrderGroup)
app.add_typer(core.app, name='core')
app.add_typer(remote_client.app, name='remote')
app.add_typer(config_driver.app, name='config')


Expand Down
79 changes: 79 additions & 0 deletions beeflow/client/remote_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python3

"""remote-client.

This script provides a client interface to the user to manage workflows remotely.
Capabilities include checking the connection to the client, getting the droppoint location,
copying files to the droppoint, and submitting the workflow to the client.
"""
import subprocess
import pathlib

import typer

from beeflow.common.config_driver import BeeConfig as bc


def remote_port_val():
"""Return the value of the remote port."""
return bc.get('DEFAULT', 'remote_api_port')


app = typer.Typer(no_args_is_help=True)


@app.command()
def connection(ssh_target: str = typer.Argument(..., help='the target to ssh to')):
"""Check the connection to Beeflow client via REST API."""
port = remote_port_val()
result = subprocess.run(["curl", f"{ssh_target}:{port}/"], stdout=subprocess.PIPE,
stderr=subprocess.PIPE, text=True, check=True)
if result.returncode == 0:
print(result.stdout)
else:
print(f"Error: {result.stderr}")


@app.command()
def droppoint(ssh_target: str = typer.Argument(..., help='the target to ssh to')):
"""Request drop point location on remote machine via Beeflow client REST API."""
port = remote_port_val()
with open('droppoint.env', 'w', encoding='utf-8') as output_file:
subprocess.run(["curl", f"{ssh_target}:{port}/droppoint"], stdout=output_file, check=True)


@app.command()
def copy(file_path: pathlib.Path = typer.Argument(..., help="path to copy to droppoint")):
"""Copy path to droppoint."""
droppoint_result = subprocess.run(
["jq", "-r", ".droppoint", "droppoint.env"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=True
)

droppoint_path = droppoint_result.stdout.strip()
print(f"Copying {str(file_path)} to {droppoint_path}")

if file_path.is_dir():
subprocess.run(["scp", "-r", str(file_path), droppoint_path], check=True)
else:
subprocess.run(["scp", str(file_path), droppoint_path], check=True)


@app.command()
def submit(ssh_target: str = typer.Argument(..., help='the target to ssh to'),
wf_name: str = typer.Argument(..., help='the workflow name'),
tarball_name: str = typer.Argument(..., help='the tarball name'),
main_cwl_file: str = typer.Argument(..., help='filename of main CWL'),
job_file: str = typer.Argument(..., help='filename of yaml file')):
"""Submit the workflow to Beeflow client."""
port = remote_port_val()
subprocess.run(
[
"curl",
f"{ssh_target}:{port}/submit_long/{wf_name}/{tarball_name}/{main_cwl_file}/{job_file}"
],
check=True
)
12 changes: 12 additions & 0 deletions docs/sphinx/rest_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ The REST API was created primarily for the purpose of connecting CI resources to
:show-refs: True


Usage
-----
The following sequence of commands can be used to remotely prepare and submit workflows to the system:

.. code-block::

beeflow remote connection $SSH_TARGET # check the connection to the Beeflow client
beeflow remote droppoint $SSH_TARGET # get the drop point location on the remote machine
beeflow remote copy $PATH # copy path for the workflow to the droppoint
beeflow remote submit $SSH_TARGET $WF_NAME $TARBALL $MAIN_CWL $YAML # submit the workflow


Endpoints
----------
.. autofunction:: beeflow.remote.remote.get_wf_status
Expand Down
Loading