Skip to content

Commit

Permalink
Only delete custom workflows registered by wdl-ci
Browse files Browse the repository at this point in the history
Do not delete other custom workflows in the user's namespace.
  • Loading branch information
hkeward committed May 18, 2023
1 parent df69017 commit 7bf0565
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/wdlci/cli/cleanup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import jsonpickle
import os
import sys
from wdlci.auth.refresh_token_auth import RefreshTokenAuth
Expand Down Expand Up @@ -40,9 +41,9 @@ def cleanup_handler(kwargs):
)
workflow_service_client = WorkflowServiceClient(workflow_service_auth)

# purge all custom workflows in the namespace
# TODO maybe add option here to purge all custom workflows, or only those registered in state file
workflow_service_client.purge_custom_workflows()
submission_state = jsonpickle.decode(open(SUBMISSION_JSON, "r").read())
for workflow in submission_state.workflows.values():
workflow_service_client.delete_custom_workflow(workflow)

print("Cleanup complete. Custom workflows purged from namespace")

Expand Down
9 changes: 7 additions & 2 deletions src/wdlci/cli/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,17 @@ def submit_handler(kwargs):
)
sys.exit(e.exit_code)

workflow_id = workflow_service_client.register_workflow(
(
workflow_id,
workflow_etag,
) = workflow_service_client.register_workflow(
test_key,
workflow_config,
transient=True,
)
submission_state.add_workflow(test_key, workflow_id)
submission_state.add_workflow(
test_key, workflow_id, workflow_etag
)

tasks_to_test[test_key] = {
"task": task,
Expand Down
15 changes: 12 additions & 3 deletions src/wdlci/model/submission_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ def __init__(self):
self.engines = {}
self.workflow_runs = []

def add_workflow(self, workflow_key, workflow_id):
def add_workflow(self, workflow_key, workflow_id, workflow_etag):
self.workflows[workflow_key] = SubmissionStateWorkflow(
workflow_key, workflow_id
workflow_key, workflow_id, workflow_etag
)

def add_engine(self, engine_id, engine_json):
Expand All @@ -31,9 +31,10 @@ def submit_all(self):


class SubmissionStateWorkflow(object):
def __init__(self, workflow_key, workflow_id):
def __init__(self, workflow_key, workflow_id, workflow_etag):
self._workflow_key = workflow_key
self._workflow_id = workflow_id
self._workflow_etag = workflow_etag

@property
def workflow_key(self):
Expand All @@ -51,6 +52,14 @@ def workflow_id(self):
def workflow_id(self, workflow_id):
self._workflow_id = workflow_id

@property
def workflow_etag(self):
return self._workflow_etag

@workflow_etag.setter
def workflow_etag(self, workflow_etag):
return self._workflow_etag


class SubmissionStateWorkflowRun(object):
STATUS_UNSUBMITTED = "UNSUBMITTED"
Expand Down
25 changes: 24 additions & 1 deletion src/wdlci/workbench/workflow_service_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,31 @@ def register_workflow(self, workflow_key, workflow_config, transient=False):
f"Could not register workflow [{workflow_key}] on Workbench", 1
)

return response.json()["id"]
workflow_id = response.json()["id"]
workflow_etag = response.headers.get("Etag").strip('"')
return workflow_id, workflow_etag

# Delete individual custom workflows
def delete_custom_workflow(self, workflow):
env = Config.instance().env
base_url, namespace = (
env.workbench_workflow_service_url,
env.workbench_namespace,
)
url = f"{base_url}/{namespace}/workflows/{workflow.workflow_id}"
headers = {
"Authorization": "Bearer " + self.workflow_service_auth.access_token,
"If-Match": workflow.workflow_etag,
}

response = requests.delete(url, headers=headers)
if response.status_code != 204:
raise WdlTestCliExitException(
f"Error when deleting custom workflow {workflow.workflow_key} ({workflow.workflow_id})",
1,
)

# Purge all custom workflows
def purge_custom_workflows(self):
env = Config.instance().env
base_url, namespace = (
Expand Down

0 comments on commit 7bf0565

Please sign in to comment.