Search in sources :

Example 16 with Channel

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

the class ChannelServiceImpl method listByIds.

/*--------------------优化内容:listAll、listByIds、findById合并-------------------------------*/
public List<Channel> listByIds(Long... identities) {
    List<Channel> channels = new ArrayList<Channel>();
    try {
        List<ChannelDO> channelDos = null;
        if (identities.length < 1) {
            channelDos = channelDao.listAll();
            if (channelDos.isEmpty()) {
                logger.debug("DEBUG ## couldn't query any channel, maybe hasn't create any channel.");
                return channels;
            }
        } else {
            channelDos = channelDao.listByMultiId(identities);
            if (channelDos.isEmpty()) {
                String exceptionCause = "couldn't query any channel by channelIds:" + Arrays.toString(identities);
                logger.error("ERROR ## " + exceptionCause);
                throw new ManagerException(exceptionCause);
            }
        }
        channels = doToModel(channelDos);
    } catch (Exception e) {
        logger.error("ERROR ## query channels 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) ChannelDO(com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO) 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)

Example 17 with Channel

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

the class FileLoadActionTest method testLoadWithLocal.

@Test
public void testLoadWithLocal() throws IOException {
    // 构造fileData使用的参数,fileDataStartIndex 决定着 pipeline 与 fileData 对应的关系(通过
    // dataMediaPair 的 id),
    // 以及 dataMediaPair 的 pushWeight
    final int fileDataStartIndex = 0;
    final int fileDataCount = 50;
    final Pipeline pipeline = buildPipeline(fileDataStartIndex, fileDataCount);
    final Channel channel = new Channel();
    new NonStrictExpectations() {

        {
            configClientService.findChannel(anyLong);
            returns(channel);
            configClientService.findPipeline(anyLong);
            returns(pipeline);
        }
    };
    Identity id = buildIdentity(1L, 2L, 3L);
    FileBatch fileBatch = buildFileBatch(id);
    fileBatch.getFiles().addAll(buildFileDatas(null, EventType.INSERT, fileDataStartIndex, fileDataCount, true));
    WeightController controller = new WeightController(1);
    FileLoadContext context = fileLoadAction.load(fileBatch, ROOT_DIR, controller);
    want.object(context.getChannel()).isEqualTo(channel);
    want.object(context.getPipeline()).isEqualTo(pipeline);
    want.object(context.getPrepareDatas()).isEqualTo(fileBatch.getFiles());
    want.number(context.getProcessedDatas().size()).isEqualTo(fileBatch.getFiles().size());
}
Also used : FileBatch(com.alibaba.otter.shared.etl.model.FileBatch) Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) FileLoadContext(com.alibaba.otter.node.etl.load.loader.db.context.FileLoadContext) WeightController(com.alibaba.otter.node.etl.load.loader.weight.WeightController) Identity(com.alibaba.otter.shared.etl.model.Identity) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline) Test(org.testng.annotations.Test) BaseDbTest(com.alibaba.otter.node.etl.BaseDbTest)

Example 18 with Channel

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

the class DbLoadActionTest method test_db_load_mysql.

@Test
public void test_db_load_mysql() {
    ArbitrateConfigRegistry.regist(configClientService);
    dbLoadAction = (DbLoadAction) TestedObject.getSpringBeanFactory().getBean("dbLoadAction");
    final Channel channel = new Channel();
    channel.setId(1L);
    final Pipeline pipeline = new Pipeline();
    pipeline.setId(100L);
    List<DataMediaPair> pairs = generatorDataMediaPairForMysql(20);
    pipeline.setPairs(pairs);
    pipeline.getParameters().merge(new SystemParameter());
    pipeline.getParameters().merge(new ChannelParameter());
    // pipeline.getParameters().setChannelInfo("LJH_DEMO");
    // final Pipeline oppositePipeline = new Pipeline();
    // oppositePipeline.setId(101L);
    channel.setPipelines(Arrays.asList(pipeline));
    final Node currentNode = new Node();
    currentNode.setId(1L);
    new NonStrictExpectations() {

        {
            configClientService.findChannel(anyLong);
            returns(channel);
            configClientService.findPipeline(anyLong);
            returns(pipeline);
            configClientService.currentNode();
            returns(currentNode);
        }
    };
    Identity identity = new Identity();
    identity.setChannelId(100L);
    identity.setPipelineId(100L);
    identity.setProcessId(100L);
    RowBatch rowBatch = new RowBatch();
    rowBatch.setIdentity(identity);
    List<EventData> eventDatas = generatorEventDataForMysql(0, 20, EventType.INSERT);
    for (EventData eventData : eventDatas) {
        rowBatch.merge(eventData);
    }
    eventDatas = generatorEventDataForMysql(10, 10, EventType.INSERT);
    for (EventData eventData : eventDatas) {
        rowBatch.merge(eventData);
    }
    eventDatas = generatorEventDataForMysql(19, 1, EventType.DELETE);
    for (EventData eventData : eventDatas) {
        rowBatch.merge(eventData);
    }
    WeightController controller = new WeightController(1);
    dbLoadAction.load(rowBatch, controller);
}
Also used : DataMediaPair(com.alibaba.otter.shared.common.model.config.data.DataMediaPair) ChannelParameter(com.alibaba.otter.shared.common.model.config.channel.ChannelParameter) Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) Node(com.alibaba.otter.shared.common.model.config.node.Node) EventData(com.alibaba.otter.shared.etl.model.EventData) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline) RowBatch(com.alibaba.otter.shared.etl.model.RowBatch) SystemParameter(com.alibaba.otter.shared.common.model.config.parameter.SystemParameter) WeightController(com.alibaba.otter.node.etl.load.loader.weight.WeightController) Identity(com.alibaba.otter.shared.etl.model.Identity) Test(org.testng.annotations.Test) BaseDbTest(com.alibaba.otter.node.etl.BaseDbTest)

Example 19 with Channel

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

the class ConfigClientServiceImpl method afterPropertiesSet.

public void afterPropertiesSet() throws Exception {
    // 获取一下nid变量
    String nid = System.getProperty(NID_NAME);
    if (StringUtils.isEmpty(nid)) {
        throw new ConfigException("nid is not set!");
    }
    this.nid = Long.valueOf(nid);
    channelMapping = new MapMaker().makeComputingMap(new Function<Long, Long>() {

        public Long apply(Long pipelineId) {
            // 处理下pipline -> channel映射关系不存在的情况
            FindChannelEvent event = new FindChannelEvent();
            event.setPipelineId(pipelineId);
            try {
                Object obj = nodeCommmunicationClient.callManager(event);
                if (obj != null && obj instanceof Channel) {
                    Channel channel = (Channel) obj;
                    // 排除下自己
                    updateMapping(channel, pipelineId);
                    // 更新下channelCache
                    channelCache.put(channel.getId(), channel);
                    return channel.getId();
                }
            } catch (Exception e) {
                logger.error("call_manager_error", event.toString(), e);
            }
            throw new ConfigException("No Such Channel by pipelineId[" + pipelineId + "]");
        }
    });
    nodeCache = new RefreshMemoryMirror<Long, Node>(timeout, new ComputeFunction<Long, Node>() {

        public Node apply(Long key, Node oldValue) {
            FindNodeEvent event = new FindNodeEvent();
            event.setNid(key);
            try {
                Object obj = nodeCommmunicationClient.callManager(event);
                if (obj != null && obj instanceof Node) {
                    return (Node) obj;
                } else {
                    throw new ConfigException("No Such Node by id[" + key + "]");
                }
            } catch (Exception e) {
                logger.error("call_manager_error", event.toString(), e);
            }
            // 其他情况直接返回内存中的旧值
            return oldValue;
        }
    });
    channelCache = new RefreshMemoryMirror<Long, Channel>(timeout, new ComputeFunction<Long, Channel>() {

        public Channel apply(Long key, Channel oldValue) {
            FindChannelEvent event = new FindChannelEvent();
            event.setChannelId(key);
            try {
                Object obj = nodeCommmunicationClient.callManager(event);
                if (obj != null && obj instanceof Channel) {
                    // 排除下自己
                    updateMapping((Channel) obj, null);
                    return (Channel) obj;
                } else {
                    throw new ConfigException("No Such Channel by pipelineId[" + key + "]");
                }
            } catch (Exception e) {
                logger.error("call_manager_error", event.toString(), e);
            }
            // 其他情况直接返回内存中的旧值
            return oldValue;
        }
    });
}
Also used : ComputeFunction(com.alibaba.otter.shared.common.utils.cache.RefreshMemoryMirror.ComputeFunction) Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) Node(com.alibaba.otter.shared.common.model.config.node.Node) MapMaker(com.google.common.collect.MapMaker) ConfigException(com.alibaba.otter.shared.common.model.config.ConfigException) ConfigException(com.alibaba.otter.shared.common.model.config.ConfigException) Function(com.google.common.base.Function) ComputeFunction(com.alibaba.otter.shared.common.utils.cache.RefreshMemoryMirror.ComputeFunction) FindNodeEvent(com.alibaba.otter.shared.communication.model.config.FindNodeEvent) FindChannelEvent(com.alibaba.otter.shared.communication.model.config.FindChannelEvent)

Example 20 with Channel

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

the class ConfigClientServiceImpl method findOppositePipeline.

public Pipeline findOppositePipeline(Long pipelineId) {
    Long channelId = channelMapping.get(pipelineId);
    Channel channel = channelCache.get(channelId);
    List<Pipeline> pipelines = channel.getPipelines();
    for (Pipeline pipeline : pipelines) {
        if (pipeline.getId().equals(pipelineId) == false) {
            // 这里假定pipeline只有两个
            return pipeline;
        }
    }
    return null;
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)

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