Search in sources :

Example 1 with CanalCluster

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

the class CanalClusterController method clustersAndServers.

@GetMapping(value = "/clustersAndServers")
public BaseModel<List<?>> clustersAndServers(@PathVariable String env) {
    List<CanalCluster> clusters = canalClusterServic.findList(new CanalCluster());
    JSONObject group = new JSONObject();
    group.put("label", "集群");
    JSONArray jsonArray = new JSONArray();
    clusters.forEach(cluster -> {
        JSONObject item = new JSONObject();
        item.put("label", cluster.getName());
        item.put("value", "cluster:" + cluster.getId());
        jsonArray.add(item);
    });
    group.put("options", jsonArray);
    NodeServer param = new NodeServer();
    param.setClusterId(-1L);
    // 取所有standalone的节点
    List<NodeServer> servers = nodeServerService.findAll(param);
    JSONObject group2 = new JSONObject();
    group2.put("label", "单机主机");
    JSONArray jsonArray2 = new JSONArray();
    servers.forEach(server -> {
        JSONObject item = new JSONObject();
        item.put("label", server.getName());
        item.put("value", "server:" + server.getId());
        jsonArray2.add(item);
    });
    group2.put("options", jsonArray2);
    List<JSONObject> result = new ArrayList<>();
    result.add(group);
    result.add(group2);
    return BaseModel.getInstance(result);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) ArrayList(java.util.ArrayList) CanalCluster(com.alibaba.otter.canal.admin.model.CanalCluster) NodeServer(com.alibaba.otter.canal.admin.model.NodeServer) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with CanalCluster

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

the class CanalClusterServiceImpl method delete.

public void delete(Long id) {
    // 判断集群下是否存在server信息
    int serverCnt = NodeServer.find.query().where().eq("clusterId", id).findCount();
    if (serverCnt > 0) {
        throw new ServiceException("当前集群下存在Server, 无法删除");
    }
    // 判断集群下是否存在instance信息
    int instanceCnt = CanalInstanceConfig.find.query().where().eq("clusterId", id).findCount();
    if (instanceCnt > 0) {
        throw new ServiceException("当前集群下存在Instance配置,无法删除");
    }
    CanalCluster canalCluster = CanalCluster.find.byId(id);
    if (canalCluster != null) {
        canalCluster.delete();
    }
}
Also used : ServiceException(com.alibaba.otter.canal.admin.common.exception.ServiceException) CanalCluster(com.alibaba.otter.canal.admin.model.CanalCluster)

Example 3 with CanalCluster

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

the class PollingConfigServiceImpl method autoRegister.

public boolean autoRegister(String ip, Integer adminPort, String cluster, String name) {
    NodeServer server = NodeServer.find.query().where().eq("ip", ip).eq("adminPort", adminPort).findOne();
    if (server == null) {
        server = new NodeServer();
        server.setName(Optional.ofNullable(name).orElse(ip));
        server.setIp(ip);
        server.setAdminPort(adminPort);
        server.setTcpPort(adminPort + 1);
        server.setMetricPort(adminPort + 2);
        if (StringUtils.isNotEmpty(cluster)) {
            CanalCluster clusterConfig = CanalCluster.find.query().where().eq("name", cluster).findOne();
            if (clusterConfig == null) {
                throw new ServiceException("auto cluster : " + cluster + " is not found.");
            }
            server.setClusterId(clusterConfig.getId());
        }
        nodeServerService.save(server);
    }
    return true;
}
Also used : ServiceException(com.alibaba.otter.canal.admin.common.exception.ServiceException) CanalCluster(com.alibaba.otter.canal.admin.model.CanalCluster) NodeServer(com.alibaba.otter.canal.admin.model.NodeServer)

Aggregations

CanalCluster (com.alibaba.otter.canal.admin.model.CanalCluster)3 ServiceException (com.alibaba.otter.canal.admin.common.exception.ServiceException)2 NodeServer (com.alibaba.otter.canal.admin.model.NodeServer)2 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 ArrayList (java.util.ArrayList)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1