You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by el...@apache.org on 2015/10/19 00:58:56 UTC
[2/8] accumulo git commit: ACCUMULO-4027 Convert the value of
ACCUMULO_CLIENT_CONF_PATH to a file if it's a directory.
ACCUMULO-4027 Convert the value of ACCUMULO_CLIENT_CONF_PATH to a file if it's a directory.
The value of this variable is expected to be an Accumulo ClientConfiguration file.
If it's a directory which happens to contain this file, it is silently ignored. We
can try to correct this automatically for users.
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/3f1346c5
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/3f1346c5
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/3f1346c5
Branch: refs/heads/1.7
Commit: 3f1346c5f39245bf959647dba1549227e954f171
Parents: 1ab3827
Author: Josh Elser <el...@apache.org>
Authored: Sun Oct 18 18:19:20 2015 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Sun Oct 18 18:30:41 2015 -0400
----------------------------------------------------------------------
.../core/client/ClientConfiguration.java | 21 ++++-
.../core/client/ClientConfigurationTest.java | 96 ++++++++++++++++++++
.../core/conf/ClientConfigurationTest.java | 66 --------------
3 files changed, 116 insertions(+), 67 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/3f1346c5/core/src/main/java/org/apache/accumulo/core/client/ClientConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/ClientConfiguration.java b/core/src/main/java/org/apache/accumulo/core/client/ClientConfiguration.java
index 8593d9e..6bccc09 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/ClientConfiguration.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/ClientConfiguration.java
@@ -170,8 +170,27 @@ public class ClientConfiguration extends CompositeConfiguration {
return new ClientConfiguration(propConfig);
}
+ /**
+ * Muck the value of {@code clientConfPath} if it points to a directory by appending
+ * {@code client.conf} to the end of the file path. This is a no-op if the value is not a
+ * directory on the filesystem.
+ *
+ * @param clientConfPath The value of ACCUMULO_CLIENT_CONF_PATH.
+ */
+ static String getClientConfPath(String clientConfPath) {
+ if (null == clientConfPath) {
+ return null;
+ }
+ File filePath = new File(clientConfPath);
+ // If clientConfPath is a directory, tack on the default client.conf file name.
+ if (filePath.exists() && filePath.isDirectory()) {
+ return new File(filePath, "client.conf").toString();
+ }
+ return clientConfPath;
+ }
+
private static List<String> getDefaultSearchPath() {
- String clientConfSearchPath = System.getenv("ACCUMULO_CLIENT_CONF_PATH");
+ String clientConfSearchPath = getClientConfPath(System.getenv("ACCUMULO_CLIENT_CONF_PATH"));
List<String> clientConfPaths;
if (clientConfSearchPath != null) {
clientConfPaths = Arrays.asList(clientConfSearchPath.split(File.pathSeparator));
http://git-wip-us.apache.org/repos/asf/accumulo/blob/3f1346c5/core/src/test/java/org/apache/accumulo/core/client/ClientConfigurationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/client/ClientConfigurationTest.java b/core/src/test/java/org/apache/accumulo/core/client/ClientConfigurationTest.java
new file mode 100644
index 0000000..81918cc
--- /dev/null
+++ b/core/src/test/java/org/apache/accumulo/core/client/ClientConfigurationTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.apache.accumulo.core.client.ClientConfiguration;
+import org.apache.accumulo.core.client.ClientConfiguration.ClientProperty;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.junit.Test;
+
+public class ClientConfigurationTest {
+ @Test
+ public void testOverrides() throws Exception {
+ ClientConfiguration clientConfig = createConfig();
+ assertExpectedConfig(clientConfig);
+ }
+
+ @Test
+ public void testSerialization() throws Exception {
+ ClientConfiguration clientConfig = createConfig();
+ // sanity check that we're starting with what we're expecting
+ assertExpectedConfig(clientConfig);
+
+ String serialized = clientConfig.serialize();
+ ClientConfiguration deserializedClientConfig = ClientConfiguration.deserialize(serialized);
+ assertExpectedConfig(deserializedClientConfig);
+ }
+
+ private void assertExpectedConfig(ClientConfiguration clientConfig) {
+ assertEquals("firstZkHosts", clientConfig.get(ClientProperty.INSTANCE_ZK_HOST));
+ assertEquals("secondInstanceName", clientConfig.get(ClientProperty.INSTANCE_NAME));
+ assertEquals("123s", clientConfig.get(ClientProperty.INSTANCE_ZK_TIMEOUT));
+ assertEquals(ClientProperty.RPC_SSL_TRUSTSTORE_TYPE.getDefaultValue(), clientConfig.get(ClientProperty.RPC_SSL_TRUSTSTORE_TYPE));
+ }
+
+ private ClientConfiguration createConfig() {
+ Configuration first = new PropertiesConfiguration();
+ first.addProperty(ClientProperty.INSTANCE_ZK_HOST.getKey(), "firstZkHosts");
+ Configuration second = new PropertiesConfiguration();
+ second.addProperty(ClientProperty.INSTANCE_ZK_HOST.getKey(), "secondZkHosts");
+ second.addProperty(ClientProperty.INSTANCE_NAME.getKey(), "secondInstanceName");
+ Configuration third = new PropertiesConfiguration();
+ third.addProperty(ClientProperty.INSTANCE_ZK_HOST.getKey(), "thirdZkHosts");
+ third.addProperty(ClientProperty.INSTANCE_NAME.getKey(), "thirdInstanceName");
+ third.addProperty(ClientProperty.INSTANCE_ZK_TIMEOUT.getKey(), "123s");
+ return new ClientConfiguration(Arrays.asList(first, second, third));
+ }
+
+ @Test
+ public void testConfPath() throws IOException {
+ File target = new File(System.getProperty("user.dir"), "target");
+ assertTrue("'target' build directory does not exist", target.exists());
+ File testDir = new File(target, getClass().getName());
+ if (!testDir.exists()) {
+ assertTrue("Failed to create test dir " + testDir, testDir.mkdirs());
+ }
+
+ File clientConf = new File(testDir, "client.conf");
+ if (!clientConf.exists()) {
+ assertTrue("Failed to create file " + clientConf, clientConf.createNewFile());
+ }
+
+ // A directory should return the path with client.conf appended.
+ assertEquals(clientConf.toString(), ClientConfiguration.getClientConfPath(testDir.toString()));
+ // A normal file should return itself
+ assertEquals(clientConf.toString(), ClientConfiguration.getClientConfPath(clientConf.toString()));
+
+ // Something that doesn't exist should return itself (specifially, it shouldn't error)
+ final File missing = new File("foobarbaz12332112");
+ assertEquals(missing.toString(), ClientConfiguration.getClientConfPath(missing.toString()));
+
+ assertNull(ClientConfiguration.getClientConfPath(null));
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/3f1346c5/core/src/test/java/org/apache/accumulo/core/conf/ClientConfigurationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/conf/ClientConfigurationTest.java b/core/src/test/java/org/apache/accumulo/core/conf/ClientConfigurationTest.java
deleted file mode 100644
index 40be70f..0000000
--- a/core/src/test/java/org/apache/accumulo/core/conf/ClientConfigurationTest.java
+++ /dev/null
@@ -1,66 +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.conf;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.Arrays;
-
-import org.apache.accumulo.core.client.ClientConfiguration;
-import org.apache.accumulo.core.client.ClientConfiguration.ClientProperty;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.junit.Test;
-
-public class ClientConfigurationTest {
- @Test
- public void testOverrides() throws Exception {
- ClientConfiguration clientConfig = createConfig();
- assertExpectedConfig(clientConfig);
- }
-
- @Test
- public void testSerialization() throws Exception {
- ClientConfiguration clientConfig = createConfig();
- // sanity check that we're starting with what we're expecting
- assertExpectedConfig(clientConfig);
-
- String serialized = clientConfig.serialize();
- ClientConfiguration deserializedClientConfig = ClientConfiguration.deserialize(serialized);
- assertExpectedConfig(deserializedClientConfig);
- }
-
- private void assertExpectedConfig(ClientConfiguration clientConfig) {
- assertEquals("firstZkHosts", clientConfig.get(ClientProperty.INSTANCE_ZK_HOST));
- assertEquals("secondInstanceName", clientConfig.get(ClientProperty.INSTANCE_NAME));
- assertEquals("123s", clientConfig.get(ClientProperty.INSTANCE_ZK_TIMEOUT));
- assertEquals(ClientProperty.RPC_SSL_TRUSTSTORE_TYPE.getDefaultValue(), clientConfig.get(ClientProperty.RPC_SSL_TRUSTSTORE_TYPE));
- }
-
- private ClientConfiguration createConfig() {
- Configuration first = new PropertiesConfiguration();
- first.addProperty(ClientProperty.INSTANCE_ZK_HOST.getKey(), "firstZkHosts");
- Configuration second = new PropertiesConfiguration();
- second.addProperty(ClientProperty.INSTANCE_ZK_HOST.getKey(), "secondZkHosts");
- second.addProperty(ClientProperty.INSTANCE_NAME.getKey(), "secondInstanceName");
- Configuration third = new PropertiesConfiguration();
- third.addProperty(ClientProperty.INSTANCE_ZK_HOST.getKey(), "thirdZkHosts");
- third.addProperty(ClientProperty.INSTANCE_NAME.getKey(), "thirdInstanceName");
- third.addProperty(ClientProperty.INSTANCE_ZK_TIMEOUT.getKey(), "123s");
- return new ClientConfiguration(Arrays.asList(first, second, third));
- }
-}