From 82fc0f1855cd187adc99c6643e0ad35c82678a2c Mon Sep 17 00:00:00 2001 From: Sanford Ryza Date: Wed, 28 Aug 2013 18:03:37 +0000 Subject: [PATCH] Adding and removing files missed for HADOOP-9906 git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1518306 13f79535-47bb-0310-9956-ffa450edef68 --- .../{ha/HAZKUtil.java => util/ZKUtil.java} | 31 ++++++++++------- .../TestZKUtil.java} | 33 ++++++++++--------- 2 files changed, 36 insertions(+), 28 deletions(-) rename hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/{ha/HAZKUtil.java => util/ZKUtil.java} (88%) rename hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/{ha/TestHAZKUtil.java => util/TestZKUtil.java} (82%) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAZKUtil.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ZKUtil.java similarity index 88% rename from hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAZKUtil.java rename to hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ZKUtil.java index 093b878bd14..bd08efb5cda 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAZKUtil.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ZKUtil.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.hadoop.ha; +package org.apache.hadoop.util; import java.io.File; import java.io.IOException; @@ -36,7 +36,7 @@ import com.google.common.io.Files; * Utilities for working with ZooKeeper. */ @InterfaceAudience.Private -public class HAZKUtil { +public class ZKUtil { /** * Parse ACL permission string, partially borrowed from @@ -76,9 +76,10 @@ public class HAZKUtil { * sasl:hdfs/host1@MY.DOMAIN:cdrwa,sasl:hdfs/host2@MY.DOMAIN:cdrwa * * @return ACL list - * @throws HadoopIllegalArgumentException if an ACL is invalid + * @throws {@link BadAclFormatException} if an ACL is invalid */ - public static List parseACLs(String aclString) { + public static List parseACLs(String aclString) throws + BadAclFormatException { List acl = Lists.newArrayList(); if (aclString == null) { return acl; @@ -113,8 +114,10 @@ public class HAZKUtil { * * @param authString the comma-separated auth mechanisms * @return a list of parsed authentications + * @throws {@link BadAuthFormatException} if the auth format is invalid */ - public static List parseAuth(String authString) { + public static List parseAuth(String authString) throws + BadAuthFormatException{ List ret = Lists.newArrayList(); if (authString == null) { return ret; @@ -161,7 +164,8 @@ public class HAZKUtil { /** * An authentication token passed to ZooKeeper.addAuthInfo */ - static class ZKAuthInfo { + @InterfaceAudience.Private + public static class ZKAuthInfo { private final String scheme; private final byte[] auth; @@ -171,29 +175,32 @@ public class HAZKUtil { this.auth = auth; } - String getScheme() { + public String getScheme() { return scheme; } - byte[] getAuth() { + public byte[] getAuth() { return auth; } } - static class BadAclFormatException extends HadoopIllegalArgumentException { + @InterfaceAudience.Private + public static class BadAclFormatException extends + HadoopIllegalArgumentException { private static final long serialVersionUID = 1L; public BadAclFormatException(String message) { super(message); } } - - static class BadAuthFormatException extends HadoopIllegalArgumentException { + + @InterfaceAudience.Private + public static class BadAuthFormatException extends + HadoopIllegalArgumentException { private static final long serialVersionUID = 1L; public BadAuthFormatException(String message) { super(message); } } - } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestHAZKUtil.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestZKUtil.java similarity index 82% rename from hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestHAZKUtil.java rename to hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestZKUtil.java index 90371f3730f..1d14326d2ab 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestHAZKUtil.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestZKUtil.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.hadoop.ha; +package org.apache.hadoop.util; import static org.junit.Assert.*; @@ -24,8 +24,9 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.List; -import org.apache.hadoop.ha.HAZKUtil.BadAclFormatException; -import org.apache.hadoop.ha.HAZKUtil.ZKAuthInfo; +import org.apache.hadoop.util.ZKUtil; +import org.apache.hadoop.util.ZKUtil.BadAclFormatException; +import org.apache.hadoop.util.ZKUtil.ZKAuthInfo; import org.apache.zookeeper.ZooDefs.Perms; import org.apache.zookeeper.data.ACL; import org.junit.Test; @@ -33,9 +34,9 @@ import org.junit.Test; import com.google.common.base.Charsets; import com.google.common.io.Files; -public class TestHAZKUtil { +public class TestZKUtil { private static final String TEST_ROOT_DIR = System.getProperty( - "test.build.data", "/tmp") + "/TestHAZKUtil"; + "test.build.data", "/tmp") + "/TestZKUtil"; private static final File TEST_FILE = new File(TEST_ROOT_DIR, "test-file"); @@ -45,13 +46,13 @@ public class TestHAZKUtil { @Test public void testEmptyACL() { - List result = HAZKUtil.parseACLs(""); + List result = ZKUtil.parseACLs(""); assertTrue(result.isEmpty()); } @Test public void testNullACL() { - List result = HAZKUtil.parseACLs(null); + List result = ZKUtil.parseACLs(null); assertTrue(result.isEmpty()); } @@ -67,7 +68,7 @@ public class TestHAZKUtil { private static void badAcl(String acls, String expectedErr) { try { - HAZKUtil.parseACLs(acls); + ZKUtil.parseACLs(acls); fail("Should have failed to parse '" + acls + "'"); } catch (BadAclFormatException e) { assertEquals(expectedErr, e.getMessage()); @@ -76,7 +77,7 @@ public class TestHAZKUtil { @Test public void testGoodACLs() { - List result = HAZKUtil.parseACLs( + List result = ZKUtil.parseACLs( "sasl:hdfs/host1@MY.DOMAIN:cdrwa, sasl:hdfs/host2@MY.DOMAIN:ca"); ACL acl0 = result.get(0); assertEquals(Perms.CREATE | Perms.DELETE | Perms.READ | @@ -92,19 +93,19 @@ public class TestHAZKUtil { @Test public void testEmptyAuth() { - List result = HAZKUtil.parseAuth(""); + List result = ZKUtil.parseAuth(""); assertTrue(result.isEmpty()); } @Test public void testNullAuth() { - List result = HAZKUtil.parseAuth(null); + List result = ZKUtil.parseAuth(null); assertTrue(result.isEmpty()); } @Test public void testGoodAuths() { - List result = HAZKUtil.parseAuth( + List result = ZKUtil.parseAuth( "scheme:data,\n scheme2:user:pass"); assertEquals(2, result.size()); ZKAuthInfo auth0 = result.get(0); @@ -118,16 +119,16 @@ public class TestHAZKUtil { @Test public void testConfIndirection() throws IOException { - assertNull(HAZKUtil.resolveConfIndirection(null)); - assertEquals("x", HAZKUtil.resolveConfIndirection("x")); + assertNull(ZKUtil.resolveConfIndirection(null)); + assertEquals("x", ZKUtil.resolveConfIndirection("x")); TEST_FILE.getParentFile().mkdirs(); Files.write("hello world", TEST_FILE, Charsets.UTF_8); - assertEquals("hello world", HAZKUtil.resolveConfIndirection( + assertEquals("hello world", ZKUtil.resolveConfIndirection( "@" + TEST_FILE.getAbsolutePath())); try { - HAZKUtil.resolveConfIndirection("@" + BOGUS_FILE); + ZKUtil.resolveConfIndirection("@" + BOGUS_FILE); fail("Did not throw for non-existent file reference"); } catch (FileNotFoundException fnfe) { assertTrue(fnfe.getMessage().startsWith(BOGUS_FILE));