Search in sources :

Example 6 with ChannelDO

use of com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO in project otter by alibaba.

the class ChannelServiceImpl method listOnlyChannels.

public List<Channel> listOnlyChannels(Long... identities) {
    List<Channel> channels = new ArrayList<Channel>();
    try {
        List<ChannelDO> channelDos = null;
        if (identities.length < 1) {
            channelDos = channelDao.listAll();
            if (channelDos.isEmpty()) {
                logger.debug("DEBUG ## couldn't query any channel, maybe hasn't create any channel.");
                return channels;
            }
        } else {
            channelDos = channelDao.listByMultiId(identities);
            if (channelDos.isEmpty()) {
                String exceptionCause = "couldn't query any channel by channelIds:" + Arrays.toString(identities);
                logger.error("ERROR ## " + exceptionCause);
                throw new ManagerException(exceptionCause);
            }
        }
        channels = doToModelOnlyChannels(channelDos);
    } catch (Exception e) {
        logger.error("ERROR ## query channels has an exception!");
        throw new ManagerException(e);
    }
    return channels;
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) ArrayList(java.util.ArrayList) ChannelDO(com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) InvalidConfigureException(com.alibaba.otter.manager.biz.common.exceptions.InvalidConfigureException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException)

Example 7 with ChannelDO

use of com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO in project otter by alibaba.

the class ChannelServiceImpl method doToModelWithColumn.

private List<Channel> doToModelWithColumn(List<ChannelDO> channelDos) {
    List<Channel> channels = new ArrayList<Channel>();
    try {
        // 1.将ChannelID单独拿出来
        List<Long> channelIds = new ArrayList<Long>();
        for (ChannelDO channelDo : channelDos) {
            channelIds.add(channelDo.getId());
        }
        Long[] idArray = new Long[channelIds.size()];
        // 拿到所有的Pipeline进行ChannelID过滤,避免重复查询。
        List<Pipeline> pipelines = pipelineService.listByChannelIdsWithoutColumn(channelIds.toArray(idArray));
        SystemParameter systemParameter = systemParameterService.find();
        for (ChannelDO channelDo : channelDos) {
            Channel channel = new Channel();
            channel.setId(channelDo.getId());
            channel.setName(channelDo.getName());
            channel.setDescription(channelDo.getDescription());
            ChannelStatus channelStatus = arbitrateManageService.channelEvent().status(channelDo.getId());
            channel.setStatus(null == channelStatus ? ChannelStatus.STOP : channelStatus);
            channel.setParameters(channelDo.getParameters());
            channel.setGmtCreate(channelDo.getGmtCreate());
            channel.setGmtModified(channelDo.getGmtModified());
            // 遍历,将该Channel节点下的Pipeline提取出来。
            List<Pipeline> subPipelines = new ArrayList<Pipeline>();
            for (Pipeline pipeline : pipelines) {
                if (pipeline.getChannelId().equals(channelDo.getId())) {
                    // 合并PipelineParameter和ChannelParameter
                    PipelineParameter parameter = new PipelineParameter();
                    parameter.merge(systemParameter);
                    parameter.merge(channel.getParameters());
                    // 最后复制pipelineId参数
                    parameter.merge(pipeline.getParameters());
                    pipeline.setParameters(parameter);
                    subPipelines.add(pipeline);
                }
            }
            channel.setPipelines(subPipelines);
            channels.add(channel);
        }
    } catch (Exception e) {
        logger.error("ERROR ## change the channels DO to Model has an exception");
        throw new ManagerException(e);
    }
    return channels;
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) ArrayList(java.util.ArrayList) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus) InvalidConfigureException(com.alibaba.otter.manager.biz.common.exceptions.InvalidConfigureException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline) SystemParameter(com.alibaba.otter.shared.common.model.config.parameter.SystemParameter) ChannelDO(com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO) PipelineParameter(com.alibaba.otter.shared.common.model.config.pipeline.PipelineParameter) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException)

Example 8 with ChannelDO

use of com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO in project otter by alibaba.

the class ChannelServiceImpl method listAllChannelId.

public List<Long> listAllChannelId() {
    List<ChannelDO> channelDos = channelDao.listChannelPks();
    List<Long> channelPks = new ArrayList<Long>();
    if (channelDos.isEmpty()) {
        logger.debug("DEBUG ## couldn't query any channel");
    }
    for (ChannelDO channelDo : channelDos) {
        channelPks.add(channelDo.getId());
    }
    return channelPks;
}
Also used : ArrayList(java.util.ArrayList) ChannelDO(com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO)

Example 9 with ChannelDO

use of com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO in project otter by alibaba.

the class ChannelServiceImpl method modify.

/**
     * 修改Channel
     */
public void modify(Channel channel) {
    Assert.assertNotNull(channel);
    try {
        ChannelDO channelDo = modelToDo(channel);
        if (channelDao.checkUnique(channelDo)) {
            channelDao.update(channelDo);
        } else {
            String exceptionCause = "exist the same name channel in the database.";
            logger.warn("WARN ## " + exceptionCause);
            throw new RepeatConfigureException(exceptionCause);
        }
    } catch (RepeatConfigureException rce) {
        throw rce;
    } catch (Exception e) {
        logger.error("ERROR ## modify channel has an exception ", e);
        throw new ManagerException(e);
    }
}
Also used : RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) ChannelDO(com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) InvalidConfigureException(com.alibaba.otter.manager.biz.common.exceptions.InvalidConfigureException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException)

Aggregations

ChannelDO (com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO)9 InvalidConfigureException (com.alibaba.otter.manager.biz.common.exceptions.InvalidConfigureException)8 ManagerException (com.alibaba.otter.manager.biz.common.exceptions.ManagerException)8 RepeatConfigureException (com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)8 ArrayList (java.util.ArrayList)6 Channel (com.alibaba.otter.shared.common.model.config.channel.Channel)5 ChannelStatus (com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)3 Pipeline (com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)3 SystemParameter (com.alibaba.otter.shared.common.model.config.parameter.SystemParameter)2 PipelineParameter (com.alibaba.otter.shared.common.model.config.pipeline.PipelineParameter)2 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1