use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi by strimzi.
the class MockK8s method createResource.
@Override
public Future<KafkaTopic> createResource(KafkaTopic topicResource) {
Promise<KafkaTopic> handler = Promise.promise();
AsyncResult<Void> response = createResponse.apply(new ResourceName(topicResource));
if (response.succeeded()) {
AsyncResult<KafkaTopic> old = byName.put(new ResourceName(topicResource), Future.succeededFuture(topicResource));
if (old != null) {
handler.handle(Future.failedFuture("resource already existed: " + topicResource.getMetadata().getName()));
return handler.future();
}
}
if (response.succeeded()) {
handler.complete(new KafkaTopicBuilder(topicResource).editMetadata().withGeneration(1L).endMetadata().build());
} else {
handler.fail(response.cause());
}
return handler.future();
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi by strimzi.
the class MockK8s method updateResource.
@Override
public Future<KafkaTopic> updateResource(KafkaTopic topicResource) {
Promise<KafkaTopic> handler = Promise.promise();
AsyncResult<Void> response = modifyResponse.apply(new ResourceName(topicResource));
if (response.succeeded()) {
AsyncResult<KafkaTopic> old = byName.put(new ResourceName(topicResource), Future.succeededFuture(topicResource));
if (old == null) {
handler.handle(Future.failedFuture("resource does not exist, cannot be updated: " + topicResource.getMetadata().getName()));
return handler.future();
}
}
if (response.succeeded()) {
Long generation = topicResource.getMetadata().getGeneration();
handler.complete(new KafkaTopicBuilder(topicResource).editMetadata().withGeneration(generation != null ? generation + 1 : 1).endMetadata().build());
} else {
handler.fail(response.cause());
}
return handler.future();
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi by strimzi.
the class MockK8s method updateResourceStatus.
@Override
public Future<KafkaTopic> updateResourceStatus(Reconciliation reconciliation, KafkaTopic topicResource) {
statuses.add(new KafkaTopicStatusBuilder(topicResource.getStatus()).build());
Long generation = topicResource.getMetadata().getGeneration();
return Future.succeededFuture(new KafkaTopicBuilder(topicResource).editMetadata().withGeneration(generation == null ? 1 : generation + 1).endMetadata().build());
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi-kafka-operator by strimzi.
the class TopicOperatorTest method testOnKafkaTopicAdded_invalidResource.
/**
* Test what happens when a non-topic KafkaTopic gets created in kubernetes
*/
@Test
public void testOnKafkaTopicAdded_invalidResource(VertxTestContext context) {
KafkaTopic kafkaTopic = new KafkaTopicBuilder().withMetadata(new ObjectMetaBuilder().withName("invalid").withLabels(labels.labels()).build()).withNewSpec().withReplicas(1).withPartitions(1).withConfig(singletonMap(null, null)).endSpec().build();
String errorMessage = "KafkaTopic's spec.config has invalid entry: The key 'null' of the topic config is invalid: The value corresponding to the key must have a string, number or boolean value but the value was null";
mockK8s.setGetFromNameResponse(new ResourceName(kafkaTopic), Future.succeededFuture(kafkaTopic));
LogContext logContext = LogContext.kubeWatch(Watcher.Action.ADDED, kafkaTopic);
Checkpoint async = context.checkpoint();
topicOperator.onResourceEvent(logContext, kafkaTopic, ADDED).onComplete(ar -> {
assertFailed(context, ar);
context.verify(() -> assertThat(ar.cause(), instanceOf(InvalidTopicException.class)));
context.verify(() -> assertThat(ar.cause().getMessage(), is(errorMessage)));
mockKafka.assertEmpty(context);
mockTopicStore.assertEmpty(context);
assertNotReadyStatus(context, new InvalidTopicException(null, ar.cause().getMessage()));
context.verify(() -> {
MeterRegistry registry = metrics.meterRegistry();
assertThat(registry.get(TopicOperator.METRICS_PREFIX + "reconciliations").tag("kind", "KafkaTopic").counter().count(), is(0.0));
assertThat(registry.get(TopicOperator.METRICS_PREFIX + "reconciliations.successful").tag("kind", "KafkaTopic").counter().count(), is(0.0));
assertThat(registry.get(TopicOperator.METRICS_PREFIX + "reconciliations.failed").tag("kind", "KafkaTopic").counter().count(), is(0.0));
assertThat(registry.get(TopicOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "KafkaTopic").timer().count(), is(0L));
assertThat(registry.get(TopicOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "KafkaTopic").timer().totalTime(TimeUnit.MILLISECONDS), is(0.0));
assertThat(registry.get(TopicOperator.METRICS_PREFIX + "resource.state").tag("kind", "KafkaTopic").tag("name", "invalid").tag("resource-namespace", "default-namespace").tag("reason", errorMessage).gauge().value(), is(0.0));
});
async.flag();
});
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi-kafka-operator by strimzi.
the class TopicOperatorTest method testOnKafkaTopicAdded_ignorable.
/**
* Test what happens when a non-topic KafkaTopic gets created in kubernetes
*/
@Test
public void testOnKafkaTopicAdded_ignorable(VertxTestContext context) {
KafkaTopic kafkaTopic = new KafkaTopicBuilder().withMetadata(new ObjectMetaBuilder().withName("non-topic").build()).build();
Checkpoint async = context.checkpoint();
K8sTopicWatcher w = new K8sTopicWatcher(topicOperator, Future.succeededFuture(), () -> {
});
w.eventReceived(ADDED, kafkaTopic);
mockKafka.assertEmpty(context);
mockTopicStore.assertEmpty(context);
async.flag();
}
Aggregations