Search in sources :

Example 1 with AtomixClusterBuilder

use of io.atomix.cluster.AtomixClusterBuilder in project zeebe by camunda.

the class AtomixClusterFactory method fromConfiguration.

public static AtomixCluster fromConfiguration(final BrokerCfg configuration) {
    final var clusterCfg = configuration.getCluster();
    final var nodeId = clusterCfg.getNodeId();
    final var localMemberId = Integer.toString(nodeId);
    final var networkCfg = configuration.getNetwork();
    final var discoveryProvider = createDiscoveryProvider(clusterCfg, localMemberId);
    final var membershipCfg = clusterCfg.getMembership();
    final var membershipProtocol = SwimMembershipProtocol.builder().withFailureTimeout(membershipCfg.getFailureTimeout()).withGossipInterval(membershipCfg.getGossipInterval()).withProbeInterval(membershipCfg.getProbeInterval()).withProbeTimeout(membershipCfg.getProbeTimeout()).withBroadcastDisputes(membershipCfg.isBroadcastDisputes()).withBroadcastUpdates(membershipCfg.isBroadcastUpdates()).withGossipFanout(membershipCfg.getGossipFanout()).withNotifySuspect(membershipCfg.isNotifySuspect()).withSuspectProbes(membershipCfg.getSuspectProbes()).withSyncInterval(membershipCfg.getSyncInterval()).build();
    final var atomixBuilder = new AtomixClusterBuilder(new ClusterConfig()).withClusterId(clusterCfg.getClusterName()).withMemberId(localMemberId).withMembershipProtocol(membershipProtocol).withMessagingInterface(networkCfg.getInternalApi().getHost()).withMessagingPort(networkCfg.getInternalApi().getPort()).withAddress(Address.from(networkCfg.getInternalApi().getAdvertisedHost(), networkCfg.getInternalApi().getAdvertisedPort())).withMembershipProvider(discoveryProvider).withMessageCompression(clusterCfg.getMessageCompression());
    final var securityCfg = networkCfg.getSecurity();
    if (securityCfg.isEnabled()) {
        atomixBuilder.withSecurity(securityCfg.getCertificateChainPath(), securityCfg.getPrivateKeyPath());
    }
    return atomixBuilder.build();
}
Also used : AtomixClusterBuilder(io.atomix.cluster.AtomixClusterBuilder) ClusterConfig(io.atomix.cluster.ClusterConfig)

Example 2 with AtomixClusterBuilder

use of io.atomix.cluster.AtomixClusterBuilder 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;
    }
}
Also used : DefaultPartitionService(io.atomix.primitive.partition.impl.DefaultPartitionService) RaftPartitionGroup(io.atomix.raft.partition.RaftPartitionGroup) AtomixClusterBuilder(io.atomix.cluster.AtomixClusterBuilder) ExecutionException(java.util.concurrent.ExecutionException) File(java.io.File) NoopSnapshotStoreFactory(io.atomix.cluster.NoopSnapshotStoreFactory) AtomixCluster(io.atomix.cluster.AtomixCluster)

Example 3 with AtomixClusterBuilder

use of io.atomix.cluster.AtomixClusterBuilder 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;
}
Also used : ActorScheduler(io.camunda.zeebe.util.sched.ActorScheduler) AtomixClusterBuilder(io.atomix.cluster.AtomixClusterBuilder) Gateway(io.camunda.zeebe.gateway.Gateway) GatewayCfg(io.camunda.zeebe.gateway.impl.configuration.GatewayCfg) ClusterCfg(io.camunda.zeebe.gateway.impl.configuration.ClusterCfg) AtomixCluster(io.atomix.cluster.AtomixCluster) ClusterConfig(io.atomix.cluster.ClusterConfig)

Example 4 with AtomixClusterBuilder

use of io.atomix.cluster.AtomixClusterBuilder 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;
    }
}
Also used : DefaultPartitionService(io.atomix.primitive.partition.impl.DefaultPartitionService) RaftPartitionGroup(io.atomix.raft.partition.RaftPartitionGroup) AtomixClusterBuilder(io.atomix.cluster.AtomixClusterBuilder) ExecutionException(java.util.concurrent.ExecutionException) File(java.io.File) NoopSnapshotStoreFactory(io.atomix.cluster.NoopSnapshotStoreFactory) AtomixCluster(io.atomix.cluster.AtomixCluster)

Example 5 with AtomixClusterBuilder

use of io.atomix.cluster.AtomixClusterBuilder 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;
}
Also used : ActorScheduler(io.camunda.zeebe.util.sched.ActorScheduler) AtomixClusterBuilder(io.atomix.cluster.AtomixClusterBuilder) Gateway(io.camunda.zeebe.gateway.Gateway) GatewayCfg(io.camunda.zeebe.gateway.impl.configuration.GatewayCfg) ClusterCfg(io.camunda.zeebe.gateway.impl.configuration.ClusterCfg) AtomixCluster(io.atomix.cluster.AtomixCluster) ClusterConfig(io.atomix.cluster.ClusterConfig)

Aggregations

AtomixClusterBuilder (io.atomix.cluster.AtomixClusterBuilder)9 AtomixCluster (io.atomix.cluster.AtomixCluster)6 ClusterConfig (io.atomix.cluster.ClusterConfig)6 NoopSnapshotStoreFactory (io.atomix.cluster.NoopSnapshotStoreFactory)3 DefaultPartitionService (io.atomix.primitive.partition.impl.DefaultPartitionService)3 RaftPartitionGroup (io.atomix.raft.partition.RaftPartitionGroup)3 Gateway (io.camunda.zeebe.gateway.Gateway)3 ClusterCfg (io.camunda.zeebe.gateway.impl.configuration.ClusterCfg)3 GatewayCfg (io.camunda.zeebe.gateway.impl.configuration.GatewayCfg)3 ActorScheduler (io.camunda.zeebe.util.sched.ActorScheduler)3 File (java.io.File)3 ExecutionException (java.util.concurrent.ExecutionException)3