Search in sources :

Example 1 with ConfigException

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

the class ArbitrateConfigImpl method afterPropertiesSet.

public void afterPropertiesSet() throws Exception {
    // 获取一下nid变量
    channelMapping = new MapMaker().makeComputingMap(new Function<Long, Long>() {

        public Long apply(Long pipelineId) {
            // 处理下pipline -> channel映射关系不存在的情况
            Channel channel = channelService.findByPipelineId(pipelineId);
            if (channel == null) {
                throw new ConfigException("No Such Channel by pipelineId[" + pipelineId + "]");
            }
            // 排除下自己
            updateMapping(channel, pipelineId);
            // 更新下channelCache
            channelCache.put(channel.getId(), channel);
            return channel.getId();
        }
    });
    channelCache = new RefreshMemoryMirror<Long, Channel>(timeout, new ComputeFunction<Long, Channel>() {

        public Channel apply(Long key, Channel oldValue) {
            Channel channel = channelService.findById(key);
            if (channel == null) {
                // 其他情况直接返回内存中的旧值
                return oldValue;
            } else {
                // 排除下自己
                updateMapping(channel, null);
                return channel;
            }
        }
    });
    nodeCache = new RefreshMemoryMirror<Long, Node>(timeout, new ComputeFunction<Long, Node>() {

        public Node apply(Long key, Node oldValue) {
            Node node = nodeService.findById(key);
            if (node == null) {
                return oldValue;
            } else {
                return node;
            }
        }
    });
}
Also used : ComputeFunction(com.alibaba.otter.shared.common.utils.cache.RefreshMemoryMirror.ComputeFunction) Function(com.google.common.base.Function) 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)

Example 2 with ConfigException

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

the class ConfigHelperTest method testWildCard.

@Test
public void testWildCard() {
    PatternMatcher matcher = new Perl5Matcher();
    Pattern pattern = null;
    PatternCompiler pc = new Perl5Compiler();
    try {
        pattern = pc.compile("havana_us_.*", Perl5Compiler.DEFAULT_MASK);
    } catch (MalformedPatternException e) {
        throw new ConfigException(e);
    }
    boolean ismatch = matcher.matches("havana_us_0001", pattern);
    System.out.println(ismatch);
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) PatternCompiler(org.apache.oro.text.regex.PatternCompiler) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) ConfigException(com.alibaba.otter.shared.common.model.config.ConfigException) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) PatternMatcher(org.apache.oro.text.regex.PatternMatcher) Test(org.testng.annotations.Test) BaseOtterTest(com.alibaba.otter.shared.common.BaseOtterTest)

Example 3 with ConfigException

use of com.alibaba.otter.shared.common.model.config.ConfigException 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 4 with ConfigException

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

the class ConfigClientServiceImpl method findPipeline.

public Pipeline findPipeline(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)) {
            return pipeline;
        }
    }
    throw new ConfigException("no pipeline for pipelineId[" + pipelineId + "]");
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) ConfigException(com.alibaba.otter.shared.common.model.config.ConfigException) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)

Example 5 with ConfigException

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

the class ArbitrateConfigImpl method findPipeline.

public Pipeline findPipeline(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)) {
            return pipeline;
        }
    }
    throw new ConfigException("no pipeline for pipelineId[" + pipelineId + "]");
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) ConfigException(com.alibaba.otter.shared.common.model.config.ConfigException) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)

Aggregations

ConfigException (com.alibaba.otter.shared.common.model.config.ConfigException)7 Channel (com.alibaba.otter.shared.common.model.config.channel.Channel)4 Pipeline (com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)3 Node (com.alibaba.otter.shared.common.model.config.node.Node)2 ComputeFunction (com.alibaba.otter.shared.common.utils.cache.RefreshMemoryMirror.ComputeFunction)2 Function (com.google.common.base.Function)2 MapMaker (com.google.common.collect.MapMaker)2 DbDialect (com.alibaba.otter.node.etl.common.db.dialect.DbDialect)1 ExtractException (com.alibaba.otter.node.etl.extract.exceptions.ExtractException)1 NodeSessionExpired (com.alibaba.otter.shared.arbitrate.impl.manage.NodeSessionExpired)1 BaseOtterTest (com.alibaba.otter.shared.common.BaseOtterTest)1 DataMedia (com.alibaba.otter.shared.common.model.config.data.DataMedia)1 FindChannelEvent (com.alibaba.otter.shared.communication.model.config.FindChannelEvent)1 FindNodeEvent (com.alibaba.otter.shared.communication.model.config.FindNodeEvent)1 EventColumn (com.alibaba.otter.shared.etl.model.EventColumn)1 EventData (com.alibaba.otter.shared.etl.model.EventData)1 EventType (com.alibaba.otter.shared.etl.model.EventType)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Column (org.apache.ddlutils.model.Column)1