Search in sources :

Example 1 with CanalConfig

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

the class NodeServerServiceImpl method delete.

public void delete(Long id) {
    NodeServer nodeServer = NodeServer.find.byId(id);
    if (nodeServer != null) {
        // 判断是否存在实例
        int cnt = CanalInstanceConfig.find.query().where().eq("serverId", nodeServer.getId()).findCount();
        if (cnt > 0) {
            throw new ServiceException("当前Server下存在Instance配置, 无法删除");
        }
        // 同时删除配置
        CanalConfig canalConfig = CanalConfig.find.query().where().eq("serverId", id).findOne();
        if (canalConfig != null) {
            canalConfig.delete();
        }
        nodeServer.delete();
    }
}
Also used : CanalConfig(com.alibaba.otter.canal.admin.model.CanalConfig) ServiceException(com.alibaba.otter.canal.admin.common.exception.ServiceException) NodeServer(com.alibaba.otter.canal.admin.model.NodeServer)

Example 2 with CanalConfig

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

the class PollingConfigServiceImpl method getChangedConfig.

public CanalConfig getChangedConfig(String ip, Integer port, String md5) {
    NodeServer server = NodeServer.find.query().where().eq("ip", ip).eq("adminPort", port).findOne();
    if (server == null) {
        return null;
    }
    CanalConfig canalConfig;
    if (server.getClusterId() != null) {
        // 集群模式
        canalConfig = CanalConfig.find.query().where().eq("clusterId", server.getClusterId()).findOne();
    } else {
        // 单机模式
        canalConfig = CanalConfig.find.query().where().eq("serverId", server.getId()).findOne();
    }
    if (canalConfig == null) {
        throw new ServiceException("canal.properties config is empty");
    }
    if (!canalConfig.getContentMd5().equals(md5)) {
        // 内容发生变化
        return canalConfig;
    }
    return null;
}
Also used : CanalConfig(com.alibaba.otter.canal.admin.model.CanalConfig) ServiceException(com.alibaba.otter.canal.admin.common.exception.ServiceException) NodeServer(com.alibaba.otter.canal.admin.model.NodeServer)

Example 3 with CanalConfig

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

the class CanalConfigServiceImpl method getAdapterConfig.

public CanalConfig getAdapterConfig() {
    long id = 2L;
    CanalConfig config = CanalConfig.find.byId(id);
    if (config == null) {
        String context = loadDefaultConf(CANAL_ADAPTER_CONFIG);
        if (context == null) {
            return null;
        }
        config = new CanalConfig();
        config.setId(id);
        config.setName(CANAL_ADAPTER_CONFIG);
        config.setModifiedTime(new Date());
        config.setContent(context);
        return config;
    }
    return config;
}
Also used : CanalConfig(com.alibaba.otter.canal.admin.model.CanalConfig) Date(java.util.Date)

Example 4 with CanalConfig

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

the class CanalConfigServiceImpl method updateContent.

public void updateContent(CanalConfig canalConfig) {
    try {
        String contentMd5 = SecurityUtil.md5String(canalConfig.getContent());
        canalConfig.setContentMd5(contentMd5);
    } catch (NoSuchAlgorithmException e) {
    // ignore
    }
    if (canalConfig.getId() != null) {
        CanalConfig canalConfigTmp = CanalConfig.find.byId(canalConfig.getId());
        if (canalConfigTmp != null && canalConfigTmp.getClusterId() != null) {
            canalConfig.setServerId(null);
        }
        canalConfig.update("serverId", "content", "contentMd5");
    } else {
        canalConfig.save();
    }
}
Also used : CanalConfig(com.alibaba.otter.canal.admin.model.CanalConfig) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 5 with CanalConfig

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

the class CanalConfigServiceImpl method getCanalConfig.

public CanalConfig getCanalConfig(Long clusterId, Long serverId) {
    CanalConfig config = null;
    if (clusterId != null && clusterId != 0) {
        config = CanalConfig.find.query().where().eq("clusterId", clusterId).findOne();
    } else if (serverId != null && serverId != 0) {
        config = CanalConfig.find.query().where().eq("serverId", serverId).findOne();
        if (config == null) {
            NodeServer nodeServer = NodeServer.find.byId(serverId);
            if (nodeServer != null) {
                Long cid = nodeServer.getClusterId();
                if (cid != null) {
                    config = CanalConfig.find.query().where().eq("clusterId", cid).findOne();
                }
            }
        }
    } else {
        throw new ServiceException("clusterId and serverId are all empty");
    }
    if (config == null) {
        config = new CanalConfig();
        config.setName(CANAL_GLOBAL_CONFIG);
        return config;
    }
    return config;
}
Also used : CanalConfig(com.alibaba.otter.canal.admin.model.CanalConfig) ServiceException(com.alibaba.otter.canal.admin.common.exception.ServiceException) NodeServer(com.alibaba.otter.canal.admin.model.NodeServer)

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