Search in sources :

Example 11 with KafkaConnectorBuilder

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

the class ConnectorMockTest method testConnectorPauseResume.

/**
 * Create connect, create connector, pause connector, resume connector
 */
@Test
public void testConnectorPauseResume() {
    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);
    waitForConnectorState(connectorName, "RUNNING");
    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))));
    verify(api, never()).pause(eq(KafkaConnectResources.qualifiedServiceName(connectName, NAMESPACE)), eq(KafkaConnectCluster.REST_API_PORT), eq(connectorName));
    verify(api, never()).resume(eq(KafkaConnectResources.qualifiedServiceName(connectName, NAMESPACE)), eq(KafkaConnectCluster.REST_API_PORT), eq(connectorName));
    Crds.kafkaConnectorOperation(client).inNamespace(NAMESPACE).withName(connectorName).edit(spec -> new KafkaConnectorBuilder(spec).editSpec().withPause(true).endSpec().build());
    waitForConnectorState(connectorName, "PAUSED");
    verify(api, times(1)).pause(eq(KafkaConnectResources.qualifiedServiceName(connectName, NAMESPACE)), eq(KafkaConnectCluster.REST_API_PORT), eq(connectorName));
    verify(api, never()).resume(eq(KafkaConnectResources.qualifiedServiceName(connectName, NAMESPACE)), eq(KafkaConnectCluster.REST_API_PORT), eq(connectorName));
    Crds.kafkaConnectorOperation(client).inNamespace(NAMESPACE).withName(connectorName).edit(sp -> new KafkaConnectorBuilder(sp).editSpec().withPause(false).endSpec().build());
    waitForConnectorState(connectorName, "RUNNING");
    verify(api, times(1)).pause(eq(KafkaConnectResources.qualifiedServiceName(connectName, NAMESPACE)), eq(KafkaConnectCluster.REST_API_PORT), eq(connectorName));
    verify(api, times(1)).resume(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)

Example 12 with KafkaConnectorBuilder

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

the class ConnectorMockTest method testConnectorNotReadyWhenConnectNotConfiguredForConnectors.

@Test
public void testConnectorNotReadyWhenConnectNotConfiguredForConnectors() {
    String connectName = "cluster";
    String connectorName = "connector";
    KafkaConnect connect = new KafkaConnectBuilder().withNewMetadata().withNamespace(NAMESPACE).withName(connectName).endMetadata().withNewSpec().withReplicas(1).endSpec().build();
    Crds.kafkaConnectOperation(client).inNamespace(NAMESPACE).create(connect);
    waitForConnectReady(connectName);
    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 cluster is not configured with annotation " + Annotations.STRIMZI_IO_USE_CONNECTOR_RESOURCES);
}
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 13 with KafkaConnectorBuilder

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

the class ConnectorConfigBuilder method getCustomResource.

/**
 * Get configuration as OpenShift CR of type {@link KafkaConnector}
 * @return Connector CR
 */
public KafkaConnector getCustomResource() {
    Map<String, Object> crConfig = new HashMap<>(config);
    KafkaConnectorBuilder connectorBuilder = new KafkaConnectorBuilder();
    return connectorBuilder.withNewMetadata().withLabels(new HashMap<>()).withName(connectorName).endMetadata().withNewSpec().withClassName((String) crConfig.remove("connector.class")).withTasksMax((Integer) crConfig.remove("task.max")).withConfig(crConfig).endSpec().build();
}
Also used : HashMap(java.util.HashMap) KafkaConnectorBuilder(io.strimzi.api.kafka.model.KafkaConnectorBuilder)

Example 14 with KafkaConnectorBuilder

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

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

the class AbstractConnectOperator method updateStatus.

public static void updateStatus(Reconciliation reconciliation, Throwable error, KafkaConnector kafkaConnector2, CrdOperator<?, KafkaConnector, ?> connectorOperations) {
    KafkaConnectorStatus status = new KafkaConnectorStatus();
    StatusUtils.setStatusConditionAndObservedGeneration(kafkaConnector2, status, error);
    StatusDiff diff = new StatusDiff(kafkaConnector2.getStatus(), status);
    if (!diff.isEmpty()) {
        KafkaConnector copy = new KafkaConnectorBuilder(kafkaConnector2).build();
        copy.setStatus(status);
        connectorOperations.updateStatusAsync(reconciliation, copy);
    }
}
Also used : StatusDiff(io.strimzi.operator.cluster.model.StatusDiff) KafkaConnectorBuilder(io.strimzi.api.kafka.model.KafkaConnectorBuilder) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) KafkaConnectorStatus(io.strimzi.api.kafka.model.status.KafkaConnectorStatus)

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