Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id CEC0E200C32 for ; Thu, 9 Mar 2017 20:55:27 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id CD4F4160B75; Thu, 9 Mar 2017 19:55:27 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id F1E1F160B5F for ; Thu, 9 Mar 2017 20:55:26 +0100 (CET) Received: (qmail 8633 invoked by uid 500); 9 Mar 2017 19:55:26 -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 8624 invoked by uid 99); 9 Mar 2017 19:55:26 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Mar 2017 19:55:26 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1875FDFE1E; Thu, 9 Mar 2017 19:55:26 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mmiller@apache.org To: commits@accumulo.apache.org Message-Id: <12a39ac5abfc46d0849acecd5396d211@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: accumulo git commit: ACCUMULO-4600: Fix to properly read from accumulo-site.xml Date: Thu, 9 Mar 2017 19:55:26 +0000 (UTC) archived-at: Thu, 09 Mar 2017 19:55:28 -0000 Repository: accumulo Updated Branches: refs/heads/1.7 de80cf53b -> 80373557b ACCUMULO-4600: Fix to properly read from accumulo-site.xml Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/80373557 Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/80373557 Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/80373557 Branch: refs/heads/1.7 Commit: 80373557b4d39c10b3dd62dca5d13d7ed0290b5d Parents: de80cf5 Author: Mike Miller Authored: Wed Mar 8 16:12:48 2017 -0500 Committer: Mike Miller Committed: Thu Mar 9 14:38:40 2017 -0500 ---------------------------------------------------------------------- .../java/org/apache/accumulo/shell/Shell.java | 10 ++++--- .../apache/accumulo/shell/ShellConfigTest.java | 25 ++++++----------- shell/src/test/resources/accumulo-site.xml | 28 ++++++++++++++++++++ 3 files changed, 42 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/80373557/shell/src/main/java/org/apache/accumulo/shell/Shell.java ---------------------------------------------------------------------- diff --git a/shell/src/main/java/org/apache/accumulo/shell/Shell.java b/shell/src/main/java/org/apache/accumulo/shell/Shell.java index 9dc69c5..ccb12a0 100644 --- a/shell/src/main/java/org/apache/accumulo/shell/Shell.java +++ b/shell/src/main/java/org/apache/accumulo/shell/Shell.java @@ -60,6 +60,7 @@ import org.apache.accumulo.core.client.security.tokens.AuthenticationToken; import org.apache.accumulo.core.client.security.tokens.PasswordToken; import org.apache.accumulo.core.conf.AccumuloConfiguration; import org.apache.accumulo.core.conf.Property; +import org.apache.accumulo.core.conf.SiteConfiguration; import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Value; import org.apache.accumulo.core.data.thrift.TConstraintViolationSummary; @@ -470,7 +471,7 @@ public class Shell extends ShellOptions implements KeywordExecutable { * ClientConfiguration instance * @return The ZooKeepers to connect to */ - static String getZooKeepers(String keepers, ClientConfiguration clientConfig, AccumuloConfiguration conf) { + static String getZooKeepers(String keepers, ClientConfiguration clientConfig) { if (null != keepers) { return keepers; } @@ -479,7 +480,7 @@ public class Shell extends ShellOptions implements KeywordExecutable { return clientConfig.get(ClientProperty.INSTANCE_ZK_HOST); } - return conf.get(Property.INSTANCE_ZK_HOST); + return SiteConfiguration.getInstance(ClientContext.convertClientConfig(clientConfig)).get(Property.INSTANCE_ZK_HOST); } /* @@ -491,9 +492,10 @@ public class Shell extends ShellOptions implements KeywordExecutable { if (instanceName == null) { instanceName = clientConfig.get(ClientProperty.INSTANCE_NAME); } - AccumuloConfiguration conf = ClientContext.convertClientConfig(clientConfig); - String keepers = getZooKeepers(keepersOption, clientConfig, conf); + + String keepers = getZooKeepers(keepersOption, clientConfig); if (instanceName == null) { + AccumuloConfiguration conf = SiteConfiguration.getInstance(ClientContext.convertClientConfig(clientConfig)); Path instanceDir = new Path(VolumeConfiguration.getVolumeUris(conf)[0], "instance_id"); instanceId = UUID.fromString(ZooUtil.getInstanceIDFromHdfs(instanceDir, conf)); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/80373557/shell/src/test/java/org/apache/accumulo/shell/ShellConfigTest.java ---------------------------------------------------------------------- diff --git a/shell/src/test/java/org/apache/accumulo/shell/ShellConfigTest.java b/shell/src/test/java/org/apache/accumulo/shell/ShellConfigTest.java index 49f22a6..7b9f72f 100644 --- a/shell/src/test/java/org/apache/accumulo/shell/ShellConfigTest.java +++ b/shell/src/test/java/org/apache/accumulo/shell/ShellConfigTest.java @@ -27,16 +27,11 @@ import java.io.IOException; import java.io.PrintStream; import java.io.PrintWriter; import java.nio.file.Files; -import java.util.HashMap; -import java.util.Map; import jline.console.ConsoleReader; import org.apache.accumulo.core.client.ClientConfiguration; import org.apache.accumulo.core.client.security.tokens.PasswordToken; -import org.apache.accumulo.core.conf.AccumuloConfiguration; -import org.apache.accumulo.core.conf.ConfigurationCopy; -import org.apache.accumulo.core.conf.Property; import org.apache.accumulo.shell.ShellTest.TestOutputStream; import org.apache.log4j.Level; import org.junit.After; @@ -120,32 +115,28 @@ public class ShellConfigTest { assertTrue(output.get().contains(ParameterException.class.getName())); } + /** + * Tests getting the ZK hosts config value will fail on String parameter, client config and then fall back to Site configuration. SiteConfiguration will get + * the accumulo-site.xml from the classpath in src/test/resources + */ @Test public void testZooKeeperHostFallBackToSite() throws Exception { ClientConfiguration clientConfig = new ClientConfiguration(); - Map data = new HashMap<>(); - data.put(Property.INSTANCE_ZK_HOST.getKey(), "site_hostname"); - AccumuloConfiguration conf = new ConfigurationCopy(data); - assertEquals("site_hostname", Shell.getZooKeepers(null, clientConfig, conf)); + assertFalse("Client config contains zk hosts", clientConfig.containsKey(ClientConfiguration.ClientProperty.INSTANCE_ZK_HOST.getKey())); + assertEquals("ShellConfigTestZKHostValue", Shell.getZooKeepers(null, clientConfig)); } @Test public void testZooKeeperHostFromClientConfig() throws Exception { ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.withZkHosts("cc_hostname"); - Map data = new HashMap<>(); - data.put(Property.INSTANCE_ZK_HOST.getKey(), "site_hostname"); - AccumuloConfiguration conf = new ConfigurationCopy(data); - assertEquals("cc_hostname", Shell.getZooKeepers(null, clientConfig, conf)); + assertEquals("cc_hostname", Shell.getZooKeepers(null, clientConfig)); } @Test public void testZooKeeperHostFromOption() throws Exception { ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.withZkHosts("cc_hostname"); - Map data = new HashMap<>(); - data.put(Property.INSTANCE_ZK_HOST.getKey(), "site_hostname"); - AccumuloConfiguration conf = new ConfigurationCopy(data); - assertEquals("opt_hostname", Shell.getZooKeepers("opt_hostname", clientConfig, conf)); + assertEquals("opt_hostname", Shell.getZooKeepers("opt_hostname", clientConfig)); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/80373557/shell/src/test/resources/accumulo-site.xml ---------------------------------------------------------------------- diff --git a/shell/src/test/resources/accumulo-site.xml b/shell/src/test/resources/accumulo-site.xml new file mode 100644 index 0000000..b468957 --- /dev/null +++ b/shell/src/test/resources/accumulo-site.xml @@ -0,0 +1,28 @@ + + + + + + + + + instance.zookeeper.host + ShellConfigTestZKHostValue + + +