// create the plan
String[] options = params.isEmpty() ? new String[0] : (String[]) params.toArray(new String[params.size()]);
PackagedProgram program;
OptimizedPlan optPlan;
Client client;
try {
if (assemblerClass == null) {
program = new PackagedProgram(jarFile, options);
} else {
program = new PackagedProgram(jarFile, assemblerClass, options);
}
client = new Client(nepheleConfig, program.getUserCodeClassLoader());
optPlan = client.getOptimizedPlan(program, -1);
if (optPlan == null) {
throw new Exception("The optimized plan could not be produced.");
}
}
catch (ProgramInvocationException e) {
// collect the stack trace
StringWriter sw = new StringWriter();
PrintWriter w = new PrintWriter(sw);
if (e.getCause() == null) {
e.printStackTrace(w);
} else {
e.getCause().printStackTrace(w);
}
showErrorPage(resp, "An error occurred while invoking the program:<br/><br/>"
+ e.getMessage() + "<br/>"
+ "<br/><br/><pre>" + sw.toString() + "</pre>");
return;
}
catch (CompilerException cex) {
// collect the stack trace
StringWriter sw = new StringWriter();
PrintWriter w = new PrintWriter(sw);
cex.printStackTrace(w);
showErrorPage(resp, "An error occurred in the compiler:<br/><br/>"
+ cex.getMessage() + "<br/>"
+ (cex.getCause()!= null?"Caused by: " + cex.getCause().getMessage():"")
+ "<br/><br/><pre>" + sw.toString() + "</pre>");
return;
}
catch (Throwable t) {
// collect the stack trace
StringWriter sw = new StringWriter();
PrintWriter w = new PrintWriter(sw);
t.printStackTrace(w);
showErrorPage(resp, "An unexpected error occurred:<br/><br/>" + t.getMessage() + "<br/><br/><pre>"
+ sw.toString() + "</pre>");
return;
}
// redirect according to our options
if (show) {
// we have a request to show the plan
// create a UID for the job
Long uid = null;
do {
uid = Math.abs(this.rand.nextLong());
} while (this.submittedJobs.containsKey(uid));
// dump the job to a JSON file
String planName = uid + ".json";
File jsonFile = new File(this.planDumpDirectory, planName);
PlanJSONDumpGenerator jsonGen = new PlanJSONDumpGenerator();
jsonGen.setEncodeForHTML(true);
jsonGen.dumpOptimizerPlanAsJSON(optPlan, jsonFile);
// submit the job only, if it should not be suspended
if (!suspend) {
try {
client.run(program, optPlan, false);
} catch (Throwable t) {
LOG.error("Error submitting job to the job-manager.", t);
showErrorPage(resp, t.getMessage());
return;
} finally {
program.deleteExtractedLibraries();
}
} else {
try {
this.submittedJobs.put(uid, client.getJobGraph(program, optPlan));
}
catch (ProgramInvocationException piex) {
LOG.error("Error creating JobGraph from optimized plan.", piex);
showErrorPage(resp, piex.getMessage());
return;
}
catch (Throwable t) {
LOG.error("Error creating JobGraph from optimized plan.", t);
showErrorPage(resp, t.getMessage());
return;
}
}
// redirect to the plan display page
resp.sendRedirect("showPlan?id=" + uid + "&suspended=" + (suspend ? "true" : "false"));
} else {
// don't show any plan. directly submit the job and redirect to the
// nephele runtime monitor
try {
client.run(program, -1, false);
} catch (Exception ex) {
LOG.error("Error submitting job to the job-manager.", ex);
// HACK: Is necessary because Message contains whole stack trace
String errorMessage = ex.getMessage().split("\n")[0];
showErrorPage(resp, errorMessage);
return;
} finally {
program.deleteExtractedLibraries();
}
resp.sendRedirect(START_PAGE_URL);
}
} else if (action.equals(ACTION_RUN_SUBMITTED_VALUE)) {
// --------------- run a job that has been submitted earlier, but was -------------------
// --------------- not executed because of a plan display -------------------
String id = req.getParameter("id");
if (checkParameterSet(resp, id, "id")) {
return;
}
Long uid = null;
try {
uid = Long.parseLong(id);
} catch (NumberFormatException nfex) {
showErrorPage(resp, "An invalid id for the job was provided.");
return;
}
// get the retained job
JobGraph job = submittedJobs.remove(uid);
if (job == null) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST,
"No job with the given uid was retained for later submission.");
return;
}
// submit the job
try {
Client client = new Client(nepheleConfig, getClass().getClassLoader());
client.run(job, false);
} catch (Exception ex) {
LOG.error("Error submitting job to the job-manager.", ex);
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
// HACK: Is necessary because Message contains whole stack trace
String errorMessage = ex.getMessage().split("\n")[0];