Search in sources :

Example 11 with ServiceException

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();
    }
}
Also used : CanalConfig(com.alibaba.otter.canal.admin.model.CanalConfig) ServiceException(com.alibaba.otter.canal.admin.common.exception.ServiceException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 12 with ServiceException

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");
}
Also used : User(com.alibaba.otter.canal.admin.model.User) ServiceException(com.alibaba.otter.canal.admin.common.exception.ServiceException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 13 with ServiceException

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;
}
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)

Example 14 with ServiceException

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;
}
Also used : ServiceException(com.alibaba.otter.canal.admin.common.exception.ServiceException) BaseModel(com.alibaba.otter.canal.admin.model.BaseModel) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ServiceException (com.alibaba.otter.canal.admin.common.exception.ServiceException)14 NodeServer (com.alibaba.otter.canal.admin.model.NodeServer)5 CanalConfig (com.alibaba.otter.canal.admin.model.CanalConfig)4 Ack (com.alibaba.otter.canal.protocol.AdminPacket.Ack)4 Packet (com.alibaba.otter.canal.protocol.AdminPacket.Packet)4 IOException (java.io.IOException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 CanalCluster (com.alibaba.otter.canal.admin.model.CanalCluster)2 User (com.alibaba.otter.canal.admin.model.User)2 BaseModel (com.alibaba.otter.canal.admin.model.BaseModel)1 CanalInstanceConfig (com.alibaba.otter.canal.admin.model.CanalInstanceConfig)1 ClientAuth (com.alibaba.otter.canal.protocol.AdminPacket.ClientAuth)1 Handshake (com.alibaba.otter.canal.protocol.AdminPacket.Handshake)1 CanalClientException (com.alibaba.otter.canal.protocol.exception.CanalClientException)1 ByteString (com.google.protobuf.ByteString)1 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1