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());
});
}
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;
}
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());
});
}
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;
}
Aggregations