Search in sources :

Example 1 with StaticNodeFinder

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

the class ItCliServiceTest method setup.

/**
 * Executes before each test.
 */
@BeforeEach
public void setup(TestInfo testInfo, @WorkDirectory Path dataPath) throws Exception {
    LOG.info(">>>>>>>>>>>>>>> Start test method: " + testInfo.getDisplayName());
    List<PeerId> peers = TestUtils.generatePeers(3);
    LinkedHashSet<PeerId> learners = new LinkedHashSet<>();
    // 2 learners
    for (int i = 0; i < 2; i++) {
        learners.add(new PeerId(TestUtils.getLocalAddress(), TestUtils.INIT_PORT + LEARNER_PORT_STEP + i));
    }
    cluster = new TestCluster(groupId, dataPath.toString(), peers, learners, ELECTION_TIMEOUT_MILLIS, testInfo);
    for (PeerId peer : peers) {
        cluster.start(peer.getEndpoint());
    }
    for (PeerId peer : learners) {
        cluster.startLearner(peer);
    }
    cluster.waitLeader();
    cluster.ensureLeader(cluster.getLeader());
    cliService = new CliServiceImpl();
    conf = new Configuration(peers, learners);
    CliOptions opts = new CliOptions();
    clientExecutor = JRaftUtils.createClientExecutor(opts, "client");
    opts.setClientExecutor(clientExecutor);
    List<NetworkAddress> addressList = peers.stream().map(PeerId::getEndpoint).map(JRaftUtils::addressFromEndpoint).collect(toList());
    ClusterService clientSvc = ClusterServiceTestUtils.clusterService(testInfo, TestUtils.INIT_PORT - 1, new StaticNodeFinder(addressList), new TestScaleCubeClusterServiceFactory());
    clientSvc.start();
    IgniteRpcClient rpcClient = new IgniteRpcClient(clientSvc) {

        @Override
        public void shutdown() {
            super.shutdown();
            clientSvc.stop();
        }
    };
    opts.setRpcClient(rpcClient);
    assertTrue(cliService.init(opts));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Configuration(org.apache.ignite.raft.jraft.conf.Configuration) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) IgniteRpcClient(org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcClient) CliOptions(org.apache.ignite.raft.jraft.option.CliOptions) ClusterService(org.apache.ignite.network.ClusterService) TestScaleCubeClusterServiceFactory(org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory) NetworkAddress(org.apache.ignite.network.NetworkAddress) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with StaticNodeFinder

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

the class ItInternalTableScanTest method setUp.

/**
 * Prepare test environment.
 * <ol>
 * <li>Start network node.</li>
 * <li>Start raft server.</li>
 * <li>Prepare partitioned raft group.</li>
 * <li>Prepare partitioned raft group service.</li>
 * <li>Prepare internal table as a test object.</li>
 * </ol>
 *
 * @throws Exception If any.
 */
@BeforeEach
public void setUp(TestInfo testInfo) throws Exception {
    NetworkAddress nodeNetworkAddress = new NetworkAddress("localhost", 20_000);
    network = ClusterServiceTestUtils.clusterService(testInfo, 20_000, new StaticNodeFinder(List.of(nodeNetworkAddress)), NETWORK_FACTORY);
    network.start();
    raftSrv = new RaftServerImpl(network, FACTORY);
    raftSrv.start();
    String grpName = "test_part_grp";
    List<Peer> conf = List.of(new Peer(nodeNetworkAddress));
    mockStorage = mock(PartitionStorage.class);
    txManager = new TxManagerImpl(network, new HeapLockManager());
    txManager.start();
    UUID tblId = UUID.randomUUID();
    raftSrv.startRaftGroup(grpName, new PartitionListener(tblId, new VersionedRowStore(mockStorage, txManager) {

        @Override
        protected Pair<BinaryRow, BinaryRow> versionedRow(@Nullable DataRow row, Timestamp timestamp) {
            // Return as is.
            return new Pair<>(new ByteBufferRow(row.valueBytes()), null);
        }
    }), conf);
    executor = new ScheduledThreadPoolExecutor(20, new NamedThreadFactory(Loza.CLIENT_POOL_NAME));
    RaftGroupService raftGrpSvc = RaftGroupServiceImpl.start(RAFT_GRP_ID, network, FACTORY, 10_000, conf, true, 200, executor).get(3, TimeUnit.SECONDS);
    internalTbl = new InternalTableImpl(TEST_TABLE_NAME, tblId, Int2ObjectMaps.singleton(0, raftGrpSvc), 1, NetworkAddress::toString, txManager, mock(TableStorage.class));
}
Also used : VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) Peer(org.apache.ignite.raft.client.Peer) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) SimpleDataRow(org.apache.ignite.internal.storage.basic.SimpleDataRow) DataRow(org.apache.ignite.internal.storage.DataRow) Timestamp(org.apache.ignite.internal.tx.Timestamp) RaftServerImpl(org.apache.ignite.internal.raft.server.impl.RaftServerImpl) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) PartitionListener(org.apache.ignite.internal.table.distributed.raft.PartitionListener) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) NetworkAddress(org.apache.ignite.network.NetworkAddress) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) UUID(java.util.UUID) Nullable(org.jetbrains.annotations.Nullable) PartitionStorage(org.apache.ignite.internal.storage.PartitionStorage) Pair(org.apache.ignite.internal.util.Pair) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with StaticNodeFinder

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

the class ItNodeRestartsTest method testRestarts.

/**
 * Tests that restarting nodes get discovered in an established topology.
 */
@Test
public void testRestarts(TestInfo testInfo) {
    final int initPort = 3344;
    List<NetworkAddress> addresses = findLocalAddresses(initPort, initPort + 5);
    var nodeFinder = new StaticNodeFinder(addresses);
    services = addresses.stream().map(addr -> startNetwork(testInfo, addr, nodeFinder)).collect(// ensure mutability
    Collectors.toCollection(ArrayList::new));
    for (ClusterService service : services) {
        assertTrue(waitForTopology(service, 5, 5_000), service.topologyService().localMember().toString() + ", topSize=" + service.topologyService().allMembers().size());
    }
    int idx0 = 0;
    int idx1 = 2;
    LOG.info("Shutdown {}", addresses.get(idx0));
    services.get(idx0).stop();
    LOG.info("Shutdown {}", addresses.get(idx1));
    services.get(idx1).stop();
    LOG.info("Starting {}", addresses.get(idx0));
    ClusterService svc0 = startNetwork(testInfo, addresses.get(idx0), nodeFinder);
    services.set(idx0, svc0);
    LOG.info("Starting {}", addresses.get(idx1));
    ClusterService svc2 = startNetwork(testInfo, addresses.get(idx1), nodeFinder);
    services.set(idx1, svc2);
    for (ClusterService service : services) {
        assertTrue(waitForTopology(service, 5, 10_000), service.topologyService().localMember().toString() + ", topSize=" + service.topologyService().allMembers().size());
    }
    LOG.info("Reached stable state");
}
Also used : ClusterService(org.apache.ignite.network.ClusterService) NetworkAddress(org.apache.ignite.network.NetworkAddress) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 4 with StaticNodeFinder

use of org.apache.ignite.network.StaticNodeFinder 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 5 with StaticNodeFinder

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

the class ItClusterServiceTest method testShutdown.

@Test
void testShutdown(TestInfo testInfo) {
    var addr = new NetworkAddress("localhost", 10000);
    ClusterService service = clusterService(testInfo, addr.port(), new StaticNodeFinder(List.of(addr)), new TestScaleCubeClusterServiceFactory());
    service.start();
    service.stop();
    assertThat(service.isStopped(), is(true));
    ExecutionException e = assertThrows(ExecutionException.class, () -> service.messagingService().send(mock(ClusterNode.class), mock(NetworkMessage.class)).get(5, TimeUnit.SECONDS));
    assertThat(e.getCause(), isA(NodeStoppingException.class));
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) ClusterService(org.apache.ignite.network.ClusterService) NetworkAddress(org.apache.ignite.network.NetworkAddress) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) ExecutionException(java.util.concurrent.ExecutionException) NetworkMessage(org.apache.ignite.network.NetworkMessage) Test(org.junit.jupiter.api.Test)

Aggregations

StaticNodeFinder (org.apache.ignite.network.StaticNodeFinder)15 ClusterService (org.apache.ignite.network.ClusterService)11 NetworkAddress (org.apache.ignite.network.NetworkAddress)10 TestScaleCubeClusterServiceFactory (org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory)9 BeforeEach (org.junit.jupiter.api.BeforeEach)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)4 NamedThreadFactory (org.apache.ignite.internal.thread.NamedThreadFactory)4 Map (java.util.Map)3 TimeUnit (java.util.concurrent.TimeUnit)3 Collectors (java.util.stream.Collectors)3 Loza (org.apache.ignite.internal.raft.Loza)3 IgniteUtils (org.apache.ignite.internal.util.IgniteUtils)3 Peer (org.apache.ignite.raft.client.Peer)3 RaftGroupService (org.apache.ignite.raft.client.service.RaftGroupService)3 NodeManager (org.apache.ignite.raft.jraft.NodeManager)3 RaftMessagesFactory (org.apache.ignite.raft.jraft.RaftMessagesFactory)3 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)3 NodeOptions (org.apache.ignite.raft.jraft.option.NodeOptions)3