seatunnel
seatunnel copied to clipboard
[Improve][Connector-V2] Migrate Kafka Source imperative validation to declarative OptionRule
Purpose of this pull request
Related #11007 Depends on #11121
- Migrate 4 imperative
if/throwchecks inKafkaSourceConfig.createConsumerMetadata()to declarativeConditionsinKafkaSourceFactory.optionRule() - Add
greaterOrEqual(START_MODE_TIMESTAMP, 0L)constraint whenstart_mode = TIMESTAMP - Add
greaterOrEqual(START_MODE_END_TIMESTAMP, 0L)optional value constraint - Add
mapNotEmpty(START_MODE_OFFSETS)constraint whenstart_mode = SPECIFIC_OFFSETS - Replace
KEY_PARTITION_DISCOVERY_INTERVAL_MILLISconditional-required withgreaterThan(..., 0L)value constraint whenignore_no_leader_partition = true - Retain runtime-only checks (
> currentTimestamp) with explanatory comments
Does this PR introduce any user-facing change?
Yes — previously invalid configurations (negative timestamps, empty offsets map) were rejected at task execution time with generic IllegalArgumentException. Now they are rejected earlier at job submission time with structured OptionValidationException including option name, constraint type, and violation details.
How was this patch tested?
Unit tests in KafkaFactoryTest:
testValidTimestampConfig— valid TIMESTAMP mode passes validationtestNegativeTimestampRejected— negativestart_mode.timestampis rejectedtestNegativeEndTimestampRejected— negativestart_mode.end_timestampis rejectedtestValidSpecificOffsetsConfig— valid SPECIFIC_OFFSETS mode passes validationtestEmptyOffsetsMapRejected— empty offsets map is rejected
./mvnw test -pl seatunnel-connectors-v2/connector-kafka -Dtest="KafkaFactoryTest" -DfailIfNoTests=false