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