Search in sources :

Example 1 with KafkaRebalanceList

use of io.strimzi.api.kafka.KafkaRebalanceList 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;
    PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(true, kubernetesVersion);
    KafkaRebalanceAssemblyOperator kcrao = new KafkaRebalanceAssemblyOperator(vertx, pfa, 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);
    RebalanceOptions.RebalanceOptionsBuilder rbOptions = new RebalanceOptions.RebalanceOptionsBuilder();
    if (kcRebalance.getSpec() != null) {
        if (kcRebalance.getSpec().getGoals() != null) {
            rbOptions.withGoals(kcRebalance.getSpec().getGoals());
        }
        if (kcRebalance.getSpec().isSkipHardGoalCheck()) {
            rbOptions.withSkipHardGoalCheck();
        }
    }
    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));
        });
        return Future.succeededFuture(result.getStatus());
    });
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) 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) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Reconciliation(io.strimzi.operator.common.Reconciliation) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) RebalanceOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.RebalanceOptions) KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance)

Example 2 with KafkaRebalanceList

use of io.strimzi.api.kafka.KafkaRebalanceList in project strimzi-kafka-operator 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;
    PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(true, kubernetesVersion);
    KafkaRebalanceAssemblyOperator kcrao = new KafkaRebalanceAssemblyOperator(vertx, pfa, 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);
    RebalanceOptions.RebalanceOptionsBuilder rbOptions = new RebalanceOptions.RebalanceOptionsBuilder();
    if (kcRebalance.getSpec() != null) {
        if (kcRebalance.getSpec().getGoals() != null) {
            rbOptions.withGoals(kcRebalance.getSpec().getGoals());
        }
        if (kcRebalance.getSpec().isSkipHardGoalCheck()) {
            rbOptions.withSkipHardGoalCheck();
        }
    }
    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));
        });
        return Future.succeededFuture(result.getStatus());
    });
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) 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) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Reconciliation(io.strimzi.operator.common.Reconciliation) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) RebalanceOptions(io.strimzi.operator.cluster.operator.resource.cruisecontrol.RebalanceOptions) KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance)

Aggregations

ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 KafkaRebalanceList (io.strimzi.api.kafka.KafkaRebalanceList)2 KafkaRebalance (io.strimzi.api.kafka.model.KafkaRebalance)2 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)2 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)2 CruiseControlApi (io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApi)2 CruiseControlApiImpl (io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl)2 RebalanceOptions (io.strimzi.operator.cluster.operator.resource.cruisecontrol.RebalanceOptions)2 Reconciliation (io.strimzi.operator.common.Reconciliation)2 ConfigMapOperator (io.strimzi.operator.common.operator.resource.ConfigMapOperator)2