Search in sources :

Example 16 with ZkException

use of org.I0Itec.zkclient.exception.ZkException 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 17 with ZkException

use of org.I0Itec.zkclient.exception.ZkException 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 18 with ZkException

use of org.I0Itec.zkclient.exception.ZkException 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 19 with ZkException

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

the class ZooKeeperx method configMutliCluster.

// ===============================
public void configMutliCluster(ZooKeeper zk) {
    if (_serversList.size() == 1) {
        return;
    }
    String cluster1 = _serversList.get(0);
    try {
        if (_serversList.size() > 1) {
            // 强制的声明accessible
            ReflectionUtils.makeAccessible(clientCnxnField);
            ReflectionUtils.makeAccessible(hostProviderField);
            ReflectionUtils.makeAccessible(serverAddressesField);
            // 添加第二组集群列表
            for (int i = 1; i < _serversList.size(); i++) {
                String cluster = _serversList.get(i);
                // 强制获取zk中的地址信息
                ClientCnxn cnxn = (ClientCnxn) ReflectionUtils.getField(clientCnxnField, zk);
                HostProvider hostProvider = (HostProvider) ReflectionUtils.getField(hostProviderField, cnxn);
                List<InetSocketAddress> serverAddrs = (List<InetSocketAddress>) ReflectionUtils.getField(serverAddressesField, hostProvider);
                // 添加第二组集群列表
                serverAddrs.addAll(new ConnectStringParser(cluster).getServerAddresses());
            }
        }
    } catch (Exception e) {
        try {
            if (zk != null) {
                zk.close();
            }
        } catch (InterruptedException ie) {
        // ignore interrupt
        }
        throw new ZkException("zookeeper_create_error, serveraddrs=" + cluster1, e);
    }
}
Also used : ConnectStringParser(org.apache.zookeeper.client.ConnectStringParser) ZkException(org.I0Itec.zkclient.exception.ZkException) InetSocketAddress(java.net.InetSocketAddress) StaticHostProvider(org.apache.zookeeper.client.StaticHostProvider) HostProvider(org.apache.zookeeper.client.HostProvider) List(java.util.List) ClientCnxn(org.apache.zookeeper.ClientCnxn) ZkException(org.I0Itec.zkclient.exception.ZkException) IOException(java.io.IOException)

Example 20 with ZkException

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

the class ZooKeeperx method connect.

@Override
public void connect(Watcher watcher) {
    ReflectionUtils.makeAccessible(zookeeperLockField);
    ReflectionUtils.makeAccessible(zookeeperFiled);
    Lock _zookeeperLock = (ReentrantLock) ReflectionUtils.getField(zookeeperLockField, this);
    ZooKeeper _zk = (ZooKeeper) ReflectionUtils.getField(zookeeperFiled, this);
    _zookeeperLock.lock();
    try {
        if (_zk != null) {
            throw new IllegalStateException("zk client has already been started");
        }
        String zkServers = _serversList.get(0);
        try {
            logger.debug("Creating new ZookKeeper instance to connect to " + zkServers + ".");
            _zk = new ZooKeeper(zkServers, _sessionTimeOut, watcher);
            configMutliCluster(_zk);
            ReflectionUtils.setField(zookeeperFiled, this, _zk);
        } catch (IOException e) {
            throw new ZkException("Unable to connect to " + zkServers, e);
        }
    } finally {
        _zookeeperLock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) ZooKeeper(org.apache.zookeeper.ZooKeeper) ZkException(org.I0Itec.zkclient.exception.ZkException) IOException(java.io.IOException) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

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