Search in sources :

Example 1 with ChannelStatus

use of com.alibaba.otter.shared.common.model.config.channel.ChannelStatus in project otter by alibaba.

the class PipelineMonitor method explore.

@Override
public void explore(List<AlarmRule> rules) {
    Long pipelineId = rules.get(0).getPipelineId();
    Pipeline pipeline = pipelineService.findById(pipelineId);
    // 如果处于stop状态,则忽略报警
    ChannelStatus status = arbitrateManageService.channelEvent().status(pipeline.getChannelId());
    if (status == null || status.isStop()) {
        return;
    }
    List<AlarmRule> delayTimeRules = new LinkedList<AlarmRule>();
    List<AlarmRule> exceptonRules = new LinkedList<AlarmRule>();
    List<AlarmRule> pipelineTimeoutRules = new LinkedList<AlarmRule>();
    List<AlarmRule> processTimeoutRules = new LinkedList<AlarmRule>();
    List<AlarmRule> positionTimeoutRules = new LinkedList<AlarmRule>();
    Date now = new Date();
    for (AlarmRule rule : rules) {
        switch(rule.getMonitorName()) {
            case DELAYTIME:
                if (checkEnable(rule, now)) {
                    delayTimeRules.add(rule);
                }
                break;
            case EXCEPTION:
                if (checkEnable(rule, now)) {
                    exceptonRules.add(rule);
                }
                break;
            case PIPELINETIMEOUT:
                if (checkEnable(rule, now)) {
                    pipelineTimeoutRules.add(rule);
                }
                break;
            case PROCESSTIMEOUT:
                if (checkEnable(rule, now)) {
                    processTimeoutRules.add(rule);
                }
                break;
            case POSITIONTIMEOUT:
                if (checkEnable(rule, now)) {
                    positionTimeoutRules.add(rule);
                }
                break;
            default:
                break;
        }
    }
    if (!delayTimeRules.isEmpty()) {
        delayStatRuleMonitor.explore(delayTimeRules);
    }
    if (!pipelineTimeoutRules.isEmpty()) {
        pipelineTimeoutRuleMonitor.explore(pipelineTimeoutRules);
    }
    if (!processTimeoutRules.isEmpty()) {
        processTimeoutRuleMonitor.explore(processTimeoutRules);
    }
    if (!positionTimeoutRules.isEmpty()) {
        positionTimeoutRuleMonitor.explore(positionTimeoutRules);
    }
}
Also used : AlarmRule(com.alibaba.otter.shared.common.model.config.alarm.AlarmRule) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus) LinkedList(java.util.LinkedList) Date(java.util.Date) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)

Example 2 with ChannelStatus

use of com.alibaba.otter.shared.common.model.config.channel.ChannelStatus in project otter by alibaba.

the class SelectZooKeeperArbitrateEvent method await.

// private TerminArbitrateEvent terminEvent;
/**
     * <pre>
     * 算法:
     * 1. 检查当前的Permit,阻塞等待其授权(解决Channel的pause状态处理)
     * 2. 开始阻塞获取符合条件的processId,创建空的EventData对象,添加next node信息后直接返回
     * </pre>
     */
public EtlEventData await(Long pipelineId) throws InterruptedException {
    Assert.notNull(pipelineId);
    PermitMonitor permitMonitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    // 阻塞等待授权
    permitMonitor.waitForPermit();
    SelectStageListener selectStageListener = ArbitrateFactory.getInstance(pipelineId, SelectStageListener.class);
    // 符合条件的processId
    Long processId = selectStageListener.waitForProcess();
    ChannelStatus status = permitMonitor.getChannelPermit();
    if (status.isStart()) {
        try {
            EtlEventData eventData = new EtlEventData();
            eventData.setPipelineId(pipelineId);
            eventData.setProcessId(processId);
            // 返回当前时间
            eventData.setStartTime(new Date().getTime());
            // 获取下一个处理节点信息
            Node node = LoadBalanceFactory.getNextExtractNode(pipelineId);
            if (node == null) {
                // terminEvent.single(termin);
                throw new ArbitrateException("Select_single", "no next node");
            } else {
                eventData.setNextNid(node.getId());
                // 标记为已使用
                markUsed(eventData);
                // 只有这一条路返回
                return eventData;
            }
        } catch (ZkNoNodeException e) {
            logger.error("pipeline[{}] processId[{}] is invalid , retry again", pipelineId, processId);
            // /出现节点不存在,说明出现了error情况,递归调用重新获取一次
            return await(pipelineId);
        } catch (ZkException e) {
            throw new ArbitrateException("Select_await", e.getMessage(), e);
        }
    } else {
        logger.warn("pipelineId[{}] select ignore processId[{}] by status[{}]", new Object[] { pipelineId, processId, status });
        // add by ljh 2013-02-01
        // 遇到一个bug:
        // a. 某台机器发起了一个RESTART指令,然后开始删除process列表
        // b. 此时另一个台机器(select工作节点),并没有收到PAUSE的推送,导致还会再创建一个process节点
        // c. 后续收到PAUSE指令后,丢弃了processId,就出现了unused的processId
        // 这里删除了,要考虑一个问题,就是和restart指令在并行删除同一个processId时的并发考虑,目前来看没问题
        String path = StagePathUtils.getProcess(pipelineId, processId);
        // 忽略删除失败
        zookeeper.delete(path);
        // 递归调用
        return await(pipelineId);
    }
}
Also used : ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ZkException(org.I0Itec.zkclient.exception.ZkException) SelectStageListener(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.SelectStageListener) 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) Date(java.util.Date) EtlEventData(com.alibaba.otter.shared.arbitrate.model.EtlEventData)

Example 3 with ChannelStatus

use of com.alibaba.otter.shared.common.model.config.channel.ChannelStatus in project otter by alibaba.

the class TransformZooKeeperArbitrateEvent method await.

/**
     * <pre>
     * 算法:
     * 1. 检查当前的Permit,阻塞等待其授权(解决Channel的pause状态处理)
     * 2. 开始阻塞获取符合条件的processId
     * 3. 检查当前的即时Permit状态 (在阻塞获取processId过程会出现一些error信号,process节点会被删除)
     * 4. 获取Select传递的EventData数据,添加next node信息后直接返回
     * </pre>
     * 
     * @return
     */
public EtlEventData await(Long pipelineId) throws InterruptedException {
    Assert.notNull(pipelineId);
    PermitMonitor permitMonitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    // 阻塞等待授权
    permitMonitor.waitForPermit();
    TransformStageListener transformStageListener = ArbitrateFactory.getInstance(pipelineId, TransformStageListener.class);
    // 符合条件的processId
    Long processId = transformStageListener.waitForProcess();
    ChannelStatus status = permitMonitor.getChannelPermit();
    if (status.isStart()) {
        // 即时查询一下当前的状态,状态随时可能会变
        // 根据pipelineId+processId构造对应的path
        String path = StagePathUtils.getExtractStage(pipelineId, processId);
        try {
            byte[] data = zookeeper.readData(path);
            EtlEventData eventData = JsonUtils.unmarshalFromByte(data, EtlEventData.class);
            // 下一个节点信息即为自己
            eventData.setNextNid(ArbitrateConfigUtils.getCurrentNid());
            // 只有这一条路返回
            return eventData;
        } catch (ZkNoNodeException e) {
            logger.error("pipeline[{}] processId[{}] is invalid , retry again", pipelineId, processId);
            // /出现节点不存在,说明出现了error情况,递归调用重新获取一次
            return await(pipelineId);
        } catch (ZkException e) {
            throw new ArbitrateException("transform_await", e.getMessage(), e);
        }
    } else {
        logger.info("pipelineId[{}] transform ignore processId[{}] by status[{}]", new Object[] { pipelineId, processId, status });
        // 递归调用
        return await(pipelineId);
    }
}
Also used : TransformStageListener(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.TransformStageListener) ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ZkException(org.I0Itec.zkclient.exception.ZkException) PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) 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 4 with ChannelStatus

use of com.alibaba.otter.shared.common.model.config.channel.ChannelStatus in project otter by alibaba.

the class MainstemMonitor method initMainstem.

public void initMainstem() {
    if (isStop()) {
        return;
    }
    PermitMonitor permitMonitor = ArbitrateFactory.getInstance(getPipelineId(), PermitMonitor.class);
    ChannelStatus status = permitMonitor.getChannelPermit(true);
    if (status.isStop()) {
        // 如果已经关闭则退出
        return;
    }
    Long nid = ArbitrateConfigUtils.getCurrentNid();
    String path = StagePathUtils.getMainStem(getPipelineId());
    MainStemEventData data = new MainStemEventData();
    data.setStatus(MainStemEventData.Status.TAKEING);
    data.setPipelineId(getPipelineId());
    // 设置当前的nid
    data.setNid(nid);
    // 序列化
    byte[] bytes = JsonUtils.marshalToByte(data);
    try {
        mutex.set(false);
        zookeeper.create(path, bytes, CreateMode.EPHEMERAL);
        activeData = data;
        // 触发一下事件
        processActiveEnter();
        mutex.set(true);
    } catch (ZkNodeExistsException e) {
        bytes = zookeeper.readData(path, true);
        if (bytes == null) {
            // 如果不存在节点,立即尝试一次
            initMainstem();
        } else {
            activeData = JsonUtils.unmarshalFromByte(bytes, MainStemEventData.class);
            if (nid.equals(activeData.getNid())) {
                // reload时会重复创建,如果是自己就触发一下
                mutex.set(true);
            }
        }
    }
}
Also used : ZkNodeExistsException(org.I0Itec.zkclient.exception.ZkNodeExistsException) MainStemEventData(com.alibaba.otter.shared.arbitrate.model.MainStemEventData) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)

Example 5 with ChannelStatus

use of com.alibaba.otter.shared.common.model.config.channel.ChannelStatus 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)

Aggregations

ChannelStatus (com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)30 PermitMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor)13 ArbitrateException (com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)8 ArrayList (java.util.ArrayList)8 EtlEventData (com.alibaba.otter.shared.arbitrate.model.EtlEventData)7 Pipeline (com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)7 Channel (com.alibaba.otter.shared.common.model.config.channel.Channel)6 Date (java.util.Date)5 ZkException (org.I0Itec.zkclient.exception.ZkException)5 ZkNoNodeException (org.I0Itec.zkclient.exception.ZkNoNodeException)5 InvalidConfigureException (com.alibaba.otter.manager.biz.common.exceptions.InvalidConfigureException)4 ManagerException (com.alibaba.otter.manager.biz.common.exceptions.ManagerException)4 RepeatConfigureException (com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)4 BaseEventTest (com.alibaba.otter.shared.arbitrate.BaseEventTest)4 MainStemEventData (com.alibaba.otter.shared.arbitrate.model.MainStemEventData)4 Node (com.alibaba.otter.shared.common.model.config.node.Node)4 Test (org.testng.annotations.Test)4 ChannelDO (com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO)3 HashMap (java.util.HashMap)3 SystemParameter (com.alibaba.otter.shared.common.model.config.parameter.SystemParameter)2