Search in sources :

Example 11 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project apache-kafka-on-k8s by banzaicloud.

the class InsertField method configure.

@Override
public void configure(Map<String, ?> props) {
    final SimpleConfig config = new SimpleConfig(CONFIG_DEF, props);
    topicField = InsertionSpec.parse(config.getString(ConfigName.TOPIC_FIELD));
    partitionField = InsertionSpec.parse(config.getString(ConfigName.PARTITION_FIELD));
    offsetField = InsertionSpec.parse(config.getString(ConfigName.OFFSET_FIELD));
    timestampField = InsertionSpec.parse(config.getString(ConfigName.TIMESTAMP_FIELD));
    staticField = InsertionSpec.parse(config.getString(ConfigName.STATIC_FIELD));
    staticValue = config.getString(ConfigName.STATIC_VALUE);
    if (topicField == null && partitionField == null && offsetField == null && timestampField == null && staticField == null) {
        throw new ConfigException("No field insertion configured");
    }
    if (staticField != null && staticValue == null) {
        throw new ConfigException(ConfigName.STATIC_VALUE, null, "No value specified for static field: " + staticField);
    }
    schemaUpdateCache = new SynchronizedCache<>(new LRUCache<Schema, Schema>(16));
}
Also used : SimpleConfig(org.apache.kafka.connect.transforms.util.SimpleConfig) LRUCache(org.apache.kafka.common.cache.LRUCache) ConfigException(org.apache.kafka.common.config.ConfigException)

Example 12 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project apache-kafka-on-k8s by banzaicloud.

the class TimestampConverter method configure.

@Override
public void configure(Map<String, ?> configs) {
    final SimpleConfig simpleConfig = new SimpleConfig(CONFIG_DEF, configs);
    final String field = simpleConfig.getString(FIELD_CONFIG);
    final String type = simpleConfig.getString(TARGET_TYPE_CONFIG);
    String formatPattern = simpleConfig.getString(FORMAT_CONFIG);
    schemaUpdateCache = new SynchronizedCache<>(new LRUCache<Schema, Schema>(16));
    if (!VALID_TYPES.contains(type)) {
        throw new ConfigException("Unknown timestamp type in TimestampConverter: " + type + ". Valid values are " + Utils.join(VALID_TYPES, ", ") + ".");
    }
    if (type.equals(TYPE_STRING) && formatPattern.trim().isEmpty()) {
        throw new ConfigException("TimestampConverter requires format option to be specified when using string timestamps");
    }
    SimpleDateFormat format = null;
    if (formatPattern != null && !formatPattern.trim().isEmpty()) {
        try {
            format = new SimpleDateFormat(formatPattern);
            format.setTimeZone(UTC);
        } catch (IllegalArgumentException e) {
            throw new ConfigException("TimestampConverter requires a SimpleDateFormat-compatible pattern for string timestamps: " + formatPattern, e);
        }
    }
    config = new Config(field, type, format);
}
Also used : SimpleConfig(org.apache.kafka.connect.transforms.util.SimpleConfig) LRUCache(org.apache.kafka.common.cache.LRUCache) SimpleConfig(org.apache.kafka.connect.transforms.util.SimpleConfig) ConfigException(org.apache.kafka.common.config.ConfigException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 13 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project apache-kafka-on-k8s by banzaicloud.

the class PushHttpMetricsReporter method configure.

@Override
public void configure(Map<String, ?> configs) {
    PushHttpMetricsReporterConfig config = new PushHttpMetricsReporterConfig(CONFIG_DEF, configs);
    try {
        url = new URL(config.getString(METRICS_URL_CONFIG));
    } catch (MalformedURLException e) {
        throw new ConfigException("Malformed metrics.url", e);
    }
    int period = config.getInteger(METRICS_PERIOD_CONFIG);
    clientId = config.getString(CLIENT_ID_CONFIG);
    host = config.getString(METRICS_HOST_CONFIG);
    if (host == null || host.isEmpty()) {
        try {
            host = InetAddress.getLocalHost().getCanonicalHostName();
        } catch (UnknownHostException e) {
            throw new ConfigException("Failed to get canonical hostname", e);
        }
    }
    executor.scheduleAtFixedRate(new HttpReporter(), period, period, TimeUnit.SECONDS);
    log.info("Configured PushHttpMetricsReporter for {} to report every {} seconds", url, period);
}
Also used : MalformedURLException(java.net.MalformedURLException) UnknownHostException(java.net.UnknownHostException) ConfigException(org.apache.kafka.common.config.ConfigException) URL(java.net.URL)

Example 14 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project apache-kafka-on-k8s by banzaicloud.

the class ConnectorConfig method enrich.

/**
 * Returns an enriched {@link ConfigDef} building upon the {@code ConfigDef}, using the current configuration specified in {@code props} as an input.
 * <p>
 * {@code requireFullConfig} specifies whether required config values that are missing should cause an exception to be thrown.
 */
public static ConfigDef enrich(Plugins plugins, ConfigDef baseConfigDef, Map<String, String> props, boolean requireFullConfig) {
    Object transformAliases = ConfigDef.parseType(TRANSFORMS_CONFIG, props.get(TRANSFORMS_CONFIG), Type.LIST);
    if (!(transformAliases instanceof List)) {
        return baseConfigDef;
    }
    ConfigDef newDef = new ConfigDef(baseConfigDef);
    LinkedHashSet<?> uniqueTransformAliases = new LinkedHashSet<>((List<?>) transformAliases);
    for (Object o : uniqueTransformAliases) {
        if (!(o instanceof String)) {
            throw new ConfigException("Item in " + TRANSFORMS_CONFIG + " property is not of " + "type String");
        }
        String alias = (String) o;
        final String prefix = TRANSFORMS_CONFIG + "." + alias + ".";
        final String group = TRANSFORMS_GROUP + ": " + alias;
        int orderInGroup = 0;
        final String transformationTypeConfig = prefix + "type";
        final ConfigDef.Validator typeValidator = new ConfigDef.Validator() {

            @Override
            public void ensureValid(String name, Object value) {
                getConfigDefFromTransformation(transformationTypeConfig, (Class) value);
            }
        };
        newDef.define(transformationTypeConfig, Type.CLASS, ConfigDef.NO_DEFAULT_VALUE, typeValidator, Importance.HIGH, "Class for the '" + alias + "' transformation.", group, orderInGroup++, Width.LONG, "Transformation type for " + alias, Collections.<String>emptyList(), new TransformationClassRecommender(plugins));
        final ConfigDef transformationConfigDef;
        try {
            final String className = props.get(transformationTypeConfig);
            final Class<?> cls = (Class<?>) ConfigDef.parseType(transformationTypeConfig, className, Type.CLASS);
            transformationConfigDef = getConfigDefFromTransformation(transformationTypeConfig, cls);
        } catch (ConfigException e) {
            if (requireFullConfig) {
                throw e;
            } else {
                continue;
            }
        }
        newDef.embed(prefix, group, orderInGroup, transformationConfigDef);
    }
    return newDef;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ConfigException(org.apache.kafka.common.config.ConfigException) ArrayList(java.util.ArrayList) List(java.util.List) ConfigDef(org.apache.kafka.common.config.ConfigDef)

Example 15 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project apache-kafka-on-k8s by banzaicloud.

the class SslFactory method reconfigure.

@Override
public void reconfigure(Map<String, ?> configs) throws KafkaException {
    SecurityStore newKeystore = maybeCreateNewKeystore(configs);
    if (newKeystore != null) {
        try {
            this.sslContext = createSSLContext(newKeystore);
            this.keystore = newKeystore;
        } catch (Exception e) {
            throw new ConfigException("Reconfiguration of SSL keystore failed", e);
        }
    }
}
Also used : ConfigException(org.apache.kafka.common.config.ConfigException) KafkaException(org.apache.kafka.common.KafkaException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) ConfigException(org.apache.kafka.common.config.ConfigException) SSLException(javax.net.ssl.SSLException)

Aggregations

ConfigException (org.apache.kafka.common.config.ConfigException)136 HashMap (java.util.HashMap)29 Test (org.junit.jupiter.api.Test)28 Test (org.junit.Test)20 Properties (java.util.Properties)10 KafkaException (org.apache.kafka.common.KafkaException)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Pattern (java.util.regex.Pattern)9 Serde (org.apache.kafka.common.serialization.Serde)8 SimpleConfig (org.apache.kafka.connect.transforms.util.SimpleConfig)8 File (java.io.File)7 SSLContext (javax.net.ssl.SSLContext)7 Map (java.util.Map)6 ByteArraySerializer (org.apache.kafka.common.serialization.ByteArraySerializer)6 KeyStore (java.security.KeyStore)5 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)5 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)5 ConfigDef (org.apache.kafka.common.config.ConfigDef)5 IOException (java.io.IOException)4