From commits-return-22298-archive-asf-public=cust-asf.ponee.io@accumulo.apache.org Fri Nov 2 21:45:05 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id A2A0418062B for ; Fri, 2 Nov 2018 21:45:04 +0100 (CET) Received: (qmail 4501 invoked by uid 500); 2 Nov 2018 20:45:03 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 4492 invoked by uid 99); 2 Nov 2018 20:45:03 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Nov 2018 20:45:03 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 1E17E87139; Fri, 2 Nov 2018 20:45:03 +0000 (UTC) Date: Fri, 02 Nov 2018 20:45:03 +0000 To: "commits@accumulo.apache.org" Subject: [accumulo] branch master updated: Fixes #533 - Create scanners with default user auths (#744) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <154119150302.4026.2802596924311385512@gitbox.apache.org> From: mwalch@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: accumulo X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: f22067517691c88dac390e1aa7fc9fe3f398c4f0 X-Git-Newrev: 18e32663d9ecbf04f6f2aa57b2400a403ce2ed62 X-Git-Rev: 18e32663d9ecbf04f6f2aa57b2400a403ce2ed62 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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 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();