Search in sources :

Example 6 with ChannelStatus

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

the class ExtractMemoryArbitrateEvent 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.EXTRACT);
    ChannelStatus status = permitMonitor.getChannelPermit();
    if (status.isStart()) {
        // 即时查询一下当前的状态,状态随时可能会变
        return stageController.getLastData(processId);
    } else {
        logger.warn("pipelineId[{}] extract 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 ChannelStatus

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

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

the class ChannelArbitrateEvent method pause.

/**
     * 停止对应的channel同步,是个异步调用
     */
public boolean pause(Long channelId, boolean needTermin) {
    ChannelStatus currstatus = status(channelId);
    boolean status = false;
    boolean result = !needTermin;
    if (currstatus.isStart()) {
        // stop的优先级高于pause,这里只针对start状态进行状态更新
        updateStatus(channelId, ChannelStatus.PAUSE);
        // 避免stop时发生rollback报警
        status = true;
    }
    if (needTermin) {
        try {
            // 调用termin进行关闭
            result |= termin(channelId, TerminType.ROLLBACK);
        } catch (Throwable e) {
            // 出错了,直接挂起
            updateStatus(channelId, ChannelStatus.PAUSE);
            throw new ArbitrateException(e);
        }
    }
    return result && status;
}
Also used : ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)

Example 9 with ChannelStatus

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

the class ChannelArbitrateEvent method restart.

/**
     * 停止对应的channel同步,是个异步调用
     */
public boolean restart(final Long channelId, boolean needTermin) {
    boolean result = !needTermin;
    boolean status = false;
    if (status(channelId).isStop() == false) {
        // stop的优先级高于pause
        updateStatus(channelId, ChannelStatus.PAUSE);
        status = true;
    }
    if (needTermin) {
        try {
            result |= termin(channelId, TerminType.RESTART);
        } catch (Throwable e) {
            // 出错了,直接挂起
            updateStatus(channelId, ChannelStatus.PAUSE);
            throw new ArbitrateException(e);
        }
    }
    // 处理一下重启操作,只处理pause状态
    if (status || result) {
        // 异步启动
        arbitrateExecutor.submit(new Runnable() {

            public void run() {
                // sleep一段时间,保证rollback信息有足够的时间能被处理完成
                try {
                    Thread.sleep(5000L + RandomUtils.nextInt(2000));
                } catch (InterruptedException e) {
                // ignore
                }
                Channel channel = ArbitrateConfigUtils.getChannelByChannelId(channelId);
                ChannelStatus status = status(channel.getId());
                if (status.isStop()) {
                    // stop优先级最高,不允许自动重启
                    logger.info("channel[{}] is already stop , restart is ignored", channel.getId());
                } else if (canStart(channel)) {
                    // 出现stop,就不允许进行自动重启,stop优先级最高
                    start(channelId);
                }
            }
        });
    }
    return result && status;
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)

Example 10 with ChannelStatus

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

the class ChannelServiceImpl method doToModel.

/**
     * <pre>
     * 用于DO对象数组转化为Model对象数组
     * 现阶段优化:
     *      需要五次SQL交互:pipeline\node\dataMediaPair\dataMedia\dataMediaSource(五个层面)
     *      目前优化方案为单层只执行一次SQL,避免重复循环造成IO及数据库查询开销
     * 长期优化:
     *      对SQL进行改造,尽量减小SQL调用次数
     * </pre>
     * 
     * @param channelDO
     * @return Channel
     */
private List<Channel> doToModel(List<ChannelDO> channelDos) {
    List<Channel> channels = new ArrayList<Channel>();
    try {
        // 1.将ChannelID单独拿出来
        List<Long> channelIds = new ArrayList<Long>();
        for (ChannelDO channelDo : channelDos) {
            channelIds.add(channelDo.getId());
        }
        Long[] idArray = new Long[channelIds.size()];
        // 拿到所有的Pipeline进行ChannelID过滤,避免重复查询。
        List<Pipeline> pipelines = pipelineService.listByChannelIds(channelIds.toArray(idArray));
        SystemParameter systemParameter = systemParameterService.find();
        for (ChannelDO channelDo : channelDos) {
            Channel channel = new Channel();
            channel.setId(channelDo.getId());
            channel.setName(channelDo.getName());
            channel.setDescription(channelDo.getDescription());
            ChannelStatus channelStatus = arbitrateManageService.channelEvent().status(channelDo.getId());
            channel.setStatus(null == channelStatus ? ChannelStatus.STOP : channelStatus);
            channel.setParameters(channelDo.getParameters());
            channel.setGmtCreate(channelDo.getGmtCreate());
            channel.setGmtModified(channelDo.getGmtModified());
            // 遍历,将该Channel节点下的Pipeline提取出来。
            List<Pipeline> subPipelines = new ArrayList<Pipeline>();
            for (Pipeline pipeline : pipelines) {
                if (pipeline.getChannelId().equals(channelDo.getId())) {
                    // 合并PipelineParameter和ChannelParameter
                    PipelineParameter parameter = new PipelineParameter();
                    parameter.merge(systemParameter);
                    parameter.merge(channel.getParameters());
                    // 最后复制pipelineId参数
                    parameter.merge(pipeline.getParameters());
                    pipeline.setParameters(parameter);
                    subPipelines.add(pipeline);
                }
            }
            channel.setPipelines(subPipelines);
            channels.add(channel);
        }
    } catch (Exception e) {
        logger.error("ERROR ## change the channels DO to Model has an exception");
        throw new ManagerException(e);
    }
    return channels;
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) ArrayList(java.util.ArrayList) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus) InvalidConfigureException(com.alibaba.otter.manager.biz.common.exceptions.InvalidConfigureException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline) SystemParameter(com.alibaba.otter.shared.common.model.config.parameter.SystemParameter) ChannelDO(com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO) PipelineParameter(com.alibaba.otter.shared.common.model.config.pipeline.PipelineParameter) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException)

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