Search in sources :

Example 11 with PermitMonitor

use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor in project otter by alibaba.

the class TerminArbitrateEventTest method test_Rollback.

@Test
public void test_Rollback() {
    normalProcess();
    // 发送rollback信号
    TerminEventData rollback = new TerminEventData();
    rollback.setPipelineId(pipelineId);
    rollback.setType(TerminType.ROLLBACK);
    terminEvent.single(rollback);
    PermitMonitor monitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    want.bool(monitor.getChannelPermit().isPause()).is(true);
    destoryTermin();
    ArbitrateFactory.destory(pipelineId);
}
Also used : TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData) PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) Test(org.testng.annotations.Test) BaseArbitrateEventTest(com.alibaba.otter.shared.arbitrate.setl.event.BaseArbitrateEventTest)

Example 12 with PermitMonitor

use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor in project otter by alibaba.

the class PermitMonitorTest method testPermit_init_fail.

@Test
public void testPermit_init_fail() {
    // 测试下permit的初始化内容
    channelEvent.start(channelId);
    updateMainStem(pipelineId, MainStemEventData.Status.OVERTAKE);
    // 一个节点挂起
    updateMainStem(oppositePipelineId, MainStemEventData.Status.TAKEING);
    permitMonitor = new PermitMonitor(pipelineId);
    boolean isPermit = permitMonitor.isPermit();
    want.bool(isPermit).is(false);
}
Also used : PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) Test(org.testng.annotations.Test) BaseEventTest(com.alibaba.otter.shared.arbitrate.BaseEventTest)

Example 13 with PermitMonitor

use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor in project otter by alibaba.

the class PermitMonitorTest method testPermit_change.

@Test
public void testPermit_change() {
    channelEvent.start(channelId);
    updateMainStem(pipelineId, MainStemEventData.Status.OVERTAKE);
    // 一个节点挂起
    updateMainStem(oppositePipelineId, MainStemEventData.Status.TAKEING);
    permitMonitor = new PermitMonitor(pipelineId);
    boolean isPermit = permitMonitor.isPermit();
    want.bool(isPermit).is(false);
    updateMainStem(oppositePipelineId, MainStemEventData.Status.OVERTAKE);
    // 一个节点挂起
    updateMainStem(pipelineId, MainStemEventData.Status.TAKEING);
    // 需要sleep一下,保证数据已经更新到monitor上
    sleep();
    isPermit = permitMonitor.isPermit();
    want.bool(isPermit).is(false);
    updateMainStem(pipelineId, MainStemEventData.Status.OVERTAKE);
    // 需要sleep一下,保证数据已经更新到monitor上
    sleep();
    isPermit = permitMonitor.isPermit();
    want.bool(isPermit).is(true);
    MonitorScheduler.unRegister(permitMonitor);
}
Also used : PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) Test(org.testng.annotations.Test) BaseEventTest(com.alibaba.otter.shared.arbitrate.BaseEventTest)

Example 14 with PermitMonitor

use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor in project otter by alibaba.

the class SelectRpcArbitrateEvent method await.

public EtlEventData await(Long pipelineId) throws InterruptedException {
    Assert.notNull(pipelineId);
    PermitMonitor permitMonitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    // 阻塞等待授权
    permitMonitor.waitForPermit();
    SelectProcessListener selectProcessListener = ArbitrateFactory.getInstance(pipelineId, SelectProcessListener.class);
    // 符合条件的processId
    Long processId = selectProcessListener.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) PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) Node(com.alibaba.otter.shared.common.model.config.node.Node) SelectProcessListener(com.alibaba.otter.shared.arbitrate.impl.setl.rpc.monitor.SelectProcessListener) 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 15 with PermitMonitor

use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor in project otter by alibaba.

the class TransformRpcArbitrateEvent 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.TRANSFORM);
    ChannelStatus status = permitMonitor.getChannelPermit();
    if (status.isStart() || status.isPause()) {
        // pause状态也让其处理,避免误删除pause状态的processId,导致通道挂起
        EtlEventData eventData = stageController.getLastData(processId);
        // 下一个节点信息即为自己
        eventData.setNextNid(ArbitrateConfigUtils.getCurrentNid());
        return eventData;
    } else {
        logger.warn("pipelineId[{}] transform ignore processId[{}] by status[{}]", new Object[] { pipelineId, processId, status });
        // 递归调用
        return await(pipelineId);
    }
}
Also used : PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus) EtlEventData(com.alibaba.otter.shared.arbitrate.model.EtlEventData)

Aggregations

PermitMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor)30 Test (org.testng.annotations.Test)14 ChannelStatus (com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)13 TerminEventData (com.alibaba.otter.shared.arbitrate.model.TerminEventData)9 BaseEventTest (com.alibaba.otter.shared.arbitrate.BaseEventTest)8 EtlEventData (com.alibaba.otter.shared.arbitrate.model.EtlEventData)7 ZkException (org.I0Itec.zkclient.exception.ZkException)7 ArbitrateException (com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)6 BaseArbitrateEventTest (com.alibaba.otter.shared.arbitrate.setl.event.BaseArbitrateEventTest)6 ZkNoNodeException (org.I0Itec.zkclient.exception.ZkNoNodeException)5 MainStemEventData (com.alibaba.otter.shared.arbitrate.model.MainStemEventData)4 Node (com.alibaba.otter.shared.common.model.config.node.Node)4 Date (java.util.Date)3 ProcessNodeEventData (com.alibaba.otter.shared.arbitrate.model.ProcessNodeEventData)2 IOException (java.io.IOException)2 MainStemArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.MainStemArbitrateEvent)1 MainstemMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.MainstemMonitor)1 SelectProcessListener (com.alibaba.otter.shared.arbitrate.impl.setl.rpc.monitor.SelectProcessListener)1 ExtractStageListener (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.ExtractStageListener)1 LoadStageListener (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.LoadStageListener)1