use of org.I0Itec.zkclient.exception.ZkException in project otter by alibaba.
the class ToolArbitrateEvent method listRemedyIndexs.
/**
* 查询当前的remedy index记录
*/
public List<RemedyIndexEventData> listRemedyIndexs(Long pipelineId) {
String path = StagePathUtils.getRemedyRoot(pipelineId);
List<RemedyIndexEventData> datas = new ArrayList<RemedyIndexEventData>();
try {
List<String> nodes = zookeeper.getChildren(path);
for (String node : nodes) {
RemedyIndexEventData data = RemedyIndexEventData.parseNodeName(node);
data.setPipelineId(pipelineId);
datas.add(data);
}
} catch (ZkException e) {
throw new ArbitrateException("listRemedyIndexs", pipelineId.toString(), e);
}
// 做一下排序
Collections.sort(datas, new RemedyIndexComparator());
return datas;
}
use of org.I0Itec.zkclient.exception.ZkException in project otter by alibaba.
the class NodeArbitrateEvent method liveNodes.
/**
* 获取当前存活的节点列表
*/
public List<Long> liveNodes() {
String path = ArbitrateConstants.NODE_NID_ROOT;
try {
List<String> nids = zookeeper.getChildren(path);
List<Long> result = new ArrayList<Long>();
for (String nid : nids) {
result.add(Long.valueOf(nid));
}
return result;
} catch (ZkException e) {
throw new ArbitrateException("liveNodes", e);
}
}
use of org.I0Itec.zkclient.exception.ZkException in project otter by alibaba.
the class PipelineArbitrateEvent method destory.
/**
* 销毁对应的pipeline节点,同步调用
*/
public void destory(Long channelId, Long pipelineId) {
String path = ManagePathUtils.getPipeline(channelId, pipelineId);
String processRootPath = ManagePathUtils.getProcessRoot(channelId, pipelineId);
String terminRootPath = ManagePathUtils.getTerminRoot(channelId, pipelineId);
String remedyRootPath = ManagePathUtils.getRemedyRoot(channelId, pipelineId);
String lockRootPath = ManagePathUtils.getLockRoot(channelId, pipelineId);
String loadLockPath = lockRootPath + "/" + ArbitrateConstants.NODE_LOCK_LOAD;
try {
// 删除节点,不关心版本
zookeeper.deleteRecursive(loadLockPath);
// 删除节点,不关心版本
zookeeper.deleteRecursive(lockRootPath);
// 删除节点,不关心版本
zookeeper.deleteRecursive(terminRootPath);
// 删除节点,不关心版本
zookeeper.deleteRecursive(remedyRootPath);
// 删除节点,不关心版本
zookeeper.deleteRecursive(processRootPath);
// 删除节点,不关心版本
zookeeper.deleteRecursive(path);
} catch (ZkNoNodeException e) {
// 如果节点已经不存在,则不抛异常
// ignore
} catch (ZkException e) {
throw new ArbitrateException("Pipeline_destory", pipelineId.toString(), e);
}
}
use of org.I0Itec.zkclient.exception.ZkException in project canal by alibaba.
the class ZooKeeperx method configMutliCluster.
// ===============================
public void configMutliCluster(ZooKeeper zk) {
if (_serversList.size() == 1) {
return;
}
String cluster1 = _serversList.get(0);
try {
if (_serversList.size() > 1) {
// 强制的声明accessible
ReflectionUtils.makeAccessible(clientCnxnField);
ReflectionUtils.makeAccessible(hostProviderField);
ReflectionUtils.makeAccessible(serverAddressesField);
// 添加第二组集群列表
for (int i = 1; i < _serversList.size(); i++) {
String cluster = _serversList.get(i);
// 强制获取zk中的地址信息
ClientCnxn cnxn = (ClientCnxn) ReflectionUtils.getField(clientCnxnField, zk);
HostProvider hostProvider = (HostProvider) ReflectionUtils.getField(hostProviderField, cnxn);
List<InetSocketAddress> serverAddrs = (List<InetSocketAddress>) ReflectionUtils.getField(serverAddressesField, hostProvider);
// 添加第二组集群列表
serverAddrs.addAll(new ConnectStringParser(cluster).getServerAddresses());
}
}
} catch (Exception e) {
try {
if (zk != null) {
zk.close();
}
} catch (InterruptedException ie) {
// ignore interrupt
}
throw new ZkException("zookeeper_create_error, serveraddrs=" + cluster1, e);
}
}
use of org.I0Itec.zkclient.exception.ZkException in project canal by alibaba.
the class ZooKeeperx method connect.
@Override
public void connect(Watcher watcher) {
ReflectionUtils.makeAccessible(zookeeperLockField);
ReflectionUtils.makeAccessible(zookeeperFiled);
Lock _zookeeperLock = (ReentrantLock) ReflectionUtils.getField(zookeeperLockField, this);
ZooKeeper _zk = (ZooKeeper) ReflectionUtils.getField(zookeeperFiled, this);
_zookeeperLock.lock();
try {
if (_zk != null) {
throw new IllegalStateException("zk client has already been started");
}
String zkServers = _serversList.get(0);
try {
logger.debug("Creating new ZookKeeper instance to connect to " + zkServers + ".");
_zk = new ZooKeeper(zkServers, _sessionTimeOut, watcher);
configMutliCluster(_zk);
ReflectionUtils.setField(zookeeperFiled, this, _zk);
} catch (IOException e) {
throw new ZkException("Unable to connect to " + zkServers, e);
}
} finally {
_zookeeperLock.unlock();
}
}
Aggregations