Example usage for org.apache.zookeeper KeeperException getPath

List of usage examples for org.apache.zookeeper KeeperException getPath

Introduction

In this page you can find the example usage for org.apache.zookeeper KeeperException getPath.

Prototype

public String getPath() 

Source Link

Document

Read the path for this exception

Usage

From source file:org.apache.hadoop.hbase.replication.ReplicationZookeeper.java

License:Apache License

/**
 * Recursive deletion of all znodes in specified rs' znode
 * @param znode//ww  w  .  java  2 s  .  co m
 */
public void deleteRsQueues(String znode) {
    String fullpath = ZKUtil.joinZNode(rsZNode, znode);
    try {
        List<String> clusters = ZKUtil.listChildrenNoWatch(this.zookeeper, fullpath);
        for (String cluster : clusters) {
            // We'll delete it later
            if (cluster.equals(RS_LOCK_ZNODE)) {
                continue;
            }
            String fullClusterPath = ZKUtil.joinZNode(fullpath, cluster);
            ZKUtil.deleteNodeRecursively(this.zookeeper, fullClusterPath);
        }
        // Finish cleaning up
        ZKUtil.deleteNodeRecursively(this.zookeeper, fullpath);
    } catch (KeeperException e) {
        if (e instanceof KeeperException.NoNodeException || e instanceof KeeperException.NotEmptyException) {
            // Testing a special case where another region server was able to
            // create a lock just after we deleted it, but then was also able to
            // delete the RS znode before us or its lock znode is still there.
            if (e.getPath().equals(fullpath)) {
                return;
            }
        }
        this.abortable.abort("Failed delete of " + znode, e);
    }
}

From source file:org.apache.hadoop.hbase.zookeeper.TestReadOnlyZKClient.java

License:Apache License

@Test
public void testNoNode() throws InterruptedException, ExecutionException {
    String pathNotExists = PATH + "_whatever";
    try {/*from   w  ww .j av a 2  s.c  om*/
        RO_ZK.get(pathNotExists).get();
        fail("should fail because of " + pathNotExists + " does not exist");
    } catch (ExecutionException e) {
        assertThat(e.getCause(), instanceOf(KeeperException.class));
        KeeperException ke = (KeeperException) e.getCause();
        assertEquals(Code.NONODE, ke.code());
        assertEquals(pathNotExists, ke.getPath());
    }
    try {
        RO_ZK.list(pathNotExists).get();
        fail("should fail because of " + pathNotExists + " does not exist");
    } catch (ExecutionException e) {
        assertThat(e.getCause(), instanceOf(KeeperException.class));
        KeeperException ke = (KeeperException) e.getCause();
        assertEquals(Code.NONODE, ke.code());
        assertEquals(pathNotExists, ke.getPath());
    }
    // exists will not throw exception.
    assertNull(RO_ZK.exists(pathNotExists).get());
}

From source file:org.fusesource.ide.zk.zookeeper.ZooKeeperActivator.java

License:Apache License

public static void reportError(Throwable t) {
    Throwable cause = t.getCause();
    if (cause != null && cause != t) {
        reportError(cause);/* www.  j a va 2s  . c  o  m*/
        return;
    }

    boolean showCustomErrorMessageDialog = false;
    int style = StatusManager.LOG;
    String title = "Error";
    String message = t.getLocalizedMessage();
    if (t instanceof KeeperException) {

        KeeperException ke = (KeeperException) t;

        title = "ZooKeeper Error";
        showCustomErrorMessageDialog = true;

        if (ke instanceof InvalidACLException) {
            title = "Invalid ACL";
            message = "ACL is invalid for '" + ke.getPath() + "'.";
        } else if (ke instanceof NodeExistsException) {
            title = "Znode Exists";
            message = "Znode '" + ke.getPath() + "' already exists.";
        } else if (ke instanceof NoAuthException) {
            title = "Not Authorized";
            message = "Not authorized to perform this action on '" + ke.getPath() + "'.";
        } else if (ke instanceof NoNodeException) {
            title = "No Znode";
            message = "Znode '" + ke.getPath() + "' does not exist.";
        } else if (ke instanceof NotEmptyException) {
            title = "Not Empty";
            message = "Znode '" + ke.getPath() + "' has children.";
        }

    }

    if (showCustomErrorMessageDialog) {
        MessageDialog.openError(Display.getCurrent().getActiveShell(), title, message);
    } else {
        style = style | StatusManager.BLOCK;
    }

    Status status = new Status(IStatus.ERROR, PLUGIN_ID, message, t);
    StatusManager.getManager().handle(status, style);
}

From source file:org.neo4j.kernel.ha.cluster.zoo.ZooClient.java

License:Open Source License

private void writeHaServerConfig() throws InterruptedException, KeeperException {
    // Make sure the HA server root is created
    String serverRootPath = rootPath + "/" + HA_SERVERS_CHILD;
    try {/*  ww w.j  a va2s. c o m*/
        zooKeeper.create(serverRootPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    } catch (KeeperException e) {
        if (e.code() != KeeperException.Code.NODEEXISTS) {
            throw e;
        }
    }

    // Make sure the compatibility node is present
    String legacyCompatibilityPath = rootPath + "/" + COMPATIBILITY_CHILD_18;
    /*
    try
    {
    zooKeeper.create( legacyCompatibilityPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
    CreateMode.PERSISTENT );
    }
    catch ( KeeperException e )
    {
    if ( e.code() != KeeperException.Code.NODEEXISTS )
    {
        throw e;
    }
    }
    */

    // Make sure the compatibility node is present
    String compatibilityPath = rootPath + "/" + COMPATIBILITY_CHILD_19;
    try {
        zooKeeper.create(compatibilityPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    } catch (KeeperException e) {
        if (e.code() != KeeperException.Code.NODEEXISTS) {
            throw e;
        }
    }

    // Write the HA server config.
    String machinePath = serverRootPath + "/" + machineId;
    String legacyCompatibilityMachinePath = legacyCompatibilityPath + "/" + machineId;
    String compatibilityMachinePath = compatibilityPath + "/" + machineId;
    byte[] data = haServerAsData();
    boolean legacyCompatCreated = false;
    boolean compatCreated = false;
    boolean machineCreated = false;
    try {
        zooKeeper.create(legacyCompatibilityMachinePath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
                CreateMode.EPHEMERAL);
        legacyCompatCreated = true;
        zooKeeper.create(compatibilityMachinePath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
                CreateMode.EPHEMERAL);
        compatCreated = true;
        zooKeeper.create(machinePath, data, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
        machineCreated = true;
    } catch (KeeperException e) {
        if (e.code() != KeeperException.Code.NODEEXISTS) {
            throw e;
        }
        msgLog.logMessage("HA server info already present, trying again");
        Thread.sleep(3000);
        try {
            if (legacyCompatCreated) {
                zooKeeper.delete(legacyCompatibilityMachinePath, -1);
            }
            if (compatCreated) {
                zooKeeper.delete(compatibilityMachinePath, -1);
            }
            if (machineCreated) {
                zooKeeper.delete(machinePath, -1);
            }
        } catch (KeeperException ee) {
            if (ee.code() != KeeperException.Code.NONODE) {
                msgLog.logMessage("Unable to delete " + ee.getPath(), ee);
            }
        } finally {
            writeHaServerConfig();
        }
    }
    zooKeeper.setData(machinePath, data, -1);
    msgLog.logMessage("Wrote HA server " + haServer + " to zoo keeper");
}

From source file:org.neo4j.kernel.ha.zookeeper.ZooClient.java

License:Open Source License

private void writeHaServerConfig() throws InterruptedException, KeeperException {
    // Make sure the HA server root is created
    String serverRootPath = rootPath + "/" + HA_SERVERS_CHILD;
    try {//www. j a  v  a 2  s.c  o  m
        zooKeeper.create(serverRootPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    } catch (KeeperException e) {
        if (e.code() != KeeperException.Code.NODEEXISTS) {
            throw e;
        }
    }

    // Make sure the compatibility node is present
    String compatibilityPath = rootPath + "/" + COMPATIBILITY_CHILD;
    try {
        zooKeeper.create(compatibilityPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    } catch (KeeperException e) {
        if (e.code() != KeeperException.Code.NODEEXISTS) {
            throw e;
        }
    }

    // Write the HA server config.
    String machinePath = serverRootPath + "/" + machineId;
    String compatibilityMachinePath = compatibilityPath + "/" + machineId;
    byte[] data = haServerAsData();
    boolean compatCreated = false;
    boolean machineCreated = false;
    try {
        zooKeeper.create(compatibilityMachinePath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
                CreateMode.EPHEMERAL);
        compatCreated = true;
        zooKeeper.create(machinePath, data, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
        machineCreated = true;
    } catch (KeeperException e) {
        if (e.code() != KeeperException.Code.NODEEXISTS) {
            throw e;
        }
        msgLog.logMessage("HA server info already present, trying again");
        try {
            if (compatCreated)
                zooKeeper.delete(compatibilityMachinePath, -1);
            if (machineCreated)
                zooKeeper.delete(machinePath, -1);
        } catch (KeeperException ee) {
            if (ee.code() != KeeperException.Code.NONODE) {
                msgLog.logMessage("Unable to delete " + ee.getPath(), ee);
            }
        } finally {
            writeHaServerConfig();
        }
    }
    zooKeeper.setData(machinePath, data, -1);
    msgLog.logMessage("Wrote HA server " + haServer + " to zoo keeper");
}