use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException 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 com.alibaba.otter.shared.arbitrate.exception.ArbitrateException 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 com.alibaba.otter.shared.arbitrate.exception.ArbitrateException 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 com.alibaba.otter.shared.arbitrate.exception.ArbitrateException in project otter by alibaba.
the class ZooKeeperx method retryOperation.
// =========================== helper method =============================
/**
* 包装重试策略
*/
public <T> T retryOperation(ZooKeeperOperation<T> operation) throws KeeperException, InterruptedException {
if (!running.get()) {
throw new ArbitrateException("Zookeeper is destory ,should never be used ....");
}
KeeperException exception = null;
for (int i = 0; i < maxRetry; i++) {
// 获取版本
int version = cversion.get();
int retryCount = i + 1;
try {
if (!zookeeper.getState().isAlive()) {
retryDelay(retryCount);
cleanup(version);
} else {
return (T) operation.execute();
}
} catch (KeeperException.SessionExpiredException e) {
logger.warn("Session expired for: " + this + " so reconnecting " + (i + 1) + " times due to: " + e, e);
retryDelay(retryCount);
cleanup(version);
} catch (KeeperException.ConnectionLossException e) {
// 特殊处理Connection Loss
if (exception == null) {
exception = e;
}
logger.warn("Attempt " + retryCount + " failed with connection loss so " + "attempting to reconnect: " + e, e);
retryDelay(retryCount);
}
}
throw exception;
}
use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException in project otter by alibaba.
the class SystemReduction method execute.
public void execute(@Param("command") String command, Context context) throws Exception {
@SuppressWarnings("unchecked") String resultStr = "";
if ("true".equals(command)) {
List<Channel> channels = channelService.listAll();
try {
// 初始化根节点
arbitrateManageService.systemEvent().init();
// 遍历所有的Channel节点
for (Channel channel : channels) {
// 在ZK中初始化每个channel节点
arbitrateManageService.channelEvent().init(channel.getId());
// 在ZK中初始化该channel下的pipeline节点
List<Pipeline> pipelines = channel.getPipelines();
//
for (Pipeline pipeline : pipelines) {
arbitrateManageService.pipelineEvent().init(pipeline.getChannelId(), pipeline.getId());
}
}
resultStr = "恭喜!Zookeeper节点数据已经补全";
} catch (ArbitrateException ae) {
logger.error("ERROR ## init zookeeper has a problem ", ae);
resultStr = "出错了!回复zookeeper的时候遇到问题!";
} catch (Exception e) {
logger.error("ERROR ## init zookeeper has a problem ", e);
resultStr = "出错了!回复zookeeper的时候遇到问题!";
}
}
context.put("resultStr", resultStr);
}
Aggregations