use of com.alibaba.otter.canal.admin.connector.AdminConnector in project canal by alibaba.
the class CanalInstanceServiceImpl method findActiveInstanceByServerId.
/**
* 通过Server id获取当前Server下所有运行的Instance
*
* @param serverId server id
*/
public List<CanalInstanceConfig> findActiveInstanceByServerId(Long serverId) {
NodeServer nodeServer = NodeServer.find.byId(serverId);
if (nodeServer == null) {
return null;
}
String runningInstances = SimpleAdminConnectors.execute(nodeServer.getIp(), nodeServer.getAdminPort(), AdminConnector::getRunningInstances);
if (runningInstances == null) {
return null;
}
String[] instances = runningInstances.split(",");
Object[] obj = Lists.newArrayList(instances).toArray();
// 单机模式和集群模式区分处理
if (nodeServer.getClusterId() != null) {
// 集群模式
List<CanalInstanceConfig> list = CanalInstanceConfig.find.query().setDisableLazyLoading(true).select("clusterId, serverId, name, modifiedTime").where().in("name", obj).findList();
list.forEach(config -> config.setRunningStatus("1"));
// 集群模式直接返回当前运行的Instances
return list;
} else {
// 单机模式
// 当前Server所配置的所有Instance
List<CanalInstanceConfig> list = CanalInstanceConfig.find.query().setDisableLazyLoading(true).select("clusterId, serverId, name, modifiedTime").where().eq("serverId", serverId).findList();
List<String> instanceList = Arrays.asList(instances);
list.forEach(config -> {
if (instanceList.contains(config.getName())) {
config.setRunningStatus("1");
}
});
return list;
}
}
use of com.alibaba.otter.canal.admin.connector.AdminConnector 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;
}
Aggregations