Search in sources :

Example 11 with ChannelStatus

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;
}
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) 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) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)

Example 12 with ChannelStatus

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;
}
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) 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) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)

Example 13 with ChannelStatus

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);
}
Also used : DataStat(com.alibaba.otter.manager.biz.statistics.delay.param.TopDelayStat.DataStat) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MainStemEventData(com.alibaba.otter.shared.arbitrate.model.MainStemEventData) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus) TopDelayStat(com.alibaba.otter.manager.biz.statistics.delay.param.TopDelayStat) ThroughputStat(com.alibaba.otter.shared.common.model.statistics.throughput.ThroughputStat)

Example 14 with ChannelStatus

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);
}
Also used : ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus) Test(org.testng.annotations.Test) BaseEventTest(com.alibaba.otter.shared.arbitrate.BaseEventTest)

Example 15 with ChannelStatus

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);
}
Also used : ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus) Test(org.testng.annotations.Test) BaseEventTest(com.alibaba.otter.shared.arbitrate.BaseEventTest)

Aggregations

ChannelStatus (com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)30 PermitMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor)13 ArbitrateException (com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)8 ArrayList (java.util.ArrayList)8 EtlEventData (com.alibaba.otter.shared.arbitrate.model.EtlEventData)7 Pipeline (com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)7 Channel (com.alibaba.otter.shared.common.model.config.channel.Channel)6 Date (java.util.Date)5 ZkException (org.I0Itec.zkclient.exception.ZkException)5 ZkNoNodeException (org.I0Itec.zkclient.exception.ZkNoNodeException)5 InvalidConfigureException (com.alibaba.otter.manager.biz.common.exceptions.InvalidConfigureException)4 ManagerException (com.alibaba.otter.manager.biz.common.exceptions.ManagerException)4 RepeatConfigureException (com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)4 BaseEventTest (com.alibaba.otter.shared.arbitrate.BaseEventTest)4 MainStemEventData (com.alibaba.otter.shared.arbitrate.model.MainStemEventData)4 Node (com.alibaba.otter.shared.common.model.config.node.Node)4 Test (org.testng.annotations.Test)4 ChannelDO (com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO)3 HashMap (java.util.HashMap)3 SystemParameter (com.alibaba.otter.shared.common.model.config.parameter.SystemParameter)2