Search in sources :

Example 6 with PermitMonitor

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

the class LoadMemoryArbitrateEvent method await.

public EtlEventData await(Long pipelineId) throws InterruptedException {
    Assert.notNull(pipelineId);
    PermitMonitor permitMonitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    // 阻塞等待授权
    permitMonitor.waitForPermit();
    MemoryStageController stageController = ArbitrateFactory.getInstance(pipelineId, MemoryStageController.class);
    // 符合条件的processId
    Long processId = stageController.waitForProcess(StageType.LOAD);
    ChannelStatus status = permitMonitor.getChannelPermit();
    if (status.isStart()) {
        // 即时查询一下当前的状态,状态随时可能会变
        return stageController.getLastData(processId);
    } else {
        logger.warn("pipelineId[{}] load 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)

Example 7 with PermitMonitor

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

the class ToolArbitrateEvent method waitForPermit.

/**
     * 阻塞等待授权通过
     * 
     * @param pipelineId
     * @throws InterruptedException
     */
public void waitForPermit(Long pipelineId) throws InterruptedException {
    Assert.notNull(pipelineId);
    PermitMonitor permitMonitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    // 阻塞等待授权
    permitMonitor.waitForPermit();
}
Also used : PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor)

Example 8 with PermitMonitor

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

the class ArbitrateOppositeIntegration method testDemo.

@Test
public void testDemo() {
    // 设置启动标志
    // channelEvent.start(channelId);
    // sleep(); //停顿一下
    // 优先启动主导线程
    mainStem.submit(pipelineId);
    PermitMonitor permit = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    try {
        // 阻塞等待授权
        permit.waitForPermit();
    } catch (InterruptedException e1) {
        want.fail();
    }
    // 启动
    select.submit(pipelineId);
    extract.submit(pipelineId);
    view.submit(pipelineId);
    this.termin.submit(pipelineId);
    // 注意是反方向的
    transform.submit(oppositePipelineId);
    // 注意是反方向的
    load.submit(oppositePipelineId);
    try {
        System.in.read();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // 发送结束事件
    TerminEventData termin = new TerminEventData();
    termin.setPipelineId(pipelineId);
    termin.setType(TerminType.SHUTDOWN);
    arbitrateEventService.terminEvent().single(termin);
    // 等待处理完所有的termin事件
    sleep(5 * 1000L);
    // 关闭
    select.destory(pipelineId);
    extract.destory(pipelineId);
    view.destory(pipelineId);
    this.termin.destory(pipelineId);
    transform.destory(oppositePipelineId);
    load.destory(oppositePipelineId);
    ArbitrateFactory.destory(pipelineId);
}
Also used : TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData) PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) IOException(java.io.IOException) Test(org.testng.annotations.Test) BaseEventTest(com.alibaba.otter.shared.arbitrate.BaseEventTest)

Example 9 with PermitMonitor

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

the class TerminMemoryArbitrateEventTest method test_Shutdown.

@Test
public void test_Shutdown() {
    normalProcess();
    // 发送shutdown信号
    TerminEventData shutdown = new TerminEventData();
    shutdown.setPipelineId(pipelineId);
    shutdown.setType(TerminType.SHUTDOWN);
    terminEvent.single(shutdown);
    PermitMonitor monitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    want.bool(monitor.getChannelPermit(true).isStop()).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 10 with PermitMonitor

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

the class TerminMemoryArbitrateEventTest 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(true).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)

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