use of org.apache.ignite.network.ClusterNode in project ignite-3 by apache.
the class MetaStorageManager method start.
/**
* {@inheritDoc}
*/
@Override
public void start() {
String[] metastorageNodes = this.locCfgMgr.configurationRegistry().getConfiguration(NodeConfiguration.KEY).metastorageNodes().value();
Predicate<ClusterNode> metaStorageNodesContainsLocPred = clusterNode -> Arrays.asList(metastorageNodes).contains(clusterNode.name());
if (metastorageNodes.length > 0) {
metaStorageNodesOnStart = true;
List<ClusterNode> metaStorageMembers = clusterNetSvc.topologyService().allMembers().stream().filter(metaStorageNodesContainsLocPred).collect(Collectors.toList());
// without hosting metastorage, this will be rewritten in init phase https://issues.apache.org/jira/browse/IGNITE-15114
if (metaStorageMembers.isEmpty()) {
throw new IgniteException("Cannot start meta storage manager because there is no node in the cluster that hosts meta storage.");
}
// This will be rewritten in init phase https://issues.apache.org/jira/browse/IGNITE-15114
if (metastorageNodes.length > 1) {
throw new IgniteException("Cannot start meta storage manager because it is not allowed to start several metastorage nodes.");
}
storage.start();
try {
raftGroupServiceFut = raftMgr.prepareRaftGroup(METASTORAGE_RAFT_GROUP_NAME, metaStorageMembers, () -> new MetaStorageListener(storage));
} catch (NodeStoppingException e) {
throw new AssertionError("Loza was stopped before Meta Storage manager", e);
}
this.metaStorageSvcFut = raftGroupServiceFut.thenApply(service -> new MetaStorageServiceImpl(service, clusterNetSvc.topologyService().localMember().id()));
if (hasMetastorageLocally(locCfgMgr)) {
clusterNetSvc.topologyService().addEventHandler(new TopologyEventHandler() {
@Override
public void onAppeared(ClusterNode member) {
// No-op.
}
@Override
public void onDisappeared(ClusterNode member) {
metaStorageSvcFut.thenCompose(svc -> svc.closeCursors(member.id()));
}
});
}
} else {
this.metaStorageSvcFut = new CompletableFuture<>();
}
// TODO: IGNITE-15114 Cluster initialization flow. Here we should complete metaStorageServiceFuture.
// clusterNetSvc.messagingService().addMessageHandler((message, senderAddr, correlationId) -> {});
}
use of org.apache.ignite.network.ClusterNode in project ignite-3 by apache.
the class ItScaleCubeNetworkMessagingTest method testSendMessageToSelf.
/**
* Sends a message from a node to itself and verifies that it gets delivered successfully.
*
* @throws Exception in case of errors.
*/
@Test
public void testSendMessageToSelf(TestInfo testInfo) throws Exception {
testCluster = new Cluster(1, testInfo);
testCluster.startAwait();
ClusterService member = testCluster.members.get(0);
ClusterNode self = member.topologyService().localMember();
class Data {
private final TestMessage message;
private final NetworkAddress sender;
private final Long correlationId;
private Data(TestMessage message, NetworkAddress sender, Long correlationId) {
this.message = message;
this.sender = sender;
this.correlationId = correlationId;
}
}
var dataFuture = new CompletableFuture<Data>();
member.messagingService().addMessageHandler(TestMessageTypes.class, (message, senderAddr, correlationId) -> dataFuture.complete(new Data((TestMessage) message, senderAddr, correlationId)));
var requestMessage = messageFactory.testMessage().msg("request").build();
member.messagingService().send(self, requestMessage);
Data actualData = dataFuture.get(3, TimeUnit.SECONDS);
assertThat(actualData.message.msg(), is(requestMessage.msg()));
assertThat(actualData.sender.consistentId(), is(self.name()));
assertNull(actualData.correlationId);
}
use of org.apache.ignite.network.ClusterNode in project ignite-3 by apache.
the class ItScaleCubeNetworkMessagingTest method testShutdown0.
/**
* Tests shutdown.
*
* @param testInfo Test info.
* @param forceful Whether shutdown should be forceful.
* @throws Exception If failed.
*/
private void testShutdown0(TestInfo testInfo, boolean forceful) throws Exception {
testCluster = new Cluster(2, testInfo);
testCluster.startAwait();
ClusterService alice = testCluster.members.get(0);
ClusterService bob = testCluster.members.get(1);
String aliceName = alice.localConfiguration().getName();
var aliceShutdownLatch = new CountDownLatch(1);
bob.topologyService().addEventHandler(new TopologyEventHandler() {
/**
* {@inheritDoc}
*/
@Override
public void onAppeared(ClusterNode member) {
// No-op.
}
/**
* {@inheritDoc}
*/
@Override
public void onDisappeared(ClusterNode member) {
if (aliceName.equals(member.name())) {
aliceShutdownLatch.countDown();
}
}
});
if (forceful) {
stopForcefully(alice);
} else {
alice.stop();
}
boolean aliceShutdownReceived = aliceShutdownLatch.await(forceful ? 10 : 3, TimeUnit.SECONDS);
assertTrue(aliceShutdownReceived);
Collection<ClusterNode> networkMembers = bob.topologyService().allMembers();
assertEquals(1, networkMembers.size());
}
use of org.apache.ignite.network.ClusterNode in project ignite-3 by apache.
the class MessageServiceImpl method onMessage.
private void onMessage(NetworkMessage msg, NetworkAddress addr, @Nullable Long correlationId) {
assert msg.groupType() == GROUP_TYPE : "unexpected message group grpType=" + msg.groupType();
ClusterNode node = topSrvc.getByAddress(addr);
if (node == null) {
LOG.warn("Received a message from a node that has not yet" + " joined the cluster: addr={}, msg={}", addr, msg);
return;
}
onMessage(node.id(), msg);
}
use of org.apache.ignite.network.ClusterNode in project ignite-3 by apache.
the class MockedStructuresTest method mockManagers.
// todo copy-paste from TableManagerTest will be removed after https://issues.apache.org/jira/browse/IGNITE-16050
/**
* Instantiates a table and prepares Table manager.
*
* @return Table manager.
*/
private TableManager mockManagers() throws NodeStoppingException {
when(rm.prepareRaftGroup(any(), any(), any())).thenAnswer(mock -> {
RaftGroupService raftGrpSrvcMock = mock(RaftGroupService.class);
when(raftGrpSrvcMock.leader()).thenReturn(new Peer(new NetworkAddress("localhost", 47500)));
return completedFuture(raftGrpSrvcMock);
});
when(ts.getByAddress(any(NetworkAddress.class))).thenReturn(new ClusterNode(UUID.randomUUID().toString(), "node0", new NetworkAddress("localhost", 47500)));
try (MockedStatic<SchemaUtils> schemaServiceMock = mockStatic(SchemaUtils.class)) {
schemaServiceMock.when(() -> SchemaUtils.prepareSchemaDescriptor(anyInt(), any())).thenReturn(mock(SchemaDescriptor.class));
}
when(cs.messagingService()).thenAnswer(invocation -> {
MessagingService ret = mock(MessagingService.class);
return ret;
});
when(cs.localConfiguration()).thenAnswer(invocation -> {
ClusterLocalConfiguration ret = mock(ClusterLocalConfiguration.class);
when(ret.getName()).thenReturn("node1");
return ret;
});
when(cs.topologyService()).thenAnswer(invocation -> {
TopologyService ret = mock(TopologyService.class);
when(ret.localMember()).thenReturn(new ClusterNode("1", "node1", null));
return ret;
});
TableManager tableManager = createTableManager();
return tableManager;
}
Aggregations