use of org.apache.kafka.common.config.ConfigException in project apache-kafka-on-k8s by banzaicloud.
the class SslFactory method createSSLContext.
// package access for testing
SSLContext createSSLContext(SecurityStore keystore) throws GeneralSecurityException, IOException {
SSLContext sslContext;
if (provider != null)
sslContext = SSLContext.getInstance(protocol, provider);
else
sslContext = SSLContext.getInstance(protocol);
KeyManager[] keyManagers = null;
if (keystore != null) {
String kmfAlgorithm = this.kmfAlgorithm != null ? this.kmfAlgorithm : KeyManagerFactory.getDefaultAlgorithm();
KeyManagerFactory kmf = KeyManagerFactory.getInstance(kmfAlgorithm);
KeyStore ks = keystore.load();
Password keyPassword = keystore.keyPassword != null ? keystore.keyPassword : keystore.password;
kmf.init(ks, keyPassword.value().toCharArray());
keyManagers = kmf.getKeyManagers();
}
String tmfAlgorithm = this.tmfAlgorithm != null ? this.tmfAlgorithm : TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
KeyStore ts = truststore == null ? null : truststore.load();
tmf.init(ts);
sslContext.init(keyManagers, tmf.getTrustManagers(), this.secureRandomImplementation);
if (keystore != null && keystore != this.keystore) {
if (this.keystore == null)
throw new ConfigException("Cannot add SSL keystore to an existing listener for which no keystore was configured.");
if (keystoreVerifiableUsingTruststore)
SSLConfigValidatorEngine.validate(this, sslContext);
if (!CertificateEntries.create(this.keystore.load()).equals(CertificateEntries.create(keystore.load()))) {
throw new ConfigException("Keystore DistinguishedName or SubjectAltNames do not match");
}
}
return sslContext;
}
use of org.apache.kafka.common.config.ConfigException in project debezium by debezium.
the class Field method validate.
/**
* Validate this field in the supplied configuration, updating the {@link ConfigValue} for the field with the results.
*
* @param config the configuration to be validated; may not be null
* @param fieldSupplier the supplier for dependent fields by name; may not be null
* @param results the set of configuration results keyed by field name; may not be null
*/
protected void validate(Configuration config, Function<String, Field> fieldSupplier, Map<String, ConfigValue> results) {
// First, merge any new recommended values ...
ConfigValue value = results.computeIfAbsent(this.name(), n -> new ConfigValue(n));
// Apply the validator ...
validate(config, (f, v, problem) -> {
value.addErrorMessage(problem);
});
// Apply the recommender ..
if (recommender != null) {
try {
// Set the visibility ...
value.visible(recommender.visible(this, config));
// Compute and set the new recommendations ...
List<Object> newRecommendations = recommender.validValues(this, config);
List<Object> previousRecommendations = value.recommendedValues();
if (!previousRecommendations.isEmpty()) {
// Don't use any newly recommended values if they were not previously recommended ...
newRecommendations.retainAll(previousRecommendations);
}
value.recommendedValues(newRecommendations);
} catch (ConfigException e) {
value.addErrorMessage(e.getMessage());
}
}
// Do the same for any dependents ...
dependents.forEach(name -> {
Field dependentField = fieldSupplier.apply(name);
if (dependentField != null) {
dependentField.validate(config, fieldSupplier, results);
}
});
}
use of org.apache.kafka.common.config.ConfigException in project apache-kafka-on-k8s by banzaicloud.
the class KafkaProducer method configureTransactionState.
private static TransactionManager configureTransactionState(ProducerConfig config, LogContext logContext, Logger log) {
TransactionManager transactionManager = null;
boolean userConfiguredIdempotence = false;
if (config.originals().containsKey(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG))
userConfiguredIdempotence = true;
boolean userConfiguredTransactions = false;
if (config.originals().containsKey(ProducerConfig.TRANSACTIONAL_ID_CONFIG))
userConfiguredTransactions = true;
boolean idempotenceEnabled = config.getBoolean(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG);
if (!idempotenceEnabled && userConfiguredIdempotence && userConfiguredTransactions)
throw new ConfigException("Cannot set a " + ProducerConfig.TRANSACTIONAL_ID_CONFIG + " without also enabling idempotence.");
if (userConfiguredTransactions)
idempotenceEnabled = true;
if (idempotenceEnabled) {
String transactionalId = config.getString(ProducerConfig.TRANSACTIONAL_ID_CONFIG);
int transactionTimeoutMs = config.getInt(ProducerConfig.TRANSACTION_TIMEOUT_CONFIG);
long retryBackoffMs = config.getLong(ProducerConfig.RETRY_BACKOFF_MS_CONFIG);
transactionManager = new TransactionManager(logContext, transactionalId, transactionTimeoutMs, retryBackoffMs);
if (transactionManager.isTransactional())
log.info("Instantiated a transactional producer.");
else
log.info("Instantiated an idempotent producer.");
}
return transactionManager;
}
use of org.apache.kafka.common.config.ConfigException in project kafka by apache.
the class SourceConnectorConfig method enrich.
/**
* Returns an enriched {@link ConfigDef} building upon the {@code ConfigDef}, using the current configuration specified in {@code props} as an input.
*
* @param baseConfigDef the base configuration definition to be enriched
* @param props the non parsed configuration properties
* @return the enriched configuration definition
*/
public static ConfigDef enrich(ConfigDef baseConfigDef, Map<String, String> props, AbstractConfig defaultGroupConfig) {
List<Object> topicCreationGroups = new ArrayList<>();
Object aliases = ConfigDef.parseType(TOPIC_CREATION_GROUPS_CONFIG, props.get(TOPIC_CREATION_GROUPS_CONFIG), ConfigDef.Type.LIST);
if (aliases instanceof List) {
topicCreationGroups.addAll((List<?>) aliases);
}
ConfigDef newDef = new ConfigDef(baseConfigDef);
String defaultGroupPrefix = TOPIC_CREATION_PREFIX + DEFAULT_TOPIC_CREATION_GROUP + ".";
short defaultGroupReplicationFactor = defaultGroupConfig.getShort(defaultGroupPrefix + REPLICATION_FACTOR_CONFIG);
int defaultGroupPartitions = defaultGroupConfig.getInt(defaultGroupPrefix + PARTITIONS_CONFIG);
topicCreationGroups.stream().distinct().forEach(group -> {
if (!(group instanceof String)) {
throw new ConfigException("Item in " + TOPIC_CREATION_GROUPS_CONFIG + " property is not of type String");
}
String alias = (String) group;
String prefix = TOPIC_CREATION_PREFIX + alias + ".";
String configGroup = TOPIC_CREATION_GROUP + ": " + alias;
newDef.embed(prefix, configGroup, 0, TopicCreationConfig.configDef(configGroup, defaultGroupReplicationFactor, defaultGroupPartitions));
});
return newDef;
}
use of org.apache.kafka.common.config.ConfigException in project kafka by apache.
the class ClientUtils method parseAndValidateAddresses.
public static List<InetSocketAddress> parseAndValidateAddresses(List<String> urls, ClientDnsLookup clientDnsLookup) {
List<InetSocketAddress> addresses = new ArrayList<>();
for (String url : urls) {
if (url != null && !url.isEmpty()) {
try {
String host = getHost(url);
Integer port = getPort(url);
if (host == null || port == null)
throw new ConfigException("Invalid url in " + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG + ": " + url);
if (clientDnsLookup == ClientDnsLookup.RESOLVE_CANONICAL_BOOTSTRAP_SERVERS_ONLY) {
InetAddress[] inetAddresses = InetAddress.getAllByName(host);
for (InetAddress inetAddress : inetAddresses) {
String resolvedCanonicalName = inetAddress.getCanonicalHostName();
InetSocketAddress address = new InetSocketAddress(resolvedCanonicalName, port);
if (address.isUnresolved()) {
log.warn("Couldn't resolve server {} from {} as DNS resolution of the canonical hostname {} failed for {}", url, CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, resolvedCanonicalName, host);
} else {
addresses.add(address);
}
}
} else {
InetSocketAddress address = new InetSocketAddress(host, port);
if (address.isUnresolved()) {
log.warn("Couldn't resolve server {} from {} as DNS resolution failed for {}", url, CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, host);
} else {
addresses.add(address);
}
}
} catch (IllegalArgumentException e) {
throw new ConfigException("Invalid port in " + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG + ": " + url);
} catch (UnknownHostException e) {
throw new ConfigException("Unknown host in " + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG + ": " + url);
}
}
}
if (addresses.isEmpty())
throw new ConfigException("No resolvable bootstrap urls given in " + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG);
return addresses;
}
Aggregations