fixed admin

This commit is contained in:
agapple
2019-08-31 12:24:41 +08:00
parent 274e91f8aa
commit 4e0b8a0278
59 changed files with 523 additions and 406 deletions

View File

@@ -2,7 +2,7 @@ package com.alibaba.otter.canal.admin;
/**
* Canal Admin动态管理接口
*
*
* @author agapple 2019年8月24日 下午9:45:49
* @since 1.1.4
*/
@@ -41,13 +41,6 @@ public interface CanalAdmin {
*/
boolean restart();
/**
* 获取所有当前节点下所有实例
*
* @return 实例信息
*/
String getInstances();
/**
* 获取所有当前节点下运行中的实例
*
@@ -57,7 +50,7 @@ public interface CanalAdmin {
/**
* 通过实例名检查
*
*
* @param destination
* @return
*/
@@ -79,6 +72,14 @@ public interface CanalAdmin {
*/
boolean stopInstance(String destination);
/**
* 通过实例名释放,主要针对cluster模式有效(通知当前主机释放instance运行交给其他人来抢占)
*
* @param destination 实例名
* @return 是否成功
*/
boolean releaseInstance(String destination);
/**
* 通过实例名重启实例
*
@@ -103,7 +104,7 @@ public interface CanalAdmin {
/**
* 获取Instance的机器日志列表
*
*
* @param destination
*/
String listInstanceLog(String destination);

View File

@@ -58,9 +58,6 @@ public class SessionHandler extends SimpleChannelHandler {
case "list":
message = canalAdmin.getRunningInstances();
break;
case "instances":
message = canalAdmin.getInstances();
break;
default:
byte[] errorBytes = AdminNettyUtils.errorPacket(301,
MessageFormatter.format("ServerAdmin action={} is unknown", action).getMessage());
@@ -83,6 +80,9 @@ public class SessionHandler extends SimpleChannelHandler {
case "stop":
message = canalAdmin.stopInstance(destination) ? "1" : "0";
break;
case "release":
message = canalAdmin.releaseInstance(destination) ? "1" : "0";
break;
case "restart":
message = canalAdmin.restartInstance(destination) ? "1" : "0";
break;
@@ -132,11 +132,9 @@ public class SessionHandler extends SimpleChannelHandler {
}
} catch (Throwable exception) {
byte[] errorBytes = AdminNettyUtils.errorPacket(400,
MessageFormatter
.format("something goes wrong with channel:{}, exception={}",
ctx.getChannel(),
ExceptionUtils.getStackTrace(exception))
.getMessage());
MessageFormatter.format("something goes wrong with channel:{}, exception={}",
ctx.getChannel(),
ExceptionUtils.getStackTrace(exception)).getMessage());
AdminNettyUtils.write(ctx.getChannel(), errorBytes);
}
}

View File

@@ -42,7 +42,7 @@ public class CanalMQStarter {
this.canalMQProducer = canalMQProducer;
}
public synchronized void start(MQProperties properties) {
public synchronized void start(MQProperties properties, String destinations) {
try {
if (running) {
return;
@@ -60,8 +60,8 @@ public class CanalMQStarter {
executorService = Executors.newCachedThreadPool();
logger.info("## start the MQ workers.");
String[] destinations = StringUtils.split(System.getProperty("canal.destinations"), ",");
for (String destination : destinations) {
String[] dsts = StringUtils.split(destinations, ",");
for (String destination : dsts) {
destination = destination.trim();
CanalMQRunnable canalMQRunnable = new CanalMQRunnable(destination);
canalMQWorks.put(destination, canalMQRunnable);