You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@metron.apache.org by GitBox <gi...@apache.org> on 2019/07/12 18:08:06 UTC

[GitHub] [metron] merrimanr commented on a change in pull request #1456: METRON-2175 Introduce HBase Connection Abstractions for HBase 2.0.2

merrimanr commented on a change in pull request #1456: METRON-2175 Introduce HBase Connection Abstractions for HBase 2.0.2
URL: https://github.com/apache/metron/pull/1456#discussion_r303091994
 
 

 ##########
 File path: metron-platform/metron-hbase/metron-hbase-common/src/main/java/org/apache/metron/hbase/client/HBaseTableClient.java
 ##########
 @@ -0,0 +1,276 @@
+/*
+ *
+ *  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.metron.hbase.client;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.Delete;
+import org.apache.hadoop.hbase.client.Durability;
+import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.client.Increment;
+import org.apache.hadoop.hbase.client.Mutation;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.metron.hbase.ColumnList;
+import org.apache.metron.hbase.HBaseProjectionCriteria;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.apache.commons.collections4.CollectionUtils.size;
+
+/**
+ * An {@link HBaseClient} that uses the {@link Table} API to interact with HBase.
+ */
+public class HBaseTableClient implements HBaseClient {
+  private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+  private List<Mutation> mutations;
+  private List<Get> gets;
+  private Connection connection;
+  private Table table;
+
+  /**
+   * @param connectionFactory Creates connections to HBase.
+   * @param configuration The HBase configuration.
+   * @param tableName The name of the HBase table.
+   */
+  public HBaseTableClient(HBaseConnectionFactory connectionFactory, Configuration configuration, String tableName) throws IOException {
+    gets = new ArrayList<>();
+    mutations = new ArrayList<>();
+    connection = connectionFactory.createConnection(configuration);
+    table = connection.getTable(TableName.valueOf(tableName));
+  }
+
+  @Override
+  public void close() throws IOException {
+    if(table != null) {
 
 Review comment:
   Should these be in try/catch blocks?  We would still want to close the connection if closing a table failed.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services