use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project hadoop by apache.
the class ZKSignerSecretProvider method pullFromZK.
/**
* Pulls data from ZooKeeper. If isInit is false, it will only parse the
* next secret and version. If isInit is true, it will also parse the current
* and previous secrets, and the next rollover date; it will also init the
* secrets. Hence, isInit should only be true on startup.
* @param isInit see description above
*/
private synchronized void pullFromZK(boolean isInit) {
try {
Stat stat = new Stat();
byte[] bytes = client.getData().storingStatIn(stat).forPath(path);
ByteBuffer bb = ByteBuffer.wrap(bytes);
int dataVersion = bb.getInt();
if (dataVersion > DATA_VERSION) {
throw new IllegalStateException("Cannot load data from ZooKeeper; it" + "was written with a newer version");
}
int nextSecretLength = bb.getInt();
byte[] nextSecret = new byte[nextSecretLength];
bb.get(nextSecret);
this.nextSecret = nextSecret;
zkVersion = stat.getVersion();
if (isInit) {
int currentSecretLength = bb.getInt();
byte[] currentSecret = new byte[currentSecretLength];
bb.get(currentSecret);
int previousSecretLength = bb.getInt();
byte[] previousSecret = null;
if (previousSecretLength > 0) {
previousSecret = new byte[previousSecretLength];
bb.get(previousSecret);
}
super.initSecrets(currentSecret, previousSecret);
nextRolloverDate = bb.getLong();
}
} catch (Exception ex) {
LOG.error("An unexpected exception occurred while pulling data from" + "ZooKeeper", ex);
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project hadoop by apache.
the class ChildReaper method doWork.
private void doWork() {
for (String path : paths) {
try {
List<String> children = client.getChildren().forPath(path);
for (String name : children) {
String thisPath = ZKPaths.makePath(path, name);
Stat stat = client.checkExists().forPath(thisPath);
if ((stat != null) && (stat.getNumChildren() == 0)) {
reaper.addPath(thisPath, mode);
}
}
} catch (Exception e) {
log.error("Could not get children for path: " + path, e);
}
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project flink by apache.
the class JobManagerHAJobGraphRecoveryITCase method verifyCleanRecoveryState.
/**
* Fails the test if the recovery state (file state backend and ZooKeeper) is not clean.
*/
private static void verifyCleanRecoveryState(Configuration config) throws Exception {
// File state backend empty
Collection<File> stateHandles = FileUtils.listFiles(FileStateBackendBasePath, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
if (!stateHandles.isEmpty()) {
fail("File state backend is not clean: " + stateHandles);
}
// ZooKeeper
String currentJobsPath = config.getString(ConfigConstants.HA_ZOOKEEPER_JOBGRAPHS_PATH, ConfigConstants.DEFAULT_ZOOKEEPER_JOBGRAPHS_PATH);
Stat stat = ZooKeeper.getClient().checkExists().forPath(currentJobsPath);
if (stat.getCversion() == 0) {
// Sanity check: verify that some changes have been performed
fail("ZooKeeper state for '" + currentJobsPath + "' has not been modified during " + "this test. What are you testing?");
}
if (stat.getNumChildren() != 0) {
// Is everything clean again?
fail("ZooKeeper path '" + currentJobsPath + "' is not clean: " + ZooKeeper.getClient().getChildren().forPath(currentJobsPath));
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project flink by apache.
the class ZooKeeperStateHandleStoreITCase method testAddWithCreateMode.
/**
* Tests that {@link CreateMode} is respected.
*/
@Test
public void testAddWithCreateMode() throws Exception {
LongStateStorage longStateStorage = new LongStateStorage();
ZooKeeperStateHandleStore<Long> store = new ZooKeeperStateHandleStore<Long>(ZooKeeper.getClient(), longStateStorage, Executors.directExecutor());
// Config
Long state = 3457347234L;
CreateMode[] modes = CreateMode.values();
for (int i = 0; i < modes.length; i++) {
CreateMode mode = modes[i];
state += i;
String pathInZooKeeper = "/testAddWithCreateMode" + mode.name();
// Test
store.add(pathInZooKeeper, state, mode);
if (mode.isSequential()) {
// Figure out the sequential ID
List<String> paths = ZooKeeper.getClient().getChildren().forPath("/");
for (String p : paths) {
if (p.startsWith("testAddWithCreateMode" + mode.name())) {
pathInZooKeeper = "/" + p;
break;
}
}
}
// Verify
// State handle created
assertEquals(i + 1, store.getAll().size());
assertEquals(state, longStateStorage.getStateHandles().get(i).retrieveState());
// Path created
Stat stat = ZooKeeper.getClient().checkExists().forPath(pathInZooKeeper);
assertNotNull(stat);
// Is ephemeral or persistent
if (mode.isEphemeral()) {
assertTrue(stat.getEphemeralOwner() != 0);
} else {
assertEquals(0, stat.getEphemeralOwner());
}
// Data is equal
@SuppressWarnings("unchecked") Long actual = ((RetrievableStateHandle<Long>) InstantiationUtil.deserializeObject(ZooKeeper.getClient().getData().forPath(pathInZooKeeper), ClassLoader.getSystemClassLoader())).retrieveState();
assertEquals(state, actual);
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project storm-signals by ptgoetz.
the class AbstractSignalConnection method initWatcher.
protected void initWatcher() throws Exception {
// create base path if necessary
Stat stat = this.client.checkExists().usingWatcher(this).forPath(this.name);
if (stat == null) {
String path = this.client.create().creatingParentsIfNeeded().forPath(this.name);
LOG.info("Created: " + path);
}
}
Aggregations