use of org.apache.zookeeper.KeeperException.InvalidACLException in project zookeeper by apache.
the class ACLTest method testNullValueACL.
@Test
public void testNullValueACL() throws Exception {
File tmpDir = ClientBase.createTmpDir();
ClientBase.setupTestEnv();
ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
f.startup(zks);
ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
try {
List<ACL> acls = new ArrayList<ACL>();
acls.add(null);
// case 1 : null value in ACL list with create
try {
zk.create("/foo", "foo".getBytes(), acls, CreateMode.PERSISTENT);
fail("Expected InvalidACLException for null value in ACL List");
} catch (InvalidACLException e) {
// Expected. Do nothing
}
// case 2 : null value in ACL list with other create API
try {
zk.create("/foo", "foo".getBytes(), acls, CreateMode.PERSISTENT, null);
fail("Expected InvalidACLException for null value in ACL List");
} catch (InvalidACLException e) {
// Expected. Do nothing
}
// case 3 : null value in ACL list with setACL
try {
zk.setACL("/foo", acls, -1);
fail("Expected InvalidACLException for null value in ACL List");
} catch (InvalidACLException e) {
// Expected. Do nothing
}
} finally {
zk.close();
f.shutdown();
zks.shutdown();
assertTrue(ClientBase.waitForServerDown(HOSTPORT, ClientBase.CONNECTION_TIMEOUT), "waiting for server down");
}
}
use of org.apache.zookeeper.KeeperException.InvalidACLException in project hive by apache.
the class ZkRegistryBase method ensureInstancesCache.
// Bogus warnings despite closeQuietly.
@SuppressWarnings("resource")
protected final synchronized PathChildrenCache ensureInstancesCache(long clusterReadyTimeoutMs) throws IOException {
Preconditions.checkArgument(zooKeeperClient != null && zooKeeperClient.getState() == CuratorFrameworkState.STARTED, "client is not started");
// lazily create PathChildrenCache
PathChildrenCache instancesCache = this.instancesCache;
if (instancesCache != null)
return instancesCache;
ExecutorService tp = Executors.newFixedThreadPool(1, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("StateChangeNotificationHandler").build());
long startTimeNs = System.nanoTime(), deltaNs = clusterReadyTimeoutMs * 1000000L;
long sleepTimeMs = Math.min(16, clusterReadyTimeoutMs);
while (true) {
instancesCache = new PathChildrenCache(zooKeeperClient, workersPath, true);
instancesCache.getListenable().addListener(new InstanceStateChangeListener(), tp);
try {
instancesCache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
this.instancesCache = instancesCache;
return instancesCache;
} catch (InvalidACLException e) {
// PathChildrenCache tried to mkdir when the znode wasn't there, and failed.
CloseableUtils.closeQuietly(instancesCache);
long elapsedNs = System.nanoTime() - startTimeNs;
if (deltaNs == 0 || deltaNs <= elapsedNs) {
LOG.error("Unable to start curator PathChildrenCache", e);
throw new IOException(e);
}
LOG.warn("The cluster is not started yet (InvalidACL); will retry");
try {
Thread.sleep(Math.min(sleepTimeMs, (deltaNs - elapsedNs) / 1000000L));
} catch (InterruptedException e1) {
LOG.error("Interrupted while retrying the PathChildrenCache startup");
throw new IOException(e1);
}
sleepTimeMs = sleepTimeMs << 1;
} catch (Exception e) {
CloseableUtils.closeQuietly(instancesCache);
LOG.error("Unable to start curator PathChildrenCache", e);
throw new IOException(e);
}
}
}
use of org.apache.zookeeper.KeeperException.InvalidACLException in project hive by apache.
the class LlapZookeeperRegistryImpl method checkPathChildrenCache.
private synchronized void checkPathChildrenCache(long clusterReadyTimeoutMs) throws IOException {
Preconditions.checkArgument(zooKeeperClient != null && zooKeeperClient.getState() == CuratorFrameworkState.STARTED, "client is not started");
// lazily create PathChildrenCache
if (instancesCache != null)
return;
ExecutorService tp = Executors.newFixedThreadPool(1, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("StateChangeNotificationHandler").build());
long startTimeNs = System.nanoTime(), deltaNs = clusterReadyTimeoutMs * 1000000L;
long sleepTimeMs = Math.min(16, clusterReadyTimeoutMs);
while (true) {
PathChildrenCache instancesCache = new PathChildrenCache(zooKeeperClient, workersPath, true);
instancesCache.getListenable().addListener(new InstanceStateChangeListener(), tp);
try {
instancesCache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
this.instancesCache = instancesCache;
break;
} catch (InvalidACLException e) {
// PathChildrenCache tried to mkdir when the znode wasn't there, and failed.
CloseableUtils.closeQuietly(instancesCache);
long elapsedNs = System.nanoTime() - startTimeNs;
if (deltaNs == 0 || deltaNs <= elapsedNs) {
LOG.error("Unable to start curator PathChildrenCache", e);
throw new IOException(e);
}
LOG.warn("The cluster is not started yet (InvalidACL); will retry");
try {
Thread.sleep(Math.min(sleepTimeMs, (deltaNs - elapsedNs) / 1000000L));
} catch (InterruptedException e1) {
LOG.error("Interrupted while retrying the PathChildrenCache startup");
throw new IOException(e1);
}
sleepTimeMs = sleepTimeMs << 1;
} catch (Exception e) {
CloseableUtils.closeQuietly(instancesCache);
LOG.error("Unable to start curator PathChildrenCache", e);
throw new IOException(e);
}
}
}
use of org.apache.zookeeper.KeeperException.InvalidACLException in project zookeeper by apache.
the class ClientTest method testACLs.
@Test
public void testACLs() throws Exception {
ZooKeeper zk = null;
try {
zk = createClient();
try {
zk.create("/acltest", new byte[0], Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);
fail("Should have received an invalid acl error");
} catch (InvalidACLException e) {
LOG.info("Test successful, invalid acl received : {}", e.getMessage());
}
try {
ArrayList<ACL> testACL = new ArrayList<ACL>();
testACL.add(new ACL(Perms.ALL | Perms.ADMIN, Ids.AUTH_IDS));
testACL.add(new ACL(Perms.ALL | Perms.ADMIN, new Id("ip", "127.0.0.1/8")));
zk.create("/acltest", new byte[0], testACL, CreateMode.PERSISTENT);
fail("Should have received an invalid acl error");
} catch (InvalidACLException e) {
LOG.info("Test successful, invalid acl received : {}", e.getMessage());
}
try {
ArrayList<ACL> testACL = new ArrayList<ACL>();
testACL.add(new ACL(Perms.ALL | Perms.ADMIN, new Id()));
zk.create("/nullidtest", new byte[0], testACL, CreateMode.PERSISTENT);
fail("Should have received an invalid acl error");
} catch (InvalidACLException e) {
LOG.info("Test successful, invalid acl received : {}", e.getMessage());
}
zk.addAuthInfo("digest", "ben:passwd".getBytes());
ArrayList<ACL> testACL = new ArrayList<ACL>();
testACL.add(new ACL(Perms.ALL, new Id("auth", "")));
testACL.add(new ACL(Perms.WRITE, new Id("ip", "127.0.0.1")));
zk.create("/acltest", new byte[0], testACL, CreateMode.PERSISTENT);
zk.close();
zk = createClient();
zk.addAuthInfo("digest", "ben:passwd2".getBytes());
if (skipACL) {
try {
zk.getData("/acltest", false, null);
} catch (KeeperException e) {
fail("Badauth reads should succeed with skipACL.");
}
} else {
try {
zk.getData("/acltest", false, null);
fail("Should have received a permission error");
} catch (KeeperException e) {
assertEquals(Code.NOAUTH, e.code());
}
}
zk.addAuthInfo("digest", "ben:passwd".getBytes());
zk.getData("/acltest", false, null);
zk.setACL("/acltest", Ids.OPEN_ACL_UNSAFE, -1);
zk.close();
zk = createClient();
zk.getData("/acltest", false, null);
List<ACL> acls = zk.getACL("/acltest", new Stat());
assertEquals(1, acls.size());
assertEquals(Ids.OPEN_ACL_UNSAFE, acls);
// The stat parameter should be optional.
acls = zk.getACL("/acltest", null);
assertEquals(1, acls.size());
assertEquals(Ids.OPEN_ACL_UNSAFE, acls);
zk.close();
} finally {
if (zk != null) {
zk.close();
}
}
}
use of org.apache.zookeeper.KeeperException.InvalidACLException in project zookeeper by apache.
the class ACLTest method testNullACL.
@Test
public void testNullACL() throws Exception {
File tmpDir = ClientBase.createTmpDir();
ClientBase.setupTestEnv();
ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
f.startup(zks);
ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
try {
// case 1 : null ACL with create
try {
zk.create("/foo", "foo".getBytes(), null, CreateMode.PERSISTENT);
fail("Expected InvalidACLException for null ACL parameter");
} catch (InvalidACLException e) {
// Expected. Do nothing
}
// case 2 : null ACL with other create API
try {
zk.create("/foo", "foo".getBytes(), null, CreateMode.PERSISTENT, null);
fail("Expected InvalidACLException for null ACL parameter");
} catch (InvalidACLException e) {
// Expected. Do nothing
}
// case 3 : null ACL with setACL
try {
zk.setACL("/foo", null, 0);
fail("Expected InvalidACLException for null ACL parameter");
} catch (InvalidACLException e) {
// Expected. Do nothing
}
} finally {
zk.close();
f.shutdown();
zks.shutdown();
assertTrue(ClientBase.waitForServerDown(HOSTPORT, ClientBase.CONNECTION_TIMEOUT), "waiting for server down");
}
}
Aggregations