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));
}
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);
}
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();
}
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();
});
}
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);
}
}
Aggregations