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() + "]");
}
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));
}
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();
}
}
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);
}
}
}
}
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);
}
});
}
}
}
}
Aggregations