Search in sources :

Example 1 with TaskReport

use of org.apache.hadoop.mapred.TaskReport in project cdap by caskdata.

the class MRJobClient method getMRJobInfo.

/**
 * @param runId for which information will be returned.
 * @return a {@link MRJobInfo} containing information about a particular MapReduce program run.
 * @throws IOException if there is failure to communicate through the JobClient.
 * @throws NotFoundException if a Job with the given runId is not found.
 */
@Override
public MRJobInfo getMRJobInfo(Id.Run runId) throws IOException, NotFoundException {
    Preconditions.checkArgument(ProgramType.MAPREDUCE.equals(runId.getProgram().getType()));
    JobClient jobClient = new JobClient(hConf);
    JobStatus[] jobs = jobClient.getAllJobs();
    JobStatus thisJob = findJobForRunId(jobs, runId.toEntityId());
    RunningJob runningJob = jobClient.getJob(thisJob.getJobID());
    if (runningJob == null) {
        throw new IllegalStateException(String.format("JobClient returned null for RunId: '%s', JobId: '%s'", runId, thisJob.getJobID()));
    }
    Counters counters = runningJob.getCounters();
    TaskReport[] mapTaskReports = jobClient.getMapTaskReports(thisJob.getJobID());
    TaskReport[] reduceTaskReports = jobClient.getReduceTaskReports(thisJob.getJobID());
    return new MRJobInfo(runningJob.mapProgress(), runningJob.reduceProgress(), groupToMap(counters.getGroup(TaskCounter.class.getName())), toMRTaskInfos(mapTaskReports), toMRTaskInfos(reduceTaskReports), true);
}
Also used : JobStatus(org.apache.hadoop.mapred.JobStatus) MRJobInfo(co.cask.cdap.proto.MRJobInfo) TaskReport(org.apache.hadoop.mapred.TaskReport) RunningJob(org.apache.hadoop.mapred.RunningJob) Counters(org.apache.hadoop.mapred.Counters) JobClient(org.apache.hadoop.mapred.JobClient) TaskCounter(org.apache.hadoop.mapreduce.TaskCounter)

Example 2 with TaskReport

use of org.apache.hadoop.mapred.TaskReport in project hive by apache.

the class HadoopJobExecHelper method progress.

private MapRedStats progress(ExecDriverTaskHandle th) throws IOException, LockException {
    JobClient jc = th.getJobClient();
    RunningJob rj = th.getRunningJob();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS");
    // DecimalFormat longFormatter = new DecimalFormat("###,###");
    long reportTime = System.currentTimeMillis();
    long maxReportInterval = HiveConf.getTimeVar(job, HiveConf.ConfVars.HIVE_LOG_INCREMENTAL_PLAN_PROGRESS_INTERVAL, TimeUnit.MILLISECONDS);
    boolean fatal = false;
    StringBuilder errMsg = new StringBuilder();
    long pullInterval = HiveConf.getLongVar(job, HiveConf.ConfVars.HIVECOUNTERSPULLINTERVAL);
    boolean initializing = true;
    boolean initOutputPrinted = false;
    long cpuMsec = -1;
    int numMap = -1;
    int numReduce = -1;
    List<ClientStatsPublisher> clientStatPublishers = getClientStatPublishers();
    final boolean localMode = ShimLoader.getHadoopShims().isLocalMode(job);
    MapRedStats mapRedStats = new MapRedStats(job, numMap, numReduce, cpuMsec, false, rj.getID().toString());
    updateMapRedTaskWebUIStatistics(mapRedStats, rj);
    while (!rj.isComplete()) {
        if (th.getContext() != null) {
            th.getContext().checkHeartbeaterLockException();
        }
        try {
            Thread.sleep(pullInterval);
        } catch (InterruptedException e) {
        }
        if (initializing && rj.getJobState() == JobStatus.PREP) {
            // No reason to poll untill the job is initialized
            continue;
        } else {
            // By now the job is initialized so no reason to do
            // rj.getJobState() again and we do not want to do an extra RPC call
            initializing = false;
        }
        if (!localMode) {
            if (!initOutputPrinted) {
                SessionState ss = SessionState.get();
                String logMapper;
                String logReducer;
                TaskReport[] mappers = jc.getMapTaskReports(rj.getID());
                if (mappers == null) {
                    logMapper = "no information for number of mappers; ";
                } else {
                    numMap = mappers.length;
                    if (ss != null) {
                        ss.getHiveHistory().setTaskProperty(queryId, getId(), Keys.TASK_NUM_MAPPERS, Integer.toString(numMap));
                    }
                    logMapper = "number of mappers: " + numMap + "; ";
                }
                TaskReport[] reducers = jc.getReduceTaskReports(rj.getID());
                if (reducers == null) {
                    logReducer = "no information for number of reducers. ";
                } else {
                    numReduce = reducers.length;
                    if (ss != null) {
                        ss.getHiveHistory().setTaskProperty(queryId, getId(), Keys.TASK_NUM_REDUCERS, Integer.toString(numReduce));
                    }
                    logReducer = "number of reducers: " + numReduce;
                }
                console.printInfo("Hadoop job information for " + getId() + ": " + logMapper + logReducer);
                initOutputPrinted = true;
            }
            RunningJob newRj = jc.getJob(rj.getID());
            if (newRj == null) {
                // So raise a meaningful exception
                throw new IOException("Could not find status of job:" + rj.getID());
            } else {
                th.setRunningJob(newRj);
                rj = newRj;
            }
        }
        // let the job retry several times, which eventually lead to failure.
        if (fatal) {
            // wait until rj.isComplete
            continue;
        }
        Counters ctrs = th.getCounters();
        mapRedStats.setCounters(ctrs);
        mapRedStats.setNumMap(numMap);
        mapRedStats.setNumReduce(numReduce);
        updateMapRedTaskWebUIStatistics(mapRedStats, rj);
        if (fatal = checkFatalErrors(ctrs, errMsg)) {
            console.printError("[Fatal Error] " + errMsg.toString() + ". Killing the job.");
            rj.killJob();
            continue;
        }
        errMsg.setLength(0);
        updateCounters(ctrs, rj);
        // Prepare data for Client Stat Publishers (if any present) and execute them
        if (clientStatPublishers.size() > 0 && ctrs != null) {
            Map<String, Double> exctractedCounters = extractAllCounterValues(ctrs);
            for (ClientStatsPublisher clientStatPublisher : clientStatPublishers) {
                try {
                    clientStatPublisher.run(exctractedCounters, rj.getID().toString());
                } catch (RuntimeException runtimeException) {
                    LOG.error("Exception " + runtimeException.getClass().getCanonicalName() + " thrown when running clientStatsPublishers. The stack trace is: ", runtimeException);
                }
            }
        }
        if (mapProgress == lastMapProgress && reduceProgress == lastReduceProgress && System.currentTimeMillis() < reportTime + maxReportInterval) {
            continue;
        }
        StringBuilder report = new StringBuilder();
        report.append(dateFormat.format(Calendar.getInstance().getTime()));
        report.append(' ').append(getId());
        report.append(" map = ").append(mapProgress).append("%, ");
        report.append(" reduce = ").append(reduceProgress).append('%');
        // it out.
        if (ctrs != null) {
            Counter counterCpuMsec = ctrs.findCounter("org.apache.hadoop.mapred.Task$Counter", "CPU_MILLISECONDS");
            if (counterCpuMsec != null) {
                long newCpuMSec = counterCpuMsec.getValue();
                if (newCpuMSec > 0) {
                    cpuMsec = newCpuMSec;
                    report.append(", Cumulative CPU ").append((cpuMsec / 1000D)).append(" sec");
                }
            }
        }
        // write out serialized plan with counters to log file
        // LOG.info(queryPlan);
        String output = report.toString();
        SessionState ss = SessionState.get();
        if (ss != null) {
            ss.getHiveHistory().setTaskCounters(queryId, getId(), ctrs);
            ss.getHiveHistory().setTaskProperty(queryId, getId(), Keys.TASK_HADOOP_PROGRESS, output);
            if (ss.getConf().getBoolVar(HiveConf.ConfVars.HIVE_LOG_INCREMENTAL_PLAN_PROGRESS)) {
                ss.getHiveHistory().progressTask(queryId, this.task);
                this.callBackObj.logPlanProgress(ss);
            }
        }
        console.printInfo(output);
        task.setStatusMessage(output);
        reportTime = System.currentTimeMillis();
    }
    Counters ctrs = th.getCounters();
    if (ctrs != null) {
        Counter counterCpuMsec = ctrs.findCounter("org.apache.hadoop.mapred.Task$Counter", "CPU_MILLISECONDS");
        if (counterCpuMsec != null) {
            long newCpuMSec = counterCpuMsec.getValue();
            if (newCpuMSec > cpuMsec) {
                cpuMsec = newCpuMSec;
            }
        }
    }
    if (cpuMsec > 0) {
        String status = "MapReduce Total cumulative CPU time: " + Utilities.formatMsecToStr(cpuMsec);
        console.printInfo(status);
        task.setStatusMessage(status);
    }
    boolean success;
    if (fatal) {
        success = false;
    } else {
        // the last check before the job is completed
        if (checkFatalErrors(ctrs, errMsg)) {
            console.printError("[Fatal Error] " + errMsg.toString());
            success = false;
        } else {
            SessionState ss = SessionState.get();
            if (ss != null) {
                ss.getHiveHistory().setTaskCounters(queryId, getId(), ctrs);
            }
            success = rj.isSuccessful();
        }
    }
    mapRedStats.setSuccess(success);
    mapRedStats.setCounters(ctrs);
    mapRedStats.setCpuMSec(cpuMsec);
    updateMapRedTaskWebUIStatistics(mapRedStats, rj);
    // update based on the final value of the counters
    updateCounters(ctrs, rj);
    SessionState ss = SessionState.get();
    if (ss != null) {
        // Set the number of table rows affected in mapRedStats to display number of rows inserted.
        if (ctrs != null) {
            Counter counter = ctrs.findCounter(ss.getConf().getVar(HiveConf.ConfVars.HIVECOUNTERGROUP), FileSinkOperator.TOTAL_TABLE_ROWS_WRITTEN);
            if (counter != null) {
                mapRedStats.setNumModifiedRows(counter.getValue());
            }
        }
        this.callBackObj.logPlanProgress(ss);
    }
    // LOG.info(queryPlan);
    return mapRedStats;
}
Also used : SessionState(org.apache.hadoop.hive.ql.session.SessionState) TaskReport(org.apache.hadoop.mapred.TaskReport) IOException(java.io.IOException) JobClient(org.apache.hadoop.mapred.JobClient) Counter(org.apache.hadoop.mapred.Counters.Counter) ClientStatsPublisher(org.apache.hadoop.hive.ql.stats.ClientStatsPublisher) RunningJob(org.apache.hadoop.mapred.RunningJob) MapRedStats(org.apache.hadoop.hive.ql.MapRedStats) Counters(org.apache.hadoop.mapred.Counters) SimpleDateFormat(java.text.SimpleDateFormat)

Example 3 with TaskReport

use of org.apache.hadoop.mapred.TaskReport in project ambrose by twitter.

the class MapReduceHelper method getMapReduceJobState.

private MapReduceJobState getMapReduceJobState(MapReduceJob job, JobClient jobClient) throws Exception {
    RunningJob runningJob = getRunningJob(job, jobClient);
    JobID jobID = runningJob.getID();
    TaskReport[] mapTaskReport = jobClient.getMapTaskReports(jobID);
    TaskReport[] reduceTaskReport = jobClient.getReduceTaskReports(jobID);
    return new MapReduceJobState(runningJob, mapTaskReport, reduceTaskReport);
}
Also used : TaskReport(org.apache.hadoop.mapred.TaskReport) RunningJob(org.apache.hadoop.mapred.RunningJob) JobID(org.apache.hadoop.mapred.JobID)

Aggregations

RunningJob (org.apache.hadoop.mapred.RunningJob)3 TaskReport (org.apache.hadoop.mapred.TaskReport)3 Counters (org.apache.hadoop.mapred.Counters)2 JobClient (org.apache.hadoop.mapred.JobClient)2 MRJobInfo (co.cask.cdap.proto.MRJobInfo)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 MapRedStats (org.apache.hadoop.hive.ql.MapRedStats)1 SessionState (org.apache.hadoop.hive.ql.session.SessionState)1 ClientStatsPublisher (org.apache.hadoop.hive.ql.stats.ClientStatsPublisher)1 Counter (org.apache.hadoop.mapred.Counters.Counter)1 JobID (org.apache.hadoop.mapred.JobID)1 JobStatus (org.apache.hadoop.mapred.JobStatus)1 TaskCounter (org.apache.hadoop.mapreduce.TaskCounter)1