Search in sources :

Example 6 with Channel

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

the class TerminMemoryArbitrateEvent method single.

public void single(TerminEventData data) {
    // 正向处理
    final TerminType type = data.getType();
    MemoryStageController stageController = ArbitrateFactory.getInstance(data.getPipelineId(), MemoryStageController.class);
    if (type.isNormal()) {
        Assert.notNull(data.getProcessId());
        stageController.offerTermin(data);
    } else if (type.isWarning()) {
        // warn单独处理,不需要关闭相关的pipeline
        warningTerminProcess.process(data);
    } else {
        // 内存版可以简化处理rollback/restart/shutdown模型,不需要进行process的termin操作处理
        Channel channel = ArbitrateConfigUtils.getChannel(data.getPipelineId());
        if (data.getType().isRollback()) {
            boolean paused = channelEvent.pause(channel.getId(), false);
            if (paused) {
                // 如果pause成功,则发送报警信息
                warningTerminProcess.process(data);
            }
        } else if (data.getType().isShutdown()) {
            boolean shutdowned = channelEvent.stop(channel.getId(), false);
            // 发送报警信息
            if (shutdowned) {
                warningTerminProcess.process(data);
            }
            // 发送关闭命令给manager
            StopChannelEvent event = new StopChannelEvent();
            event.setChannelId(channel.getId());
            arbitrateCommmunicationClient.callManager(event);
        } else if (data.getType().isRestart()) {
            boolean restarted = channelEvent.restart(channel.getId(), false);
            // 发送报警信息
            if (restarted) {
                warningTerminProcess.process(data);
            }
        }
        // 内存中构造异常termin信号返回
        stageController.termin(data.getType());
    }
}
Also used : TerminType(com.alibaba.otter.shared.arbitrate.model.TerminEventData.TerminType) StopChannelEvent(com.alibaba.otter.shared.communication.model.arbitrate.StopChannelEvent) Channel(com.alibaba.otter.shared.common.model.config.channel.Channel)

Example 7 with Channel

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

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

the class ChannelArbitrateEvent method termin.

// ===================== help method =================
/**
     * 执行结束同步任务操作
     */
private Boolean termin(Long channelId, final TerminType type) throws Exception {
    Channel channel = ArbitrateConfigUtils.getChannelByChannelId(channelId);
    List<Pipeline> pipelines = channel.getPipelines();
    List<Future<Boolean>> futures = new ArrayList<Future<Boolean>>();
    for (final Pipeline pipeline : pipelines) {
        futures.add(arbitrateExecutor.submit(new Callable<Boolean>() {

            public Boolean call() {
                TerminEventData data = new TerminEventData();
                data.setPipelineId(pipeline.getId());
                data.setType(type);
                data.setCode("channel");
                data.setDesc(type.toString());
                // 处理关闭
                return errorTerminProcess.process(data);
            }
        }));
    }
    boolean result = false;
    Exception exception = null;
    int index = 0;
    for (Future<Boolean> future : futures) {
        try {
            // 进行处理
            result |= future.get();
        } catch (InterruptedException e) {
            // ignore
            Thread.currentThread().interrupt();
        } catch (ExecutionException e) {
            sendWarningMessage(pipelines.get(index).getId(), e);
            exception = e;
        }
        index++;
    }
    if (exception != null) {
        throw exception;
    } else {
        return result;
    }
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException) ZkException(org.I0Itec.zkclient.exception.ZkException) ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ExecutionException(java.util.concurrent.ExecutionException) ZkNodeExistsException(org.I0Itec.zkclient.exception.ZkNodeExistsException) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline) TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException)

Example 9 with Channel

use of com.alibaba.otter.shared.common.model.config.channel.Channel 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 Channel doToModel(ChannelDO channelDo) {
    Channel channel = new Channel();
    try {
        channel.setId(channelDo.getId());
        channel.setName(channelDo.getName());
        channel.setDescription(channelDo.getDescription());
        channel.setStatus(arbitrateManageService.channelEvent().status(channelDo.getId()));
        channel.setParameters(channelDo.getParameters());
        channel.setGmtCreate(channelDo.getGmtCreate());
        channel.setGmtModified(channelDo.getGmtModified());
        List<Pipeline> pipelines = pipelineService.listByChannelIds(channelDo.getId());
        // 合并PipelineParameter和ChannelParameter
        SystemParameter systemParameter = systemParameterService.find();
        for (Pipeline pipeline : pipelines) {
            PipelineParameter parameter = new PipelineParameter();
            parameter.merge(systemParameter);
            parameter.merge(channel.getParameters());
            // 最后复制pipelineId参数
            parameter.merge(pipeline.getParameters());
            pipeline.setParameters(parameter);
        // pipeline.getParameters().merge(channel.getParameters());
        }
        channel.setPipelines(pipelines);
    } catch (Exception e) {
        logger.error("ERROR ## change the channel DO to Model has an exception");
        throw new ManagerException(e);
    }
    return channel;
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) SystemParameter(com.alibaba.otter.shared.common.model.config.parameter.SystemParameter) PipelineParameter(com.alibaba.otter.shared.common.model.config.pipeline.PipelineParameter) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) 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)

Example 10 with Channel

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

Channel (com.alibaba.otter.shared.common.model.config.channel.Channel)77 Pipeline (com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)38 Mock (mockit.Mock)16 ArrayList (java.util.ArrayList)13 ManagerException (com.alibaba.otter.manager.biz.common.exceptions.ManagerException)10 RepeatConfigureException (com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)10 ChannelArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.manage.ChannelArbitrateEvent)10 BeforeClass (org.testng.annotations.BeforeClass)10 PipelineArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.manage.PipelineArbitrateEvent)9 InvalidConfigureException (com.alibaba.otter.manager.biz.common.exceptions.InvalidConfigureException)8 NodeArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent)8 Node (com.alibaba.otter.shared.common.model.config.node.Node)7 Event (com.alibaba.otter.shared.communication.core.model.Event)7 Test (org.testng.annotations.Test)7 ChannelStatus (com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)6 DataMediaPair (com.alibaba.otter.shared.common.model.config.data.DataMediaPair)6 HashMap (java.util.HashMap)6 ChannelDO (com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO)5 SystemParameter (com.alibaba.otter.shared.common.model.config.parameter.SystemParameter)5 Identity (com.alibaba.otter.shared.etl.model.Identity)5