gcBeans =
- ManagementFactory.getGarbageCollectorMXBeans();
- long count = 0;
- long timeMillis = 0;
- for (GarbageCollectorMXBean gcBean : gcBeans) {
- count += gcBean.getCollectionCount();
- timeMillis += gcBean.getCollectionTime();
- }
- metrics.incrMetric("gcCount", (int)(count - gcCount));
- metrics.incrMetric("gcTimeMillis", (int)(timeMillis - gcTimeMillis));
-
- gcCount = count;
- gcTimeMillis = timeMillis;
- }
-
- private void doThreadUpdates() {
- ThreadMXBean threadMXBean =
- ManagementFactory.getThreadMXBean();
- long threadIds[] =
- threadMXBean.getAllThreadIds();
- ThreadInfo[] threadInfos =
- threadMXBean.getThreadInfo(threadIds, 0);
-
- int threadsNew = 0;
- int threadsRunnable = 0;
- int threadsBlocked = 0;
- int threadsWaiting = 0;
- int threadsTimedWaiting = 0;
- int threadsTerminated = 0;
-
- for (ThreadInfo threadInfo : threadInfos) {
- // threadInfo is null if the thread is not alive or doesn't exist
- if (threadInfo == null) continue;
- Thread.State state = threadInfo.getThreadState();
- if (state == NEW) {
- threadsNew++;
- }
- else if (state == RUNNABLE) {
- threadsRunnable++;
- }
- else if (state == BLOCKED) {
- threadsBlocked++;
- }
- else if (state == WAITING) {
- threadsWaiting++;
- }
- else if (state == TIMED_WAITING) {
- threadsTimedWaiting++;
- }
- else if (state == TERMINATED) {
- threadsTerminated++;
- }
- }
- metrics.setMetric("threadsNew", threadsNew);
- metrics.setMetric("threadsRunnable", threadsRunnable);
- metrics.setMetric("threadsBlocked", threadsBlocked);
- metrics.setMetric("threadsWaiting", threadsWaiting);
- metrics.setMetric("threadsTimedWaiting", threadsTimedWaiting);
- metrics.setMetric("threadsTerminated", threadsTerminated);
- }
-
- private void doEventCountUpdates() {
- long newFatal = EventCounter.getFatal();
- long newError = EventCounter.getError();
- long newWarn = EventCounter.getWarn();
- long newInfo = EventCounter.getInfo();
-
- metrics.incrMetric("logFatal", (int)(newFatal - fatalCount));
- metrics.incrMetric("logError", (int)(newError - errorCount));
- metrics.incrMetric("logWarn", (int)(newWarn - warnCount));
- metrics.incrMetric("logInfo", (int)(newInfo - infoCount));
-
- fatalCount = newFatal;
- errorCount = newError;
- warnCount = newWarn;
- infoCount = newInfo;
- }
-}
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/jvm/package-info.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/jvm/package-info.java
deleted file mode 100644
index d4661e3f741..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/jvm/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-@InterfaceAudience.Private
-@InterfaceStability.Evolving
-package org.apache.hadoop.metrics.jvm;
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.classification.InterfaceStability;
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/package.html b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/package.html
deleted file mode 100644
index dd16e382dac..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/package.html
+++ /dev/null
@@ -1,159 +0,0 @@
-
-
-
-
-
- org.apache.hadoop.metrics
-
-
-This package defines an API for reporting performance metric information.
-
-The API is abstract so that it can be implemented on top of
-a variety of metrics client libraries. The choice of
-client library is a configuration option, and different
-modules within the same application can use
-different metrics implementation libraries.
-
-Sub-packages:
-
- org.apache.hadoop.metrics.spi
- - The abstract Server Provider Interface package. Those wishing to
- integrate the metrics API with a particular metrics client library should
- extend this package.
-
- org.apache.hadoop.metrics.file
- - An implementation package which writes the metric data to
- a file, or sends it to the standard output stream.
-
- -
org.apache.hadoop.metrics.ganglia
- - An implementation package which sends metric data to
- Ganglia.
-
-
-Introduction to the Metrics API
-
-Here is a simple example of how to use this package to report a single
-metric value:
-
- private ContextFactory contextFactory = ContextFactory.getFactory();
-
- void reportMyMetric(float myMetric) {
- MetricsContext myContext = contextFactory.getContext("myContext");
- MetricsRecord myRecord = myContext.getRecord("myRecord");
- myRecord.setMetric("myMetric", myMetric);
- myRecord.update();
- }
-
-
-In this example there are three names:
-
- - myContext
- - The context name will typically identify either the application, or else a
- module within an application or library.
-
- - myRecord
- - The record name generally identifies some entity for which a set of
- metrics are to be reported. For example, you could have a record named
- "cacheStats" for reporting a number of statistics relating to the usage of
- some cache in your application.
-
- - myMetric
- - This identifies a particular metric. For example, you might have metrics
- named "cache_hits" and "cache_misses".
-
-
-
-Tags
-
-In some cases it is useful to have multiple records with the same name. For
-example, suppose that you want to report statistics about each disk on a computer.
-In this case, the record name would be something like "diskStats", but you also
-need to identify the disk which is done by adding a tag to the record.
-The code could look something like this:
-
- private MetricsRecord diskStats =
- contextFactory.getContext("myContext").getRecord("diskStats");
-
- void reportDiskMetrics(String diskName, float diskBusy, float diskUsed) {
- diskStats.setTag("diskName", diskName);
- diskStats.setMetric("diskBusy", diskBusy);
- diskStats.setMetric("diskUsed", diskUsed);
- diskStats.update();
- }
-
-
-Buffering and Callbacks
-
-Data is not sent immediately to the metrics system when
-MetricsRecord.update()
is called. Instead it is stored in an
-internal table, and the contents of the table are sent periodically.
-This can be important for two reasons:
-
- - It means that a programmer is free to put calls to this API in an
- inner loop, since updates can be very frequent without slowing down
- the application significantly.
- - Some implementations can gain efficiency by combining many metrics
- into a single UDP message.
-
-
-The API provides a timer-based callback via the
-registerUpdater()
method. The benefit of this
-versus using java.util.Timer
is that the callbacks will be done
-immediately before sending the data, making the data as current as possible.
-
-Configuration
-
-It is possible to programmatically examine and modify configuration data
-before creating a context, like this:
-
- ContextFactory factory = ContextFactory.getFactory();
- ... examine and/or modify factory attributes ...
- MetricsContext context = factory.getContext("myContext");
-
-The factory attributes can be examined and modified using the following
-ContextFactory
methods:
-
- Object getAttribute(String attributeName)
- String[] getAttributeNames()
- void setAttribute(String name, Object value)
- void removeAttribute(attributeName)
-
-
-
-ContextFactory.getFactory()
initializes the factory attributes by
-reading the properties file hadoop-metrics.properties
if it exists
-on the class path.
-
-
-A factory attribute named:
-
-contextName.class
-
-should have as its value the fully qualified name of the class to be
-instantiated by a call of the CodeFactory
method
-getContext(contextName)
. If this factory attribute is not
-specified, the default is to instantiate
-org.apache.hadoop.metrics.file.FileContext
.
-
-
-Other factory attributes are specific to a particular implementation of this
-API and are documented elsewhere. For example, configuration attributes for
-the file and Ganglia implementations can be found in the javadoc for
-their respective packages.
-
-
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/AbstractMetricsContext.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/AbstractMetricsContext.java
deleted file mode 100644
index dccfbe9fd88..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/AbstractMetricsContext.java
+++ /dev/null
@@ -1,494 +0,0 @@
-/*
- * AbstractMetricsContext.java
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.metrics.spi;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.TreeMap;
-import java.util.Map.Entry;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.classification.InterfaceStability;
-import org.apache.hadoop.metrics.ContextFactory;
-import org.apache.hadoop.metrics.MetricsContext;
-import org.apache.hadoop.metrics.MetricsException;
-import org.apache.hadoop.metrics.MetricsRecord;
-import org.apache.hadoop.metrics.Updater;
-
-/**
- * The main class of the Service Provider Interface. This class should be
- * extended in order to integrate the Metrics API with a specific metrics
- * client library.
- *
- * This class implements the internal table of metric data, and the timer
- * on which data is to be sent to the metrics system. Subclasses must
- * override the abstract emitRecord
method in order to transmit
- * the data.
- *
- * @deprecated Use org.apache.hadoop.metrics2 package instead.
- */
-@Deprecated
-@InterfaceAudience.Public
-@InterfaceStability.Evolving
-public abstract class AbstractMetricsContext implements MetricsContext {
-
- private int period = MetricsContext.DEFAULT_PERIOD;
- private Timer timer = null;
-
- private Set updaters = new HashSet(1);
- private volatile boolean isMonitoring = false;
-
- private ContextFactory factory = null;
- private String contextName = null;
-
- @InterfaceAudience.Private
- public static class TagMap extends TreeMap {
- private static final long serialVersionUID = 3546309335061952993L;
- TagMap() {
- super();
- }
- TagMap(TagMap orig) {
- super(orig);
- }
- /**
- * Returns true if this tagmap contains every tag in other.
- */
- public boolean containsAll(TagMap other) {
- for (Map.Entry entry : other.entrySet()) {
- Object value = get(entry.getKey());
- if (value == null || !value.equals(entry.getValue())) {
- // either key does not exist here, or the value is different
- return false;
- }
- }
- return true;
- }
- }
-
- @InterfaceAudience.Private
- public static class MetricMap extends TreeMap {
- private static final long serialVersionUID = -7495051861141631609L;
- MetricMap() {
- super();
- }
- MetricMap(MetricMap orig) {
- super(orig);
- }
- }
-
- static class RecordMap extends HashMap {
- private static final long serialVersionUID = 259835619700264611L;
- }
-
- private Map bufferedData = new HashMap();
-
-
- /**
- * Creates a new instance of AbstractMetricsContext
- */
- protected AbstractMetricsContext() {
- }
-
- /**
- * Initializes the context.
- */
- @Override
- public void init(String contextName, ContextFactory factory)
- {
- this.contextName = contextName;
- this.factory = factory;
- }
-
- /**
- * Convenience method for subclasses to access factory attributes.
- */
- protected String getAttribute(String attributeName) {
- String factoryAttribute = contextName + "." + attributeName;
- return (String) factory.getAttribute(factoryAttribute);
- }
-
- /**
- * Returns an attribute-value map derived from the factory attributes
- * by finding all factory attributes that begin with
- * contextName.tableName. The returned map consists of
- * those attributes with the contextName and tableName stripped off.
- */
- protected Map getAttributeTable(String tableName) {
- String prefix = contextName + "." + tableName + ".";
- Map result = new HashMap();
- for (String attributeName : factory.getAttributeNames()) {
- if (attributeName.startsWith(prefix)) {
- String name = attributeName.substring(prefix.length());
- String value = (String) factory.getAttribute(attributeName);
- result.put(name, value);
- }
- }
- return result;
- }
-
- /**
- * Returns the context name.
- */
- @Override
- public String getContextName() {
- return contextName;
- }
-
- /**
- * Returns the factory by which this context was created.
- */
- public ContextFactory getContextFactory() {
- return factory;
- }
-
- /**
- * Starts or restarts monitoring, the emitting of metrics records.
- */
- @Override
- public synchronized void startMonitoring()
- throws IOException {
- if (!isMonitoring) {
- startTimer();
- isMonitoring = true;
- }
- }
-
- /**
- * Stops monitoring. This does not free buffered data.
- * @see #close()
- */
- @Override
- public synchronized void stopMonitoring() {
- if (isMonitoring) {
- stopTimer();
- isMonitoring = false;
- }
- }
-
- /**
- * Returns true if monitoring is currently in progress.
- */
- @Override
- public boolean isMonitoring() {
- return isMonitoring;
- }
-
- /**
- * Stops monitoring and frees buffered data, returning this
- * object to its initial state.
- */
- @Override
- public synchronized void close() {
- stopMonitoring();
- clearUpdaters();
- }
-
- /**
- * Creates a new AbstractMetricsRecord instance with the given recordName
.
- * Throws an exception if the metrics implementation is configured with a fixed
- * set of record names and recordName
is not in that set.
- *
- * @param recordName the name of the record
- * @throws MetricsException if recordName conflicts with configuration data
- */
- @Override
- public final synchronized MetricsRecord createRecord(String recordName) {
- if (bufferedData.get(recordName) == null) {
- bufferedData.put(recordName, new RecordMap());
- }
- return newRecord(recordName);
- }
-
- /**
- * Subclasses should override this if they subclass MetricsRecordImpl.
- * @param recordName the name of the record
- * @return newly created instance of MetricsRecordImpl or subclass
- */
- protected MetricsRecord newRecord(String recordName) {
- return new MetricsRecordImpl(recordName, this);
- }
-
- /**
- * Registers a callback to be called at time intervals determined by
- * the configuration.
- *
- * @param updater object to be run periodically; it should update
- * some metrics records
- */
- @Override
- public synchronized void registerUpdater(final Updater updater) {
- if (!updaters.contains(updater)) {
- updaters.add(updater);
- }
- }
-
- /**
- * Removes a callback, if it exists.
- *
- * @param updater object to be removed from the callback list
- */
- @Override
- public synchronized void unregisterUpdater(Updater updater) {
- updaters.remove(updater);
- }
-
- private synchronized void clearUpdaters() {
- updaters.clear();
- }
-
- /**
- * Starts timer if it is not already started
- */
- private synchronized void startTimer() {
- if (timer == null) {
- timer = new Timer("Timer thread for monitoring " + getContextName(),
- true);
- TimerTask task = new TimerTask() {
- @Override
- public void run() {
- try {
- timerEvent();
- } catch (IOException ioe) {
- ioe.printStackTrace();
- }
- }
- };
- long millis = period * 1000;
- timer.scheduleAtFixedRate(task, millis, millis);
- }
- }
-
- /**
- * Stops timer if it is running
- */
- private synchronized void stopTimer() {
- if (timer != null) {
- timer.cancel();
- timer = null;
- }
- }
-
- /**
- * Timer callback.
- */
- private void timerEvent() throws IOException {
- if (isMonitoring) {
- Collection myUpdaters;
- synchronized (this) {
- myUpdaters = new ArrayList(updaters);
- }
- // Run all the registered updates without holding a lock
- // on this context
- for (Updater updater : myUpdaters) {
- try {
- updater.doUpdates(this);
- } catch (Throwable throwable) {
- throwable.printStackTrace();
- }
- }
- emitRecords();
- }
- }
-
- /**
- * Emits the records.
- */
- private synchronized void emitRecords() throws IOException {
- for (Map.Entry recordEntry : bufferedData.entrySet()) {
- RecordMap recordMap = recordEntry.getValue();
- synchronized (recordMap) {
- Set> entrySet = recordMap.entrySet ();
- for (Entry entry : entrySet) {
- OutputRecord outRec = new OutputRecord(entry.getKey(), entry.getValue());
- emitRecord(contextName, recordEntry.getKey(), outRec);
- }
- }
- }
- flush();
- }
-
- /**
- * Retrieves all the records managed by this MetricsContext.
- * Useful for monitoring systems that are polling-based.
- * @return A non-null collection of all monitoring records.
- */
- @Override
- public synchronized Map> getAllRecords() {
- Map> out = new TreeMap>();
- for (Map.Entry recordEntry : bufferedData.entrySet()) {
- RecordMap recordMap = recordEntry.getValue();
- synchronized (recordMap) {
- List records = new ArrayList();
- Set> entrySet = recordMap.entrySet();
- for (Entry entry : entrySet) {
- OutputRecord outRec = new OutputRecord(entry.getKey(), entry.getValue());
- records.add(outRec);
- }
- out.put(recordEntry.getKey(), records);
- }
- }
- return out;
- }
-
- /**
- * Sends a record to the metrics system.
- */
- protected abstract void emitRecord(String contextName, String recordName,
- OutputRecord outRec) throws IOException;
-
- /**
- * Called each period after all records have been emitted, this method does nothing.
- * Subclasses may override it in order to perform some kind of flush.
- */
- protected void flush() throws IOException {
- }
-
- /**
- * Called by MetricsRecordImpl.update(). Creates or updates a row in
- * the internal table of metric data.
- */
- protected void update(MetricsRecordImpl record) {
- String recordName = record.getRecordName();
- TagMap tagTable = record.getTagTable();
- Map metricUpdates = record.getMetricTable();
-
- RecordMap recordMap = getRecordMap(recordName);
- synchronized (recordMap) {
- MetricMap metricMap = recordMap.get(tagTable);
- if (metricMap == null) {
- metricMap = new MetricMap();
- TagMap tagMap = new TagMap(tagTable); // clone tags
- recordMap.put(tagMap, metricMap);
- }
-
- Set> entrySet = metricUpdates.entrySet();
- for (Entry entry : entrySet) {
- String metricName = entry.getKey ();
- MetricValue updateValue = entry.getValue ();
- Number updateNumber = updateValue.getNumber();
- Number currentNumber = metricMap.get(metricName);
- if (currentNumber == null || updateValue.isAbsolute()) {
- metricMap.put(metricName, updateNumber);
- }
- else {
- Number newNumber = sum(updateNumber, currentNumber);
- metricMap.put(metricName, newNumber);
- }
- }
- }
- }
-
- private synchronized RecordMap getRecordMap(String recordName) {
- return bufferedData.get(recordName);
- }
-
- /**
- * Adds two numbers, coercing the second to the type of the first.
- *
- */
- private Number sum(Number a, Number b) {
- if (a instanceof Integer) {
- return Integer.valueOf(a.intValue() + b.intValue());
- }
- else if (a instanceof Float) {
- return new Float(a.floatValue() + b.floatValue());
- }
- else if (a instanceof Short) {
- return Short.valueOf((short)(a.shortValue() + b.shortValue()));
- }
- else if (a instanceof Byte) {
- return Byte.valueOf((byte)(a.byteValue() + b.byteValue()));
- }
- else if (a instanceof Long) {
- return Long.valueOf((a.longValue() + b.longValue()));
- }
- else {
- // should never happen
- throw new MetricsException("Invalid number type");
- }
-
- }
-
- /**
- * Called by MetricsRecordImpl.remove(). Removes all matching rows in
- * the internal table of metric data. A row matches if it has the same
- * tag names and values as record, but it may also have additional
- * tags.
- */
- protected void remove(MetricsRecordImpl record) {
- String recordName = record.getRecordName();
- TagMap tagTable = record.getTagTable();
-
- RecordMap recordMap = getRecordMap(recordName);
- synchronized (recordMap) {
- Iterator it = recordMap.keySet().iterator();
- while (it.hasNext()) {
- TagMap rowTags = it.next();
- if (rowTags.containsAll(tagTable)) {
- it.remove();
- }
- }
- }
- }
-
- /**
- * Returns the timer period.
- */
- @Override
- public int getPeriod() {
- return period;
- }
-
- /**
- * Sets the timer period
- */
- protected void setPeriod(int period) {
- this.period = period;
- }
-
- /**
- * If a period is set in the attribute passed in, override
- * the default with it.
- */
- protected void parseAndSetPeriod(String attributeName) {
- String periodStr = getAttribute(attributeName);
- if (periodStr != null) {
- int period = 0;
- try {
- period = Integer.parseInt(periodStr);
- } catch (NumberFormatException nfe) {
- }
- if (period <= 0) {
- throw new MetricsException("Invalid period: " + periodStr);
- }
- setPeriod(period);
- }
- }
-}
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/CompositeContext.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/CompositeContext.java
deleted file mode 100644
index e073a2ef104..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/CompositeContext.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.metrics.spi;
-
-import java.io.IOException;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.ArrayList;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.classification.InterfaceStability;
-import org.apache.hadoop.metrics.ContextFactory;
-import org.apache.hadoop.metrics.MetricsContext;
-import org.apache.hadoop.metrics.MetricsRecord;
-import org.apache.hadoop.metrics.MetricsUtil;
-import org.apache.hadoop.metrics.Updater;
-
-/**
- * @deprecated Use org.apache.hadoop.metrics2 package instead.
- */
-@Deprecated
-@InterfaceAudience.Public
-@InterfaceStability.Evolving
-public class CompositeContext extends AbstractMetricsContext {
-
- private static final Log LOG = LogFactory.getLog(CompositeContext.class);
- private static final String ARITY_LABEL = "arity";
- private static final String SUB_FMT = "%s.sub%d";
- private final ArrayList subctxt =
- new ArrayList();
-
- @InterfaceAudience.Private
- public CompositeContext() {
- }
-
- @Override
- @InterfaceAudience.Private
- public void init(String contextName, ContextFactory factory) {
- super.init(contextName, factory);
- int nKids;
- try {
- String sKids = getAttribute(ARITY_LABEL);
- nKids = Integer.parseInt(sKids);
- } catch (Exception e) {
- LOG.error("Unable to initialize composite metric " + contextName +
- ": could not init arity", e);
- return;
- }
- for (int i = 0; i < nKids; ++i) {
- MetricsContext ctxt = MetricsUtil.getContext(
- String.format(SUB_FMT, contextName, i), contextName);
- if (null != ctxt) {
- subctxt.add(ctxt);
- }
- }
- }
-
- @InterfaceAudience.Private
- @Override
- public MetricsRecord newRecord(String recordName) {
- return (MetricsRecord) Proxy.newProxyInstance(
- MetricsRecord.class.getClassLoader(),
- new Class[] { MetricsRecord.class },
- new MetricsRecordDelegator(recordName, subctxt));
- }
-
- @InterfaceAudience.Private
- @Override
- protected void emitRecord(String contextName, String recordName,
- OutputRecord outRec) throws IOException {
- for (MetricsContext ctxt : subctxt) {
- try {
- ((AbstractMetricsContext)ctxt).emitRecord(
- contextName, recordName, outRec);
- if (contextName == null || recordName == null || outRec == null) {
- throw new IOException(contextName + ":" + recordName + ":" + outRec);
- }
- } catch (IOException e) {
- LOG.warn("emitRecord failed: " + ctxt.getContextName(), e);
- }
- }
- }
-
- @InterfaceAudience.Private
- @Override
- protected void flush() throws IOException {
- for (MetricsContext ctxt : subctxt) {
- try {
- ((AbstractMetricsContext)ctxt).flush();
- } catch (IOException e) {
- LOG.warn("flush failed: " + ctxt.getContextName(), e);
- }
- }
- }
-
- @InterfaceAudience.Private
- @Override
- public void startMonitoring() throws IOException {
- for (MetricsContext ctxt : subctxt) {
- try {
- ctxt.startMonitoring();
- } catch (IOException e) {
- LOG.warn("startMonitoring failed: " + ctxt.getContextName(), e);
- }
- }
- }
-
- @InterfaceAudience.Private
- @Override
- public void stopMonitoring() {
- for (MetricsContext ctxt : subctxt) {
- ctxt.stopMonitoring();
- }
- }
-
- /**
- * Return true if all subcontexts are monitoring.
- */
- @InterfaceAudience.Private
- @Override
- public boolean isMonitoring() {
- boolean ret = true;
- for (MetricsContext ctxt : subctxt) {
- ret &= ctxt.isMonitoring();
- }
- return ret;
- }
-
- @InterfaceAudience.Private
- @Override
- public void close() {
- for (MetricsContext ctxt : subctxt) {
- ctxt.close();
- }
- }
-
- @InterfaceAudience.Private
- @Override
- public void registerUpdater(Updater updater) {
- for (MetricsContext ctxt : subctxt) {
- ctxt.registerUpdater(updater);
- }
- }
-
- @InterfaceAudience.Private
- @Override
- public void unregisterUpdater(Updater updater) {
- for (MetricsContext ctxt : subctxt) {
- ctxt.unregisterUpdater(updater);
- }
- }
-
- private static class MetricsRecordDelegator implements InvocationHandler {
- private static final Method m_getRecordName = initMethod();
- private static Method initMethod() {
- try {
- return MetricsRecord.class.getMethod("getRecordName", new Class[0]);
- } catch (Exception e) {
- throw new RuntimeException("Internal error", e);
- }
- }
-
- private final String recordName;
- private final ArrayList subrecs;
-
- MetricsRecordDelegator(String recordName, ArrayList ctxts) {
- this.recordName = recordName;
- this.subrecs = new ArrayList(ctxts.size());
- for (MetricsContext ctxt : ctxts) {
- subrecs.add(ctxt.createRecord(recordName));
- }
- }
-
- @Override
- public Object invoke(Object p, Method m, Object[] args) throws Throwable {
- if (m_getRecordName.equals(m)) {
- return recordName;
- }
- assert Void.TYPE.equals(m.getReturnType());
- for (MetricsRecord rec : subrecs) {
- m.invoke(rec, args);
- }
- return null;
- }
- }
-
-}
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/MetricValue.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/MetricValue.java
deleted file mode 100644
index 865d36c67f7..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/MetricValue.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * MetricValue.java
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.metrics.spi;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.classification.InterfaceStability;
-
-/**
- * A Number that is either an absolute or an incremental amount.
- */
-@Deprecated
-@InterfaceAudience.Public
-@InterfaceStability.Evolving
-public class MetricValue {
-
- public static final boolean ABSOLUTE = false;
- public static final boolean INCREMENT = true;
-
- private boolean isIncrement;
- private Number number;
-
- /** Creates a new instance of MetricValue */
- public MetricValue(Number number, boolean isIncrement) {
- this.number = number;
- this.isIncrement = isIncrement;
- }
-
- public boolean isIncrement() {
- return isIncrement;
- }
-
- public boolean isAbsolute() {
- return !isIncrement;
- }
-
- public Number getNumber() {
- return number;
- }
-
-}
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/MetricsRecordImpl.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/MetricsRecordImpl.java
deleted file mode 100644
index e3d11af369c..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/MetricsRecordImpl.java
+++ /dev/null
@@ -1,304 +0,0 @@
-/*
- * MetricsRecordImpl.java
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.metrics.spi;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.classification.InterfaceStability;
-import org.apache.hadoop.metrics.MetricsException;
-import org.apache.hadoop.metrics.MetricsRecord;
-import org.apache.hadoop.metrics.spi.AbstractMetricsContext.TagMap;
-
-/**
- * An implementation of MetricsRecord. Keeps a back-pointer to the context
- * from which it was created, and delegates back to it on update
- * and remove()
.
- *
- * @deprecated Use {@link org.apache.hadoop.metrics2.impl.MetricsRecordImpl}
- * instead.
- */
-@Deprecated
-@InterfaceAudience.Public
-@InterfaceStability.Evolving
-public class MetricsRecordImpl implements MetricsRecord {
-
- private TagMap tagTable = new TagMap();
- private Map metricTable = new LinkedHashMap();
-
- private String recordName;
- private AbstractMetricsContext context;
-
-
- /** Creates a new instance of FileRecord */
- protected MetricsRecordImpl(String recordName, AbstractMetricsContext context)
- {
- this.recordName = recordName;
- this.context = context;
- }
-
- /**
- * Returns the record name.
- *
- * @return the record name
- */
- @Override
- public String getRecordName() {
- return recordName;
- }
-
- /**
- * Sets the named tag to the specified value.
- *
- * @param tagName name of the tag
- * @param tagValue new value of the tag
- * @throws MetricsException if the tagName conflicts with the configuration
- */
- @Override
- public void setTag(String tagName, String tagValue) {
- if (tagValue == null) {
- tagValue = "";
- }
- tagTable.put(tagName, tagValue);
- }
-
- /**
- * Sets the named tag to the specified value.
- *
- * @param tagName name of the tag
- * @param tagValue new value of the tag
- * @throws MetricsException if the tagName conflicts with the configuration
- */
- @Override
- public void setTag(String tagName, int tagValue) {
- tagTable.put(tagName, Integer.valueOf(tagValue));
- }
-
- /**
- * Sets the named tag to the specified value.
- *
- * @param tagName name of the tag
- * @param tagValue new value of the tag
- * @throws MetricsException if the tagName conflicts with the configuration
- */
- @Override
- public void setTag(String tagName, long tagValue) {
- tagTable.put(tagName, Long.valueOf(tagValue));
- }
-
- /**
- * Sets the named tag to the specified value.
- *
- * @param tagName name of the tag
- * @param tagValue new value of the tag
- * @throws MetricsException if the tagName conflicts with the configuration
- */
- @Override
- public void setTag(String tagName, short tagValue) {
- tagTable.put(tagName, Short.valueOf(tagValue));
- }
-
- /**
- * Sets the named tag to the specified value.
- *
- * @param tagName name of the tag
- * @param tagValue new value of the tag
- * @throws MetricsException if the tagName conflicts with the configuration
- */
- @Override
- public void setTag(String tagName, byte tagValue) {
- tagTable.put(tagName, Byte.valueOf(tagValue));
- }
-
- /**
- * Removes any tag of the specified name.
- */
- @Override
- public void removeTag(String tagName) {
- tagTable.remove(tagName);
- }
-
- /**
- * Sets the named metric to the specified value.
- *
- * @param metricName name of the metric
- * @param metricValue new value of the metric
- * @throws MetricsException if the metricName or the type of the metricValue
- * conflicts with the configuration
- */
- @Override
- public void setMetric(String metricName, int metricValue) {
- setAbsolute(metricName, Integer.valueOf(metricValue));
- }
-
- /**
- * Sets the named metric to the specified value.
- *
- * @param metricName name of the metric
- * @param metricValue new value of the metric
- * @throws MetricsException if the metricName or the type of the metricValue
- * conflicts with the configuration
- */
- @Override
- public void setMetric(String metricName, long metricValue) {
- setAbsolute(metricName, Long.valueOf(metricValue));
- }
-
- /**
- * Sets the named metric to the specified value.
- *
- * @param metricName name of the metric
- * @param metricValue new value of the metric
- * @throws MetricsException if the metricName or the type of the metricValue
- * conflicts with the configuration
- */
- @Override
- public void setMetric(String metricName, short metricValue) {
- setAbsolute(metricName, Short.valueOf(metricValue));
- }
-
- /**
- * Sets the named metric to the specified value.
- *
- * @param metricName name of the metric
- * @param metricValue new value of the metric
- * @throws MetricsException if the metricName or the type of the metricValue
- * conflicts with the configuration
- */
- @Override
- public void setMetric(String metricName, byte metricValue) {
- setAbsolute(metricName, Byte.valueOf(metricValue));
- }
-
- /**
- * Sets the named metric to the specified value.
- *
- * @param metricName name of the metric
- * @param metricValue new value of the metric
- * @throws MetricsException if the metricName or the type of the metricValue
- * conflicts with the configuration
- */
- @Override
- public void setMetric(String metricName, float metricValue) {
- setAbsolute(metricName, new Float(metricValue));
- }
-
- /**
- * Increments the named metric by the specified value.
- *
- * @param metricName name of the metric
- * @param metricValue incremental value
- * @throws MetricsException if the metricName or the type of the metricValue
- * conflicts with the configuration
- */
- @Override
- public void incrMetric(String metricName, int metricValue) {
- setIncrement(metricName, Integer.valueOf(metricValue));
- }
-
- /**
- * Increments the named metric by the specified value.
- *
- * @param metricName name of the metric
- * @param metricValue incremental value
- * @throws MetricsException if the metricName or the type of the metricValue
- * conflicts with the configuration
- */
- @Override
- public void incrMetric(String metricName, long metricValue) {
- setIncrement(metricName, Long.valueOf(metricValue));
- }
-
- /**
- * Increments the named metric by the specified value.
- *
- * @param metricName name of the metric
- * @param metricValue incremental value
- * @throws MetricsException if the metricName or the type of the metricValue
- * conflicts with the configuration
- */
- @Override
- public void incrMetric(String metricName, short metricValue) {
- setIncrement(metricName, Short.valueOf(metricValue));
- }
-
- /**
- * Increments the named metric by the specified value.
- *
- * @param metricName name of the metric
- * @param metricValue incremental value
- * @throws MetricsException if the metricName or the type of the metricValue
- * conflicts with the configuration
- */
- @Override
- public void incrMetric(String metricName, byte metricValue) {
- setIncrement(metricName, Byte.valueOf(metricValue));
- }
-
- /**
- * Increments the named metric by the specified value.
- *
- * @param metricName name of the metric
- * @param metricValue incremental value
- * @throws MetricsException if the metricName or the type of the metricValue
- * conflicts with the configuration
- */
- @Override
- public void incrMetric(String metricName, float metricValue) {
- setIncrement(metricName, new Float(metricValue));
- }
-
- private void setAbsolute(String metricName, Number metricValue) {
- metricTable.put(metricName, new MetricValue(metricValue, MetricValue.ABSOLUTE));
- }
-
- private void setIncrement(String metricName, Number metricValue) {
- metricTable.put(metricName, new MetricValue(metricValue, MetricValue.INCREMENT));
- }
-
- /**
- * Updates the table of buffered data which is to be sent periodically.
- * If the tag values match an existing row, that row is updated;
- * otherwise, a new row is added.
- */
- @Override
- public void update() {
- context.update(this);
- }
-
- /**
- * Removes the row, if it exists, in the buffered data table having tags
- * that equal the tags that have been set on this record.
- */
- @Override
- public void remove() {
- context.remove(this);
- }
-
- TagMap getTagTable() {
- return tagTable;
- }
-
- Map getMetricTable() {
- return metricTable;
- }
-}
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/NoEmitMetricsContext.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/NoEmitMetricsContext.java
deleted file mode 100644
index f3ca882ac35..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/NoEmitMetricsContext.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.metrics.spi;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.classification.InterfaceStability;
-import org.apache.hadoop.metrics.ContextFactory;
-import org.apache.hadoop.metrics.MetricsServlet;
-
-/**
- * A MetricsContext that does not emit data, but, unlike NullContextWithUpdate,
- * does save it for retrieval with getAllRecords().
- *
- * This is useful if you want to support {@link MetricsServlet}, but
- * not emit metrics in any other way.
- *
- * @deprecated Use org.apache.hadoop.metrics2 package instead.
- */
-@Deprecated
-@InterfaceAudience.Public
-@InterfaceStability.Evolving
-public class NoEmitMetricsContext extends AbstractMetricsContext {
-
- private static final String PERIOD_PROPERTY = "period";
-
- /** Creates a new instance of NullContextWithUpdateThread */
- @InterfaceAudience.Private
- public NoEmitMetricsContext() {
- }
-
- @Override
- @InterfaceAudience.Private
- public void init(String contextName, ContextFactory factory) {
- super.init(contextName, factory);
- parseAndSetPeriod(PERIOD_PROPERTY);
- }
-
- /**
- * Do-nothing version of emitRecord
- */
- @Override
- @InterfaceAudience.Private
- protected void emitRecord(String contextName, String recordName,
- OutputRecord outRec) {
- }
-}
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/NullContext.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/NullContext.java
deleted file mode 100644
index 38c0cd2ada4..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/NullContext.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * NullContext.java
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.metrics.spi;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.classification.InterfaceStability;
-
-/**
- * Null metrics context: a metrics context which does nothing. Used as the
- * default context, so that no performance data is emitted if no configuration
- * data is found.
- *
- * @deprecated Use org.apache.hadoop.metrics2 package instead.
- */
-@Deprecated
-@InterfaceAudience.Public
-@InterfaceStability.Evolving
-public class NullContext extends AbstractMetricsContext {
-
- /** Creates a new instance of NullContext */
- @InterfaceAudience.Private
- public NullContext() {
- }
-
- /**
- * Do-nothing version of startMonitoring
- */
- @Override
- @InterfaceAudience.Private
- public void startMonitoring() {
- }
-
- /**
- * Do-nothing version of emitRecord
- */
- @Override
- @InterfaceAudience.Private
- protected void emitRecord(String contextName, String recordName,
- OutputRecord outRec)
- {}
-
- /**
- * Do-nothing version of update
- */
- @Override
- @InterfaceAudience.Private
- protected void update(MetricsRecordImpl record) {
- }
-
- /**
- * Do-nothing version of remove
- */
- @Override
- @InterfaceAudience.Private
- protected void remove(MetricsRecordImpl record) {
- }
-}
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/NullContextWithUpdateThread.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/NullContextWithUpdateThread.java
deleted file mode 100644
index 518a8861ec6..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/NullContextWithUpdateThread.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.metrics.spi;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.classification.InterfaceStability;
-import org.apache.hadoop.metrics.ContextFactory;
-
-/**
- * A null context which has a thread calling
- * periodically when monitoring is started. This keeps the data sampled
- * correctly.
- * In all other respects, this is like the NULL context: No data is emitted.
- * This is suitable for Monitoring systems like JMX which reads the metrics
- * when someone reads the data from JMX.
- *
- * The default impl of start and stop monitoring:
- * is the AbstractMetricsContext is good enough.
- *
- * @deprecated Use org.apache.hadoop.metrics2 package instead.
- */
-@Deprecated
-@InterfaceAudience.Public
-@InterfaceStability.Evolving
-public class NullContextWithUpdateThread extends AbstractMetricsContext {
-
- private static final String PERIOD_PROPERTY = "period";
-
- /** Creates a new instance of NullContextWithUpdateThread */
- @InterfaceAudience.Private
- public NullContextWithUpdateThread() {
- }
-
- @Override
- @InterfaceAudience.Private
- public void init(String contextName, ContextFactory factory) {
- super.init(contextName, factory);
- parseAndSetPeriod(PERIOD_PROPERTY);
- }
-
-
- /**
- * Do-nothing version of emitRecord
- */
- @Override
- @InterfaceAudience.Private
- protected void emitRecord(String contextName, String recordName,
- OutputRecord outRec)
- {}
-
- /**
- * Do-nothing version of update
- */
- @Override
- @InterfaceAudience.Private
- protected void update(MetricsRecordImpl record) {
- }
-
- /**
- * Do-nothing version of remove
- */
- @Override
- @InterfaceAudience.Private
- protected void remove(MetricsRecordImpl record) {
- }
-}
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/OutputRecord.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/OutputRecord.java
deleted file mode 100644
index 4f0865e136d..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/OutputRecord.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * OutputRecord.java
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.metrics.spi;
-
-import java.util.Collections;
-import java.util.Set;
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.classification.InterfaceStability;
-import org.apache.hadoop.metrics.spi.AbstractMetricsContext.MetricMap;
-import org.apache.hadoop.metrics.spi.AbstractMetricsContext.TagMap;
-
-/**
- * Represents a record of metric data to be sent to a metrics system.
- *
- * @deprecated Use org.apache.hadoop.metrics2 package instead.
- */
-@Deprecated
-@InterfaceAudience.Public
-@InterfaceStability.Evolving
-public class OutputRecord {
-
- private TagMap tagMap;
- private MetricMap metricMap;
-
- /** Creates a new instance of OutputRecord */
- OutputRecord(TagMap tagMap, MetricMap metricMap) {
- this.tagMap = tagMap;
- this.metricMap = metricMap;
- }
-
- /**
- * Returns the set of tag names
- */
- public Set getTagNames() {
- return Collections.unmodifiableSet(tagMap.keySet());
- }
-
- /**
- * Returns a tag object which is can be a String, Integer, Short or Byte.
- *
- * @return the tag value, or null if there is no such tag
- */
- public Object getTag(String name) {
- return tagMap.get(name);
- }
-
- /**
- * Returns the set of metric names.
- */
- public Set getMetricNames() {
- return Collections.unmodifiableSet(metricMap.keySet());
- }
-
- /**
- * Returns the metric object which can be a Float, Integer, Short or Byte.
- */
- public Number getMetric(String name) {
- return metricMap.get(name);
- }
-
-
- /**
- * Returns a copy of this record's tags.
- */
- public TagMap getTagsCopy() {
- return new TagMap(tagMap);
- }
-
- /**
- * Returns a copy of this record's metrics.
- */
- public MetricMap getMetricsCopy() {
- return new MetricMap(metricMap);
- }
-}
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/Util.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/Util.java
deleted file mode 100644
index 6fb7c9ee56c..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/Util.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Util.java
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package org.apache.hadoop.metrics.spi;
-
-import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.classification.InterfaceStability;
-import org.apache.hadoop.net.NetUtils;
-
-/**
- * Static utility methods
- *
- * @deprecated Use org.apache.hadoop.metrics2 package instead.
- */
-@Deprecated
-@InterfaceAudience.Public
-@InterfaceStability.Evolving
-public class Util {
-
- /**
- * This class is not intended to be instantiated
- */
- private Util() {}
-
- /**
- * Parses a space and/or comma separated sequence of server specifications
- * of the form hostname or hostname:port. If
- * the specs string is null, defaults to localhost:defaultPort.
- *
- * @return a list of InetSocketAddress objects.
- */
- public static List parse(String specs, int defaultPort) {
- List result = new ArrayList(1);
- if (specs == null) {
- result.add(new InetSocketAddress("localhost", defaultPort));
- }
- else {
- String[] specStrings = specs.split("[ ,]+");
- for (String specString : specStrings) {
- result.add(NetUtils.createSocketAddr(specString, defaultPort));
- }
- }
- return result;
- }
-
-}
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/package.html b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/package.html
deleted file mode 100644
index b72552f761f..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/spi/package.html
+++ /dev/null
@@ -1,36 +0,0 @@
-
-
-
-
-
-
- org.apache.hadoop.metrics.spi
-
-
-The Service Provider Interface for the Metrics API. This package provides
-an interface allowing a variety of metrics reporting implementations to be
-plugged in to the Metrics API. Examples of such implementations can be found
-in the packages org.apache.hadoop.metrics.file
and
-org.apache.hadoop.metrics.ganglia
.
-
-Plugging in an implementation involves writing a concrete subclass of
-AbstractMetricsContext
. The subclass should get its
- configuration information using the getAttribute(attributeName)
- method.
-
-
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MBeanUtil.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MBeanUtil.java
deleted file mode 100644
index 7746b4fdf62..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MBeanUtil.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.metrics.util;
-
-import java.lang.management.ManagementFactory;
-
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import javax.management.InstanceAlreadyExistsException;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-
-
-/**
- * This util class provides a method to register an MBean using
- * our standard naming convention as described in the doc
- * for {link {@link #registerMBean(String, String, Object)}
- *
- * @deprecated Use {@link org.apache.hadoop.metrics2.util.MBeans} instead.
- */
-@Deprecated
-@InterfaceAudience.LimitedPrivate({"HDFS", "MapReduce"})
-public class MBeanUtil {
-
- /**
- * Register the MBean using our standard MBeanName format
- * "hadoop:service=,name="
- * Where the and are the supplied parameters
- *
- * @param serviceName
- * @param nameName
- * @param theMbean - the MBean to register
- * @return the named used to register the MBean
- */
- static public ObjectName registerMBean(final String serviceName,
- final String nameName,
- final Object theMbean) {
- final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
- ObjectName name = getMBeanName(serviceName, nameName);
- try {
- mbs.registerMBean(theMbean, name);
- return name;
- } catch (InstanceAlreadyExistsException ie) {
- // Ignore if instance already exists
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- static public void unregisterMBean(ObjectName mbeanName) {
- final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
- if (mbeanName == null)
- return;
- try {
- mbs.unregisterMBean(mbeanName);
- } catch (InstanceNotFoundException e ) {
- // ignore
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- static private ObjectName getMBeanName(final String serviceName,
- final String nameName) {
- ObjectName name = null;
- try {
- name = new ObjectName("hadoop:" +
- "service=" + serviceName + ",name=" + nameName);
- } catch (MalformedObjectNameException e) {
- e.printStackTrace();
- }
- return name;
- }
-}
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsBase.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsBase.java
deleted file mode 100644
index 96d7b6147cd..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsBase.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.metrics.util;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.metrics.MetricsRecord;
-
-/**
- *
- * This is base class for all metrics
- *
- * @deprecated Use org.apache.hadoop.metrics2 package instead.
- */
-@Deprecated
-@InterfaceAudience.Private
-public abstract class MetricsBase {
- public static final String NO_DESCRIPTION = "NoDescription";
- final private String name;
- final private String description;
-
- protected MetricsBase(final String nam) {
- name = nam;
- description = NO_DESCRIPTION;
- }
-
- protected MetricsBase(final String nam, final String desc) {
- name = nam;
- description = desc;
- }
-
- public abstract void pushMetric(final MetricsRecord mr);
-
- public String getName() { return name; }
- public String getDescription() { return description; };
-
-}
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsDynamicMBeanBase.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsDynamicMBeanBase.java
deleted file mode 100644
index 24932d6727b..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsDynamicMBeanBase.java
+++ /dev/null
@@ -1,229 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.metrics.util;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.management.Attribute;
-import javax.management.AttributeList;
-import javax.management.AttributeNotFoundException;
-import javax.management.DynamicMBean;
-import javax.management.InvalidAttributeValueException;
-import javax.management.MBeanAttributeInfo;
-import javax.management.MBeanException;
-import javax.management.MBeanInfo;
-import javax.management.MBeanOperationInfo;
-import javax.management.ReflectionException;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.metrics.MetricsUtil;
-
-
-
-/**
- * This abstract base class facilitates creating dynamic mbeans automatically from
- * metrics.
- * The metrics constructors registers metrics in a registry.
- * Different categories of metrics should be in differnt classes with their own
- * registry (as in NameNodeMetrics and DataNodeMetrics).
- * Then the MBean can be created passing the registry to the constructor.
- * The MBean should be then registered using a mbean name (example):
- * MetricsHolder myMetrics = new MetricsHolder(); // has metrics and registry
- * MetricsTestMBean theMBean = new MetricsTestMBean(myMetrics.mregistry);
- * ObjectName mbeanName = MBeanUtil.registerMBean("ServiceFoo",
- * "TestStatistics", theMBean);
- *
- * @deprecated Use org.apache.hadoop.metrics2 package instead.
- */
-@Deprecated
-@InterfaceAudience.LimitedPrivate({"HDFS", "MapReduce"})
-public abstract class MetricsDynamicMBeanBase implements DynamicMBean {
- private final static String AVG_TIME = "AvgTime";
- private final static String MIN_TIME = "MinTime";
- private final static String MAX_TIME = "MaxTime";
- private final static String NUM_OPS = "NumOps";
- private final static String RESET_ALL_MIN_MAX_OP = "resetAllMinMax";
- private MetricsRegistry metricsRegistry;
- private MBeanInfo mbeanInfo;
- private Map metricsRateAttributeMod;
- private int numEntriesInRegistry = 0;
- private String mbeanDescription;
-
- protected MetricsDynamicMBeanBase(final MetricsRegistry mr, final String aMBeanDescription) {
- metricsRegistry = mr;
- mbeanDescription = aMBeanDescription;
- metricsRateAttributeMod = new ConcurrentHashMap();
- createMBeanInfo();
- }
-
- private void updateMbeanInfoIfMetricsListChanged() {
- if (numEntriesInRegistry != metricsRegistry.size())
- createMBeanInfo();
- }
-
- private void createMBeanInfo() {
- boolean needsMinMaxResetOperation = false;
- List attributesInfo = new ArrayList();
- MBeanOperationInfo[] operationsInfo = null;
- numEntriesInRegistry = metricsRegistry.size();
-
- for (MetricsBase o : metricsRegistry.getMetricsList()) {
-
- if (MetricsTimeVaryingRate.class.isInstance(o)) {
- // For each of the metrics there are 3 different attributes
- attributesInfo.add(new MBeanAttributeInfo(o.getName() + NUM_OPS, "java.lang.Integer",
- o.getDescription(), true, false, false));
- attributesInfo.add(new MBeanAttributeInfo(o.getName() + AVG_TIME, "java.lang.Long",
- o.getDescription(), true, false, false));
- attributesInfo.add(new MBeanAttributeInfo(o.getName() + MIN_TIME, "java.lang.Long",
- o.getDescription(), true, false, false));
- attributesInfo.add(new MBeanAttributeInfo(o.getName() + MAX_TIME, "java.lang.Long",
- o.getDescription(), true, false, false));
- needsMinMaxResetOperation = true; // the min and max can be reset.
-
- // Note the special attributes (AVG_TIME, MIN_TIME, ..) are derived from metrics
- // Rather than check for the suffix we store them in a map.
- metricsRateAttributeMod.put(o.getName() + NUM_OPS, o);
- metricsRateAttributeMod.put(o.getName() + AVG_TIME, o);
- metricsRateAttributeMod.put(o.getName() + MIN_TIME, o);
- metricsRateAttributeMod.put(o.getName() + MAX_TIME, o);
-
- } else if ( MetricsIntValue.class.isInstance(o) || MetricsTimeVaryingInt.class.isInstance(o) ) {
- attributesInfo.add(new MBeanAttributeInfo(o.getName(), "java.lang.Integer",
- o.getDescription(), true, false, false));
- } else if ( MetricsLongValue.class.isInstance(o) || MetricsTimeVaryingLong.class.isInstance(o) ) {
- attributesInfo.add(new MBeanAttributeInfo(o.getName(), "java.lang.Long",
- o.getDescription(), true, false, false));
- } else {
- MetricsUtil.LOG.error("unknown metrics type: " + o.getClass().getName());
- }
-
- if (needsMinMaxResetOperation) {
- operationsInfo = new MBeanOperationInfo[] {
- new MBeanOperationInfo(RESET_ALL_MIN_MAX_OP, "Reset (zero) All Min Max",
- null, "void", MBeanOperationInfo.ACTION) };
- }
- }
- MBeanAttributeInfo[] attrArray = new MBeanAttributeInfo[attributesInfo.size()];
- mbeanInfo = new MBeanInfo(this.getClass().getName(), mbeanDescription,
- attributesInfo.toArray(attrArray), null, operationsInfo, null);
- }
-
- @Override
- public Object getAttribute(String attributeName) throws AttributeNotFoundException,
- MBeanException, ReflectionException {
- if (attributeName == null || attributeName.isEmpty())
- throw new IllegalArgumentException();
-
- updateMbeanInfoIfMetricsListChanged();
-
- Object o = metricsRateAttributeMod.get(attributeName);
- if (o == null) {
- o = metricsRegistry.get(attributeName);
- }
- if (o == null)
- throw new AttributeNotFoundException();
-
- if (o instanceof MetricsIntValue)
- return ((MetricsIntValue) o).get();
- else if (o instanceof MetricsLongValue)
- return ((MetricsLongValue) o).get();
- else if (o instanceof MetricsTimeVaryingInt)
- return ((MetricsTimeVaryingInt) o).getPreviousIntervalValue();
- else if (o instanceof MetricsTimeVaryingLong)
- return ((MetricsTimeVaryingLong) o).getPreviousIntervalValue();
- else if (o instanceof MetricsTimeVaryingRate) {
- MetricsTimeVaryingRate or = (MetricsTimeVaryingRate) o;
- if (attributeName.endsWith(NUM_OPS))
- return or.getPreviousIntervalNumOps();
- else if (attributeName.endsWith(AVG_TIME))
- return or.getPreviousIntervalAverageTime();
- else if (attributeName.endsWith(MIN_TIME))
- return or.getMinTime();
- else if (attributeName.endsWith(MAX_TIME))
- return or.getMaxTime();
- else {
- MetricsUtil.LOG.error("Unexpected attribute suffix");
- throw new AttributeNotFoundException();
- }
- } else {
- MetricsUtil.LOG.error("unknown metrics type: " + o.getClass().getName());
- throw new AttributeNotFoundException();
- }
- }
-
- @Override
- public AttributeList getAttributes(String[] attributeNames) {
- if (attributeNames == null || attributeNames.length == 0)
- throw new IllegalArgumentException();
-
- updateMbeanInfoIfMetricsListChanged();
-
- AttributeList result = new AttributeList(attributeNames.length);
- for (String iAttributeName : attributeNames) {
- try {
- Object value = getAttribute(iAttributeName);
- result.add(new Attribute(iAttributeName, value));
- } catch (Exception e) {
- continue;
- }
- }
- return result;
- }
-
- @Override
- public MBeanInfo getMBeanInfo() {
- return mbeanInfo;
- }
-
- @Override
- public Object invoke(String actionName, Object[] parms, String[] signature)
- throws MBeanException, ReflectionException {
-
- if (actionName == null || actionName.isEmpty())
- throw new IllegalArgumentException();
-
-
- // Right now we support only one fixed operation (if it applies)
- if (!(actionName.equals(RESET_ALL_MIN_MAX_OP)) ||
- mbeanInfo.getOperations().length != 1) {
- throw new ReflectionException(new NoSuchMethodException(actionName));
- }
- for (MetricsBase m : metricsRegistry.getMetricsList()) {
- if ( MetricsTimeVaryingRate.class.isInstance(m) ) {
- MetricsTimeVaryingRate.class.cast(m).resetMinMax();
- }
- }
- return null;
- }
-
- @Override
- public void setAttribute(Attribute attribute)
- throws AttributeNotFoundException, InvalidAttributeValueException,
- MBeanException, ReflectionException {
- throw new ReflectionException(new NoSuchMethodException("set" + attribute));
- }
-
- @Override
- public AttributeList setAttributes(AttributeList attributes) {
- return null;
- }
-}
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsIntValue.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsIntValue.java
deleted file mode 100644
index d0a258bcd3a..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsIntValue.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.metrics.util;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.metrics.MetricsRecord;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * The MetricsIntValue class is for a metric that is not time varied
- * but changes only when it is set.
- * Each time its value is set, it is published only *once* at the next update
- * call.
- *
- * @deprecated Use org.apache.hadoop.metrics2 package instead.
- */
-@Deprecated
-@InterfaceAudience.LimitedPrivate({"HDFS", "MapReduce"})
-public class MetricsIntValue extends MetricsBase {
-
- private static final Log LOG =
- LogFactory.getLog("org.apache.hadoop.metrics.util");
-
- private int value;
- private boolean changed;
-
-
- /**
- * Constructor - create a new metric
- * @param nam the name of the metrics to be used to publish the metric
- * @param registry - where the metrics object will be registered
- */
- public MetricsIntValue(final String nam, final MetricsRegistry registry, final String description) {
- super(nam, description);
- value = 0;
- changed = false;
- registry.add(nam, this);
- }
-
- /**
- * Constructor - create a new metric
- * @param nam the name of the metrics to be used to publish the metric
- * @param registry - where the metrics object will be registered
- * A description of {@link #NO_DESCRIPTION} is used
- */
- public MetricsIntValue(final String nam, MetricsRegistry registry) {
- this(nam, registry, NO_DESCRIPTION);
- }
-
-
-
- /**
- * Set the value
- * @param newValue
- */
- public synchronized void set(final int newValue) {
- value = newValue;
- changed = true;
- }
-
- /**
- * Get value
- * @return the value last set
- */
- public synchronized int get() {
- return value;
- }
-
-
- /**
- * Push the metric to the mr.
- * The metric is pushed only if it was updated since last push
- *
- * Note this does NOT push to JMX
- * (JMX gets the info via {@link #get()}
- *
- * @param mr
- */
- @Override
- public synchronized void pushMetric(final MetricsRecord mr) {
- if (changed) {
- try {
- mr.setMetric(getName(), value);
- } catch (Exception e) {
- LOG.info("pushMetric failed for " + getName() + "\n", e);
- }
- }
- changed = false;
- }
-}
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsLongValue.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsLongValue.java
deleted file mode 100644
index b00a739ef09..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsLongValue.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.metrics.util;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.metrics.MetricsRecord;
-
-
-/**
- * The MetricsLongValue class is for a metric that is not time varied
- * but changes only when it is set.
- * Each time its value is set, it is published only *once* at the next update
- * call.
- *
- * @deprecated Use org.apache.hadoop.metrics2 package instead.
- */
-@Deprecated
-@InterfaceAudience.LimitedPrivate({"HDFS", "MapReduce"})
-public class MetricsLongValue extends MetricsBase{
- private long value;
- private boolean changed;
-
- /**
- * Constructor - create a new metric
- * @param nam the name of the metrics to be used to publish the metric
- * @param registry - where the metrics object will be registered
- */
- public MetricsLongValue(final String nam, final MetricsRegistry registry, final String description) {
- super(nam, description);
- value = 0;
- changed = false;
- registry.add(nam, this);
- }
-
- /**
- * Constructor - create a new metric
- * @param nam the name of the metrics to be used to publish the metric
- * @param registry - where the metrics object will be registered
- * A description of {@link #NO_DESCRIPTION} is used
- */
- public MetricsLongValue(final String nam, MetricsRegistry registry) {
- this(nam, registry, NO_DESCRIPTION);
- }
-
- /**
- * Set the value
- * @param newValue
- */
- public synchronized void set(final long newValue) {
- value = newValue;
- changed = true;
- }
-
- /**
- * Get value
- * @return the value last set
- */
- public synchronized long get() {
- return value;
- }
-
-
- /**
- * Push the metric to the mr.
- * The metric is pushed only if it was updated since last push
- *
- * Note this does NOT push to JMX
- * (JMX gets the info via {@link #get()}
- *
- * @param mr
- */
- @Override
- public synchronized void pushMetric(final MetricsRecord mr) {
- if (changed)
- mr.setMetric(getName(), value);
- changed = false;
- }
-}
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsRegistry.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsRegistry.java
deleted file mode 100644
index 2baa3d32fd0..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsRegistry.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.metrics.util;
-
-import java.util.Collection;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-
-/**
- *
- * This is the registry for metrics.
- * Related set of metrics should be declared in a holding class and registered
- * in a registry for those metrics which is also stored in the the holding class.
- *
- * @deprecated Use org.apache.hadoop.metrics2 package instead.
- */
-@Deprecated
-@InterfaceAudience.LimitedPrivate({"HDFS", "MapReduce"})
-public class MetricsRegistry {
- private ConcurrentHashMap metricsList =
- new ConcurrentHashMap();
-
- public MetricsRegistry() {
- }
-
- /**
- *
- * @return number of metrics in the registry
- */
- public int size() {
- return metricsList.size();
- }
-
- /**
- * Add a new metrics to the registry
- * @param metricsName - the name
- * @param theMetricsObj - the metrics
- * @throws IllegalArgumentException if a name is already registered
- */
- public void add(final String metricsName, final MetricsBase theMetricsObj) {
- if (metricsList.putIfAbsent(metricsName, theMetricsObj) != null) {
- throw new IllegalArgumentException("Duplicate metricsName:" +
- metricsName);
- }
- }
-
-
- /**
- *
- * @param metricsName
- * @return the metrics if there is one registered by the supplied name.
- * Returns null if none is registered
- */
- public MetricsBase get(final String metricsName) {
- return metricsList.get(metricsName);
- }
-
-
- /**
- *
- * @return the list of metrics names
- */
- public Collection getKeyList() {
- return metricsList.keySet();
- }
-
- /**
- *
- * @return the list of metrics
- */
- public Collection getMetricsList() {
- return metricsList.values();
- }
-}
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsTimeVaryingInt.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsTimeVaryingInt.java
deleted file mode 100644
index 17379ad56b2..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsTimeVaryingInt.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.metrics.util;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.metrics.MetricsRecord;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * The MetricsTimeVaryingInt class is for a metric that naturally
- * varies over time (e.g. number of files created). The metrics is accumulated
- * over an interval (set in the metrics config file); the metrics is
- * published at the end of each interval and then
- * reset to zero. Hence the counter has the value in the current interval.
- *
- * Note if one wants a time associated with the metric then use
- * @see org.apache.hadoop.metrics.util.MetricsTimeVaryingRate
- * @deprecated Use org.apache.hadoop.metrics2 package instead.
- */
-@Deprecated
-@InterfaceAudience.LimitedPrivate({"HDFS", "MapReduce"})
-public class MetricsTimeVaryingInt extends MetricsBase {
-
- private static final Log LOG =
- LogFactory.getLog("org.apache.hadoop.metrics.util");
-
- private int currentValue;
- private int previousIntervalValue;
-
-
- /**
- * Constructor - create a new metric
- * @param nam the name of the metrics to be used to publish the metric
- * @param registry - where the metrics object will be registered
- * @param description - the description
- */
- public MetricsTimeVaryingInt(final String nam,
- final MetricsRegistry registry,
- final String description) {
- super(nam, description);
- currentValue = 0;
- previousIntervalValue = 0;
- registry.add(nam, this);
- }
-
- /**
- * Constructor - create a new metric
- * @param nam the name of the metrics to be used to publish the metric
- * @param registry - where the metrics object will be registered
- * A description of {@link #NO_DESCRIPTION} is used
- */
- public MetricsTimeVaryingInt(final String nam, final MetricsRegistry registry) {
- this(nam, registry, NO_DESCRIPTION);
- }
-
-
-
- /**
- * Inc metrics for incr vlaue
- * @param incr - number of operations
- */
- public synchronized void inc(final int incr) {
- currentValue += incr;
- }
-
- /**
- * Inc metrics by one
- */
- public synchronized void inc() {
- currentValue++;
- }
-
- private synchronized void intervalHeartBeat() {
- previousIntervalValue = currentValue;
- currentValue = 0;
- }
-
- /**
- * Push the delta metrics to the mr.
- * The delta is since the last push/interval.
- *
- * Note this does NOT push to JMX
- * (JMX gets the info via {@link #previousIntervalValue}
- *
- * @param mr
- */
- @Override
- public synchronized void pushMetric(final MetricsRecord mr) {
- intervalHeartBeat();
- try {
- mr.incrMetric(getName(), getPreviousIntervalValue());
- } catch (Exception e) {
- LOG.info("pushMetric failed for " + getName() + "\n" , e);
- }
- }
-
-
- /**
- * The Value at the Previous interval
- * @return prev interval value
- */
- public synchronized int getPreviousIntervalValue() {
- return previousIntervalValue;
- }
-
- /**
- * The Value at the current interval
- * @return prev interval value
- */
- public synchronized int getCurrentIntervalValue() {
- return currentValue;
- }
-}
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsTimeVaryingLong.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsTimeVaryingLong.java
deleted file mode 100644
index 95059db5ce2..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsTimeVaryingLong.java
+++ /dev/null
@@ -1,125 +0,0 @@
-package org.apache.hadoop.metrics.util;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.metrics.MetricsRecord;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * The MetricsTimeVaryingLong class is for a metric that naturally
- * varies over time (e.g. number of files created). The metrics is accumulated
- * over an interval (set in the metrics config file); the metrics is
- * published at the end of each interval and then
- * reset to zero. Hence the counter has the value in the current interval.
- *
- * Note if one wants a time associated with the metric then use
- * @see org.apache.hadoop.metrics.util.MetricsTimeVaryingRate
- * @deprecated Use org.apache.hadoop.metrics2 package instead.
- */
-@Deprecated
-@InterfaceAudience.LimitedPrivate({"HDFS", "MapReduce"})
-public class MetricsTimeVaryingLong extends MetricsBase{
-
- private static final Log LOG =
- LogFactory.getLog("org.apache.hadoop.metrics.util");
-
- private long currentValue;
- private long previousIntervalValue;
-
- /**
- * Constructor - create a new metric
- * @param nam the name of the metrics to be used to publish the metric
- * @param registry - where the metrics object will be registered
- */
- public MetricsTimeVaryingLong(final String nam, MetricsRegistry registry, final String description) {
- super(nam, description);
- currentValue = 0;
- previousIntervalValue = 0;
- registry.add(nam, this);
- }
-
-
- /**
- * Constructor - create a new metric
- * @param nam the name of the metrics to be used to publish the metric
- * @param registry - where the metrics object will be registered
- * A description of {@link #NO_DESCRIPTION} is used
- */
- public MetricsTimeVaryingLong(final String nam, MetricsRegistry registry) {
- this(nam, registry, NO_DESCRIPTION);
- }
-
- /**
- * Inc metrics for incr vlaue
- * @param incr - number of operations
- */
- public synchronized void inc(final long incr) {
- currentValue += incr;
- }
-
- /**
- * Inc metrics by one
- */
- public synchronized void inc() {
- currentValue++;
- }
-
- private synchronized void intervalHeartBeat() {
- previousIntervalValue = currentValue;
- currentValue = 0;
- }
-
- /**
- * Push the delta metrics to the mr.
- * The delta is since the last push/interval.
- *
- * Note this does NOT push to JMX
- * (JMX gets the info via {@link #previousIntervalValue}
- *
- * @param mr
- */
- @Override
- public synchronized void pushMetric(final MetricsRecord mr) {
- intervalHeartBeat();
- try {
- mr.incrMetric(getName(), getPreviousIntervalValue());
- } catch (Exception e) {
- LOG.info("pushMetric failed for " + getName() + "\n" , e);
- }
- }
-
-
- /**
- * The Value at the Previous interval
- * @return prev interval value
- */
- public synchronized long getPreviousIntervalValue() {
- return previousIntervalValue;
- }
-
- /**
- * The Value at the current interval
- * @return prev interval value
- */
- public synchronized long getCurrentIntervalValue() {
- return currentValue;
- }
-}
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsTimeVaryingRate.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsTimeVaryingRate.java
deleted file mode 100644
index 71f4b5e6691..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/MetricsTimeVaryingRate.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.metrics.util;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.metrics.MetricsRecord;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * The MetricsTimeVaryingRate class is for a rate based metric that
- * naturally varies over time (e.g. time taken to create a file).
- * The rate is averaged at each interval heart beat (the interval
- * is set in the metrics config file).
- * This class also keeps track of the min and max rates along with
- * a method to reset the min-max.
- *
- * @deprecated Use org.apache.hadoop.metrics2 package instead.
- */
-@Deprecated
-@InterfaceAudience.LimitedPrivate({"HDFS", "MapReduce"})
-public class MetricsTimeVaryingRate extends MetricsBase {
-
- private static final Log LOG =
- LogFactory.getLog("org.apache.hadoop.metrics.util");
-
- static class Metrics {
- int numOperations = 0;
- long time = 0; // total time or average time
-
- void set(final Metrics resetTo) {
- numOperations = resetTo.numOperations;
- time = resetTo.time;
- }
-
- void reset() {
- numOperations = 0;
- time = 0;
- }
- }
-
- static class MinMax {
- long minTime = -1;
- long maxTime = 0;
-
- void set(final MinMax newVal) {
- minTime = newVal.minTime;
- maxTime = newVal.maxTime;
- }
-
- void reset() {
- minTime = -1;
- maxTime = 0;
- }
- void update(final long time) { // update min max
- minTime = (minTime == -1) ? time : Math.min(minTime, time);
- minTime = Math.min(minTime, time);
- maxTime = Math.max(maxTime, time);
- }
- }
- private Metrics currentData;
- private Metrics previousIntervalData;
- private MinMax minMax;
-
-
- /**
- * Constructor - create a new metric
- * @param nam the name of the metrics to be used to publish the metric
- * @param registry - where the metrics object will be registered
- */
- public MetricsTimeVaryingRate(final String nam, final MetricsRegistry registry, final String description) {
- super(nam, description);
- currentData = new Metrics();
- previousIntervalData = new Metrics();
- minMax = new MinMax();
- registry.add(nam, this);
- }
-
- /**
- * Constructor - create a new metric
- * @param nam the name of the metrics to be used to publish the metric
- * @param registry - where the metrics object will be registered
- * A description of {@link #NO_DESCRIPTION} is used
- */
- public MetricsTimeVaryingRate(final String nam, MetricsRegistry registry) {
- this(nam, registry, NO_DESCRIPTION);
-
- }
-
-
- /**
- * Increment the metrics for numOps operations
- * @param numOps - number of operations
- * @param time - time for numOps operations
- */
- public synchronized void inc(final int numOps, final long time) {
- currentData.numOperations += numOps;
- currentData.time += time;
- long timePerOps = time/numOps;
- minMax.update(timePerOps);
- }
-
- /**
- * Increment the metrics for one operation
- * @param time for one operation
- */
- public synchronized void inc(final long time) {
- currentData.numOperations++;
- currentData.time += time;
- minMax.update(time);
- }
-
-
-
- private synchronized void intervalHeartBeat() {
- previousIntervalData.numOperations = currentData.numOperations;
- previousIntervalData.time = (currentData.numOperations == 0) ?
- 0 : currentData.time / currentData.numOperations;
- currentData.reset();
- }
-
- /**
- * Push the delta metrics to the mr.
- * The delta is since the last push/interval.
- *
- * Note this does NOT push to JMX
- * (JMX gets the info via {@link #getPreviousIntervalAverageTime()} and
- * {@link #getPreviousIntervalNumOps()}
- *
- * @param mr
- */
- @Override
- public synchronized void pushMetric(final MetricsRecord mr) {
- intervalHeartBeat();
- try {
- mr.incrMetric(getName() + "_num_ops", getPreviousIntervalNumOps());
- mr.setMetric(getName() + "_avg_time", getPreviousIntervalAverageTime());
- } catch (Exception e) {
- LOG.info("pushMetric failed for " + getName() + "\n" , e);
- }
- }
-
- /**
- * The number of operations in the previous interval
- * @return - ops in prev interval
- */
- public synchronized int getPreviousIntervalNumOps() {
- return previousIntervalData.numOperations;
- }
-
- /**
- * The average rate of an operation in the previous interval
- * @return - the average rate.
- */
- public synchronized long getPreviousIntervalAverageTime() {
- return previousIntervalData.time;
- }
-
- /**
- * The min time for a single operation since the last reset
- * {@link #resetMinMax()}
- * @return min time for an operation
- */
- public synchronized long getMinTime() {
- return minMax.minTime;
- }
-
- /**
- * The max time for a single operation since the last reset
- * {@link #resetMinMax()}
- * @return max time for an operation
- */
- public synchronized long getMaxTime() {
- return minMax.maxTime;
- }
-
- /**
- * Reset the min max values
- */
- public synchronized void resetMinMax() {
- minMax.reset();
- }
-}
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/package-info.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/package-info.java
deleted file mode 100644
index 46dac34e946..00000000000
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics/util/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-@InterfaceAudience.LimitedPrivate({"HBase", "HDFS", "MapReduce"})
-@InterfaceStability.Evolving
-package org.apache.hadoop.metrics.util;
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.classification.InterfaceStability;
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestHttpServer.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestHttpServer.java
index 3ed89a8466b..f3ac5daef2d 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestHttpServer.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestHttpServer.java
@@ -323,7 +323,7 @@ public List getGroups(String user) throws IOException {
}
/**
- * Verify the access for /logs, /stacks, /conf, /logLevel and /metrics
+ * Verify the access for /logs, /stacks, /conf, and /logLevel
* servlets, when authentication filters are set, but authorization is not
* enabled.
* @throws Exception
@@ -349,7 +349,7 @@ public void testDisabledAuthorizationOfDefaultServlets() throws Exception {
myServer.start();
String serverURL = "http://" + NetUtils.getHostPortString(myServer.getConnectorAddress(0)) + "/";
for (String servlet : new String[] { "conf", "logs", "stacks",
- "logLevel", "metrics" }) {
+ "logLevel" }) {
for (String user : new String[] { "userA", "userB" }) {
assertEquals(HttpURLConnection.HTTP_OK, getHttpStatusCode(serverURL
+ servlet, user));
@@ -359,8 +359,8 @@ public void testDisabledAuthorizationOfDefaultServlets() throws Exception {
}
/**
- * Verify the administrator access for /logs, /stacks, /conf, /logLevel and
- * /metrics servlets.
+ * Verify the administrator access for /logs, /stacks, /conf, and /logLevel
+ * servlets.
*
* @throws Exception
*/
@@ -393,7 +393,7 @@ public void testAuthorizationOfDefaultServlets() throws Exception {
String serverURL = "http://"
+ NetUtils.getHostPortString(myServer.getConnectorAddress(0)) + "/";
for (String servlet : new String[] { "conf", "logs", "stacks",
- "logLevel", "metrics" }) {
+ "logLevel" }) {
for (String user : new String[] { "userA", "userB", "userC", "userD" }) {
assertEquals(HttpURLConnection.HTTP_OK, getHttpStatusCode(serverURL
+ servlet, user));
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics/TestMetricsServlet.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics/TestMetricsServlet.java
deleted file mode 100644
index b2ea9df57ac..00000000000
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics/TestMetricsServlet.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.metrics;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.apache.hadoop.metrics.MetricsServlet.TagsMetricsPair;
-import org.apache.hadoop.metrics.spi.NoEmitMetricsContext;
-import org.apache.hadoop.metrics.spi.OutputRecord;
-import org.mortbay.util.ajax.JSON;
-
-@Deprecated
-public class TestMetricsServlet extends TestCase {
- MetricsContext nc1;
- MetricsContext nc2;
- // List containing nc1 and nc2.
- List contexts;
- OutputRecord outputRecord;
-
- /**
- * Initializes, for testing, two NoEmitMetricsContext's, and adds one value
- * to the first of them.
- */
- @Override
- public void setUp() throws IOException {
- nc1 = new NoEmitMetricsContext();
- nc1.init("test1", ContextFactory.getFactory());
- nc2 = new NoEmitMetricsContext();
- nc2.init("test2", ContextFactory.getFactory());
- contexts = new ArrayList();
- contexts.add(nc1);
- contexts.add(nc2);
-
- MetricsRecord r = nc1.createRecord("testRecord");
-
- r.setTag("testTag1", "testTagValue1");
- r.setTag("testTag2", "testTagValue2");
- r.setMetric("testMetric1", 1);
- r.setMetric("testMetric2", 33);
- r.update();
-
- Map> m = nc1.getAllRecords();
- assertEquals(1, m.size());
- assertEquals(1, m.values().size());
- Collection outputRecords = m.values().iterator().next();
- assertEquals(1, outputRecords.size());
- outputRecord = outputRecords.iterator().next();
- }
-
-
-
- public void testTagsMetricsPair() throws IOException {
- TagsMetricsPair pair = new TagsMetricsPair(outputRecord.getTagsCopy(),
- outputRecord.getMetricsCopy());
- String s = JSON.toString(pair);
- assertEquals(
- "[{\"testTag1\":\"testTagValue1\",\"testTag2\":\"testTagValue2\"},"+
- "{\"testMetric1\":1,\"testMetric2\":33}]", s);
- }
-
- public void testGetMap() throws IOException {
- MetricsServlet servlet = new MetricsServlet();
- Map>> m = servlet.makeMap(contexts);
- assertEquals("Map missing contexts", 2, m.size());
- assertTrue(m.containsKey("test1"));
-
- Map> m2 = m.get("test1");
-
- assertEquals("Missing records", 1, m2.size());
- assertTrue(m2.containsKey("testRecord"));
- assertEquals("Wrong number of tags-values pairs.", 1, m2.get("testRecord").size());
- }
-
- public void testPrintMap() throws IOException {
- StringWriter sw = new StringWriter();
- PrintWriter out = new PrintWriter(sw);
- MetricsServlet servlet = new MetricsServlet();
- servlet.printMap(out, servlet.makeMap(contexts));
-
- String EXPECTED = "" +
- "test1\n" +
- " testRecord\n" +
- " {testTag1=testTagValue1,testTag2=testTagValue2}:\n" +
- " testMetric1=1\n" +
- " testMetric2=33\n" +
- "test2\n";
- assertEquals(EXPECTED, sw.toString());
- }
-}
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics/ganglia/TestGangliaContext.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics/ganglia/TestGangliaContext.java
deleted file mode 100644
index bae3ec048fb..00000000000
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics/ganglia/TestGangliaContext.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * TestGangliaContext.java
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package org.apache.hadoop.metrics.ganglia;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.hadoop.metrics.ContextFactory;
-import org.apache.hadoop.metrics.spi.AbstractMetricsContext;
-
-import java.net.MulticastSocket;
-
-@Deprecated
-public class TestGangliaContext {
- @Test
- public void testShouldCreateDatagramSocketByDefault() throws Exception {
- GangliaContext context = new GangliaContext();
- context.init("gangliaContext", ContextFactory.getFactory());
- assertFalse("Created MulticastSocket", context.datagramSocket instanceof MulticastSocket);
- }
-
- @Test
- public void testShouldCreateDatagramSocketIfMulticastIsDisabled() throws Exception {
- GangliaContext context = new GangliaContext();
- ContextFactory factory = ContextFactory.getFactory();
- factory.setAttribute("gangliaContext.multicast", "false");
- context.init("gangliaContext", factory);
- assertFalse("Created MulticastSocket", context.datagramSocket instanceof MulticastSocket);
- }
-
- @Test
- public void testShouldCreateMulticastSocket() throws Exception {
- GangliaContext context = new GangliaContext();
- ContextFactory factory = ContextFactory.getFactory();
- factory.setAttribute("gangliaContext.multicast", "true");
- context.init("gangliaContext", factory);
- assertTrue("Did not create MulticastSocket", context.datagramSocket instanceof MulticastSocket);
- MulticastSocket multicastSocket = (MulticastSocket) context.datagramSocket;
- assertEquals("Did not set default TTL", multicastSocket.getTimeToLive(), 1);
- }
-
- @Test
- public void testShouldSetMulticastSocketTtl() throws Exception {
- GangliaContext context = new GangliaContext();
- ContextFactory factory = ContextFactory.getFactory();
- factory.setAttribute("gangliaContext.multicast", "true");
- factory.setAttribute("gangliaContext.multicast.ttl", "10");
- context.init("gangliaContext", factory);
- MulticastSocket multicastSocket = (MulticastSocket) context.datagramSocket;
- assertEquals("Did not set TTL", multicastSocket.getTimeToLive(), 10);
- }
-
- @Test
- public void testCloseShouldCloseTheSocketWhichIsCreatedByInit() throws Exception {
- AbstractMetricsContext context=new GangliaContext();
- context.init("gangliaContext", ContextFactory.getFactory());
- GangliaContext gangliaContext =(GangliaContext) context;
- assertFalse("Socket already closed",gangliaContext.datagramSocket.isClosed());
- context.close();
- assertTrue("Socket not closed",gangliaContext.datagramSocket.isClosed());
- }
-}
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics/spi/TestOutputRecord.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics/spi/TestOutputRecord.java
deleted file mode 100644
index 9747cb9a80a..00000000000
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics/spi/TestOutputRecord.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.metrics.spi;
-
-import org.apache.hadoop.metrics.spi.AbstractMetricsContext.MetricMap;
-import org.apache.hadoop.metrics.spi.AbstractMetricsContext.TagMap;
-
-import junit.framework.TestCase;
-
-@Deprecated
-public class TestOutputRecord extends TestCase {
- public void testCopy() {
- TagMap tags = new TagMap();
- tags.put("tagkey", "tagval");
- MetricMap metrics = new MetricMap();
- metrics.put("metrickey", 123.4);
- OutputRecord r = new OutputRecord(tags, metrics);
-
- assertEquals(tags, r.getTagsCopy());
- assertNotSame(tags, r.getTagsCopy());
- assertEquals(metrics, r.getMetricsCopy());
- assertNotSame(metrics, r.getMetricsCopy());
- }
-}