Search in sources :

Example 96 with Stat

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project phoenix by apache.

the class ZookeeperRegistry method registerServer.

@Override
public void registerServer(LoadBalanceZookeeperConf configuration, int pqsPort, String zookeeperConnectString, String pqsHost) throws Exception {
    this.client = CuratorFrameworkFactory.newClient(zookeeperConnectString, new ExponentialBackoffRetry(1000, 10));
    this.client.start();
    HostAndPort hostAndPort = HostAndPort.fromParts(pqsHost, pqsPort);
    String path = configuration.getFullPathToNode(hostAndPort);
    String node = hostAndPort.toString();
    this.client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(path, node.getBytes(StandardCharsets.UTF_8));
    Stat stat = this.client.setACL().withACL(configuration.getAcls()).forPath(path);
    if (stat != null) {
        LOG.info(" node created with right ACL");
    } else {
        LOG.error("could not create node with right ACL. So, system would exit now.");
        throw new RuntimeException(" Unable to connect to Zookeeper");
    }
}
Also used : HostAndPort(com.google.common.net.HostAndPort) Stat(org.apache.zookeeper.data.Stat) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry)

Example 97 with Stat

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project atlas by apache.

the class SetupSteps method setupInProgress.

private boolean setupInProgress(HAConfiguration.ZookeeperProperties zookeeperProperties) {
    CuratorFramework client = curatorFactory.clientInstance();
    Stat lockInProgressStat;
    String path = lockPath(zookeeperProperties);
    try {
        lockInProgressStat = client.checkExists().forPath(path);
        return lockInProgressStat != null;
    } catch (Exception e) {
        LOG.error("Error checking if path {} exists.", path, e);
        return true;
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) Stat(org.apache.zookeeper.data.Stat) SetupException(org.apache.atlas.setup.SetupException) AtlasException(org.apache.atlas.AtlasException)

Example 98 with Stat

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project atlas by apache.

the class ActiveInstanceState method update.

/**
 * Update state of the active server instance.
 *
 * This method writes this instance's Server Address to a shared node in Zookeeper.
 * This information is used by other passive instances to locate the current active server.
 * @throws Exception
 * @param serverId ID of this server instance
 */
public void update(String serverId) throws AtlasBaseException {
    try {
        CuratorFramework client = curatorFactory.clientInstance();
        HAConfiguration.ZookeeperProperties zookeeperProperties = HAConfiguration.getZookeeperProperties(configuration);
        String atlasServerAddress = HAConfiguration.getBoundAddressForId(configuration, serverId);
        List<ACL> acls = Arrays.asList(new ACL[] { AtlasZookeeperSecurityProperties.parseAcl(zookeeperProperties.getAcl(), ZooDefs.Ids.OPEN_ACL_UNSAFE.get(0)) });
        Stat serverInfo = client.checkExists().forPath(getZnodePath(zookeeperProperties));
        if (serverInfo == null) {
            client.create().withMode(CreateMode.EPHEMERAL).withACL(acls).forPath(getZnodePath(zookeeperProperties));
        }
        client.setData().forPath(getZnodePath(zookeeperProperties), atlasServerAddress.getBytes(Charset.forName("UTF-8")));
    } catch (Exception e) {
        throw new AtlasBaseException(AtlasErrorCode.CURATOR_FRAMEWORK_UPDATE, e, "forPath: getZnodePath");
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) Stat(org.apache.zookeeper.data.Stat) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) HAConfiguration(org.apache.atlas.ha.HAConfiguration) ACL(org.apache.zookeeper.data.ACL) AtlasException(org.apache.atlas.AtlasException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException)

Example 99 with Stat

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project x-pipe by ctripcorp.

the class DefaultCurrentClusterServerTest method testRestartHard.

@Test(expected = IllegalStateException.class)
public void testRestartHard() throws Exception {
    currentServer.initialize();
    currentServer.start();
    sleep(100);
    Stat stat1 = getCurator().checkExists().forPath(MetaZkConfig.getMetaServerRegisterPath() + "/" + config.getMetaServerId());
    Assert.assertNotNull(stat1);
    DefaultCurrentClusterServer newServer = new DefaultCurrentClusterServer();
    newServer.setConfig(config);
    newServer.setZkClient(createZkClient());
    newServer.initialize();
    newServer.start();
    Stat stat2 = getCurator().checkExists().forPath(MetaZkConfig.getMetaServerRegisterPath() + "/" + config.getMetaServerId());
    Assert.assertNotNull(stat2);
    Assert.assertNotEquals(stat1, stat2);
}
Also used : Stat(org.apache.zookeeper.data.Stat) AbstractMetaServerContextTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerContextTest) Test(org.junit.Test)

Example 100 with Stat

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project x-pipe by ctripcorp.

the class DefaultCurrentClusterServerTest method testStartStop.

@Test
public void testStartStop() throws Exception {
    currentServer.initialize();
    currentServer.start();
    sleep(150);
    logger.info("[testStartStop][check exists]");
    Stat stat = getCurator().checkExists().forPath(MetaZkConfig.getMetaServerRegisterPath() + "/" + config.getMetaServerId());
    Assert.assertNotNull(stat);
    currentServer.stop();
    logger.info("[testStartStop][check not exists]");
    stat = getCurator().checkExists().forPath(MetaZkConfig.getMetaServerRegisterPath() + "/" + config.getMetaServerId());
    Assert.assertNull(stat);
}
Also used : Stat(org.apache.zookeeper.data.Stat) AbstractMetaServerContextTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerContextTest) Test(org.junit.Test)

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