Search in sources :

Example 1 with Channel

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

the class DbLoadAction method buildContext.

private DbLoadContext buildContext(Identity identity) {
    DbLoadContext context = new DbLoadContext();
    context.setIdentity(identity);
    Channel channel = configClientService.findChannel(identity.getChannelId());
    Pipeline pipeline = configClientService.findPipeline(identity.getPipelineId());
    context.setChannel(channel);
    context.setPipeline(pipeline);
    return context;
}
Also used : DbLoadContext(com.alibaba.otter.node.etl.load.loader.db.context.DbLoadContext) Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)

Example 2 with Channel

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

the class AbstractOperationInterceptor method updateMark.

/**
 * 更新一下事务标记
 */
private void updateMark(DbLoadContext context, DbDialect dialect, int threadId, String sql, boolean needInfo, String hint) {
    Identity identity = context.getIdentity();
    Channel channel = context.getChannel();
    // 获取dbDialect
    String markTableName = context.getPipeline().getParameters().getSystemSchema() + "." + context.getPipeline().getParameters().getSystemMarkTable();
    String markTableColumn = context.getPipeline().getParameters().getSystemMarkTableColumn();
    synchronized (dialect.getJdbcTemplate()) {
        if (tableCheckStatus.contains(dialect.getJdbcTemplate()) == false) {
            init(dialect.getJdbcTemplate(), markTableName, markTableColumn);
            tableCheckStatus.add(dialect.getJdbcTemplate());
        }
    }
    int affectedCount = 0;
    if (needInfo) {
        String infoColumn = context.getPipeline().getParameters().getSystemMarkTableInfo();
        // 记录一下channelInfo
        String info = context.getPipeline().getParameters().getChannelInfo();
        String esql = MessageFormat.format(sql, new Object[] { markTableName, markTableColumn, infoColumn });
        if (hint != null) {
            esql = hint + esql;
        }
        affectedCount = dialect.getJdbcTemplate().update(esql, new Object[] { threadId, channel.getId(), info });
    } else {
        String esql = MessageFormat.format(sql, new Object[] { markTableName, markTableColumn });
        if (hint != null) {
            esql = hint + esql;
        }
        affectedCount = dialect.getJdbcTemplate().update(esql, new Object[] { threadId, channel.getId() });
    }
    if (affectedCount <= 0) {
        logger.warn("## update {} failed by [{}]", markTableName, threadId);
    } else {
        if (logger.isInfoEnabled()) {
            logger.debug("Interceptor For [{}]", identity);
        }
    }
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) Identity(com.alibaba.otter.shared.etl.model.Identity)

Example 3 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 4 with Channel

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

the class TerminZooKeeperArbitrateEvent method single.

/**
 * <pre>
 * 算法:
 * 1. 创建对应的termin节点,标志process为终结状态
 * </pre>
 */
public void single(final TerminEventData data) {
    // 正向处理
    final TerminType type = data.getType();
    if (type.isNormal()) {
        Assert.notNull(data.getProcessId());
        // 单独处理
        normalTerminProcess.process(data);
    } else if (type.isWarning()) {
        // warn单独处理,不需要关闭相关的pipeline
        warningTerminProcess.process(data);
    } else {
        Channel channel = ArbitrateConfigUtils.getChannel(data.getPipelineId());
        if (data.getType().isRollback()) {
            boolean paused = channelEvent.pause(channel.getId());
            if (paused) {
                // 如果pause成功,则发送报警信息
                warningTerminProcess.process(data);
            }
        } else if (data.getType().isShutdown()) {
            boolean shutdowned = channelEvent.stop(channel.getId());
            // 发送报警信息
            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());
            // 发送报警信息
            if (restarted) {
                warningTerminProcess.process(data);
            }
        }
    }
}
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 5 with Channel

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

the class ChannelArbitrateEventIntegration method init.

@BeforeClass
public void init() {
    // 初始化节点
    // mock 配置信息数据
    Mockit.setUpMock(ArbitrateConfigUtils.class, new Object() {

        @Mock
        public Pipeline getPipeline(Long pipelineId) {
            Pipeline pipeline = new Pipeline();
            pipeline.setId(pipelineId);
            return pipeline;
        }

        @Mock
        public Channel getChannel(Long pipelineId) {
            Channel channel = new Channel();
            channel.setId(channelId);
            Pipeline pipeline = new Pipeline();
            pipeline.setId(pipelineId);
            Pipeline oppositePipeline = new Pipeline();
            oppositePipeline.setId(oppositePipelineId);
            channel.setPipelines(Arrays.asList(pipeline, oppositePipeline));
            return channel;
        }

        @Mock
        public Channel getChannelByChannelId(Long channelId) {
            Channel channel = new Channel();
            channel.setId(channelId);
            Pipeline pipeline = new Pipeline();
            pipeline.setId(pipelineId);
            Pipeline oppositePipeline = new Pipeline();
            oppositePipeline.setId(oppositePipelineId);
            channel.setPipelines(Arrays.asList(pipeline, oppositePipeline));
            return channel;
        }

        @Mock
        public Pipeline getOppositePipeline(Long pipelineId) {
            Pipeline pipeline = new Pipeline();
            pipeline.setId(pipelineId);
            return pipeline;
        }
    });
    zookeeper = getZookeeper();
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) Mock(mockit.Mock) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline) BeforeClass(org.testng.annotations.BeforeClass)

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