Search in sources :

Example 1 with NodeTask

use of com.alibaba.otter.node.common.config.model.NodeTask in project otter by alibaba.

the class NodeTaskServiceImpl method printNodeTasks.

private String printNodeTasks(List<NodeTask> tasks) {
    StringBuilder builder = new StringBuilder();
    for (NodeTask task : tasks) {
        builder.append("\n=========================");
        builder.append("pipeline:" + task.getPipeline().getId()).append("\n");
        builder.append("\t").append(task.getStage()).append("\n");
        builder.append("\t").append(task.getEvent()).append("\n");
        builder.append("\t").append("shutdown:").append(task.isShutdown()).append("\n");
    }
    return builder.toString();
}
Also used : NodeTask(com.alibaba.otter.node.common.config.model.NodeTask)

Example 2 with NodeTask

use of com.alibaba.otter.node.common.config.model.NodeTask in project otter by alibaba.

the class NodeTaskServiceImpl method retain.

// 将target的目标除去source中的信息
private NodeTask retain(NodeTask targetTask, NodeTask sourceTask) {
    List<StageType> stages = targetTask.getStage();
    List<TaskEvent> events = targetTask.getEvent();
    List<StageType> mergeStates = new ArrayList<StageType>();
    List<TaskEvent> mergeEvents = new ArrayList<TaskEvent>();
    // 合并两者的交集的数据
    for (int i = 0; i < stages.size(); i++) {
        StageType stage = stages.get(i);
        TaskEvent event = events.get(i);
        // 找到source节点对应的TaskEvent
        TaskEvent sourceEvent = getMatchStage(sourceTask, stage);
        if (sourceEvent != null && sourceEvent != event) {
            // 存在相同的stage节点,判断event是否相同,不同则则添加
            mergeStates.add(stage);
            mergeEvents.add(event);
        }
    }
    // 添加targtTask中特有的stage/event
    for (int i = 0; i < stages.size(); i++) {
        StageType stage = stages.get(i);
        TaskEvent event = events.get(i);
        if (getMatchStage(sourceTask, stage) == null) {
            mergeStates.add(stage);
            mergeEvents.add(event);
        }
    }
    if (mergeStates.size() > 0) {
        NodeTask result = new NodeTask();
        result.setPipeline(targetTask.getPipeline());
        result.setEvent(mergeEvents);
        result.setStage(mergeStates);
        result.setShutdown(targetTask.isShutdown());
        return result;
    } else {
        return null;
    }
}
Also used : StageType(com.alibaba.otter.shared.common.model.config.enums.StageType) TaskEvent(com.alibaba.otter.node.common.config.model.NodeTask.TaskEvent) FindTaskEvent(com.alibaba.otter.shared.communication.model.config.FindTaskEvent) ArrayList(java.util.ArrayList) NodeTask(com.alibaba.otter.node.common.config.model.NodeTask)

Example 3 with NodeTask

use of com.alibaba.otter.node.common.config.model.NodeTask in project otter by alibaba.

the class NodeTaskServiceImpl method notifyListener.

private synchronized boolean notifyListener() {
    boolean result = true;
    List<NodeTask> incNodeTask = new ArrayList<NodeTask>(incTasks);
    if (CollectionUtils.isEmpty(listeners) == false) {
        for (NodeTaskListener listener : listeners) {
            result &= listener.process(incNodeTask);
        }
        if (result) {
            mergeIncNodeTasks();
        } else {
            // 清除本次的增量数据
            incTasks.clear();
            if (logger.isInfoEnabled()) {
                logger.info("##notify listener error {}", printNodeTasks(incNodeTask));
            }
        }
    }
    return result;
}
Also used : NodeTaskListener(com.alibaba.otter.node.common.config.NodeTaskListener) ArrayList(java.util.ArrayList) NodeTask(com.alibaba.otter.node.common.config.model.NodeTask)

Example 4 with NodeTask

use of com.alibaba.otter.node.common.config.model.NodeTask 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 5 with NodeTask

use of com.alibaba.otter.node.common.config.model.NodeTask 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)

Aggregations

NodeTask (com.alibaba.otter.node.common.config.model.NodeTask)7 StageType (com.alibaba.otter.shared.common.model.config.enums.StageType)3 Node (com.alibaba.otter.shared.common.model.config.node.Node)3 Pipeline (com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)3 ArrayList (java.util.ArrayList)3 BaseOtterTest (com.alibaba.otter.node.common.BaseOtterTest)2 NodeTaskServiceImpl (com.alibaba.otter.node.common.config.impl.NodeTaskServiceImpl)2 TaskEvent (com.alibaba.otter.node.common.config.model.NodeTask.TaskEvent)2 Channel (com.alibaba.otter.shared.common.model.config.channel.Channel)2 Event (com.alibaba.otter.shared.communication.core.model.Event)2 FindNodeEvent (com.alibaba.otter.shared.communication.model.config.FindNodeEvent)2 FindTaskEvent (com.alibaba.otter.shared.communication.model.config.FindTaskEvent)2 NotifyChannelEvent (com.alibaba.otter.shared.communication.model.config.NotifyChannelEvent)2 Mock (mockit.Mock)2 Test (org.testng.annotations.Test)2 NodeTaskListener (com.alibaba.otter.node.common.config.NodeTaskListener)1 GlobalTask (com.alibaba.otter.node.etl.common.task.GlobalTask)1