use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project free-framework by a601942905git.
the class ZookeeperTest method main.
public static void main(String[] args) {
FtpConfig ftpConfig = FtpConfig.builder().host("127.0.0.1").port(80).userName("admin").userPassword("111111").build();
byte[] strData = null;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(ftpConfig);
strData = baos.toByteArray();
} catch (Exception e) {
e.printStackTrace();
}
String serverList = "192.168.1.11:2181";
int sessionTimeOut = 6000;
try {
ZooKeeper zooKeeper = new ZooKeeper(serverList, sessionTimeOut, (watchedEvent) -> {
System.out.println("触发客户端监听事件......");
});
Stat stat = zooKeeper.exists(CONFIG_DATA, true);
if (null == stat) {
zooKeeper.create(CONFIG_DATA, strData, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
stat = zooKeeper.exists(CONFIG_DATA, true);
if (null != stat) {
byte[] data = zooKeeper.getData(CONFIG_DATA, true, null);
ByteArrayInputStream bais = new ByteArrayInputStream(data);
ObjectInputStream ois = new ObjectInputStream(bais);
Object obj = ois.readObject();
System.out.println("配置信息===============>" + obj.toString());
}
} catch (IOException e) {
log.error("异常:", e);
} catch (InterruptedException e) {
log.error("异常:", e);
} catch (KeeperException e) {
log.error("异常:", e);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project incubator-gobblin by apache.
the class ZookeeperLeaderElection method determineLeadership.
private void determineLeadership() {
ReentrantReadWriteLock.WriteLock lock = this.readWriteLock.writeLock();
lock.lock();
try {
List<String> children = this.zooKeeper.getChildren().forPath(this.leaderElectionNode);
Collections.sort(children);
int idx = children.indexOf(this.nodeId);
if (idx == 0) {
Stat stat = this.zooKeeper.checkExists().forPath(this.leaderNode);
if (stat == null) {
this.zooKeeper.create().forPath(this.leaderNode, serializeMetadata(this.localMetadata));
} else {
this.zooKeeper.setData().forPath(this.leaderNode, serializeMetadata(this.localMetadata));
}
this.isLeader = true;
} else {
this.isLeader = false;
String watchedNode = this.leaderElectionNode + "/" + children.get(idx - 1);
this.zooKeeper.checkExists().usingWatcher(new DetermineLeadershipWatcher()).forPath(watchedNode);
}
findLeader();
} catch (KeeperException exc) {
reset();
} catch (Throwable exc) {
log.error("Fatal failure.", exc);
this.fatalFailure = true;
} finally {
lock.unlock();
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project herddb by diennea.
the class ZookeeperClientSideMetadataProvider method getServerHostData.
@Override
public ServerHostData getServerHostData(String nodeId) throws ClientSideMetadataProviderException {
ServerHostData cached = servers.get(nodeId);
if (cached != null) {
return cached;
}
ZooKeeper zooKeeper = getZooKeeper();
try {
for (int i = 0; i < MAX_TRIALS; i++) {
try {
Stat stat = new Stat();
byte[] node = zooKeeper.getData(basePath + "/nodes/" + nodeId, null, stat);
NodeMetadata nodeMetadata = NodeMetadata.deserialize(node, stat.getVersion());
ServerHostData result = new ServerHostData(nodeMetadata.host, nodeMetadata.port, "?", nodeMetadata.ssl, new HashMap<>());
servers.put(nodeId, result);
return result;
} catch (KeeperException.NoNodeException ex) {
return null;
} catch (KeeperException.ConnectionLossException ex) {
LOG.log(Level.SEVERE, "tmp error getServerHostData for " + nodeId + ": " + ex);
try {
Thread.sleep(i * 500 + 1000);
} catch (InterruptedException exit) {
throw new ClientSideMetadataProviderException(exit);
}
} catch (KeeperException | InterruptedException | IOException ex) {
throw new ClientSideMetadataProviderException(ex);
} finally {
if (ownZooKeeper) {
try {
zooKeeper.close();
} catch (InterruptedException ex) {
throw new ClientSideMetadataProviderException(ex);
}
}
}
}
} finally {
if (ownZooKeeper) {
try {
zooKeeper.close();
} catch (InterruptedException ex) {
throw new ClientSideMetadataProviderException(ex);
}
}
}
throw new ClientSideMetadataProviderException("Could not find a server info for node " + nodeId + " in time");
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project herddb by diennea.
the class ZookeeperMetadataStorageManager method listNodes.
@Override
public List<NodeMetadata> listNodes() throws MetadataStorageManagerException {
try {
List<String> children = ensureZooKeeper().getChildren(nodesPath, mainWatcher, null);
LOGGER.severe("listNodes: for " + nodesPath + ": " + children);
List<NodeMetadata> result = new ArrayList<>();
for (String child : children) {
NodeMetadata nodeMetadata = getNode(child);
result.add(nodeMetadata);
}
return result;
} catch (IOException | InterruptedException | KeeperException err) {
handleSessionExpiredError(err);
throw new MetadataStorageManagerException(err);
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project herddb by diennea.
the class ZookeeperMetadataStorageManager method updateTableSpaceReplicaState.
@Override
public void updateTableSpaceReplicaState(TableSpaceReplicaState state) throws MetadataStorageManagerException {
try {
String tableSpacePath = tableSpacesReplicasPath + "/" + state.uuid;
byte[] data = state.serialize();
try {
ensureZooKeeper().setData(tableSpacePath + "/" + state.nodeId, data, -1);
} catch (KeeperException.NoNodeException notExists) {
try {
ensureZooKeeper().create(tableSpacePath, data, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
} catch (KeeperException.NodeExistsException existsRoot) {
}
ensureZooKeeper().create(tableSpacePath + "/" + state.nodeId, data, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
} catch (InterruptedException | KeeperException | IOException err) {
handleSessionExpiredError(err);
throw new MetadataStorageManagerException(err);
}
}
Aggregations