Search in sources :

Example 1 with InvalidACLException

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");
    }
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ArrayList(java.util.ArrayList) ServerCnxnFactory(org.apache.zookeeper.server.ServerCnxnFactory) ACL(org.apache.zookeeper.data.ACL) File(java.io.File) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) InvalidACLException(org.apache.zookeeper.KeeperException.InvalidACLException) Test(org.junit.jupiter.api.Test)

Example 2 with InvalidACLException

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);
        }
    }
}
Also used : ServiceInstanceStateChangeListener(org.apache.hadoop.hive.registry.ServiceInstanceStateChangeListener) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) IOException(java.io.IOException) InvalidACLException(org.apache.zookeeper.KeeperException.InvalidACLException) IOException(java.io.IOException) InvalidACLException(org.apache.zookeeper.KeeperException.InvalidACLException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException)

Example 3 with InvalidACLException

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);
        }
    }
}
Also used : ServiceInstanceStateChangeListener(org.apache.hadoop.hive.llap.registry.ServiceInstanceStateChangeListener) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) IOException(java.io.IOException) InvalidACLException(org.apache.zookeeper.KeeperException.InvalidACLException) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) InvalidACLException(org.apache.zookeeper.KeeperException.InvalidACLException)

Example 4 with InvalidACLException

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();
        }
    }
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) TestableZooKeeper(org.apache.zookeeper.TestableZooKeeper) Stat(org.apache.zookeeper.data.Stat) ArrayList(java.util.ArrayList) ACL(org.apache.zookeeper.data.ACL) Id(org.apache.zookeeper.data.Id) InvalidACLException(org.apache.zookeeper.KeeperException.InvalidACLException) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.jupiter.api.Test)

Example 5 with InvalidACLException

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");
    }
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ServerCnxnFactory(org.apache.zookeeper.server.ServerCnxnFactory) File(java.io.File) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) InvalidACLException(org.apache.zookeeper.KeeperException.InvalidACLException) Test(org.junit.jupiter.api.Test)

Aggregations

InvalidACLException (org.apache.zookeeper.KeeperException.InvalidACLException)5 ZooKeeper (org.apache.zookeeper.ZooKeeper)3 Test (org.junit.jupiter.api.Test)3 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ExecutorService (java.util.concurrent.ExecutorService)2 PathChildrenCache (org.apache.curator.framework.recipes.cache.PathChildrenCache)2 ACL (org.apache.zookeeper.data.ACL)2 ServerCnxnFactory (org.apache.zookeeper.server.ServerCnxnFactory)2 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)2 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 ServiceInstanceStateChangeListener (org.apache.hadoop.hive.llap.registry.ServiceInstanceStateChangeListener)1 ServiceInstanceStateChangeListener (org.apache.hadoop.hive.registry.ServiceInstanceStateChangeListener)1 KeeperException (org.apache.zookeeper.KeeperException)1 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)1 TestableZooKeeper (org.apache.zookeeper.TestableZooKeeper)1