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 reset command from previous branch #724

Merged
merged 15 commits into from
Oct 31, 2023
Merged
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: 1 addition & 1 deletion beeflow/client/bee_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def unpackage(package_path, dest_path):

@app.command('list')
def list_workflows():
"""List all worklfows."""
"""List all workflows."""
try:
conn = _wfm_conn()
resp = conn.get(_url(), timeout=60)
Expand Down
69 changes: 69 additions & 0 deletions beeflow/client/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from beeflow.common.config_driver import BeeConfig as bc
from beeflow.common import cli_connection
from beeflow.common import paths
from beeflow.wf_manager.resources import wf_utils


class ComponentManager:
Expand Down Expand Up @@ -445,6 +446,74 @@ def stop():
print(f'Beeflow has stopped. Check the log at "{beeflow_log}".')


@app.command()
def reset(archive: bool = typer.Option(False, '--archive', '-a',
help='Archive bee_workdir before removal')):
"""Delete the bee_workdir directory."""
# Check to see if the user is absolutely sure. Warning Message.
absolutely_sure = ""
while absolutely_sure != "y" or absolutely_sure != "n":
# Get the user's bee_workdir directory
directory_to_delete = os.path.expanduser(wf_utils.get_bee_workdir())
print(f"A reset will remove this directory: {directory_to_delete}")

absolutely_sure = input(
"""
Are you sure you want to reset?

Please ensure all workflows are complete before running a reset
Check the status of workflows by running 'beeflow list'

A reset will shutdown beeflow and its components.

A reset will delete the bee_workdir directory which results in:
Removing the archive of workflows executed.
Removing the archive of workflow containers.
Reset all databases associated with the beeflow app.
Removing all beeflow logs.

Beeflow configuration files from bee_cfg will remain.

Respond with yes(y)/no(n): """)
if absolutely_sure in ("n", "no"):
# Exit out if the user didn't really mean to do a reset
sys.exit()
if absolutely_sure in ("y", "yes"):
# Stop all of the beeflow processes
resp = cli_connection.send(paths.beeflow_socket(), {'type': 'quit'})
if resp is not None:
print("Beeflow has been shutdown.")
print("Waiting for components to cleanly stop.")
# This wait is essential. It takes a minute to shut down.
time.sleep(5)

if os.path.exists(directory_to_delete):
# Save the bee_workdir directory if the archive option was set
if archive:
if os.path.exists(directory_to_delete + "/logs"):
shutil.copytree(directory_to_delete + "/logs",
directory_to_delete + ".backup/logs")
if os.path.exists(directory_to_delete + "/container_archive"):
shutil.copytree(directory_to_delete + "/container_archive",
directory_to_delete + ".backup/container_archive")
if os.path.exists(directory_to_delete + "/archives"):
shutil.copytree(directory_to_delete + "/archives",
directory_to_delete + ".backup/archives")
if os.path.exists(directory_to_delete + "/workflows"):
shutil.copytree(directory_to_delete + "/workflows",
directory_to_delete + ".backup/workflows")
print("Archive flag enabled,")
print("Existing logs, containers, and workflows backed up in:")
print(f"{directory_to_delete}.backup")
shutil.rmtree(directory_to_delete)
print(f"{directory_to_delete} has been removed.")
sys.exit()
else:
print(f"{directory_to_delete} does not exist. Exiting.")
sys.exit()
print("Please respond with either the letter (y) or (n).")


@app.command()
def restart(foreground: bool = typer.Option(False, '--foreground', '-F',
help='run in the foreground')):
Expand Down
6 changes: 6 additions & 0 deletions docs/sphinx/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ Options:

``beeflow core --version``: Display the version number of BEE.

``beeflow core reset``: Stop the beeflow daemon and cleanup the bee_workdir directory to start from a fresh install.

Options:
``--archive``, ``-a``, Backup logs, workflows, and containers in bee_workdir directory before removal. [optional]

``beeflow core pull-deps``: Pull BEE dependency containers


Submission and workflow commands
================================

Expand Down