Example usage for org.apache.hadoop.mapred TaskReport getCurrentStatus

List of usage examples for org.apache.hadoop.mapred TaskReport getCurrentStatus

Introduction

In this page you can find the example usage for org.apache.hadoop.mapred TaskReport getCurrentStatus.

Prototype

public TIPStatus getCurrentStatus() 

Source Link

Document

The current status

Usage

From source file:azkaban.jobtype.MapReduceJobState.java

License:Apache License

public MapReduceJobState(RunningJob runningJob, TaskReport[] mapTaskReport, TaskReport[] reduceTaskReport)
        throws IOException {
    jobId = runningJob.getID().toString();
    jobName = runningJob.getJobName();/*  ww  w  .  ja v  a2s .  c o  m*/
    trackingURL = runningJob.getTrackingURL();
    isComplete = runningJob.isComplete();
    isSuccessful = runningJob.isSuccessful();
    mapProgress = runningJob.mapProgress();
    reduceProgress = runningJob.reduceProgress();
    failureInfo = runningJob.getFailureInfo();

    totalMappers = mapTaskReport.length;
    totalReducers = reduceTaskReport.length;

    for (TaskReport report : mapTaskReport) {
        if (report.getStartTime() < jobStartTime || jobStartTime == 0L) {
            jobStartTime = report.getStartTime();
        }

        TIPStatus status = report.getCurrentStatus();
        if (status != TIPStatus.PENDING && status != TIPStatus.RUNNING) {
            finishedMappersCount++;
        }
    }

    for (TaskReport report : reduceTaskReport) {
        if (jobLastUpdateTime < report.getFinishTime()) {
            jobLastUpdateTime = report.getFinishTime();
        }

        TIPStatus status = report.getCurrentStatus();
        if (status != TIPStatus.PENDING && status != TIPStatus.RUNNING) {
            finishedReducersCount++;
        }
    }

    // If not all the reducers are finished.
    if (finishedReducersCount != reduceTaskReport.length || jobLastUpdateTime == 0) {
        jobLastUpdateTime = System.currentTimeMillis();
    }

    counters = runningJob.getCounters();
}

From source file:com.atlantbh.jmeter.plugins.hadooputilities.jobstatistics.TaskLayer.java

License:Apache License

public String getTaskStatisticsByJobId(String jobTracker, String jobId) throws IOException {
    StringBuilder taskStatistics = new StringBuilder();
    long taskDuration;
    String duration;/* ww w .  j  a  v a2 s  .  c  o  m*/

    JobID id = this.convertToJobId(jobId);
    JobClient client = this.prepareJobClient(jobTracker);
    RunningJob job = client.getJob(id);

    TaskReport[] mapTaskReports = client.getMapTaskReports(id);
    TaskReport[] reduceTaskReports = client.getReduceTaskReports(id);

    taskStatistics.append("<job id='").append(jobId).append("' name='").append(job.getJobName()).append("'>\n");
    taskStatistics.append(" <mapTasks>\n");

    for (TaskReport mapTaskReport : mapTaskReports) {
        taskDuration = mapTaskReport.getFinishTime() - mapTaskReport.getStartTime();

        if (taskDuration < 0) {
            duration = "N/A";
        } else {
            duration = String.valueOf(taskDuration);
        }

        double progress = mapTaskReport.getProgress() * 100;
        String taskProgress = Double.toString(progress) + "%";

        taskStatistics.append("  <task id='").append(mapTaskReport.getTaskID().toString()).append("'\n");
        taskStatistics.append("   <progress>").append(taskProgress).append("</progress>\n");
        taskStatistics.append("   <duration>").append(duration).append("</duration>\n");
        taskStatistics.append("   <status>").append(mapTaskReport.getCurrentStatus().toString())
                .append("</status>\n");
        taskStatistics.append("  </task>\n");
    }

    taskStatistics.append(" </mapTasks>\n");

    taskStatistics.append(" <reduceTasks>\n");

    for (TaskReport reduceTaskReport : reduceTaskReports) {
        taskDuration = reduceTaskReport.getFinishTime() - reduceTaskReport.getStartTime();

        if (taskDuration < 0) {
            duration = "N/A";
        } else {
            duration = String.valueOf(taskDuration);
        }

        double progress = reduceTaskReport.getProgress() * 100;
        String taskProgress = Double.toString(progress) + "%";

        taskStatistics.append("  <task id='").append(reduceTaskReport.getTaskID().toString()).append("'\n");
        taskStatistics.append("   <progress>").append(taskProgress).append("</progress>\n");
        taskStatistics.append("   <duration>").append(duration).append("</duration>\n");
        taskStatistics.append("   <status>").append(reduceTaskReport.getCurrentStatus().toString())
                .append("</status>\n");
        taskStatistics.append("  </task>\n");
    }

    taskStatistics.append(" </reduceTasks>\n");
    taskStatistics.append("</job>");

    return taskStatistics.toString();
}

From source file:com.impetus.ankush2.hadoop.monitor.JobStatusProvider.java

License:Open Source License

/**
 * @param jobClient//from  www  .  j  a va  2  s .  c  o m
 * @param jobSts
 * @return
 * @throws IOException
 */
private Map<String, Object> getJobReport(JobStatus jobSts) throws IOException {
    // Creating an empty map for storing job information
    Map<String, Object> jobReport = new HashMap<String, Object>();
    // Returns the jobid of the Job
    org.apache.hadoop.mapred.JobID jobId = jobSts.getJobID();
    // Get an RunningJob object to track an ongoing Map-Reduce
    // job.
    RunningJob job = jobClient.getJob(jobId);
    String jobName = "";
    if (job != null) {
        // Get the name of the job.
        jobName = job.getJobName();
    }
    // Percentage of progress in maps
    float mapProgress = jobSts.mapProgress() * 100;
    // Percentage of progress in reduce
    float reduceProgress = jobSts.reduceProgress() * 100;

    int mapTotal = 0;
    int reduceTotal = 0;
    int mapComp = 0;
    int reduceComp = 0;

    // Count for Map and Reduce Complete
    try {
        // Get the information of the current state of the map
        // tasks of a job
        TaskReport[] mapTaskReports = jobClient.getMapTaskReports(jobId);
        // Get the total map
        mapTotal = mapTaskReports.length;
        // Iterating over the map tasks
        for (TaskReport taskReport : mapTaskReports) {
            // The current state of a map TaskInProgress as seen
            // by the JobTracker.
            TIPStatus currentStatus = taskReport.getCurrentStatus();
            if (currentStatus == TIPStatus.COMPLETE) {
                mapComp++;
            }
        }

        // Get the information of the current state of the
        // reduce tasks of a job.
        TaskReport[] reduceTaskReport = jobClient.getReduceTaskReports(jobId);
        // Get the total reduce
        reduceTotal = reduceTaskReport.length;
        // Iterating over the reduce tasks
        for (TaskReport taskReport : reduceTaskReport) {
            // The current state of a reduce TaskInProgress as
            // seen by the JobTracker.
            TIPStatus currentStatus = taskReport.getCurrentStatus();
            if (currentStatus == TIPStatus.COMPLETE) {
                reduceComp++;
            }
        }
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }
    // Percentage of progress in setup
    float setupProgress = jobSts.setupProgress() * 100;
    // The progress made on cleanup
    float cleanupProgress = jobSts.cleanupProgress() * 100;
    // gets any available info on the reason of failure of the
    // job..Returns the diagnostic information on why a job
    // might have failed.
    String failureInfo = jobSts.getFailureInfo();

    // Putting Job Sttaus information in map
    jobReport.put("jobId", jobId.toString());
    jobReport.put("jobName", jobName);
    jobReport.put("jobPriority", jobSts.getJobPriority().toString());
    jobReport.put("jobStartTime", jobSts.getStartTime());

    jobReport.put("userName", jobSts.getUsername());
    jobReport.put("jobComplete", jobSts.isJobComplete());

    jobReport.put("mapProgress", mapProgress);
    jobReport.put("reduceProgress", reduceProgress);

    jobReport.put("mapTotal", mapTotal);
    jobReport.put("reduceTotal", reduceTotal);
    jobReport.put("mapCompleted", mapComp);
    jobReport.put("reduceCompleted", reduceComp);

    jobReport.put("setupProgress", setupProgress);
    jobReport.put("cleanupProgress", cleanupProgress);

    jobReport.put("schedulingInfo", jobSts.getSchedulingInfo());
    jobReport.put("jobState", JobStatus.getJobRunState(jobSts.getRunState()));
    jobReport.put("failureInfo", failureInfo);
    jobReport.put("jobFile", job.getJobFile());
    jobReport.put("trackingURL", job.getTrackingURL());

    jobReport.putAll(getDetailedJobReport(jobId));
    return jobReport;
}

From source file:com.impetus.ankush2.hadoop.monitor.JobStatusProvider.java

License:Open Source License

/**
 * Gets the task report.//from   w w  w.  j a va  2s .  c  om
 * 
 * @param taskReports
 *            the task reports
 * @return the task report
 */
private Map<String, Object> getTaskReport(TaskReport[] taskReports) {
    Map<String, Object> taskReportsInfo = new HashMap<String, Object>();
    try {
        LOG.info("Total Task : " + taskReports.length);
        List<Map> taskLists = new ArrayList<Map>();
        // A report on the state of a task.
        if (taskReports != null) {
            int completeTask = 0;
            int failedTask = 0;
            int killedTask = 0;
            int runningTask = 0;
            int pendingTask = 0;
            Map<String, Object[]> diagInfo = new HashMap<String, Object[]>();
            // Iterating over the task reports
            for (TaskReport mtr : taskReports) {
                // Creating an empty map for storing task details
                Map<String, Object> taskReport = new HashMap<String, Object>();
                // The current status of the task
                TIPStatus currentStatus = mtr.getCurrentStatus();
                // Checking for task's current status COMPLETE
                if (currentStatus == TIPStatus.COMPLETE) {
                    completeTask++;
                }
                // Checking for task's current status KILLED
                if (currentStatus == TIPStatus.KILLED) {
                    killedTask++;
                }
                // Checking for task's current status RUNNING
                if (currentStatus == TIPStatus.RUNNING) {
                    runningTask++;
                }
                // Checking for task's current status PENDING
                if (currentStatus == TIPStatus.PENDING) {
                    pendingTask++;
                }
                // The id of the task.
                TaskID taskId = mtr.getTaskID();
                float progress = mtr.getProgress();
                // The most recent state
                String state = mtr.getState();

                // Putting value in a map
                taskReport.put("taskId", taskId.toString());
                taskReport.put("successfulTaskAttemp", mtr.getSuccessfulTaskAttempt().toString());
                taskReport.put("startTime", mtr.getStartTime());
                taskReport.put("finishTime", mtr.getFinishTime());
                taskReport.put("progress", progress * 100);
                taskReport.put("state", state);
                taskReport.put("currentStatus", currentStatus);
                Counters counters = mtr.getCounters();
                List countersList = new ArrayList();
                for (Group group : counters) {
                    Map<String, Object> counterMap = new HashMap<String, Object>();
                    counterMap.put("name", group.getDisplayName());
                    List subCounters = new ArrayList();
                    for (Counter counter : group) {
                        Map subCounter = new HashMap();
                        subCounter.put("name", counter.getDisplayName());
                        subCounter.put("value", counter.getCounter());
                        subCounters.add(subCounter);
                    }
                    counterMap.put("subCounters", subCounters);
                    countersList.add(counterMap);
                }
                taskReport.put("counters", countersList);
                taskLists.add(taskReport);
                // A list of error messages.
                String[] diagnostics = mtr.getDiagnostics();
                if (diagnostics != null) {
                    int count = 0;
                    // Iterating over the list of error messages
                    for (String di : diagnostics) {
                        Object[] diagStatus = new Object[2];
                        diagStatus[0] = taskId;
                        diagStatus[1] = di;
                        diagInfo.put(taskId + "_" + count, diagStatus);
                        count++;
                    }
                }
            }
            // Putting value in a map
            taskReportsInfo.put("completedTask", completeTask);
            taskReportsInfo.put("pendingTask", pendingTask);
            taskReportsInfo.put("killedTask", killedTask);
            taskReportsInfo.put("runningTask", runningTask);
            taskReportsInfo.put("failedTask", failedTask);
            taskReportsInfo.put("failedOrKilledTask", failedTask);
            taskReportsInfo.put("diagInfo", diagInfo);
            taskReportsInfo.put("tasks", taskLists);
        }
    } catch (Exception e) {
        HadoopUtils.addAndLogError(this.LOG, this.clusterConfig, "Could not get task report",
                Constant.Component.Name.HADOOP, e);
    }
    return taskReportsInfo;
}

From source file:com.twitter.hraven.hadoopJobMonitor.AppStatusCheckerTest.java

License:Apache License

public boolean testTask(TaskType taskType, String confParamName, long durationMin, final int MAX_RUN,
        float progress, boolean enforce, boolean dryRun, TIPStatus status, boolean wellBahaved, boolean killed)
        throws Exception {
    setTaskAttemptXML(durationMin * MIN, progress);

    TaskReport taskReport = mock(TaskReport.class);
    when(taskReport.getCurrentStatus()).thenReturn(status);
    Collection<TaskAttemptID> attempts = new ArrayList<TaskAttemptID>();
    attempts.add(taskAttemptId);/*from   w w w .ja va  2  s . co  m*/
    when(taskReport.getRunningTaskAttemptIds()).thenReturn(attempts);
    when(taskReport.getTaskID()).thenReturn(org.apache.hadoop.mapred.TaskID.downgrade(taskId));
    when(taskReport.getProgress()).thenReturn(progress);

    vConf.setBoolean(HadoopJobMonitorConfiguration.DRY_RUN, dryRun);
    Configuration remoteAppConf = new Configuration();
    remoteAppConf.setInt(confParamName, MAX_RUN);
    remoteAppConf.setBoolean(HadoopJobMonitorConfiguration.enforced(confParamName), enforce);
    when(taskReport.getStartTime()).thenReturn(now - durationMin * MIN);
    AppConfiguraiton appConf = new AppConfiguraiton(remoteAppConf, vConf);
    AppConfCache.getInstance().put(appId, appConf);
    appStatusChecker.init();
    appStatusChecker.loadClientService();

    boolean res = appStatusChecker.checkTask(taskType, taskReport, now);

    if (wellBahaved)
        assertEquals("Well-bahved task does not pass the check", wellBahaved, res);
    else
        assertEquals("Not Well-bahved task passes the check", wellBahaved, res);
    if (killed) {
        killCounter++;
        verify(clientService, times(killCounter)).killTask(any(TaskAttemptID.class), Mockito.anyBoolean());
    } else
        verify(clientService, times(killCounter)).killTask(any(TaskAttemptID.class), Mockito.anyBoolean());
    return res;
}

From source file:org.apache.pig.backend.hadoop.executionengine.shims.HadoopShims.java

License:Apache License

public static boolean isJobFailed(TaskReport report) {
    return report.getCurrentStatus() == TIPStatus.FAILED;
}

From source file:org.godhuli.rhipe.FileUtils.java

License:Apache License

private REXP TaskReportToRexp(TaskReport t) {
    REXP.Builder thevals = REXP.newBuilder();
    thevals.setRclass(REXP.RClass.LIST);
    thevals.addRexpValue(FileUtils.buildlistFromOldCounter(t.getCounters(), 0));
    thevals.addRexpValue(RObjects.makeStringVector(convertTIP(t.getCurrentStatus())));
    thevals.addRexpValue(/*  w w  w.j  a v  a  2 s .c  om*/
            RObjects.buildDoubleVector(new double[] { t.getProgress(), t.getStartTime(), t.getFinishTime() }));
    thevals.addRexpValue(RObjects.makeStringVector(t.getTaskID().toString()));
    thevals.addRexpValue(RObjects.makeStringVector(t.getSuccessfulTaskAttempt().toString()));

    return thevals.build();
}