[2/3] PHOENIX-1286 Remove hadoop2 compat modules

2014-10-27 Thread jyates
http://git-wip-us.apache.org/repos/asf/phoenix/blob/b48ca7b5/phoenix-core/src/main/java/org/apache/phoenix/trace/TracingUtils.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/trace/TracingUtils.java 
b/phoenix-core/src/main/java/org/apache/phoenix/trace/TracingUtils.java
new file mode 100644
index 000..6ae52d8
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/trace/TracingUtils.java
@@ -0,0 +1,63 @@
+/**
+ * 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.phoenix.trace;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.Pair;
+import org.cloudera.htrace.Span;
+
+/**
+ * Utilities for tracing
+ */
+public class TracingUtils {
+
+private static final Log LOG = LogFactory.getLog(TracingUtils.class);
+
+public static final String METRIC_SOURCE_KEY = "phoenix.";
+
+/** Set context to enable filtering */
+public static final String METRICS_CONTEXT = "tracing";
+
+/** Marker metric to ensure that we register the tracing mbeans */
+public static final String METRICS_MARKER_CONTEXT = "marker";
+
+public static void addAnnotation(Span span, String message, int value) {
+span.addKVAnnotation(message.getBytes(), 
Bytes.toBytes(Integer.toString(value)));
+}
+
+public static Pair readAnnotation(byte[] key, byte[] 
value) {
+return new Pair(new String(key), 
Bytes.toString(value));
+}
+
+/**
+ * @see #getTraceMetricName(String)
+ */
+public static final String getTraceMetricName(long traceId) {
+return getTraceMetricName(Long.toString(traceId));
+}
+
+/**
+ * @param traceId unique id of the trace
+ * @return the name of the metric record that should be generated for a 
given trace
+ */
+public static final String getTraceMetricName(String traceId) {
+return METRIC_SOURCE_KEY + traceId;
+}
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b48ca7b5/phoenix-core/src/main/java/org/apache/phoenix/trace/util/Tracing.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/trace/util/Tracing.java 
b/phoenix-core/src/main/java/org/apache/phoenix/trace/util/Tracing.java
index d0677cf..b093b9c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/trace/util/Tracing.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/trace/util/Tracing.java
@@ -36,8 +36,7 @@ import org.apache.phoenix.call.CallWrapper;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
-import org.apache.phoenix.trace.TracingCompat;
-import org.apache.phoenix.util.StringUtil;
+import org.apache.phoenix.trace.TraceMetricSource;
 import org.cloudera.htrace.Sampler;
 import org.cloudera.htrace.Span;
 import org.cloudera.htrace.Trace;
@@ -313,7 +312,7 @@ public class Tracing {
 public synchronized static void addTraceMetricsSource() {
 try {
 if (!initialized) {
-Trace.addReceiver(TracingCompat.newTraceMetricSource());
+Trace.addReceiver(new TraceMetricSource());
 }
 } catch (RuntimeException e) {
 LOG.warn("Tracing will outputs will not be written to any metrics 
sink! No "

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b48ca7b5/phoenix-core/src/test/java/org/apache/hadoop/metrics2/impl/ExposedMetricCounterLong.java
--
diff --git 
a/phoenix-core/src/test/java/org/apache/hadoop/metrics2/impl/ExposedMetricCounterLong.java
 
b/phoenix-core/src/test/java/org/apache/hadoop/metrics2/impl/ExposedMetricCounterLong.java
new file mode 100644
index 000..f4dfd74
--- /dev/null
+++ 
b/phoenix-core/src/test/java/org/apache/hadoop/metrics2/impl/ExposedMetricCounterLong.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file

[2/3] PHOENIX-1286 Remove hadoop2 compat modules

2014-10-27 Thread jyates
http://git-wip-us.apache.org/repos/asf/phoenix/blob/842f8a8a/phoenix-core/src/main/java/org/apache/phoenix/trace/TracingUtils.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/trace/TracingUtils.java 
b/phoenix-core/src/main/java/org/apache/phoenix/trace/TracingUtils.java
new file mode 100644
index 000..6ae52d8
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/trace/TracingUtils.java
@@ -0,0 +1,63 @@
+/**
+ * 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.phoenix.trace;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.Pair;
+import org.cloudera.htrace.Span;
+
+/**
+ * Utilities for tracing
+ */
+public class TracingUtils {
+
+private static final Log LOG = LogFactory.getLog(TracingUtils.class);
+
+public static final String METRIC_SOURCE_KEY = "phoenix.";
+
+/** Set context to enable filtering */
+public static final String METRICS_CONTEXT = "tracing";
+
+/** Marker metric to ensure that we register the tracing mbeans */
+public static final String METRICS_MARKER_CONTEXT = "marker";
+
+public static void addAnnotation(Span span, String message, int value) {
+span.addKVAnnotation(message.getBytes(), 
Bytes.toBytes(Integer.toString(value)));
+}
+
+public static Pair readAnnotation(byte[] key, byte[] 
value) {
+return new Pair(new String(key), 
Bytes.toString(value));
+}
+
+/**
+ * @see #getTraceMetricName(String)
+ */
+public static final String getTraceMetricName(long traceId) {
+return getTraceMetricName(Long.toString(traceId));
+}
+
+/**
+ * @param traceId unique id of the trace
+ * @return the name of the metric record that should be generated for a 
given trace
+ */
+public static final String getTraceMetricName(String traceId) {
+return METRIC_SOURCE_KEY + traceId;
+}
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/842f8a8a/phoenix-core/src/main/java/org/apache/phoenix/trace/util/Tracing.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/trace/util/Tracing.java 
b/phoenix-core/src/main/java/org/apache/phoenix/trace/util/Tracing.java
index d0677cf..b093b9c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/trace/util/Tracing.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/trace/util/Tracing.java
@@ -36,8 +36,7 @@ import org.apache.phoenix.call.CallWrapper;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
-import org.apache.phoenix.trace.TracingCompat;
-import org.apache.phoenix.util.StringUtil;
+import org.apache.phoenix.trace.TraceMetricSource;
 import org.cloudera.htrace.Sampler;
 import org.cloudera.htrace.Span;
 import org.cloudera.htrace.Trace;
@@ -313,7 +312,7 @@ public class Tracing {
 public synchronized static void addTraceMetricsSource() {
 try {
 if (!initialized) {
-Trace.addReceiver(TracingCompat.newTraceMetricSource());
+Trace.addReceiver(new TraceMetricSource());
 }
 } catch (RuntimeException e) {
 LOG.warn("Tracing will outputs will not be written to any metrics 
sink! No "

http://git-wip-us.apache.org/repos/asf/phoenix/blob/842f8a8a/phoenix-core/src/test/java/org/apache/hadoop/metrics2/impl/ExposedMetricCounterLong.java
--
diff --git 
a/phoenix-core/src/test/java/org/apache/hadoop/metrics2/impl/ExposedMetricCounterLong.java
 
b/phoenix-core/src/test/java/org/apache/hadoop/metrics2/impl/ExposedMetricCounterLong.java
new file mode 100644
index 000..f4dfd74
--- /dev/null
+++ 
b/phoenix-core/src/test/java/org/apache/hadoop/metrics2/impl/ExposedMetricCounterLong.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file