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
This commit is contained in:
Sanford Ryza 2013-08-28 18:03:37 +00:00
parent f3c0074030
commit 82fc0f1855
2 changed files with 36 additions and 28 deletions

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.hadoop.ha; package org.apache.hadoop.util;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -36,7 +36,7 @@ import com.google.common.io.Files;
* Utilities for working with ZooKeeper. * Utilities for working with ZooKeeper.
*/ */
@InterfaceAudience.Private @InterfaceAudience.Private
public class HAZKUtil { public class ZKUtil {
/** /**
* Parse ACL permission string, partially borrowed from * Parse ACL permission string, partially borrowed from
@ -76,9 +76,10 @@ public class HAZKUtil {
* <code>sasl:hdfs/host1@MY.DOMAIN:cdrwa,sasl:hdfs/host2@MY.DOMAIN:cdrwa</code> * <code>sasl:hdfs/host1@MY.DOMAIN:cdrwa,sasl:hdfs/host2@MY.DOMAIN:cdrwa</code>
* *
* @return ACL list * @return ACL list
* @throws HadoopIllegalArgumentException if an ACL is invalid * @throws {@link BadAclFormatException} if an ACL is invalid
*/ */
public static List<ACL> parseACLs(String aclString) { public static List<ACL> parseACLs(String aclString) throws
BadAclFormatException {
List<ACL> acl = Lists.newArrayList(); List<ACL> acl = Lists.newArrayList();
if (aclString == null) { if (aclString == null) {
return acl; return acl;
@ -113,8 +114,10 @@ public class HAZKUtil {
* *
* @param authString the comma-separated auth mechanisms * @param authString the comma-separated auth mechanisms
* @return a list of parsed authentications * @return a list of parsed authentications
* @throws {@link BadAuthFormatException} if the auth format is invalid
*/ */
public static List<ZKAuthInfo> parseAuth(String authString) { public static List<ZKAuthInfo> parseAuth(String authString) throws
BadAuthFormatException{
List<ZKAuthInfo> ret = Lists.newArrayList(); List<ZKAuthInfo> ret = Lists.newArrayList();
if (authString == null) { if (authString == null) {
return ret; return ret;
@ -161,7 +164,8 @@ public class HAZKUtil {
/** /**
* An authentication token passed to ZooKeeper.addAuthInfo * An authentication token passed to ZooKeeper.addAuthInfo
*/ */
static class ZKAuthInfo { @InterfaceAudience.Private
public static class ZKAuthInfo {
private final String scheme; private final String scheme;
private final byte[] auth; private final byte[] auth;
@ -171,29 +175,32 @@ public class HAZKUtil {
this.auth = auth; this.auth = auth;
} }
String getScheme() { public String getScheme() {
return scheme; return scheme;
} }
byte[] getAuth() { public byte[] getAuth() {
return auth; return auth;
} }
} }
static class BadAclFormatException extends HadoopIllegalArgumentException { @InterfaceAudience.Private
public static class BadAclFormatException extends
HadoopIllegalArgumentException {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public BadAclFormatException(String message) { public BadAclFormatException(String message) {
super(message); super(message);
} }
} }
static class BadAuthFormatException extends HadoopIllegalArgumentException { @InterfaceAudience.Private
public static class BadAuthFormatException extends
HadoopIllegalArgumentException {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public BadAuthFormatException(String message) { public BadAuthFormatException(String message) {
super(message); super(message);
} }
} }
} }

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.hadoop.ha; package org.apache.hadoop.util;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -24,8 +24,9 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import org.apache.hadoop.ha.HAZKUtil.BadAclFormatException; import org.apache.hadoop.util.ZKUtil;
import org.apache.hadoop.ha.HAZKUtil.ZKAuthInfo; import org.apache.hadoop.util.ZKUtil.BadAclFormatException;
import org.apache.hadoop.util.ZKUtil.ZKAuthInfo;
import org.apache.zookeeper.ZooDefs.Perms; import org.apache.zookeeper.ZooDefs.Perms;
import org.apache.zookeeper.data.ACL; import org.apache.zookeeper.data.ACL;
import org.junit.Test; import org.junit.Test;
@ -33,9 +34,9 @@ import org.junit.Test;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.io.Files; import com.google.common.io.Files;
public class TestHAZKUtil { public class TestZKUtil {
private static final String TEST_ROOT_DIR = System.getProperty( 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, private static final File TEST_FILE = new File(TEST_ROOT_DIR,
"test-file"); "test-file");
@ -45,13 +46,13 @@ public class TestHAZKUtil {
@Test @Test
public void testEmptyACL() { public void testEmptyACL() {
List<ACL> result = HAZKUtil.parseACLs(""); List<ACL> result = ZKUtil.parseACLs("");
assertTrue(result.isEmpty()); assertTrue(result.isEmpty());
} }
@Test @Test
public void testNullACL() { public void testNullACL() {
List<ACL> result = HAZKUtil.parseACLs(null); List<ACL> result = ZKUtil.parseACLs(null);
assertTrue(result.isEmpty()); assertTrue(result.isEmpty());
} }
@ -67,7 +68,7 @@ public class TestHAZKUtil {
private static void badAcl(String acls, String expectedErr) { private static void badAcl(String acls, String expectedErr) {
try { try {
HAZKUtil.parseACLs(acls); ZKUtil.parseACLs(acls);
fail("Should have failed to parse '" + acls + "'"); fail("Should have failed to parse '" + acls + "'");
} catch (BadAclFormatException e) { } catch (BadAclFormatException e) {
assertEquals(expectedErr, e.getMessage()); assertEquals(expectedErr, e.getMessage());
@ -76,7 +77,7 @@ public class TestHAZKUtil {
@Test @Test
public void testGoodACLs() { public void testGoodACLs() {
List<ACL> result = HAZKUtil.parseACLs( List<ACL> result = ZKUtil.parseACLs(
"sasl:hdfs/host1@MY.DOMAIN:cdrwa, sasl:hdfs/host2@MY.DOMAIN:ca"); "sasl:hdfs/host1@MY.DOMAIN:cdrwa, sasl:hdfs/host2@MY.DOMAIN:ca");
ACL acl0 = result.get(0); ACL acl0 = result.get(0);
assertEquals(Perms.CREATE | Perms.DELETE | Perms.READ | assertEquals(Perms.CREATE | Perms.DELETE | Perms.READ |
@ -92,19 +93,19 @@ public class TestHAZKUtil {
@Test @Test
public void testEmptyAuth() { public void testEmptyAuth() {
List<ZKAuthInfo> result = HAZKUtil.parseAuth(""); List<ZKAuthInfo> result = ZKUtil.parseAuth("");
assertTrue(result.isEmpty()); assertTrue(result.isEmpty());
} }
@Test @Test
public void testNullAuth() { public void testNullAuth() {
List<ZKAuthInfo> result = HAZKUtil.parseAuth(null); List<ZKAuthInfo> result = ZKUtil.parseAuth(null);
assertTrue(result.isEmpty()); assertTrue(result.isEmpty());
} }
@Test @Test
public void testGoodAuths() { public void testGoodAuths() {
List<ZKAuthInfo> result = HAZKUtil.parseAuth( List<ZKAuthInfo> result = ZKUtil.parseAuth(
"scheme:data,\n scheme2:user:pass"); "scheme:data,\n scheme2:user:pass");
assertEquals(2, result.size()); assertEquals(2, result.size());
ZKAuthInfo auth0 = result.get(0); ZKAuthInfo auth0 = result.get(0);
@ -118,16 +119,16 @@ public class TestHAZKUtil {
@Test @Test
public void testConfIndirection() throws IOException { public void testConfIndirection() throws IOException {
assertNull(HAZKUtil.resolveConfIndirection(null)); assertNull(ZKUtil.resolveConfIndirection(null));
assertEquals("x", HAZKUtil.resolveConfIndirection("x")); assertEquals("x", ZKUtil.resolveConfIndirection("x"));
TEST_FILE.getParentFile().mkdirs(); TEST_FILE.getParentFile().mkdirs();
Files.write("hello world", TEST_FILE, Charsets.UTF_8); Files.write("hello world", TEST_FILE, Charsets.UTF_8);
assertEquals("hello world", HAZKUtil.resolveConfIndirection( assertEquals("hello world", ZKUtil.resolveConfIndirection(
"@" + TEST_FILE.getAbsolutePath())); "@" + TEST_FILE.getAbsolutePath()));
try { try {
HAZKUtil.resolveConfIndirection("@" + BOGUS_FILE); ZKUtil.resolveConfIndirection("@" + BOGUS_FILE);
fail("Did not throw for non-existent file reference"); fail("Did not throw for non-existent file reference");
} catch (FileNotFoundException fnfe) { } catch (FileNotFoundException fnfe) {
assertTrue(fnfe.getMessage().startsWith(BOGUS_FILE)); assertTrue(fnfe.getMessage().startsWith(BOGUS_FILE));