Search in sources :

Example 6 with CanalConfig

use of com.alibaba.otter.canal.admin.model.CanalConfig in project canal by alibaba.

the class NodeServerServiceImpl method save.

public void save(NodeServer nodeServer) {
    int cnt = NodeServer.find.query().where().eq("ip", nodeServer.getIp()).eq("adminPort", nodeServer.getAdminPort()).findCount();
    if (cnt > 0) {
        throw new ServiceException("节点信息已存在");
    }
    nodeServer.save();
    if (nodeServer.getClusterId() == null) {
        // 单机模式
        CanalConfig canalConfig = new CanalConfig();
        canalConfig.setServerId(nodeServer.getId());
        String configTmp = TemplateConfigLoader.loadCanalConfig();
        canalConfig.setContent(configTmp);
        try {
            String contentMd5 = SecurityUtil.md5String(canalConfig.getContent());
            canalConfig.setContentMd5(contentMd5);
        } catch (NoSuchAlgorithmException e) {
        }
        canalConfig.save();
    }
}
Also used : CanalConfig(com.alibaba.otter.canal.admin.model.CanalConfig) ServiceException(com.alibaba.otter.canal.admin.common.exception.ServiceException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

CanalConfig (com.alibaba.otter.canal.admin.model.CanalConfig)6 ServiceException (com.alibaba.otter.canal.admin.common.exception.ServiceException)4 NodeServer (com.alibaba.otter.canal.admin.model.NodeServer)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Date (java.util.Date)1