use of io.strimzi.api.kafka.model.KafkaRebalanceSpecBuilder in project strimzi by strimzi.
the class KafkaRebalanceAssemblyOperatorTest method testNewToProposalReadySkipHardGoalsRebalance.
/**
* Tests the transition from 'New' to 'ProposalReady' skipping the hard goals check
*
* 1. A new KafkaRebalance resource is created with some specified goals not included in the hard goals but with flag to skip the check; it is in the 'New' state
* 2. The operator requests a rebalance proposal through the Cruise Control REST API
* 3. The rebalance proposal is ready on the first call
* 4. The KafkaRebalance resource transitions to the 'ProposalReady' state
*/
@Test
public void testNewToProposalReadySkipHardGoalsRebalance(VertxTestContext context) throws IOException, URISyntaxException {
// Setup the rebalance endpoint with the number of pending calls before a response is received.
MockCruiseControl.setupCCRebalanceResponse(ccServer, 0);
KafkaRebalanceSpec kafkaRebalanceSpec = new KafkaRebalanceSpecBuilder().withGoals("DiskCapacityGoal", "CpuCapacityGoal").withSkipHardGoalCheck(true).build();
KafkaRebalance kr = createKafkaRebalance(CLUSTER_NAMESPACE, CLUSTER_NAME, RESOURCE_NAME, kafkaRebalanceSpec);
Crds.kafkaRebalanceOperation(kubernetesClient).inNamespace(CLUSTER_NAMESPACE).create(kr);
when(mockKafkaOps.getAsync(CLUSTER_NAMESPACE, CLUSTER_NAME)).thenReturn(Future.succeededFuture(kafka));
mockSecretResources();
mockRebalanceOperator(mockRebalanceOps, mockCmOps, CLUSTER_NAMESPACE, RESOURCE_NAME, kubernetesClient);
Checkpoint checkpoint = context.checkpoint();
kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, RESOURCE_NAME), kr).onComplete(context.succeeding(v -> {
// the resource moved from New directly to ProposalReady (no pending calls in the Mock server)
assertState(context, kubernetesClient, CLUSTER_NAMESPACE, RESOURCE_NAME, KafkaRebalanceState.ProposalReady);
checkpoint.flag();
}));
}
use of io.strimzi.api.kafka.model.KafkaRebalanceSpecBuilder in project strimzi by strimzi.
the class KafkaRebalanceStateMachineTest method testNewBadGoalsError.
@Test
public void testNewBadGoalsError(Vertx vertx, VertxTestContext context) throws IOException, URISyntaxException {
// Test the case where the user asks for a rebalance with custom goals which do not contain all the configured hard goals
// In this case the computeNextStatus error will return a failed future with a message containing an illegal argument exception
MockCruiseControl.setupCCRebalanceBadGoalsError(ccServer);
List<String> customGoals = new ArrayList<>();
customGoals.add("Goal.one");
customGoals.add("Goal.two");
customGoals.add("Goal.three");
KafkaRebalanceSpec rebalanceSpec = new KafkaRebalanceSpecBuilder().addAllToGoals(customGoals).build();
KafkaRebalance kcRebalance = createKafkaRebalance(KafkaRebalanceState.New, null, null, rebalanceSpec);
checkTransition(vertx, context, KafkaRebalanceState.New, KafkaRebalanceState.NotReady, KafkaRebalanceAnnotation.none, kcRebalance).onComplete(result -> {
if (result.failed()) {
if (result.cause().getMessage().contains("java.lang.IllegalArgumentException: Missing hard goals")) {
context.completeNow();
} else {
context.failNow(new RuntimeException("This operation failed with an unexpected error:" + result.cause().getMessage()));
}
}
context.failNow(new RuntimeException("This operations should have failed"));
});
}
use of io.strimzi.api.kafka.model.KafkaRebalanceSpecBuilder in project strimzi by strimzi.
the class KafkaRebalanceStateMachineTest method testNewBadGoalsErrorWithSkipHGCheck.
@Test
public void testNewBadGoalsErrorWithSkipHGCheck(Vertx vertx, VertxTestContext context) throws IOException, URISyntaxException {
// Test the case where the user asks for a rebalance with custom goals which do not contain all the configured hard goals
// But we have set skip hard goals check to true
MockCruiseControl.setupCCRebalanceBadGoalsError(ccServer);
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);
checkTransition(vertx, context, KafkaRebalanceState.New, KafkaRebalanceState.ProposalReady, KafkaRebalanceAnnotation.none, kcRebalance).onComplete(result -> checkOptimizationResults(result, context, false));
}
use of io.strimzi.api.kafka.model.KafkaRebalanceSpecBuilder in project strimzi-kafka-operator by strimzi.
the class KafkaRebalanceAssemblyOperatorTest method testCruiseControlNotReachable.
/**
* Test the Cruise Control server not reachable
*
* 1. A new KafkaRebalance resource is created; it is in the 'New' state
* 2. The operator requests a rebalance proposal through the Cruise Control REST API
* 3. The operator doesn't get a response on time; the resource moves to 'NotReady'
*/
@Test
public void testCruiseControlNotReachable(VertxTestContext context) {
// stop the mocked Cruise Control server to make it unreachable
ccServer.stop();
KafkaRebalance kr = createKafkaRebalance(CLUSTER_NAMESPACE, CLUSTER_NAME, RESOURCE_NAME, new KafkaRebalanceSpecBuilder().build());
Crds.kafkaRebalanceOperation(kubernetesClient).inNamespace(CLUSTER_NAMESPACE).create(kr);
when(mockKafkaOps.getAsync(CLUSTER_NAMESPACE, CLUSTER_NAME)).thenReturn(Future.succeededFuture(kafka));
mockSecretResources();
mockRebalanceOperator(mockRebalanceOps, mockCmOps, CLUSTER_NAMESPACE, RESOURCE_NAME, kubernetesClient);
Checkpoint checkpoint = context.checkpoint();
kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, RESOURCE_NAME), kr).onComplete(context.succeeding(v -> {
try {
ccServer = MockCruiseControl.server(CruiseControl.REST_API_PORT);
} catch (IOException e) {
context.failNow(e);
}
// the resource moved from 'New' to 'NotReady' (mocked Cruise Control not reachable)
assertState(context, kubernetesClient, CLUSTER_NAMESPACE, RESOURCE_NAME, KafkaRebalanceState.NotReady, ConnectException.class, "Connection refused");
checkpoint.flag();
}));
}
use of io.strimzi.api.kafka.model.KafkaRebalanceSpecBuilder in project strimzi-kafka-operator by strimzi.
the class KafkaRebalanceAssemblyOperatorTest method testNewToPendingProposalDeleteRebalance.
/**
* Tests the transition from 'New' to 'PendingProposal' then the resource is deleted
*
* 1. A new KafkaRebalance resource is created; it is in the New state
* 2. The operator requests a rebalance proposal through the Cruise Control REST API
* 3. The rebalance proposal is not ready on the first call; the operator starts polling the Cruise Control REST API
* 4. The KafkaRebalance resource moves to the 'PendingProposal' state
* 5. The KafkaRebalance resource is deleted
*/
@Test
public void testNewToPendingProposalDeleteRebalance(VertxTestContext context) throws IOException, URISyntaxException {
// Setup the rebalance endpoint with the number of pending calls before a response is received.
MockCruiseControl.setupCCRebalanceResponse(ccServer, 2);
KafkaRebalance kr = createKafkaRebalance(CLUSTER_NAMESPACE, CLUSTER_NAME, RESOURCE_NAME, new KafkaRebalanceSpecBuilder().build());
Crds.kafkaRebalanceOperation(kubernetesClient).inNamespace(CLUSTER_NAMESPACE).create(kr);
when(mockKafkaOps.getAsync(CLUSTER_NAMESPACE, CLUSTER_NAME)).thenReturn(Future.succeededFuture(kafka));
mockSecretResources();
mockRebalanceOperator(mockRebalanceOps, mockCmOps, CLUSTER_NAMESPACE, RESOURCE_NAME, kubernetesClient, new Runnable() {
int count = 0;
@Override
public void run() {
if (++count == 4) {
// delete the KafkaRebalance resource while on PendingProposal
Crds.kafkaRebalanceOperation(kubernetesClient).inNamespace(CLUSTER_NAMESPACE).withName(RESOURCE_NAME).delete();
}
return;
}
});
Checkpoint checkpoint = context.checkpoint();
kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, RESOURCE_NAME), kr).onComplete(context.succeeding(v -> assertState(context, kubernetesClient, CLUSTER_NAMESPACE, RESOURCE_NAME, KafkaRebalanceState.PendingProposal))).compose(v -> {
// trigger another reconcile to process the PendingProposal state
KafkaRebalance currentKR = Crds.kafkaRebalanceOperation(kubernetesClient).inNamespace(CLUSTER_NAMESPACE).withName(RESOURCE_NAME).get();
return kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, RESOURCE_NAME), currentKR);
}).onComplete(context.succeeding(v -> context.verify(() -> {
// the resource should not exist anymore
KafkaRebalance currentKR = Crds.kafkaRebalanceOperation(kubernetesClient).inNamespace(CLUSTER_NAMESPACE).withName(RESOURCE_NAME).get();
assertThat(currentKR, is(nullValue()));
checkpoint.flag();
})));
}
Aggregations