use of io.strimzi.api.kafka.model.KafkaRebalance in project strimzi by strimzi.
the class KafkaRebalanceStateMachineTest method testRebalancingCompleted.
@Test
public void testRebalancingCompleted(Vertx vertx, VertxTestContext context) throws IOException, URISyntaxException {
KafkaRebalance kcRebalance = createKafkaRebalance(KafkaRebalanceState.Rebalancing, MockCruiseControl.REBALANCE_NO_GOALS_VERBOSE_RESPONSE_UTID, null, EMPTY_KAFKA_REBALANCE_SPEC);
this.krRebalancingCompleted(vertx, context, 0, 0, kcRebalance);
kcRebalance = createKafkaRebalance(KafkaRebalanceState.Rebalancing, MockCruiseControl.REBALANCE_NO_GOALS_VERBOSE_RESPONSE_UTID, null, ADD_BROKER_KAFKA_REBALANCE_SPEC);
this.krRebalancingCompleted(vertx, context, 0, 0, kcRebalance);
kcRebalance = createKafkaRebalance(KafkaRebalanceState.Rebalancing, MockCruiseControl.REBALANCE_NO_GOALS_VERBOSE_RESPONSE_UTID, null, REMOVE_BROKER_KAFKA_REBALANCE_SPEC);
this.krRebalancingCompleted(vertx, context, 0, 0, kcRebalance);
}
use of io.strimzi.api.kafka.model.KafkaRebalance in project strimzi by strimzi.
the class KafkaRebalanceStateMachineTest method checkTransition.
/**
* Checks the expected transition between two states of the Kafka Rebalance operator.
*
* @param vertx The vertx test instance.
* @param context The test context instance.
* @param currentState The current state of the resource before being passed to computeNextStatus.
* @param nextState The expected state of the resouce after computeNextStatus has been called.
* @param initialAnnotation The initial annotation attached to the Kafka Rebalance resource. For example none or refresh.
* @param kcRebalance The Kafka Rebalance instance that will be returned by the resourceSupplier.
* @return A future for the {@link KafkaRebalanceStatus} returned by the {@link KafkaRebalanceAssemblyOperator#computeNextStatus} method
*/
private Future<KafkaRebalanceStatus> checkTransition(Vertx vertx, VertxTestContext context, KafkaRebalanceState currentState, KafkaRebalanceState nextState, KafkaRebalanceAnnotation initialAnnotation, KafkaRebalance kcRebalance) {
CruiseControlApi client = new CruiseControlApiImpl(vertx, HTTP_DEFAULT_IDLE_TIMEOUT_SECONDS, MockCruiseControl.CC_SECRET, MockCruiseControl.CC_API_SECRET, true, true);
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(true);
ConfigMapOperator mockCmOps = supplier.configMapOperations;
KafkaRebalanceAssemblyOperator kcrao = new KafkaRebalanceAssemblyOperator(vertx, supplier, ResourceUtils.dummyClusterOperatorConfig()) {
@Override
public String cruiseControlHost(String clusterName, String clusterNamespace) {
return HOST;
}
};
Reconciliation recon = new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, RESOURCE_NAME);
AbstractRebalanceOptions.AbstractRebalanceOptionsBuilder<?, ?> rbOptions = kcrao.convertRebalanceSpecToRebalanceOptions(kcRebalance.getSpec());
CrdOperator<KubernetesClient, KafkaRebalance, KafkaRebalanceList> mockRebalanceOps = supplier.kafkaRebalanceOperator;
when(mockCmOps.getAsync(CLUSTER_NAMESPACE, RESOURCE_NAME)).thenReturn(Future.succeededFuture(new ConfigMap()));
when(mockRebalanceOps.get(CLUSTER_NAMESPACE, RESOURCE_NAME)).thenReturn(kcRebalance);
when(mockRebalanceOps.getAsync(CLUSTER_NAMESPACE, RESOURCE_NAME)).thenReturn(Future.succeededFuture(kcRebalance));
return kcrao.computeNextStatus(recon, HOST, client, kcRebalance, currentState, initialAnnotation, rbOptions).compose(result -> {
context.verify(() -> {
assertThat(result.getStatus().getConditions(), StateMatchers.hasStateInConditions(nextState));
if (initialAnnotation != KafkaRebalanceAnnotation.none && !currentState.isValidateAnnotation(initialAnnotation)) {
assertThat("InvalidAnnotation", is(result.status.getConditions().get(0).getReason()));
}
});
return Future.succeededFuture(result.getStatus());
});
}
use of io.strimzi.api.kafka.model.KafkaRebalance in project strimzi by strimzi.
the class KafkaRebalanceStateMachineTest method testNewToProposalPending.
@Test
public void testNewToProposalPending(Vertx vertx, VertxTestContext context) throws IOException, URISyntaxException {
KafkaRebalance kcRebalance = createKafkaRebalance(KafkaRebalanceState.New, null, null, EMPTY_KAFKA_REBALANCE_SPEC);
this.krNewToProposalPending(vertx, context, 1, CruiseControlEndpoints.REBALANCE, kcRebalance);
kcRebalance = createKafkaRebalance(KafkaRebalanceState.New, null, null, ADD_BROKER_KAFKA_REBALANCE_SPEC);
this.krNewToProposalPending(vertx, context, 1, CruiseControlEndpoints.ADD_BROKER, kcRebalance);
kcRebalance = createKafkaRebalance(KafkaRebalanceState.New, null, null, REMOVE_BROKER_KAFKA_REBALANCE_SPEC);
this.krNewToProposalPending(vertx, context, 1, CruiseControlEndpoints.REMOVE_BROKER, kcRebalance);
}
use of io.strimzi.api.kafka.model.KafkaRebalance in project strimzi by strimzi.
the class KafkaRebalanceStateMachineTest method testReadyRefreshToPendingProposalNotEnoughData.
@Test
public void testReadyRefreshToPendingProposalNotEnoughData(Vertx vertx, VertxTestContext context) throws IOException, URISyntaxException {
KafkaRebalance kcRebalance = createKafkaRebalance(KafkaRebalanceState.Ready, null, null, EMPTY_KAFKA_REBALANCE_SPEC);
this.krReadyRefreshToPendingProposalNotEnoughData(vertx, context, CruiseControlEndpoints.REBALANCE, kcRebalance);
kcRebalance = createKafkaRebalance(KafkaRebalanceState.Ready, null, null, ADD_BROKER_KAFKA_REBALANCE_SPEC);
this.krReadyRefreshToPendingProposalNotEnoughData(vertx, context, CruiseControlEndpoints.ADD_BROKER, kcRebalance);
kcRebalance = createKafkaRebalance(KafkaRebalanceState.Ready, null, null, REMOVE_BROKER_KAFKA_REBALANCE_SPEC);
this.krReadyRefreshToPendingProposalNotEnoughData(vertx, context, CruiseControlEndpoints.REMOVE_BROKER, kcRebalance);
}
use of io.strimzi.api.kafka.model.KafkaRebalance in project strimzi by strimzi.
the class KafkaRebalanceStateMachineTest method testNewBadGoalsErrorWithSkipHGCheck.
@Test
public void testNewBadGoalsErrorWithSkipHGCheck(Vertx vertx, VertxTestContext context) throws IOException, URISyntaxException {
List<String> customGoals = new ArrayList<>();
customGoals.add("Goal.one");
customGoals.add("Goal.two");
customGoals.add("Goal.three");
KafkaRebalanceSpec rebalanceSpec = new KafkaRebalanceSpecBuilder().addAllToGoals(customGoals).withSkipHardGoalCheck(true).build();
KafkaRebalance kcRebalance = createKafkaRebalance(KafkaRebalanceState.New, null, null, rebalanceSpec);
this.krNewBadGoalsErrorWithSkipHGCheck(vertx, context, CruiseControlEndpoints.REBALANCE, kcRebalance);
rebalanceSpec = new KafkaRebalanceSpecBuilder().withMode(KafkaRebalanceMode.ADD_BROKERS).withBrokers(3).addAllToGoals(customGoals).withSkipHardGoalCheck(true).build();
kcRebalance = createKafkaRebalance(KafkaRebalanceState.New, null, null, rebalanceSpec);
this.krNewBadGoalsError(vertx, context, CruiseControlEndpoints.ADD_BROKER, kcRebalance);
rebalanceSpec = new KafkaRebalanceSpecBuilder().withMode(KafkaRebalanceMode.REMOVE_BROKERS).withBrokers(3).addAllToGoals(customGoals).withSkipHardGoalCheck(true).build();
kcRebalance = createKafkaRebalance(KafkaRebalanceState.New, null, null, rebalanceSpec);
this.krNewBadGoalsError(vertx, context, CruiseControlEndpoints.REMOVE_BROKER, kcRebalance);
}
Aggregations