|
@@ -25,7 +25,6 @@ import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.util.Collections;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.TreeMap;
|
|
@@ -38,11 +37,12 @@ import org.apache.hadoop.classification.InterfaceAudience;
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
import org.apache.hadoop.io.IOUtils;
|
|
|
import org.apache.hadoop.tracing.SpanReceiverInfo.ConfigurationPair;
|
|
|
+import org.apache.hadoop.tracing.TraceUtils;
|
|
|
import org.apache.hadoop.util.ReflectionUtils;
|
|
|
import org.apache.hadoop.util.ShutdownHookManager;
|
|
|
-import org.htrace.HTraceConfiguration;
|
|
|
-import org.htrace.SpanReceiver;
|
|
|
-import org.htrace.Trace;
|
|
|
+import org.apache.htrace.SpanReceiver;
|
|
|
+import org.apache.htrace.SpanReceiverBuilder;
|
|
|
+import org.apache.htrace.Trace;
|
|
|
|
|
|
/**
|
|
|
* This class provides functions for reading the names of SpanReceivers from
|
|
@@ -156,60 +156,13 @@ public class SpanReceiverHost implements TraceAdminProtocol {
|
|
|
|
|
|
private synchronized SpanReceiver loadInstance(String className,
|
|
|
List<ConfigurationPair> extraConfig) throws IOException {
|
|
|
- className = className.trim();
|
|
|
- if (!className.contains(".")) {
|
|
|
- className = "org.htrace.impl." + className;
|
|
|
- }
|
|
|
- Class<?> implClass = null;
|
|
|
- SpanReceiver impl;
|
|
|
- try {
|
|
|
- implClass = Class.forName(className);
|
|
|
- Object o = ReflectionUtils.newInstance(implClass, config);
|
|
|
- impl = (SpanReceiver)o;
|
|
|
- impl.configure(wrapHadoopConf(config, extraConfig));
|
|
|
- } catch (ClassCastException e) {
|
|
|
- throw new IOException("Class " + className +
|
|
|
- " does not implement SpanReceiver.");
|
|
|
- } catch (ClassNotFoundException e) {
|
|
|
- throw new IOException("Class " + className + " cannot be found.");
|
|
|
- } catch (SecurityException e) {
|
|
|
- throw new IOException("Got SecurityException while loading " +
|
|
|
- "SpanReceiver " + className);
|
|
|
- } catch (IllegalArgumentException e) {
|
|
|
- throw new IOException("Got IllegalArgumentException while loading " +
|
|
|
- "SpanReceiver " + className, e);
|
|
|
- } catch (RuntimeException e) {
|
|
|
- throw new IOException("Got RuntimeException while loading " +
|
|
|
- "SpanReceiver " + className, e);
|
|
|
- }
|
|
|
- return impl;
|
|
|
- }
|
|
|
-
|
|
|
- private static HTraceConfiguration wrapHadoopConf(final Configuration conf,
|
|
|
- List<ConfigurationPair> extraConfig) {
|
|
|
- final HashMap<String, String> extraMap = new HashMap<String, String>();
|
|
|
- for (ConfigurationPair pair : extraConfig) {
|
|
|
- extraMap.put(pair.getKey(), pair.getValue());
|
|
|
+ SpanReceiverBuilder builder =
|
|
|
+ new SpanReceiverBuilder(TraceUtils.wrapHadoopConf(config, extraConfig));
|
|
|
+ SpanReceiver rcvr = builder.spanReceiverClass(className.trim()).build();
|
|
|
+ if (rcvr == null) {
|
|
|
+ throw new IOException("Failed to load SpanReceiver " + className);
|
|
|
}
|
|
|
- return new HTraceConfiguration() {
|
|
|
- public static final String HTRACE_CONF_PREFIX = "hadoop.htrace.";
|
|
|
-
|
|
|
- @Override
|
|
|
- public String get(String key) {
|
|
|
- if (extraMap.containsKey(key)) {
|
|
|
- return extraMap.get(key);
|
|
|
- }
|
|
|
- return conf.get(HTRACE_CONF_PREFIX + key);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String get(String key, String defaultValue) {
|
|
|
- if (extraMap.containsKey(key)) {
|
|
|
- return extraMap.get(key);
|
|
|
- }
|
|
|
- return conf.get(HTRACE_CONF_PREFIX + key, defaultValue);
|
|
|
- }
|
|
|
- };
|
|
|
+ return rcvr;
|
|
|
}
|
|
|
|
|
|
/**
|