use of io.strimzi.api.kafka.model.KafkaConnectorSpecBuilder in project strimzi-kafka-operator by strimzi.
the class KafkaMirrorMaker2AssemblyOperator method reconcileMirrorMaker2Connectors.
private Future<Void> reconcileMirrorMaker2Connectors(Reconciliation reconciliation, String host, KafkaConnectApi apiClient, KafkaMirrorMaker2 mirrorMaker2, KafkaMirrorMaker2MirrorSpec mirror, KafkaMirrorMaker2Cluster mirrorMaker2Cluster, KafkaMirrorMaker2Status mirrorMaker2Status, String desiredLogging) {
String targetClusterAlias = mirror.getTargetCluster();
String sourceClusterAlias = mirror.getSourceCluster();
if (targetClusterAlias == null) {
return maybeUpdateMirrorMaker2Status(reconciliation, mirrorMaker2, new InvalidResourceException("targetCluster property is required"));
} else if (sourceClusterAlias == null) {
return maybeUpdateMirrorMaker2Status(reconciliation, mirrorMaker2, new InvalidResourceException("sourceCluster property is required"));
}
List<KafkaMirrorMaker2ClusterSpec> clusters = ModelUtils.asListOrEmptyList(mirrorMaker2.getSpec().getClusters());
Map<String, KafkaMirrorMaker2ClusterSpec> clusterMap = clusters.stream().filter(cluster -> targetClusterAlias.equals(cluster.getAlias()) || sourceClusterAlias.equals(cluster.getAlias())).collect(Collectors.toMap(KafkaMirrorMaker2ClusterSpec::getAlias, Function.identity()));
if (!clusterMap.containsKey(targetClusterAlias)) {
return maybeUpdateMirrorMaker2Status(reconciliation, mirrorMaker2, new InvalidResourceException("targetCluster with alias " + mirror.getTargetCluster() + " cannot be found in the list of clusters at spec.clusters"));
} else if (!clusterMap.containsKey(sourceClusterAlias)) {
return maybeUpdateMirrorMaker2Status(reconciliation, mirrorMaker2, new InvalidResourceException("sourceCluster with alias " + mirror.getSourceCluster() + " cannot be found in the list of clusters at spec.clusters"));
}
return CompositeFuture.join(MIRRORMAKER2_CONNECTORS.entrySet().stream().filter(// filter out non-existent connectors
entry -> entry.getValue().apply(mirror) != null).map(entry -> {
String connectorName = sourceClusterAlias + "->" + targetClusterAlias + entry.getKey();
String className = MIRRORMAKER2_CONNECTOR_PACKAGE + entry.getKey();
KafkaMirrorMaker2ConnectorSpec mm2ConnectorSpec = entry.getValue().apply(mirror);
KafkaConnectorSpec connectorSpec = new KafkaConnectorSpecBuilder().withClassName(className).withConfig(mm2ConnectorSpec.getConfig()).withPause(mm2ConnectorSpec.getPause()).withTasksMax(mm2ConnectorSpec.getTasksMax()).build();
prepareMirrorMaker2ConnectorConfig(reconciliation, mirror, clusterMap.get(sourceClusterAlias), clusterMap.get(targetClusterAlias), connectorSpec, mirrorMaker2Cluster);
LOGGER.debugCr(reconciliation, "creating/updating connector {} config: {}", connectorName, connectorSpec.getConfig());
return reconcileMirrorMaker2Connector(reconciliation, mirrorMaker2, apiClient, host, connectorName, connectorSpec, mirrorMaker2Status);
}).collect(Collectors.toList())).map((Void) null).compose(i -> apiClient.updateConnectLoggers(reconciliation, host, KafkaConnectCluster.REST_API_PORT, desiredLogging, mirrorMaker2Cluster.getDefaultLogConfig())).compose(i -> {
boolean failedConnector = mirrorMaker2Status.getConnectors().stream().anyMatch(connector -> {
Object state = ((Map) connector.getOrDefault("connector", emptyMap())).get("state");
return "FAILED".equalsIgnoreCase(state.toString());
});
if (failedConnector) {
return Future.failedFuture("One or more connectors are in FAILED state");
} else {
return Future.succeededFuture();
}
}).map((Void) null);
}
use of io.strimzi.api.kafka.model.KafkaConnectorSpecBuilder in project strimzi by strimzi.
the class KafkaMirrorMaker2AssemblyOperator method reconcileMirrorMaker2Connectors.
private Future<Void> reconcileMirrorMaker2Connectors(Reconciliation reconciliation, String host, KafkaConnectApi apiClient, KafkaMirrorMaker2 mirrorMaker2, KafkaMirrorMaker2MirrorSpec mirror, KafkaMirrorMaker2Cluster mirrorMaker2Cluster, KafkaMirrorMaker2Status mirrorMaker2Status, String desiredLogging) {
String targetClusterAlias = mirror.getTargetCluster();
String sourceClusterAlias = mirror.getSourceCluster();
if (targetClusterAlias == null) {
return maybeUpdateMirrorMaker2Status(reconciliation, mirrorMaker2, new InvalidResourceException("targetCluster property is required"));
} else if (sourceClusterAlias == null) {
return maybeUpdateMirrorMaker2Status(reconciliation, mirrorMaker2, new InvalidResourceException("sourceCluster property is required"));
}
List<KafkaMirrorMaker2ClusterSpec> clusters = ModelUtils.asListOrEmptyList(mirrorMaker2.getSpec().getClusters());
Map<String, KafkaMirrorMaker2ClusterSpec> clusterMap = clusters.stream().filter(cluster -> targetClusterAlias.equals(cluster.getAlias()) || sourceClusterAlias.equals(cluster.getAlias())).collect(Collectors.toMap(KafkaMirrorMaker2ClusterSpec::getAlias, Function.identity()));
if (!clusterMap.containsKey(targetClusterAlias)) {
return maybeUpdateMirrorMaker2Status(reconciliation, mirrorMaker2, new InvalidResourceException("targetCluster with alias " + mirror.getTargetCluster() + " cannot be found in the list of clusters at spec.clusters"));
} else if (!clusterMap.containsKey(sourceClusterAlias)) {
return maybeUpdateMirrorMaker2Status(reconciliation, mirrorMaker2, new InvalidResourceException("sourceCluster with alias " + mirror.getSourceCluster() + " cannot be found in the list of clusters at spec.clusters"));
}
return CompositeFuture.join(MIRRORMAKER2_CONNECTORS.entrySet().stream().filter(// filter out non-existent connectors
entry -> entry.getValue().apply(mirror) != null).map(entry -> {
String connectorName = sourceClusterAlias + "->" + targetClusterAlias + entry.getKey();
String className = MIRRORMAKER2_CONNECTOR_PACKAGE + entry.getKey();
KafkaMirrorMaker2ConnectorSpec mm2ConnectorSpec = entry.getValue().apply(mirror);
KafkaConnectorSpec connectorSpec = new KafkaConnectorSpecBuilder().withClassName(className).withConfig(mm2ConnectorSpec.getConfig()).withPause(mm2ConnectorSpec.getPause()).withTasksMax(mm2ConnectorSpec.getTasksMax()).build();
prepareMirrorMaker2ConnectorConfig(reconciliation, mirror, clusterMap.get(sourceClusterAlias), clusterMap.get(targetClusterAlias), connectorSpec, mirrorMaker2Cluster);
LOGGER.debugCr(reconciliation, "creating/updating connector {} config: {}", connectorName, connectorSpec.getConfig());
return reconcileMirrorMaker2Connector(reconciliation, mirrorMaker2, apiClient, host, connectorName, connectorSpec, mirrorMaker2Status);
}).collect(Collectors.toList())).map((Void) null).compose(i -> apiClient.updateConnectLoggers(reconciliation, host, KafkaConnectCluster.REST_API_PORT, desiredLogging, mirrorMaker2Cluster.getDefaultLogConfig())).compose(i -> {
boolean failedConnector = mirrorMaker2Status.getConnectors().stream().anyMatch(connector -> {
Object state = ((Map) connector.getOrDefault("connector", emptyMap())).get("state");
return "FAILED".equalsIgnoreCase(state.toString());
});
if (failedConnector) {
return Future.failedFuture("One or more connectors are in FAILED state");
} else {
return Future.succeededFuture();
}
}).map((Void) null);
}
use of io.strimzi.api.kafka.model.KafkaConnectorSpecBuilder in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class DebeziumOperandController method doReify.
@Override
protected List<HasMetadata> doReify(ManagedConnector connector, DebeziumShardMetadata shardMetadata, ConnectorConfiguration<ObjectNode> connectorConfiguration, ServiceAccountSpec serviceAccountSpec) {
final Map<String, String> secretsData = createSecretsData(connectorConfiguration.getConnectorSpec());
final Secret secret = new SecretBuilder().withMetadata(new ObjectMetaBuilder().withName(connector.getMetadata().getName() + Resources.CONNECTOR_SECRET_SUFFIX).build()).addToData(EXTERNAL_CONFIG_FILE, asBytesBase64(secretsData)).addToData(KAFKA_CLIENT_SECRET_KEY, serviceAccountSpec.getClientSecret()).build();
final KafkaConnectSpecBuilder kcsb = new KafkaConnectSpecBuilder().withReplicas(1).withBootstrapServers(connector.getSpec().getDeployment().getKafka().getUrl()).withKafkaClientAuthenticationPlain(new KafkaClientAuthenticationPlainBuilder().withUsername(serviceAccountSpec.getClientId()).withPasswordSecret(new PasswordSecretSourceBuilder().withSecretName(secret.getMetadata().getName()).withPassword(KAFKA_CLIENT_SECRET_KEY).build()).build()).addToConfig(DebeziumConstants.DEFAULT_CONFIG_OPTIONS).addToConfig(new TreeMap<>(configuration.kafkaConnect().config())).addToConfig("group.id", connector.getMetadata().getName()).addToConfig("key.converter", configuration.keyConverter()).addToConfig("value.converter", configuration.valueConverter()).addToConfig("offset.storage.topic", connector.getMetadata().getName() + "-offset").addToConfig("config.storage.topic", connector.getMetadata().getName() + "-config").addToConfig("status.storage.topic", connector.getMetadata().getName() + "-status").addToConfig("connector.secret.name", secret.getMetadata().getName()).addToConfig("connector.secret.checksum", Secrets.computeChecksum(secret)).withTls(new ClientTlsBuilder().withTrustedCertificates(Collections.emptyList()).build()).withExternalConfiguration(new ExternalConfigurationBuilder().addToVolumes(new ExternalConfigurationVolumeSourceBuilder().withName(EXTERNAL_CONFIG_DIRECTORY).withSecret(new SecretVolumeSourceBuilder().withSecretName(secret.getMetadata().getName()).build()).build()).build());
kcsb.withImage(shardMetadata.getContainerImage());
final KafkaConnect kc = new KafkaConnectBuilder().withApiVersion(Constants.RESOURCE_GROUP_NAME + "/" + KafkaConnect.CONSUMED_VERSION).withMetadata(new ObjectMetaBuilder().withName(connector.getMetadata().getName()).addToAnnotations(STRIMZI_IO_USE_CONNECTOR_RESOURCES, "true").build()).withSpec(kcsb.build()).build();
final KafkaConnector kctr = new KafkaConnectorBuilder().withApiVersion(Constants.RESOURCE_GROUP_NAME + "/" + KafkaConnector.CONSUMED_VERSION).withMetadata(new ObjectMetaBuilder().withName(connector.getMetadata().getName()).addToLabels(STRIMZI_DOMAIN + "cluster", connector.getMetadata().getName()).build()).withSpec(new KafkaConnectorSpecBuilder().withClassName(shardMetadata.getConnectorClass()).withTasksMax(1).withPause(false).withConfig(createConfig(configuration, connectorConfiguration.getConnectorSpec())).build()).build();
return List.of(secret, kc, kctr);
}
Aggregations