Search in sources :

Example 6 with NodeServer

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

the class PollingConfigServiceImpl method getInstancesConfig.

public CanalInstanceConfig getInstancesConfig(String ip, Integer port, String md5) {
    NodeServer server = NodeServer.find.query().where().eq("ip", ip).eq("adminPort", port).findOne();
    if (server == null) {
        return null;
    }
    List<CanalInstanceConfig> canalInstanceConfigs;
    if (server.getClusterId() != null) {
        // 集群模式
        canalInstanceConfigs = CanalInstanceConfig.find.query().where().eq("status", "1").eq("clusterId", server.getClusterId()).findList();
    } else {
        // 单机模式
        canalInstanceConfigs = CanalInstanceConfig.find.query().where().eq("status", "1").eq("serverId", server.getId()).findList();
    }
    CanalInstanceConfig canalInstanceConfig = new CanalInstanceConfig();
    List<String> instances = canalInstanceConfigs.stream().map(CanalInstanceConfig::getName).collect(Collectors.toList());
    String data = Joiner.on(',').join(instances);
    canalInstanceConfig.setContent(data);
    if (!StringUtils.isEmpty(md5)) {
        try {
            String newMd5 = SecurityUtil.md5String(canalInstanceConfig.getContent());
            if (StringUtils.equals(md5, newMd5)) {
                canalInstanceConfig.setContent(null);
            }
        } catch (NoSuchAlgorithmException e) {
        // ignore
        }
    }
    return canalInstanceConfig;
}
Also used : CanalInstanceConfig(com.alibaba.otter.canal.admin.model.CanalInstanceConfig) NodeServer(com.alibaba.otter.canal.admin.model.NodeServer) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 7 with NodeServer

use of com.alibaba.otter.canal.admin.model.NodeServer 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 8 with NodeServer

use of com.alibaba.otter.canal.admin.model.NodeServer 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)

Example 9 with NodeServer

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

the class NodeServerServiceImpl method remoteOperation.

public boolean remoteOperation(Long id, String option) {
    NodeServer nodeServer = NodeServer.find.byId(id);
    if (nodeServer == null) {
        return false;
    }
    Boolean result = null;
    if ("start".equals(option)) {
        result = SimpleAdminConnectors.execute(nodeServer.getIp(), nodeServer.getAdminPort(), AdminConnector::start);
    } else if ("stop".equals(option)) {
        result = SimpleAdminConnectors.execute(nodeServer.getIp(), nodeServer.getAdminPort(), AdminConnector::stop);
    } else {
        return false;
    }
    if (result == null) {
        result = false;
    }
    return result;
}
Also used : AdminConnector(com.alibaba.otter.canal.admin.connector.AdminConnector) NodeServer(com.alibaba.otter.canal.admin.model.NodeServer)

Example 10 with NodeServer

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

the class CanalInstanceServiceImpl method remoteInstanceLog.

public Map<String, String> remoteInstanceLog(Long id, Long nodeId) {
    Map<String, String> result = new HashMap<>();
    NodeServer nodeServer = NodeServer.find.byId(nodeId);
    if (nodeServer == null) {
        return result;
    }
    CanalInstanceConfig canalInstanceConfig = CanalInstanceConfig.find.byId(id);
    if (canalInstanceConfig == null) {
        return result;
    }
    String log = SimpleAdminConnectors.execute(nodeServer.getIp(), nodeServer.getAdminPort(), adminConnector -> adminConnector.instanceLog(canalInstanceConfig.getName(), null, 100));
    result.put("instance", canalInstanceConfig.getName());
    result.put("log", log);
    return result;
}
Also used : HashMap(java.util.HashMap) CanalInstanceConfig(com.alibaba.otter.canal.admin.model.CanalInstanceConfig) NodeServer(com.alibaba.otter.canal.admin.model.NodeServer)

Aggregations

NodeServer (com.alibaba.otter.canal.admin.model.NodeServer)12 ServiceException (com.alibaba.otter.canal.admin.common.exception.ServiceException)5 CanalInstanceConfig (com.alibaba.otter.canal.admin.model.CanalInstanceConfig)5 CanalConfig (com.alibaba.otter.canal.admin.model.CanalConfig)3 ArrayList (java.util.ArrayList)3 AdminConnector (com.alibaba.otter.canal.admin.connector.AdminConnector)2 CanalCluster (com.alibaba.otter.canal.admin.model.CanalCluster)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2 TimeoutException (java.util.concurrent.TimeoutException)2 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1