Search in sources :

Example 1 with ConfigurationManager

use of org.apache.ignite.internal.configuration.ConfigurationManager in project ignite-3 by apache.

the class ClusterServiceTestUtils method clusterService.

/**
 * Creates a cluster service and required node configuration manager beneath it. Populates node configuration with specified port.
 * Manages configuration manager lifecycle: on cluster service start starts node configuration manager, on cluster service stop - stops
 * node configuration manager.
 *
 * @param testInfo                 Test info.
 * @param port                     Local port.
 * @param nodeFinder               Node finder.
 * @param clusterSvcFactory        Cluster service factory.
 */
public static ClusterService clusterService(TestInfo testInfo, int port, NodeFinder nodeFinder, TestScaleCubeClusterServiceFactory clusterSvcFactory) {
    var registry = new MessageSerializationRegistryImpl();
    REGISTRY_INITIALIZERS.forEach(c -> {
        try {
            c.invoke(c.getDeclaringClass(), registry);
        } catch (Throwable e) {
            throw new RuntimeException("Failed to invoke registry initializer", e);
        }
    });
    var ctx = new ClusterLocalConfiguration(testNodeName(testInfo, port), registry);
    ConfigurationManager nodeConfigurationMgr = new ConfigurationManager(Collections.singleton(NetworkConfiguration.KEY), Map.of(), new TestConfigurationStorage(ConfigurationType.LOCAL), List.of(), List.of());
    NetworkConfiguration configuration = nodeConfigurationMgr.configurationRegistry().getConfiguration(NetworkConfiguration.KEY);
    var bootstrapFactory = new NettyBootstrapFactory(configuration, ctx.getName());
    var clusterSvc = clusterSvcFactory.createClusterService(ctx, configuration, bootstrapFactory);
    assert nodeFinder instanceof StaticNodeFinder : "Only StaticNodeFinder is supported at the moment";
    return new ClusterService() {

        @Override
        public TopologyService topologyService() {
            return clusterSvc.topologyService();
        }

        @Override
        public MessagingService messagingService() {
            return clusterSvc.messagingService();
        }

        @Override
        public ClusterLocalConfiguration localConfiguration() {
            return clusterSvc.localConfiguration();
        }

        @Override
        public boolean isStopped() {
            return clusterSvc.isStopped();
        }

        @Override
        public void start() {
            nodeConfigurationMgr.start();
            NetworkConfiguration configuration = nodeConfigurationMgr.configurationRegistry().getConfiguration(NetworkConfiguration.KEY);
            configuration.change(netCfg -> netCfg.changePort(port).changeNodeFinder(c -> c.changeType(NodeFinderType.STATIC.toString()).changeNetClusterNodes(nodeFinder.findNodes().stream().map(NetworkAddress::toString).toArray(String[]::new)))).join();
            bootstrapFactory.start();
            clusterSvc.start();
        }

        @Override
        public void stop() {
            try {
                clusterSvc.stop();
                bootstrapFactory.stop();
                nodeConfigurationMgr.stop();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
}
Also used : IntStream(java.util.stream.IntStream) ClassGraph(io.github.classgraph.ClassGraph) NodeFinderType(org.apache.ignite.configuration.schemas.network.NodeFinderType) NettyBootstrapFactory(org.apache.ignite.network.NettyBootstrapFactory) ConfigurationType(org.apache.ignite.configuration.annotation.ConfigurationType) IgniteTestUtils.testNodeName(org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName) Collectors.toUnmodifiableList(java.util.stream.Collectors.toUnmodifiableList) ArrayList(java.util.ArrayList) TestScaleCubeClusterServiceFactory(org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory) NetworkConfiguration(org.apache.ignite.configuration.schemas.network.NetworkConfiguration) Map(java.util.Map) NodeFinder(org.apache.ignite.network.NodeFinder) ScanResult(io.github.classgraph.ScanResult) Method(java.lang.reflect.Method) MessagingService(org.apache.ignite.network.MessagingService) MessageSerializationRegistryInitializer(org.apache.ignite.network.serialization.MessageSerializationRegistryInitializer) TopologyService(org.apache.ignite.network.TopologyService) ClusterLocalConfiguration(org.apache.ignite.network.ClusterLocalConfiguration) ClassInfo(io.github.classgraph.ClassInfo) ConfigurationManager(org.apache.ignite.internal.configuration.ConfigurationManager) TestInfo(org.junit.jupiter.api.TestInfo) NetworkAddress(org.apache.ignite.network.NetworkAddress) List(java.util.List) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) MessageSerializationRegistry(org.apache.ignite.network.serialization.MessageSerializationRegistry) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) ClusterService(org.apache.ignite.network.ClusterService) NetworkMessagesSerializationRegistryInitializer(org.apache.ignite.internal.network.NetworkMessagesSerializationRegistryInitializer) MessageSerializationRegistryImpl(org.apache.ignite.network.MessageSerializationRegistryImpl) Collections(java.util.Collections) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) NettyBootstrapFactory(org.apache.ignite.network.NettyBootstrapFactory) ClusterService(org.apache.ignite.network.ClusterService) MessageSerializationRegistryImpl(org.apache.ignite.network.MessageSerializationRegistryImpl) NetworkConfiguration(org.apache.ignite.configuration.schemas.network.NetworkConfiguration) ClusterLocalConfiguration(org.apache.ignite.network.ClusterLocalConfiguration) ConfigurationManager(org.apache.ignite.internal.configuration.ConfigurationManager)

Example 2 with ConfigurationManager

use of org.apache.ignite.internal.configuration.ConfigurationManager 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;
}
Also used : TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Socket(java.net.Socket) NettyBootstrapFactory(org.apache.ignite.network.NettyBootstrapFactory) QueryProcessor(org.apache.ignite.internal.sql.engine.QueryProcessor) NetworkConfiguration(org.apache.ignite.configuration.schemas.network.NetworkConfiguration) Map(java.util.Map) IgniteTables(org.apache.ignite.table.manager.IgniteTables) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) OutputStream(java.io.OutputStream) IOException(java.io.IOException) MessagePack(org.msgpack.core.MessagePack) ConfigurationManager(org.apache.ignite.internal.configuration.ConfigurationManager) InetSocketAddress(java.net.InetSocketAddress) TestInfo(org.junit.jupiter.api.TestInfo) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) LOCAL(org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) IgniteTransactions(org.apache.ignite.tx.IgniteTransactions) Mockito.mock(org.mockito.Mockito.mock) ClientConnectorConfiguration(org.apache.ignite.configuration.schemas.clientconnector.ClientConnectorConfiguration) NettyBootstrapFactory(org.apache.ignite.network.NettyBootstrapFactory) IgniteTables(org.apache.ignite.table.manager.IgniteTables) IgniteTransactions(org.apache.ignite.tx.IgniteTransactions) ConfigurationManager(org.apache.ignite.internal.configuration.ConfigurationManager) QueryProcessor(org.apache.ignite.internal.sql.engine.QueryProcessor)

Aggregations

List (java.util.List)2 Map (java.util.Map)2 NetworkConfiguration (org.apache.ignite.configuration.schemas.network.NetworkConfiguration)2 ConfigurationManager (org.apache.ignite.internal.configuration.ConfigurationManager)2 TestConfigurationStorage (org.apache.ignite.internal.configuration.storage.TestConfigurationStorage)2 NettyBootstrapFactory (org.apache.ignite.network.NettyBootstrapFactory)2 TestInfo (org.junit.jupiter.api.TestInfo)2 ClassGraph (io.github.classgraph.ClassGraph)1 ClassInfo (io.github.classgraph.ClassInfo)1 ScanResult (io.github.classgraph.ScanResult)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Method (java.lang.reflect.Method)1 InetSocketAddress (java.net.InetSocketAddress)1 Socket (java.net.Socket)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Objects (java.util.Objects)1 Collectors.toUnmodifiableList (java.util.stream.Collectors.toUnmodifiableList)1 IntStream (java.util.stream.IntStream)1