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);
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations