use of io.strimzi.operator.common.BackOff in project strimzi-kafka-operator by strimzi.
the class ZookeeperLeaderFinderTest method testReturnUnknownLeaderDuringNetworkExceptions.
@Test
public void testReturnUnknownLeaderDuringNetworkExceptions(VertxTestContext context) throws InterruptedException {
int[] ports = startMockZks(context, 2, (id, attempt) -> false);
// Close ports to ensure closed ports are used so as to mock network problems
stopZks();
ZookeeperLeaderFinder finder = new TestingZookeeperLeaderFinder(this::backoff, ports);
Checkpoint a = context.checkpoint();
finder.findZookeeperLeader(Reconciliation.DUMMY_RECONCILIATION, treeSet(createPodWithId(0), createPodWithId(1)), dummySecret(), dummySecret()).onComplete(context.succeeding(leader -> context.verify(() -> {
assertThat(leader, is(ZookeeperLeaderFinder.UNKNOWN_LEADER));
for (FakeZk zk : zks) {
assertThat("Unexpected number of attempts for node " + zk.id, zk.attempts.get(), is(0));
}
a.flag();
})));
}
use of io.strimzi.operator.common.BackOff in project strimzi by strimzi.
the class ZookeeperLeaderFinder method zookeeperLeaderWithBackoff.
private Future<String> zookeeperLeaderWithBackoff(Reconciliation reconciliation, Set<String> pods, NetClientOptions netClientOptions) {
Promise<String> result = Promise.promise();
BackOff backOff = backOffSupplier.get();
Handler<Long> handler = new Handler<Long>() {
@Override
public void handle(Long tid) {
zookeeperLeader(reconciliation, pods, netClientOptions).onComplete(leader -> {
if (leader.succeeded()) {
if (!UNKNOWN_LEADER.equals(leader.result())) {
result.complete(leader.result());
} else {
rescheduleOrComplete(reconciliation, tid);
}
} else {
LOGGER.debugOp("Ignoring error", leader.cause());
if (backOff.done()) {
result.complete(UNKNOWN_LEADER);
} else {
rescheduleOrComplete(reconciliation, tid);
}
}
});
}
void rescheduleOrComplete(Reconciliation reconciliation, Long tid) {
if (backOff.done()) {
LOGGER.warnCr(reconciliation, "Giving up trying to find the leader of {}/{} after {} attempts taking {}ms", reconciliation.name(), reconciliation.namespace(), backOff.maxAttempts(), backOff.totalDelayMs());
result.complete(UNKNOWN_LEADER);
} else {
// Schedule ourselves to run again
long delay = backOff.delayMs();
LOGGER.infoCr(reconciliation, "No leader found for cluster {} in namespace {}; " + "backing off for {}ms (cumulative {}ms)", reconciliation.name(), reconciliation.namespace(), delay, backOff.cumulativeDelayMs());
if (delay < 1) {
this.handle(tid);
} else {
vertx.setTimer(delay, this);
}
}
}
};
handler.handle(null);
return result.future();
}
use of io.strimzi.operator.common.BackOff in project strimzi by strimzi.
the class ConnectorMockTest method setup.
@SuppressWarnings({ "checkstyle:MethodLength" })
@BeforeEach
public void setup(VertxTestContext testContext) {
vertx = Vertx.vertx();
client = new MockKube().withCustomResourceDefinition(Crds.kafkaConnect(), KafkaConnect.class, KafkaConnectList.class, KafkaConnect::getStatus, KafkaConnect::setStatus).end().withCustomResourceDefinition(Crds.kafkaConnector(), KafkaConnector.class, KafkaConnectorList.class, KafkaConnector::getStatus, KafkaConnector::setStatus).end().build();
PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(true, KubernetesVersion.V1_18);
setupMockConnectAPI();
ResourceOperatorSupplier ros = new ResourceOperatorSupplier(vertx, client, new ZookeeperLeaderFinder(vertx, // Retry up to 3 times (4 attempts), with overall max delay of 35000ms
() -> new BackOff(5_000, 2, 4)), new DefaultAdminClientProvider(), new DefaultZookeeperScalerProvider(), ResourceUtils.metricsProvider(), pfa, FeatureGates.NONE, 10_000);
ClusterOperatorConfig config = ClusterOperatorConfig.fromMap(map(ClusterOperatorConfig.STRIMZI_KAFKA_IMAGES, KafkaVersionTestUtils.getKafkaImagesEnvVarString(), ClusterOperatorConfig.STRIMZI_KAFKA_CONNECT_IMAGES, KafkaVersionTestUtils.getKafkaConnectImagesEnvVarString(), ClusterOperatorConfig.STRIMZI_KAFKA_MIRROR_MAKER_2_IMAGES, KafkaVersionTestUtils.getKafkaMirrorMaker2ImagesEnvVarString(), ClusterOperatorConfig.STRIMZI_FULL_RECONCILIATION_INTERVAL_MS, Long.toString(Long.MAX_VALUE)), KafkaVersionTestUtils.getKafkaVersionLookup());
kafkaConnectOperator = new KafkaConnectAssemblyOperator(vertx, pfa, ros, config, x -> api);
Checkpoint async = testContext.checkpoint();
// Fail test if watcher closes for any reason
kafkaConnectOperator.createWatch(NAMESPACE, e -> testContext.failNow(e)).onComplete(testContext.succeeding()).compose(watch -> AbstractConnectOperator.createConnectorWatch(kafkaConnectOperator, NAMESPACE, null)).onComplete(testContext.succeeding(v -> async.flag()));
}
use of io.strimzi.operator.common.BackOff in project strimzi by strimzi.
the class ZookeeperLeaderFinderTest method test0PodsClusterReturnsUnknowLeader.
@Test
public void test0PodsClusterReturnsUnknowLeader(VertxTestContext context) {
ZookeeperLeaderFinder finder = new ZookeeperLeaderFinder(vertx, this::backoff);
Checkpoint a = context.checkpoint();
finder.findZookeeperLeader(Reconciliation.DUMMY_RECONCILIATION, emptySet(), dummySecret(), dummySecret()).onComplete(context.succeeding(leader -> {
context.verify(() -> assertThat(leader, is(ZookeeperLeaderFinder.UNKNOWN_LEADER)));
a.flag();
}));
}
use of io.strimzi.operator.common.BackOff in project strimzi by strimzi.
the class KafkaMirrorMaker2AssemblyOperatorMockTest method createMirrorMaker2Cluster.
private Future<Void> createMirrorMaker2Cluster(VertxTestContext context, KafkaConnectApi kafkaConnectApi, boolean reconciliationPaused) {
PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(true, KubernetesVersion.V1_16);
ResourceOperatorSupplier supplier = new ResourceOperatorSupplier(vertx, this.mockClient, new ZookeeperLeaderFinder(vertx, // Retry up to 3 times (4 attempts), with overall max delay of 35000ms
() -> new BackOff(5_000, 2, 4)), new DefaultAdminClientProvider(), new DefaultZookeeperScalerProvider(), ResourceUtils.metricsProvider(), pfa, FeatureGates.NONE, 60_000L);
ClusterOperatorConfig config = ResourceUtils.dummyClusterOperatorConfig(VERSIONS);
kco = new KafkaMirrorMaker2AssemblyOperator(vertx, pfa, supplier, config, foo -> kafkaConnectApi);
LOGGER.info("Reconciling initially -> create");
Promise<Void> created = Promise.promise();
kco.reconcile(new Reconciliation("test-trigger", KafkaMirrorMaker2.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME)).onComplete(context.succeeding(ar -> context.verify(() -> {
if (!reconciliationPaused) {
assertThat(mockClient.apps().deployments().inNamespace(NAMESPACE).withName(KafkaMirrorMaker2Resources.deploymentName(CLUSTER_NAME)).get(), is(notNullValue()));
assertThat(mockClient.configMaps().inNamespace(NAMESPACE).withName(KafkaMirrorMaker2Resources.metricsAndLogConfigMapName(CLUSTER_NAME)).get(), is(notNullValue()));
assertThat(mockClient.services().inNamespace(NAMESPACE).withName(KafkaMirrorMaker2Resources.serviceName(CLUSTER_NAME)).get(), is(notNullValue()));
assertThat(mockClient.policy().v1beta1().podDisruptionBudget().inNamespace(NAMESPACE).withName(KafkaMirrorMaker2Resources.deploymentName(CLUSTER_NAME)).get(), is(notNullValue()));
} else {
assertThat(mockClient.apps().deployments().inNamespace(NAMESPACE).withName(KafkaMirrorMaker2Resources.deploymentName(CLUSTER_NAME)).get(), is(nullValue()));
verify(mockClient, never()).resources(KafkaMirrorMaker2.class);
}
created.complete();
})));
return created.future();
}
Aggregations