use of org.I0Itec.zkclient.exception.ZkException in project otter by alibaba.
the class SystemArbitrateEvent method destory.
/**
* 销毁对应的系统节点,同步调用
*/
public void destory() {
String rootPath = ManagePathUtils.getRoot();
String channelRootPath = ManagePathUtils.getChannelRoot();
String nodeRootPath = ManagePathUtils.getNodeRoot();
try {
// 删除节点,不关心版本
zookeeper.deleteRecursive(channelRootPath);
// 删除节点,不关心版本
zookeeper.deleteRecursive(nodeRootPath);
// 删除节点,不关心版本
zookeeper.deleteRecursive(rootPath);
} catch (ZkNoNodeException e) {
// 如果节点已经不存在,则不抛异常
// ignore
} catch (ZkException e) {
throw new ArbitrateException("system_destory", e);
}
}
use of org.I0Itec.zkclient.exception.ZkException in project otter by alibaba.
the class SystemArbitrateEvent method init.
/**
* 初始化对应的系统节点,同步调用
*/
public void init() {
String rootPath = ManagePathUtils.getRoot();
String channelRootPath = ManagePathUtils.getChannelRoot();
String nodeRootPath = ManagePathUtils.getNodeRoot();
try {
zookeeper.create(rootPath, new byte[0], CreateMode.PERSISTENT);
zookeeper.create(channelRootPath, new byte[0], CreateMode.PERSISTENT);
zookeeper.create(nodeRootPath, new byte[0], CreateMode.PERSISTENT);
} catch (ZkNodeExistsException e) {
// 如果节点已经存在,则不抛异常
// ignore
} catch (ZkException e) {
throw new ArbitrateException("system_init", e);
}
}
use of org.I0Itec.zkclient.exception.ZkException in project otter by alibaba.
the class SystemArbitrateEvent method switchWarmup.
/**
* 手工触发一次主备切换
*/
public void switchWarmup(Long channelId, Long pipelineId) {
String path = ManagePathUtils.getMainStem(channelId, pipelineId);
try {
while (true) {
Stat stat = new Stat();
byte[] bytes = zookeeper.readData(path, stat);
MainStemEventData mainStemData = JsonUtils.unmarshalFromByte(bytes, MainStemEventData.class);
mainStemData.setActive(false);
try {
zookeeper.writeData(path, JsonUtils.marshalToByte(mainStemData), stat.getVersion());
logger.warn("relase channelId[{}],pipelineId[{}] mainstem successed! ", channelId, pipelineId);
break;
} catch (ZkBadVersionException e) {
// ignore , retrying
}
}
} catch (ZkNoNodeException e) {
// ignore
} catch (ZkException e) {
throw new ArbitrateException("releaseMainStem", pipelineId.toString(), e);
}
}
use of org.I0Itec.zkclient.exception.ZkException in project otter by alibaba.
the class PipelineArbitrateEvent method init.
/**
* 初始化对应的pipeline节点,同步调用
*/
public void init(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.createPersistent(path, true);
zookeeper.create(processRootPath, new byte[0], CreateMode.PERSISTENT);
zookeeper.create(terminRootPath, new byte[0], CreateMode.PERSISTENT);
zookeeper.create(remedyRootPath, new byte[0], CreateMode.PERSISTENT);
zookeeper.create(lockRootPath, new byte[0], CreateMode.PERSISTENT);
zookeeper.create(loadLockPath, new byte[0], CreateMode.PERSISTENT);
} catch (ZkNodeExistsException e) {
// 如果节点已经存在,则不抛异常
// ignore
} catch (ZkException e) {
throw new ArbitrateException("Pipeline_init", pipelineId.toString(), e);
}
}
use of org.I0Itec.zkclient.exception.ZkException in project otter by alibaba.
the class ToolArbitrateEvent method fetch.
/**
* 提供数据接口获取对应pipeline上的状态
*/
public SyncStatusEventData fetch(Long pipelineId) {
String path = StagePathUtils.getPipeline(pipelineId);
try {
byte[] bytes = zookeeper.readData(path);
if (bytes == null || bytes.length == 0) {
SyncStatusEventData evnetData = new SyncStatusEventData();
evnetData.setPipelineId(pipelineId);
return evnetData;
} else {
return JsonUtils.unmarshalFromByte(bytes, SyncStatusEventData.class);
}
} catch (ZkException e) {
// 没有节点返回空
throw new ArbitrateException("fetch_SyncStatus", pipelineId.toString(), e);
}
}
Aggregations