Commit 74b45e3a authored by Jerome Mariette's avatar Jerome Mariette
Browse files

delete ok

parent 360e4460
......@@ -78,6 +78,12 @@ if __name__ == '__main__':
required=True, dest="component_name")
sub_parser.set_defaults(cmd_object="reset")
# Add delete workflow availability
sub_parser = subparsers.add_parser("delete", help="Delete a workflow")
sub_parser.add_argument("--workflow-id", type=str, help="Which workflow should be deleted",
required=True, dest="workflow_id")
sub_parser.set_defaults(cmd_object="delete")
# Add rerun workflow availability
sub_parser = subparsers.add_parser("execution-graph", help="Display the workflow execution graph")
sub_parser.add_argument("--workflow-id", type=str, help="Which workflow should be considered",
......@@ -130,6 +136,8 @@ if __name__ == '__main__':
wfmanager.rerun_workflow(args["workflow_id"])
elif args["cmd_object"] == "reset":
wfmanager.reset_workflow_component(args["workflow_id"], args["component_name"])
elif args["cmd_object"] == "delete":
wfmanager.delete_workflow(args["workflow_id"])
elif args["cmd_object"] == "execution_graph":
workflow = wfmanager.get_workflow(args["workflow_id"])
gr = workflow.get_execution_graph()
......
......@@ -255,6 +255,11 @@ class JFlowServer (object):
except Exception as err:
return { "status" : 1, "content" : str(err) }
@cherrypy.expose
@jsonify
def delete_workflow(self, **kwargs):
self.wfmanager.delete_workflow(kwargs["workflow_id"])
@cherrypy.expose
@jsonify
def rerun_workflow(self, **kwargs):
......
......@@ -28,6 +28,7 @@ import threading
import types
import logging
import datetime
import shutil
from logging import FileHandler
from ConfigParser import ConfigParser, NoOptionError
......@@ -356,6 +357,10 @@ class Workflow(threading.Thread):
logger.addHandler(file_handler)
self.stderr = stderr
def delete(self):
if self.get_status() in [self.STATUS_COMPLETED, self.STATUS_FAILED, self.STATUS_ABORTED]:
shutil.rmtree(self.directory)
@staticmethod
def config_parser(arg_lines):
for arg in arg_lines:
......
......@@ -110,6 +110,28 @@ class WorkflowsManager(object):
self._dump_workflows([workflow])
return workflow
def delete_workflow(self, workflow_id):
from jflow.workflow import Workflow
WorkflowsManager.lock_workflows_file.acquire()
try:
workflows_dump = pickle.load(open(self.dump_file))
except:
workflows_dump = {}
rworkflow_id = utils.get_nb_string(workflow_id)
try:
workflow_dump = open(workflows_dump[rworkflow_id]["dump_path"], "rb")
workflow = pickle.load(workflow_dump)
# if workflow is not in a running status
if workflow.get_status() in [Workflow.STATUS_COMPLETED, Workflow.STATUS_FAILED, Workflow.STATUS_ABORTED]:
workflow.delete()
del workflows_dump[rworkflow_id]
workflow_dump.close()
except:
utils.display_error_message("Workflow #" + rworkflow_id + " connot be retrieved in the available workflows!")
# and save them
pickle.dump(workflows_dump, open(self.dump_file, "w"))
WorkflowsManager.lock_workflows_file.release()
def get_workflow_errors(self, workflow_id):
workflow = self.get_workflow(workflow_id)
return workflow.get_errors()
......
......@@ -86,6 +86,24 @@
$("#activewf_refresh_btn").click(function(){
$this.reload();
});
$("[id^=activewf_delete_]").click(function(){
var workflow_id = $(this).attr("id").split("activewf_delete_")[1];
$.ajax({
url: $this.options.serverURL + '/delete_workflow?workflow_id=' + workflow_id + '&callback=?',
dataType: "json",
timeout: 20000,
error: function (xhr, ajaxOptions, thrownError) {
var alert_message = ['<div class="alert alert-danger" role="alert">',
'<strong>Error!</strong>',
'Jflow failed to connect to the specified server <strong>' + $this.options.serverURL + '</strong>',
'</div>'].join('\n');
$this.$element.html(alert_message);
},
success: function(data) {
$this.reload();
}
});
});
}
});
}
......@@ -117,6 +135,7 @@
'<th>Status</th>',
'<th>Start time</th>',
'<th>End time</th>',
'<th>Actions</th>',
'</tr>',
'</thead>',
'{{each(index, workflow) workflows}}',
......@@ -138,6 +157,13 @@
'{{/if}}',
'<td>${workflow.start_time}</td>',
'<td>${workflow.end_time}</td>',
'<td>',
' <div class="btn-group">',
' <button type="button" id="activewf_delete_${workflow.id}" class="btn btn-default btn-xs" aria-label="Left Align">',
' <span class="glyphicon glyphicon-remove"></span>',
' </button>',
' </div>',
'</td>',
'</tr>',
'{{/each}}',
'</table>',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment