use of org.apache.ignite.network.NettyBootstrapFactory in project ignite-3 by apache.
the class ItRecoveryHandshakeTest method startManager.
/**
* Starts a {@link ConnectionManager} adding it to the {@link #startedManagers} list.
*
* @param port Port for the server.
* @param serverHandshakeFailAt At what stage to fail server handshake.
* @param clientHandshakeFailAt At what stage to fail client handshake.
* @return Connection manager.
*/
private ConnectionManager startManager(int port, ServerStageFail serverHandshakeFailAt, ClientStageFail clientHandshakeFailAt) {
var registry = new TestMessageSerializationRegistryImpl();
var serializationService = new SerializationService(registry, mock(UserObjectSerializationContext.class));
var messageFactory = new NetworkMessagesFactory();
UUID launchId = UUID.randomUUID();
String consistentId = UUID.randomUUID().toString();
networkConfiguration.port().update(port).join();
NetworkView cfg = networkConfiguration.value();
NettyBootstrapFactory bootstrapFactory = new NettyBootstrapFactory(networkConfiguration, consistentId);
bootstrapFactory.start();
startedBootstrapFactories.add(bootstrapFactory);
var manager = new ConnectionManager(cfg, serializationService, consistentId, () -> new FailingRecoveryServerHandshakeManager(launchId, consistentId, serverHandshakeFailAt, messageFactory), () -> new FailingRecoveryClientHandshakeManager(launchId, consistentId, clientHandshakeFailAt, messageFactory), bootstrapFactory);
manager.start();
startedManagers.add(manager);
return manager;
}
use of org.apache.ignite.network.NettyBootstrapFactory in project ignite-3 by apache.
the class ScaleCubeClusterServiceFactory method createClusterService.
/**
* Creates a new {@link ClusterService} using the provided context. The created network will not be in the "started" state.
*
* @param context Cluster context.
* @param networkConfiguration Network configuration.
* @param nettyBootstrapFactory Bootstrap factory.
* @return New cluster service.
*/
public ClusterService createClusterService(ClusterLocalConfiguration context, NetworkConfiguration networkConfiguration, NettyBootstrapFactory nettyBootstrapFactory) {
var messageFactory = new NetworkMessagesFactory();
var topologyService = new ScaleCubeTopologyService();
UserObjectSerializationContext userObjectSerialization = createUserObjectSerializationContext();
var messagingService = new DefaultMessagingService(messageFactory, topologyService, userObjectSerialization);
return new AbstractClusterService(context, topologyService, messagingService) {
private volatile ClusterImpl cluster;
private volatile ConnectionManager connectionMgr;
private volatile CompletableFuture<Void> shutdownFuture;
/**
* {@inheritDoc}
*/
@Override
public void start() {
String consistentId = context.getName();
var serializationService = new SerializationService(context.getSerializationRegistry(), userObjectSerialization);
UUID launchId = UUID.randomUUID();
NetworkView configView = networkConfiguration.value();
connectionMgr = new ConnectionManager(configView, serializationService, consistentId, () -> new RecoveryServerHandshakeManager(launchId, consistentId, messageFactory), () -> new RecoveryClientHandshakeManager(launchId, consistentId, messageFactory), nettyBootstrapFactory);
connectionMgr.start();
var transport = new ScaleCubeDirectMarshallerTransport(connectionMgr.getLocalAddress(), messagingService, topologyService, messageFactory);
NodeFinder finder = NodeFinderFactory.createNodeFinder(configView.nodeFinder());
cluster = new ClusterImpl(clusterConfig(configView.membership())).handler(cl -> new ClusterMessageHandler() {
/**
* {@inheritDoc}
*/
@Override
public void onMembershipEvent(MembershipEvent event) {
topologyService.onMembershipEvent(event);
}
}).config(opts -> opts.memberAlias(consistentId)).transport(opts -> opts.transportFactory(transportConfig -> transport)).membership(opts -> opts.seedMembers(parseAddresses(finder.findNodes())));
shutdownFuture = cluster.onShutdown().toFuture();
// resolve cyclic dependencies
topologyService.setCluster(cluster);
messagingService.setConnectionManager(connectionMgr);
cluster.startAwait();
// emit an artificial event as if the local member has joined the topology (ScaleCube doesn't do that)
var localMembershipEvent = MembershipEvent.createAdded(cluster.member(), null, System.currentTimeMillis());
topologyService.onMembershipEvent(localMembershipEvent);
}
/**
* {@inheritDoc}
*/
@Override
public void stop() {
// local member will be null, if cluster has not been started
if (cluster.member() == null) {
return;
}
cluster.shutdown();
try {
shutdownFuture.get(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IgniteInternalException("Interrupted while waiting for the ClusterService to stop", e);
} catch (TimeoutException e) {
throw new IgniteInternalException("Timeout while waiting for the ClusterService to stop", e);
} catch (ExecutionException e) {
throw new IgniteInternalException("Unable to stop the ClusterService", e.getCause());
}
connectionMgr.stop();
// Messaging service checks connection manager's status before sending a message, so connection manager should be
// stopped before messaging service
messagingService.stop();
}
/**
* {@inheritDoc}
*/
@Override
public void beforeNodeStop() {
stop();
}
/**
* {@inheritDoc}
*/
@Override
public boolean isStopped() {
return shutdownFuture.isDone();
}
};
}
use of org.apache.ignite.network.NettyBootstrapFactory in project ignite-3 by apache.
the class NettyServerTest method getServer.
/**
* Creates a server from a backing {@link ChannelFuture}.
*
* @param shouldStart {@code true} if a server should start successfully
* @return NettyServer.
*/
private NettyServer getServer(boolean shouldStart) {
bootstrapFactory = new NettyBootstrapFactory(serverCfg, "");
bootstrapFactory.start();
var server = new NettyServer(serverCfg.value(), () -> mock(HandshakeManager.class), null, null, null, bootstrapFactory);
try {
server.start().get(3, TimeUnit.SECONDS);
} catch (Exception e) {
if (shouldStart) {
fail(e);
}
}
return server;
}
use of org.apache.ignite.network.NettyBootstrapFactory in project ignite-3 by apache.
the class ItClientHandlerTest method startServer.
private ClientHandlerModule startServer(TestInfo testInfo) {
configurationManager = new ConfigurationManager(List.of(ClientConnectorConfiguration.KEY, NetworkConfiguration.KEY), Map.of(), new TestConfigurationStorage(LOCAL), List.of(), List.of());
configurationManager.start();
var registry = configurationManager.configurationRegistry();
registry.getConfiguration(ClientConnectorConfiguration.KEY).change(local -> local.changePort(10800).changePortRange(10)).join();
bootstrapFactory = new NettyBootstrapFactory(registry.getConfiguration(NetworkConfiguration.KEY), testInfo.getDisplayName());
bootstrapFactory.start();
var module = new ClientHandlerModule(mock(QueryProcessor.class), mock(IgniteTables.class), mock(IgniteTransactions.class), registry, bootstrapFactory);
module.start();
return module;
}
Aggregations