Search in sources :

Example 6 with CanalException

use of com.alibaba.otter.canal.common.CanalException in project otter by alibaba.

the class CanalConfigClient method findFilter.

/**
     * 根据对应的destinantion查询filter信息
     */
public String findFilter(String destination) {
    FindFilterEvent event = new FindFilterEvent();
    event.setDestination(destination);
    try {
        Object obj = delegate.callManager(event);
        if (obj != null && obj instanceof String) {
            return (String) obj;
        } else {
            throw new CanalException("No Such Canal by [" + destination + "]");
        }
    } catch (Exception e) {
        throw new CanalException("call_manager_error", e);
    }
}
Also used : FindFilterEvent(com.alibaba.otter.shared.communication.model.canal.FindFilterEvent) CanalException(com.alibaba.otter.canal.common.CanalException) CanalException(com.alibaba.otter.canal.common.CanalException)

Example 7 with CanalException

use of com.alibaba.otter.canal.common.CanalException in project canal by alibaba.

the class CanalInstanceWithManager method initLogPositionManager.

protected CanalLogPositionManager initLogPositionManager() {
    logger.info("init logPositionPersistManager begin...");
    IndexMode indexMode = parameters.getIndexMode();
    CanalLogPositionManager logPositionManager = null;
    if (indexMode.isMemory()) {
        logPositionManager = new MemoryLogPositionManager();
    } else if (indexMode.isZookeeper()) {
        logPositionManager = new ZooKeeperLogPositionManager();
        ((ZooKeeperLogPositionManager) logPositionManager).setZkClientx(getZkclientx());
    } else if (indexMode.isMixed()) {
        logPositionManager = new PeriodMixedLogPositionManager();
        ZooKeeperLogPositionManager zooKeeperLogPositionManager = new ZooKeeperLogPositionManager();
        zooKeeperLogPositionManager.setZkClientx(getZkclientx());
        ((PeriodMixedLogPositionManager) logPositionManager).setZooKeeperLogPositionManager(zooKeeperLogPositionManager);
    } else if (indexMode.isMeta()) {
        logPositionManager = new MetaLogPositionManager();
        ((MetaLogPositionManager) logPositionManager).setMetaManager(metaManager);
    } else if (indexMode.isMemoryMetaFailback()) {
        MemoryLogPositionManager primaryLogPositionManager = new MemoryLogPositionManager();
        MetaLogPositionManager failbackLogPositionManager = new MetaLogPositionManager();
        failbackLogPositionManager.setMetaManager(metaManager);
        logPositionManager = new FailbackLogPositionManager();
        ((FailbackLogPositionManager) logPositionManager).setPrimary(primaryLogPositionManager);
        ((FailbackLogPositionManager) logPositionManager).setFailback(failbackLogPositionManager);
    } else {
        throw new CanalException("unsupport indexMode for " + indexMode);
    }
    logger.info("init logPositionManager end! \n\t load CanalLogPositionManager:{}", logPositionManager.getClass().getName());
    return logPositionManager;
}
Also used : MemoryLogPositionManager(com.alibaba.otter.canal.parse.index.MemoryLogPositionManager) FailbackLogPositionManager(com.alibaba.otter.canal.parse.index.FailbackLogPositionManager) CanalLogPositionManager(com.alibaba.otter.canal.parse.index.CanalLogPositionManager) MetaLogPositionManager(com.alibaba.otter.canal.parse.index.MetaLogPositionManager) IndexMode(com.alibaba.otter.canal.instance.manager.model.CanalParameter.IndexMode) ZooKeeperLogPositionManager(com.alibaba.otter.canal.parse.index.ZooKeeperLogPositionManager) PeriodMixedLogPositionManager(com.alibaba.otter.canal.parse.index.PeriodMixedLogPositionManager) CanalException(com.alibaba.otter.canal.common.CanalException)

Example 8 with CanalException

use of com.alibaba.otter.canal.common.CanalException in project canal by alibaba.

the class CanalInstanceWithManager method initHaController.

protected CanalHAController initHaController() {
    logger.info("init haController begin...");
    HAMode haMode = parameters.getHaMode();
    CanalHAController haController = null;
    if (haMode.isHeartBeat()) {
        haController = new HeartBeatHAController();
        ((HeartBeatHAController) haController).setDetectingRetryTimes(parameters.getDetectingRetryTimes());
        ((HeartBeatHAController) haController).setSwitchEnable(parameters.getHeartbeatHaEnable());
    } else {
        throw new CanalException("unsupport HAMode for " + haMode);
    }
    logger.info("init haController end! \n\t load CanalHAController:{}", haController.getClass().getName());
    return haController;
}
Also used : HeartBeatHAController(com.alibaba.otter.canal.parse.ha.HeartBeatHAController) HAMode(com.alibaba.otter.canal.instance.manager.model.CanalParameter.HAMode) CanalHAController(com.alibaba.otter.canal.parse.ha.CanalHAController) CanalException(com.alibaba.otter.canal.common.CanalException)

Example 9 with CanalException

use of com.alibaba.otter.canal.common.CanalException in project canal by alibaba.

the class CanalController method initGlobalConfig.

private InstanceConfig initGlobalConfig(Properties properties) {
    InstanceConfig globalConfig = new InstanceConfig();
    String modeStr = getProperty(properties, CanalConstants.getInstanceModeKey(CanalConstants.GLOBAL_NAME));
    if (StringUtils.isNotEmpty(modeStr)) {
        globalConfig.setMode(InstanceMode.valueOf(StringUtils.upperCase(modeStr)));
    }
    String lazyStr = getProperty(properties, CanalConstants.getInstancLazyKey(CanalConstants.GLOBAL_NAME));
    if (StringUtils.isNotEmpty(lazyStr)) {
        globalConfig.setLazy(Boolean.valueOf(lazyStr));
    }
    String managerAddress = getProperty(properties, CanalConstants.getInstanceManagerAddressKey(CanalConstants.GLOBAL_NAME));
    if (StringUtils.isNotEmpty(managerAddress)) {
        globalConfig.setManagerAddress(managerAddress);
    }
    String springXml = getProperty(properties, CanalConstants.getInstancSpringXmlKey(CanalConstants.GLOBAL_NAME));
    if (StringUtils.isNotEmpty(springXml)) {
        globalConfig.setSpringXml(springXml);
    }
    instanceGenerator = new CanalInstanceGenerator() {

        public CanalInstance generate(String destination) {
            InstanceConfig config = instanceConfigs.get(destination);
            if (config == null) {
                throw new CanalServerException("can't find destination:{}");
            }
            if (config.getMode().isManager()) {
                ManagerCanalInstanceGenerator instanceGenerator = new ManagerCanalInstanceGenerator();
                instanceGenerator.setCanalConfigClient(managerClients.get(config.getManagerAddress()));
                return instanceGenerator.generate(destination);
            } else if (config.getMode().isSpring()) {
                SpringCanalInstanceGenerator instanceGenerator = new SpringCanalInstanceGenerator();
                synchronized (this) {
                    try {
                        // 设置当前正在加载的通道,加载spring查找文件时会用到该变量
                        System.setProperty(CanalConstants.CANAL_DESTINATION_PROPERTY, destination);
                        instanceGenerator.setBeanFactory(getBeanFactory(config.getSpringXml()));
                        return instanceGenerator.generate(destination);
                    } catch (Throwable e) {
                        logger.error("generator instance failed.", e);
                        throw new CanalException(e);
                    } finally {
                        System.setProperty(CanalConstants.CANAL_DESTINATION_PROPERTY, "");
                    }
                }
            } else {
                throw new UnsupportedOperationException("unknow mode :" + config.getMode());
            }
        }
    };
    return globalConfig;
}
Also used : CanalInstance(com.alibaba.otter.canal.instance.core.CanalInstance) ManagerCanalInstanceGenerator(com.alibaba.otter.canal.instance.manager.ManagerCanalInstanceGenerator) ManagerCanalInstanceGenerator(com.alibaba.otter.canal.instance.manager.ManagerCanalInstanceGenerator) CanalInstanceGenerator(com.alibaba.otter.canal.instance.core.CanalInstanceGenerator) SpringCanalInstanceGenerator(com.alibaba.otter.canal.instance.spring.SpringCanalInstanceGenerator) SpringCanalInstanceGenerator(com.alibaba.otter.canal.instance.spring.SpringCanalInstanceGenerator) CanalServerException(com.alibaba.otter.canal.server.exception.CanalServerException) CanalException(com.alibaba.otter.canal.common.CanalException)

Example 10 with CanalException

use of com.alibaba.otter.canal.common.CanalException in project otter by alibaba.

the class CanalConfigClient method findCanal.

/**
     * 根据对应的destinantion查询Canal信息
     */
public Canal findCanal(String destination) {
    FindCanalEvent event = new FindCanalEvent();
    event.setDestination(destination);
    try {
        Object obj = delegate.callManager(event);
        if (obj != null && obj instanceof Canal) {
            return (Canal) obj;
        } else {
            throw new CanalException("No Such Canal by [" + destination + "]");
        }
    } catch (Exception e) {
        throw new CanalException("call_manager_error", e);
    }
}
Also used : Canal(com.alibaba.otter.canal.instance.manager.model.Canal) FindCanalEvent(com.alibaba.otter.shared.communication.model.canal.FindCanalEvent) CanalException(com.alibaba.otter.canal.common.CanalException) CanalException(com.alibaba.otter.canal.common.CanalException)

Aggregations

CanalException (com.alibaba.otter.canal.common.CanalException)10 CanalEventParser (com.alibaba.otter.canal.parse.CanalEventParser)3 CanalHAController (com.alibaba.otter.canal.parse.ha.CanalHAController)3 CanalInstance (com.alibaba.otter.canal.instance.core.CanalInstance)2 CanalInstanceGenerator (com.alibaba.otter.canal.instance.core.CanalInstanceGenerator)2 Canal (com.alibaba.otter.canal.instance.manager.model.Canal)2 HAMode (com.alibaba.otter.canal.instance.manager.model.CanalParameter.HAMode)2 MysqlEventParser (com.alibaba.otter.canal.parse.inbound.mysql.MysqlEventParser)2 AuthenticationInfo (com.alibaba.otter.canal.parse.support.AuthenticationInfo)2 MediaHAController (com.alibaba.otter.canal.extend.ha.MediaHAController)1 AviaterRegexFilter (com.alibaba.otter.canal.filter.aviater.AviaterRegexFilter)1 CanalInstanceWithManager (com.alibaba.otter.canal.instance.manager.CanalInstanceWithManager)1 ManagerCanalInstanceGenerator (com.alibaba.otter.canal.instance.manager.ManagerCanalInstanceGenerator)1 DataSourcing (com.alibaba.otter.canal.instance.manager.model.CanalParameter.DataSourcing)1 IndexMode (com.alibaba.otter.canal.instance.manager.model.CanalParameter.IndexMode)1 MetaMode (com.alibaba.otter.canal.instance.manager.model.CanalParameter.MetaMode)1 SourcingType (com.alibaba.otter.canal.instance.manager.model.CanalParameter.SourcingType)1 StorageMode (com.alibaba.otter.canal.instance.manager.model.CanalParameter.StorageMode)1 StorageScavengeMode (com.alibaba.otter.canal.instance.manager.model.CanalParameter.StorageScavengeMode)1 SpringCanalInstanceGenerator (com.alibaba.otter.canal.instance.spring.SpringCanalInstanceGenerator)1