Search in sources :

Example 1 with NetworkMessagesFactory

use of org.apache.ignite.internal.network.NetworkMessagesFactory in project ignite-3 by apache.

the class ItConnectionManagerTest method startManager.

/**
 * Creates and starts a {@link ConnectionManager} listening on the given port, configured with the provided serialization registry.
 *
 * @param port     Port for the connection manager to listen on.
 * @param registry Serialization registry.
 * @return Connection manager.
 */
private IgniteBiTuple<ConnectionManager, NettyBootstrapFactory> startManager(int port, MessageSerializationRegistry registry) {
    UUID launchId = UUID.randomUUID();
    String consistentId = UUID.randomUUID().toString();
    var messageFactory = new NetworkMessagesFactory();
    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, new SerializationService(registry, mock(UserObjectSerializationContext.class)), consistentId, () -> new RecoveryServerHandshakeManager(launchId, consistentId, messageFactory), () -> new RecoveryClientHandshakeManager(launchId, consistentId, messageFactory), bootstrapFactory);
    manager.start();
    startedManagers.add(manager);
    return new IgniteBiTuple<>(manager, bootstrapFactory);
}
Also used : NettyBootstrapFactory(org.apache.ignite.network.NettyBootstrapFactory) NetworkMessagesFactory(org.apache.ignite.internal.network.NetworkMessagesFactory) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) SerializationService(org.apache.ignite.internal.network.serialization.SerializationService) UUID(java.util.UUID) NetworkView(org.apache.ignite.configuration.schemas.network.NetworkView) RecoveryClientHandshakeManager(org.apache.ignite.internal.network.recovery.RecoveryClientHandshakeManager) RecoveryServerHandshakeManager(org.apache.ignite.internal.network.recovery.RecoveryServerHandshakeManager)

Example 2 with NetworkMessagesFactory

use of org.apache.ignite.internal.network.NetworkMessagesFactory in project ignite-3 by apache.

the class ItRecoveryHandshakeTest method startManager.

/**
 * Starts a {@link ConnectionManager} with a normal handshake manager adding it to the {@link #startedManagers} list.
 *
 * @param port Port.
 * @return Connection manager
 */
private ConnectionManager startManager(int port) {
    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 RecoveryServerHandshakeManager(launchId, consistentId, messageFactory), () -> new RecoveryClientHandshakeManager(launchId, consistentId, messageFactory), bootstrapFactory);
    manager.start();
    startedManagers.add(manager);
    return manager;
}
Also used : TestMessageSerializationRegistryImpl(org.apache.ignite.network.TestMessageSerializationRegistryImpl) NettyBootstrapFactory(org.apache.ignite.network.NettyBootstrapFactory) ConnectionManager(org.apache.ignite.internal.network.netty.ConnectionManager) NetworkMessagesFactory(org.apache.ignite.internal.network.NetworkMessagesFactory) SerializationService(org.apache.ignite.internal.network.serialization.SerializationService) UUID(java.util.UUID) UserObjectSerializationContext(org.apache.ignite.internal.network.serialization.UserObjectSerializationContext) NetworkView(org.apache.ignite.configuration.schemas.network.NetworkView)

Example 3 with NetworkMessagesFactory

use of org.apache.ignite.internal.network.NetworkMessagesFactory 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;
}
Also used : TestMessageSerializationRegistryImpl(org.apache.ignite.network.TestMessageSerializationRegistryImpl) NettyBootstrapFactory(org.apache.ignite.network.NettyBootstrapFactory) ConnectionManager(org.apache.ignite.internal.network.netty.ConnectionManager) NetworkMessagesFactory(org.apache.ignite.internal.network.NetworkMessagesFactory) SerializationService(org.apache.ignite.internal.network.serialization.SerializationService) UUID(java.util.UUID) UserObjectSerializationContext(org.apache.ignite.internal.network.serialization.UserObjectSerializationContext) NetworkView(org.apache.ignite.configuration.schemas.network.NetworkView)

Example 4 with NetworkMessagesFactory

use of org.apache.ignite.internal.network.NetworkMessagesFactory in project ignite-3 by apache.

the class ItScaleCubeNetworkMessagingTest method testMessageGroupsHandlers.

/**
 * Tests that messages from different message groups can be delivered to different sets of handlers.
 *
 * @throws Exception in case of errors.
 */
@Test
public void testMessageGroupsHandlers(TestInfo testInfo) throws Exception {
    testCluster = new Cluster(2, testInfo);
    testCluster.startAwait();
    ClusterService node1 = testCluster.members.get(0);
    ClusterService node2 = testCluster.members.get(1);
    var testMessageFuture1 = new CompletableFuture<NetworkMessage>();
    var testMessageFuture2 = new CompletableFuture<NetworkMessage>();
    var networkMessageFuture = new CompletableFuture<NetworkMessage>();
    // register multiple handlers for the same group
    node1.messagingService().addMessageHandler(TestMessageTypes.class, (message, senderAddr, correlationId) -> assertTrue(testMessageFuture1.complete(message)));
    node1.messagingService().addMessageHandler(TestMessageTypes.class, (message, senderAddr, correlationId) -> assertTrue(testMessageFuture2.complete(message)));
    // register a different handle for the second group
    node1.messagingService().addMessageHandler(NetworkMessageTypes.class, (message, senderAddr, correlationId) -> {
        if (message instanceof FieldDescriptorMessage) {
            assertTrue(networkMessageFuture.complete(message));
        }
    });
    var testMessage = messageFactory.testMessage().msg("foo").build();
    FieldDescriptorMessage networkMessage = new NetworkMessagesFactory().fieldDescriptorMessage().build();
    // test that a message gets delivered to both handlers
    node2.messagingService().send(node1.topologyService().localMember(), testMessage).get(1, TimeUnit.SECONDS);
    // test that a message from the other group is only delivered to a single handler
    node2.messagingService().send(node1.topologyService().localMember(), networkMessage).get(1, TimeUnit.SECONDS);
    assertThat(testMessageFuture1, willBe(equalTo(testMessage)));
    assertThat(testMessageFuture2, willBe(equalTo(testMessage)));
    assertThat(networkMessageFuture, willBe(equalTo(networkMessage)));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ClusterService(org.apache.ignite.network.ClusterService) NetworkMessagesFactory(org.apache.ignite.internal.network.NetworkMessagesFactory) FieldDescriptorMessage(org.apache.ignite.internal.network.message.FieldDescriptorMessage) Test(org.junit.jupiter.api.Test)

Example 5 with NetworkMessagesFactory

use of org.apache.ignite.internal.network.NetworkMessagesFactory 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();
        }
    };
}
Also used : ClusterImpl(io.scalecube.cluster.ClusterImpl) DefaultUserObjectMarshaller(org.apache.ignite.internal.network.serialization.marshal.DefaultUserObjectMarshaller) NettyBootstrapFactory(org.apache.ignite.network.NettyBootstrapFactory) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) NetworkMessagesFactory(org.apache.ignite.internal.network.NetworkMessagesFactory) ClassDescriptorRegistry(org.apache.ignite.internal.network.serialization.ClassDescriptorRegistry) RecoveryClientHandshakeManager(org.apache.ignite.internal.network.recovery.RecoveryClientHandshakeManager) ClusterConfig(io.scalecube.cluster.ClusterConfig) ClusterMembershipView(org.apache.ignite.configuration.schemas.network.ClusterMembershipView) RecoveryServerHandshakeManager(org.apache.ignite.internal.network.recovery.RecoveryServerHandshakeManager) NetworkConfiguration(org.apache.ignite.configuration.schemas.network.NetworkConfiguration) ScaleCubeView(org.apache.ignite.configuration.schemas.network.ScaleCubeView) UserObjectSerializationContext(org.apache.ignite.internal.network.serialization.UserObjectSerializationContext) ClusterImpl(io.scalecube.cluster.ClusterImpl) DefaultMessagingService(org.apache.ignite.network.DefaultMessagingService) NodeFinder(org.apache.ignite.network.NodeFinder) NetworkView(org.apache.ignite.configuration.schemas.network.NetworkView) Address(io.scalecube.net.Address) NodeFinderFactory(org.apache.ignite.network.NodeFinderFactory) ConnectionManager(org.apache.ignite.internal.network.netty.ConnectionManager) ClassDescriptorFactory(org.apache.ignite.internal.network.serialization.ClassDescriptorFactory) ClusterLocalConfiguration(org.apache.ignite.network.ClusterLocalConfiguration) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) NetworkAddress(org.apache.ignite.network.NetworkAddress) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) MembershipEvent(io.scalecube.cluster.membership.MembershipEvent) AbstractClusterService(org.apache.ignite.network.AbstractClusterService) ClusterService(org.apache.ignite.network.ClusterService) ClusterMessageHandler(io.scalecube.cluster.ClusterMessageHandler) SerializationService(org.apache.ignite.internal.network.serialization.SerializationService) MembershipEvent(io.scalecube.cluster.membership.MembershipEvent) SerializationService(org.apache.ignite.internal.network.serialization.SerializationService) CompletableFuture(java.util.concurrent.CompletableFuture) ConnectionManager(org.apache.ignite.internal.network.netty.ConnectionManager) NetworkMessagesFactory(org.apache.ignite.internal.network.NetworkMessagesFactory) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException) UserObjectSerializationContext(org.apache.ignite.internal.network.serialization.UserObjectSerializationContext) TimeoutException(java.util.concurrent.TimeoutException) ClusterMessageHandler(io.scalecube.cluster.ClusterMessageHandler) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) DefaultMessagingService(org.apache.ignite.network.DefaultMessagingService) AbstractClusterService(org.apache.ignite.network.AbstractClusterService) NetworkView(org.apache.ignite.configuration.schemas.network.NetworkView) NodeFinder(org.apache.ignite.network.NodeFinder) RecoveryClientHandshakeManager(org.apache.ignite.internal.network.recovery.RecoveryClientHandshakeManager) RecoveryServerHandshakeManager(org.apache.ignite.internal.network.recovery.RecoveryServerHandshakeManager)

Aggregations

NetworkMessagesFactory (org.apache.ignite.internal.network.NetworkMessagesFactory)5 UUID (java.util.UUID)4 NetworkView (org.apache.ignite.configuration.schemas.network.NetworkView)4 SerializationService (org.apache.ignite.internal.network.serialization.SerializationService)4 NettyBootstrapFactory (org.apache.ignite.network.NettyBootstrapFactory)4 ConnectionManager (org.apache.ignite.internal.network.netty.ConnectionManager)3 UserObjectSerializationContext (org.apache.ignite.internal.network.serialization.UserObjectSerializationContext)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 RecoveryClientHandshakeManager (org.apache.ignite.internal.network.recovery.RecoveryClientHandshakeManager)2 RecoveryServerHandshakeManager (org.apache.ignite.internal.network.recovery.RecoveryServerHandshakeManager)2 ClusterService (org.apache.ignite.network.ClusterService)2 TestMessageSerializationRegistryImpl (org.apache.ignite.network.TestMessageSerializationRegistryImpl)2 ClusterConfig (io.scalecube.cluster.ClusterConfig)1 ClusterImpl (io.scalecube.cluster.ClusterImpl)1 ClusterMessageHandler (io.scalecube.cluster.ClusterMessageHandler)1 MembershipEvent (io.scalecube.cluster.membership.MembershipEvent)1 Address (io.scalecube.net.Address)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1