Search in sources :

Example 16 with ArbitrateException

use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException in project otter by alibaba.

the class NodeArbitrateEvent method liveNodes.

/**
     * 获取当前存活的节点列表
     */
public List<Long> liveNodes() {
    String path = ArbitrateConstants.NODE_NID_ROOT;
    try {
        List<String> nids = zookeeper.getChildren(path);
        List<Long> result = new ArrayList<Long>();
        for (String nid : nids) {
            result.add(Long.valueOf(nid));
        }
        return result;
    } catch (ZkException e) {
        throw new ArbitrateException("liveNodes", e);
    }
}
Also used : ZkException(org.I0Itec.zkclient.exception.ZkException) ArrayList(java.util.ArrayList) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Example 17 with ArbitrateException

use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException in project otter by alibaba.

the class PipelineArbitrateEvent method destory.

/**
     * 销毁对应的pipeline节点,同步调用
     */
public void destory(Long channelId, Long pipelineId) {
    String path = ManagePathUtils.getPipeline(channelId, pipelineId);
    String processRootPath = ManagePathUtils.getProcessRoot(channelId, pipelineId);
    String terminRootPath = ManagePathUtils.getTerminRoot(channelId, pipelineId);
    String remedyRootPath = ManagePathUtils.getRemedyRoot(channelId, pipelineId);
    String lockRootPath = ManagePathUtils.getLockRoot(channelId, pipelineId);
    String loadLockPath = lockRootPath + "/" + ArbitrateConstants.NODE_LOCK_LOAD;
    try {
        // 删除节点,不关心版本
        zookeeper.deleteRecursive(loadLockPath);
        // 删除节点,不关心版本
        zookeeper.deleteRecursive(lockRootPath);
        // 删除节点,不关心版本
        zookeeper.deleteRecursive(terminRootPath);
        // 删除节点,不关心版本
        zookeeper.deleteRecursive(remedyRootPath);
        // 删除节点,不关心版本
        zookeeper.deleteRecursive(processRootPath);
        // 删除节点,不关心版本
        zookeeper.deleteRecursive(path);
    } catch (ZkNoNodeException e) {
    // 如果节点已经不存在,则不抛异常
    // ignore
    } catch (ZkException e) {
        throw new ArbitrateException("Pipeline_destory", pipelineId.toString(), e);
    }
}
Also used : ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ZkException(org.I0Itec.zkclient.exception.ZkException) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Example 18 with ArbitrateException

use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException in project otter by alibaba.

the class ToolArbitrateEvent method listRemedyIndexs.

/**
     * 查询当前的remedy index记录
     */
public List<RemedyIndexEventData> listRemedyIndexs(Long pipelineId) {
    String path = StagePathUtils.getRemedyRoot(pipelineId);
    List<RemedyIndexEventData> datas = new ArrayList<RemedyIndexEventData>();
    try {
        List<String> nodes = zookeeper.getChildren(path);
        for (String node : nodes) {
            RemedyIndexEventData data = RemedyIndexEventData.parseNodeName(node);
            data.setPipelineId(pipelineId);
            datas.add(data);
        }
    } catch (ZkException e) {
        throw new ArbitrateException("listRemedyIndexs", pipelineId.toString(), e);
    }
    // 做一下排序
    Collections.sort(datas, new RemedyIndexComparator());
    return datas;
}
Also used : RemedyIndexEventData(com.alibaba.otter.shared.arbitrate.model.RemedyIndexEventData) ZkException(org.I0Itec.zkclient.exception.ZkException) RemedyIndexComparator(com.alibaba.otter.shared.arbitrate.impl.setl.helper.RemedyIndexComparator) ArrayList(java.util.ArrayList) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Example 19 with ArbitrateException

use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException in project otter by alibaba.

the class ZooKeeperx method retryOperation.

// =========================== helper method =============================
/**
     * 包装重试策略
     */
public <T> T retryOperation(ZooKeeperOperation<T> operation) throws KeeperException, InterruptedException {
    if (!running.get()) {
        throw new ArbitrateException("Zookeeper is destory ,should never be used ....");
    }
    KeeperException exception = null;
    for (int i = 0; i < maxRetry; i++) {
        // 获取版本
        int version = cversion.get();
        int retryCount = i + 1;
        try {
            if (!zookeeper.getState().isAlive()) {
                retryDelay(retryCount);
                cleanup(version);
            } else {
                return (T) operation.execute();
            }
        } catch (KeeperException.SessionExpiredException e) {
            logger.warn("Session expired for: " + this + " so reconnecting " + (i + 1) + " times due to: " + e, e);
            retryDelay(retryCount);
            cleanup(version);
        } catch (KeeperException.ConnectionLossException e) {
            // 特殊处理Connection Loss
            if (exception == null) {
                exception = e;
            }
            logger.warn("Attempt " + retryCount + " failed with connection loss so " + "attempting to reconnect: " + e, e);
            retryDelay(retryCount);
        }
    }
    throw exception;
}
Also used : ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException) KeeperException(org.apache.zookeeper.KeeperException)

Example 20 with ArbitrateException

use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException in project otter by alibaba.

the class SystemReduction method execute.

public void execute(@Param("command") String command, Context context) throws Exception {
    @SuppressWarnings("unchecked") String resultStr = "";
    if ("true".equals(command)) {
        List<Channel> channels = channelService.listAll();
        try {
            // 初始化根节点
            arbitrateManageService.systemEvent().init();
            // 遍历所有的Channel节点
            for (Channel channel : channels) {
                // 在ZK中初始化每个channel节点
                arbitrateManageService.channelEvent().init(channel.getId());
                // 在ZK中初始化该channel下的pipeline节点
                List<Pipeline> pipelines = channel.getPipelines();
                //
                for (Pipeline pipeline : pipelines) {
                    arbitrateManageService.pipelineEvent().init(pipeline.getChannelId(), pipeline.getId());
                }
            }
            resultStr = "恭喜!Zookeeper节点数据已经补全";
        } catch (ArbitrateException ae) {
            logger.error("ERROR ## init zookeeper has a problem ", ae);
            resultStr = "出错了!回复zookeeper的时候遇到问题!";
        } catch (Exception e) {
            logger.error("ERROR ## init zookeeper has a problem ", e);
            resultStr = "出错了!回复zookeeper的时候遇到问题!";
        }
    }
    context.put("resultStr", resultStr);
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)

Aggregations

ArbitrateException (com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)39 ZkException (org.I0Itec.zkclient.exception.ZkException)27 ZkNoNodeException (org.I0Itec.zkclient.exception.ZkNoNodeException)17 ChannelStatus (com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)8 ZkNodeExistsException (org.I0Itec.zkclient.exception.ZkNodeExistsException)7 PermitMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor)6 EtlEventData (com.alibaba.otter.shared.arbitrate.model.EtlEventData)6 Node (com.alibaba.otter.shared.common.model.config.node.Node)4 ArrayList (java.util.ArrayList)4 TerminMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.TerminMonitor)3 KeeperException (org.apache.zookeeper.KeeperException)3 Stat (org.apache.zookeeper.data.Stat)3 StageComparator (com.alibaba.otter.shared.arbitrate.impl.setl.helper.StageComparator)2 MainStemEventData (com.alibaba.otter.shared.arbitrate.model.MainStemEventData)2 TerminEventData (com.alibaba.otter.shared.arbitrate.model.TerminEventData)2 Channel (com.alibaba.otter.shared.common.model.config.channel.Channel)2 Date (java.util.Date)2 ZkBadVersionException (org.I0Itec.zkclient.exception.ZkBadVersionException)2 ErrorHandlerHelper (com.alibaba.citrus.webx.util.ErrorHandlerHelper)1 RemedyIndexComparator (com.alibaba.otter.shared.arbitrate.impl.setl.helper.RemedyIndexComparator)1