use of com.alibaba.otter.shared.common.model.config.channel.ChannelStatus 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.shared.common.model.config.channel.ChannelStatus 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.channel.ChannelStatus in project otter by alibaba.
the class AnalysisTopStat method execute.
public void execute(@Param("searchKey") String searchKey, @Param("topN") int topN, @Param("statTime") int minute, Context context) throws Exception {
if (topN <= 0) {
topN = 15;
}
if (minute <= 0) {
minute = 1;
}
List<TopDelayStat> tops = delayStatService.listTopDelayStat(searchKey, topN);
List<Long> pipelineIds = new ArrayList<Long>();
for (TopDelayStat top : tops) {
top.setStatTime(Long.valueOf(minute));
pipelineIds.add(top.getPipelineId());
}
Map<Long, ChannelStatus> channelStatuses = new HashMap<Long, ChannelStatus>(tops.size(), 1f);
Map<Long, MainStemEventData> mainstemStatuses = new HashMap<Long, MainStemEventData>(tops.size(), 1f);
if (pipelineIds.size() > 0) {
List<ThroughputStat> stats = throughputStatService.listRealtimeThroughputByPipelineIds(pipelineIds, minute);
for (ThroughputStat stat : stats) {
for (TopDelayStat top : tops) {
if (stat.getPipelineId().equals(top.getPipelineId())) {
DataStat s = new DataStat(stat.getNumber(), stat.getSize());
if (ThroughputType.FILE == stat.getType()) {
top.setFileStat(s);
} else if (ThroughputType.ROW == stat.getType()) {
top.setDbStat(s);
}
break;
}
}
}
for (TopDelayStat top : tops) {
if (!channelStatuses.containsKey(top.getChannelId())) {
channelStatuses.put(top.getChannelId(), arbitrateManageService.channelEvent().status(top.getChannelId()));
}
if (!mainstemStatuses.containsKey(top.getPipelineId())) {
mainstemStatuses.put(top.getPipelineId(), arbitrateViewService.mainstemData(top.getChannelId(), top.getPipelineId()));
}
}
}
context.put("tops", tops);
context.put("statTime", minute);
context.put("channelStatuses", channelStatuses);
context.put("mainstemStatuses", mainstemStatuses);
}
use of com.alibaba.otter.shared.common.model.config.channel.ChannelStatus in project otter by alibaba.
the class ChannelArbitrateEventTest method testStart.
@Test
public void testStart() {
// 初始化
channelEvent.init(channelId);
// 启动
channelEvent.start(channelId);
String path = StagePathUtils.getChannelByChannelId(channelId);
byte[] data = zookeeper.readData(path);
ChannelStatus status = JsonUtils.unmarshalFromByte(data, ChannelStatus.class);
want.bool(status == ChannelStatus.START).is(true);
channelEvent.destory(channelId);
}
use of com.alibaba.otter.shared.common.model.config.channel.ChannelStatus in project otter by alibaba.
the class ChannelArbitrateEventTest method testInit.
@Test
public void testInit() {
channelEvent.init(channelId);
String path = StagePathUtils.getChannelByChannelId(channelId);
byte[] data = zookeeper.readData(path);
ChannelStatus status = JsonUtils.unmarshalFromByte(data, ChannelStatus.class);
want.bool(status == ChannelStatus.STOP).is(true);
channelEvent.destory(channelId);
}
Aggregations