use of com.alibaba.otter.canal.admin.common.exception.ServiceException in project canal by alibaba.
the class NodeServerServiceImpl method save.
public void save(NodeServer nodeServer) {
int cnt = NodeServer.find.query().where().eq("ip", nodeServer.getIp()).eq("adminPort", nodeServer.getAdminPort()).findCount();
if (cnt > 0) {
throw new ServiceException("节点信息已存在");
}
nodeServer.save();
if (nodeServer.getClusterId() == null) {
// 单机模式
CanalConfig canalConfig = new CanalConfig();
canalConfig.setServerId(nodeServer.getId());
String configTmp = TemplateConfigLoader.loadCanalConfig();
canalConfig.setContent(configTmp);
try {
String contentMd5 = SecurityUtil.md5String(canalConfig.getContent());
canalConfig.setContentMd5(contentMd5);
} catch (NoSuchAlgorithmException e) {
}
canalConfig.save();
}
}
use of com.alibaba.otter.canal.admin.common.exception.ServiceException in project canal by alibaba.
the class UserServiceImpl method update.
public void update(User user) {
User userTmp = User.find.query().where().eq("username", user.getUsername()).findOne();
if (userTmp == null) {
throw new ServiceException();
}
try {
byte[] pass = SecurityUtil.scramble411(user.getOldPassword().getBytes(), seeds);
if (!SecurityUtil.scrambleServerAuth(pass, SecurityUtil.hexStr2Bytes(userTmp.getPassword()), seeds)) {
throw new ServiceException("old passwd is unmatch");
}
user.setId(userTmp.getId());
user.setPassword(SecurityUtil.scrambleGenPass(user.getPassword().getBytes()));
} catch (NoSuchAlgorithmException e) {
throw new ServiceException("passwd process failed");
}
user.update("username", "nn:password");
}
use of com.alibaba.otter.canal.admin.common.exception.ServiceException 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;
}
use of com.alibaba.otter.canal.admin.common.exception.ServiceException in project canal by alibaba.
the class CustomExceptionHandler method commonExceptionHandle.
/**
* 通用异常处理
*
* @param e 异常
* @return
*/
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@ExceptionHandler(value = Exception.class)
public BaseModel commonExceptionHandle(Exception e) {
if (e instanceof ServiceException) {
logger.error(e.getMessage());
} else {
logger.error(e.getMessage(), e);
}
BaseModel res = new BaseModel();
res.setCode(50000);
res.setMessage(e.getMessage());
return res;
}
Aggregations