-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split common Config for source and sink connectors, have S3 sink conn…
…ector use the sink source for configuration Signed-off-by: Aindriu Lavelle <[email protected]>
- Loading branch information
1 parent
ecdc04e
commit 46436c0
Showing
18 changed files
with
993 additions
and
662 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
commons/src/main/java/io/aiven/kafka/connect/common/config/CommonConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2024 Aiven Oy | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.aiven.kafka.connect.common.config; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.apache.kafka.common.config.AbstractConfig; | ||
import org.apache.kafka.common.config.ConfigDef; | ||
import org.apache.kafka.common.config.ConfigException; | ||
public abstract class CommonConfig extends AbstractConfig { | ||
protected static final String GROUP_COMPRESSION = "File Compression"; | ||
protected static final String GROUP_FORMAT = "Format"; | ||
|
||
private static final String GROUP_RETRY_BACKOFF_POLICY = "Retry backoff policy"; | ||
public static final String KAFKA_RETRY_BACKOFF_MS_CONFIG = "kafka.retry.backoff.ms"; | ||
|
||
public CommonConfig(ConfigDef definition, Map<?, ?> originals) { // NOPMD | ||
super(definition, originals); | ||
} | ||
|
||
protected static void addKafkaBackoffPolicy(final ConfigDef configDef) { | ||
configDef.define(KAFKA_RETRY_BACKOFF_MS_CONFIG, ConfigDef.Type.LONG, null, new ConfigDef.Validator() { | ||
|
||
final long maximumBackoffPolicy = TimeUnit.HOURS.toMillis(24); | ||
|
||
@Override | ||
public void ensureValid(final String name, final Object value) { | ||
if (Objects.isNull(value)) { | ||
return; | ||
} | ||
assert value instanceof Long; | ||
final var longValue = (Long) value; | ||
if (longValue < 0) { | ||
throw new ConfigException(name, value, "Value must be at least 0"); | ||
} else if (longValue > maximumBackoffPolicy) { | ||
throw new ConfigException(name, value, | ||
"Value must be no more than " + maximumBackoffPolicy + " (24 hours)"); | ||
} | ||
} | ||
}, ConfigDef.Importance.MEDIUM, | ||
"The retry backoff in milliseconds. " | ||
+ "This config is used to notify Kafka Connect to retry delivering a message batch or " | ||
+ "performing recovery in case of transient exceptions. Maximum value is " | ||
+ TimeUnit.HOURS.toMillis(24) + " (24 hours).", | ||
GROUP_RETRY_BACKOFF_POLICY, 1, ConfigDef.Width.NONE, KAFKA_RETRY_BACKOFF_MS_CONFIG); | ||
} | ||
|
||
public Long getKafkaRetryBackoffMs() { | ||
return getLong(KAFKA_RETRY_BACKOFF_MS_CONFIG); | ||
} | ||
|
||
} |
Oops, something went wrong.