use of play.data.DynamicForm in project dr-elephant by linkedin.
the class Web method search.
/**
* Returns the search results for the given query
* @return
* JsonObject:
*
* <pre>
* {
* search-results: {
* id: "id"
* start: 0,
* end: 20,
* total: 0,
* summaries: [
* {
* application_summary_object
* }
* ]
* }
* }
* </pre>
*/
public static Result search() {
DynamicForm form = Form.form().bindFromRequest(request());
JsonObject parent = new JsonObject();
int offset = SEARCH_DEFAULT_PAGE_OFFSET;
int limit = SEARCH_DEFAULT_PAGE_LIMIT;
int end = 0;
int total = 0;
if (form.get("offset") != null && form.get("offset") != "") {
offset = Integer.valueOf(form.get("offset"));
}
if (form.get("limit") != null && form.get("limit") != "") {
limit = Integer.valueOf(form.get("limit"));
}
if (offset < 0) {
offset = 0;
}
if (limit > SEARCH_APPLICATION_MAX_OFFSET) {
limit = SEARCH_APPLICATION_MAX_OFFSET;
} else if (limit <= 0) {
return ok(new Gson().toJson(parent));
}
Query<AppResult> query = Application.generateSearchQuery(AppResult.getSearchFields(), Application.getSearchParams());
total = query.findRowCount();
if (offset > total) {
offset = total;
}
List<AppResult> results = query.setFirstRow(offset).setMaxRows(limit).fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, AppHeuristicResult.getSearchFields()).findList();
end = offset + results.size();
JsonArray applicationSummaryArray = new JsonArray();
for (AppResult application : results) {
JsonObject applicationObject = new JsonObject();
JsonArray heuristicsArray = new JsonArray();
List<AppHeuristicResult> appHeuristicResult = application.yarnAppHeuristicResults;
for (AppHeuristicResult heuristic : appHeuristicResult) {
JsonObject heuristicObject = new JsonObject();
heuristicObject.addProperty(JsonKeys.NAME, heuristic.heuristicName);
heuristicObject.addProperty(JsonKeys.SEVERITY, heuristic.severity.getText());
heuristicsArray.add(heuristicObject);
}
applicationObject.addProperty(JsonKeys.ID, application.id);
applicationObject.addProperty(JsonKeys.USERNAME, application.username);
applicationObject.addProperty(JsonKeys.START_TIME, application.startTime);
applicationObject.addProperty(JsonKeys.FINISH_TIME, application.finishTime);
applicationObject.addProperty(JsonKeys.RUNTIME, application.finishTime - application.startTime);
applicationObject.addProperty(JsonKeys.WAITTIME, application.totalDelay);
applicationObject.addProperty(JsonKeys.RESOURCE_USED, application.resourceUsed);
applicationObject.addProperty(JsonKeys.RESOURCE_WASTED, application.resourceWasted);
applicationObject.addProperty(JsonKeys.SEVERITY, application.severity.getText());
applicationObject.addProperty(JsonKeys.QUEUE, application.queueName);
applicationObject.add(JsonKeys.HEURISTICS_SUMMARY, heuristicsArray);
applicationSummaryArray.add(applicationObject);
}
JsonObject searchResults = new JsonObject();
searchResults.addProperty(JsonKeys.ID, query.toString());
searchResults.addProperty(JsonKeys.START, offset);
searchResults.addProperty(JsonKeys.END, end);
searchResults.addProperty(JsonKeys.TOTAL, total);
searchResults.add(JsonKeys.SUMMARIES, applicationSummaryArray);
parent.add(JsonKeys.SEARCH_RESULTS, searchResults);
return ok(new Gson().toJson(parent));
}
use of play.data.DynamicForm in project dr-elephant by linkedin.
the class Web method restExceptions.
/**
* Controls Exceptions
* @throws URISyntaxException
*/
public static Result restExceptions() throws URISyntaxException, MalformedURLException, IOException, AuthenticationException {
DynamicForm form = Form.form().bindFromRequest(request());
String url = form.get("flow-exec-url");
JsonObject parent = new JsonObject();
String scheduler = form.get("scheduler");
HadoopSecurity _hadoopSeverity = HadoopSecurity.getInstance();
logger.info(String.format("scheduler + ", scheduler));
if (scheduler == null) {
scheduler = "azkaban";
logger.info(String.format("Setting scheduler ", scheduler));
}
if (!InfoExtractor.getSchedulersConfiguredForException().contains(scheduler)) {
logger.info("scheduler not found ");
parent.add("workflow-exceptions", new JsonArray());
return status(503, "Service is currently unavailable");
}
if (url == null || url.isEmpty()) {
parent.add("workflow-exceptions", new JsonArray());
return notFound(new Gson().toJson(parent));
} else {
ExceptionFinder expGen;
HadoopException flowException;
try {
expGen = new ExceptionFinder(url, scheduler);
flowException = expGen.getExceptions();
} catch (RuntimeException e) {
parent.add("workflow-exceptions", new JsonArray());
return status(500, "Unexpected error occured");
} catch (Exception e) {
parent.add("workflow-exceptions", new JsonArray());
return status(500, "Unexpected error occured");
}
JsonArray jobsArray = new JsonArray();
if (!flowException.getChildExceptions().isEmpty()) {
for (HadoopException jobException : flowException.getChildExceptions()) {
JsonObject job = new JsonObject();
job.addProperty(JsonKeys.NAME, jobException.getId());
job.addProperty(JsonKeys.TYPE, jobException.getType().toString());
job.addProperty(JsonKeys.ID, jobException.getId());
if (jobException.getType() == HadoopException.HadoopExceptionType.SCHEDULER) {
if (jobException.getLoggingEvent() != null && jobException.getLoggingEvent().getLog() != null) {
job.addProperty(JsonKeys.EXCEPTION_SUMMARY, getSchedulerLog(jobException.getLoggingEvent().getLog()));
job.addProperty(JsonKeys.STATUS, "failed");
} else {
job.addProperty(JsonKeys.EXCEPTION_SUMMARY, "");
job.addProperty(JsonKeys.STATUS, "failed");
}
}
if (jobException.getType() == HadoopException.HadoopExceptionType.SCRIPT) {
if (jobException.getLoggingEvent() != null && jobException.getLoggingEvent().getLog() != null) {
job.addProperty(JsonKeys.EXCEPTION_SUMMARY, getSchedulerLog(jobException.getLoggingEvent().getLog()));
job.addProperty(JsonKeys.STATUS, "failed");
} else {
job.addProperty(JsonKeys.EXCEPTION_SUMMARY, "");
job.addProperty(JsonKeys.STATUS, "failed");
}
}
JsonArray mrExceptionsArray = new JsonArray();
if (jobException.getType() == HadoopException.HadoopExceptionType.MR) {
for (HadoopException mrJobException : jobException.getChildExceptions()) {
JsonObject child = new JsonObject();
child.addProperty(JsonKeys.NAME, mrJobException.getId());
if (mrJobException.getLoggingEvent() != null && mrJobException.getLoggingEvent().getLog() != null) {
child.addProperty(JsonKeys.EXCEPTION_SUMMARY, getSchedulerLog(mrJobException.getLoggingEvent().getLog()));
} else {
child.addProperty(JsonKeys.EXCEPTION_SUMMARY, "");
}
JsonArray taskExceptionsArray = new JsonArray();
for (HadoopException mrTaskException : mrJobException.getChildExceptions()) {
JsonObject task = new JsonObject();
task.addProperty(JsonKeys.NAME, mrTaskException.getId());
if (mrTaskException.getLoggingEvent() != null && mrTaskException.getLoggingEvent().getLog() != null) {
task.addProperty(JsonKeys.EXCEPTION_SUMMARY, getSchedulerLog(mrTaskException.getLoggingEvent().getLog()));
} else {
task.addProperty(JsonKeys.EXCEPTION_SUMMARY, "");
}
taskExceptionsArray.add(task);
}
child.add(JsonKeys.TASKS, taskExceptionsArray);
mrExceptionsArray.add(child);
}
if (jobException.getChildExceptions().isEmpty()) {
JsonObject child = new JsonObject();
child.addProperty(JsonKeys.NAME, "");
child.add(JsonKeys.TASKS, new JsonArray());
child.addProperty(JsonKeys.EXCEPTION_SUMMARY, getSchedulerLog(jobException.getLoggingEvent().getLog()));
mrExceptionsArray.add(child);
}
job.add(JsonKeys.APPLICATIONS, mrExceptionsArray);
job.addProperty(JsonKeys.STATUS, "failed");
}
jobsArray.add(job);
}
parent.add(JsonKeys.WORKFLOW_EXCEPTIONS, jobsArray);
return ok(new Gson().toJson(parent));
}
parent.add(JsonKeys.WORKFLOW_EXCEPTIONS, jobsArray);
return ok(new Gson().toJson(parent));
}
}
Aggregations