Repository: nifi
Updated Branches:
  refs/heads/master fc902234b -> 1dbfcb944


NIFI-5062: Removed hbase-client dependecy from hbase bundle

This closes #2636

Signed-off-by: Mike Thomsen <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/1dbfcb94
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/1dbfcb94
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/1dbfcb94

Branch: refs/heads/master
Commit: 1dbfcb94453cdfb50666b876c6836d924fae9048
Parents: fc90223
Author: zenfenan <[email protected]>
Authored: Sat Apr 14 11:34:07 2018 +0530
Committer: Mike Thomsen <[email protected]>
Committed: Fri Apr 20 08:50:25 2018 -0400

----------------------------------------------------------------------
 .../nifi-hbase-processors/pom.xml               |  12 ---
 .../nifi/hbase/MockHBaseClientService.java      |  35 ++++++-
 .../apache/nifi/hbase/TestPutHBaseRecord.java   |   2 +-
 .../java/org/apache/nifi/hbase/util/Bytes.java  | 104 +++++++++++++++++++
 nifi-nar-bundles/nifi-hbase-bundle/pom.xml      |   5 -
 .../nifi-hbase_1_1_2-client-service/pom.xml     |   5 +-
 6 files changed, 142 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/1dbfcb94/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/pom.xml
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/pom.xml 
b/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/pom.xml
index 93b7963..a44f4d6 100644
--- a/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/pom.xml
+++ b/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/pom.xml
@@ -78,18 +78,6 @@
             <artifactId>mockito-all</artifactId>
             <scope>test</scope>
         </dependency>
-
-        <dependency>
-            <groupId>org.apache.hbase</groupId>
-            <artifactId>hbase-client</artifactId>
-            <exclusions>
-                <exclusion>
-                    <groupId>org.slf4j</groupId>
-                    <artifactId>slf4j-log4j12</artifactId>
-                </exclusion>
-            </exclusions>
-            <scope>test</scope>
-        </dependency>
         <dependency>
             <groupId>org.apache.nifi</groupId>
             <artifactId>nifi-mock-record-utils</artifactId>

http://git-wip-us.apache.org/repos/asf/nifi/blob/1dbfcb94/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/src/test/java/org/apache/nifi/hbase/MockHBaseClientService.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/src/test/java/org/apache/nifi/hbase/MockHBaseClientService.java
 
b/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/src/test/java/org/apache/nifi/hbase/MockHBaseClientService.java
index 6cecec8..b3b65f1 100644
--- 
a/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/src/test/java/org/apache/nifi/hbase/MockHBaseClientService.java
+++ 
b/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/src/test/java/org/apache/nifi/hbase/MockHBaseClientService.java
@@ -16,7 +16,6 @@
  */
 package org.apache.nifi.hbase;
 
-import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.nifi.controller.AbstractControllerService;
 import org.apache.nifi.hbase.put.PutColumn;
 import org.apache.nifi.hbase.put.PutFlowFile;
@@ -262,7 +261,7 @@ public class MockHBaseClientService extends 
AbstractControllerService implements
 
     @Override
     public byte[] toBytesBinary(String s) {
-       return Bytes.toBytesBinary(s);
+       return convertToBytesBinary(s);
     }
 
     private boolean testFailure = false;
@@ -290,4 +289,36 @@ public class MockHBaseClientService extends 
AbstractControllerService implements
     public void setLinesBeforeException(int linesBeforeException) {
         this.linesBeforeException = linesBeforeException;
     }
+
+    private byte[] convertToBytesBinary(String in) {
+        byte[] b = new byte[in.length()];
+        int size = 0;
+
+        for(int i = 0; i < in.length(); ++i) {
+            char ch = in.charAt(i);
+            if (ch == '\\' && in.length() > i + 1 && in.charAt(i + 1) == 'x') {
+                char hd1 = in.charAt(i + 2);
+                char hd2 = in.charAt(i + 3);
+                if (isHexDigit(hd1) && isHexDigit(hd2)) {
+                    byte d = (byte)((toBinaryFromHex((byte)hd1) << 4) + 
toBinaryFromHex((byte)hd2));
+                    b[size++] = d;
+                    i += 3;
+                }
+            } else {
+                b[size++] = (byte)ch;
+            }
+        }
+
+        byte[] b2 = new byte[size];
+        System.arraycopy(b, 0, b2, 0, size);
+        return b2;
+    }
+
+    private static boolean isHexDigit(char c) {
+        return c >= 'A' && c <= 'F' || c >= '0' && c <= '9';
+    }
+
+    private static byte toBinaryFromHex(byte ch) {
+        return ch >= 65 && ch <= 70 ? (byte)(10 + (byte)(ch - 65)) : (byte)(ch 
- 48);
+    }
 }

http://git-wip-us.apache.org/repos/asf/nifi/blob/1dbfcb94/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/src/test/java/org/apache/nifi/hbase/TestPutHBaseRecord.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/src/test/java/org/apache/nifi/hbase/TestPutHBaseRecord.java
 
b/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/src/test/java/org/apache/nifi/hbase/TestPutHBaseRecord.java
index 7bc5f96..af0da95 100644
--- 
a/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/src/test/java/org/apache/nifi/hbase/TestPutHBaseRecord.java
+++ 
b/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/src/test/java/org/apache/nifi/hbase/TestPutHBaseRecord.java
@@ -17,9 +17,9 @@
 
 package org.apache.nifi.hbase;
 
-import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.nifi.hbase.put.PutColumn;
 import org.apache.nifi.hbase.put.PutFlowFile;
+import org.apache.nifi.hbase.util.Bytes;
 import org.apache.nifi.reporting.InitializationException;
 import org.apache.nifi.serialization.record.MockRecordParser;
 import org.apache.nifi.serialization.record.RecordFieldType;

http://git-wip-us.apache.org/repos/asf/nifi/blob/1dbfcb94/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/src/test/java/org/apache/nifi/hbase/util/Bytes.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/src/test/java/org/apache/nifi/hbase/util/Bytes.java
 
b/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/src/test/java/org/apache/nifi/hbase/util/Bytes.java
new file mode 100644
index 0000000..f79dfcd
--- /dev/null
+++ 
b/nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/src/test/java/org/apache/nifi/hbase/util/Bytes.java
@@ -0,0 +1,104 @@
+/*
+ * 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.nifi.hbase.util;
+
+import sun.misc.Unsafe;
+
+import java.lang.reflect.Field;
+import java.nio.ByteOrder;
+import java.nio.charset.Charset;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+public class Bytes {
+
+    public static String toString(byte[] b) {
+        return b == null ? null : toString(b, 0, b.length);
+    }
+
+    public static String toString(byte[] b1, String sep, byte[] b2) {
+        return toString(b1, 0, b1.length) + sep + toString(b2, 0, b2.length);
+    }
+
+    public static String toString(byte[] b, int off, int len) {
+        if (b == null) {
+            return null;
+        } else {
+            return len == 0 ? "" : new String(b, off, len, 
Charset.forName("UTF-8"));
+        }
+    }
+
+    public static long toLong(byte[] bytes) {
+        return toLong(bytes, 0, 8);
+    }
+
+    private static long toLong(byte[] bytes, int offset, int length) {
+        if (length == 8 && offset + length <= bytes.length) {
+            if (theUnsafe != null) {
+                return toLongUnsafe(bytes, offset);
+            } else {
+                long l = 0L;
+
+                for(int i = offset; i < offset + length; ++i) {
+                    l <<= 8;
+                    l ^= (long)(bytes[i] & 255);
+                }
+
+                return l;
+            }
+        } else {
+            throw explainWrongLengthOrOffset(bytes, offset, length, 8);
+        }
+    }
+
+    private static long toLongUnsafe(byte[] bytes, int offset) {
+        final boolean littleEndian = 
ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN);
+        final int BYTE_ARRAY_BASE_OFFSET = 
theUnsafe.arrayBaseOffset(byte[].class);
+
+        if (littleEndian) {
+            return Long.reverseBytes(theUnsafe.getLong(bytes,
+                    (long) offset + BYTE_ARRAY_BASE_OFFSET));
+        } else {
+            return theUnsafe.getLong(bytes,
+                    (long) offset + BYTE_ARRAY_BASE_OFFSET);
+        }
+    }
+
+    private static IllegalArgumentException explainWrongLengthOrOffset(byte[] 
bytes, int offset, int length, int expectedLength) {
+        String reason;
+        if (length != expectedLength) {
+            reason = "Wrong length: " + length + ", expected " + 
expectedLength;
+        } else {
+            reason = "offset (" + offset + ") + length (" + length + ") exceed 
the" + " capacity of the array: " + bytes.length;
+        }
+
+        return new IllegalArgumentException(reason);
+    }
+
+    private static final Unsafe theUnsafe = (Unsafe) 
AccessController.doPrivileged(new PrivilegedAction<Object>() {
+        public Object run() {
+            try {
+                Field f = Unsafe.class.getDeclaredField("theUnsafe");
+                f.setAccessible(true);
+                return f.get((Object)null);
+            } catch (NoSuchFieldException | IllegalAccessException var2) {
+                throw new Error();
+            }
+        }
+    });
+
+}

http://git-wip-us.apache.org/repos/asf/nifi/blob/1dbfcb94/nifi-nar-bundles/nifi-hbase-bundle/pom.xml
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-hbase-bundle/pom.xml 
b/nifi-nar-bundles/nifi-hbase-bundle/pom.xml
index 84c5fa2..962086d 100644
--- a/nifi-nar-bundles/nifi-hbase-bundle/pom.xml
+++ b/nifi-nar-bundles/nifi-hbase-bundle/pom.xml
@@ -37,11 +37,6 @@
                 <artifactId>nifi-hbase-processors</artifactId>
                 <version>1.7.0-SNAPSHOT</version>
             </dependency>
-            <dependency>
-                <groupId>org.apache.hbase</groupId>
-                <artifactId>hbase-client</artifactId>
-                <version>1.1.2</version>
-            </dependency>
         </dependencies>
     </dependencyManagement>
 </project>

http://git-wip-us.apache.org/repos/asf/nifi/blob/1dbfcb94/nifi-nar-bundles/nifi-standard-services/nifi-hbase_1_1_2-client-service-bundle/nifi-hbase_1_1_2-client-service/pom.xml
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-standard-services/nifi-hbase_1_1_2-client-service-bundle/nifi-hbase_1_1_2-client-service/pom.xml
 
b/nifi-nar-bundles/nifi-standard-services/nifi-hbase_1_1_2-client-service-bundle/nifi-hbase_1_1_2-client-service/pom.xml
index dcb1f76..54f0d2d 100644
--- 
a/nifi-nar-bundles/nifi-standard-services/nifi-hbase_1_1_2-client-service-bundle/nifi-hbase_1_1_2-client-service/pom.xml
+++ 
b/nifi-nar-bundles/nifi-standard-services/nifi-hbase_1_1_2-client-service-bundle/nifi-hbase_1_1_2-client-service/pom.xml
@@ -24,6 +24,9 @@
 
     <artifactId>nifi-hbase_1_1_2-client-service</artifactId>
     <packaging>jar</packaging>
+    <properties>
+        <hbase.version>1.1.2</hbase.version>
+    </properties>
     <dependencies>
         <dependency>
             <groupId>org.apache.nifi</groupId>
@@ -70,7 +73,7 @@
         <dependency>
             <groupId>org.apache.hbase</groupId>
             <artifactId>hbase-client</artifactId>
-            <version>1.1.2</version>
+            <version>${hbase.version}</version>
             <exclusions>
                 <exclusion>
                     <groupId>org.slf4j</groupId>

Reply via email to