use of io.strimzi.api.kafka.model.KafkaRebalance in project strimzi-kafka-operator by strimzi.
the class KafkaRebalanceAssemblyOperatorTest method testNewToPendingProposalDeleteAddBroker.
/**
* See the {@link KafkaRebalanceAssemblyOperatorTest#testNewToPendingProposalDeleteRebalance} for description
*/
@Test
public void testNewToPendingProposalDeleteAddBroker(VertxTestContext context) throws IOException, URISyntaxException {
KafkaRebalance kr = createKafkaRebalance(CLUSTER_NAMESPACE, CLUSTER_NAME, RESOURCE_NAME, ADD_BROKER_KAFKA_REBALANCE_SPEC);
this.krNewToPendingProposalDelete(context, 2, CruiseControlEndpoints.ADD_BROKER, kr);
}
use of io.strimzi.api.kafka.model.KafkaRebalance in project strimzi-kafka-operator by strimzi.
the class KafkaRebalanceAssemblyOperatorTest method krNewToProposalReadyToRebalancingToReady.
private void krNewToProposalReadyToRebalancingToReady(VertxTestContext context, int pendingCalls, int activeCalls, int inExecutionCalls, CruiseControlEndpoints endpoint, KafkaRebalance kr) throws IOException, URISyntaxException {
// Setup the rebalance and user tasks endpoints with the number of pending calls before a response is received.
MockCruiseControl.setupCCRebalanceResponse(ccServer, pendingCalls, endpoint);
MockCruiseControl.setupCCUserTasksResponseNoGoals(ccServer, activeCalls, inExecutionCalls);
Crds.kafkaRebalanceOperation(client).inNamespace(CLUSTER_NAMESPACE).create(kr);
when(mockKafkaOps.getAsync(CLUSTER_NAMESPACE, CLUSTER_NAME)).thenReturn(Future.succeededFuture(kafka));
mockSecretResources();
mockRebalanceOperator(mockRebalanceOps, mockCmOps, CLUSTER_NAMESPACE, kr.getMetadata().getName(), client);
Checkpoint checkpoint = context.checkpoint();
kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, kr.getMetadata().getName()), kr).onComplete(context.succeeding(v -> assertState(context, client, CLUSTER_NAMESPACE, kr.getMetadata().getName(), KafkaRebalanceState.ProposalReady))).compose(v -> {
// apply the "approve" annotation to the resource in the ProposalReady state
KafkaRebalance approvedKr = annotate(client, CLUSTER_NAMESPACE, kr.getMetadata().getName(), KafkaRebalanceAnnotation.approve);
return kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, kr.getMetadata().getName()), approvedKr);
}).onComplete(context.succeeding(v -> {
// the resource moved from ProposalReady to Rebalancing on approval
assertState(context, client, CLUSTER_NAMESPACE, kr.getMetadata().getName(), KafkaRebalanceState.Rebalancing);
})).compose(v -> {
// trigger another reconcile to process the Rebalancing state
KafkaRebalance kr4 = Crds.kafkaRebalanceOperation(client).inNamespace(CLUSTER_NAMESPACE).withName(kr.getMetadata().getName()).get();
return kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, kr.getMetadata().getName()), kr4);
}).onComplete(context.succeeding(v -> {
// the resource moved from Rebalancing to Ready
assertState(context, client, CLUSTER_NAMESPACE, kr.getMetadata().getName(), KafkaRebalanceState.Ready);
checkpoint.flag();
}));
}
use of io.strimzi.api.kafka.model.KafkaRebalance in project strimzi-kafka-operator by strimzi.
the class KafkaRebalanceAssemblyOperatorTest method testNewWithMissingHardGoalsAndRefreshRemoveBroker.
/**
* See the {@link KafkaRebalanceAssemblyOperatorTest#testNewWithMissingHardGoalsAndRefreshRebalance} for description
*/
@Test
public void testNewWithMissingHardGoalsAndRefreshRemoveBroker(VertxTestContext context) throws IOException, URISyntaxException {
KafkaRebalanceSpec kafkaRebalanceSpec = new KafkaRebalanceSpecBuilder().withMode(KafkaRebalanceMode.REMOVE_BROKERS).withBrokers(3).withGoals("DiskCapacityGoal", "CpuCapacityGoal").build();
KafkaRebalance kr = createKafkaRebalance(CLUSTER_NAMESPACE, CLUSTER_NAME, RESOURCE_NAME, kafkaRebalanceSpec);
this.krNewWithMissingHardGoalsAndRefresh(context, 0, CruiseControlEndpoints.REMOVE_BROKER, kr);
}
use of io.strimzi.api.kafka.model.KafkaRebalance in project strimzi-kafka-operator by strimzi.
the class KafkaRebalanceAssemblyOperatorTest method testCruiseControlTimingOut.
/**
* Test the Cruise Control API REST client timing out
*
* 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 testCruiseControlTimingOut(VertxTestContext context) throws IOException, URISyntaxException {
// Setup the rebalance endpoint with the number of pending calls before a response is received
// and with a delay on response higher than the client timeout to test timing out
MockCruiseControl.setupCCRebalanceResponse(ccServer, 0, 10, CruiseControlEndpoints.REBALANCE);
KafkaRebalance kr = createKafkaRebalance(CLUSTER_NAMESPACE, CLUSTER_NAME, RESOURCE_NAME, EMPTY_KAFKA_REBALANCE_SPEC);
Crds.kafkaRebalanceOperation(client).inNamespace(CLUSTER_NAMESPACE).create(kr);
when(mockKafkaOps.getAsync(CLUSTER_NAMESPACE, CLUSTER_NAME)).thenReturn(Future.succeededFuture(kafka));
mockSecretResources();
mockRebalanceOperator(mockRebalanceOps, mockCmOps, CLUSTER_NAMESPACE, RESOURCE_NAME, client);
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 to NotReady (mocked Cruise Control didn't reply on time)
assertState(context, client, CLUSTER_NAMESPACE, RESOURCE_NAME, KafkaRebalanceState.NotReady, NoStackTraceTimeoutException.class, "The timeout period of 1000ms has been exceeded while executing POST");
checkpoint.flag();
}));
}
use of io.strimzi.api.kafka.model.KafkaRebalance in project strimzi-kafka-operator by strimzi.
the class KafkaRebalanceAssemblyOperatorTest method testUnknownPropertyInSpec.
@Test
public void testUnknownPropertyInSpec(VertxTestContext context) throws IOException, URISyntaxException {
MockCruiseControl.setupCCRebalanceResponse(ccServer, 2, CruiseControlEndpoints.REBALANCE);
String yaml = "apiVersion: kafka.strimzi.io/v1beta2\n" + "kind: KafkaRebalance\n" + "metadata:\n" + " name: " + RESOURCE_NAME + "\n" + " namespace: " + CLUSTER_NAMESPACE + "\n" + " labels:\n" + " strimzi.io/cluster: " + CLUSTER_NAME + "\n" + "spec:\n" + " unknown: \"property\"\n" + " goals:\n" + " - CpuCapacityGoal\n" + " - NetworkInboundCapacityGoal\n" + " - DiskCapacityGoal\n" + " - RackAwareGoal\n" + " - NetworkOutboundCapacityGoal\n" + " - ReplicaCapacityGoal\n";
KafkaRebalance kr = TestUtils.fromYamlString(yaml, KafkaRebalance.class);
Crds.kafkaRebalanceOperation(client).inNamespace(CLUSTER_NAMESPACE).create(kr);
// the Kafka cluster isn't deployed in the namespace
when(mockKafkaOps.getAsync(CLUSTER_NAMESPACE, CLUSTER_NAME)).thenReturn(Future.succeededFuture(kafka));
mockSecretResources();
mockRebalanceOperator(mockRebalanceOps, mockCmOps, CLUSTER_NAMESPACE, RESOURCE_NAME, client);
Checkpoint checkpoint = context.checkpoint();
kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, RESOURCE_NAME), kr).onComplete(context.succeeding(v -> context.verify(() -> {
KafkaRebalance kr1 = Crds.kafkaRebalanceOperation(client).inNamespace(CLUSTER_NAMESPACE).withName(RESOURCE_NAME).get();
assertThat(kr1, StateMatchers.hasState());
Optional<Condition> condition = kr1.getStatus().getConditions().stream().filter(cond -> "UnknownFields".equals(cond.getReason())).findFirst();
assertTrue(condition.isPresent());
assertThat(condition.get().getStatus(), is("True"));
assertThat(condition.get().getMessage(), is("Contains object at path spec with an unknown property: unknown"));
assertThat(condition.get().getType(), is("Warning"));
checkpoint.flag();
})));
}
Aggregations