Search in sources :

Example 6 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 7 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 8 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.mapreduce.Counters counters) {
    if (counters == null) {
        return null;
    }
    Counters yCntrs = recordFactory.newRecordInstance(Counters.class);
    yCntrs.addAllCounterGroups(new HashMap<String, CounterGroup>());
    for (org.apache.hadoop.mapreduce.CounterGroup 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.mapreduce.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 9 with CounterGroup

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

the class CountersPBImpl method incrCounter.

@Override
public void incrCounter(Enum<?> key, long amount) {
    String groupName = key.getDeclaringClass().getName();
    if (getCounterGroup(groupName) == null) {
        CounterGroup cGrp = new CounterGroupPBImpl();
        cGrp.setName(groupName);
        cGrp.setDisplayName(groupName);
        setCounterGroup(groupName, cGrp);
    }
    if (getCounterGroup(groupName).getCounter(key.name()) == null) {
        Counter c = new CounterPBImpl();
        c.setName(key.name());
        c.setDisplayName(key.name());
        c.setValue(0l);
        getCounterGroup(groupName).setCounter(key.name(), c);
    }
    Counter counter = getCounterGroup(groupName).getCounter(key.name());
    counter.setValue(counter.getValue() + amount);
}
Also used : Counter(org.apache.hadoop.mapreduce.v2.api.records.Counter) CounterGroup(org.apache.hadoop.mapreduce.v2.api.records.CounterGroup)

Example 10 with CounterGroup

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

the class TestRecordFactory method testPbRecordFactory.

@Test
public void testPbRecordFactory() {
    RecordFactory pbRecordFactory = RecordFactoryPBImpl.get();
    try {
        CounterGroup response = pbRecordFactory.newRecordInstance(CounterGroup.class);
        Assert.assertEquals(CounterGroupPBImpl.class, response.getClass());
    } catch (YarnRuntimeException e) {
        e.printStackTrace();
        Assert.fail("Failed to crete record");
    }
    try {
        GetCountersRequest response = pbRecordFactory.newRecordInstance(GetCountersRequest.class);
        Assert.assertEquals(GetCountersRequestPBImpl.class, response.getClass());
    } catch (YarnRuntimeException e) {
        e.printStackTrace();
        Assert.fail("Failed to crete record");
    }
}
Also used : YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) GetCountersRequest(org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetCountersRequest) RecordFactory(org.apache.hadoop.yarn.factories.RecordFactory) CounterGroup(org.apache.hadoop.mapreduce.v2.api.records.CounterGroup) Test(org.junit.Test)

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