use of com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData in project quick by bakdata.
the class TopicRegistryInitializer method onStartUp.
/**
* Ensures the topic registry itself and its topic are created.
*/
@EventListener
@Async
public void onStartUp(final StartupEvent event) {
// the topic registry is a basically just a mirror application
// therefore, it needs its own kafka topic
final Properties properties = new Properties();
properties.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, this.kafkaConfig.getBootstrapServer());
boolean registryExists = false;
try (final AdminClient admin = AdminClient.create(properties)) {
final NewTopic immutableTopic = this.topicRegistryConfig.toNewKafkaTopic();
admin.createTopics(List.of(immutableTopic));
} catch (final TopicExistsException ignored) {
log.info("Internal registry topic already exists");
registryExists = true;
} catch (final KafkaException e) {
throw new InternalErrorException("Kafka could not be reached: " + e.getMessage());
}
// register the avro schema of the topic data class with the schema registry
try {
final String subject = VALUE.asSubject(this.topicRegistryConfig.getTopicName());
final Schema topicDataSchema = AvroTopicData.getClassSchema();
this.schemaRegistryClient.register(subject, topicDataSchema);
} catch (final IOException | RestClientException exception) {
if (!registryExists) {
throw new InternalErrorException("Could not register schema for internal topic registry topic");
}
}
final MirrorCreationData topicRegistryCreationData = new MirrorCreationData(this.topicRegistryConfig.getServiceName(), this.topicRegistryConfig.getTopicName(), 1, // null means we use the default tag
null, null);
// create topic-registry mirror
// no retention time
this.mirrorService.createInternalMirror(topicRegistryCreationData).subscribe(() -> log.info("Deployed internal topic-registry service"), e -> log.info("Could not deploy internal topic-registry service: {}", e.getMessage())).dispose();
}
use of com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData in project quick by bakdata.
the class MirrorControllerTest method shouldCreateMirrorWithQueryValues.
@Test
void shouldCreateMirrorWithQueryValues() {
when(this.service.createMirror(any())).thenReturn(Completable.complete());
final MirrorCreationData mirrorCreationData = new MirrorCreationData(NAME, NAME, REPLICAS, TAG, null);
this.httpClient.toBlocking().exchange(POST("topic/mirror", mirrorCreationData));
verify(this.service).createMirror(mirrorCreationData);
}
use of com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData in project quick by bakdata.
the class KubernetesMirrorServiceTest method shouldCreateDeployment.
@Test
void shouldCreateDeployment() {
final MirrorCreationData mirrorCreationData = new MirrorCreationData(TOPIC_NAME, TOPIC_NAME, 1, null, null);
this.createMirror(mirrorCreationData);
final List<Deployment> items = this.getDeployments();
assertThat(items).isNotNull().hasSize(1);
final Deployment deployment = items.get(0);
assertThat(deployment.getMetadata()).hasFieldOrPropertyWithValue("name", DEPLOYMENT_NAME);
}
use of com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData in project quick by bakdata.
the class KubernetesMirrorServiceTest method shouldCreateDeletionJob.
@Test
void shouldCreateDeletionJob() {
final MirrorCreationData mirrorCreationData = new MirrorCreationData(TOPIC_NAME, TOPIC_NAME, 1, null, null);
this.createMirror(mirrorCreationData);
assertThat(this.getServices()).isNotNull().hasSize(1);
final Completable deleteRequest = this.mirrorService.deleteMirror(TOPIC_NAME);
Optional.ofNullable(deleteRequest.blockingGet()).ifPresent(Assertions::fail);
assertThat(this.client.batch().v1().jobs().list().getItems()).isNotNull().hasSize(1).first().satisfies(job -> assertThat(job.getMetadata().getName()).isEqualTo(DEPLOYMENT_NAME + "-deletion")).extracting(job -> job.getSpec().getTemplate().getSpec().getContainers(), InstanceOfAssertFactories.list(Container.class)).hasSize(1).first().satisfies(container -> assertThat(container.getArgs()).contains("--input-topics=" + TOPIC_NAME));
}
use of com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData in project quick by bakdata.
the class KubernetesMirrorServiceTest method shouldDeleteDeployment.
@Test
void shouldDeleteDeployment() {
final MirrorCreationData mirrorCreationData = new MirrorCreationData(TOPIC_NAME, TOPIC_NAME, 1, null, null);
this.createMirror(mirrorCreationData);
assertThat(this.getDeployments()).isNotNull().hasSize(1);
final Completable deleteRequest = this.mirrorService.deleteMirror(TOPIC_NAME);
Optional.ofNullable(deleteRequest.blockingGet()).ifPresent(Assertions::fail);
assertThat(this.getDeployments()).isNullOrEmpty();
}
Aggregations