Search in sources :

Example 36 with KafkaRebalance

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);
}
Also used : KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance) Test(org.junit.jupiter.api.Test)

Example 37 with KafkaRebalance

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());
    });
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) AbstractRebalanceOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.AbstractRebalanceOptions) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) CruiseControlApi(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApi) KafkaRebalanceList(io.strimzi.api.kafka.KafkaRebalanceList) CruiseControlApiImpl(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Reconciliation(io.strimzi.operator.common.Reconciliation) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance)

Example 38 with KafkaRebalance

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);
}
Also used : KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance) Test(org.junit.jupiter.api.Test)

Example 39 with KafkaRebalance

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);
}
Also used : KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance) Test(org.junit.jupiter.api.Test)

Example 40 with KafkaRebalance

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);
}
Also used : KafkaRebalanceSpec(io.strimzi.api.kafka.model.KafkaRebalanceSpec) ArrayList(java.util.ArrayList) KafkaRebalanceSpecBuilder(io.strimzi.api.kafka.model.KafkaRebalanceSpecBuilder) KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance) Test(org.junit.jupiter.api.Test)

Aggregations

KafkaRebalance (io.strimzi.api.kafka.model.KafkaRebalance)200 Test (org.junit.jupiter.api.Test)182 KafkaRebalanceSpec (io.strimzi.api.kafka.model.KafkaRebalanceSpec)76 KafkaRebalanceSpecBuilder (io.strimzi.api.kafka.model.KafkaRebalanceSpecBuilder)72 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)60 Condition (io.strimzi.api.kafka.model.status.Condition)58 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)56 KafkaRebalanceList (io.strimzi.api.kafka.KafkaRebalanceList)56 KafkaRebalanceBuilder (io.strimzi.api.kafka.model.KafkaRebalanceBuilder)56 InvalidResourceException (io.strimzi.operator.cluster.model.InvalidResourceException)56 NoSuchResourceException (io.strimzi.operator.cluster.model.NoSuchResourceException)56 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)56 CruiseControlApi (io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApi)56 CruiseControlApiImpl (io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl)56 CruiseControlRestException (io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRestException)56 Reconciliation (io.strimzi.operator.common.Reconciliation)56 ConfigMapOperator (io.strimzi.operator.common.operator.resource.ConfigMapOperator)56 Map (java.util.Map)56 Secret (io.fabric8.kubernetes.api.model.Secret)54 KafkaList (io.strimzi.api.kafka.KafkaList)54