Search in sources :

Example 6 with ListenerStatusBuilder

use of io.strimzi.api.kafka.model.status.ListenerStatusBuilder in project strimzi by strimzi.

the class StatusDiffTest method testTimestampDiff.

@ParallelTest
public void testTimestampDiff() throws ParseException {
    ListenerStatus ls1 = new ListenerStatusBuilder().withName("plain").withAddresses(new ListenerAddressBuilder().withHost("my-service.my-namespace.svc").withPort(9092).build()).build();
    ListenerStatus ls2 = new ListenerStatusBuilder().withName("tls").withAddresses(new ListenerAddressBuilder().withHost("my-service.my-namespace.svc").withPort(9093).build()).build();
    Condition condition1 = new ConditionBuilder().withLastTransitionTime(StatusUtils.iso8601(new Date())).withType("Ready").withStatus("True").build();
    Condition condition2 = new ConditionBuilder().withLastTransitionTime(StatusUtils.iso8601(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse("2011-01-01 00:00:00"))).withType("Ready").withStatus("True").build();
    KafkaStatus status1 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls1, ls2).build();
    KafkaStatus status2 = new KafkaStatusBuilder().withConditions(condition2).withListeners(ls1, ls2).build();
    StatusDiff diff = new StatusDiff(status1, status2);
    assertThat(diff.isEmpty(), is(true));
}
Also used : ListenerAddressBuilder(io.strimzi.api.kafka.model.status.ListenerAddressBuilder) Condition(io.strimzi.api.kafka.model.status.Condition) ListenerStatus(io.strimzi.api.kafka.model.status.ListenerStatus) ConditionBuilder(io.strimzi.api.kafka.model.status.ConditionBuilder) KafkaStatusBuilder(io.strimzi.api.kafka.model.status.KafkaStatusBuilder) ListenerStatusBuilder(io.strimzi.api.kafka.model.status.ListenerStatusBuilder) SimpleDateFormat(java.text.SimpleDateFormat) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus) Date(java.util.Date) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 7 with ListenerStatusBuilder

use of io.strimzi.api.kafka.model.status.ListenerStatusBuilder in project strimzi by strimzi.

the class KafkaTest method testListenerTypeAndNameInStatus.

@Test
public void testListenerTypeAndNameInStatus() throws ParseException, URISyntaxException {
    Kafka kafka = new KafkaBuilder().withNewMetadata().withName("my-cluster").withNamespace("my-namespace").withGeneration(2L).endMetadata().withNewSpec().withNewKafka().withReplicas(3).withListeners(new GenericKafkaListenerBuilder().withName("plain").withPort(9092).withType(KafkaListenerType.INTERNAL).withTls(false).build()).withNewEphemeralStorage().endEphemeralStorage().endKafka().withNewZookeeper().withReplicas(3).withNewEphemeralStorage().endEphemeralStorage().endZookeeper().endSpec().withNewStatus().withObservedGeneration(1L).withConditions(new ConditionBuilder().withType("Ready").withStatus("True").build()).withListeners(new ListenerStatusBuilder().withName("plain").withAddresses(new ListenerAddressBuilder().withHost("my-service.my-namespace.svc").withPort(9092).build()).build(), new ListenerStatusBuilder().withName("external").withAddresses(new ListenerAddressBuilder().withHost("my-route-address.domain.tld").withPort(443).build()).build()).endStatus().build();
    String path = Objects.requireNonNull(this.getClass().getResource("Kafka-listener-name-and-status.yaml")).toURI().getPath();
    assertThat(TestUtils.toYamlString(kafka), is(TestUtils.getFileAsString(path)));
}
Also used : ListenerAddressBuilder(io.strimzi.api.kafka.model.status.ListenerAddressBuilder) ConditionBuilder(io.strimzi.api.kafka.model.status.ConditionBuilder) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) ListenerStatusBuilder(io.strimzi.api.kafka.model.status.ListenerStatusBuilder) Test(org.junit.jupiter.api.Test)

Example 8 with ListenerStatusBuilder

use of io.strimzi.api.kafka.model.status.ListenerStatusBuilder in project strimzi-kafka-operator by strimzi.

the class StatusDiffTest method testStatusDiff.

@ParallelTest
public void testStatusDiff() {
    ListenerStatus ls1 = new ListenerStatusBuilder().withName("plain").withAddresses(new ListenerAddressBuilder().withHost("my-service.my-namespace.svc").withPort(9092).build()).build();
    ListenerStatus ls2 = new ListenerStatusBuilder().withName("tls").withAddresses(new ListenerAddressBuilder().withHost("my-service.my-namespace.svc").withPort(9093).build()).build();
    ListenerStatus ls3 = new ListenerStatusBuilder().withName("tls").withAddresses(new ListenerAddressBuilder().withHost("my-service.my-namespace.svc").withPort(9094).build()).build();
    Condition condition1 = new ConditionBuilder().withLastTransitionTime(StatusUtils.iso8601(new Date())).withType("Ready").withStatus("True").build();
    Condition condition2 = new ConditionBuilder().withLastTransitionTime(StatusUtils.iso8601(new Date())).withType("Ready2").withStatus("True").build();
    KafkaStatus status1 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls1).build();
    KafkaStatus status2 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls1).build();
    KafkaStatus status3 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls1, ls2).build();
    KafkaStatus status4 = new KafkaStatusBuilder().withConditions(condition1, condition2).withListeners(ls1).build();
    KafkaStatus status5 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls1, ls3).build();
    KafkaStatus status6 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls3, ls1).build();
    StatusDiff diff = new StatusDiff(status1, status2);
    assertThat(diff.isEmpty(), is(true));
    diff = new StatusDiff(status1, status3);
    assertThat(diff.isEmpty(), is(false));
    diff = new StatusDiff(status1, status4);
    assertThat(diff.isEmpty(), is(false));
    diff = new StatusDiff(status3, status4);
    assertThat(diff.isEmpty(), is(false));
    diff = new StatusDiff(status3, status5);
    assertThat(diff.isEmpty(), is(false));
    diff = new StatusDiff(status5, status6);
    assertThat(diff.isEmpty(), is(false));
}
Also used : ListenerAddressBuilder(io.strimzi.api.kafka.model.status.ListenerAddressBuilder) Condition(io.strimzi.api.kafka.model.status.Condition) ListenerStatus(io.strimzi.api.kafka.model.status.ListenerStatus) ConditionBuilder(io.strimzi.api.kafka.model.status.ConditionBuilder) KafkaStatusBuilder(io.strimzi.api.kafka.model.status.KafkaStatusBuilder) ListenerStatusBuilder(io.strimzi.api.kafka.model.status.ListenerStatusBuilder) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus) Date(java.util.Date) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 9 with ListenerStatusBuilder

use of io.strimzi.api.kafka.model.status.ListenerStatusBuilder in project strimzi-kafka-operator by strimzi.

the class StatusDiffTest method testTimestampDiff.

@ParallelTest
public void testTimestampDiff() throws ParseException {
    ListenerStatus ls1 = new ListenerStatusBuilder().withName("plain").withAddresses(new ListenerAddressBuilder().withHost("my-service.my-namespace.svc").withPort(9092).build()).build();
    ListenerStatus ls2 = new ListenerStatusBuilder().withName("tls").withAddresses(new ListenerAddressBuilder().withHost("my-service.my-namespace.svc").withPort(9093).build()).build();
    Condition condition1 = new ConditionBuilder().withLastTransitionTime(StatusUtils.iso8601(new Date())).withType("Ready").withStatus("True").build();
    Condition condition2 = new ConditionBuilder().withLastTransitionTime(StatusUtils.iso8601(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse("2011-01-01 00:00:00"))).withType("Ready").withStatus("True").build();
    KafkaStatus status1 = new KafkaStatusBuilder().withConditions(condition1).withListeners(ls1, ls2).build();
    KafkaStatus status2 = new KafkaStatusBuilder().withConditions(condition2).withListeners(ls1, ls2).build();
    StatusDiff diff = new StatusDiff(status1, status2);
    assertThat(diff.isEmpty(), is(true));
}
Also used : ListenerAddressBuilder(io.strimzi.api.kafka.model.status.ListenerAddressBuilder) Condition(io.strimzi.api.kafka.model.status.Condition) ListenerStatus(io.strimzi.api.kafka.model.status.ListenerStatus) ConditionBuilder(io.strimzi.api.kafka.model.status.ConditionBuilder) KafkaStatusBuilder(io.strimzi.api.kafka.model.status.KafkaStatusBuilder) ListenerStatusBuilder(io.strimzi.api.kafka.model.status.ListenerStatusBuilder) SimpleDateFormat(java.text.SimpleDateFormat) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus) Date(java.util.Date) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 10 with ListenerStatusBuilder

use of io.strimzi.api.kafka.model.status.ListenerStatusBuilder in project strimzi-kafka-operator by strimzi.

the class KafkaStatusTest method testStatusAfterSuccessfulReconciliationWithPreviousSuccess.

@Test
public void testStatusAfterSuccessfulReconciliationWithPreviousSuccess(VertxTestContext context) throws ParseException {
    Kafka kafka = getKafkaCrd();
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    // Mock the Kafka Operator
    CrdOperator mockKafkaOps = supplier.kafkaOperator;
    Kafka readyKafka = new KafkaBuilder(kafka).editStatus().withObservedGeneration(2L).editCondition(0).withType("Ready").endCondition().withListeners(new ListenerStatusBuilder().withName("plain").withAddresses(new ListenerAddressBuilder().withHost("my-service.my-namespace.svc").withPort(9092).build()).build(), new ListenerStatusBuilder().withName("external").withAddresses(new ListenerAddressBuilder().withHost("my-route-address.domain.tld").withPort(443).build()).build()).endStatus().build();
    when(mockKafkaOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(readyKafka));
    ArgumentCaptor<Kafka> kafkaCaptor = ArgumentCaptor.forClass(Kafka.class);
    when(mockKafkaOps.updateStatusAsync(any(), kafkaCaptor.capture())).thenReturn(Future.succeededFuture());
    MockWorkingKafkaAssemblyOperator kao = new MockWorkingKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config);
    Checkpoint async = context.checkpoint();
    kao.createOrUpdate(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName), kafka).onComplete(res -> {
        assertThat(res.succeeded(), is(true));
        // The status should not change => we test that updateStatusAsync was not called
        assertThat(kafkaCaptor.getAllValues().size(), is(0));
        async.flag();
    });
}
Also used : ListenerAddressBuilder(io.strimzi.api.kafka.model.status.ListenerAddressBuilder) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Checkpoint(io.vertx.junit5.Checkpoint) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) Reconciliation(io.strimzi.operator.common.Reconciliation) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ListenerStatusBuilder(io.strimzi.api.kafka.model.status.ListenerStatusBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

ListenerAddressBuilder (io.strimzi.api.kafka.model.status.ListenerAddressBuilder)10 ListenerStatusBuilder (io.strimzi.api.kafka.model.status.ListenerStatusBuilder)10 ConditionBuilder (io.strimzi.api.kafka.model.status.ConditionBuilder)6 KafkaStatus (io.strimzi.api.kafka.model.status.KafkaStatus)6 Test (org.junit.jupiter.api.Test)6 Kafka (io.strimzi.api.kafka.model.Kafka)4 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)4 Condition (io.strimzi.api.kafka.model.status.Condition)4 KafkaStatusBuilder (io.strimzi.api.kafka.model.status.KafkaStatusBuilder)4 ListenerStatus (io.strimzi.api.kafka.model.status.ListenerStatus)4 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)4 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)4 Reconciliation (io.strimzi.operator.common.Reconciliation)4 CrdOperator (io.strimzi.operator.common.operator.resource.CrdOperator)4 ParallelTest (io.strimzi.test.annotations.ParallelTest)4 Checkpoint (io.vertx.junit5.Checkpoint)4 Date (java.util.Date)4 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)2 SimpleDateFormat (java.text.SimpleDateFormat)2