@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("application/json");
final FlowManager allFlows = this.getApplication().getAllFlows();
String action = getParam(req, "action");
if (action.equals("restart")) {
String value = req.getParameter("disabled");
String[] disabledValues = value.split(",");
HashSet<String> disabledJobs = new HashSet<String>();
for (String disabled : disabledValues) {
if (!disabled.isEmpty()) {
disabledJobs.add(disabled);
}
}
long id = Long.parseLong(getParam(req, "id"));
FlowExecutionHolder holder = allFlows.loadExecutableFlow(id);
//Flows.resetFailedFlows(holder.getFlow());
// Disable all proper values
ExecutableFlow executableFlow = holder.getFlow();
traverseFlow(disabledJobs, executableFlow);
PrintWriter writer = resp.getWriter();
JSONUtils jsonUtils = new JSONUtils();
HashMap<String,Object> results = new HashMap<String,Object>();
try {
this.getApplication().getJobExecutorManager().execute(holder);
results.put("id", holder.getFlow().getId());
results.put("success", true);
results.put("message", String.format("Executing Flow[%s].", id));
} catch(Exception e) {
results.put("id", holder.getFlow().getId());
results.put("error", true);
results.put("message", String.format("Error running Flow[%s]. " + e.getMessage(), id));
}
writer.print(jsonUtils.toJSONString(results));
writer.flush();
}
else if (action.equals("run")) {
String name = getParam(req, "name");
String value = req.getParameter("disabled");
String[] disabledValues = value.split(",");
HashSet<String> disabledJobs = new HashSet<String>();
for (String disabled : disabledValues) {
if (!disabled.isEmpty()) {
disabledJobs.add(disabled);
}
}
ExecutableFlow flow = allFlows.createNewExecutableFlow(name);
if (flow == null) {
addError(req, "Job " + name + " not found.");
}
traverseFlow(disabledJobs, flow);
PrintWriter writer = resp.getWriter();