Search in sources :

Example 11 with ZkException

use of org.I0Itec.zkclient.exception.ZkException in project otter by alibaba.

the class LoadStageListener method stageChannged.

public void stageChannged(Long processId, List<String> stageNodes) {
    try {
        // 1. 根据pipelineId+processId构造对应的path
        String path = StagePathUtils.getProcess(getPipelineId(), processId);
        if (replyProcessIds.contains(processId)) {
            // 避免重复处理
            return;
        }
        // 2.2 判断是否存在了prev节点
        if (stageNodes.contains(prevNode)) {
            // 2.2.1 获取上一个节点的next node节点信息
            byte[] data = zookeeper.readData(path + "/" + prevNode);
            EtlEventData eventData = JsonUtils.unmarshalFromByte(data, EtlEventData.class);
            if (eventData.getNextNid().equals(ArbitrateConfigUtils.getCurrentNid())) {
                List<Long> currentProcessIds = stageMonitor.getCurrentProcessIds(false);
                if (currentProcessIds.contains(processId) && currentProcessIds.get(0).equals(processId)) {
                    // 判断是否是当前最小的processId节点,轮到自己处理了
                    // 添加到返回队列,唤醒wait阻塞
                    addReply(processId);
                }
            }
        }
    } catch (ZkNoNodeException e) {
    // 出现节点不存在,说明出现了error情况
    } catch (ZkException e) {
        logger.error("LoadStageListener", e);
    }
}
Also used : ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ZkException(org.I0Itec.zkclient.exception.ZkException) EtlEventData(com.alibaba.otter.shared.arbitrate.model.EtlEventData)

Example 12 with ZkException

use of org.I0Itec.zkclient.exception.ZkException in project otter by alibaba.

the class TransformStageListener method stageChannged.

public void stageChannged(Long processId, List<String> stageNodes) {
    try {
        // 1. 根据pipelineId+processId构造对应的path
        String path = StagePathUtils.getProcess(getPipelineId(), processId);
        // 2.1 判断是否存在了error节点,end节点或者current节点
        if (stageNodes.contains(currentNode)) {
            if (replyProcessIds.remove(processId)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("## remove reply id [{}]", processId);
                }
            }
            // 不需要监听了
            return;
        }
        if (replyProcessIds.contains(processId)) {
            // 避免重复处理
            return;
        }
        // 2.2 判断是否存在了prev节点
        if (stageNodes.contains(prevNode)) {
            // 2.2.1 获取上一个节点的next node节点信息
            byte[] data = zookeeper.readData(path + "/" + prevNode);
            EtlEventData eventData = JsonUtils.unmarshalFromByte(data, EtlEventData.class);
            if (eventData.getNextNid().equals(ArbitrateConfigUtils.getCurrentNid())) {
                // 添加到返回队列,唤醒wait阻塞
                addReply(processId);
            }
        }
    } catch (ZkNoNodeException e) {
    // 出现节点不存在,说明出现了error情况
    } catch (ZkException e) {
        logger.error("TransformStageListener", e);
    }
}
Also used : ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ZkException(org.I0Itec.zkclient.exception.ZkException) EtlEventData(com.alibaba.otter.shared.arbitrate.model.EtlEventData)

Example 13 with ZkException

use of org.I0Itec.zkclient.exception.ZkException in project otter by alibaba.

the class ExtractStageListener method stageChannged.

public void stageChannged(Long processId, List<String> stageNodes) {
    try {
        // 1. 根据pipelineId+processId构造对应的path
        String path = StagePathUtils.getProcess(getPipelineId(), processId);
        // 2.1 判断是否存在了current节点
        if (stageNodes.contains(currentNode)) {
            if (replyProcessIds.remove(processId)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("## remove reply id [{}]", processId);
                }
            }
            // 不需要监听了
            return;
        }
        if (replyProcessIds.contains(processId)) {
            // 避免重复处理
            return;
        }
        // 2.2 判断是否存在了prev节点
        if (stageNodes.contains(prevNode)) {
            // 2.2.1 获取上一个节点的next node节点信息
            byte[] data = zookeeper.readData(path + "/" + prevNode);
            EtlEventData eventData = JsonUtils.unmarshalFromByte(data, EtlEventData.class);
            if (eventData.getNextNid().equals(ArbitrateConfigUtils.getCurrentNid())) {
                // 添加到返回队列,唤醒wait阻塞
                addReply(processId);
            }
        }
    } catch (ZkNoNodeException e) {
    // 出现节点不存在,说明出现了error情况
    } catch (ZkException e) {
        logger.error("ExtractStageListener", e);
    }
}
Also used : ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ZkException(org.I0Itec.zkclient.exception.ZkException) EtlEventData(com.alibaba.otter.shared.arbitrate.model.EtlEventData)

Example 14 with ZkException

use of org.I0Itec.zkclient.exception.ZkException in project otter by alibaba.

the class SelectStageListener method recovery.

/**
 * 尝试载入一下上一次未使用的processId,可能发生mainstem切换,新的S模块需要感知前S模块已创建但未使用的process,不然就是一个死锁。而针对已经使用的processId会由e/t/l节点进行处理
 */
private void recovery(Long pipelineId) {
    List<Long> currentProcessIds = stageMonitor.getCurrentProcessIds(false);
    for (Long processId : currentProcessIds) {
        String path = StagePathUtils.getProcess(pipelineId, processId);
        try {
            byte[] bytes = zookeeper.readData(path);
            ProcessNodeEventData nodeData = JsonUtils.unmarshalFromByte(bytes, ProcessNodeEventData.class);
            if (nodeData.getStatus().isUnUsed()) {
                // 加入未使用的processId
                addReply(processId);
            }
        } catch (ZkException e) {
            logger.error("SelectStageListener", e);
        }
    }
}
Also used : ZkException(org.I0Itec.zkclient.exception.ZkException) ProcessNodeEventData(com.alibaba.otter.shared.arbitrate.model.ProcessNodeEventData)

Example 15 with ZkException

use of org.I0Itec.zkclient.exception.ZkException in project otter by alibaba.

the class ChannelArbitrateEvent method init.

/**
 * 初始化对应的channel节点,同步调用
 */
public void init(Long channelId) {
    String path = ManagePathUtils.getChannelByChannelId(channelId);
    // 初始化的数据对象
    byte[] data = JsonUtils.marshalToByte(ChannelStatus.STOP);
    try {
        zookeeper.create(path, data, CreateMode.PERSISTENT);
    } catch (ZkNodeExistsException e) {
    // 如果节点已经存在,则不抛异常
    // ignore
    } catch (ZkNoNodeException e) {
        // 创建父节点
        zookeeper.createPersistent(path, data, true);
    } catch (ZkException e) {
        throw new ArbitrateException("Channel_init", channelId.toString(), e);
    }
}
Also used : ZkNodeExistsException(org.I0Itec.zkclient.exception.ZkNodeExistsException) ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ZkException(org.I0Itec.zkclient.exception.ZkException) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Aggregations

ZkException (org.I0Itec.zkclient.exception.ZkException)41 ArbitrateException (com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)27 ZkNoNodeException (org.I0Itec.zkclient.exception.ZkNoNodeException)22 PermitMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor)7 EtlEventData (com.alibaba.otter.shared.arbitrate.model.EtlEventData)7 ZkNodeExistsException (org.I0Itec.zkclient.exception.ZkNodeExistsException)7 MainStemEventData (com.alibaba.otter.shared.arbitrate.model.MainStemEventData)5 ProcessNodeEventData (com.alibaba.otter.shared.arbitrate.model.ProcessNodeEventData)5 ChannelStatus (com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)5 IOException (java.io.IOException)4 Node (com.alibaba.otter.shared.common.model.config.node.Node)3 ArrayList (java.util.ArrayList)3 ZkInterruptedException (org.I0Itec.zkclient.exception.ZkInterruptedException)3 TerminMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.TerminMonitor)2 InetSocketAddress (java.net.InetSocketAddress)2 Date (java.util.Date)2 List (java.util.List)2 Lock (java.util.concurrent.locks.Lock)2 ReentrantLock (java.util.concurrent.locks.ReentrantLock)2 ZkBadVersionException (org.I0Itec.zkclient.exception.ZkBadVersionException)2