Search in sources :

Example 1 with Node

use of com.alibaba.otter.shared.common.model.config.node.Node in project otter by alibaba.

the class RoundRobinLoadBalance method next.

public Node next() throws InterruptedException {
    List<Node> nodes = getAliveNodes();
    if (nodes == null || nodes.size() == 0) {
        return null;
    }
    Long nid = ArbitrateConfigUtils.getCurrentNid();
    Node current = new Node();
    current.setId(nid);
    // 判断一下是否优先返回local
    boolean existLocal = nodes.remove(current);
    if (existLocal && nodes.size() == 0) {
        // 如果只有它自己
        return current;
    } else if (existLocal && RandomUtils.nextInt(100) < localPercent) {
        // 计算一下百分比
        return current;
    } else {
        int number = round.incrementAndGet();
        if (number > MAX_ROUND) {
            number = round.getAndSet(0);
        }
        int index = (int) (number % nodes.size());
        return nodes.get(index);
    }
}
Also used : Node(com.alibaba.otter.shared.common.model.config.node.Node)

Example 2 with Node

use of com.alibaba.otter.shared.common.model.config.node.Node 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);
    }
}
Also used : PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) Node(com.alibaba.otter.shared.common.model.config.node.Node) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus) EtlEventData(com.alibaba.otter.shared.arbitrate.model.EtlEventData)

Example 3 with Node

use of com.alibaba.otter.shared.common.model.config.node.Node in project otter by alibaba.

the class AbstractLoadBalance method getExtractAliveNodes.

public List<Node> getExtractAliveNodes() {
    Pipeline pipeline = ArbitrateConfigUtils.getPipeline(getPipelineId());
    List<Node> extractNodes = pipeline.getExtractNodes();
    List<Node> eNodes = new ArrayList<Node>();
    List<Long> aliveNodes = nodeMonitor.getAliveNodes();
    for (Node sourceNode : extractNodes) {
        if (aliveNodes.contains(sourceNode.getId())) {
            eNodes.add(sourceNode);
        }
    }
    return eNodes;
}
Also used : Node(com.alibaba.otter.shared.common.model.config.node.Node) ArrayList(java.util.ArrayList) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)

Example 4 with Node

use of com.alibaba.otter.shared.common.model.config.node.Node in project otter by alibaba.

the class AbstractLoadBalance method getTransformAliveNodes.

public List<Node> getTransformAliveNodes() {
    Pipeline pipeline = ArbitrateConfigUtils.getPipeline(getPipelineId());
    List<Node> transformNodes = pipeline.getLoadNodes();
    List<Node> tNodes = new ArrayList<Node>();
    List<Long> aliveNodes = nodeMonitor.getAliveNodes();
    for (Node sourceNode : transformNodes) {
        if (aliveNodes.contains(sourceNode.getId())) {
            tNodes.add(sourceNode);
        }
    }
    return tNodes;
}
Also used : Node(com.alibaba.otter.shared.common.model.config.node.Node) ArrayList(java.util.ArrayList) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)

Example 5 with Node

use of com.alibaba.otter.shared.common.model.config.node.Node in project otter by alibaba.

the class ConfigClientServiceImpl method afterPropertiesSet.

public void afterPropertiesSet() throws Exception {
    // 获取一下nid变量
    String nid = System.getProperty(NID_NAME);
    if (StringUtils.isEmpty(nid)) {
        throw new ConfigException("nid is not set!");
    }
    this.nid = Long.valueOf(nid);
    channelMapping = OtterMigrateMap.makeComputingMap(new Function<Long, Long>() {

        public Long apply(Long pipelineId) {
            // 处理下pipline -> channel映射关系不存在的情况
            FindChannelEvent event = new FindChannelEvent();
            event.setPipelineId(pipelineId);
            try {
                Object obj = nodeCommmunicationClient.callManager(event);
                if (obj != null && obj instanceof Channel) {
                    Channel channel = (Channel) obj;
                    // 排除下自己
                    updateMapping(channel, pipelineId);
                    // 更新下channelCache
                    channelCache.put(channel.getId(), channel);
                    return channel.getId();
                }
            } catch (Exception e) {
                logger.error("call_manager_error", event.toString(), e);
            }
            throw new ConfigException("No Such Channel by pipelineId[" + pipelineId + "]");
        }
    });
    nodeCache = new RefreshMemoryMirror<Long, Node>(timeout, new ComputeFunction<Long, Node>() {

        public Node apply(Long key, Node oldValue) {
            FindNodeEvent event = new FindNodeEvent();
            event.setNid(key);
            try {
                Object obj = nodeCommmunicationClient.callManager(event);
                if (obj != null && obj instanceof Node) {
                    return (Node) obj;
                } else {
                    throw new ConfigException("No Such Node by id[" + key + "]");
                }
            } catch (Exception e) {
                logger.error("call_manager_error", event.toString(), e);
            }
            // 其他情况直接返回内存中的旧值
            return oldValue;
        }
    });
    channelCache = new RefreshMemoryMirror<Long, Channel>(timeout, new ComputeFunction<Long, Channel>() {

        public Channel apply(Long key, Channel oldValue) {
            FindChannelEvent event = new FindChannelEvent();
            event.setChannelId(key);
            try {
                Object obj = nodeCommmunicationClient.callManager(event);
                if (obj != null && obj instanceof Channel) {
                    // 排除下自己
                    updateMapping((Channel) obj, null);
                    return (Channel) obj;
                } else {
                    throw new ConfigException("No Such Channel by pipelineId[" + key + "]");
                }
            } catch (Exception e) {
                logger.error("call_manager_error", event.toString(), e);
            }
            // 其他情况直接返回内存中的旧值
            return oldValue;
        }
    });
}
Also used : 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) ConfigException(com.alibaba.otter.shared.common.model.config.ConfigException) ConfigException(com.alibaba.otter.shared.common.model.config.ConfigException) Function(com.google.common.base.Function) ComputeFunction(com.alibaba.otter.shared.common.utils.cache.RefreshMemoryMirror.ComputeFunction) FindNodeEvent(com.alibaba.otter.shared.communication.model.config.FindNodeEvent) FindChannelEvent(com.alibaba.otter.shared.communication.model.config.FindChannelEvent)

Aggregations

Node (com.alibaba.otter.shared.common.model.config.node.Node)46 Pipeline (com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)22 ArrayList (java.util.ArrayList)13 Test (org.testng.annotations.Test)13 RepeatConfigureException (com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)10 Channel (com.alibaba.otter.shared.common.model.config.channel.Channel)8 ManagerException (com.alibaba.otter.manager.biz.common.exceptions.ManagerException)7 Mock (mockit.Mock)7 NodeParameter (com.alibaba.otter.shared.common.model.config.node.NodeParameter)5 PipelineNodeRelationDO (com.alibaba.otter.manager.biz.config.pipeline.dal.dataobject.PipelineNodeRelationDO)4 BaseOtterTest (com.alibaba.otter.node.common.BaseOtterTest)4 ArbitrateException (com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)4 PermitMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor)4 EtlEventData (com.alibaba.otter.shared.arbitrate.model.EtlEventData)4 AutoKeeperCluster (com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperCluster)4 ChannelStatus (com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)4 FindNodeEvent (com.alibaba.otter.shared.communication.model.config.FindNodeEvent)4 Identity (com.alibaba.otter.shared.etl.model.Identity)4 NodeTask (com.alibaba.otter.node.common.config.model.NodeTask)3 BaseOtterTest (com.alibaba.otter.node.etl.BaseOtterTest)3