use of com.alibaba.otter.shared.common.model.config.channel.Channel in project otter by alibaba.
the class ChannelServiceImpl method doToModelOnlyChannels.
private List<Channel> doToModelOnlyChannels(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());
}
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>();
channel.setPipelines(subPipelines);
channels.add(channel);
}
} catch (Exception e) {
logger.error("ERROR ## change the channels doToModelOnlyChannels has an exception");
throw new ManagerException(e);
}
return channels;
}
use of com.alibaba.otter.shared.common.model.config.channel.Channel in project otter by alibaba.
the class ArbitrateConfigImpl method afterPropertiesSet.
public void afterPropertiesSet() throws Exception {
// 获取一下nid变量
channelMapping = new MapMaker().makeComputingMap(new Function<Long, Long>() {
public Long apply(Long pipelineId) {
// 处理下pipline -> channel映射关系不存在的情况
Channel channel = channelService.findByPipelineId(pipelineId);
if (channel == null) {
throw new ConfigException("No Such Channel by pipelineId[" + pipelineId + "]");
}
// 排除下自己
updateMapping(channel, pipelineId);
// 更新下channelCache
channelCache.put(channel.getId(), channel);
return channel.getId();
}
});
channelCache = new RefreshMemoryMirror<Long, Channel>(timeout, new ComputeFunction<Long, Channel>() {
public Channel apply(Long key, Channel oldValue) {
Channel channel = channelService.findById(key);
if (channel == null) {
// 其他情况直接返回内存中的旧值
return oldValue;
} else {
// 排除下自己
updateMapping(channel, null);
return channel;
}
}
});
nodeCache = new RefreshMemoryMirror<Long, Node>(timeout, new ComputeFunction<Long, Node>() {
public Node apply(Long key, Node oldValue) {
Node node = nodeService.findById(key);
if (node == null) {
return oldValue;
} else {
return node;
}
}
});
}
use of com.alibaba.otter.shared.common.model.config.channel.Channel in project otter by alibaba.
the class DeadNodeListener method processDead.
private void processDead(Long deadNode) {
List<Long> aliveNodes = nodeMonitor.getAliveNodes(true);
// 需要考虑一种网络瞬断的情况,会导致node所有出现重连,导致出现restart风暴,执行restart时需要重新check下是否存活
if (aliveNodes.contains(deadNode)) {
logger.warn("dead node[{}] happend just one moment , check it's alived", deadNode);
return;
}
// 发送一条报警信息
List<Long> channelIds = Lists.newArrayList();
List<Channel> channels = channelService.listByNodeId(deadNode, ChannelStatus.START);
for (Channel channel : channels) {
channelIds.add(channel.getId());
}
Collections.sort(channelIds);
NodeAlarmEvent alarm = new NodeAlarmEvent();
alarm.setPipelineId(-1L);
alarm.setTitle(MonitorName.EXCEPTION.name());
alarm.setMessage(String.format("nid:%s is dead and restart cids:%s", String.valueOf(deadNode), channelIds.toString()));
try {
exceptionRuleMonitor.feed(alarm, alarm.getPipelineId());
} catch (Exception e) {
logger.error(String.format("ERROR # exceptionRuleMonitor error for %s", alarm.toString()), e);
}
for (Long channelId : channelIds) {
// 重启一下对应的channel
boolean result = arbitrateManageService.channelEvent().restart(channelId);
if (result) {
// 推送一下配置
channelService.notifyChannel(channelId);
}
}
}
use of com.alibaba.otter.shared.common.model.config.channel.Channel in project otter by alibaba.
the class ChannelServiceImpl method listByNodeId.
/**
* 根据NodeId和Channel状态找到对应的Channel列表。
*/
public List<Channel> listByNodeId(Long nodeId, ChannelStatus... statuses) {
List<Channel> channels = new ArrayList<Channel>();
List<Channel> results = new ArrayList<Channel>();
try {
List<Pipeline> pipelines = pipelineService.listByNodeId(nodeId);
List<Long> pipelineIds = new ArrayList<Long>();
for (Pipeline pipeline : pipelines) {
pipelineIds.add(pipeline.getId());
}
if (pipelineIds.isEmpty()) {
// 没有关联任务直接返回
return channels;
}
// 反查对应的channel
channels = listByPipelineIds(pipelineIds.toArray(new Long[pipelineIds.size()]));
if (null == statuses || statuses.length == 0) {
return channels;
}
for (Channel channel : channels) {
for (ChannelStatus status : statuses) {
if (channel.getStatus().equals(status)) {
results.add(channel);
}
}
}
} catch (Exception e) {
logger.error("ERROR ## list query channel by nodeId:" + nodeId + " has an exception!");
throw new ManagerException(e);
}
return results;
}
use of com.alibaba.otter.shared.common.model.config.channel.Channel in project otter by alibaba.
the class ChannelServiceImpl method findByPipelineId.
/*--------------------外部关联查询Channel-----------------------*/
/**
* <pre>
* 根据PipelineID找到对应的Channel
* 优化设想:
* 应该通过变长参数达到后期扩展的方便性
* </pre>
*/
public Channel findByPipelineId(Long pipelineId) {
Pipeline pipeline = pipelineService.findById(pipelineId);
Channel channel = findById(pipeline.getChannelId());
return channel;
}
Aggregations