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());
}
});
}
Aggregations