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