Search in sources :

Example 1 with NodeArbitrateEvent

use of com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent in project otter by alibaba.

the class NodeSerivceTest method testListAllNodes.

@Test
public void testListAllNodes() {
    new NonStrictExpectations() {

        {
            nodeDao.listAll();
            List<NodeDO> nodeDos = new ArrayList<NodeDO>();
            for (int i = 0; i < 10; i++) {
                NodeDO nodeDo = new NodeDO();
                nodeDo.setId(Long.valueOf(1));
                nodeDo.setIp("127.0.0.1");
                nodeDos.add(nodeDo);
            }
            returns(nodeDos);
            arbitrateManageService.nodeEvent();
            returns(new NodeArbitrateEvent() {

                @Override
                public List<Long> liveNodes() {
                    return Arrays.asList(1L);
                }
            });
        }
    };
    want.number(nodeService.listAll().size()).isEqualTo(10);
    want.string(nodeService.listAll().get(0).getIp()).isEqualTo("127.0.0.1");
}
Also used : ArrayList(java.util.ArrayList) NodeDO(com.alibaba.otter.manager.biz.config.node.dal.dataobject.NodeDO) ArrayList(java.util.ArrayList) List(java.util.List) NodeArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent) Test(org.testng.annotations.Test) BaseOtterTest(com.alibaba.otter.manager.biz.BaseOtterTest)

Example 2 with NodeArbitrateEvent

use of com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent in project otter by alibaba.

the class ArbitrateAllTest method setUp.

@BeforeMethod
public void setUp() {
    // mock 配置信息数据
    Mockit.setUpMock(ArbitrateConfigUtils.class, new Object() {

        @Mock
        public Channel getChannelByChannelId(Long channelId) {
            Channel channel = new Channel();
            channel.setId(channelId);
            Pipeline pipeline = new Pipeline();
            pipeline.setId(pipelineId);
            pipeline.setSelectNodes(Arrays.asList(local));
            pipeline.setExtractNodes(Arrays.asList(local));
            pipeline.setLoadNodes(Arrays.asList(local));
            pipeline.getParameters().setArbitrateMode(arbitrateMode);
            channel.setPipelines(Arrays.asList(pipeline));
            return channel;
        }

        @Mock
        public Pipeline getPipeline(Long pipelineId) {
            Pipeline pipeline = new Pipeline();
            pipeline.setId(pipelineId);
            pipeline.setSelectNodes(Arrays.asList(local));
            pipeline.setExtractNodes(Arrays.asList(local));
            pipeline.setLoadNodes(Arrays.asList(local));
            pipeline.getParameters().setArbitrateMode(arbitrateMode);
            return pipeline;
        }

        @Mock
        public Long getCurrentNid() {
            return nid;
        }

        @Mock
        public int getParallelism(Long pipelineId) {
            // 并行度
            return 3;
        }

        @Mock
        public Pipeline getOppositePipeline(Long pipelineId) {
            return null;
        }

        @Mock
        public Channel getChannel(Long pipelineId) {
            Channel channel = new Channel();
            channel.setId(channelId);
            Pipeline pipeline = new Pipeline();
            pipeline.setId(pipelineId);
            pipeline.getParameters().setArbitrateMode(arbitrateMode);
            channel.setPipelines(Arrays.asList(pipeline));
            return channel;
        }
    });
    Mockit.setUpMock(ArbitrateCommmunicationClient.class, new Object() {

        @Mock
        public Object callManager(final Event event) {
            // do nothing
            return null;
        }
    });
    zookeeper = getZookeeper();
    local.setId(nid);
    nodeEvent = new NodeArbitrateEvent();
    channelEvent = new ChannelArbitrateEvent();
    pipelineEvent = new PipelineArbitrateEvent();
    // 创建node节点
    nodeEvent.init(local.getId());
    // 创建pipeline节点
    channelEvent.init(channelId);
    pipelineEvent.init(channelId, pipelineId);
    arbitrateEventService = (ArbitrateEventService) getBeanFactory().getBean("arbitrateEventService");
    mainStem = new MainStemServiceDemo();
    autowire(mainStem);
    select = new SelectServiceDemo();
    autowire(select);
    extract = new ExtractServiceDemo();
    autowire(extract);
    transform = new TransformServiceDemo();
    autowire(transform);
    load = new LoadServiceDemo();
    autowire(load);
    view = new ProcessViewDemo();
    autowire(view);
    termin = new TerminProcessDemo();
    autowire(termin);
}
Also used : TransformServiceDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.TransformServiceDemo) Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) Mock(mockit.Mock) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline) SelectServiceDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.SelectServiceDemo) ExtractServiceDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.ExtractServiceDemo) TerminProcessDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.TerminProcessDemo) ChannelArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.ChannelArbitrateEvent) Event(com.alibaba.otter.shared.communication.core.model.Event) PipelineArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.PipelineArbitrateEvent) NodeArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent) ChannelArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.ChannelArbitrateEvent) LoadServiceDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.LoadServiceDemo) PipelineArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.PipelineArbitrateEvent) MainStemServiceDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.MainStemServiceDemo) NodeArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent) ProcessViewDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.ProcessViewDemo) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with NodeArbitrateEvent

use of com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent in project otter by alibaba.

the class BaseStageTest method init.

@BeforeClass
public void init() {
    // 初始化节点
    // mock 配置信息数据
    local.setStatus(NodeStatus.START);
    Mockit.setUpMock(ArbitrateConfigUtils.class, new Object() {

        @Mock
        public Channel getChannelByChannelId(Long channelId) {
            Channel channel = new Channel();
            channel.setId(channelId);
            Pipeline pipeline = new Pipeline();
            pipeline.setId(pipelineId);
            pipeline.setSelectNodes(Arrays.asList(local));
            pipeline.setExtractNodes(Arrays.asList(local));
            pipeline.setLoadNodes(Arrays.asList(local));
            channel.setPipelines(Arrays.asList(pipeline));
            return channel;
        }

        @Mock
        public Channel getChannel(Long pipelineId) {
            Channel channel = new Channel();
            channel.setId(channelId);
            Pipeline pipeline = new Pipeline();
            pipeline.setId(pipelineId);
            pipeline.setSelectNodes(Arrays.asList(local));
            pipeline.setExtractNodes(Arrays.asList(local));
            pipeline.setLoadNodes(Arrays.asList(local));
            channel.setPipelines(Arrays.asList(pipeline));
            return channel;
        }

        @Mock
        public Pipeline getPipeline(Long pipelineId) {
            Pipeline pipeline = new Pipeline();
            pipeline.setSelectNodes(Arrays.asList(local));
            pipeline.setExtractNodes(Arrays.asList(local));
            pipeline.setLoadNodes(Arrays.asList(local));
            return pipeline;
        }

        @Mock
        public Pipeline getOppositePipeline(Long pipelineId) {
            // 没有反向同步
            return null;
        }

        @Mock
        public Long getCurrentNid() {
            return nid;
        }

        @Mock
        public int getParallelism(Long pipelineId) {
            // 并行度
            return 3;
        }
    });
    Mockit.setUpMock(ArbitrateCommmunicationClient.class, new Object() {

        @Mock
        public Object callManager(final Event event) {
            // do nothing
            return null;
        }

        @Mock
        public void callManager(final Event event, final Callback callback) {
        // do nothing
        }
    });
    zookeeper = getZookeeper();
    local.setId(nid);
    nodeEvent = new NodeArbitrateEvent();
    channelEvent = new ChannelArbitrateEvent();
    pipelineEvent = new PipelineArbitrateEvent();
    pipelinePath = StagePathUtils.getPipeline(channelId, pipelineId);
    processPath = StagePathUtils.getProcessRoot(channelId, pipelineId);
    channelEvent.init(channelId);
    pipelineEvent.init(channelId, pipelineId);
    channelEvent.start(channelId);
    String path = pipelinePath + "/" + ArbitrateConstants.NODE_MAINSTEM;
    MainStemEventData eventData = new MainStemEventData();
    eventData.setStatus(MainStemEventData.Status.OVERTAKE);
    eventData.setNid(nid);
    // 初始化的数据对象
    byte[] bytes = JsonUtils.marshalToByte(eventData);
    zookeeper.create(path, bytes, CreateMode.EPHEMERAL);
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) MainStemEventData(com.alibaba.otter.shared.arbitrate.model.MainStemEventData) Mock(mockit.Mock) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline) Callback(com.alibaba.otter.shared.communication.core.model.Callback) ChannelArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.ChannelArbitrateEvent) Event(com.alibaba.otter.shared.communication.core.model.Event) PipelineArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.PipelineArbitrateEvent) NodeArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent) ChannelArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.ChannelArbitrateEvent) PipelineArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.PipelineArbitrateEvent) NodeArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with NodeArbitrateEvent

use of com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent in project otter by alibaba.

the class ArbitrateForwardIntegration method setUp.

@BeforeMethod
public void setUp() {
    // mock 配置信息数据
    Mockit.setUpMock(ArbitrateConfigUtils.class, new Object() {

        @Mock
        public Channel getChannelByChannelId(Long channelId) {
            Channel channel = new Channel();
            channel.setId(channelId);
            Pipeline pipeline = new Pipeline();
            pipeline.setId(pipelineId);
            pipeline.setSelectNodes(Arrays.asList(one));
            pipeline.setExtractNodes(Arrays.asList(one));
            pipeline.setLoadNodes(Arrays.asList(two));
            channel.setPipelines(Arrays.asList(pipeline));
            return channel;
        }

        @Mock
        public Pipeline getPipeline(Long pipelineId) {
            Pipeline pipeline = new Pipeline();
            pipeline.setId(pipelineId);
            pipeline.setSelectNodes(Arrays.asList(one));
            pipeline.setExtractNodes(Arrays.asList(one));
            pipeline.setLoadNodes(Arrays.asList(two));
            return pipeline;
        }

        @Mock
        public Long getCurrentNid() {
            return oneNid;
        }

        @Mock
        public int getParallelism(Long pipelineId) {
            // 并行度
            return 3;
        }

        @Mock
        public Pipeline getOppositePipeline(Long pipelineId) {
            Pipeline pipeline = new Pipeline();
            pipeline.setId(oppositePipelineId);
            pipeline.setSelectNodes(Arrays.asList(two));
            pipeline.setExtractNodes(Arrays.asList(two));
            pipeline.setLoadNodes(Arrays.asList(one));
            return pipeline;
        }

        @Mock
        public Channel getChannel(Long pipelineId) {
            Channel channel = new Channel();
            channel.setId(channelId);
            Pipeline pipeline = new Pipeline();
            pipeline.setId(pipelineId);
            Pipeline oppositePipeline = new Pipeline();
            oppositePipeline.setId(oppositePipelineId);
            channel.setPipelines(Arrays.asList(pipeline, oppositePipeline));
            return channel;
        }
    });
    Mockit.setUpMock(ArbitrateCommmunicationClient.class, new Object() {

        @Mock
        public Object callManager(final Event event) {
            // do nothing
            return null;
        }
    });
    zookeeper = getZookeeper();
    one.setId(oneNid);
    two.setId(twoNid);
    nodeEvent = new NodeArbitrateEvent();
    // 创建channel
    channelEvent = new ChannelArbitrateEvent();
    pipelineEvent = new PipelineArbitrateEvent();
    // 创建node节点
    nodeEvent.init(oneNid);
    // 创建pipeline节点
    try {
        channelEvent.init(channelId);
    } catch (Exception e) {
    // ignore
    }
    try {
        pipelineEvent.init(channelId, pipelineId);
    } catch (Exception e) {
    // ignore
    }
    arbitrateEventService = (ArbitrateEventService) getBeanFactory().getBean("arbitrateEventService");
    mainStem = new MainStemServiceDemo();
    autowire(mainStem);
    select = new SelectServiceDemo();
    autowire(select);
    extract = new ExtractServiceDemo();
    autowire(extract);
    transform = new TransformServiceDemo();
    autowire(transform);
    load = new LoadServiceDemo();
    autowire(load);
    view = new ProcessViewDemo();
    autowire(view);
    termin = new TerminProcessDemo();
    autowire(termin);
}
Also used : TransformServiceDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.TransformServiceDemo) Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) Mock(mockit.Mock) IOException(java.io.IOException) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline) SelectServiceDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.SelectServiceDemo) ExtractServiceDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.ExtractServiceDemo) TerminProcessDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.TerminProcessDemo) ChannelArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.ChannelArbitrateEvent) Event(com.alibaba.otter.shared.communication.core.model.Event) PipelineArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.PipelineArbitrateEvent) NodeArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent) ChannelArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.ChannelArbitrateEvent) LoadServiceDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.LoadServiceDemo) PipelineArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.PipelineArbitrateEvent) MainStemServiceDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.MainStemServiceDemo) NodeArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent) ProcessViewDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.ProcessViewDemo) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with NodeArbitrateEvent

use of com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent in project otter by alibaba.

the class ArbitrateOppositeIntegration method setUp.

@BeforeMethod
public void setUp() {
    // mock 配置信息数据
    Mockit.setUpMock(ArbitrateConfigUtils.class, new Object() {

        @Mock
        public Channel getChannelByChannelId(Long channelId) {
            Channel channel = new Channel();
            channel.setId(channelId);
            Pipeline pipeline = new Pipeline();
            pipeline.setId(pipelineId);
            pipeline.setSelectNodes(Arrays.asList(one));
            pipeline.setExtractNodes(Arrays.asList(one));
            pipeline.setLoadNodes(Arrays.asList(two));
            channel.setPipelines(Arrays.asList(pipeline));
            return channel;
        }

        @Mock
        public Pipeline getPipeline(Long pipelineId) {
            Pipeline pipeline = new Pipeline();
            pipeline.setId(pipelineId);
            pipeline.setSelectNodes(Arrays.asList(one));
            pipeline.setExtractNodes(Arrays.asList(one));
            pipeline.setLoadNodes(Arrays.asList(two));
            return pipeline;
        }

        @Mock
        public Long getCurrentNid() {
            return oneNid;
        }

        @Mock
        public int getParallelism(Long pipelineId) {
            // 并行度
            return 3;
        }

        @Mock
        public Pipeline getOppositePipeline(Long pipelineId) {
            Pipeline pipeline = new Pipeline();
            pipeline.setId(oppositePipelineId);
            pipeline.setSelectNodes(Arrays.asList(two));
            pipeline.setExtractNodes(Arrays.asList(two));
            pipeline.setLoadNodes(Arrays.asList(one));
            return pipeline;
        }

        @Mock
        public Channel getChannel(Long pipelineId) {
            Channel channel = new Channel();
            channel.setId(channelId);
            Pipeline pipeline = new Pipeline();
            pipeline.setId(pipelineId);
            Pipeline oppositePipeline = new Pipeline();
            oppositePipeline.setId(oppositePipelineId);
            channel.setPipelines(Arrays.asList(pipeline, oppositePipeline));
            return channel;
        }
    });
    Mockit.setUpMock(ArbitrateCommmunicationClient.class, new Object() {

        @Mock
        public Object callManager(final Event event) {
            // do nothing
            return null;
        }
    });
    zookeeper = getZookeeper();
    one.setId(oneNid);
    two.setId(twoNid);
    nodeEvent = new NodeArbitrateEvent();
    // 创建channel
    channelEvent = new ChannelArbitrateEvent();
    pipelineEvent = new PipelineArbitrateEvent();
    // 创建node节点
    nodeEvent.init(one.getId());
    // 创建pipeline节点
    try {
        channelEvent.init(channelId);
    } catch (Exception e) {
    // ignore
    }
    try {
        pipelineEvent.init(channelId, pipelineId);
    } catch (Exception e) {
    // ignore
    }
    arbitrateEventService = (ArbitrateEventService) getBeanFactory().getBean("arbitrateEventService");
    mainStem = new MainStemServiceDemo();
    autowire(mainStem);
    select = new SelectServiceDemo();
    autowire(select);
    extract = new ExtractServiceDemo();
    autowire(extract);
    transform = new TransformServiceDemo();
    autowire(transform);
    load = new LoadServiceDemo();
    autowire(load);
    view = new ProcessViewDemo();
    autowire(view);
    termin = new TerminProcessDemo();
    autowire(termin);
}
Also used : TransformServiceDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.TransformServiceDemo) Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) Mock(mockit.Mock) IOException(java.io.IOException) Pipeline(com.alibaba.otter.shared.common.model.config.pipeline.Pipeline) SelectServiceDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.SelectServiceDemo) ExtractServiceDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.ExtractServiceDemo) TerminProcessDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.TerminProcessDemo) ChannelArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.ChannelArbitrateEvent) Event(com.alibaba.otter.shared.communication.core.model.Event) PipelineArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.PipelineArbitrateEvent) NodeArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent) ChannelArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.ChannelArbitrateEvent) LoadServiceDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.LoadServiceDemo) PipelineArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.PipelineArbitrateEvent) MainStemServiceDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.MainStemServiceDemo) NodeArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent) ProcessViewDemo(com.alibaba.otter.shared.arbitrate.demo.servcie.ProcessViewDemo) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

NodeArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.manage.NodeArbitrateEvent)10 Channel (com.alibaba.otter.shared.common.model.config.channel.Channel)8 Mock (mockit.Mock)8 Pipeline (com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)7 ChannelArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.manage.ChannelArbitrateEvent)6 PipelineArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.manage.PipelineArbitrateEvent)6 BeforeClass (org.testng.annotations.BeforeClass)5 Event (com.alibaba.otter.shared.communication.core.model.Event)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 ExtractServiceDemo (com.alibaba.otter.shared.arbitrate.demo.servcie.ExtractServiceDemo)3 LoadServiceDemo (com.alibaba.otter.shared.arbitrate.demo.servcie.LoadServiceDemo)3 MainStemServiceDemo (com.alibaba.otter.shared.arbitrate.demo.servcie.MainStemServiceDemo)3 ProcessViewDemo (com.alibaba.otter.shared.arbitrate.demo.servcie.ProcessViewDemo)3 SelectServiceDemo (com.alibaba.otter.shared.arbitrate.demo.servcie.SelectServiceDemo)3 TerminProcessDemo (com.alibaba.otter.shared.arbitrate.demo.servcie.TerminProcessDemo)3 TransformServiceDemo (com.alibaba.otter.shared.arbitrate.demo.servcie.TransformServiceDemo)3 IOException (java.io.IOException)2 BaseOtterTest (com.alibaba.otter.manager.biz.BaseOtterTest)1 NodeDO (com.alibaba.otter.manager.biz.config.node.dal.dataobject.NodeDO)1 NodeMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.NodeMonitor)1