Search in sources :

Example 1 with RoleType

use of com.alibaba.maxgraph.common.RoleType in project GraphScope by alibaba.

the class MaxGraph method main.

public static void main(String[] args) throws IOException {
    String configFile = System.getProperty("config.file");
    Configs conf = new Configs(configFile);
    NodeBase node;
    if (args.length == 0) {
        logger.warn("No role type, use MaxNode");
        try {
            node = new MaxNode(conf);
        } catch (Exception e) {
            throw new MaxGraphException(e);
        }
    } else {
        String roleName = args[0];
        if (roleName.equalsIgnoreCase("store-gaia") || roleName.equalsIgnoreCase("frontend-gaia")) {
            conf = Configs.newBuilder(conf).put(CommonConfig.ENGINE_TYPE.getKey(), "gaia").build();
        }
        RoleType roleType = RoleType.fromName(roleName);
        switch(roleType) {
            case FRONTEND:
                node = new Frontend(conf);
                break;
            case INGESTOR:
                node = new Ingestor(conf);
                break;
            case STORE:
                node = new Store(conf);
                break;
            case COORDINATOR:
                node = new Coordinator(conf);
                break;
            default:
                throw new IllegalArgumentException("invalid roleType [" + roleType + "]");
        }
    }
    new NodeLauncher(node).start();
    logger.info("node started. [" + node.getName() + "]");
}
Also used : RoleType(com.alibaba.maxgraph.common.RoleType) MaxGraphException(com.alibaba.maxgraph.compiler.api.exception.MaxGraphException) MaxGraphException(com.alibaba.maxgraph.compiler.api.exception.MaxGraphException) IOException(java.io.IOException) Configs(com.alibaba.maxgraph.common.config.Configs)

Example 2 with RoleType

use of com.alibaba.maxgraph.common.RoleType in project GraphScope by alibaba.

the class LocalNodeProviderTest method testProvider.

@Test
void testProvider() {
    RoleType role = RoleType.STORE;
    int idx = 2;
    int port = 1111;
    Configs configs = Configs.newBuilder().put("role.name", role.getName()).put("node.idx", String.valueOf(idx)).put("discovery.mode", "zookeeper").build();
    LocalNodeProvider localNodeProvider = new LocalNodeProvider(configs);
    MaxGraphNode node = localNodeProvider.apply(port);
    Assertions.assertAll(() -> assertEquals(node.getRoleName(), role.getName()), () -> assertEquals(node.getIdx(), idx), () -> assertEquals(node.getPort(), port));
    assertThrows(MaxGraphException.class, () -> localNodeProvider.apply(port));
}
Also used : LocalNodeProvider(com.alibaba.graphscope.groot.discovery.LocalNodeProvider) MaxGraphNode(com.alibaba.graphscope.groot.discovery.MaxGraphNode) RoleType(com.alibaba.maxgraph.common.RoleType) Configs(com.alibaba.maxgraph.common.config.Configs) Test(org.junit.jupiter.api.Test)

Example 3 with RoleType

use of com.alibaba.maxgraph.common.RoleType in project GraphScope by alibaba.

the class ZkDiscoveryTest method testDiscovery.

@Test
void testDiscovery() throws Exception {
    try (TestingServer testingServer = new TestingServer(-1)) {
        int zkPort = testingServer.getPort();
        Configs zkConfigs = Configs.newBuilder().put(ZkConfig.ZK_CONNECT_STRING.getKey(), "localhost:" + zkPort).put(ZkConfig.ZK_BASE_PATH.getKey(), "test_discovery").build();
        CuratorFramework curator = CuratorUtils.makeCurator(zkConfigs);
        curator.start();
        RoleType role = RoleType.STORE;
        NodeDiscovery discovery1 = createNodeDiscovery(role, 0, 1111, zkConfigs, curator);
        NodeDiscovery discovery2 = createNodeDiscovery(role, 1, 2222, zkConfigs, curator);
        discovery1.start();
        CountDownLatch latch1 = new CountDownLatch(1);
        CountDownLatch latch2 = new CountDownLatch(1);
        NodeDiscovery.Listener mockListener = mock(NodeDiscovery.Listener.class);
        doAnswer(invocationOnMock -> {
            latch1.countDown();
            return null;
        }).when(mockListener).nodesJoin(RoleType.STORE, Collections.singletonMap(0, discovery1.getLocalNode()));
        doAnswer(invocationOnMock -> {
            latch2.countDown();
            return null;
        }).when(mockListener).nodesJoin(RoleType.STORE, Collections.singletonMap(1, discovery2.getLocalNode()));
        discovery1.addListener(mockListener);
        assertTrue(latch1.await(5L, TimeUnit.SECONDS));
        discovery2.start();
        assertTrue(latch2.await(5L, TimeUnit.SECONDS));
        verify(mockListener, times(2)).nodesJoin(any(), any());
        verify(mockListener, never()).nodesLeft(any(), any());
        discovery2.stop();
        verify(mockListener, timeout(5000L)).nodesLeft(RoleType.STORE, Collections.singletonMap(1, discovery2.getLocalNode()));
        discovery1.stop();
        curator.close();
    }
}
Also used : TestingServer(org.apache.curator.test.TestingServer) CuratorFramework(org.apache.curator.framework.CuratorFramework) NodeDiscovery(com.alibaba.graphscope.groot.discovery.NodeDiscovery) RoleType(com.alibaba.maxgraph.common.RoleType) Configs(com.alibaba.maxgraph.common.config.Configs) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 4 with RoleType

use of com.alibaba.maxgraph.common.RoleType in project GraphScope by alibaba.

the class FileDiscovery method addListener.

@Override
public void addListener(Listener listener) {
    for (Map.Entry<RoleType, Map<Integer, MaxGraphNode>> e : allNodes.entrySet()) {
        RoleType role = e.getKey();
        Map<Integer, MaxGraphNode> nodes = e.getValue();
        if (!nodes.isEmpty()) {
            try {
                listener.nodesJoin(role, nodes);
            } catch (Exception ex) {
                logger.error("listener [" + listener + "] failed on nodesJoin [" + nodes + "]", ex);
            }
        }
    }
}
Also used : RoleType(com.alibaba.maxgraph.common.RoleType) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with RoleType

use of com.alibaba.maxgraph.common.RoleType in project GraphScope by alibaba.

the class ZkDiscovery method addListener.

@Override
public void addListener(Listener listener) {
    synchronized (lock) {
        this.listeners.add(listener);
        Map<RoleType, Map<Integer, MaxGraphNode>> currentNodes = this.currentNodesRef.get();
        for (Map.Entry<RoleType, Map<Integer, MaxGraphNode>> e : currentNodes.entrySet()) {
            RoleType role = e.getKey();
            Map<Integer, MaxGraphNode> nodes = e.getValue();
            if (!nodes.isEmpty()) {
                this.singleThreadExecutor.execute(() -> {
                    try {
                        listener.nodesJoin(role, nodes);
                    } catch (Exception ex) {
                        logger.error("listener [" + listener + "] failed on nodesJoin [" + nodes + "]", ex);
                    }
                });
            }
        }
    }
}
Also used : RoleType(com.alibaba.maxgraph.common.RoleType) HashMap(java.util.HashMap) Map(java.util.Map) MaxGraphException(com.alibaba.maxgraph.compiler.api.exception.MaxGraphException)

Aggregations

RoleType (com.alibaba.maxgraph.common.RoleType)9 HashMap (java.util.HashMap)4 Configs (com.alibaba.maxgraph.common.config.Configs)3 MaxGraphException (com.alibaba.maxgraph.compiler.api.exception.MaxGraphException)3 Map (java.util.Map)3 ManagedChannel (io.grpc.ManagedChannel)2 Test (org.junit.jupiter.api.Test)2 LocalNodeProvider (com.alibaba.graphscope.groot.discovery.LocalNodeProvider)1 MaxGraphNode (com.alibaba.graphscope.groot.discovery.MaxGraphNode)1 NodeDiscovery (com.alibaba.graphscope.groot.discovery.NodeDiscovery)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 TestingServer (org.apache.curator.test.TestingServer)1 JsonInstanceSerializer (org.apache.curator.x.discovery.details.JsonInstanceSerializer)1