use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException in project otter by alibaba.
the class PrepareExceptionValve method invoke.
@Override
public void invoke(PipelineContext pipelineContext) throws Exception {
//
clearBuffer(response);
Exception e = (Exception) pipelineContext.getAttribute("exception");
log.error(e.getMessage(), e);
Throwable cause = e.getCause();
if (cause != null && cause instanceof ArbitrateException) {
e = (ArbitrateException) cause;
}
ErrorHandlerHelper errorHandlerHelper = ErrorHandlerHelper.getInstance(request);
errorHandlerHelper.setException(e);
pipelineContext.invokeNext();
}
use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException in project otter by alibaba.
the class ErrorTerminProcess method process.
public boolean process(TerminEventData data) {
DistributedLock lock = new DistributedLock(StagePathUtils.getLoadLock(data.getPipelineId()));
try {
// 尝试进行锁定,等待当前的load操作完成
boolean locked = lock.tryLock();
if (!locked) {
return false;
}
processChain(data);
return true;
} catch (KeeperException e) {
throw new ArbitrateException("Termin_process", e);
} finally {
try {
// 马上进行释放
lock.unlock();
} catch (KeeperException e1) {
// ignore
}
}
}
use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException in project otter by alibaba.
the class ErrorTerminProcess method processChain.
public void processChain(TerminEventData data) {
// 关闭对应的服务
Long pipelineId = data.getPipelineId();
// 清理对应的process
String processRoot = StagePathUtils.getProcessRoot(pipelineId);
try {
List<String> processNodes = zookeeper.getChildren(processRoot);
// 3. 循环处理每个process
List<Long> processIds = new ArrayList<Long>();
for (String process : processNodes) {
processIds.add(StagePathUtils.getProcessId(process));
}
// 排序一下
Collections.sort(processIds);
Long processId = data.getProcessId();
if (processId != null) {
// 可能为空
normalTerminProcess.process(data);
}
for (Long currProcessId : processIds) {
if (processId != null && currProcessId <= processId) {
continue;
}
// 发送给最小的一个process的termin信号,进行链式的触发
data.setProcessId(currProcessId);
// 处理异常信息
processChain(data);
break;
}
} catch (ZkException e) {
throw new ArbitrateException("Termin_process", e);
}
}
use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException in project otter by alibaba.
the class NormalTerminProcess method createTermin.
private boolean createTermin(TerminEventData data, Long pipelineId, Long processId) {
// 1. 创建end节点
String path = StagePathUtils.getTermin(pipelineId, processId);
data.setCurrNid(ArbitrateConfigUtils.getCurrentNid());
// 序列化
byte[] bytes = JsonUtils.marshalToByte(data);
try {
zookeeper.create(path, bytes, CreateMode.PERSISTENT);
} catch (ZkNodeExistsException e) {
// ignore
return false;
} catch (ZkException e) {
throw new ArbitrateException("Termin_single", e);
}
return true;
}
use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException in project otter by alibaba.
the class NormalTerminProcess method doProcess.
private boolean doProcess(TerminEventData data, boolean retry) {
Long pipelineId = data.getPipelineId();
Long processId = data.getProcessId();
List<String> currentStages = null;
try {
currentStages = zookeeper.getChildren(StagePathUtils.getProcess(pipelineId, processId));
Collections.sort(currentStages, new StageComparator());
} catch (ZkNoNodeException e) {
// ignore,说明节点已经被删除了
return false;
} catch (ZkException e) {
throw new ArbitrateException("Termin_process", e);
}
// s节点
if (currentStages == null || currentStages.contains(ArbitrateConstants.NODE_SELECTED)) {
try {
boolean successed = zookeeper.delete(StagePathUtils.getSelectStage(pipelineId, processId));
if (!successed) {
processDeleteFailed();
}
} catch (ZkException e) {
throw new ArbitrateException("Termin_process", e);
}
}
// e节点
if (currentStages == null || currentStages.contains(ArbitrateConstants.NODE_EXTRACTED)) {
try {
boolean successed = zookeeper.delete(StagePathUtils.getExtractStage(pipelineId, processId));
if (!successed) {
processDeleteFailed();
}
} catch (ZkException e) {
throw new ArbitrateException("Termin_process", e);
}
}
// t节点
if (currentStages == null || currentStages.contains(ArbitrateConstants.NODE_TRANSFORMED)) {
try {
boolean successed = zookeeper.delete(StagePathUtils.getTransformStage(pipelineId, processId));
if (!successed) {
processDeleteFailed();
}
} catch (ZkException e) {
throw new ArbitrateException("Termin_process", e);
}
}
// 不过会有遗漏判断,比如并发时都是一个线程全删除成功
return processDelete(data, CollectionUtils.isEmpty(currentStages), retry);
}
Aggregations