Search in sources :

Example 26 with NoNodeException

use of org.apache.zookeeper.KeeperException.NoNodeException in project hbase by apache.

the class IntegrationTestZKAndFSPermissions method assertZnodePerms.

private void assertZnodePerms(RecoverableZooKeeper zk, String znode, boolean expectedWorldReadable) throws KeeperException, InterruptedException {
    Stat stat = new Stat();
    List<ACL> acls;
    try {
        acls = zk.getZooKeeper().getACL(znode, stat);
    } catch (NoNodeException ex) {
        LOG.debug("Caught exception for missing znode", ex);
        // the znode is deleted. Probably it was a temporary znode (like RIT).
        return;
    }
    String[] superUsers = superUser == null ? null : superUser.split(",");
    LOG.info("Checking ACLs for znode znode:" + znode + " acls:" + acls);
    for (ACL acl : acls) {
        int perms = acl.getPerms();
        Id id = acl.getId();
        // and one for the hbase user
        if (Ids.ANYONE_ID_UNSAFE.equals(id)) {
            // everyone should be set only if we are expecting this znode to be world readable
            assertTrue(expectedWorldReadable);
            // assert that anyone can only read
            assertEquals(perms, Perms.READ);
        } else if (superUsers != null && ZooKeeperWatcher.isSuperUserId(superUsers, id)) {
            // assert that super user has all the permissions
            assertEquals(perms, Perms.ALL);
        } else if (new Id("sasl", masterPrincipal).equals(id)) {
            // hbase.master.kerberos.principal?
            assertEquals(perms, Perms.ALL);
        } else {
            fail("An ACL is found which is not expected for the znode:" + znode + " , ACL:" + acl);
        }
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ACL(org.apache.zookeeper.data.ACL) Id(org.apache.zookeeper.data.Id)

Example 27 with NoNodeException

use of org.apache.zookeeper.KeeperException.NoNodeException in project storm by apache.

the class BlobStoreUtils method updateKeyForBlobStore.

public static void updateKeyForBlobStore(Map<String, Object> conf, BlobStore blobStore, CuratorFramework zkClient, String key, NimbusInfo nimbusDetails) {
    try {
        // nimbus ha.
        if (nimbusDetails == null) {
            return;
        }
        boolean isListContainsCurrentNimbusInfo = false;
        List<String> stateInfo;
        if (zkClient.checkExists().forPath(BLOBSTORE_SUBTREE + "/" + key) == null) {
            return;
        }
        stateInfo = zkClient.getChildren().forPath(BLOBSTORE_SUBTREE + "/" + key);
        LOG.debug("StateInfo for update {}", stateInfo);
        Set<NimbusInfo> nimbusInfoList = getNimbodesWithLatestSequenceNumberOfBlob(zkClient, key);
        for (NimbusInfo nimbusInfo : nimbusInfoList) {
            if (nimbusInfo.getHost().equals(nimbusDetails.getHost())) {
                isListContainsCurrentNimbusInfo = true;
                break;
            }
        }
        if (!isListContainsCurrentNimbusInfo && downloadUpdatedBlob(conf, blobStore, key, nimbusInfoList)) {
            LOG.debug("Updating state inside zookeeper for an update");
            createStateInZookeeper(conf, key, nimbusDetails);
        }
    } catch (NoNodeException | KeyNotFoundException e) {
        //race condition with a delete
        return;
    } catch (Exception exp) {
        throw new RuntimeException(exp);
    }
}
Also used : NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) TTransportException(org.apache.thrift.transport.TTransportException) KeeperException(org.apache.zookeeper.KeeperException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) IOException(java.io.IOException) AuthorizationException(org.apache.storm.generated.AuthorizationException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) NimbusInfo(org.apache.storm.nimbus.NimbusInfo)

Example 28 with NoNodeException

use of org.apache.zookeeper.KeeperException.NoNodeException in project zookeeper by apache.

the class InstanceManager method getStatus.

public String getStatus(String name, long timeout) throws KeeperException, InterruptedException {
    Stat stat = new Stat();
    byte[] data = null;
    long endTime = Time.currentElapsedTime() + timeout;
    KeeperException lastException = null;
    for (int i = 0; i < maxTries && endTime > Time.currentElapsedTime(); i++) {
        try {
            data = zk.getData(reportsNode + '/' + name, false, stat);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Got Data: " + ((data == null) ? "null" : new String(data)));
            }
            lastException = null;
            break;
        } catch (ConnectionLossException e) {
            lastException = e;
        } catch (NoNodeException e) {
            final Object eventObj = new Object();
            synchronized (eventObj) {
                // wait for the node to appear
                Stat eStat = zk.exists(reportsNode + '/' + name, new Watcher() {

                    public void process(WatchedEvent event) {
                        synchronized (eventObj) {
                            eventObj.notifyAll();
                        }
                    }
                });
                if (eStat == null) {
                    eventObj.wait(endTime - Time.currentElapsedTime());
                }
            }
            lastException = e;
        }
    }
    if (lastException != null) {
        throw lastException;
    }
    return new String(data);
}
Also used : WatchedEvent(org.apache.zookeeper.WatchedEvent) Stat(org.apache.zookeeper.data.Stat) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) Watcher(org.apache.zookeeper.Watcher) ConnectionLossException(org.apache.zookeeper.KeeperException.ConnectionLossException) KeeperException(org.apache.zookeeper.KeeperException)

Example 29 with NoNodeException

use of org.apache.zookeeper.KeeperException.NoNodeException in project zookeeper by apache.

the class SimpleSysTest method testSimpleCase.

/**
     * This test checks the following:
     * 1) All clients connect successfully
     * 2) Half of the servers die (assuming odd number) and a write succeeds
     * 3) All servers are restarted and cluster stays alive
     * 4) Clients see a change by the server
     * 5) Clients' ephemeral nodes are cleaned up
     * 
     * @throws Exception
     */
@Test
public void testSimpleCase() throws Exception {
    configureServers(serverCount);
    configureClients(clientCount, SimpleClient.class, getHostPort());
    Stat stat = new Stat();
    startServers();
    LOG.debug("Connecting to " + getHostPort());
    ZooKeeper zk = new ZooKeeper(getHostPort(), 15000, this);
    waitForConnect(zk, 10000);
    zk.create("/simpleCase", "orig".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    startClients();
    // Check that all clients connect properly
    for (int i = 0; i < getClientCount(); i++) {
        for (int j = 0; j < maxTries; j++) {
            try {
                byte[] b = zk.getData("/simpleCase/" + i, false, stat);
                Assert.assertEquals("orig", new String(b));
            } catch (NoNodeException e) {
                if (j + 1 == maxTries) {
                    Assert.fail("Max tries exceeded on client " + i);
                }
                Thread.sleep(1000);
            }
        }
    }
    // servers, and then bounce the other servers one by one
    for (int i = 0; i < getServerCount(); i++) {
        stopServer(i);
        if (i + 1 > getServerCount() / 2) {
            startServer(i);
        } else if (i + 1 == getServerCount() / 2) {
            Assert.assertTrue("Connection didn't recover", waitForConnect(zk, 10000));
            try {
                zk.setData("/simpleCase", "new".getBytes(), -1);
            } catch (ConnectionLossException e) {
                Assert.assertTrue("Connection didn't recover", waitForConnect(zk, 10000));
                zk.setData("/simpleCase", "new".getBytes(), -1);
            }
            for (int j = 0; j < i; j++) {
                LOG.info("Starting server " + j);
                startServer(i);
            }
        }
    }
    // wait for things to stabilize
    Thread.sleep(100);
    Assert.assertTrue("Servers didn't bounce", waitForConnect(zk, 15000));
    try {
        zk.getData("/simpleCase", false, stat);
    } catch (ConnectionLossException e) {
        Assert.assertTrue("Servers didn't bounce", waitForConnect(zk, 15000));
    }
    // check that the change has propagated to everyone
    for (int i = 0; i < getClientCount(); i++) {
        for (int j = 0; j < maxTries; j++) {
            byte[] data = zk.getData("/simpleCase/" + i, false, stat);
            if (new String(data).equals("new")) {
                break;
            }
            if (j + 1 == maxTries) {
                Assert.fail("max tries exceeded for " + i);
            }
            Thread.sleep(1000);
        }
    }
    // send out the kill signal
    zk.setData("/simpleCase", "die".getBytes(), -1);
    // watch for everyone to die
    for (int i = 0; i < getClientCount(); i++) {
        try {
            for (int j = 0; j < maxTries; j++) {
                zk.getData("/simpleCase/" + i, false, stat);
                if (j + 1 == maxTries) {
                    Assert.fail("max tries exceeded waiting for child " + i + " to die");
                }
                Thread.sleep(200);
            }
        } catch (NoNodeException e) {
        // Great this is what we were hoping for!
        }
    }
    stopClients();
    stopServers();
}
Also used : Stat(org.apache.zookeeper.data.Stat) ZooKeeper(org.apache.zookeeper.ZooKeeper) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ConnectionLossException(org.apache.zookeeper.KeeperException.ConnectionLossException) Test(org.junit.Test)

Example 30 with NoNodeException

use of org.apache.zookeeper.KeeperException.NoNodeException in project zookeeper by apache.

the class DataTree method createNode.

/**
     * Add a new node to the DataTree.
     * @param path
     * 			  Path for the new node.
     * @param data
     *            Data to store in the node.
     * @param acl
     *            Node acls
     * @param ephemeralOwner
     *            the session id that owns this node. -1 indicates this is not
     *            an ephemeral node.
     * @param zxid
     *            Transaction ID
     * @param time
     * @param outputStat
     * 			  A Stat object to store Stat output results into.
     * @throws NodeExistsException 
     * @throws NoNodeException 
     * @throws KeeperException
     */
public void createNode(final String path, byte[] data, List<ACL> acl, long ephemeralOwner, int parentCVersion, long zxid, long time, Stat outputStat) throws KeeperException.NoNodeException, KeeperException.NodeExistsException {
    int lastSlash = path.lastIndexOf('/');
    String parentName = path.substring(0, lastSlash);
    String childName = path.substring(lastSlash + 1);
    StatPersisted stat = new StatPersisted();
    stat.setCtime(time);
    stat.setMtime(time);
    stat.setCzxid(zxid);
    stat.setMzxid(zxid);
    stat.setPzxid(zxid);
    stat.setVersion(0);
    stat.setAversion(0);
    stat.setEphemeralOwner(ephemeralOwner);
    DataNode parent = nodes.get(parentName);
    if (parent == null) {
        throw new KeeperException.NoNodeException();
    }
    synchronized (parent) {
        Set<String> children = parent.getChildren();
        if (children.contains(childName)) {
            throw new KeeperException.NodeExistsException();
        }
        if (parentCVersion == -1) {
            parentCVersion = parent.stat.getCversion();
            parentCVersion++;
        }
        parent.stat.setCversion(parentCVersion);
        parent.stat.setPzxid(zxid);
        Long longval = aclCache.convertAcls(acl);
        DataNode child = new DataNode(data, longval, stat);
        parent.addChild(childName);
        nodes.put(path, child);
        EphemeralType ephemeralType = EphemeralType.get(ephemeralOwner);
        if (ephemeralType == EphemeralType.CONTAINER) {
            containers.add(path);
        } else if (ephemeralType == EphemeralType.TTL) {
            ttls.add(path);
        } else if (ephemeralOwner != 0) {
            HashSet<String> list = ephemerals.get(ephemeralOwner);
            if (list == null) {
                list = new HashSet<String>();
                ephemerals.put(ephemeralOwner, list);
            }
            synchronized (list) {
                list.add(path);
            }
        }
        if (outputStat != null) {
            child.copyStat(outputStat);
        }
    }
    // now check if its one of the zookeeper node child
    if (parentName.startsWith(quotaZookeeper)) {
        // now check if its the limit node
        if (Quotas.limitNode.equals(childName)) {
            // this is the limit node
            // get the parent and add it to the trie
            pTrie.addPath(parentName.substring(quotaZookeeper.length()));
        }
        if (Quotas.statNode.equals(childName)) {
            updateQuotaForPath(parentName.substring(quotaZookeeper.length()));
        }
    }
    // also check to update the quotas for this node
    String lastPrefix = getMaxPrefixWithQuota(path);
    if (lastPrefix != null) {
        // ok we have some match and need to update
        updateCount(lastPrefix, 1);
        updateBytes(lastPrefix, data == null ? 0 : data.length);
    }
    dataWatches.triggerWatch(path, Event.EventType.NodeCreated);
    childWatches.triggerWatch(parentName.equals("") ? "/" : parentName, Event.EventType.NodeChildrenChanged);
}
Also used : NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) StatPersisted(org.apache.zookeeper.data.StatPersisted)

Aggregations

NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)44 KeeperException (org.apache.zookeeper.KeeperException)30 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)16 IOException (java.io.IOException)12 Stat (org.apache.zookeeper.data.Stat)12 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)11 ZooKeeperOperation (com.spotify.helios.servicescommon.coordination.ZooKeeperOperation)9 Job (com.spotify.helios.common.descriptors.Job)8 ConnectionLossException (org.apache.zookeeper.KeeperException.ConnectionLossException)8 JobId (com.spotify.helios.common.descriptors.JobId)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 UnknownHostException (java.net.UnknownHostException)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 ZooKeeperException (org.apache.solr.common.cloud.ZooKeeperException)5 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)5 SessionExpiredException (org.apache.zookeeper.KeeperException.SessionExpiredException)5 DeploymentGroup (com.spotify.helios.common.descriptors.DeploymentGroup)4 UUID (java.util.UUID)4 TimeoutException (java.util.concurrent.TimeoutException)4