use of org.apache.kafka.common.config.ConfigException in project apache-kafka-on-k8s by banzaicloud.
the class Cast method parseFieldTypes.
private static Map<String, Schema.Type> parseFieldTypes(List<String> mappings) {
final Map<String, Schema.Type> m = new HashMap<>();
boolean isWholeValueCast = false;
for (String mapping : mappings) {
final String[] parts = mapping.split(":");
if (parts.length > 2) {
throw new ConfigException(ReplaceField.ConfigName.RENAME, mappings, "Invalid rename mapping: " + mapping);
}
if (parts.length == 1) {
Schema.Type targetType = Schema.Type.valueOf(parts[0].trim().toUpperCase(Locale.ROOT));
m.put(WHOLE_VALUE_CAST, validCastType(targetType, FieldType.OUTPUT));
isWholeValueCast = true;
} else {
Schema.Type type;
try {
type = Schema.Type.valueOf(parts[1].trim().toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException e) {
throw new ConfigException("Invalid type found in casting spec: " + parts[1].trim(), e);
}
m.put(parts[0].trim(), validCastType(type, FieldType.OUTPUT));
}
}
if (isWholeValueCast && mappings.size() > 1) {
throw new ConfigException("Cast transformations that specify a type to cast the entire value to " + "may ony specify a single cast in their spec");
}
return m;
}
use of org.apache.kafka.common.config.ConfigException in project apache-kafka-on-k8s by banzaicloud.
the class SetSchemaMetadata method configure.
@Override
public void configure(Map<String, ?> configs) {
final SimpleConfig config = new SimpleConfig(CONFIG_DEF, configs);
schemaName = config.getString(ConfigName.SCHEMA_NAME);
schemaVersion = config.getInt(ConfigName.SCHEMA_VERSION);
if (schemaName == null && schemaVersion == null) {
throw new ConfigException("Neither schema name nor version configured");
}
}
use of org.apache.kafka.common.config.ConfigException in project apache-kafka-on-k8s by banzaicloud.
the class ClientUtils method parseAndValidateAddresses.
public static List<InetSocketAddress> parseAndValidateAddresses(List<String> urls) {
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);
InetSocketAddress address = new InetSocketAddress(host, port);
if (address.isUnresolved()) {
log.warn("Removing 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);
}
}
}
if (addresses.isEmpty())
throw new ConfigException("No resolvable bootstrap urls given in " + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG);
return addresses;
}
use of org.apache.kafka.common.config.ConfigException in project apache-kafka-on-k8s by banzaicloud.
the class KafkaLog4jAppender method activateOptions.
@Override
public void activateOptions() {
// check for config parameter validity
Properties props = new Properties();
if (brokerList != null)
props.put(BOOTSTRAP_SERVERS_CONFIG, brokerList);
if (props.isEmpty())
throw new ConfigException("The bootstrap servers property should be specified");
if (topic == null)
throw new ConfigException("Topic must be specified by the Kafka log4j appender");
if (compressionType != null)
props.put(COMPRESSION_TYPE_CONFIG, compressionType);
if (requiredNumAcks != Integer.MAX_VALUE)
props.put(ACKS_CONFIG, Integer.toString(requiredNumAcks));
if (retries > 0)
props.put(RETRIES_CONFIG, retries);
if (securityProtocol != null) {
props.put(SECURITY_PROTOCOL_CONFIG, securityProtocol);
}
if (securityProtocol != null && securityProtocol.contains("SSL") && sslTruststoreLocation != null && sslTruststorePassword != null) {
props.put(SSL_TRUSTSTORE_LOCATION_CONFIG, sslTruststoreLocation);
props.put(SSL_TRUSTSTORE_PASSWORD_CONFIG, sslTruststorePassword);
if (sslKeystoreType != null && sslKeystoreLocation != null && sslKeystorePassword != null) {
props.put(SSL_KEYSTORE_TYPE_CONFIG, sslKeystoreType);
props.put(SSL_KEYSTORE_LOCATION_CONFIG, sslKeystoreLocation);
props.put(SSL_KEYSTORE_PASSWORD_CONFIG, sslKeystorePassword);
}
}
if (securityProtocol != null && securityProtocol.contains("SASL") && saslKerberosServiceName != null && clientJaasConfPath != null) {
props.put(SASL_KERBEROS_SERVICE_NAME, saslKerberosServiceName);
System.setProperty("java.security.auth.login.config", clientJaasConfPath);
if (kerb5ConfPath != null) {
System.setProperty("java.security.krb5.conf", kerb5ConfPath);
}
}
props.put(KEY_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName());
props.put(VALUE_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName());
this.producer = getKafkaProducer(props);
LogLog.debug("Kafka producer connected to " + brokerList);
LogLog.debug("Logging for topic: " + topic);
}
use of org.apache.kafka.common.config.ConfigException in project apache-kafka-on-k8s by banzaicloud.
the class KafkaLog4jAppenderTest method testKafkaLog4jConfigs.
@Test
public void testKafkaLog4jConfigs() {
// host missing
Properties props = new Properties();
props.put("log4j.rootLogger", "INFO");
props.put("log4j.appender.KAFKA", "org.apache.kafka.log4jappender.KafkaLog4jAppender");
props.put("log4j.appender.KAFKA.layout", "org.apache.log4j.PatternLayout");
props.put("log4j.appender.KAFKA.layout.ConversionPattern", "%-5p: %c - %m%n");
props.put("log4j.appender.KAFKA.Topic", "test-topic");
props.put("log4j.logger.kafka.log4j", "INFO, KAFKA");
try {
PropertyConfigurator.configure(props);
Assert.fail("Missing properties exception was expected !");
} catch (ConfigException ex) {
// It's OK!
}
// topic missing
props = new Properties();
props.put("log4j.rootLogger", "INFO");
props.put("log4j.appender.KAFKA", "org.apache.kafka.log4jappender.KafkaLog4jAppender");
props.put("log4j.appender.KAFKA.layout", "org.apache.log4j.PatternLayout");
props.put("log4j.appender.KAFKA.layout.ConversionPattern", "%-5p: %c - %m%n");
props.put("log4j.appender.KAFKA.brokerList", "127.0.0.1:9093");
props.put("log4j.logger.kafka.log4j", "INFO, KAFKA");
try {
PropertyConfigurator.configure(props);
Assert.fail("Missing properties exception was expected !");
} catch (ConfigException ex) {
// It's OK!
}
}
Aggregations