accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mwa...@apache.org
Subject [accumulo] branch master updated: Fixes #533 - Create scanners with default user auths (#744)
Date Fri, 02 Nov 2018 20:45:03 GMT
This is an automated email from the ASF dual-hosted git repository.

mwalch pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/master by this push:
     new 18e3266  Fixes #533 - Create scanners with default user auths (#744)
18e3266 is described below

commit 18e32663d9ecbf04f6f2aa57b2400a403ce2ed62
Author: Mike Walch <mwalch@apache.org>
AuthorDate: Fri Nov 2 16:44:57 2018 -0400

    Fixes #533 - Create scanners with default user auths (#744)
---
 .../accumulo/core/client/AccumuloClient.java       | 28 ++++++++++
 .../core/client/impl/AccumuloClientImpl.java       | 14 +++++
 .../accumulo/core/client/impl/ClientContext.java   | 21 +++++++-
 .../core/client/impl/ClientInfoFactory.java        | 59 ----------------------
 .../accumulo/core/client/impl/ClientInfoImpl.java  |  4 +-
 .../accumulo/test/functional/AccumuloClientIT.java |  6 +--
 6 files changed, 66 insertions(+), 66 deletions(-)

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 e7f6a4b..359419c 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
@@ -100,6 +100,20 @@ public interface AccumuloClient extends AutoCloseable {
       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
    *
    * @param tableName
@@ -212,6 +226,20 @@ public interface AccumuloClient extends AutoCloseable {
       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.
    *
    * @param tableName
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 8a6ce3e..eaf0d8d 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
@@ -126,6 +126,13 @@ public class AccumuloClientImpl implements AccumuloClient {
   }
 
   @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 {
     checkArgument(tableName != null, "tableName is null");
@@ -194,6 +201,13 @@ public class AccumuloClientImpl implements AccumuloClient {
   }
 
   @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();
     return context.getCredentials().getPrincipal();
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 cd18f50..3c63cda 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.AccumuloException;
 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 class ClientContext {
   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 9c40b03..0000000
--- 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 ad9b001..ff4ccca 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 class ClientInfoImpl implements ClientInfo {
   @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 71d4820..487cdca 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 @@ import com.google.common.collect.Iterables;
 
 public class AccumuloClientIT extends AccumuloClusterHarness {
 
-  private static interface CloseCheck {
+  private interface CloseCheck {
     void check() throws Exception;
   }
 
@@ -69,11 +69,11 @@ public class AccumuloClientIT extends AccumuloClusterHarness {
     // 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();


Mime
View raw message