Skip to content

Commit

Permalink
Merge 489c5bc into 4422c17
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinos Kousidis committed Nov 1, 2018
2 parents 4422c17 + 489c5bc commit c96be4b
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
30 changes: 30 additions & 0 deletions reana_client/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,33 @@ def upload_to_server(self, workflow, paths, access_token):
logging.debug(str(e))
logging.info("Something went wrong while uploading {}".
format(fname))

def delete_workflow(self, workflow, all_runs, hard_delete, access_token):
"""Delete a workflow."""
try:
parameters = {'all_runs': all_runs,
'hard_delete': hard_delete}
(response,
http_response) = self._client.api.set_workflow_status(
workflow_id_or_name=workflow,
status='deleted',
access_token=access_token,
parameters=parameters).result()
if http_response.status_code == 200:
return response
else:
raise Exception(
"Expected status code 200 but replied with "
"{status_code}".format(
status_code=http_response.status_code))

except HTTPError as e:
logging.debug(
'Workflow run could not be deleted: '
'\nStatus: {}\nReason: {}\n'
'Message: {}'.format(e.response.status_code,
e.response.reason,
e.response.json()['message']))
raise Exception(e.response.json()['message'])
except Exception as e:
raise e
62 changes: 62 additions & 0 deletions reana_client/cli/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,71 @@ def workflow_validate(ctx, file):
err=True)


@click.command(
'delete',
help='Delete a workflow run.')
@click.option(
'-A',
'--all',
'all_runs',
count=True,
help='Delete all runs of a given workflow.')
@click.option(
'--hard',
'hard_delete',
count=True,
help='Completely remove workflow run data and workspace from REANA.')
@click.option(
'-w',
'--workflow',
default=os.environ.get('REANA_WORKON', None),
callback=workflow_uuid_or_name,
help='Name and run number to be deleted. '
'Overrides value of REANA_WORKON.')
@add_access_token_options
@click.pass_context
@with_api_client
def workflow_delete_run(ctx, workflow, all_runs, hard_delete, access_token):
"""Delete a workflow run given the workflow name and run number."""
logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
for p in ctx.params:
logging.debug('{param}: {value}'.format(param=p, value=ctx.params[p]))

if not access_token:
click.echo(
click.style(ERROR_MESSAGES['missing_access_token'],
fg='red'), err=True)
sys.exit(1)

if workflow:
try:
logging.info('Connecting to {0}'.format(ctx.obj.client.server_url))
response = ctx.obj.client.delete_workflow(workflow,
all_runs,
hard_delete,
access_token)
click.echo(
click.style('{} has been started.'.format(workflow),
fg='green'))

except Exception as e:
logging.debug(traceback.format_exc())
logging.debug(str(e))
click.echo(
click.style('Workflow could not be started: \n{}'
.format(str(e)), fg='red'),
err=True)
else:
click.secho('Workflow name and number must be provided'
' either with `--workflow` option or with '
'REANA_WORKON environment variable',
fg='red', err=True)


workflow.add_command(workflow_workflows)
workflow.add_command(workflow_create)
workflow.add_command(workflow_start)
workflow.add_command(workflow_validate)
workflow.add_command(workflow_status)
workflow.add_command(workflow_delete_run)
# workflow.add_command(workflow_logs)

0 comments on commit c96be4b

Please sign in to comment.