mikewalch closed pull request #744: Fixes #533 - Create scanner with default 
user auths
URL: https://github.com/apache/accumulo/pull/744
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/core/src/main/java/org/apache/accumulo/core/client/AccumuloClient.java 
b/core/src/main/java/org/apache/accumulo/core/client/AccumuloClient.java
index e7f6a4bd4c..359419c8bc 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/AccumuloClient.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/AccumuloClient.java
@@ -99,6 +99,20 @@ BatchScanner createBatchScanner(String tableName, 
Authorizations authorizations,
   BatchScanner createBatchScanner(String tableName, Authorizations 
authorizations)
       throws TableNotFoundException;
 
+  /**
+   * Factory method to create a BatchScanner with all of user's authorizations 
and the number of
+   * query threads configured when AccumuloClient was created. If no query 
threads were configured,
+   * defaults will be used.
+   *
+   * @param tableName
+   *          the name of the table to query
+   *
+   * @return BatchScanner object for configuring and querying
+   * @throws TableNotFoundException
+   *           when the specified table doesn't exist
+   */
+  BatchScanner createBatchScanner(String tableName) throws 
TableNotFoundException, AccumuloSecurityException, AccumuloException;
+
   /**
    * Factory method to create BatchDeleter
    *
@@ -211,6 +225,20 @@ BatchWriter createBatchWriter(String tableName, 
BatchWriterConfig config)
   Scanner createScanner(String tableName, Authorizations authorizations)
       throws TableNotFoundException;
 
+  /**
+   * Factory method to create a Scanner with all of the user's authorizations.
+   *
+   * @param tableName
+   *          the name of the table to query data from
+   *
+   * @return Scanner object for configuring and querying data with
+   * @throws TableNotFoundException
+   *           when the specified table doesn't exist
+   *
+   * @see IsolatedScanner
+   */
+  Scanner createScanner(String tableName) throws TableNotFoundException, 
AccumuloSecurityException, AccumuloException;
+
   /**
    * Factory method to create a ConditionalWriter connected to Accumulo.
    *
diff --git 
a/core/src/main/java/org/apache/accumulo/core/client/impl/AccumuloClientImpl.java
 
b/core/src/main/java/org/apache/accumulo/core/client/impl/AccumuloClientImpl.java
index 8a6ce3e70a..eaf0d8d0a1 100644
--- 
a/core/src/main/java/org/apache/accumulo/core/client/impl/AccumuloClientImpl.java
+++ 
b/core/src/main/java/org/apache/accumulo/core/client/impl/AccumuloClientImpl.java
@@ -125,6 +125,13 @@ public BatchScanner createBatchScanner(String tableName, 
Authorizations authoriz
     return createBatchScanner(tableName, authorizations, numQueryThreads);
   }
 
+  @Override
+  public BatchScanner createBatchScanner(String tableName) throws 
TableNotFoundException,
+      AccumuloSecurityException, AccumuloException {
+    Authorizations auths = 
securityOperations().getUserAuthorizations(context.getPrincipal());
+    return createBatchScanner(tableName, auths);
+  }
+
   @Override
   public BatchDeleter createBatchDeleter(String tableName, Authorizations 
authorizations,
       int numQueryThreads, BatchWriterConfig config) throws 
TableNotFoundException {
@@ -193,6 +200,13 @@ public Scanner createScanner(String tableName, 
Authorizations authorizations)
     return scanner;
   }
 
+  @Override
+  public Scanner createScanner(String tableName) throws TableNotFoundException,
+      AccumuloSecurityException, AccumuloException {
+    Authorizations auths = 
securityOperations().getUserAuthorizations(context.getPrincipal());
+    return createScanner(tableName, auths);
+  }
+
   @Override
   public String whoami() {
     ensureOpen();
diff --git 
a/core/src/main/java/org/apache/accumulo/core/client/impl/ClientContext.java 
b/core/src/main/java/org/apache/accumulo/core/client/impl/ClientContext.java
index cd18f50c2f..3c63cdae4f 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/impl/ClientContext.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/impl/ClientContext.java
@@ -31,8 +31,10 @@
 import org.apache.accumulo.core.client.AccumuloSecurityException;
 import org.apache.accumulo.core.client.BatchWriterConfig;
 import org.apache.accumulo.core.client.ClientInfo;
+import org.apache.accumulo.core.client.Durability;
 import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
 import org.apache.accumulo.core.conf.AccumuloConfiguration;
+import org.apache.accumulo.core.conf.ClientProperty;
 import org.apache.accumulo.core.conf.Property;
 import org.apache.accumulo.core.metadata.RootTable;
 import org.apache.accumulo.core.rpc.SaslConnectionParams;
@@ -243,7 +245,24 @@ public synchronized AccumuloClient getClient()
   public BatchWriterConfig getBatchWriterConfig() {
     ensureOpen();
     if (batchWriterConfig == null) {
-      batchWriterConfig = 
ClientInfoFactory.getBatchWriterConfig(getClientInfo());
+      Properties props = info.getProperties();
+      batchWriterConfig = new BatchWriterConfig();
+      Long maxMemory = 
ClientProperty.BATCH_WRITER_MAX_MEMORY_BYTES.getLong(props);
+      if (maxMemory != null) {
+        batchWriterConfig.setMaxMemory(maxMemory);
+      }
+      Long maxLatency = 
ClientProperty.BATCH_WRITER_MAX_LATENCY_SEC.getLong(props);
+      if (maxLatency != null) {
+        batchWriterConfig.setMaxLatency(maxLatency, TimeUnit.SECONDS);
+      }
+      Long timeout = 
ClientProperty.BATCH_WRITER_MAX_TIMEOUT_SEC.getLong(props);
+      if (timeout != null) {
+        batchWriterConfig.setTimeout(timeout, TimeUnit.SECONDS);
+      }
+      String durability = 
ClientProperty.BATCH_WRITER_DURABILITY.getValue(props);
+      if (!durability.isEmpty()) {
+        
batchWriterConfig.setDurability(Durability.valueOf(durability.toUpperCase()));
+      }
     }
     return batchWriterConfig;
   }
diff --git 
a/core/src/main/java/org/apache/accumulo/core/client/impl/ClientInfoFactory.java
 
b/core/src/main/java/org/apache/accumulo/core/client/impl/ClientInfoFactory.java
deleted file mode 100644
index 9c40b03d99..0000000000
--- 
a/core/src/main/java/org/apache/accumulo/core/client/impl/ClientInfoFactory.java
+++ /dev/null
@@ -1,59 +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.accumulo.core.client.impl;
-
-import java.util.concurrent.TimeUnit;
-
-import org.apache.accumulo.core.client.BatchWriterConfig;
-import org.apache.accumulo.core.client.ClientInfo;
-import org.apache.accumulo.core.client.Durability;
-import org.apache.accumulo.core.conf.ClientProperty;
-
-/**
- * Creates internal objects using {@link ClientInfo}
- */
-public class ClientInfoFactory {
-
-  public static String getString(ClientInfo info, ClientProperty property) {
-    return property.getValue(info.getProperties());
-  }
-
-  public static Long getLong(ClientInfo info, ClientProperty property) {
-    return property.getLong(info.getProperties());
-  }
-
-  public static BatchWriterConfig getBatchWriterConfig(ClientInfo info) {
-    BatchWriterConfig batchWriterConfig = new BatchWriterConfig();
-    Long maxMemory = getLong(info, 
ClientProperty.BATCH_WRITER_MAX_MEMORY_BYTES);
-    if (maxMemory != null) {
-      batchWriterConfig.setMaxMemory(maxMemory);
-    }
-    Long maxLatency = getLong(info, 
ClientProperty.BATCH_WRITER_MAX_LATENCY_SEC);
-    if (maxLatency != null) {
-      batchWriterConfig.setMaxLatency(maxLatency, TimeUnit.SECONDS);
-    }
-    Long timeout = getLong(info, ClientProperty.BATCH_WRITER_MAX_TIMEOUT_SEC);
-    if (timeout != null) {
-      batchWriterConfig.setTimeout(timeout, TimeUnit.SECONDS);
-    }
-    String durability = getString(info, 
ClientProperty.BATCH_WRITER_DURABILITY);
-    if (!durability.isEmpty()) {
-      
batchWriterConfig.setDurability(Durability.valueOf(durability.toUpperCase()));
-    }
-    return batchWriterConfig;
-  }
-}
diff --git 
a/core/src/main/java/org/apache/accumulo/core/client/impl/ClientInfoImpl.java 
b/core/src/main/java/org/apache/accumulo/core/client/impl/ClientInfoImpl.java
index ad9b001625..ff4cccafd5 100644
--- 
a/core/src/main/java/org/apache/accumulo/core/client/impl/ClientInfoImpl.java
+++ 
b/core/src/main/java/org/apache/accumulo/core/client/impl/ClientInfoImpl.java
@@ -70,9 +70,7 @@ public String getPrincipal() {
   @Override
   public Properties getProperties() {
     Properties result = new Properties();
-    properties.forEach((key, value) -> {
-      result.setProperty((String) key, (String) value);
-    });
+    properties.forEach((key, value) -> result.setProperty((String) key, 
(String) value));
     return result;
   }
 
diff --git 
a/test/src/main/java/org/apache/accumulo/test/functional/AccumuloClientIT.java 
b/test/src/main/java/org/apache/accumulo/test/functional/AccumuloClientIT.java
index 71d4820555..487cdca7da 100644
--- 
a/test/src/main/java/org/apache/accumulo/test/functional/AccumuloClientIT.java
+++ 
b/test/src/main/java/org/apache/accumulo/test/functional/AccumuloClientIT.java
@@ -45,7 +45,7 @@
 
 public class AccumuloClientIT extends AccumuloClusterHarness {
 
-  private static interface CloseCheck {
+  private interface CloseCheck {
     void check() throws Exception;
   }
 
@@ -69,11 +69,11 @@ public void testGetConnectorFromAccumuloClient() throws 
Exception {
     // this should cause the connector to stop functioning
     client.close();
 
-    expectClosed(() -> c.tableOperations());
+    expectClosed(c::tableOperations);
   }
 
   @Test
-  public void testclientectorBuilder() throws Exception {
+  public void testAccumuloClientBuilder() throws Exception {
     AccumuloClient c = getAccumuloClient();
     String instanceName = c.info().getInstanceName();
     String zookeepers = c.info().getZooKeepers();


 

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


With regards,
Apache Git Services

Reply via email to