Search in sources :

Example 11 with MirrorCreationData

use of com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData in project quick by bakdata.

the class MirrorResourceLoaderTest method shouldCreateMirrorService.

@Test
void shouldCreateMirrorService() {
    final MirrorCreationData mirrorCreationData = new MirrorCreationData(DEFAULT_NAME, DEFAULT_TOPIC_NAME, 3, "snapshot", null);
    final MirrorResources mirrorResources = this.loader.forCreation(mirrorCreationData, ResourcePrefix.MIRROR);
    final Optional<HasMetadata> hasMetadata = findResource(mirrorResources, ResourceKind.SERVICE);
    final Map<String, String> labels = Map.of("app.kubernetes.io/name", DEFAULT_DEPLOYMENT_NAME, "app.kubernetes.io/managed-by", "quick", "app.kubernetes.io/component", "mirror");
    final Map<String, String> selectors = Map.of("app.kubernetes.io/name", DEFAULT_DEPLOYMENT_NAME, "app.kubernetes.io/component", "mirror");
    assertThat(hasMetadata).isPresent().get(InstanceOfAssertFactories.type(Service.class)).satisfies(service -> {
        assertThat(service.getMetadata()).hasFieldOrPropertyWithValue("name", DEFAULT_DEPLOYMENT_NAME).extracting(ObjectMeta::getLabels, MAP).isNotNull().containsExactlyInAnyOrderEntriesOf(labels);
        final ServiceSpec serviceSpec = service.getSpec();
        assertThat(serviceSpec.getSelector()).containsExactlyInAnyOrderEntriesOf(selectors);
        assertThat(serviceSpec.getPorts()).hasSize(1).first().hasFieldOrPropertyWithValue("protocol", "TCP").hasFieldOrPropertyWithValue("port", KubernetesResources.SERVICE_PORT).hasFieldOrPropertyWithValue("targetPort", new IntOrString(KubernetesResources.CONTAINER_PORT));
    });
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) MirrorCreationData(com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData) KubernetesTest(com.bakdata.quick.manager.k8s.KubernetesTest) Test(org.junit.jupiter.api.Test)

Example 12 with MirrorCreationData

use of com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData in project quick by bakdata.

the class KafkaTopicServiceTest method shouldSetRetentionTime.

@Test
void shouldSetRetentionTime() {
    final String topicName = UUID.randomUUID().toString();
    this.successfulMock();
    when(this.gatewayService.getGateway(GATEWAY_SCHEMA.getGateway())).thenReturn(Single.just(new GatewayDescription("test", 1, "latest")));
    when(this.gatewayClient.getWriteSchema(anyString(), anyString())).thenReturn(Single.just(new SchemaData(SCHEMA)));
    final Duration retentionTime = Duration.ofMinutes(30);
    final TopicCreationData requestData = new TopicCreationData(TopicWriteType.MUTABLE, GATEWAY_SCHEMA, null, retentionTime);
    final Completable completable = this.topicService.createTopic(topicName, QuickTopicType.DOUBLE, QuickTopicType.DOUBLE, requestData);
    assertThat(completable.blockingGet()).isNull();
    final MirrorCreationData mirrorCreationData = new MirrorCreationData(topicName, topicName, 1, null, retentionTime);
    verify(this.mirrorService).createMirror(mirrorCreationData);
}
Also used : TopicCreationData(com.bakdata.quick.common.api.model.manager.creation.TopicCreationData) Completable(io.reactivex.Completable) SchemaData(com.bakdata.quick.common.api.model.gateway.SchemaData) GatewayDescription(com.bakdata.quick.common.api.model.manager.GatewayDescription) Duration(java.time.Duration) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MirrorCreationData(com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData) Test(org.junit.jupiter.api.Test)

Example 13 with MirrorCreationData

use of com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData in project quick by bakdata.

the class KafkaTopicService method createMirror.

private Completable createMirror(final String name, final Duration retentionTime) {
    return Completable.defer(() -> {
        log.debug("Create mirror for topic {}", name);
        final MirrorCreationData mirrorCreationData = new MirrorCreationData(name, name, 1, // use default tag
        null, retentionTime);
        return this.mirrorService.createMirror(mirrorCreationData);
    });
}
Also used : MirrorCreationData(com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData)

Example 14 with MirrorCreationData

use of com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData in project quick by bakdata.

the class TopicRegistryInitializerTest method shouldCreateMirror.

@Test
void shouldCreateMirror() {
    final String topicName = UUID.randomUUID().toString();
    this.successfulMock();
    final KafkaConfig kafkaConfig = new KafkaConfig(kafkaCluster.getBrokerList(), this.schemaRegistry.getUrl());
    final TopicRegistryConfig registryConfig = new TopicRegistryConfig(topicName, TEST_NAME, 3, (short) 1);
    final TopicRegistryInitializer topicRegistryInitializer = new TopicRegistryInitializer(kafkaConfig, registryConfig, this.mock);
    topicRegistryInitializer.onStartUp(new StartupEvent(this.applicationContext));
    final MirrorCreationData mirrorCreationData = new MirrorCreationData(TEST_NAME, topicName, 1, null, null);
    verify(this.mock).createInternalMirror(mirrorCreationData);
}
Also used : StartupEvent(io.micronaut.context.event.StartupEvent) TopicRegistryConfig(com.bakdata.quick.common.config.TopicRegistryConfig) KafkaConfig(com.bakdata.quick.common.config.KafkaConfig) MirrorCreationData(com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData) Test(org.junit.jupiter.api.Test)

Example 15 with MirrorCreationData

use of com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData in project quick by bakdata.

the class ImageUpdaterTest method shouldUpdateMultipleMirrors.

@Test
void shouldUpdateMultipleMirrors() {
    final MirrorResourceLoader loader = new MirrorResourceLoader(new KubernetesResources(), this.getDeploymentConfig(), this.getResourceConfig());
    final MirrorService mirrorService = new KubernetesMirrorService(new KubernetesResources(), this.getManagerClient(), this.getDeploymentConfig(), loader);
    final MirrorCreationData mirrorCreationData1 = new MirrorCreationData("topic", "service", 1, // use default tag
    null, null);
    mirrorService.createMirror(mirrorCreationData1).blockingAwait();
    final MirrorCreationData mirrorCreationData2 = new MirrorCreationData("topic2", "service2", 1, // use default tag
    null, null);
    mirrorService.createMirror(mirrorCreationData2).blockingAwait();
    assertThat(this.getDeployments()).hasSize(2).extracting(ImageUpdaterTest::getContainerImage).allMatch(name -> name.equals(String.format("%s/%s:%s", DOCKER_REGISTRY, MIRROR_IMAGE, DEFAULT_IMAGE_TAG)));
    final DeploymentConfig newDeploymentConfig = this.createNewDeploymentConfig();
    final ImageUpdater imageUpdater = new ImageUpdater(this.client, newDeploymentConfig);
    imageUpdater.updateManagedDeployments();
    assertThat(this.getDeployments()).hasSize(2).extracting(ImageUpdaterTest::getContainerImage).allMatch(name -> name.equals(String.format("%s/%s:%s", DOCKER_REGISTRY, MIRROR_IMAGE, NEW_TAG)));
}
Also used : MirrorResourceLoader(com.bakdata.quick.manager.mirror.resources.MirrorResourceLoader) KubernetesMirrorService(com.bakdata.quick.manager.mirror.KubernetesMirrorService) MirrorService(com.bakdata.quick.manager.mirror.MirrorService) KubernetesResources(com.bakdata.quick.manager.k8s.KubernetesResources) KubernetesMirrorService(com.bakdata.quick.manager.mirror.KubernetesMirrorService) DeploymentConfig(com.bakdata.quick.manager.config.DeploymentConfig) MirrorCreationData(com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData) KubernetesTest(com.bakdata.quick.manager.k8s.KubernetesTest) Test(org.junit.jupiter.api.Test)

Aggregations

MirrorCreationData (com.bakdata.quick.common.api.model.manager.creation.MirrorCreationData)23 Test (org.junit.jupiter.api.Test)21 KubernetesTest (com.bakdata.quick.manager.k8s.KubernetesTest)17 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)7 KubernetesResources (com.bakdata.quick.manager.k8s.KubernetesResources)5 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)5 MirrorService (com.bakdata.quick.manager.mirror.MirrorService)4 MirrorResourceLoader (com.bakdata.quick.manager.mirror.resources.MirrorResourceLoader)4 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)4 Service (io.fabric8.kubernetes.api.model.Service)4 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)4 Completable (io.reactivex.Completable)4 DeploymentConfig (com.bakdata.quick.manager.config.DeploymentConfig)3 KubernetesMirrorService (com.bakdata.quick.manager.mirror.KubernetesMirrorService)3 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)3 ServiceSpec (io.fabric8.kubernetes.api.model.ServiceSpec)3 DeploymentSpec (io.fabric8.kubernetes.api.model.apps.DeploymentSpec)3 Duration (java.time.Duration)3 Assertions (org.junit.jupiter.api.Assertions)3 KafkaConfig (com.bakdata.quick.common.config.KafkaConfig)2