Search in sources :

Example 26 with Channel

use of com.alibaba.otter.shared.common.model.config.channel.Channel in project otter by alibaba.

the class CheckDelayStat method execute.

public void execute(@Param("queueSize") String queueSize, @Param("delayTime") String delayTime, @Param("timeout") String timeout, Context context) throws WebxException {
    Map<Long, Long> queueSizeMap = parseAlert(queueSize);
    Map<Long, Long> delayTimeMap = parseAlert(delayTime);
    Map<Long, Long> timeoutMap = parseAlert(timeout);
    Boolean result = true;
    if ((queueSizeMap != null) && (false == queueSizeMap.isEmpty())) {
        Set<Long> key = queueSizeMap.keySet();
        for (Iterator it = key.iterator(); it.hasNext(); ) {
            Long pipelineId = (Long) it.next();
            Channel channel = channelService.findByPipelineId(pipelineId);
            // 判断channel状态,只有启动状态才进行判断超时时间
            if (!channel.getStatus().isStop()) {
                DelayStat delayStat = delayStatService.findRealtimeDelayStat(pipelineId);
                logger.info("delayStat.getDelayNumber() == " + delayStat.getDelayNumber());
                if (null != delayStat.getDelayNumber() && delayStat.getDelayNumber() >= queueSizeMap.get(pipelineId)) {
                    result = false;
                }
            }
        }
    }
    if ((delayTimeMap != null) && (false == delayTimeMap.isEmpty())) {
        Set<Long> key = delayTimeMap.keySet();
        for (Iterator it = key.iterator(); it.hasNext(); ) {
            Long pipelineId = (Long) it.next();
            Channel channel = channelService.findByPipelineId(pipelineId);
            // 判断channel状态,只有启动状态才进行判断超时时间
            if (!channel.getStatus().isStop()) {
                DelayStat delayStat = delayStatService.findRealtimeDelayStat(pipelineId);
                logger.info("delayStat.getDelayTime() == " + delayStat.getDelayTime());
                if (null != delayStat.getDelayTime() && delayStat.getDelayTime() >= delayTimeMap.get(pipelineId)) {
                    result = false;
                }
            }
        }
    }
    if ((timeoutMap != null) && (false == timeoutMap.isEmpty())) {
        Set<Long> key = timeoutMap.keySet();
        for (Iterator it = key.iterator(); it.hasNext(); ) {
            Long pipelineId = (Long) it.next();
            Channel channel = channelService.findByPipelineId(pipelineId);
            // 判断channel状态,只有启动状态才进行判断超时时间
            if (!channel.getStatus().isStop()) {
                ThroughputCondition condition = new ThroughputCondition();
                condition.setPipelineId(pipelineId);
                condition.setType(ThroughputType.ROW);
                ThroughputStat throughputStat = throughputStatService.findThroughputStatByPipelineId(condition);
                if (null != throughputStat.getGmtModified()) {
                    Date now = new Date();
                    long time = now.getTime() - throughputStat.getGmtModified().getTime();
                    logger.info("timeout == " + time + "(ms)");
                    // 单位为分钟
                    long timeout_min = MAX_TIMEOUT;
                    if (timeoutMap.containsKey(pipelineId)) {
                        timeout_min = timeoutMap.get(pipelineId);
                    }
                    if (time / (1000 * 60) > timeout_min) {
                        result = false;
                    }
                }
            }
        }
    }
    context.put("result", result);
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) Iterator(java.util.Iterator) ThroughputStat(com.alibaba.otter.shared.common.model.statistics.throughput.ThroughputStat) DelayStat(com.alibaba.otter.shared.common.model.statistics.delay.DelayStat) ThroughputCondition(com.alibaba.otter.manager.biz.statistics.throughput.param.ThroughputCondition) Date(java.util.Date)

Example 27 with Channel

use of com.alibaba.otter.shared.common.model.config.channel.Channel in project otter by alibaba.

the class NodeTaskServiceImpl method initNodeTask.

private void initNodeTask() {
    // 从manager下获取一下对应的任务列表
    Node node = configClientService.currentNode();
    FindTaskEvent event = new FindTaskEvent();
    event.setNid(node.getId());
    Object obj = nodeCommmunicationClient.callManager(event);
    if (obj != null) {
        List<Channel> channels = (List<Channel>) obj;
        for (Channel channel : channels) {
            // 排除已经分配过的task
            processNodeTask(channel);
        }
    }
}
Also used : Node(com.alibaba.otter.shared.common.model.config.node.Node) Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) ArrayList(java.util.ArrayList) List(java.util.List) FindTaskEvent(com.alibaba.otter.shared.communication.model.config.FindTaskEvent)

Example 28 with Channel

use of com.alibaba.otter.shared.common.model.config.channel.Channel in project otter by alibaba.

the class NodeTaskServiceTest method test_a_reload.

@Test
public void test_a_reload() throws Exception {
    Long channelId = 100L;
    Long pipelineId = 100L;
    Long oppositePipelineId = 101L;
    final Channel channel = new Channel();
    channel.setId(channelId);
    channel.setStatus(ChannelStatus.START);
    Pipeline pipeline1 = new Pipeline();
    pipeline1.setChannelId(channelId);
    pipeline1.setId(pipelineId);
    Pipeline pipeline2 = new Pipeline();
    pipeline2.setChannelId(channelId);
    pipeline2.setId(oppositePipelineId);
    channel.setPipelines(Arrays.asList(pipeline1, pipeline2));
    Node node1 = new Node();
    node1.setId(1L);
    Node node2 = new Node();
    node2.setId(2L);
    pipeline1.setSelectNodes(Arrays.asList(node1, node2));
    pipeline1.setExtractNodes(Arrays.asList(node1, node2));
    pipeline1.setLoadNodes(Arrays.asList(node1));
    pipeline2.setSelectNodes(Arrays.asList(node2));
    pipeline2.setExtractNodes(Arrays.asList(node2));
    pipeline2.setLoadNodes(Arrays.asList(node1, node2));
    Mockit.setUpMock(NodeCommmunicationClient.class, new Object() {

        @Mock
        public Object callManager(final Event event) {
            if (event instanceof FindNodeEvent) {
                Node node = new Node();
                Long nid = ((FindNodeEvent) event).getNid();
                node.setId(nid);
                return node;
            } else {
                return Arrays.asList(channel);
            }
        }
    });
    List<NodeTask> tasks = null;
    NodeTaskServiceImpl nodeTaskSerivce = (NodeTaskServiceImpl) spring.getBean("nodeTaskService");
    reflector.invoke(nodeTaskSerivce, "initNodeTask");
    tasks = reflector.invoke(nodeTaskSerivce, "mergeIncNodeTasks");
    want.number(tasks.size()).isEqualTo(2);
    reflector.invoke(nodeTaskSerivce, "initNodeTask");
    tasks = reflector.invoke(nodeTaskSerivce, "mergeIncNodeTasks");
    want.bool(tasks.size() == 0).is(true);
    channel.setStatus(ChannelStatus.STOP);
    reflector.invoke(nodeTaskSerivce, "initNodeTask");
    tasks = reflector.invoke(nodeTaskSerivce, "mergeIncNodeTasks");
    want.bool(tasks.size() == 2).is(true);
    tasks = nodeTaskSerivce.listAllNodeTasks();
    want.bool(tasks.size() == 2).is(true);
    // 清理内存
    TestUtils.setField(nodeTaskSerivce, "allTasks", Lists.newArrayList());
    TestUtils.setField(nodeTaskSerivce, "incTasks", Lists.newArrayList());
    // 删除某个pipeline的node
    channel.setStatus(ChannelStatus.START);
    reflector.invoke(nodeTaskSerivce, "initNodeTask");
    tasks = reflector.invoke(nodeTaskSerivce, "mergeIncNodeTasks");
    want.number(tasks.size()).isEqualTo(2);
    pipeline1.setSelectNodes(Arrays.asList(node2));
    pipeline1.setExtractNodes(Arrays.asList(node2));
    pipeline1.setLoadNodes(Arrays.asList(node2));
    channel.setStatus(ChannelStatus.START);
    reflector.invoke(nodeTaskSerivce, "initNodeTask");
    tasks = reflector.invoke(nodeTaskSerivce, "mergeIncNodeTasks");
    want.bool(tasks.size() == 1).is(true);
    // 清理内存
    TestUtils.setField(nodeTaskSerivce, "allTasks", Lists.newArrayList());
    TestUtils.setField(nodeTaskSerivce, "incTasks", Lists.newArrayList());
    channel.setStatus(ChannelStatus.START);
    reflector.invoke(nodeTaskSerivce, "initNodeTask");
    tasks = reflector.invoke(nodeTaskSerivce, "mergeIncNodeTasks");
    want.number(tasks.size()).isEqualTo(1);
    // 删除某个pipeline
    channel.setPipelines(Arrays.asList(pipeline1));
    reflector.invoke(nodeTaskSerivce, "initNodeTask");
    tasks = reflector.invoke(nodeTaskSerivce, "mergeIncNodeTasks");
    want.number(tasks.size()).isEqualTo(1);
}
Also used : FindNodeEvent(com.alibaba.otter.shared.communication.model.config.FindNodeEvent) NodeTaskServiceImpl(com.alibaba.otter.node.common.config.impl.NodeTaskServiceImpl) Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) Node(com.alibaba.otter.shared.common.model.config.node.Node) Event(com.alibaba.otter.shared.communication.core.model.Event) FindNodeEvent(com.alibaba.otter.shared.communication.model.config.FindNodeEvent) NotifyChannelEvent(com.alibaba.otter.shared.communication.model.config.NotifyChannelEvent) NodeTask(com.alibaba.otter.node.common.config.model.NodeTask) Mock(mockit.Mock) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline) Test(org.testng.annotations.Test) BaseOtterTest(com.alibaba.otter.node.common.BaseOtterTest)

Example 29 with Channel

use of com.alibaba.otter.shared.common.model.config.channel.Channel in project otter by alibaba.

the class NodeTaskServiceTest method test_b_channel.

@Test
public void test_b_channel() {
    Long channelId = 100L;
    Long pipelineId = 101L;
    // 先加一个pipeline的同步任务
    Long oppositePipelineId = 102L;
    final Channel channel = new Channel();
    channel.setId(channelId);
    channel.setStatus(ChannelStatus.START);
    Pipeline pipeline1 = new Pipeline();
    pipeline1.setChannelId(channelId);
    pipeline1.setId(pipelineId);
    Pipeline pipeline2 = new Pipeline();
    pipeline2.setChannelId(channelId);
    pipeline2.setId(oppositePipelineId);
    channel.setPipelines(Arrays.asList(pipeline1, pipeline2));
    Node node1 = new Node();
    node1.setId(1L);
    Node node2 = new Node();
    node2.setId(2L);
    pipeline1.setSelectNodes(Arrays.asList(node1, node2));
    pipeline1.setExtractNodes(Arrays.asList(node1, node2));
    pipeline1.setLoadNodes(Arrays.asList(node2));
    pipeline2.setSelectNodes(Arrays.asList(node1));
    pipeline2.setExtractNodes(Arrays.asList(node1));
    pipeline2.setLoadNodes(Arrays.asList(node1, node2));
    Mockit.setUpMock(NodeCommmunicationClient.class, new Object() {

        @Mock
        public Object callManager(final Event event) {
            if (event instanceof FindNodeEvent) {
                Node node = new Node();
                Long nid = ((FindNodeEvent) event).getNid();
                node.setId(nid);
                return node;
            } else {
                return Arrays.asList(channel);
            }
        }
    });
    // 初始化一下数据
    NodeTaskServiceImpl nodeTaskSerivce = (NodeTaskServiceImpl) spring.getBean("nodeTaskService");
    List<NodeTask> tasks = null;
    NotifyChannelEvent event = new NotifyChannelEvent();
    event.setChannel(channel);
    reflector.invoke(nodeTaskSerivce, "onNotifyChannel", event);
    tasks = reflector.invoke(nodeTaskSerivce, "mergeIncNodeTasks");
    want.bool(tasks.size() == 2).is(true);
    tasks = nodeTaskSerivce.listAllNodeTasks();
    want.bool(tasks.size() == 2).is(true);
}
Also used : FindNodeEvent(com.alibaba.otter.shared.communication.model.config.FindNodeEvent) NodeTaskServiceImpl(com.alibaba.otter.node.common.config.impl.NodeTaskServiceImpl) NotifyChannelEvent(com.alibaba.otter.shared.communication.model.config.NotifyChannelEvent) Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) Node(com.alibaba.otter.shared.common.model.config.node.Node) Event(com.alibaba.otter.shared.communication.core.model.Event) FindNodeEvent(com.alibaba.otter.shared.communication.model.config.FindNodeEvent) NotifyChannelEvent(com.alibaba.otter.shared.communication.model.config.NotifyChannelEvent) NodeTask(com.alibaba.otter.node.common.config.model.NodeTask) Mock(mockit.Mock) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline) Test(org.testng.annotations.Test) BaseOtterTest(com.alibaba.otter.node.common.BaseOtterTest)

Example 30 with Channel

use of com.alibaba.otter.shared.common.model.config.channel.Channel in project otter by alibaba.

the class PipelineAction method doDelete.

public void doDelete(@Param("pipelineId") Long pipelineId, @Param("channelId") Long channelId, Navigator nav) throws WebxException {
    Channel channel = channelService.findById(channelId);
    if (channel.getStatus().isStart()) {
        nav.redirectTo(WebConstant.ERROR_FORBIDDEN_Link);
        return;
    }
    // 如果pipeline节点下面存在dataMediaPair,则不允许删除
    if (dataMediaPairService.listByPipelineId(pipelineId).size() < 1) {
        pipelineService.remove(pipelineId);
    }
    nav.redirectToLocation("pipelineList.htm?channelId=" + channelId);
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel)

Aggregations

Channel (com.alibaba.otter.shared.common.model.config.channel.Channel)77 Pipeline (com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)38 Mock (mockit.Mock)16 ArrayList (java.util.ArrayList)13 ManagerException (com.alibaba.otter.manager.biz.common.exceptions.ManagerException)10 RepeatConfigureException (com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)10 ChannelArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.manage.ChannelArbitrateEvent)10 BeforeClass (org.testng.annotations.BeforeClass)10 PipelineArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.manage.PipelineArbitrateEvent)9 InvalidConfigureException (com.alibaba.otter.manager.biz.common.exceptions.InvalidConfigureException)8 NodeArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent)8 Node (com.alibaba.otter.shared.common.model.config.node.Node)7 Event (com.alibaba.otter.shared.communication.core.model.Event)7 Test (org.testng.annotations.Test)7 ChannelStatus (com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)6 DataMediaPair (com.alibaba.otter.shared.common.model.config.data.DataMediaPair)6 HashMap (java.util.HashMap)6 ChannelDO (com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO)5 SystemParameter (com.alibaba.otter.shared.common.model.config.parameter.SystemParameter)5 Identity (com.alibaba.otter.shared.etl.model.Identity)5