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