Search in sources :

Example 1 with HadoopSecurity

use of com.linkedin.drelephant.security.HadoopSecurity 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));
    }
}
Also used : JsonArray(com.google.gson.JsonArray) ExceptionFinder(com.linkedin.drelephant.exceptions.ExceptionFinder) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) DynamicForm(play.data.DynamicForm) HadoopException(com.linkedin.drelephant.exceptions.HadoopException) HadoopSecurity(com.linkedin.drelephant.security.HadoopSecurity) URISyntaxException(java.net.URISyntaxException) AuthenticationException(javax.naming.AuthenticationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) HadoopException(com.linkedin.drelephant.exceptions.HadoopException)

Aggregations

Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 ExceptionFinder (com.linkedin.drelephant.exceptions.ExceptionFinder)1 HadoopException (com.linkedin.drelephant.exceptions.HadoopException)1 HadoopSecurity (com.linkedin.drelephant.security.HadoopSecurity)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 AuthenticationException (javax.naming.AuthenticationException)1 DynamicForm (play.data.DynamicForm)1