use of com.alibaba.otter.shared.common.model.config.pipeline.Pipeline in project otter by alibaba.
the class ChannelServiceImpl method listByNodeId.
/**
* 根据NodeId和Channel状态找到对应的Channel列表。
*/
public List<Channel> listByNodeId(Long nodeId, ChannelStatus... statuses) {
List<Channel> channels = new ArrayList<Channel>();
List<Channel> results = new ArrayList<Channel>();
try {
List<Pipeline> pipelines = pipelineService.listByNodeId(nodeId);
List<Long> pipelineIds = new ArrayList<Long>();
for (Pipeline pipeline : pipelines) {
pipelineIds.add(pipeline.getId());
}
if (pipelineIds.isEmpty()) {
// 没有关联任务直接返回
return channels;
}
// 反查对应的channel
channels = listByPipelineIds(pipelineIds.toArray(new Long[pipelineIds.size()]));
if (null == statuses || statuses.length == 0) {
return channels;
}
for (Channel channel : channels) {
for (ChannelStatus status : statuses) {
if (channel.getStatus().equals(status)) {
results.add(channel);
}
}
}
} catch (Exception e) {
logger.error("ERROR ## list query channel by nodeId:" + nodeId + " has an exception!");
throw new ManagerException(e);
}
return results;
}
use of com.alibaba.otter.shared.common.model.config.pipeline.Pipeline 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 Channel doToModel(ChannelDO channelDo) {
Channel channel = new Channel();
try {
channel.setId(channelDo.getId());
channel.setName(channelDo.getName());
channel.setDescription(channelDo.getDescription());
channel.setStatus(arbitrateManageService.channelEvent().status(channelDo.getId()));
channel.setParameters(channelDo.getParameters());
channel.setGmtCreate(channelDo.getGmtCreate());
channel.setGmtModified(channelDo.getGmtModified());
List<Pipeline> pipelines = pipelineService.listByChannelIds(channelDo.getId());
// 合并PipelineParameter和ChannelParameter
SystemParameter systemParameter = systemParameterService.find();
for (Pipeline pipeline : pipelines) {
PipelineParameter parameter = new PipelineParameter();
parameter.merge(systemParameter);
parameter.merge(channel.getParameters());
// 最后复制pipelineId参数
parameter.merge(pipeline.getParameters());
pipeline.setParameters(parameter);
// pipeline.getParameters().merge(channel.getParameters());
}
channel.setPipelines(pipelines);
} catch (Exception e) {
logger.error("ERROR ## change the channel DO to Model has an exception");
throw new ManagerException(e);
}
return channel;
}
use of com.alibaba.otter.shared.common.model.config.pipeline.Pipeline in project otter by alibaba.
the class ChannelServiceImpl method findByPipelineId.
/*--------------------外部关联查询Channel-----------------------*/
/**
* <pre>
* 根据PipelineID找到对应的Channel
* 优化设想:
* 应该通过变长参数达到后期扩展的方便性
* </pre>
*/
public Channel findByPipelineId(Long pipelineId) {
Pipeline pipeline = pipelineService.findById(pipelineId);
Channel channel = findById(pipeline.getChannelId());
return channel;
}
use of com.alibaba.otter.shared.common.model.config.pipeline.Pipeline in project otter by alibaba.
the class CanalInfo method execute.
public void execute(@Param("canalId") Long canalId, Context context) throws Exception {
Canal canal = canalService.findById(canalId);
AutoKeeperCluster zkCluster = autoKeeperClusterService.findAutoKeeperClusterById(canal.getCanalParameter().getZkClusterId());
List<Pipeline> pipelines = pipelineService.listByDestinationWithoutOther(canal.getName());
List<Long> channelIds = new ArrayList<Long>();
for (Pipeline pipeline : pipelines) {
channelIds.add(pipeline.getChannelId());
}
List<Channel> channels = channelService.listOnlyChannels(channelIds.toArray(new Long[channelIds.size()]));
Map<Long, Channel> channelMap = new HashMap<Long, Channel>();
for (Channel channel : channels) {
channelMap.put(channel.getId(), channel);
}
context.put("canal", canal);
context.put("pipelines", pipelines);
context.put("channelMap", channelMap);
context.put("zkCluster", zkCluster);
}
use of com.alibaba.otter.shared.common.model.config.pipeline.Pipeline in project otter by alibaba.
the class CanalList method execute.
public void execute(@Param("pageIndex") int pageIndex, @Param("searchKey") String searchKey, Context context) throws Exception {
@SuppressWarnings("unchecked") Map<String, Object> condition = new HashMap<String, Object>();
if ("请输入关键字(目前支持Node的ID、名字搜索)".equals(searchKey)) {
searchKey = "";
}
condition.put("searchKey", searchKey);
int count = canalService.getCount(condition);
Paginator paginator = new Paginator();
paginator.setItems(count);
paginator.setPage(pageIndex);
condition.put("offset", paginator.getOffset());
condition.put("length", paginator.getLength());
List<Canal> canals = canalService.listByCondition(condition);
List<SeniorCanal> seniorCanals = new ArrayList<SeniorCanal>();
for (Canal canal : canals) {
SeniorCanal seniorCanal = new SeniorCanal();
seniorCanal.setId(canal.getId());
seniorCanal.setName(canal.getName());
seniorCanal.setStatus(canal.getStatus());
seniorCanal.setDesc(canal.getDesc());
seniorCanal.setCanalParameter(canal.getCanalParameter());
seniorCanal.setGmtCreate(canal.getGmtCreate());
seniorCanal.setGmtModified(canal.getGmtModified());
List<Pipeline> pipelines = pipelineService.listByDestinationWithoutOther(canal.getName());
seniorCanal.setPipelines(pipelines);
seniorCanal.setUsed(!pipelines.isEmpty());
seniorCanals.add(seniorCanal);
}
context.put("seniorCanals", seniorCanals);
context.put("paginator", paginator);
context.put("searchKey", searchKey);
}
Aggregations