use of io.atomix.cluster.AtomixCluster in project zeebe by camunda.
the class RaftRolesTest method startPartitionManagerWithPartitionConsumer.
private CompletableFuture<Void> startPartitionManagerWithPartitionConsumer(final int nodeId, final int partitionCount, final List<Integer> nodeIds, final Consumer<? super Partition> partitionConsumer) {
final List<String> memberIds = nodeIds.stream().map(Object::toString).collect(Collectors.toList());
final RaftPartitionGroup partitionGroup = RaftPartitionGroup.builder("normal").withNumPartitions(partitionCount).withPartitionSize(memberIds.size()).withPriorityElection(false).withMembers(memberIds).withDataDirectory(new File(new File(atomixClusterRule.getDataDir(), "log"), "" + nodeId)).withSnapshotStoreFactory(new NoopSnapshotStoreFactory()).build();
final var atomixFuture = atomixClusterRule.startAtomix(nodeId, nodeIds, AtomixClusterBuilder::build);
final AtomixCluster atomix;
try {
atomix = atomixFuture.get();
final var partitionService = new DefaultPartitionService(atomix.getMembershipService(), atomix.getCommunicationService(), partitionGroup);
partitionGroup.getPartitions().forEach(partitionConsumer);
return partitionService.start().thenApply(ps -> null);
} catch (final InterruptedException | ExecutionException e) {
LangUtil.rethrowUnchecked(e);
// won't be executed
return null;
}
}
use of io.atomix.cluster.AtomixCluster in project zeebe by camunda.
the class ClusteringRule method createGateway.
private Gateway createGateway() {
final String contactPoint = NetUtil.toSocketAddressString(getBrokerCfg(0).getNetwork().getInternalApi().getAddress());
final GatewayCfg gatewayCfg = new GatewayCfg();
gatewayCfg.getCluster().setContactPoint(contactPoint).setClusterName(clusterName);
gatewayCfg.getNetwork().setPort(SocketUtil.getNextAddress().getPort());
gatewayCfg.getCluster().setPort(SocketUtil.getNextAddress().getPort());
// temporarily increase request time out, but we should make this configurable per test
gatewayCfg.getCluster().setRequestTimeout(Duration.ofSeconds(45));
gatewayCfg.init();
gatewayConfigurator.accept(gatewayCfg);
final ClusterCfg clusterCfg = gatewayCfg.getCluster();
// copied from StandaloneGateway
final AtomixCluster atomixCluster = new AtomixClusterBuilder(new ClusterConfig()).withMemberId(clusterCfg.getMemberId()).withAddress(Address.from(clusterCfg.getHost(), clusterCfg.getPort())).withClusterId(clusterCfg.getClusterName()).withMembershipProvider(BootstrapDiscoveryProvider.builder().withNodes(Address.from(clusterCfg.getContactPoint())).build()).withMembershipProtocol(SwimMembershipProtocol.builder().withSyncInterval(Duration.ofSeconds(1)).build()).withMessageCompression(gatewayCfg.getCluster().getMessageCompression()).build();
atomixCluster.start().join();
final ActorScheduler actorScheduler = ActorScheduler.newActorScheduler().setCpuBoundActorThreadCount(1).build();
actorScheduler.start();
final Gateway gateway = new Gateway(gatewayCfg, atomixCluster.getMessagingService(), atomixCluster.getMembershipService(), atomixCluster.getEventService(), actorScheduler);
closeables.manage(gateway::stop);
closeables.manage(atomixCluster::stop);
closeables.manage(actorScheduler::stop);
return gateway;
}
use of io.atomix.cluster.AtomixCluster in project zeebe by camunda.
the class CommandApiRule method fetchAtomix.
private AtomixCluster fetchAtomix() {
final AtomixCluster atomixCluster = atomixSupplier.get();
Objects.requireNonNull(atomixCluster);
return atomixCluster;
}
use of io.atomix.cluster.AtomixCluster in project zeebe by zeebe-io.
the class RaftRolesTest method startPartitionManagerWithPartitionConsumer.
private CompletableFuture<Void> startPartitionManagerWithPartitionConsumer(final int nodeId, final int partitionCount, final List<Integer> nodeIds, final Consumer<? super Partition> partitionConsumer) {
final List<String> memberIds = nodeIds.stream().map(Object::toString).collect(Collectors.toList());
final RaftPartitionGroup partitionGroup = RaftPartitionGroup.builder("normal").withNumPartitions(partitionCount).withPartitionSize(memberIds.size()).withPriorityElection(false).withMembers(memberIds).withDataDirectory(new File(new File(atomixClusterRule.getDataDir(), "log"), "" + nodeId)).withSnapshotStoreFactory(new NoopSnapshotStoreFactory()).build();
final var atomixFuture = atomixClusterRule.startAtomix(nodeId, nodeIds, AtomixClusterBuilder::build);
final AtomixCluster atomix;
try {
atomix = atomixFuture.get();
final var partitionService = new DefaultPartitionService(atomix.getMembershipService(), atomix.getCommunicationService(), partitionGroup);
partitionGroup.getPartitions().forEach(partitionConsumer);
return partitionService.start().thenApply(ps -> null);
} catch (final InterruptedException | ExecutionException e) {
LangUtil.rethrowUnchecked(e);
// won't be executed
return null;
}
}
use of io.atomix.cluster.AtomixCluster in project zeebe by zeebe-io.
the class ClusteringRule method createGateway.
private Gateway createGateway() {
final String contactPoint = NetUtil.toSocketAddressString(getBrokerCfg(0).getNetwork().getInternalApi().getAddress());
final GatewayCfg gatewayCfg = new GatewayCfg();
gatewayCfg.getCluster().setContactPoint(contactPoint).setClusterName(clusterName);
gatewayCfg.getNetwork().setPort(SocketUtil.getNextAddress().getPort());
gatewayCfg.getCluster().setPort(SocketUtil.getNextAddress().getPort());
// temporarily increase request time out, but we should make this configurable per test
gatewayCfg.getCluster().setRequestTimeout(Duration.ofSeconds(45));
gatewayCfg.init();
gatewayConfigurator.accept(gatewayCfg);
final ClusterCfg clusterCfg = gatewayCfg.getCluster();
// copied from StandaloneGateway
final AtomixCluster atomixCluster = new AtomixClusterBuilder(new ClusterConfig()).withMemberId(clusterCfg.getMemberId()).withAddress(Address.from(clusterCfg.getHost(), clusterCfg.getPort())).withClusterId(clusterCfg.getClusterName()).withMembershipProvider(BootstrapDiscoveryProvider.builder().withNodes(Address.from(clusterCfg.getContactPoint())).build()).withMembershipProtocol(SwimMembershipProtocol.builder().withSyncInterval(Duration.ofSeconds(1)).build()).withMessageCompression(gatewayCfg.getCluster().getMessageCompression()).build();
atomixCluster.start().join();
final ActorScheduler actorScheduler = ActorScheduler.newActorScheduler().setCpuBoundActorThreadCount(1).build();
actorScheduler.start();
final Gateway gateway = new Gateway(gatewayCfg, atomixCluster.getMessagingService(), atomixCluster.getMembershipService(), atomixCluster.getEventService(), actorScheduler);
closeables.manage(gateway::stop);
closeables.manage(atomixCluster::stop);
closeables.manage(actorScheduler::stop);
return gateway;
}
Aggregations