Search in sources :

Example 36 with ZkException

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

the class SystemArbitrateEvent method destory.

/**
 * 销毁对应的系统节点,同步调用
 */
public void destory() {
    String rootPath = ManagePathUtils.getRoot();
    String channelRootPath = ManagePathUtils.getChannelRoot();
    String nodeRootPath = ManagePathUtils.getNodeRoot();
    try {
        // 删除节点,不关心版本
        zookeeper.deleteRecursive(channelRootPath);
        // 删除节点,不关心版本
        zookeeper.deleteRecursive(nodeRootPath);
        // 删除节点,不关心版本
        zookeeper.deleteRecursive(rootPath);
    } catch (ZkNoNodeException e) {
    // 如果节点已经不存在,则不抛异常
    // ignore
    } catch (ZkException e) {
        throw new ArbitrateException("system_destory", e);
    }
}
Also used : ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ZkException(org.I0Itec.zkclient.exception.ZkException) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Example 37 with ZkException

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

the class SystemArbitrateEvent method init.

/**
 * 初始化对应的系统节点,同步调用
 */
public void init() {
    String rootPath = ManagePathUtils.getRoot();
    String channelRootPath = ManagePathUtils.getChannelRoot();
    String nodeRootPath = ManagePathUtils.getNodeRoot();
    try {
        zookeeper.create(rootPath, new byte[0], CreateMode.PERSISTENT);
        zookeeper.create(channelRootPath, new byte[0], CreateMode.PERSISTENT);
        zookeeper.create(nodeRootPath, new byte[0], CreateMode.PERSISTENT);
    } catch (ZkNodeExistsException e) {
    // 如果节点已经存在,则不抛异常
    // ignore
    } catch (ZkException e) {
        throw new ArbitrateException("system_init", e);
    }
}
Also used : ZkNodeExistsException(org.I0Itec.zkclient.exception.ZkNodeExistsException) ZkException(org.I0Itec.zkclient.exception.ZkException) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Example 38 with ZkException

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

the class SystemArbitrateEvent method switchWarmup.

/**
 * 手工触发一次主备切换
 */
public void switchWarmup(Long channelId, Long pipelineId) {
    String path = ManagePathUtils.getMainStem(channelId, pipelineId);
    try {
        while (true) {
            Stat stat = new Stat();
            byte[] bytes = zookeeper.readData(path, stat);
            MainStemEventData mainStemData = JsonUtils.unmarshalFromByte(bytes, MainStemEventData.class);
            mainStemData.setActive(false);
            try {
                zookeeper.writeData(path, JsonUtils.marshalToByte(mainStemData), stat.getVersion());
                logger.warn("relase channelId[{}],pipelineId[{}] mainstem successed! ", channelId, pipelineId);
                break;
            } catch (ZkBadVersionException e) {
            // ignore , retrying
            }
        }
    } catch (ZkNoNodeException e) {
    // ignore
    } catch (ZkException e) {
        throw new ArbitrateException("releaseMainStem", pipelineId.toString(), e);
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ZkException(org.I0Itec.zkclient.exception.ZkException) MainStemEventData(com.alibaba.otter.shared.arbitrate.model.MainStemEventData) ZkBadVersionException(org.I0Itec.zkclient.exception.ZkBadVersionException) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Example 39 with ZkException

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

the class PipelineArbitrateEvent method init.

/**
 * 初始化对应的pipeline节点,同步调用
 */
public void init(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.createPersistent(path, true);
        zookeeper.create(processRootPath, new byte[0], CreateMode.PERSISTENT);
        zookeeper.create(terminRootPath, new byte[0], CreateMode.PERSISTENT);
        zookeeper.create(remedyRootPath, new byte[0], CreateMode.PERSISTENT);
        zookeeper.create(lockRootPath, new byte[0], CreateMode.PERSISTENT);
        zookeeper.create(loadLockPath, new byte[0], CreateMode.PERSISTENT);
    } catch (ZkNodeExistsException e) {
    // 如果节点已经存在,则不抛异常
    // ignore
    } catch (ZkException e) {
        throw new ArbitrateException("Pipeline_init", pipelineId.toString(), e);
    }
}
Also used : ZkNodeExistsException(org.I0Itec.zkclient.exception.ZkNodeExistsException) ZkException(org.I0Itec.zkclient.exception.ZkException) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Example 40 with ZkException

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

the class ToolArbitrateEvent method fetch.

/**
 * 提供数据接口获取对应pipeline上的状态
 */
public SyncStatusEventData fetch(Long pipelineId) {
    String path = StagePathUtils.getPipeline(pipelineId);
    try {
        byte[] bytes = zookeeper.readData(path);
        if (bytes == null || bytes.length == 0) {
            SyncStatusEventData evnetData = new SyncStatusEventData();
            evnetData.setPipelineId(pipelineId);
            return evnetData;
        } else {
            return JsonUtils.unmarshalFromByte(bytes, SyncStatusEventData.class);
        }
    } catch (ZkException e) {
        // 没有节点返回空
        throw new ArbitrateException("fetch_SyncStatus", pipelineId.toString(), e);
    }
}
Also used : ZkException(org.I0Itec.zkclient.exception.ZkException) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException) SyncStatusEventData(com.alibaba.otter.shared.arbitrate.model.SyncStatusEventData)

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