Search in sources :

Example 16 with TerminEventData

use of com.alibaba.otter.shared.arbitrate.model.TerminEventData in project otter by alibaba.

the class GlobalTask method sendRollbackTermin.

protected void sendRollbackTermin(long pipelineId, String message) {
    TerminEventData errorEventData = new TerminEventData();
    errorEventData.setPipelineId(pipelineId);
    errorEventData.setType(TerminType.ROLLBACK);
    errorEventData.setCode("setl");
    errorEventData.setDesc(message);
    arbitrateEventService.terminEvent().single(errorEventData);
    // 每次发送完报警后,sleep一段时间,继续做后面的事
    try {
        Thread.sleep(3000 + RandomUtils.nextInt(3000));
    } catch (InterruptedException e) {
    }
}
Also used : TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData) ZkInterruptedException(org.I0Itec.zkclient.exception.ZkInterruptedException)

Example 17 with TerminEventData

use of com.alibaba.otter.shared.arbitrate.model.TerminEventData in project otter by alibaba.

the class GlobalTask method processMissData.

/**
     * 自动处理数据为null的情况,重新发一遍数据
     */
protected void processMissData(long pipelineId, String message) {
    TerminEventData errorEventData = new TerminEventData();
    errorEventData.setPipelineId(pipelineId);
    errorEventData.setType(TerminType.RESTART);
    errorEventData.setCode("setl");
    errorEventData.setDesc(message);
    arbitrateEventService.terminEvent().single(errorEventData);
}
Also used : TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData)

Example 18 with TerminEventData

use of com.alibaba.otter.shared.arbitrate.model.TerminEventData in project otter by alibaba.

the class OtterAlarmHandler method sendAlarm.

public void sendAlarm(String destination, String msg) {
    TerminEventData errorEventData = new TerminEventData();
    errorEventData.setPipelineId(pipelineId);
    errorEventData.setType(TerminType.WARNING);
    errorEventData.setCode("canal");
    errorEventData.setDesc(destination + ":" + msg);
    arbitrateEventService.terminEvent().single(errorEventData);
}
Also used : TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData)

Example 19 with TerminEventData

use of com.alibaba.otter.shared.arbitrate.model.TerminEventData in project otter by alibaba.

the class LoadZooKeeperArbitrateEvent method single.

/**
     * <pre>
     * 算法:
     * 1. 创建对应的loaded节点,标志load已完成
     * </pre>
     * 
     * @param pipelineId 同步流id
     */
public void single(EtlEventData data) {
    Assert.notNull(data);
    try {
        // String path = StagePathUtils.getLoadStage(data.getPipelineId(), data.getProcessId());
        // // 序列化
        // data.setEndTime(new Date().getTime());// 返回当前时间
        // byte[] bytes = JsonUtils.marshalToByte(data, SerializerFeature.WriteClassName);
        // try {
        // zookeeper.create(path, bytes, CreateMode.PERSISTENT);
        // } catch (NodeExistsException e) {
        // throw new ArbitrateException("Load_single", e.getMessage(), e);
        // } catch (KeeperException e) {
        // throw new ArbitrateException("Load_single", e.getMessage(), e);
        // } catch (InterruptedException e) {
        // // ignore
        // }
        // 返回当前时间
        data.setEndTime(new Date().getTime());
        // 调用Termin信号
        TerminEventData termin = new TerminEventData();
        termin.setPipelineId(data.getPipelineId());
        termin.setProcessId(data.getProcessId());
        termin.setStartTime(data.getStartTime());
        termin.setEndTime(data.getEndTime());
        termin.setFirstTime(data.getFirstTime());
        termin.setNumber(data.getNumber());
        termin.setBatchId(data.getBatchId());
        termin.setSize(data.getSize());
        termin.setExts(data.getExts());
        termin.setType(TerminType.NORMAL);
        termin.setCode("setl");
        termin.setDesc("");
        termin.setCurrNid(ArbitrateConfigUtils.getCurrentNid());
        terminEvent.single(termin);
    } finally {
    // // 最后一步释放锁
    // DistributedLock lock = getLock(data.getPipelineId());
    // try {
    // lock.unlock();// 解除lock
    // } catch (KeeperException e) {
    // throw new ArbitrateException("Load_single", e.getMessage(), e);
    // }
    }
}
Also used : TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData) Date(java.util.Date)

Example 20 with TerminEventData

use of com.alibaba.otter.shared.arbitrate.model.TerminEventData in project otter by alibaba.

the class ArbitrateAllTest method testDemo.

@Test
public void testDemo() {
    // 设置启动标志
    channelEvent.start(channelId);
    // 停顿一下
    sleep();
    PermitMonitor permit = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    // 优先启动主导线程
    mainStem.submit(pipelineId);
    try {
        // 阻塞等待授权
        permit.waitForPermit();
    } catch (InterruptedException e1) {
        want.fail();
    }
    if (arbitrateMode.isZookeeper()) {
        ArbitrateFactory.getInstance(pipelineId, SelectStageListener.class);
        ArbitrateFactory.getInstance(pipelineId, ExtractStageListener.class);
        ArbitrateFactory.getInstance(pipelineId, TransformStageListener.class);
        ArbitrateFactory.getInstance(pipelineId, LoadStageListener.class);
    }
    if (arbitrateMode.isMemory()) {
        ArbitrateFactory.getInstance(pipelineId, MemoryStageController.class);
    }
    if (arbitrateMode.isRpc()) {
        ArbitrateFactory.getInstance(pipelineId, RpcStageController.class);
        ArbitrateFactory.getInstance(pipelineId, SelectProcessListener.class);
    }
    if (arbitrateMode.isZookeeper() || arbitrateMode.isRpc()) {
        ArbitrateFactory.getInstance(pipelineId, ExtractRandomLoadBanlance.class);
        ArbitrateFactory.getInstance(pipelineId, ExtractRoundRobinLoadBalance.class);
        ArbitrateFactory.getInstance(pipelineId, TransformRandomLoadBanlance.class);
        ArbitrateFactory.getInstance(pipelineId, TransformRoundRobinLoadBalance.class);
    }
    // 启动
    select.submit(pipelineId);
    extract.submit(pipelineId);
    transform.submit(pipelineId);
    load.submit(pipelineId);
    view.submit(pipelineId);
    this.termin.submit(pipelineId);
    try {
        // 运行30s
        Thread.sleep(20 * 1000);
    } catch (InterruptedException e) {
        want.fail();
    }
    // 发送结束事件
    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);
    transform.destory(pipelineId);
    load.destory(pipelineId);
    view.destory(pipelineId);
    this.termin.destory(pipelineId);
    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) BaseEventTest(com.alibaba.otter.shared.arbitrate.BaseEventTest)

Aggregations

TerminEventData (com.alibaba.otter.shared.arbitrate.model.TerminEventData)32 Test (org.testng.annotations.Test)12 PermitMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor)9 BaseArbitrateEventTest (com.alibaba.otter.shared.arbitrate.setl.event.BaseArbitrateEventTest)9 ArrayList (java.util.ArrayList)7 EtlEventData (com.alibaba.otter.shared.arbitrate.model.EtlEventData)6 Mock (mockit.Mock)5 BaseEventTest (com.alibaba.otter.shared.arbitrate.BaseEventTest)3 ArbitrateException (com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)3 Date (java.util.Date)3 ExtractMemoryArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.memory.ExtractMemoryArbitrateEvent)2 LoadMemoryArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.memory.LoadMemoryArbitrateEvent)2 SelectMemoryArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.memory.SelectMemoryArbitrateEvent)2 TransformMemoryArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.memory.TransformMemoryArbitrateEvent)2 ExtractZooKeeperArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.ExtractZooKeeperArbitrateEvent)2 LoadZooKeeperArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.LoadZooKeeperArbitrateEvent)2 SelectZooKeeperArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.SelectZooKeeperArbitrateEvent)2 TransformZooKeeperArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.TransformZooKeeperArbitrateEvent)2 IOException (java.io.IOException)2 SelectException (com.alibaba.otter.node.etl.select.exceptions.SelectException)1