Search in sources :

Example 6 with KafkaRebalanceState

use of io.strimzi.api.kafka.model.balancing.KafkaRebalanceState 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, RebalanceOptions.RebalanceOptionsBuilder rebalanceOptionsBuilder, String userTaskID) {
    LOGGER.infoCr(reconciliation, "Requesting Cruise Control rebalance [dryrun={}]", dryrun);
    rebalanceOptionsBuilder.withVerboseResponse();
    if (!dryrun) {
        rebalanceOptionsBuilder.withFullRun();
    }
    return apiClient.rebalance(host, CruiseControl.REST_API_PORT, rebalanceOptionsBuilder.build(), userTaskID).map(response -> {
        if (dryrun) {
            if (response.isNotEnoughDataForProposal()) {
                // Need to re-request the proposal at a later time so move to the PendingProposal State.
                return buildRebalanceStatus(null, KafkaRebalanceState.PendingProposal, validate(reconciliation, kafkaRebalance));
            } else if (response.isProposalStillCalaculating()) {
                // with the corresponding session-id so we move to the PendingProposal State.
                return buildRebalanceStatus(response.getUserTaskId(), KafkaRebalanceState.PendingProposal, validate(reconciliation, kafkaRebalance));
            }
        } else {
            if (response.isNotEnoughDataForProposal()) {
                // this failed tasks (COMPLETED_WITH_ERROR)
                return buildRebalanceStatus(null, KafkaRebalanceState.PendingProposal, validate(reconciliation, kafkaRebalance));
            } else if (response.isProposalStillCalaculating()) {
                // In the onRebalancing method the optimization proposal will be added when it is ready.
                return buildRebalanceStatus(response.getUserTaskId(), KafkaRebalanceState.Rebalancing, validate(reconciliation, kafkaRebalance));
            }
        }
        if (response.getJson() != null && response.getJson().containsKey(CruiseControlRebalanceKeys.SUMMARY.getKey())) {
            // If there is enough data and the proposal is complete (the response has the "summary" key) then we move
            // to ProposalReady for a dry run or to the Rebalancing state for a full run
            KafkaRebalanceState ready = dryrun ? KafkaRebalanceState.ProposalReady : KafkaRebalanceState.Rebalancing;
            return buildRebalanceStatus(kafkaRebalance, response.getUserTaskId(), ready, response.getJson(), validate(reconciliation, kafkaRebalance));
        } else {
            throw new CruiseControlRestException("Rebalance returned unknown response: " + response.toString());
        }
    });
}
Also used : KafkaRebalanceState(io.strimzi.api.kafka.model.balancing.KafkaRebalanceState) CruiseControlRestException(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRestException)

Aggregations

KafkaRebalanceState (io.strimzi.api.kafka.model.balancing.KafkaRebalanceState)6 Secret (io.fabric8.kubernetes.api.model.Secret)4 KafkaRebalanceAnnotation (io.strimzi.api.kafka.model.balancing.KafkaRebalanceAnnotation)4 KafkaRebalanceStatus (io.strimzi.api.kafka.model.status.KafkaRebalanceStatus)4 JbodStorage (io.strimzi.api.kafka.model.storage.JbodStorage)4 CruiseControlConfiguration (io.strimzi.operator.cluster.model.CruiseControlConfiguration)4 InvalidResourceException (io.strimzi.operator.cluster.model.InvalidResourceException)4 NoSuchResourceException (io.strimzi.operator.cluster.model.NoSuchResourceException)4 CruiseControlApi (io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApi)4 CruiseControlRestException (io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRestException)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)2 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)2 Watcher (io.fabric8.kubernetes.client.Watcher)2 WatcherException (io.fabric8.kubernetes.client.WatcherException)2 Resource (io.fabric8.kubernetes.client.dsl.Resource)2 KafkaList (io.strimzi.api.kafka.KafkaList)2 KafkaRebalanceList (io.strimzi.api.kafka.KafkaRebalanceList)2