use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.
the class ItJraftCounterServerTest method startServer.
/**
* Starts server.
*
* @param idx The index.
* @param clo Init closure.
* @param cons Node options updater.
*
* @return Raft server instance.
*/
private JraftServerImpl startServer(int idx, Consumer<RaftServer> clo, Consumer<NodeOptions> cons) {
var addr = new NetworkAddress(getLocalAddress(), PORT);
ClusterService service = clusterService(PORT + idx, List.of(addr), true);
NodeOptions opts = new NodeOptions();
cons.accept(opts);
JraftServerImpl server = new JraftServerImpl(service, dataPath, opts) {
@Override
public void stop() {
servers.remove(this);
super.stop();
service.stop();
}
};
server.start();
clo.accept(server);
servers.add(server);
assertTrue(waitForTopology(service, servers.size(), 15_000));
return server;
}
use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.
the class ItSimpleCounterServerTest method before.
/**
* Before each.
*/
@BeforeEach
void before() throws Exception {
LOG.info(">>>> Starting test {}", testInfo.getTestMethod().orElseThrow().getName());
var addr = new NetworkAddress("localhost", PORT);
ClusterService service = clusterService(PORT, List.of(addr), true);
server = new JraftServerImpl(service, dataPath) {
@Override
public synchronized void stop() {
super.stop();
service.stop();
}
};
server.start();
ClusterNode serverNode = server.clusterService().topologyService().localMember();
assertTrue(server.startRaftGroup(COUNTER_GROUP_ID_0, new CounterListener(), List.of(new Peer(serverNode.address()))));
assertTrue(server.startRaftGroup(COUNTER_GROUP_ID_1, new CounterListener(), List.of(new Peer(serverNode.address()))));
ClusterService clientNode1 = clusterService(PORT + 1, List.of(addr), true);
executor = new ScheduledThreadPoolExecutor(20, new NamedThreadFactory(Loza.CLIENT_POOL_NAME));
client1 = RaftGroupServiceImpl.start(COUNTER_GROUP_ID_0, clientNode1, FACTORY, 1000, List.of(new Peer(serverNode.address())), false, 200, executor).get(3, TimeUnit.SECONDS);
ClusterService clientNode2 = clusterService(PORT + 2, List.of(addr), true);
client2 = RaftGroupServiceImpl.start(COUNTER_GROUP_ID_1, clientNode2, FACTORY, 1000, List.of(new Peer(serverNode.address())), false, 200, executor).get(3, TimeUnit.SECONDS);
assertTrue(waitForTopology(service, 3, 1000));
assertTrue(waitForTopology(clientNode1, 3, 1000));
assertTrue(waitForTopology(clientNode2, 3, 1000));
}
use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.
the class JraftServerImpl method startRaftGroup.
/**
* {@inheritDoc}
*/
@Override
public synchronized boolean startRaftGroup(String groupId, RaftGroupListener lsnr, @Nullable List<Peer> initialConf) {
if (groups.containsKey(groupId)) {
return false;
}
// Thread pools are shared by all raft groups.
NodeOptions nodeOptions = opts.copy();
Path serverDataPath = getServerDataPath(groupId);
try {
Files.createDirectories(serverDataPath);
} catch (IOException e) {
throw new IgniteInternalException(e);
}
nodeOptions.setLogUri(serverDataPath.resolve("logs").toString());
nodeOptions.setRaftMetaUri(serverDataPath.resolve("meta").toString());
nodeOptions.setSnapshotUri(serverDataPath.resolve("snapshot").toString());
nodeOptions.setFsm(new DelegatingStateMachine(lsnr));
if (initialConf != null) {
List<PeerId> mapped = initialConf.stream().map(PeerId::fromPeer).collect(Collectors.toList());
nodeOptions.setInitialConf(new Configuration(mapped, null));
}
IgniteRpcClient client = new IgniteRpcClient(service);
nodeOptions.setRpcClient(client);
NetworkAddress addr = service.topologyService().localMember().address();
var peerId = new PeerId(addr.host(), addr.port(), 0, ElectionPriority.DISABLED);
var server = new RaftGroupService(groupId, peerId, nodeOptions, rpcServer, nodeManager);
server.start();
groups.put(groupId, server);
return true;
}
use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.
the class ItAbstractListenerSnapshotTest method startServer.
/**
* Starts a raft server.
*
* @param testInfo Test info.
* @param idx Server index (affects port of the server).
* @return Server.
*/
private JraftServerImpl startServer(TestInfo testInfo, int idx) {
var addr = new NetworkAddress(getLocalAddress(), PORT);
ClusterService service = clusterService(testInfo, PORT + idx, addr);
Path jraft = workDir.resolve("jraft" + idx);
JraftServerImpl server = new JraftServerImpl(service, jraft) {
@Override
public void stop() {
super.stop();
service.stop();
}
};
server.start();
Path listenerPersistencePath = workDir.resolve("db" + idx);
servers.add(server);
server.startRaftGroup(raftGroupId(), createListener(service, listenerPersistencePath), INITIAL_CONF);
return server;
}
use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.
the class ScaleCubeDirectMarshallerTransport method send.
/**
* {@inheritDoc}
*/
@Override
public Mono<Void> send(Address address, Message message) {
var addr = InetSocketAddress.createUnresolved(address.host(), address.port());
return Mono.fromFuture(() -> {
NetworkAddress networkAddress = NetworkAddress.from(addr);
ClusterNode node = topologyService.getByAddress(networkAddress);
if (node == null) {
node = new ClusterNode(null, null, networkAddress);
}
return messagingService.send(node, fromMessage(message));
});
}
Aggregations