use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException in project otter by alibaba.
the class ChannelArbitrateEvent method status.
/**
* 查询当前channel的运行状态,是否同步调用
*/
public ChannelStatus status(Long channelId) {
String path = StagePathUtils.getChannelByChannelId(channelId);
byte[] data = null;
try {
data = zookeeper.readData(path);
} catch (ZkNoNodeException e) {
// ignore
return null;
} catch (ZkException e) {
throw new ArbitrateException("Channel_status", channelId.toString(), e);
}
return JsonUtils.unmarshalFromByte(data, ChannelStatus.class);
}
use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException 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 com.alibaba.otter.shared.arbitrate.exception.ArbitrateException 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 com.alibaba.otter.shared.arbitrate.exception.ArbitrateException 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 com.alibaba.otter.shared.arbitrate.exception.ArbitrateException 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);
}
}
Aggregations