Search in sources :

Example 1 with CanalParameter

use of com.alibaba.otter.canal.instance.manager.model.CanalParameter in project canal by alibaba.

the class CanalServerWithEmbedded_StandaloneTest method buildCanal.

protected Canal buildCanal() {
    Canal canal = new Canal();
    canal.setId(1L);
    canal.setName(DESTINATION);
    canal.setDesc("test");
    CanalParameter parameter = new CanalParameter();
    parameter.setZkClusters(Arrays.asList("127.0.0.1:2188"));
    parameter.setMetaMode(MetaMode.MEMORY);
    parameter.setHaMode(HAMode.HEARTBEAT);
    parameter.setIndexMode(IndexMode.MEMORY);
    parameter.setStorageMode(StorageMode.MEMORY);
    parameter.setMemoryStorageBufferSize(32 * 1024);
    parameter.setSourcingType(SourcingType.MYSQL);
    parameter.setDbAddresses(Arrays.asList(new InetSocketAddress(MYSQL_ADDRESS, 3306), new InetSocketAddress(MYSQL_ADDRESS, 3306)));
    parameter.setDbUsername(USERNAME);
    parameter.setDbPassword(PASSWORD);
    parameter.setPositions(Arrays.asList("{\"journalName\":\"mysql-bin.000001\",\"position\":6163L,\"timestamp\":1322803601000L}", "{\"journalName\":\"mysql-bin.000001\",\"position\":6163L,\"timestamp\":1322803601000L}"));
    parameter.setSlaveId(1234L);
    parameter.setDefaultConnectionTimeoutInSeconds(30);
    parameter.setConnectionCharset("UTF-8");
    parameter.setConnectionCharsetNumber((byte) 33);
    parameter.setReceiveBufferSize(8 * 1024);
    parameter.setSendBufferSize(8 * 1024);
    parameter.setDetectingEnable(false);
    parameter.setDetectingIntervalInSeconds(10);
    parameter.setDetectingRetryTimes(3);
    parameter.setDetectingSQL(DETECTING_SQL);
    canal.setCanalParameter(parameter);
    return canal;
}
Also used : CanalParameter(com.alibaba.otter.canal.instance.manager.model.CanalParameter) Canal(com.alibaba.otter.canal.instance.manager.model.Canal) InetSocketAddress(java.net.InetSocketAddress)

Example 2 with CanalParameter

use of com.alibaba.otter.canal.instance.manager.model.CanalParameter in project canal by alibaba.

the class CanalServerWithEmbedded_StandbyTest method buildCanal.

protected Canal buildCanal() {
    Canal canal = new Canal();
    canal.setId(1L);
    canal.setName(DESTINATION);
    canal.setDesc("test");
    CanalParameter parameter = new CanalParameter();
    parameter.setZkClusters(Arrays.asList("127.0.0.1:2188"));
    // 冷备,可选择混合模式
    parameter.setMetaMode(MetaMode.MIXED);
    parameter.setHaMode(HAMode.HEARTBEAT);
    // 内存版store,需要选择meta做为index
    parameter.setIndexMode(IndexMode.META);
    parameter.setStorageMode(StorageMode.MEMORY);
    parameter.setMemoryStorageBufferSize(32 * 1024);
    parameter.setSourcingType(SourcingType.MYSQL);
    parameter.setDbAddresses(Arrays.asList(new InetSocketAddress(MYSQL_ADDRESS, 3306), new InetSocketAddress(MYSQL_ADDRESS, 3306)));
    parameter.setDbUsername(USERNAME);
    parameter.setDbPassword(PASSWORD);
    parameter.setPositions(Arrays.asList("{\"journalName\":\"mysql-bin.000001\",\"position\":6163L,\"timestamp\":1322803601000L}", "{\"journalName\":\"mysql-bin.000001\",\"position\":6163L,\"timestamp\":1322803601000L}"));
    parameter.setSlaveId(1234L);
    parameter.setDefaultConnectionTimeoutInSeconds(30);
    parameter.setConnectionCharset("UTF-8");
    parameter.setConnectionCharsetNumber((byte) 33);
    parameter.setReceiveBufferSize(8 * 1024);
    parameter.setSendBufferSize(8 * 1024);
    parameter.setDetectingEnable(false);
    parameter.setDetectingIntervalInSeconds(10);
    parameter.setDetectingRetryTimes(3);
    parameter.setDetectingSQL(DETECTING_SQL);
    canal.setCanalParameter(parameter);
    return canal;
}
Also used : CanalParameter(com.alibaba.otter.canal.instance.manager.model.CanalParameter) Canal(com.alibaba.otter.canal.instance.manager.model.Canal) InetSocketAddress(java.net.InetSocketAddress)

Example 3 with CanalParameter

use of com.alibaba.otter.canal.instance.manager.model.CanalParameter in project canal by alibaba.

the class CanalServerWithNettyTest method buildCanal.

private Canal buildCanal() {
    Canal canal = new Canal();
    canal.setId(1L);
    canal.setName(DESTINATION);
    canal.setDesc("test");
    CanalParameter parameter = new CanalParameter();
    parameter.setZkClusters(Arrays.asList("127.0.0.1:2188"));
    parameter.setMetaMode(MetaMode.MEMORY);
    parameter.setHaMode(HAMode.HEARTBEAT);
    parameter.setIndexMode(IndexMode.MEMORY);
    parameter.setStorageMode(StorageMode.MEMORY);
    parameter.setMemoryStorageBufferSize(32 * 1024);
    parameter.setSourcingType(SourcingType.MYSQL);
    parameter.setDbAddresses(Arrays.asList(new InetSocketAddress(MYSQL_ADDRESS, 3306), new InetSocketAddress(MYSQL_ADDRESS, 3306)));
    parameter.setDbUsername(USERNAME);
    parameter.setDbPassword(PASSWORD);
    parameter.setPositions(Arrays.asList("{\"journalName\":\"mysql-bin.000001\",\"position\":6163L,\"timestamp\":1322803601000L}", "{\"journalName\":\"mysql-bin.000001\",\"position\":6163L,\"timestamp\":1322803601000L}"));
    parameter.setSlaveId(1234L);
    parameter.setDefaultConnectionTimeoutInSeconds(30);
    parameter.setConnectionCharset("UTF-8");
    parameter.setConnectionCharsetNumber((byte) 33);
    parameter.setReceiveBufferSize(8 * 1024);
    parameter.setSendBufferSize(8 * 1024);
    parameter.setDetectingEnable(false);
    parameter.setDetectingIntervalInSeconds(10);
    parameter.setDetectingRetryTimes(3);
    parameter.setDetectingSQL(DETECTING_SQL);
    canal.setCanalParameter(parameter);
    return canal;
}
Also used : CanalParameter(com.alibaba.otter.canal.instance.manager.model.CanalParameter) Canal(com.alibaba.otter.canal.instance.manager.model.Canal) InetSocketAddress(java.net.InetSocketAddress)

Example 4 with CanalParameter

use of com.alibaba.otter.canal.instance.manager.model.CanalParameter in project otter by alibaba.

the class CanalAction method doAdd.

/**
     * 添加canal
     */
public void doAdd(@FormGroup("canalInfo") Group canalInfo, @FormGroup("canalParameterInfo") Group canalParameterInfo, @FormField(name = "formCanalError", group = "canalInfo") CustomErrors err, @FormField(name = "formHeartBeatError", group = "canalParameterInfo") CustomErrors heartBeatErr, Navigator nav) throws Exception {
    Canal canal = new Canal();
    CanalParameter parameter = new CanalParameter();
    canalInfo.setProperties(canal);
    canalParameterInfo.setProperties(parameter);
    String zkClustersString = canalParameterInfo.getField("zkClusters").getStringValue();
    String[] zkClusters = StringUtils.split(zkClustersString, ";");
    parameter.setZkClusters(Arrays.asList(zkClusters));
    Long zkClusterId = canalParameterInfo.getField("autoKeeperClusterId").getLongValue();
    parameter.setZkClusterId(zkClusterId);
    canal.setCanalParameter(parameter);
    String dbAddressesString = canalParameterInfo.getField("groupDbAddresses").getStringValue();
    // 第一层的分号代表主备概念,,第二层逗号代表分组概念
    if (StringUtils.isNotEmpty(dbAddressesString)) {
        List<List<DataSourcing>> dbSocketAddress = new ArrayList<List<DataSourcing>>();
        String[] dbAddresses = StringUtils.split(dbAddressesString, ";");
        for (String dbAddressString : dbAddresses) {
            List<DataSourcing> groupDbSocketAddress = new ArrayList<DataSourcing>();
            String[] groupDbAddresses = StringUtils.split(dbAddressString, ",");
            for (String groupDbAddress : groupDbAddresses) {
                String[] strs = StringUtils.split(groupDbAddress, ":");
                InetSocketAddress address = new InetSocketAddress(strs[0].trim(), Integer.valueOf(strs[1]));
                SourcingType type = parameter.getSourcingType();
                if (strs.length > 2) {
                    type = SourcingType.valueOf(strs[2]);
                }
                groupDbSocketAddress.add(new DataSourcing(type, address));
            }
            dbSocketAddress.add(groupDbSocketAddress);
        }
        parameter.setGroupDbAddresses(dbSocketAddress);
    }
    String positionsString = canalParameterInfo.getField("positions").getStringValue();
    if (StringUtils.isNotEmpty(positionsString)) {
        String[] positions = StringUtils.split(positionsString, ";");
        parameter.setPositions(Arrays.asList(positions));
    }
    if (parameter.getDetectingEnable() && StringUtils.startsWithIgnoreCase(parameter.getDetectingSQL(), "select")) {
        heartBeatErr.setMessage("invaliedHeartBeat");
        return;
    }
    try {
        canalService.create(canal);
    } catch (RepeatConfigureException rce) {
        err.setMessage("invalidCanal");
        return;
    }
    if (parameter.getSourcingType().isMysql() && parameter.getSlaveId() == null) {
        parameter.setSlaveId(10000 + canal.getId());
        // 再次更新一下slaveId
        try {
            canalService.modify(canal);
        } catch (RepeatConfigureException rce) {
            err.setMessage("invalidCanal");
            return;
        }
    }
    nav.redirectTo(WebConstant.CANAL_LIST_LINK);
}
Also used : SourcingType(com.alibaba.otter.canal.instance.manager.model.CanalParameter.SourcingType) Canal(com.alibaba.otter.canal.instance.manager.model.Canal) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) CanalParameter(com.alibaba.otter.canal.instance.manager.model.CanalParameter) ArrayList(java.util.ArrayList) List(java.util.List) DataSourcing(com.alibaba.otter.canal.instance.manager.model.CanalParameter.DataSourcing)

Example 5 with CanalParameter

use of com.alibaba.otter.canal.instance.manager.model.CanalParameter in project otter by alibaba.

the class CanalAction method doEdit.

/**
     * 修改canal
     */
public void doEdit(@FormGroup("canalInfo") Group canalInfo, @FormGroup("canalParameterInfo") Group canalParameterInfo, @FormField(name = "formCanalError", group = "canalInfo") CustomErrors err, @FormField(name = "formHeartBeatError", group = "canalParameterInfo") CustomErrors heartBeatErr, Navigator nav) throws Exception {
    Canal canal = new Canal();
    CanalParameter parameter = new CanalParameter();
    canalInfo.setProperties(canal);
    canalParameterInfo.setProperties(parameter);
    String zkClustersString = canalParameterInfo.getField("zkClusters").getStringValue();
    String[] zkClusters = StringUtils.split(zkClustersString, ";");
    parameter.setZkClusters(Arrays.asList(zkClusters));
    Long zkClusterId = canalParameterInfo.getField("autoKeeperClusterId").getLongValue();
    parameter.setZkClusterId(zkClusterId);
    String dbAddressesString = canalParameterInfo.getField("groupDbAddresses").getStringValue();
    if (StringUtils.isNotEmpty(dbAddressesString)) {
        List<List<DataSourcing>> dbSocketAddress = new ArrayList<List<DataSourcing>>();
        String[] dbAddresses = StringUtils.split(dbAddressesString, ";");
        for (String dbAddressString : dbAddresses) {
            List<DataSourcing> groupDbSocketAddress = new ArrayList<DataSourcing>();
            String[] groupDbAddresses = StringUtils.split(dbAddressString, ",");
            for (String groupDbAddress : groupDbAddresses) {
                String[] strs = StringUtils.split(groupDbAddress, ":");
                InetSocketAddress address = new InetSocketAddress(strs[0].trim(), Integer.valueOf(strs[1]));
                SourcingType type = parameter.getSourcingType();
                if (strs.length > 2) {
                    type = SourcingType.valueOf(strs[2]);
                }
                groupDbSocketAddress.add(new DataSourcing(type, address));
            }
            dbSocketAddress.add(groupDbSocketAddress);
        }
        parameter.setGroupDbAddresses(dbSocketAddress);
    }
    String positionsString = canalParameterInfo.getField("positions").getStringValue();
    if (StringUtils.isNotEmpty(positionsString)) {
        String[] positions = StringUtils.split(positionsString, ";");
        parameter.setPositions(Arrays.asList(positions));
    }
    if (parameter.getDetectingEnable() && StringUtils.startsWithIgnoreCase(parameter.getDetectingSQL(), "select")) {
        heartBeatErr.setMessage("invaliedHeartBeat");
        return;
    }
    canal.setCanalParameter(parameter);
    try {
        canalService.modify(canal);
    } catch (RepeatConfigureException rce) {
        err.setMessage("invalidCanal");
        return;
    }
    nav.redirectToLocation("canalList.htm");
}
Also used : SourcingType(com.alibaba.otter.canal.instance.manager.model.CanalParameter.SourcingType) Canal(com.alibaba.otter.canal.instance.manager.model.Canal) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) CanalParameter(com.alibaba.otter.canal.instance.manager.model.CanalParameter) ArrayList(java.util.ArrayList) List(java.util.List) DataSourcing(com.alibaba.otter.canal.instance.manager.model.CanalParameter.DataSourcing)

Aggregations

CanalParameter (com.alibaba.otter.canal.instance.manager.model.CanalParameter)7 Canal (com.alibaba.otter.canal.instance.manager.model.Canal)6 InetSocketAddress (java.net.InetSocketAddress)5 DataSourcing (com.alibaba.otter.canal.instance.manager.model.CanalParameter.DataSourcing)3 RepeatConfigureException (com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)3 SourcingType (com.alibaba.otter.canal.instance.manager.model.CanalParameter.SourcingType)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ManagerException (com.alibaba.otter.manager.biz.common.exceptions.ManagerException)1 AutoKeeperCluster (com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperCluster)1