Search in sources :

Example 11 with Channel

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;
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) ArrayList(java.util.ArrayList) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus) ChannelDO(com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) InvalidConfigureException(com.alibaba.otter.manager.biz.common.exceptions.InvalidConfigureException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)

Example 12 with Channel

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;
            }
        }
    });
}
Also used : ComputeFunction(com.alibaba.otter.shared.common.utils.cache.RefreshMemoryMirror.ComputeFunction) Function(com.google.common.base.Function) ComputeFunction(com.alibaba.otter.shared.common.utils.cache.RefreshMemoryMirror.ComputeFunction) Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) Node(com.alibaba.otter.shared.common.model.config.node.Node) MapMaker(com.google.common.collect.MapMaker) ConfigException(com.alibaba.otter.shared.common.model.config.ConfigException)

Example 13 with Channel

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);
        }
    }
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) NodeAlarmEvent(com.alibaba.otter.shared.communication.model.arbitrate.NodeAlarmEvent)

Example 14 with Channel

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;
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) ArrayList(java.util.ArrayList) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) InvalidConfigureException(com.alibaba.otter.manager.biz.common.exceptions.InvalidConfigureException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)

Example 15 with Channel

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;
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)

Aggregations

Channel (com.alibaba.otter.shared.common.model.config.channel.Channel)77 Pipeline (com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)38 Mock (mockit.Mock)16 ArrayList (java.util.ArrayList)13 ManagerException (com.alibaba.otter.manager.biz.common.exceptions.ManagerException)10 RepeatConfigureException (com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)10 ChannelArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.manage.ChannelArbitrateEvent)10 BeforeClass (org.testng.annotations.BeforeClass)10 PipelineArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.manage.PipelineArbitrateEvent)9 InvalidConfigureException (com.alibaba.otter.manager.biz.common.exceptions.InvalidConfigureException)8 NodeArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent)8 Node (com.alibaba.otter.shared.common.model.config.node.Node)7 Event (com.alibaba.otter.shared.communication.core.model.Event)7 Test (org.testng.annotations.Test)7 ChannelStatus (com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)6 DataMediaPair (com.alibaba.otter.shared.common.model.config.data.DataMediaPair)6 HashMap (java.util.HashMap)6 ChannelDO (com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO)5 SystemParameter (com.alibaba.otter.shared.common.model.config.parameter.SystemParameter)5 Identity (com.alibaba.otter.shared.etl.model.Identity)5