Search in sources :

Example 61 with KafkaConnector

use of io.strimzi.api.kafka.model.KafkaConnector in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class KafkaConnectorSteps method kc_config_contains.

@And("the kctr has config containing:")
public void kc_config_contains(DataTable table) {
    KafkaConnector res = kctr();
    assertThat(res).isNotNull();
    assertThatDataTable(table, ctx::resolvePlaceholders).matches(res.getSpec().getConfig());
}
Also used : KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) And(io.cucumber.java.en.And)

Example 62 with KafkaConnector

use of io.strimzi.api.kafka.model.KafkaConnector in project strimzi by strimzi.

the class ConnectorMockTest method testConnectorConnectConnectorConnect.

/**
 * Create connector, create connect, delete connector, delete connect
 */
@Test
public void testConnectorConnectConnectorConnect() {
    String connectName = "cluster";
    String connectorName = "connector";
    // Create KafkaConnector and wait till it's ready
    KafkaConnector connector = new KafkaConnectorBuilder().withNewMetadata().withName(connectorName).withNamespace(NAMESPACE).addToLabels(Labels.STRIMZI_CLUSTER_LABEL, connectName).endMetadata().withNewSpec().endSpec().build();
    Crds.kafkaConnectorOperation(client).inNamespace(NAMESPACE).create(connector);
    waitForConnectorNotReady(connectorName, "NoSuchResourceException", "KafkaConnect resource 'cluster' identified by label '" + Labels.STRIMZI_CLUSTER_LABEL + "' does not exist in namespace ns.");
    verify(api, never()).list(eq(KafkaConnectResources.qualifiedServiceName(connectName, NAMESPACE)), eq(KafkaConnectCluster.REST_API_PORT));
    verify(api, never()).createOrUpdatePutRequest(any(), eq(KafkaConnectResources.qualifiedServiceName(connectName, NAMESPACE)), eq(KafkaConnectCluster.REST_API_PORT), eq(connectorName), any());
    assertThat(runningConnectors.keySet(), is(empty()));
    // Create KafkaConnect cluster and wait till it's ready
    KafkaConnect connect = new KafkaConnectBuilder().withNewMetadata().withNamespace(NAMESPACE).withName(connectName).addToAnnotations(Annotations.STRIMZI_IO_USE_CONNECTOR_RESOURCES, "true").endMetadata().withNewSpec().withReplicas(1).endSpec().build();
    Crds.kafkaConnectOperation(client).inNamespace(NAMESPACE).create(connect);
    waitForConnectReady(connectName);
    // could be triggered twice (creation followed by status update) but waitForConnectReady could be satisfied with single
    verify(api, atLeastOnce()).list(eq(KafkaConnectResources.qualifiedServiceName(connectName, NAMESPACE)), eq(KafkaConnectCluster.REST_API_PORT));
    // triggered three times (Connect creation, Connector Status update, Connect Status update)
    verify(api, times(3)).createOrUpdatePutRequest(any(), eq(KafkaConnectResources.qualifiedServiceName(connectName, NAMESPACE)), eq(KafkaConnectCluster.REST_API_PORT), eq(connectorName), any());
    assertThat(runningConnectors.keySet(), is(Collections.singleton(key("cluster-connect-api.ns.svc", connectorName))));
    boolean connectorDeleted = Crds.kafkaConnectorOperation(client).inNamespace(NAMESPACE).withName(connectorName).delete();
    assertThat(connectorDeleted, is(true));
    waitFor("delete call on connect REST api", 1_000, 30_000, () -> runningConnectors.isEmpty());
    verify(api).delete(any(), eq(KafkaConnectResources.qualifiedServiceName(connectName, NAMESPACE)), eq(KafkaConnectCluster.REST_API_PORT), eq(connectorName));
    boolean connectDeleted = Crds.kafkaConnectOperation(client).inNamespace(NAMESPACE).withName(connectName).delete();
    assertThat(connectDeleted, is(true));
}
Also used : KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) KafkaConnectorBuilder(io.strimzi.api.kafka.model.KafkaConnectorBuilder) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) Test(org.junit.jupiter.api.Test)

Example 63 with KafkaConnector

use of io.strimzi.api.kafka.model.KafkaConnector in project strimzi by strimzi.

the class ConnectorMockTest method testConnectorNotReadyWhenConnectDoesNotExist.

@Test
public void testConnectorNotReadyWhenConnectDoesNotExist() {
    String connectorName = "connector";
    KafkaConnector connector = new KafkaConnectorBuilder().withNewMetadata().withNamespace(NAMESPACE).withName(connectorName).addToLabels(Labels.STRIMZI_CLUSTER_LABEL, "cluster").endMetadata().build();
    Crds.kafkaConnectorOperation(client).inNamespace(NAMESPACE).create(connector);
    waitForConnectorNotReady(connectorName, "NoSuchResourceException", "KafkaConnect resource 'cluster' identified by label '" + Labels.STRIMZI_CLUSTER_LABEL + "' does not exist in namespace ns.");
}
Also used : KafkaConnectorBuilder(io.strimzi.api.kafka.model.KafkaConnectorBuilder) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 64 with KafkaConnector

use of io.strimzi.api.kafka.model.KafkaConnector in project strimzi by strimzi.

the class ConnectorMockTest method waitForConnectorState.

public void waitForConnectorState(String connectorName, String state) {
    Resource<KafkaConnector> resource = Crds.kafkaConnectorOperation(client).inNamespace(NAMESPACE).withName(connectorName);
    waitForStatus(resource, connectorName, s -> {
        Map<String, Object> connector = s.getStatus().getConnectorStatus();
        if (connector != null) {
            Object connectorState = ((Map) connector.getOrDefault("connector", emptyMap())).get("state");
            return connectorState instanceof String && state.equals(connectorState);
        } else {
            return false;
        }
    });
}
Also used : KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) JsonObject(io.vertx.core.json.JsonObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Map(java.util.Map) HashMap(java.util.HashMap) Collections.emptyMap(java.util.Collections.emptyMap)

Example 65 with KafkaConnector

use of io.strimzi.api.kafka.model.KafkaConnector in project strimzi by strimzi.

the class ConnectorMockTest method testConnectRestAPIIssues.

/**
 * Create connect, create connector, break the REST API
 */
@Test
public void testConnectRestAPIIssues() {
    String connectName = "cluster";
    String connectorName = "connector";
    // Create KafkaConnect cluster and wait till it's ready
    KafkaConnect connect = new KafkaConnectBuilder().withNewMetadata().withNamespace(NAMESPACE).withName(connectName).addToAnnotations(Annotations.STRIMZI_IO_USE_CONNECTOR_RESOURCES, "true").endMetadata().withNewSpec().withReplicas(1).endSpec().build();
    Crds.kafkaConnectOperation(client).inNamespace(NAMESPACE).create(connect);
    waitForConnectReady(connectName);
    // could be triggered twice (creation followed by status update) but waitForConnectReady could be satisfied with single
    verify(api, atLeastOnce()).list(eq(KafkaConnectResources.qualifiedServiceName(connectName, NAMESPACE)), eq(KafkaConnectCluster.REST_API_PORT));
    verify(api, never()).createOrUpdatePutRequest(any(), eq(KafkaConnectResources.qualifiedServiceName(connectName, NAMESPACE)), eq(KafkaConnectCluster.REST_API_PORT), eq(connectorName), any());
    // Create KafkaConnector and wait till it's ready
    KafkaConnector connector = new KafkaConnectorBuilder().withNewMetadata().withName(connectorName).withNamespace(NAMESPACE).addToLabels(Labels.STRIMZI_CLUSTER_LABEL, connectName).endMetadata().withNewSpec().withTasksMax(1).withClassName("Dummy").endSpec().build();
    Crds.kafkaConnectorOperation(client).inNamespace(NAMESPACE).create(connector);
    waitForConnectorReady(connectorName);
    verify(api, times(2)).list(eq(KafkaConnectResources.qualifiedServiceName(connectName, NAMESPACE)), eq(KafkaConnectCluster.REST_API_PORT));
    verify(api, times(1)).createOrUpdatePutRequest(any(), eq(KafkaConnectResources.qualifiedServiceName(connectName, NAMESPACE)), eq(KafkaConnectCluster.REST_API_PORT), eq(connectorName), any());
    assertThat(runningConnectors.keySet(), is(Collections.singleton(key("cluster-connect-api.ns.svc", connectorName))));
    when(api.list(any(), anyInt())).thenReturn(Future.failedFuture(new ConnectTimeoutException("connection timed out")));
    when(api.listConnectorPlugins(any(), any(), anyInt())).thenReturn(Future.failedFuture(new ConnectTimeoutException("connection timed out")));
    when(api.createOrUpdatePutRequest(any(), any(), anyInt(), anyString(), any())).thenReturn(Future.failedFuture(new ConnectTimeoutException("connection timed out")));
    when(api.getConnectorConfig(any(), any(), any(), anyInt(), any())).thenReturn(Future.failedFuture(new ConnectTimeoutException("connection timed out")));
    when(api.getConnector(any(), any(), anyInt(), any())).thenReturn(Future.failedFuture(new ConnectTimeoutException("connection timed out")));
    Crds.kafkaConnectOperation(client).inNamespace(NAMESPACE).withName(connectName).edit(sp -> new KafkaConnectBuilder(sp).editSpec().withNewTemplate().endTemplate().endSpec().build());
    // Wait for Status change due to the broker REST API
    waitForConnectNotReady(connectName, "ConnectTimeoutException", "connection timed out");
    waitForConnectorNotReady(connectorName, "ConnectTimeoutException", "connection timed out");
}
Also used : KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) KafkaConnectorBuilder(io.strimzi.api.kafka.model.KafkaConnectorBuilder) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) ConnectTimeoutException(io.netty.channel.ConnectTimeoutException) Test(org.junit.jupiter.api.Test)

Aggregations

KafkaConnector (io.strimzi.api.kafka.model.KafkaConnector)113 Test (org.junit.jupiter.api.Test)82 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)82 KafkaConnect (io.strimzi.api.kafka.model.KafkaConnect)79 KafkaConnectBuilder (io.strimzi.api.kafka.model.KafkaConnectBuilder)65 KafkaConnectorList (io.strimzi.api.kafka.KafkaConnectorList)60 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)58 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)58 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)58 Reconciliation (io.strimzi.operator.common.Reconciliation)58 Future (io.vertx.core.Future)58 Vertx (io.vertx.core.Vertx)58 List (java.util.List)57 KafkaConnectResources (io.strimzi.api.kafka.model.KafkaConnectResources)56 KafkaConnectCluster (io.strimzi.operator.cluster.model.KafkaConnectCluster)56 Annotations (io.strimzi.operator.common.Annotations)56 KubernetesVersion (io.strimzi.operator.KubernetesVersion)54 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)54 CrdOperator (io.strimzi.operator.common.operator.resource.CrdOperator)54 Checkpoint (io.vertx.junit5.Checkpoint)54