Search in sources :

Example 16 with KafkaConnectorBuilder

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

the class AbstractConnectOperator method maybeUpdateConnectorStatus.

Future<Void> maybeUpdateConnectorStatus(Reconciliation reconciliation, KafkaConnector connector, ConnectorStatusAndConditions connectorStatus, Throwable error) {
    KafkaConnectorStatus status = new KafkaConnectorStatus();
    if (error != null) {
        LOGGER.warnCr(reconciliation, "Error reconciling connector {}", connector.getMetadata().getName(), error);
    }
    Map<String, Object> statusResult = null;
    List<String> topics = new ArrayList<>();
    List<Condition> conditions = new ArrayList<>();
    if (connectorStatus != null) {
        statusResult = connectorStatus.statusResult;
        topics = connectorStatus.topics.stream().sorted().collect(Collectors.toList());
        connectorStatus.conditions.forEach(condition -> conditions.add(condition));
    }
    Set<Condition> unknownAndDeprecatedConditions = validate(reconciliation, connector);
    unknownAndDeprecatedConditions.forEach(condition -> conditions.add(condition));
    if (!Annotations.isReconciliationPausedWithAnnotation(connector)) {
        StatusUtils.setStatusConditionAndObservedGeneration(connector, status, error != null ? Future.failedFuture(error) : Future.succeededFuture());
        status.setConnectorStatus(statusResult);
        status.setTasksMax(getActualTaskCount(connector, statusResult));
        status.setTopics(topics);
    } else {
        status.setObservedGeneration(connector.getStatus() != null ? connector.getStatus().getObservedGeneration() : 0);
        conditions.add(StatusUtils.getPausedCondition());
    }
    status.addConditions(conditions);
    return maybeUpdateStatusCommon(connectorOperator, connector, reconciliation, status, (connector1, status1) -> {
        return new KafkaConnectorBuilder(connector1).withStatus(status1).build();
    });
}
Also used : Condition(io.strimzi.api.kafka.model.status.Condition) KafkaConnectorBuilder(io.strimzi.api.kafka.model.KafkaConnectorBuilder) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) KafkaConnectorStatus(io.strimzi.api.kafka.model.status.KafkaConnectorStatus)

Example 17 with KafkaConnectorBuilder

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

the class AbstractConnectOperator method removeAnnotation.

/**
 * Patches the KafkaConnector CR to remove the supplied annotation.
 */
private Future<Void> removeAnnotation(Reconciliation reconciliation, KafkaConnector resource, String annotationKey) {
    LOGGER.debugCr(reconciliation, "Removing annotation {}", annotationKey);
    KafkaConnector patchedKafkaConnector = new KafkaConnectorBuilder(resource).editMetadata().removeFromAnnotations(annotationKey).endMetadata().build();
    return connectorOperator.patchAsync(reconciliation, patchedKafkaConnector).compose(ignored -> Future.succeededFuture());
}
Also used : KafkaConnectorBuilder(io.strimzi.api.kafka.model.KafkaConnectorBuilder) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector)

Example 18 with KafkaConnectorBuilder

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

the class ConnectorMockTest method testConnectScaleToZero.

/**
 * Create connect, create connector, Scale to 0
 */
@Test
public void testConnectScaleToZero() {
    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(), 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(spec -> new KafkaConnectBuilder(spec).editSpec().withReplicas(0).endSpec().build());
    waitForConnectReady(connectName);
    waitForConnectorNotReady(connectorName, "RuntimeException", "Kafka Connect cluster 'cluster' in namespace ns has 0 replicas.");
}
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)

Example 19 with KafkaConnectorBuilder

use of io.strimzi.api.kafka.model.KafkaConnectorBuilder in project strimzi-kafka-operator 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 20 with KafkaConnectorBuilder

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

the class ConnectorMockTest method testConnectConnectorConnectConnector.

/**
 * Create connect, create connector, delete connect, delete connector
 */
@Test
public void testConnectConnectorConnectConnector() {
    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);
    // 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 twice (Connect creation, Connector Status update)
    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))));
    boolean connectDeleted = Crds.kafkaConnectOperation(client).inNamespace(NAMESPACE).withName(connectName).delete();
    assertThat(connectDeleted, is(true));
    waitForConnectorNotReady(connectorName, "NoSuchResourceException", "KafkaConnect resource 'cluster' identified by label '" + Labels.STRIMZI_CLUSTER_LABEL + "' does not exist in namespace ns.");
    boolean connectorDeleted = Crds.kafkaConnectorOperation(client).inNamespace(NAMESPACE).withName(connectorName).delete();
    assertThat(connectorDeleted, is(true));
    verify(api, never()).delete(any(), eq(KafkaConnectResources.qualifiedServiceName(connectName, NAMESPACE)), eq(KafkaConnectCluster.REST_API_PORT), eq(connectorName));
}
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)

Aggregations

KafkaConnectorBuilder (io.strimzi.api.kafka.model.KafkaConnectorBuilder)45 Test (org.junit.jupiter.api.Test)36 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)36 KafkaConnectBuilder (io.strimzi.api.kafka.model.KafkaConnectBuilder)33 KafkaConnector (io.strimzi.api.kafka.model.KafkaConnector)33 KafkaConnect (io.strimzi.api.kafka.model.KafkaConnect)23 ConnectTimeoutException (io.netty.channel.ConnectTimeoutException)6 Condition (io.strimzi.api.kafka.model.status.Condition)4 KafkaConnectorStatus (io.strimzi.api.kafka.model.status.KafkaConnectorStatus)4 JsonObject (io.vertx.core.json.JsonObject)3 CustomResource (io.fabric8.kubernetes.client.CustomResource)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 Resource (io.fabric8.kubernetes.client.dsl.Resource)2 Crds (io.strimzi.api.kafka.Crds)2 KafkaConnectList (io.strimzi.api.kafka.KafkaConnectList)2 KafkaConnectorList (io.strimzi.api.kafka.KafkaConnectorList)2 KafkaConnectResources (io.strimzi.api.kafka.model.KafkaConnectResources)2 ConnectorPlugin (io.strimzi.api.kafka.model.connect.ConnectorPlugin)2 ConnectorPluginBuilder (io.strimzi.api.kafka.model.connect.ConnectorPluginBuilder)2 Status (io.strimzi.api.kafka.model.status.Status)2