use of com.alibaba.otter.canal.admin.common.exception.ServiceException 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();
}
}
use of com.alibaba.otter.canal.admin.common.exception.ServiceException in project canal by alibaba.
the class CanalInstanceServiceImpl method remoteOperation.
public boolean remoteOperation(Long id, Long nodeId, String option) {
NodeServer nodeServer = null;
if ("start".equals(option)) {
if (nodeId != null) {
nodeServer = NodeServer.find.byId(nodeId);
} else {
nodeServer = NodeServer.find.query().findOne();
}
} else {
if (nodeId == null) {
return false;
}
nodeServer = NodeServer.find.byId(nodeId);
}
if (nodeServer == null) {
return false;
}
CanalInstanceConfig canalInstanceConfig = CanalInstanceConfig.find.byId(id);
if (canalInstanceConfig == null) {
return false;
}
Boolean result = null;
if ("start".equals(option)) {
if (nodeServer.getClusterId() == null) {
// 非集群模式
return instanceOperation(id, "start");
} else {
throw new ServiceException("集群模式不允许指定server启动");
}
} else if ("stop".equals(option)) {
if (nodeServer.getClusterId() != null) {
// 集群模式,通知主动释放
result = SimpleAdminConnectors.execute(nodeServer.getIp(), nodeServer.getAdminPort(), adminConnector -> adminConnector.releaseInstance(canalInstanceConfig.getName()));
} else {
// 非集群模式下直接将状态置为0
return instanceOperation(id, "stop");
}
} else {
return false;
}
if (result == null) {
result = false;
}
return result;
}
use of com.alibaba.otter.canal.admin.common.exception.ServiceException 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;
}
use of com.alibaba.otter.canal.admin.common.exception.ServiceException in project canal by alibaba.
the class SimpleAdminConnector method doInstanceAdmin.
private String doInstanceAdmin(String destination, String action) {
try {
writeWithHeader(Packet.newBuilder().setType(PacketType.INSTANCE).setBody(InstanceAdmin.newBuilder().setDestination(destination).setAction(action).build().toByteString()).build().toByteArray());
Packet p = Packet.parseFrom(readNextPacket());
Ack ack = Ack.parseFrom(p.getBody());
if (ack.getCode() > 0) {
throw new ServiceException("failed to subscribe with reason: " + ack.getMessage());
}
return ack.getMessage();
} catch (IOException e) {
throw new ServiceException(e);
}
}
use of com.alibaba.otter.canal.admin.common.exception.ServiceException 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;
}
Aggregations