Search in sources :

Example 1 with KafkaRebalanceMode

use of io.strimzi.api.kafka.model.balancing.KafkaRebalanceMode in project strimzi by strimzi.

the class KafkaRebalanceAssemblyOperator method convertRebalanceSpecToRebalanceOptions.

/* test */
AbstractRebalanceOptions.AbstractRebalanceOptionsBuilder<?, ?> convertRebalanceSpecToRebalanceOptions(KafkaRebalanceSpec kafkaRebalanceSpec) {
    AbstractRebalanceOptions.AbstractRebalanceOptionsBuilder<?, ?> rebalanceOptionsBuilder;
    // backward compatibility, no mode specified means "full"
    KafkaRebalanceMode mode = Optional.ofNullable(kafkaRebalanceSpec).map(kr -> kr.getMode()).orElse(KafkaRebalanceMode.FULL);
    List<Integer> brokers = Optional.ofNullable(kafkaRebalanceSpec).map(kr -> kr.getBrokers()).orElse(null);
    switch(mode) {
        case ADD_BROKERS:
            rebalanceOptionsBuilder = new AddBrokerOptions.AddBrokerOptionsBuilder();
            if (brokers != null && !brokers.isEmpty()) {
                ((AddBrokerOptions.AddBrokerOptionsBuilder) rebalanceOptionsBuilder).withBrokers(brokers);
            } else {
                throw new IllegalArgumentException("The brokers list is mandatory when using the " + mode.toValue() + " rebalancing mode");
            }
            break;
        case REMOVE_BROKERS:
            rebalanceOptionsBuilder = new RemoveBrokerOptions.RemoveBrokerOptionsBuilder();
            if (brokers != null && !brokers.isEmpty()) {
                ((RemoveBrokerOptions.RemoveBrokerOptionsBuilder) rebalanceOptionsBuilder).withBrokers(brokers);
            } else {
                throw new IllegalArgumentException("The brokers list is mandatory when using the " + mode.toValue() + " rebalancing mode");
            }
            break;
        default:
            rebalanceOptionsBuilder = new RebalanceOptions.RebalanceOptionsBuilder();
            if (kafkaRebalanceSpec.isRebalanceDisk()) {
                ((RebalanceOptions.RebalanceOptionsBuilder) rebalanceOptionsBuilder).withRebalanceDisk();
            }
            if (kafkaRebalanceSpec.getConcurrentIntraBrokerPartitionMovements() > 0) {
                ((RebalanceOptions.RebalanceOptionsBuilder) rebalanceOptionsBuilder).withConcurrentIntraPartitionMovements(kafkaRebalanceSpec.getConcurrentIntraBrokerPartitionMovements());
            }
            if (brokers != null && !brokers.isEmpty()) {
                LOGGER.warnOp("The {} mode is used. The specified list of brokers is ignored", mode.toValue());
            }
            break;
    }
    if (kafkaRebalanceSpec.getGoals() != null) {
        rebalanceOptionsBuilder.withGoals(kafkaRebalanceSpec.getGoals());
    }
    if (kafkaRebalanceSpec.isSkipHardGoalCheck()) {
        rebalanceOptionsBuilder.withSkipHardGoalCheck();
    }
    if (kafkaRebalanceSpec.getExcludedTopics() != null) {
        rebalanceOptionsBuilder.withExcludedTopics(kafkaRebalanceSpec.getExcludedTopics());
    }
    if (kafkaRebalanceSpec.getConcurrentPartitionMovementsPerBroker() > 0) {
        rebalanceOptionsBuilder.withConcurrentPartitionMovementsPerBroker(kafkaRebalanceSpec.getConcurrentPartitionMovementsPerBroker());
    }
    if (kafkaRebalanceSpec.getConcurrentLeaderMovements() > 0) {
        rebalanceOptionsBuilder.withConcurrentLeaderMovements(kafkaRebalanceSpec.getConcurrentLeaderMovements());
    }
    if (kafkaRebalanceSpec.getReplicationThrottle() > 0) {
        rebalanceOptionsBuilder.withReplicationThrottle(kafkaRebalanceSpec.getReplicationThrottle());
    }
    if (kafkaRebalanceSpec.getReplicaMovementStrategies() != null) {
        rebalanceOptionsBuilder.withReplicaMovementStrategies(kafkaRebalanceSpec.getReplicaMovementStrategies());
    }
    return rebalanceOptionsBuilder;
}
Also used : Arrays(java.util.Arrays) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) ANNO_STRIMZI_IO_REBALANCE(io.strimzi.operator.common.Annotations.ANNO_STRIMZI_IO_REBALANCE) Watcher(io.fabric8.kubernetes.client.Watcher) Annotations(io.strimzi.operator.common.Annotations) CruiseControlConfiguration(io.strimzi.operator.cluster.model.CruiseControlConfiguration) AbstractRebalanceOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.AbstractRebalanceOptions) Resource(io.fabric8.kubernetes.client.dsl.Resource) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CruiseControlRebalanceResponse(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRebalanceResponse) Map(java.util.Map) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) JsonObject(io.vertx.core.json.JsonObject) CruiseControlRebalanceKeys(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRebalanceKeys) ModelUtils(io.strimzi.operator.cluster.model.ModelUtils) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) AbstractOperator(io.strimzi.operator.common.AbstractOperator) StatusUtils(io.strimzi.operator.common.operator.resource.StatusUtils) KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) Set(java.util.Set) KafkaRebalanceList(io.strimzi.api.kafka.KafkaRebalanceList) KafkaRebalanceAnnotation(io.strimzi.api.kafka.model.balancing.KafkaRebalanceAnnotation) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) NoSuchResourceException(io.strimzi.operator.cluster.model.NoSuchResourceException) CruiseControlUserTaskStatus(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlUserTaskStatus) KafkaRebalanceStatusBuilder(io.strimzi.api.kafka.model.status.KafkaRebalanceStatusBuilder) CruiseControlResources(io.strimzi.api.kafka.model.CruiseControlResources) AddBrokerOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.AddBrokerOptions) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) Stream(java.util.stream.Stream) CruiseControlApi(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApi) Secret(io.fabric8.kubernetes.api.model.Secret) Optional(java.util.Optional) Condition(io.strimzi.api.kafka.model.status.Condition) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) KafkaList(io.strimzi.api.kafka.KafkaList) KafkaRebalanceState(io.strimzi.api.kafka.model.balancing.KafkaRebalanceState) KafkaRebalanceBuilder(io.strimzi.api.kafka.model.KafkaRebalanceBuilder) HashMap(java.util.HashMap) CruiseControlApiImpl(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl) KafkaRebalanceSpec(io.strimzi.api.kafka.model.KafkaRebalanceSpec) ArrayList(java.util.ArrayList) KafkaRebalanceMode(io.strimzi.api.kafka.model.balancing.KafkaRebalanceMode) HashSet(java.util.HashSet) WatcherException(io.fabric8.kubernetes.client.WatcherException) CompositeFuture(io.vertx.core.CompositeFuture) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) RebalanceOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.RebalanceOptions) CruiseControl(io.strimzi.operator.cluster.model.CruiseControl) JbodStorage(io.strimzi.api.kafka.model.storage.JbodStorage) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) InvalidResourceException(io.strimzi.operator.cluster.model.InvalidResourceException) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) CruiseControlLoadParameters(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlLoadParameters) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KafkaRebalanceStatus(io.strimzi.api.kafka.model.status.KafkaRebalanceStatus) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) Reconciliation(io.strimzi.operator.common.Reconciliation) JsonArray(io.vertx.core.json.JsonArray) HTTP_DEFAULT_IDLE_TIMEOUT_SECONDS(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl.HTTP_DEFAULT_IDLE_TIMEOUT_SECONDS) StatusDiff(io.strimzi.operator.cluster.model.StatusDiff) Util(io.strimzi.operator.common.Util) RemoveBrokerOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.RemoveBrokerOptions) AbstractWatchableStatusedResourceOperator(io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Kafka(io.strimzi.api.kafka.model.Kafka) CruiseControlRestException(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRestException) Collections(java.util.Collections) AddBrokerOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.AddBrokerOptions) AbstractRebalanceOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.AbstractRebalanceOptions) KafkaRebalanceMode(io.strimzi.api.kafka.model.balancing.KafkaRebalanceMode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RemoveBrokerOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.RemoveBrokerOptions) AbstractRebalanceOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.AbstractRebalanceOptions) RebalanceOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.RebalanceOptions)

Example 2 with KafkaRebalanceMode

use of io.strimzi.api.kafka.model.balancing.KafkaRebalanceMode in project strimzi by strimzi.

the class KafkaRebalanceAssemblyOperator method requestRebalance.

private Future<MapAndStatus<ConfigMap, KafkaRebalanceStatus>> requestRebalance(Reconciliation reconciliation, String host, CruiseControlApi apiClient, KafkaRebalance kafkaRebalance, boolean dryrun, AbstractRebalanceOptions.AbstractRebalanceOptionsBuilder<?, ?> rebalanceOptionsBuilder, String userTaskID) {
    LOGGER.infoCr(reconciliation, "Requesting Cruise Control rebalance [dryrun={}]", dryrun);
    rebalanceOptionsBuilder.withVerboseResponse();
    if (!dryrun) {
        rebalanceOptionsBuilder.withFullRun();
    }
    // backward compatibility, no mode specified means "full"
    KafkaRebalanceMode mode = Optional.ofNullable(kafkaRebalance.getSpec()).map(spec -> spec.getMode()).orElse(KafkaRebalanceMode.FULL);
    Future<CruiseControlRebalanceResponse> future;
    switch(mode) {
        case ADD_BROKERS:
            future = apiClient.addBroker(host, CruiseControl.REST_API_PORT, ((AddBrokerOptions.AddBrokerOptionsBuilder) rebalanceOptionsBuilder).build(), userTaskID);
            break;
        case REMOVE_BROKERS:
            future = apiClient.removeBroker(host, CruiseControl.REST_API_PORT, ((RemoveBrokerOptions.RemoveBrokerOptionsBuilder) rebalanceOptionsBuilder).build(), userTaskID);
            break;
        default:
            future = apiClient.rebalance(host, CruiseControl.REST_API_PORT, ((RebalanceOptions.RebalanceOptionsBuilder) rebalanceOptionsBuilder).build(), userTaskID);
            break;
    }
    return future.map(response -> handleRebalanceResponse(reconciliation, kafkaRebalance, dryrun, response));
}
Also used : Arrays(java.util.Arrays) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) ANNO_STRIMZI_IO_REBALANCE(io.strimzi.operator.common.Annotations.ANNO_STRIMZI_IO_REBALANCE) Watcher(io.fabric8.kubernetes.client.Watcher) Annotations(io.strimzi.operator.common.Annotations) CruiseControlConfiguration(io.strimzi.operator.cluster.model.CruiseControlConfiguration) AbstractRebalanceOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.AbstractRebalanceOptions) Resource(io.fabric8.kubernetes.client.dsl.Resource) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CruiseControlRebalanceResponse(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRebalanceResponse) Map(java.util.Map) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) JsonObject(io.vertx.core.json.JsonObject) CruiseControlRebalanceKeys(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRebalanceKeys) ModelUtils(io.strimzi.operator.cluster.model.ModelUtils) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) AbstractOperator(io.strimzi.operator.common.AbstractOperator) StatusUtils(io.strimzi.operator.common.operator.resource.StatusUtils) KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) Set(java.util.Set) KafkaRebalanceList(io.strimzi.api.kafka.KafkaRebalanceList) KafkaRebalanceAnnotation(io.strimzi.api.kafka.model.balancing.KafkaRebalanceAnnotation) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) NoSuchResourceException(io.strimzi.operator.cluster.model.NoSuchResourceException) CruiseControlUserTaskStatus(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlUserTaskStatus) KafkaRebalanceStatusBuilder(io.strimzi.api.kafka.model.status.KafkaRebalanceStatusBuilder) CruiseControlResources(io.strimzi.api.kafka.model.CruiseControlResources) AddBrokerOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.AddBrokerOptions) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) Stream(java.util.stream.Stream) CruiseControlApi(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApi) Secret(io.fabric8.kubernetes.api.model.Secret) Optional(java.util.Optional) Condition(io.strimzi.api.kafka.model.status.Condition) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) KafkaList(io.strimzi.api.kafka.KafkaList) KafkaRebalanceState(io.strimzi.api.kafka.model.balancing.KafkaRebalanceState) KafkaRebalanceBuilder(io.strimzi.api.kafka.model.KafkaRebalanceBuilder) HashMap(java.util.HashMap) CruiseControlApiImpl(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl) KafkaRebalanceSpec(io.strimzi.api.kafka.model.KafkaRebalanceSpec) ArrayList(java.util.ArrayList) KafkaRebalanceMode(io.strimzi.api.kafka.model.balancing.KafkaRebalanceMode) HashSet(java.util.HashSet) WatcherException(io.fabric8.kubernetes.client.WatcherException) CompositeFuture(io.vertx.core.CompositeFuture) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) RebalanceOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.RebalanceOptions) CruiseControl(io.strimzi.operator.cluster.model.CruiseControl) JbodStorage(io.strimzi.api.kafka.model.storage.JbodStorage) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) InvalidResourceException(io.strimzi.operator.cluster.model.InvalidResourceException) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) CruiseControlLoadParameters(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlLoadParameters) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KafkaRebalanceStatus(io.strimzi.api.kafka.model.status.KafkaRebalanceStatus) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) Reconciliation(io.strimzi.operator.common.Reconciliation) JsonArray(io.vertx.core.json.JsonArray) HTTP_DEFAULT_IDLE_TIMEOUT_SECONDS(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl.HTTP_DEFAULT_IDLE_TIMEOUT_SECONDS) StatusDiff(io.strimzi.operator.cluster.model.StatusDiff) Util(io.strimzi.operator.common.Util) RemoveBrokerOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.RemoveBrokerOptions) AbstractWatchableStatusedResourceOperator(io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Kafka(io.strimzi.api.kafka.model.Kafka) CruiseControlRestException(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRestException) Collections(java.util.Collections) CruiseControlRebalanceResponse(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRebalanceResponse) KafkaRebalanceMode(io.strimzi.api.kafka.model.balancing.KafkaRebalanceMode)

Example 3 with KafkaRebalanceMode

use of io.strimzi.api.kafka.model.balancing.KafkaRebalanceMode in project strimzi-kafka-operator by strimzi.

the class KafkaRebalanceAssemblyOperator method requestRebalance.

private Future<MapAndStatus<ConfigMap, KafkaRebalanceStatus>> requestRebalance(Reconciliation reconciliation, String host, CruiseControlApi apiClient, KafkaRebalance kafkaRebalance, boolean dryrun, AbstractRebalanceOptions.AbstractRebalanceOptionsBuilder<?, ?> rebalanceOptionsBuilder, String userTaskID) {
    LOGGER.infoCr(reconciliation, "Requesting Cruise Control rebalance [dryrun={}]", dryrun);
    rebalanceOptionsBuilder.withVerboseResponse();
    if (!dryrun) {
        rebalanceOptionsBuilder.withFullRun();
    }
    // backward compatibility, no mode specified means "full"
    KafkaRebalanceMode mode = Optional.ofNullable(kafkaRebalance.getSpec()).map(spec -> spec.getMode()).orElse(KafkaRebalanceMode.FULL);
    Future<CruiseControlRebalanceResponse> future;
    switch(mode) {
        case ADD_BROKERS:
            future = apiClient.addBroker(host, CruiseControl.REST_API_PORT, ((AddBrokerOptions.AddBrokerOptionsBuilder) rebalanceOptionsBuilder).build(), userTaskID);
            break;
        case REMOVE_BROKERS:
            future = apiClient.removeBroker(host, CruiseControl.REST_API_PORT, ((RemoveBrokerOptions.RemoveBrokerOptionsBuilder) rebalanceOptionsBuilder).build(), userTaskID);
            break;
        default:
            future = apiClient.rebalance(host, CruiseControl.REST_API_PORT, ((RebalanceOptions.RebalanceOptionsBuilder) rebalanceOptionsBuilder).build(), userTaskID);
            break;
    }
    return future.map(response -> handleRebalanceResponse(reconciliation, kafkaRebalance, dryrun, response));
}
Also used : Arrays(java.util.Arrays) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) ANNO_STRIMZI_IO_REBALANCE(io.strimzi.operator.common.Annotations.ANNO_STRIMZI_IO_REBALANCE) Watcher(io.fabric8.kubernetes.client.Watcher) Annotations(io.strimzi.operator.common.Annotations) CruiseControlConfiguration(io.strimzi.operator.cluster.model.CruiseControlConfiguration) AbstractRebalanceOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.AbstractRebalanceOptions) Resource(io.fabric8.kubernetes.client.dsl.Resource) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CruiseControlRebalanceResponse(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRebalanceResponse) Map(java.util.Map) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) JsonObject(io.vertx.core.json.JsonObject) CruiseControlRebalanceKeys(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRebalanceKeys) ModelUtils(io.strimzi.operator.cluster.model.ModelUtils) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) AbstractOperator(io.strimzi.operator.common.AbstractOperator) StatusUtils(io.strimzi.operator.common.operator.resource.StatusUtils) KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) Set(java.util.Set) KafkaRebalanceList(io.strimzi.api.kafka.KafkaRebalanceList) KafkaRebalanceAnnotation(io.strimzi.api.kafka.model.balancing.KafkaRebalanceAnnotation) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) NoSuchResourceException(io.strimzi.operator.cluster.model.NoSuchResourceException) CruiseControlUserTaskStatus(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlUserTaskStatus) KafkaRebalanceStatusBuilder(io.strimzi.api.kafka.model.status.KafkaRebalanceStatusBuilder) CruiseControlResources(io.strimzi.api.kafka.model.CruiseControlResources) AddBrokerOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.AddBrokerOptions) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) Stream(java.util.stream.Stream) CruiseControlApi(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApi) Secret(io.fabric8.kubernetes.api.model.Secret) Optional(java.util.Optional) Condition(io.strimzi.api.kafka.model.status.Condition) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) KafkaList(io.strimzi.api.kafka.KafkaList) KafkaRebalanceState(io.strimzi.api.kafka.model.balancing.KafkaRebalanceState) KafkaRebalanceBuilder(io.strimzi.api.kafka.model.KafkaRebalanceBuilder) HashMap(java.util.HashMap) CruiseControlApiImpl(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl) KafkaRebalanceSpec(io.strimzi.api.kafka.model.KafkaRebalanceSpec) ArrayList(java.util.ArrayList) KafkaRebalanceMode(io.strimzi.api.kafka.model.balancing.KafkaRebalanceMode) HashSet(java.util.HashSet) WatcherException(io.fabric8.kubernetes.client.WatcherException) CompositeFuture(io.vertx.core.CompositeFuture) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) RebalanceOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.RebalanceOptions) CruiseControl(io.strimzi.operator.cluster.model.CruiseControl) JbodStorage(io.strimzi.api.kafka.model.storage.JbodStorage) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) InvalidResourceException(io.strimzi.operator.cluster.model.InvalidResourceException) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) CruiseControlLoadParameters(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlLoadParameters) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KafkaRebalanceStatus(io.strimzi.api.kafka.model.status.KafkaRebalanceStatus) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) Reconciliation(io.strimzi.operator.common.Reconciliation) JsonArray(io.vertx.core.json.JsonArray) HTTP_DEFAULT_IDLE_TIMEOUT_SECONDS(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl.HTTP_DEFAULT_IDLE_TIMEOUT_SECONDS) StatusDiff(io.strimzi.operator.cluster.model.StatusDiff) Util(io.strimzi.operator.common.Util) RemoveBrokerOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.RemoveBrokerOptions) AbstractWatchableStatusedResourceOperator(io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Kafka(io.strimzi.api.kafka.model.Kafka) CruiseControlRestException(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRestException) Collections(java.util.Collections) CruiseControlRebalanceResponse(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRebalanceResponse) KafkaRebalanceMode(io.strimzi.api.kafka.model.balancing.KafkaRebalanceMode)

Example 4 with KafkaRebalanceMode

use of io.strimzi.api.kafka.model.balancing.KafkaRebalanceMode in project strimzi-kafka-operator by strimzi.

the class KafkaRebalanceAssemblyOperator method convertRebalanceSpecToRebalanceOptions.

/* test */
AbstractRebalanceOptions.AbstractRebalanceOptionsBuilder<?, ?> convertRebalanceSpecToRebalanceOptions(KafkaRebalanceSpec kafkaRebalanceSpec) {
    AbstractRebalanceOptions.AbstractRebalanceOptionsBuilder<?, ?> rebalanceOptionsBuilder;
    // backward compatibility, no mode specified means "full"
    KafkaRebalanceMode mode = Optional.ofNullable(kafkaRebalanceSpec).map(kr -> kr.getMode()).orElse(KafkaRebalanceMode.FULL);
    List<Integer> brokers = Optional.ofNullable(kafkaRebalanceSpec).map(kr -> kr.getBrokers()).orElse(null);
    switch(mode) {
        case ADD_BROKERS:
            rebalanceOptionsBuilder = new AddBrokerOptions.AddBrokerOptionsBuilder();
            if (brokers != null && !brokers.isEmpty()) {
                ((AddBrokerOptions.AddBrokerOptionsBuilder) rebalanceOptionsBuilder).withBrokers(brokers);
            } else {
                throw new IllegalArgumentException("The brokers list is mandatory when using the " + mode.toValue() + " rebalancing mode");
            }
            break;
        case REMOVE_BROKERS:
            rebalanceOptionsBuilder = new RemoveBrokerOptions.RemoveBrokerOptionsBuilder();
            if (brokers != null && !brokers.isEmpty()) {
                ((RemoveBrokerOptions.RemoveBrokerOptionsBuilder) rebalanceOptionsBuilder).withBrokers(brokers);
            } else {
                throw new IllegalArgumentException("The brokers list is mandatory when using the " + mode.toValue() + " rebalancing mode");
            }
            break;
        default:
            rebalanceOptionsBuilder = new RebalanceOptions.RebalanceOptionsBuilder();
            if (kafkaRebalanceSpec.isRebalanceDisk()) {
                ((RebalanceOptions.RebalanceOptionsBuilder) rebalanceOptionsBuilder).withRebalanceDisk();
            }
            if (kafkaRebalanceSpec.getConcurrentIntraBrokerPartitionMovements() > 0) {
                ((RebalanceOptions.RebalanceOptionsBuilder) rebalanceOptionsBuilder).withConcurrentIntraPartitionMovements(kafkaRebalanceSpec.getConcurrentIntraBrokerPartitionMovements());
            }
            if (brokers != null && !brokers.isEmpty()) {
                LOGGER.warnOp("The {} mode is used. The specified list of brokers is ignored", mode.toValue());
            }
            break;
    }
    if (kafkaRebalanceSpec.getGoals() != null) {
        rebalanceOptionsBuilder.withGoals(kafkaRebalanceSpec.getGoals());
    }
    if (kafkaRebalanceSpec.isSkipHardGoalCheck()) {
        rebalanceOptionsBuilder.withSkipHardGoalCheck();
    }
    if (kafkaRebalanceSpec.getExcludedTopics() != null) {
        rebalanceOptionsBuilder.withExcludedTopics(kafkaRebalanceSpec.getExcludedTopics());
    }
    if (kafkaRebalanceSpec.getConcurrentPartitionMovementsPerBroker() > 0) {
        rebalanceOptionsBuilder.withConcurrentPartitionMovementsPerBroker(kafkaRebalanceSpec.getConcurrentPartitionMovementsPerBroker());
    }
    if (kafkaRebalanceSpec.getConcurrentLeaderMovements() > 0) {
        rebalanceOptionsBuilder.withConcurrentLeaderMovements(kafkaRebalanceSpec.getConcurrentLeaderMovements());
    }
    if (kafkaRebalanceSpec.getReplicationThrottle() > 0) {
        rebalanceOptionsBuilder.withReplicationThrottle(kafkaRebalanceSpec.getReplicationThrottle());
    }
    if (kafkaRebalanceSpec.getReplicaMovementStrategies() != null) {
        rebalanceOptionsBuilder.withReplicaMovementStrategies(kafkaRebalanceSpec.getReplicaMovementStrategies());
    }
    return rebalanceOptionsBuilder;
}
Also used : Arrays(java.util.Arrays) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) ANNO_STRIMZI_IO_REBALANCE(io.strimzi.operator.common.Annotations.ANNO_STRIMZI_IO_REBALANCE) Watcher(io.fabric8.kubernetes.client.Watcher) Annotations(io.strimzi.operator.common.Annotations) CruiseControlConfiguration(io.strimzi.operator.cluster.model.CruiseControlConfiguration) AbstractRebalanceOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.AbstractRebalanceOptions) Resource(io.fabric8.kubernetes.client.dsl.Resource) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CruiseControlRebalanceResponse(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRebalanceResponse) Map(java.util.Map) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) JsonObject(io.vertx.core.json.JsonObject) CruiseControlRebalanceKeys(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRebalanceKeys) ModelUtils(io.strimzi.operator.cluster.model.ModelUtils) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) AbstractOperator(io.strimzi.operator.common.AbstractOperator) StatusUtils(io.strimzi.operator.common.operator.resource.StatusUtils) KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) Set(java.util.Set) KafkaRebalanceList(io.strimzi.api.kafka.KafkaRebalanceList) KafkaRebalanceAnnotation(io.strimzi.api.kafka.model.balancing.KafkaRebalanceAnnotation) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) NoSuchResourceException(io.strimzi.operator.cluster.model.NoSuchResourceException) CruiseControlUserTaskStatus(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlUserTaskStatus) KafkaRebalanceStatusBuilder(io.strimzi.api.kafka.model.status.KafkaRebalanceStatusBuilder) CruiseControlResources(io.strimzi.api.kafka.model.CruiseControlResources) AddBrokerOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.AddBrokerOptions) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) Stream(java.util.stream.Stream) CruiseControlApi(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApi) Secret(io.fabric8.kubernetes.api.model.Secret) Optional(java.util.Optional) Condition(io.strimzi.api.kafka.model.status.Condition) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) KafkaList(io.strimzi.api.kafka.KafkaList) KafkaRebalanceState(io.strimzi.api.kafka.model.balancing.KafkaRebalanceState) KafkaRebalanceBuilder(io.strimzi.api.kafka.model.KafkaRebalanceBuilder) HashMap(java.util.HashMap) CruiseControlApiImpl(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl) KafkaRebalanceSpec(io.strimzi.api.kafka.model.KafkaRebalanceSpec) ArrayList(java.util.ArrayList) KafkaRebalanceMode(io.strimzi.api.kafka.model.balancing.KafkaRebalanceMode) HashSet(java.util.HashSet) WatcherException(io.fabric8.kubernetes.client.WatcherException) CompositeFuture(io.vertx.core.CompositeFuture) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) RebalanceOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.RebalanceOptions) CruiseControl(io.strimzi.operator.cluster.model.CruiseControl) JbodStorage(io.strimzi.api.kafka.model.storage.JbodStorage) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) InvalidResourceException(io.strimzi.operator.cluster.model.InvalidResourceException) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) CruiseControlLoadParameters(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlLoadParameters) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KafkaRebalanceStatus(io.strimzi.api.kafka.model.status.KafkaRebalanceStatus) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) Reconciliation(io.strimzi.operator.common.Reconciliation) JsonArray(io.vertx.core.json.JsonArray) HTTP_DEFAULT_IDLE_TIMEOUT_SECONDS(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl.HTTP_DEFAULT_IDLE_TIMEOUT_SECONDS) StatusDiff(io.strimzi.operator.cluster.model.StatusDiff) Util(io.strimzi.operator.common.Util) RemoveBrokerOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.RemoveBrokerOptions) AbstractWatchableStatusedResourceOperator(io.strimzi.operator.common.operator.resource.AbstractWatchableStatusedResourceOperator) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Kafka(io.strimzi.api.kafka.model.Kafka) CruiseControlRestException(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRestException) Collections(java.util.Collections) AddBrokerOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.AddBrokerOptions) AbstractRebalanceOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.AbstractRebalanceOptions) KafkaRebalanceMode(io.strimzi.api.kafka.model.balancing.KafkaRebalanceMode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RemoveBrokerOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.RemoveBrokerOptions) AbstractRebalanceOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.AbstractRebalanceOptions) RebalanceOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.RebalanceOptions)

Aggregations

ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)4 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)4 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)4 Secret (io.fabric8.kubernetes.api.model.Secret)4 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)4 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)4 Watcher (io.fabric8.kubernetes.client.Watcher)4 WatcherException (io.fabric8.kubernetes.client.WatcherException)4 Resource (io.fabric8.kubernetes.client.dsl.Resource)4 KafkaList (io.strimzi.api.kafka.KafkaList)4 KafkaRebalanceList (io.strimzi.api.kafka.KafkaRebalanceList)4 CruiseControlResources (io.strimzi.api.kafka.model.CruiseControlResources)4 Kafka (io.strimzi.api.kafka.model.Kafka)4 KafkaRebalance (io.strimzi.api.kafka.model.KafkaRebalance)4 KafkaRebalanceBuilder (io.strimzi.api.kafka.model.KafkaRebalanceBuilder)4 KafkaRebalanceSpec (io.strimzi.api.kafka.model.KafkaRebalanceSpec)4 KafkaRebalanceAnnotation (io.strimzi.api.kafka.model.balancing.KafkaRebalanceAnnotation)4 KafkaRebalanceMode (io.strimzi.api.kafka.model.balancing.KafkaRebalanceMode)4 KafkaRebalanceState (io.strimzi.api.kafka.model.balancing.KafkaRebalanceState)4 Condition (io.strimzi.api.kafka.model.status.Condition)4