@SuppressWarnings("rawtypes") @Test public void testFrameworkCounter() { GroupFactory groupFactory = new GroupFactoryForTest(); FrameworkGroupFactory frameworkGroupFactory = groupFactory.newFrameworkGroupFactory(JobCounter.class); Group group = (Group) frameworkGroupFactory.newGroup("JobCounter"); FrameworkCounterGroup counterGroup = (FrameworkCounterGroup) group.getUnderlyingGroup(); org.apache.hadoop.mapreduce.Counter count1 = counterGroup.findCounter(JobCounter.NUM_FAILED_MAPS.toString()); Assert.assertNotNull(count1); // Verify no exception get thrown when finding an unknown counter org.apache.hadoop.mapreduce.Counter count2 = counterGroup.findCounter("Unknown"); Assert.assertNull(count2); }
@Override public C addCounter(String name, String displayName, long value) { C counter = findCounter(name); if (counter != null) { counter.setValue(value); } else { LOG.warn(name + "is not a known counter."); } return counter; }
@Override public C findCounter(String counterName, boolean create) { try { return findCounter(valueOf(counterName)); } catch (Exception e) { if (create) throw new IllegalArgumentException(e); return null; } }
@Override public C addCounter(String name, String displayName, long value) { C counter = findCounter(name); if (counter != null) { counter.setValue(value); } else { LOG.warn(name + "is not a known counter."); } return counter; }
@Override public C findCounter(String counterName, boolean create) { try { return findCounter(valueOf(counterName)); } catch (Exception e) { if (create) throw new IllegalArgumentException(e); return null; } }
@Override public C addCounter(String name, String displayName, long value) { C counter = findCounter(name); if (counter != null) { counter.setValue(value); } else { LOG.warn(name + "is not a known counter."); } return counter; }
@Override public C findCounter(String counterName) { try { T enumValue = valueOf(counterName); return findCounter(enumValue); } catch (IllegalArgumentException e) { LOG.warn(counterName + " is not a recognized counter."); return null; } }
@Override public C findCounter(String counterName) { try { T enumValue = valueOf(counterName); return findCounter(enumValue); } catch (IllegalArgumentException e) { LOG.warn(counterName + " is not a recognized counter."); return null; } }
@Override public C findCounter(String counterName, boolean create) { try { return findCounter(valueOf(counterName)); } catch (Exception e) { if (create) throw new IllegalArgumentException(e); return null; } }
@Override public C findCounter(String counterName) { try { T enumValue = valueOf(counterName); return findCounter(enumValue); } catch (IllegalArgumentException e) { LOG.warn(counterName + " is not a recognized counter."); return null; } }
@Override public C findCounter(String counterName, boolean create) { try { return findCounter(valueOf(counterName)); } catch (Exception e) { if (create) throw new IllegalArgumentException(e); return null; } }
@SuppressWarnings("rawtypes") @Test public void testTaskCounter() { GroupFactory groupFactory = new GroupFactoryForTest(); FrameworkGroupFactory frameworkGroupFactory = groupFactory.newFrameworkGroupFactory(TaskCounter.class); Group group = (Group) frameworkGroupFactory.newGroup("TaskCounter"); FrameworkCounterGroup counterGroup = (FrameworkCounterGroup) group.getUnderlyingGroup(); org.apache.hadoop.mapreduce.Counter count1 = counterGroup.findCounter( TaskCounter.PHYSICAL_MEMORY_BYTES.toString()); Assert.assertNotNull(count1); count1.increment(10); count1.increment(10); Assert.assertEquals(20, count1.getValue()); // Verify no exception get thrown when finding an unknown counter org.apache.hadoop.mapreduce.Counter count2 = counterGroup.findCounter( TaskCounter.MAP_PHYSICAL_MEMORY_BYTES_MAX.toString()); Assert.assertNotNull(count2); count2.increment(5); count2.increment(10); Assert.assertEquals(10, count2.getValue()); }
@Override @SuppressWarnings("rawtypes") public void incrAllCounters(CounterGroupBase<C> other) { if (checkNotNull(other, "other counter group") instanceof FrameworkCounterGroup<?, ?>) { for (Counter counter : other) { C c = findCounter(((FrameworkCounter) counter).key.name()); if (c != null) { c.increment(counter.getValue()); } } } }
@Override @SuppressWarnings("rawtypes") public void incrAllCounters(CounterGroupBase<C> other) { if (checkNotNull(other, "other counter group") instanceof FrameworkCounterGroup<?, ?>) { for (Counter counter : other) { C c = findCounter(((FrameworkCounter) counter).key.name()); if (c != null) { c.increment(counter.getValue()); } } } }
@Override public C addCounter(String name, String displayName, long value) { C counter = findCounter(name); if (counter != null) { counter.setValue(value); } else { LOG.warn(name + "is not a known counter."); } return counter; }
@Override @SuppressWarnings("rawtypes") public void incrAllCounters(CounterGroupBase<C> other) { if (checkNotNull(other, "other counter group") instanceof FrameworkCounterGroup<?, ?>) { for (Counter counter : other) { C c = findCounter(((FrameworkCounter) counter).key.name()); if (c != null) { c.increment(counter.getValue()); } } } }
@Override public void addCounter(C counter) { C ours = findCounter(counter.getName()); if (ours != null) { ours.setValue(counter.getValue()); } else { LOG.warn(counter.getName() + "is not a known counter."); } }
@Override public void addCounter(C counter) { C ours = findCounter(counter.getName()); if (ours != null) { ours.setValue(counter.getValue()); } else { LOG.warn(counter.getName() + "is not a known counter."); } }
@Override public void addCounter(C counter) { C ours = findCounter(counter.getName()); if (ours != null) { ours.setValue(counter.getValue()); } else { LOG.warn(counter.getName() + "is not a known counter."); } }
@Override public void addCounter(C counter) { C ours = findCounter(counter.getName()); if (ours != null) { ours.setValue(counter.getValue()); } else { LOG.warn(counter.getName() + "is not a known counter."); } }