Java Code Examples for org.apache.hadoop.mapreduce.v2.api.records.CounterGroup

The following examples show how to use org.apache.hadoop.mapreduce.v2.api.records.CounterGroup. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hadoop   Source File: TestClientServiceDelegate.java    License: Apache License 2.0 6 votes vote down vote up
private GetCountersResponse getCountersResponseFromHistoryServer() {
  GetCountersResponse countersResponse = Records
      .newRecord(GetCountersResponse.class);
  Counter counter = Records.newRecord(Counter.class);
  CounterGroup counterGroup = Records.newRecord(CounterGroup.class);
  Counters counters = Records.newRecord(Counters.class);
  counter.setDisplayName("dummyCounter");
  counter.setName("dummyCounter");
  counter.setValue(1001);
  counterGroup.setName("dummyCounters");
  counterGroup.setDisplayName("dummyCounters");
  counterGroup.setCounter("dummyCounter", counter);
  counters.setCounterGroup("dummyCounters", counterGroup);
  countersResponse.setCounters(counters);
  return countersResponse;
}
 
Example 2
Source Project: hadoop   Source File: TestClientRedirect.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source Project: hadoop   Source File: TypeConverter.java    License: Apache License 2.0 6 votes vote down vote up
public static org.apache.hadoop.mapreduce.Counters fromYarn(
    Counters yCntrs) {
  if (yCntrs == null) {
    return null;
  }
  org.apache.hadoop.mapreduce.Counters counters =
    new org.apache.hadoop.mapreduce.Counters();
  for (CounterGroup yGrp : yCntrs.getAllCounterGroups().values()) {
    counters.addGroup(yGrp.getName(), yGrp.getDisplayName());
    for (Counter yCntr : yGrp.getAllCounters().values()) {
      org.apache.hadoop.mapreduce.Counter c =
        counters.findCounter(yGrp.getName(),
            yCntr.getName());
      // if c can be found, or it will be skipped.
      if (c != null) {
        c.setValue(yCntr.getValue());
      }
    }
  }
  return counters;
}
 
Example 4
Source Project: hadoop   Source File: TypeConverter.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 5
Source Project: hadoop   Source File: TypeConverter.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 6
Source Project: hadoop   Source File: CountersPBImpl.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 7
Source Project: big-c   Source File: TestClientServiceDelegate.java    License: Apache License 2.0 6 votes vote down vote up
private GetCountersResponse getCountersResponseFromHistoryServer() {
  GetCountersResponse countersResponse = Records
      .newRecord(GetCountersResponse.class);
  Counter counter = Records.newRecord(Counter.class);
  CounterGroup counterGroup = Records.newRecord(CounterGroup.class);
  Counters counters = Records.newRecord(Counters.class);
  counter.setDisplayName("dummyCounter");
  counter.setName("dummyCounter");
  counter.setValue(1001);
  counterGroup.setName("dummyCounters");
  counterGroup.setDisplayName("dummyCounters");
  counterGroup.setCounter("dummyCounter", counter);
  counters.setCounterGroup("dummyCounters", counterGroup);
  countersResponse.setCounters(counters);
  return countersResponse;
}
 
Example 8
Source Project: big-c   Source File: TestClientRedirect.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 9
Source Project: big-c   Source File: TypeConverter.java    License: Apache License 2.0 6 votes vote down vote up
public static org.apache.hadoop.mapreduce.Counters fromYarn(
    Counters yCntrs) {
  if (yCntrs == null) {
    return null;
  }
  org.apache.hadoop.mapreduce.Counters counters =
    new org.apache.hadoop.mapreduce.Counters();
  for (CounterGroup yGrp : yCntrs.getAllCounterGroups().values()) {
    counters.addGroup(yGrp.getName(), yGrp.getDisplayName());
    for (Counter yCntr : yGrp.getAllCounters().values()) {
      org.apache.hadoop.mapreduce.Counter c =
        counters.findCounter(yGrp.getName(),
            yCntr.getName());
      // if c can be found, or it will be skipped.
      if (c != null) {
        c.setValue(yCntr.getValue());
      }
    }
  }
  return counters;
}
 
Example 10
Source Project: big-c   Source File: TypeConverter.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 11
Source Project: big-c   Source File: TypeConverter.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 12
Source Project: big-c   Source File: CountersPBImpl.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 13
Source Project: hadoop   Source File: NotRunningJob.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public GetCountersResponse getCounters(GetCountersRequest request)
    throws IOException {
  GetCountersResponse resp =
    recordFactory.newRecordInstance(GetCountersResponse.class);
  Counters counters = recordFactory.newRecordInstance(Counters.class);
  counters.addAllCounterGroups(new HashMap<String, CounterGroup>());
  resp.setCounters(counters);
  return resp;
}
 
Example 14
Source Project: hadoop   Source File: NotRunningJob.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public GetTaskReportResponse getTaskReport(GetTaskReportRequest request)
    throws IOException {
  GetTaskReportResponse resp =
    recordFactory.newRecordInstance(GetTaskReportResponse.class);
  TaskReport report = recordFactory.newRecordInstance(TaskReport.class);
  report.setTaskId(request.getTaskId());
  report.setTaskState(TaskState.NEW);
  Counters counters = recordFactory.newRecordInstance(Counters.class);
  counters.addAllCounterGroups(new HashMap<String, CounterGroup>());
  report.setCounters(counters);
  report.addAllRunningAttempts(new ArrayList<TaskAttemptId>());
  return resp;
}
 
Example 15
Source Project: hadoop   Source File: TestClientRedirect.java    License: Apache License 2.0 5 votes vote down vote up
private void validateCounters(org.apache.hadoop.mapreduce.Counters counters) {
  Iterator<org.apache.hadoop.mapreduce.CounterGroup> it = counters.iterator();
  while (it.hasNext()) {
    org.apache.hadoop.mapreduce.CounterGroup group = it.next();
    LOG.info("Group " + group.getDisplayName());
    Iterator<org.apache.hadoop.mapreduce.Counter> itc = group.iterator();
    while (itc.hasNext()) {
      LOG.info("Counter is " + itc.next().getDisplayName());
    }
  }
  Assert.assertEquals(1, counters.countCounters());
}
 
Example 16
Source Project: hadoop   Source File: CountersPBImpl.java    License: Apache License 2.0 5 votes vote down vote up
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()));
  }
}
 
Example 17
Source Project: hadoop   Source File: CountersPBImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void addAllCounterGroups(final Map<String, CounterGroup> counterGroups) {
  if (counterGroups == null)
    return;
  initCounterGroups();
  this.counterGroups.putAll(counterGroups);
}
 
Example 18
Source Project: big-c   Source File: NotRunningJob.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public GetCountersResponse getCounters(GetCountersRequest request)
    throws IOException {
  GetCountersResponse resp =
    recordFactory.newRecordInstance(GetCountersResponse.class);
  Counters counters = recordFactory.newRecordInstance(Counters.class);
  counters.addAllCounterGroups(new HashMap<String, CounterGroup>());
  resp.setCounters(counters);
  return resp;
}
 
Example 19
Source Project: big-c   Source File: NotRunningJob.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public GetTaskReportResponse getTaskReport(GetTaskReportRequest request)
    throws IOException {
  GetTaskReportResponse resp =
    recordFactory.newRecordInstance(GetTaskReportResponse.class);
  TaskReport report = recordFactory.newRecordInstance(TaskReport.class);
  report.setTaskId(request.getTaskId());
  report.setTaskState(TaskState.NEW);
  Counters counters = recordFactory.newRecordInstance(Counters.class);
  counters.addAllCounterGroups(new HashMap<String, CounterGroup>());
  report.setCounters(counters);
  report.addAllRunningAttempts(new ArrayList<TaskAttemptId>());
  return resp;
}
 
Example 20
Source Project: big-c   Source File: TestClientRedirect.java    License: Apache License 2.0 5 votes vote down vote up
private void validateCounters(org.apache.hadoop.mapreduce.Counters counters) {
  Iterator<org.apache.hadoop.mapreduce.CounterGroup> it = counters.iterator();
  while (it.hasNext()) {
    org.apache.hadoop.mapreduce.CounterGroup group = it.next();
    LOG.info("Group " + group.getDisplayName());
    Iterator<org.apache.hadoop.mapreduce.Counter> itc = group.iterator();
    while (itc.hasNext()) {
      LOG.info("Counter is " + itc.next().getDisplayName());
    }
  }
  Assert.assertEquals(1, counters.countCounters());
}
 
Example 21
Source Project: big-c   Source File: CountersPBImpl.java    License: Apache License 2.0 5 votes vote down vote up
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()));
  }
}
 
Example 22
Source Project: big-c   Source File: CountersPBImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void addAllCounterGroups(final Map<String, CounterGroup> counterGroups) {
  if (counterGroups == null)
    return;
  initCounterGroups();
  this.counterGroups.putAll(counterGroups);
}
 
Example 23
Source Project: incubator-tez   Source File: NotRunningJob.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public GetCountersResponse getCounters(GetCountersRequest request)
    throws IOException {
  GetCountersResponse resp =
    recordFactory.newRecordInstance(GetCountersResponse.class);
  Counters counters = recordFactory.newRecordInstance(Counters.class);
  counters.addAllCounterGroups(new HashMap<String, CounterGroup>());
  resp.setCounters(counters);
  return resp;
}
 
Example 24
Source Project: incubator-tez   Source File: NotRunningJob.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public GetTaskReportResponse getTaskReport(GetTaskReportRequest request)
    throws IOException {
  GetTaskReportResponse resp =
    recordFactory.newRecordInstance(GetTaskReportResponse.class);
  TaskReport report = recordFactory.newRecordInstance(TaskReport.class);
  report.setTaskId(request.getTaskId());
  report.setTaskState(TaskState.NEW);
  Counters counters = recordFactory.newRecordInstance(Counters.class);
  counters.addAllCounterGroups(new HashMap<String, CounterGroup>());
  report.setCounters(counters);
  report.addAllRunningAttempts(new ArrayList<TaskAttemptId>());
  return resp;
}
 
Example 25
Source Project: tez   Source File: NotRunningJob.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public GetCountersResponse getCounters(GetCountersRequest request)
    throws IOException {
  GetCountersResponse resp =
    recordFactory.newRecordInstance(GetCountersResponse.class);
  Counters counters = recordFactory.newRecordInstance(Counters.class);
  counters.addAllCounterGroups(new HashMap<String, CounterGroup>());
  resp.setCounters(counters);
  return resp;
}
 
Example 26
Source Project: tez   Source File: NotRunningJob.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public GetTaskReportResponse getTaskReport(GetTaskReportRequest request)
    throws IOException {
  GetTaskReportResponse resp =
    recordFactory.newRecordInstance(GetTaskReportResponse.class);
  TaskReport report = recordFactory.newRecordInstance(TaskReport.class);
  report.setTaskId(request.getTaskId());
  report.setTaskState(TaskState.NEW);
  Counters counters = recordFactory.newRecordInstance(Counters.class);
  counters.addAllCounterGroups(new HashMap<String, CounterGroup>());
  report.setCounters(counters);
  report.addAllRunningAttempts(new ArrayList<TaskAttemptId>());
  return resp;
}
 
Example 27
Source Project: hadoop   Source File: CountersPBImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, CounterGroup> getAllCounterGroups() {
  initCounterGroups();
  return this.counterGroups;
}
 
Example 28
Source Project: hadoop   Source File: CountersPBImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public CounterGroup getCounterGroup(String key) {
  initCounterGroups();
  return this.counterGroups.get(key);
}
 
Example 29
Source Project: hadoop   Source File: CountersPBImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Counter getCounter(Enum<?> key) {
  CounterGroup group = getCounterGroup(key.getDeclaringClass().getName());
  return group == null ? null : group.getCounter(key.name());
}
 
Example 30
Source Project: hadoop   Source File: CountersPBImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setCounterGroup(String key, CounterGroup val) {
  initCounterGroups();
  this.counterGroups.put(key, val);
}