Search in sources :

Example 71 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project nifi by apache.

the class ZooKeeperMigrator method retrieveNode.

private DataStatAclNode retrieveNode(ZooKeeper zooKeeper, String path) {
    Preconditions.checkNotNull(zooKeeper, "ZooKeeper client must not be null");
    Preconditions.checkNotNull(path, "path must not be null");
    final Stat stat = new Stat();
    final byte[] data;
    final List<ACL> acls;
    final long ephemeralOwner;
    try {
        data = zooKeeper.getData(path, false, stat);
        acls = zooKeeper.getACL(path, stat);
        ephemeralOwner = stat.getEphemeralOwner();
    } catch (InterruptedException | KeeperException e) {
        if (e instanceof InterruptedException) {
            Thread.currentThread().interrupt();
        }
        throw new RuntimeException(String.format("unable to get data, ACLs, and stats from %s for node at path %s", zooKeeper, path), e);
    }
    return new DataStatAclNode(path, data, stat, acls, ephemeralOwner);
}
Also used : Stat(org.apache.zookeeper.data.Stat) ACL(org.apache.zookeeper.data.ACL) KeeperException(org.apache.zookeeper.KeeperException)

Example 72 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project nifi by apache.

the class ZooKeeperStateProvider method getState.

@Override
public StateMap getState(final String componentId) throws IOException {
    verifyEnabled();
    try {
        final Stat stat = new Stat();
        final String path = getComponentPath(componentId);
        final byte[] data = getZooKeeper().getData(path, false, stat);
        final StateMap stateMap = deserialize(data, stat.getVersion(), componentId);
        return stateMap;
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId + ", due to interruption", e);
    } catch (final KeeperException ke) {
        final Code exceptionCode = ke.code();
        if (Code.NONODE == exceptionCode) {
            return new StandardStateMap(null, -1L);
        }
        if (Code.SESSIONEXPIRED == exceptionCode) {
            invalidateClient();
            return getState(componentId);
        }
        throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId + " with exception code " + exceptionCode, ke);
    } catch (final IOException ioe) {
        // provide more context in the error message
        throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId, ioe);
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) StateMap(org.apache.nifi.components.state.StateMap) StandardStateMap(org.apache.nifi.controller.state.StandardStateMap) IOException(java.io.IOException) Code(org.apache.zookeeper.KeeperException.Code) StandardStateMap(org.apache.nifi.controller.state.StandardStateMap) KeeperException(org.apache.zookeeper.KeeperException)

Example 73 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project coprhd-controller by CoprHD.

the class CoordinatorClientImpl method persistRuntimeState.

@Override
public <T extends CoordinatorSerializable> void persistRuntimeState(String key, T state) throws CoordinatorException {
    String path = String.format("%s/%s", ZkPath.STATE, key);
    try {
        int lastSlash = path.lastIndexOf('/');
        String parentPath = path.substring(0, lastSlash);
        EnsurePath ensurePath = new EnsurePath(parentPath);
        ensurePath.ensure(_zkConnection.curator().getZookeeperClient());
    } catch (Exception e) {
        log.error(String.format("Failed to ensure path to key: %s", path), e);
    }
    try {
        byte[] data = state.encodeAsString().getBytes("UTF-8");
        // Here the loop can end (break or throw Exception) from inside, safe to suppress
        for (boolean exist = _zkConnection.curator().checkExists().forPath(path) != null; ; exist = !exist) {
            // NOSONAR("squid:S1994")
            try {
                if (exist) {
                    _zkConnection.curator().setData().forPath(path, data);
                } else {
                    _zkConnection.curator().create().forPath(path, data);
                }
                break;
            } catch (KeeperException ex) {
                if (exist && ex.code() == KeeperException.Code.NONODE || !exist && ex.code() == KeeperException.Code.NODEEXISTS) {
                    continue;
                }
                throw ex;
            }
        }
    } catch (Exception e) {
        log.info("Failed to persist runtime state e=", e);
        throw CoordinatorException.fatals.unableToPersistTheState(e);
    }
}
Also used : EnsurePath(org.apache.curator.utils.EnsurePath) PropertyInfoMapper.decodeFromString(com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) KeeperException(org.apache.zookeeper.KeeperException)

Example 74 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project zookeeper by apache.

the class DelQuotaCommand method delQuota.

/**
 * this method deletes quota for a node.
 *
 * @param zk the zookeeper client
 * @param path the path to delete quota for
 * @param bytes true if number of bytes needs to be unset
 * @param numNodes true if number of nodes needs to be unset
 * @return true if quota deletion is successful
 * @throws KeeperException
 * @throws IOException
 * @throws InterruptedException
 */
public static boolean delQuota(ZooKeeper zk, String path, boolean bytes, boolean numNodes) throws KeeperException, IOException, InterruptedException, MalformedPathException {
    String parentPath = Quotas.quotaZookeeper + path;
    String quotaPath = Quotas.quotaZookeeper + path + "/" + Quotas.limitNode;
    if (zk.exists(quotaPath, false) == null) {
        System.out.println("Quota does not exist for " + path);
        return true;
    }
    byte[] data = null;
    try {
        data = zk.getData(quotaPath, false, new Stat());
    } catch (IllegalArgumentException ex) {
        throw new MalformedPathException(ex.getMessage());
    } catch (KeeperException.NoNodeException ne) {
        System.err.println("quota does not exist for " + path);
        return true;
    }
    StatsTrack strack = new StatsTrack(new String(data));
    if (bytes && !numNodes) {
        strack.setBytes(-1L);
        zk.setData(quotaPath, strack.toString().getBytes(), -1);
    } else if (!bytes && numNodes) {
        strack.setCount(-1);
        zk.setData(quotaPath, strack.toString().getBytes(), -1);
    } else if (bytes && numNodes) {
        // delete till you can find a node with more than
        // one child
        List<String> children = zk.getChildren(parentPath, false);
        // / delete the direct children first
        for (String child : children) {
            zk.delete(parentPath + "/" + child, -1);
        }
        // cut the tree till their is more than one child
        trimProcQuotas(zk, parentPath);
    }
    return true;
}
Also used : Stat(org.apache.zookeeper.data.Stat) StatsTrack(org.apache.zookeeper.StatsTrack) KeeperException(org.apache.zookeeper.KeeperException)

Example 75 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project zookeeper by apache.

the class Ls2Command method exec.

@Override
public boolean exec() throws CliException {
    err.println("'ls2' has been deprecated. " + "Please use 'ls [-s] path' instead.");
    String path = args[1];
    boolean watch = args.length > 2;
    Stat stat = new Stat();
    List<String> children;
    try {
        children = zk.getChildren(path, watch, stat);
    } catch (IllegalArgumentException ex) {
        throw new MalformedPathException(ex.getMessage());
    } catch (KeeperException | InterruptedException ex) {
        throw new CliWrapperException(ex);
    }
    out.println(children);
    new StatPrinter(out).print(stat);
    return watch;
}
Also used : Stat(org.apache.zookeeper.data.Stat) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

KeeperException (org.apache.zookeeper.KeeperException)566 IOException (java.io.IOException)188 Stat (org.apache.zookeeper.data.Stat)127 ZooKeeper (org.apache.zookeeper.ZooKeeper)87 ArrayList (java.util.ArrayList)51 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)45 Watcher (org.apache.zookeeper.Watcher)39 WatchedEvent (org.apache.zookeeper.WatchedEvent)38 Test (org.junit.jupiter.api.Test)38 CountDownLatch (java.util.concurrent.CountDownLatch)30 SolrException (org.apache.solr.common.SolrException)30 HashMap (java.util.HashMap)29 List (java.util.List)28 ACL (org.apache.zookeeper.data.ACL)27 Test (org.junit.Test)27 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)25 ServerName (org.apache.hadoop.hbase.ServerName)24 Map (java.util.Map)23 IZooReaderWriter (org.apache.accumulo.fate.zookeeper.IZooReaderWriter)23 InterruptedIOException (java.io.InterruptedIOException)20