use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException in project otter by alibaba.
the class ExtractRpcArbitrateEvent method await.
public EtlEventData await(Long pipelineId) throws InterruptedException {
Assert.notNull(pipelineId);
PermitMonitor permitMonitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
// 阻塞等待授权
permitMonitor.waitForPermit();
RpcStageController stageController = ArbitrateFactory.getInstance(pipelineId, RpcStageController.class);
// 符合条件的processId
Long processId = stageController.waitForProcess(StageType.EXTRACT);
ChannelStatus status = permitMonitor.getChannelPermit();
if (status.isStart() || status.isPause()) {
// pause状态也让其处理,避免误删除pause状态的processId,导致通道挂起
EtlEventData eventData = stageController.getLastData(processId);
// 获取下一个处理节点信息
Node node = LoadBalanceFactory.getNextTransformNode(pipelineId);
if (node == null) {
// 没有后端节点
throw new ArbitrateException("Extract_single", "no next node");
} else {
eventData.setNextNid(node.getId());
// 只有这一条路返回
return eventData;
}
} else {
logger.warn("pipelineId[{}] extract ignore processId[{}] by status[{}]", new Object[] { pipelineId, processId, status });
String path = StagePathUtils.getProcess(pipelineId, processId);
zookeeper.exists(path);
// 递归调用
return await(pipelineId);
}
}
use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException in project otter by alibaba.
the class ChannelArbitrateEvent method init.
/**
* 初始化对应的channel节点,同步调用
*/
public void init(Long channelId) {
String path = ManagePathUtils.getChannelByChannelId(channelId);
// 初始化的数据对象
byte[] data = JsonUtils.marshalToByte(ChannelStatus.STOP);
try {
zookeeper.create(path, data, CreateMode.PERSISTENT);
} catch (ZkNodeExistsException e) {
// 如果节点已经存在,则不抛异常
// ignore
} catch (ZkNoNodeException e) {
//创建父节点
zookeeper.createPersistent(path, data, true);
} catch (ZkException e) {
throw new ArbitrateException("Channel_init", channelId.toString(), e);
}
}
use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException in project otter by alibaba.
the class ChannelArbitrateEvent method pause.
/**
* 停止对应的channel同步,是个异步调用
*/
public boolean pause(Long channelId, boolean needTermin) {
ChannelStatus currstatus = status(channelId);
boolean status = false;
boolean result = !needTermin;
if (currstatus.isStart()) {
// stop的优先级高于pause,这里只针对start状态进行状态更新
updateStatus(channelId, ChannelStatus.PAUSE);
// 避免stop时发生rollback报警
status = true;
}
if (needTermin) {
try {
// 调用termin进行关闭
result |= termin(channelId, TerminType.ROLLBACK);
} catch (Throwable e) {
// 出错了,直接挂起
updateStatus(channelId, ChannelStatus.PAUSE);
throw new ArbitrateException(e);
}
}
return result && status;
}
use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException in project otter by alibaba.
the class ChannelArbitrateEvent method restart.
/**
* 停止对应的channel同步,是个异步调用
*/
public boolean restart(final Long channelId, boolean needTermin) {
boolean result = !needTermin;
boolean status = false;
if (status(channelId).isStop() == false) {
// stop的优先级高于pause
updateStatus(channelId, ChannelStatus.PAUSE);
status = true;
}
if (needTermin) {
try {
result |= termin(channelId, TerminType.RESTART);
} catch (Throwable e) {
// 出错了,直接挂起
updateStatus(channelId, ChannelStatus.PAUSE);
throw new ArbitrateException(e);
}
}
// 处理一下重启操作,只处理pause状态
if (status || result) {
// 异步启动
arbitrateExecutor.submit(new Runnable() {
public void run() {
// sleep一段时间,保证rollback信息有足够的时间能被处理完成
try {
Thread.sleep(5000L + RandomUtils.nextInt(2000));
} catch (InterruptedException e) {
// ignore
}
Channel channel = ArbitrateConfigUtils.getChannelByChannelId(channelId);
ChannelStatus status = status(channel.getId());
if (status.isStop()) {
// stop优先级最高,不允许自动重启
logger.info("channel[{}] is already stop , restart is ignored", channel.getId());
} else if (canStart(channel)) {
// 出现stop,就不允许进行自动重启,stop优先级最高
start(channelId);
}
}
});
}
return result && status;
}
use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException in project otter by alibaba.
the class ChannelArbitrateEvent method stop.
/**
* 停止对应的channel同步,是个异步调用
*/
public boolean stop(Long channelId, boolean needTermin) {
// stop优先级高于pause
updateStatus(channelId, ChannelStatus.STOP);
boolean result = !needTermin;
if (needTermin) {
try {
result |= termin(channelId, TerminType.SHUTDOWN);
} catch (Throwable e) {
// 出错了,直接挂起
updateStatus(channelId, ChannelStatus.STOP);
throw new ArbitrateException(e);
}
}
return result;
}
Aggregations