use of com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO in project otter by alibaba.
the class ChannelServiceImpl method modelToDo.
/*----------------------DO <-> MODEL 组装方法--------------------------*/
/**
* <pre>
* 用于Model对象转化为DO对象
* 优化:
* 无SQL交互,只是简单进行字段组装,暂时无须优化
* </pre>
*
* @param channel
* @return ChannelDO
*/
private ChannelDO modelToDo(Channel channel) {
ChannelDO channelDO = new ChannelDO();
try {
channelDO.setId(channel.getId());
channelDO.setName(channel.getName());
channelDO.setDescription(channel.getDescription());
channelDO.setStatus(channel.getStatus());
channelDO.setParameters(channel.getParameters());
channelDO.setGmtCreate(channel.getGmtCreate());
channelDO.setGmtModified(channel.getGmtModified());
} catch (Exception e) {
logger.error("ERROR ## change the channel Model to Do has an exception");
throw new ManagerException(e);
}
return channelDO;
}
use of com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO in project otter by alibaba.
the class ChannelServiceImpl method doToModel.
/**
* <pre>
* 用于DO对象数组转化为Model对象数组
* 现阶段优化:
* 需要五次SQL交互:pipeline\node\dataMediaPair\dataMedia\dataMediaSource(五个层面)
* 目前优化方案为单层只执行一次SQL,避免重复循环造成IO及数据库查询开销
* 长期优化:
* 对SQL进行改造,尽量减小SQL调用次数
* </pre>
*
* @param channelDO
* @return Channel
*/
private List<Channel> doToModel(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.listByChannelIds(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;
}
use of com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO in project otter by alibaba.
the class ChannelServiceImpl method doToModelOnlyChannels.
private List<Channel> doToModelOnlyChannels(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());
}
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>();
channel.setPipelines(subPipelines);
channels.add(channel);
}
} catch (Exception e) {
logger.error("ERROR ## change the channels doToModelOnlyChannels has an exception");
throw new ManagerException(e);
}
return channels;
}
use of com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO in project otter by alibaba.
the class ChannelServiceImpl method create.
/**
* 添加Channel
*/
public void create(final Channel channel) {
Assert.assertNotNull(channel);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
ChannelDO channelDo = modelToDo(channel);
channelDo.setId(0L);
if (!channelDao.checkUnique(channelDo)) {
String exceptionCause = "exist the same name channel in the database.";
logger.warn("WARN ## " + exceptionCause);
throw new RepeatConfigureException(exceptionCause);
}
channelDao.insert(channelDo);
arbitrateManageService.channelEvent().init(channelDo.getId());
} catch (RepeatConfigureException rce) {
throw rce;
} catch (Exception e) {
logger.error("ERROR ## create channel has an exception ", e);
throw new ManagerException(e);
}
}
});
}
use of com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO in project otter by alibaba.
the class ChannelServiceImpl method listByIds.
/*--------------------优化内容:listAll、listByIds、findById合并-------------------------------*/
public List<Channel> listByIds(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 = doToModel(channelDos);
} catch (Exception e) {
logger.error("ERROR ## query channels has an exception!");
throw new ManagerException(e);
}
return channels;
}
Aggregations