Search in sources :

Example 71 with Stat

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);
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) ByteBuffer(java.nio.ByteBuffer) KeeperException(org.apache.zookeeper.KeeperException)

Example 72 with Stat

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);
        }
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) IOException(java.io.IOException)

Example 73 with Stat

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));
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) File(java.io.File)

Example 74 with Stat

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);
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) CreateMode(org.apache.zookeeper.CreateMode) RetrievableStateHandle(org.apache.flink.runtime.state.RetrievableStateHandle) Test(org.junit.Test)

Example 75 with Stat

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);
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat)

Aggregations

Stat (org.apache.zookeeper.data.Stat)799 KeeperException (org.apache.zookeeper.KeeperException)266 Test (org.junit.Test)124 IOException (java.io.IOException)120 ZooKeeper (org.apache.zookeeper.ZooKeeper)88 ArrayList (java.util.ArrayList)67 Test (org.testng.annotations.Test)58 Test (org.junit.jupiter.api.Test)53 Watcher (org.apache.zookeeper.Watcher)49 AsyncCallback (org.apache.zookeeper.AsyncCallback)48 ACL (org.apache.zookeeper.data.ACL)47 List (java.util.List)43 CountDownLatch (java.util.concurrent.CountDownLatch)43 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)39 WatchedEvent (org.apache.zookeeper.WatchedEvent)38 CuratorFramework (org.apache.curator.framework.CuratorFramework)37 Map (java.util.Map)34 HashMap (java.util.HashMap)32 WebApplicationException (javax.ws.rs.WebApplicationException)29 ExecutionException (java.util.concurrent.ExecutionException)27