Search in sources :

Example 1 with CanalDO

use of com.alibaba.otter.manager.biz.config.canal.dal.dataobject.CanalDO in project otter by alibaba.

the class CanalServiceImpl method listByIds.

public List<Canal> listByIds(Long... identities) {
    List<Canal> canals = new ArrayList<Canal>();
    try {
        List<CanalDO> canalDos = null;
        if (identities.length < 1) {
            canalDos = canalDao.listAll();
            if (canalDos.isEmpty()) {
                logger.debug("DEBUG ## couldn't query any canal, maybe hasn't create any canal.");
                return canals;
            }
        } else {
            canalDos = canalDao.listByMultiId(identities);
            if (canalDos.isEmpty()) {
                String exceptionCause = "couldn't query any canal by canalIds:" + Arrays.toString(identities);
                logger.error("ERROR ## " + exceptionCause);
                throw new ManagerException(exceptionCause);
            }
        }
        canals = doToModel(canalDos);
    } catch (Exception e) {
        logger.error("ERROR ## query channels has an exception!");
        throw new ManagerException(e);
    }
    return canals;
}
Also used : CanalDO(com.alibaba.otter.manager.biz.config.canal.dal.dataobject.CanalDO) Canal(com.alibaba.otter.canal.instance.manager.model.Canal) ArrayList(java.util.ArrayList) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)

Example 2 with CanalDO

use of com.alibaba.otter.manager.biz.config.canal.dal.dataobject.CanalDO in project otter by alibaba.

the class CanalServiceImpl method modelToDo.

/**
 * 用于Model对象转化为DO对象
 *
 * @param canal
 * @return CanalDO
 */
private CanalDO modelToDo(Canal canal) {
    CanalDO canalDo = new CanalDO();
    try {
        canalDo.setId(canal.getId());
        canalDo.setName(canal.getName());
        canalDo.setStatus(canal.getStatus());
        canalDo.setDescription(canal.getDesc());
        canalDo.setParameters(canal.getCanalParameter());
        canalDo.setGmtCreate(canal.getGmtCreate());
        canalDo.setGmtModified(canal.getGmtModified());
    } catch (Exception e) {
        logger.error("ERROR ## change the canal Model to Do has an exception");
        throw new ManagerException(e);
    }
    return canalDo;
}
Also used : CanalDO(com.alibaba.otter.manager.biz.config.canal.dal.dataobject.CanalDO) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)

Example 3 with CanalDO

use of com.alibaba.otter.manager.biz.config.canal.dal.dataobject.CanalDO in project otter by alibaba.

the class CanalServiceImpl method modify.

/**
 * 修改
 */
public void modify(final Canal canal) {
    Assert.assertNotNull(canal);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        protected void doInTransactionWithoutResult(TransactionStatus status) {
            try {
                CanalDO canalDo = modelToDo(canal);
                if (canalDao.checkUnique(canalDo)) {
                    canalDao.update(canalDo);
                } else {
                    String exceptionCause = "exist the same repeat canal in the database.";
                    logger.warn("WARN ## " + exceptionCause);
                    throw new RepeatConfigureException(exceptionCause);
                }
            } catch (RepeatConfigureException rce) {
                throw rce;
            } catch (Exception e) {
                logger.error("ERROR ## modify canal(" + canal.getId() + ") has an exception!");
                throw new ManagerException(e);
            }
        }
    });
}
Also used : RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) CanalDO(com.alibaba.otter.manager.biz.config.canal.dal.dataobject.CanalDO) TransactionStatus(org.springframework.transaction.TransactionStatus) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)

Example 4 with CanalDO

use of com.alibaba.otter.manager.biz.config.canal.dal.dataobject.CanalDO in project otter by alibaba.

the class CanalServiceImpl method findByName.

public Canal findByName(String name) {
    Assert.assertNotNull(name);
    CanalDO canalDo = canalDao.findByName(name);
    if (canalDo == null) {
        String exceptionCause = "query name:" + name + " return null.";
        logger.error("ERROR ## " + exceptionCause);
        throw new ManagerException(exceptionCause);
    }
    return doToModel(canalDo);
}
Also used : CanalDO(com.alibaba.otter.manager.biz.config.canal.dal.dataobject.CanalDO) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException)

Example 5 with CanalDO

use of com.alibaba.otter.manager.biz.config.canal.dal.dataobject.CanalDO in project otter by alibaba.

the class CanalServiceImpl method create.

/**
 * 添加
 */
public void create(final Canal canal) {
    Assert.assertNotNull(canal);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        protected void doInTransactionWithoutResult(TransactionStatus status) {
            try {
                CanalDO canalDO = modelToDo(canal);
                canalDO.setId(0L);
                if (!canalDao.checkUnique(canalDO)) {
                    String exceptionCause = "exist the same repeat canal in the database.";
                    logger.warn("WARN ## " + exceptionCause);
                    throw new RepeatConfigureException(exceptionCause);
                }
                canalDao.insert(canalDO);
                canal.setId(canalDO.getId());
            } catch (RepeatConfigureException rce) {
                throw rce;
            } catch (Exception e) {
                logger.error("ERROR ## create canal has an exception!");
                throw new ManagerException(e);
            }
        }
    });
}
Also used : RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) CanalDO(com.alibaba.otter.manager.biz.config.canal.dal.dataobject.CanalDO) TransactionStatus(org.springframework.transaction.TransactionStatus) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)

Aggregations

ManagerException (com.alibaba.otter.manager.biz.common.exceptions.ManagerException)5 CanalDO (com.alibaba.otter.manager.biz.config.canal.dal.dataobject.CanalDO)5 RepeatConfigureException (com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)4 TransactionStatus (org.springframework.transaction.TransactionStatus)2 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)2 Canal (com.alibaba.otter.canal.instance.manager.model.Canal)1 ArrayList (java.util.ArrayList)1