Search in sources :

Example 1 with CounterGroup

use of org.apache.hadoop.mapreduce.v2.api.records.CounterGroup in project hadoop by apache.

the class TypeConverter method toYarn.

public static Counters toYarn(org.apache.hadoop.mapred.Counters counters) {
    if (counters == null) {
        return null;
    }
    Counters yCntrs = recordFactory.newRecordInstance(Counters.class);
    yCntrs.addAllCounterGroups(new HashMap<String, CounterGroup>());
    for (org.apache.hadoop.mapred.Counters.Group grp : counters) {
        CounterGroup yGrp = recordFactory.newRecordInstance(CounterGroup.class);
        yGrp.setName(grp.getName());
        yGrp.setDisplayName(grp.getDisplayName());
        yGrp.addAllCounters(new HashMap<String, Counter>());
        for (org.apache.hadoop.mapred.Counters.Counter cntr : grp) {
            Counter yCntr = recordFactory.newRecordInstance(Counter.class);
            yCntr.setName(cntr.getName());
            yCntr.setDisplayName(cntr.getDisplayName());
            yCntr.setValue(cntr.getValue());
            yGrp.setCounter(yCntr.getName(), yCntr);
        }
        yCntrs.setCounterGroup(yGrp.getName(), yGrp);
    }
    return yCntrs;
}
Also used : Counter(org.apache.hadoop.mapreduce.v2.api.records.Counter) CounterGroup(org.apache.hadoop.mapreduce.v2.api.records.CounterGroup) Counters(org.apache.hadoop.mapreduce.v2.api.records.Counters)

Example 2 with CounterGroup

use of org.apache.hadoop.mapreduce.v2.api.records.CounterGroup in project hadoop by apache.

the class TaskImpl method getCounters.

@Override
public Counters getCounters() {
    Counters counters = null;
    readLock.lock();
    try {
        TaskAttempt bestAttempt = selectBestAttempt();
        if (bestAttempt != null) {
            counters = bestAttempt.getCounters();
        } else {
            counters = TaskAttemptImpl.EMPTY_COUNTERS;
        //        counters.groups = new HashMap<CharSequence, CounterGroup>();
        }
        return counters;
    } finally {
        readLock.unlock();
    }
}
Also used : Counters(org.apache.hadoop.mapreduce.Counters) TaskAttempt(org.apache.hadoop.mapreduce.v2.app.job.TaskAttempt)

Example 3 with CounterGroup

use of org.apache.hadoop.mapreduce.v2.api.records.CounterGroup in project hadoop by apache.

the class SingleCounterBlock method populateMembers.

private void populateMembers(AppContext ctx) {
    JobId jobID = null;
    TaskId taskID = null;
    String tid = $(TASK_ID);
    if ($(TITLE).contains("MAPS")) {
        counterType = TaskType.MAP;
    } else if ($(TITLE).contains("REDUCES")) {
        counterType = TaskType.REDUCE;
    } else {
        counterType = null;
    }
    if (!tid.isEmpty()) {
        taskID = MRApps.toTaskID(tid);
        jobID = taskID.getJobId();
    } else {
        String jid = $(JOB_ID);
        if (!jid.isEmpty()) {
            jobID = MRApps.toJobID(jid);
        }
    }
    if (jobID == null) {
        return;
    }
    job = ctx.getJob(jobID);
    if (job == null) {
        return;
    }
    if (taskID != null) {
        task = job.getTask(taskID);
        if (task == null) {
            return;
        }
        for (Map.Entry<TaskAttemptId, TaskAttempt> entry : task.getAttempts().entrySet()) {
            long value = 0;
            Counters counters = entry.getValue().getCounters();
            CounterGroup group = (counters != null) ? counters.getGroup($(COUNTER_GROUP)) : null;
            if (group != null) {
                Counter c = group.findCounter($(COUNTER_NAME));
                if (c != null) {
                    value = c.getValue();
                }
            }
            values.put(MRApps.toString(entry.getKey()), value);
        }
        return;
    }
    // Get all types of counters
    Map<TaskId, Task> tasks = job.getTasks();
    for (Map.Entry<TaskId, Task> entry : tasks.entrySet()) {
        long value = 0;
        Counters counters = entry.getValue().getCounters();
        CounterGroup group = (counters != null) ? counters.getGroup($(COUNTER_GROUP)) : null;
        if (group != null) {
            Counter c = group.findCounter($(COUNTER_NAME));
            if (c != null) {
                value = c.getValue();
            }
        }
        if (counterType == null || counterType == entry.getValue().getType()) {
            values.put(MRApps.toString(entry.getKey()), value);
        }
    }
}
Also used : Task(org.apache.hadoop.mapreduce.v2.app.job.Task) TaskId(org.apache.hadoop.mapreduce.v2.api.records.TaskId) TaskAttemptId(org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId) CounterGroup(org.apache.hadoop.mapreduce.CounterGroup) Counter(org.apache.hadoop.mapreduce.Counter) Counters(org.apache.hadoop.mapreduce.Counters) TaskAttempt(org.apache.hadoop.mapreduce.v2.app.job.TaskAttempt) Map(java.util.Map) TreeMap(java.util.TreeMap) JobId(org.apache.hadoop.mapreduce.v2.api.records.JobId)

Example 4 with CounterGroup

use of org.apache.hadoop.mapreduce.v2.api.records.CounterGroup in project hadoop by apache.

the class CountersPBImpl method initCounterGroups.

private void initCounterGroups() {
    if (this.counterGroups != null) {
        return;
    }
    CountersProtoOrBuilder p = viaProto ? proto : builder;
    List<StringCounterGroupMapProto> list = p.getCounterGroupsList();
    this.counterGroups = new HashMap<String, CounterGroup>();
    for (StringCounterGroupMapProto c : list) {
        this.counterGroups.put(c.getKey(), convertFromProtoFormat(c.getValue()));
    }
}
Also used : StringCounterGroupMapProto(org.apache.hadoop.mapreduce.v2.proto.MRProtos.StringCounterGroupMapProto) CounterGroup(org.apache.hadoop.mapreduce.v2.api.records.CounterGroup) CountersProtoOrBuilder(org.apache.hadoop.mapreduce.v2.proto.MRProtos.CountersProtoOrBuilder)

Example 5 with CounterGroup

use of org.apache.hadoop.mapreduce.v2.api.records.CounterGroup in project hadoop by apache.

the class TestClientRedirect method getMyCounters.

static Counters getMyCounters() {
    Counter counter = recordFactory.newRecordInstance(Counter.class);
    counter.setName("Mycounter");
    counter.setDisplayName("My counter display name");
    counter.setValue(12345);
    CounterGroup group = recordFactory.newRecordInstance(CounterGroup.class);
    group.setName("MyGroup");
    group.setDisplayName("My groupd display name");
    group.setCounter("myCounter", counter);
    Counters counters = recordFactory.newRecordInstance(Counters.class);
    counters.setCounterGroup("myGroupd", group);
    return counters;
}
Also used : Counter(org.apache.hadoop.mapreduce.v2.api.records.Counter) CounterGroup(org.apache.hadoop.mapreduce.v2.api.records.CounterGroup) Counters(org.apache.hadoop.mapreduce.v2.api.records.Counters)

Aggregations

CounterGroup (org.apache.hadoop.mapreduce.v2.api.records.CounterGroup)9 Counters (org.apache.hadoop.mapreduce.v2.api.records.Counters)6 Counter (org.apache.hadoop.mapreduce.v2.api.records.Counter)5 Counters (org.apache.hadoop.mapreduce.Counters)2 GetCountersResponse (org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetCountersResponse)2 TaskAttemptId (org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId)2 TaskAttempt (org.apache.hadoop.mapreduce.v2.app.job.TaskAttempt)2 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Counter (org.apache.hadoop.mapreduce.Counter)1 CounterGroup (org.apache.hadoop.mapreduce.CounterGroup)1 GetCountersRequest (org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetCountersRequest)1 GetTaskReportResponse (org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetTaskReportResponse)1 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)1 TaskId (org.apache.hadoop.mapreduce.v2.api.records.TaskId)1 TaskReport (org.apache.hadoop.mapreduce.v2.api.records.TaskReport)1 Task (org.apache.hadoop.mapreduce.v2.app.job.Task)1 CountersProtoOrBuilder (org.apache.hadoop.mapreduce.v2.proto.MRProtos.CountersProtoOrBuilder)1 StringCounterGroupMapProto (org.apache.hadoop.mapreduce.v2.proto.MRProtos.StringCounterGroupMapProto)1 YarnRuntimeException (org.apache.hadoop.yarn.exceptions.YarnRuntimeException)1