Example usage for org.apache.hadoop.mapred JobStatus setState

List of usage examples for org.apache.hadoop.mapred JobStatus setState

Introduction

In this page you can find the example usage for org.apache.hadoop.mapred JobStatus setState.

Prototype

protected synchronized void setState(State state) 

Source Link

Document

Change the current run state of the job.

Usage

From source file:edu.stolaf.cs.wmrserver.TestJobEngine.java

License:Apache License

public JobStatus getStatus(Submission submission) throws NotFoundException, InternalException {
    JobStatus status = new JobStatus();

    status.setInfo(getInfo(submission));

    if (!isComplete(submission.getID())) {
        // In progress

        status.setState(State.RUNNING);
        // Should be no way or need to set mapper or reducer progress.
        return status;
    } else {/* w w w .j  a v  a  2  s .  c  om*/
        if (isKilled(submission.getID())) {
            // Killed

            status.setState(State.KILLED);
            return status;
        } else {
            // Succeeded or failed

            TestJobResult tjr;
            try {
                tjr = getResult(submission.getID());
            } catch (ExecutionException ex) {
                throw JobServiceHandler.wrapException("A serious error prevented the test job from completing.",
                        ex);
            }

            // Set map status
            PhaseStatus mapStatus = new PhaseStatus();
            mapStatus.setProgress(100);
            mapStatus.setCode(tjr.getMapResult().getExitCode());
            mapStatus.setOutput(readFile(tjr.getMapResult().getOutputFile()));
            mapStatus.setErrors(readFile(tjr.getMapResult().getErrorFile()));
            if (mapStatus.getCode() == 0)
                mapStatus.setState(State.SUCCESSFUL);
            else
                mapStatus.setState(State.FAILED);
            status.setMapStatus(mapStatus);

            // Set reduce status
            PhaseStatus reduceStatus = new PhaseStatus();
            reduceStatus.setCode(-1); // HACK
            if (tjr.getReduceResult() != null) {
                reduceStatus.setCode(tjr.getReduceResult().getExitCode());
                reduceStatus.setOutput(readFile(tjr.getReduceResult().getOutputFile()));
                reduceStatus.setErrors(readFile(tjr.getReduceResult().getErrorFile()));
                reduceStatus.setProgress(100);
                if (reduceStatus.getCode() == 0)
                    reduceStatus.setState(State.SUCCESSFUL);
                else
                    reduceStatus.setState(State.FAILED);
                status.setReduceStatus(reduceStatus);
            }

            // Set overall success
            if (mapStatus.getCode() == 0 && reduceStatus.getCode() == 0)
                status.setState(State.SUCCESSFUL);
            else
                status.setState(State.FAILED);

            return status;
        }
    }
}