use of com.alibaba.otter.shared.common.model.config.channel.Channel in project otter by alibaba.
the class TerminMemoryArbitrateEvent method single.
public void single(TerminEventData data) {
// 正向处理
final TerminType type = data.getType();
MemoryStageController stageController = ArbitrateFactory.getInstance(data.getPipelineId(), MemoryStageController.class);
if (type.isNormal()) {
Assert.notNull(data.getProcessId());
stageController.offerTermin(data);
} else if (type.isWarning()) {
// warn单独处理,不需要关闭相关的pipeline
warningTerminProcess.process(data);
} else {
// 内存版可以简化处理rollback/restart/shutdown模型,不需要进行process的termin操作处理
Channel channel = ArbitrateConfigUtils.getChannel(data.getPipelineId());
if (data.getType().isRollback()) {
boolean paused = channelEvent.pause(channel.getId(), false);
if (paused) {
// 如果pause成功,则发送报警信息
warningTerminProcess.process(data);
}
} else if (data.getType().isShutdown()) {
boolean shutdowned = channelEvent.stop(channel.getId(), false);
// 发送报警信息
if (shutdowned) {
warningTerminProcess.process(data);
}
// 发送关闭命令给manager
StopChannelEvent event = new StopChannelEvent();
event.setChannelId(channel.getId());
arbitrateCommmunicationClient.callManager(event);
} else if (data.getType().isRestart()) {
boolean restarted = channelEvent.restart(channel.getId(), false);
// 发送报警信息
if (restarted) {
warningTerminProcess.process(data);
}
}
// 内存中构造异常termin信号返回
stageController.termin(data.getType());
}
}
use of com.alibaba.otter.shared.common.model.config.channel.Channel 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.common.model.config.channel.Channel in project otter by alibaba.
the class ChannelArbitrateEvent method termin.
// ===================== help method =================
/**
* 执行结束同步任务操作
*/
private Boolean termin(Long channelId, final TerminType type) throws Exception {
Channel channel = ArbitrateConfigUtils.getChannelByChannelId(channelId);
List<Pipeline> pipelines = channel.getPipelines();
List<Future<Boolean>> futures = new ArrayList<Future<Boolean>>();
for (final Pipeline pipeline : pipelines) {
futures.add(arbitrateExecutor.submit(new Callable<Boolean>() {
public Boolean call() {
TerminEventData data = new TerminEventData();
data.setPipelineId(pipeline.getId());
data.setType(type);
data.setCode("channel");
data.setDesc(type.toString());
// 处理关闭
return errorTerminProcess.process(data);
}
}));
}
boolean result = false;
Exception exception = null;
int index = 0;
for (Future<Boolean> future : futures) {
try {
// 进行处理
result |= future.get();
} catch (InterruptedException e) {
// ignore
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
sendWarningMessage(pipelines.get(index).getId(), e);
exception = e;
}
index++;
}
if (exception != null) {
throw exception;
} else {
return result;
}
}
use of com.alibaba.otter.shared.common.model.config.channel.Channel in project otter by alibaba.
the class ChannelServiceImpl method doToModel.
/**
* <pre>
* 用于DO对象转化为Model对象
* 现阶段优化:
* 需要五次SQL交互:pipeline\node\dataMediaPair\dataMedia\dataMediaSource(五个层面)
* 目前优化方案为单层只执行一次SQL,避免重复循环造成IO及数据库查询开销
* 长期优化:
* 对SQL进行改造,尽量减小SQL调用次数
* </pre>
*
* @param channelDO
* @return Channel
*/
private Channel doToModel(ChannelDO channelDo) {
Channel channel = new Channel();
try {
channel.setId(channelDo.getId());
channel.setName(channelDo.getName());
channel.setDescription(channelDo.getDescription());
channel.setStatus(arbitrateManageService.channelEvent().status(channelDo.getId()));
channel.setParameters(channelDo.getParameters());
channel.setGmtCreate(channelDo.getGmtCreate());
channel.setGmtModified(channelDo.getGmtModified());
List<Pipeline> pipelines = pipelineService.listByChannelIds(channelDo.getId());
// 合并PipelineParameter和ChannelParameter
SystemParameter systemParameter = systemParameterService.find();
for (Pipeline pipeline : pipelines) {
PipelineParameter parameter = new PipelineParameter();
parameter.merge(systemParameter);
parameter.merge(channel.getParameters());
// 最后复制pipelineId参数
parameter.merge(pipeline.getParameters());
pipeline.setParameters(parameter);
// pipeline.getParameters().merge(channel.getParameters());
}
channel.setPipelines(pipelines);
} catch (Exception e) {
logger.error("ERROR ## change the channel DO to Model has an exception");
throw new ManagerException(e);
}
return channel;
}
use of com.alibaba.otter.shared.common.model.config.channel.Channel in project otter by alibaba.
the class ChannelServiceImpl method doToModel.
/**
* <pre>
* 用于DO对象数组转化为Model对象数组
* 现阶段优化:
* 需要五次SQL交互:pipeline\node\dataMediaPair\dataMedia\dataMediaSource(五个层面)
* 目前优化方案为单层只执行一次SQL,避免重复循环造成IO及数据库查询开销
* 长期优化:
* 对SQL进行改造,尽量减小SQL调用次数
* </pre>
*
* @param channelDO
* @return Channel
*/
private List<Channel> doToModel(List<ChannelDO> channelDos) {
List<Channel> channels = new ArrayList<Channel>();
try {
// 1.将ChannelID单独拿出来
List<Long> channelIds = new ArrayList<Long>();
for (ChannelDO channelDo : channelDos) {
channelIds.add(channelDo.getId());
}
Long[] idArray = new Long[channelIds.size()];
// 拿到所有的Pipeline进行ChannelID过滤,避免重复查询。
List<Pipeline> pipelines = pipelineService.listByChannelIds(channelIds.toArray(idArray));
SystemParameter systemParameter = systemParameterService.find();
for (ChannelDO channelDo : channelDos) {
Channel channel = new Channel();
channel.setId(channelDo.getId());
channel.setName(channelDo.getName());
channel.setDescription(channelDo.getDescription());
ChannelStatus channelStatus = arbitrateManageService.channelEvent().status(channelDo.getId());
channel.setStatus(null == channelStatus ? ChannelStatus.STOP : channelStatus);
channel.setParameters(channelDo.getParameters());
channel.setGmtCreate(channelDo.getGmtCreate());
channel.setGmtModified(channelDo.getGmtModified());
// 遍历,将该Channel节点下的Pipeline提取出来。
List<Pipeline> subPipelines = new ArrayList<Pipeline>();
for (Pipeline pipeline : pipelines) {
if (pipeline.getChannelId().equals(channelDo.getId())) {
// 合并PipelineParameter和ChannelParameter
PipelineParameter parameter = new PipelineParameter();
parameter.merge(systemParameter);
parameter.merge(channel.getParameters());
// 最后复制pipelineId参数
parameter.merge(pipeline.getParameters());
pipeline.setParameters(parameter);
subPipelines.add(pipeline);
}
}
channel.setPipelines(subPipelines);
channels.add(channel);
}
} catch (Exception e) {
logger.error("ERROR ## change the channels DO to Model has an exception");
throw new ManagerException(e);
}
return channels;
}
Aggregations