Search in sources :

Example 1 with CruiseControlApiImpl

use of io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl 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 CruiseControlApiImpl

use of io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl in project strimzi-kafka-operator by strimzi.

the class KafkaRebalanceAssemblyOperatorTest method beforeEach.

@BeforeEach
public void beforeEach(Vertx vertx) {
    ccServer.reset();
    kubernetesClient = new MockKube().withCustomResourceDefinition(Crds.kafkaRebalance(), KafkaRebalance.class, KafkaRebalanceList.class).end().build();
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(true);
    PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(true, kubernetesVersion);
    // Override to inject mocked cruise control address so real cruise control not required
    kcrao = new KafkaRebalanceAssemblyOperator(vertx, pfa, supplier, ResourceUtils.dummyClusterOperatorConfig()) {

        @Override
        public String cruiseControlHost(String clusterName, String clusterNamespace) {
            return HOST;
        }

        @Override
        public CruiseControlApi cruiseControlClientProvider(Secret ccSecret, Secret ccApiSecret, boolean apiAuthEnabled, boolean apiSslEnabled) {
            return new CruiseControlApiImpl(vertx, 1, ccSecret, ccApiSecret, true, true);
        }
    };
    mockRebalanceOps = supplier.kafkaRebalanceOperator;
    mockKafkaOps = supplier.kafkaOperator;
    mockCmOps = supplier.configMapOperations;
    mockSecretOps = supplier.secretOperations;
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) MockKube(io.strimzi.test.mockkube.MockKube) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) KafkaRebalanceList(io.strimzi.api.kafka.KafkaRebalanceList) CruiseControlApi(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApi) CruiseControlApiImpl(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl) KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with CruiseControlApiImpl

use of io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl 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)

Example 4 with CruiseControlApiImpl

use of io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl in project strimzi by strimzi.

the class KafkaRebalanceAssemblyOperatorTest method beforeEach.

@BeforeEach
public void beforeEach(Vertx vertx) {
    ccServer.reset();
    kubernetesClient = new MockKube().withCustomResourceDefinition(Crds.kafkaRebalance(), KafkaRebalance.class, KafkaRebalanceList.class).end().build();
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(true);
    PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(true, kubernetesVersion);
    // Override to inject mocked cruise control address so real cruise control not required
    kcrao = new KafkaRebalanceAssemblyOperator(vertx, pfa, supplier, ResourceUtils.dummyClusterOperatorConfig()) {

        @Override
        public String cruiseControlHost(String clusterName, String clusterNamespace) {
            return HOST;
        }

        @Override
        public CruiseControlApi cruiseControlClientProvider(Secret ccSecret, Secret ccApiSecret, boolean apiAuthEnabled, boolean apiSslEnabled) {
            return new CruiseControlApiImpl(vertx, 1, ccSecret, ccApiSecret, true, true);
        }
    };
    mockRebalanceOps = supplier.kafkaRebalanceOperator;
    mockKafkaOps = supplier.kafkaOperator;
    mockCmOps = supplier.configMapOperations;
    mockSecretOps = supplier.secretOperations;
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) MockKube(io.strimzi.test.mockkube.MockKube) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) KafkaRebalanceList(io.strimzi.api.kafka.KafkaRebalanceList) CruiseControlApi(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApi) CruiseControlApiImpl(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl) KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

KafkaRebalanceList (io.strimzi.api.kafka.KafkaRebalanceList)4 KafkaRebalance (io.strimzi.api.kafka.model.KafkaRebalance)4 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)4 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)4 CruiseControlApi (io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApi)4 CruiseControlApiImpl (io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 Secret (io.fabric8.kubernetes.api.model.Secret)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)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 MockKube (io.strimzi.test.mockkube.MockKube)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2