All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.camunda.zeebe.broker.bootstrap.ClusterConfigurationManagerStep Maven / Gradle / Ivy

There is a newer version: 8.7.0-alpha1
Show newest version
/*
 * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
 * one or more contributor license agreements. See the NOTICE file distributed
 * with this work for additional information regarding copyright ownership.
 * Licensed under the Camunda License 1.0. You may not use this file
 * except in compliance with the Camunda License 1.0.
 */
package io.camunda.zeebe.broker.bootstrap;

import io.camunda.zeebe.broker.partitioning.topology.ClusterConfigurationService;
import io.camunda.zeebe.broker.partitioning.topology.DynamicClusterConfigurationService;
import io.camunda.zeebe.scheduler.future.ActorFuture;

public class ClusterConfigurationManagerStep
    implements io.camunda.zeebe.scheduler.startup.StartupStep {

  @Override
  public String getName() {
    return "Cluster Topology Manager";
  }

  @Override
  public ActorFuture startup(
      final BrokerStartupContext brokerStartupContext) {
    final ActorFuture started =
        brokerStartupContext.getConcurrencyControl().createFuture();

    final ClusterConfigurationService clusterConfigurationService =
        new DynamicClusterConfigurationService();
    clusterConfigurationService
        .start(brokerStartupContext)
        .onComplete(
            (ignore, error) -> {
              if (error == null) {
                brokerStartupContext.setClusterConfigurationService(clusterConfigurationService);
                started.complete(brokerStartupContext);
              } else {
                started.completeExceptionally(error);
              }
            });

    return started;
  }

  @Override
  public ActorFuture shutdown(
      final BrokerStartupContext brokerStartupContext) {
    final ActorFuture stopFuture =
        brokerStartupContext.getConcurrencyControl().createFuture();
    final var clusterTopologyService = brokerStartupContext.getClusterConfigurationService();
    if (clusterTopologyService != null) {
      clusterTopologyService
          .closeAsync()
          .onComplete(
              (ignore, error) -> {
                if (error == null) {
                  brokerStartupContext.setClusterConfigurationService(null);
                  stopFuture.complete(brokerStartupContext);
                } else {
                  stopFuture.completeExceptionally(error);
                }
              });
    } else {
      stopFuture.complete(brokerStartupContext);
    }
    return stopFuture;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy