amalsaidov opened a new pull request, #13236:
URL: https://github.com/apache/seatunnel/pull/13236

   Yes, glad to contribute this to Apache SeaTunnel.
   
   ### Purpose of this pull request
   
   Part of #11007 (migrate connector validation to declarative `OptionRule`).
   
   The SNMP source validated its options imperatively inside 
`SnmpSourceConfig`: host and community non-blank, port in `1..65535`, 
`timeout_millis > 0`, `retries >= 0`, and `poll_interval_millis > 0`. Those 
checks ran only when the config object was built, so a bad value passed 
`--check` and failed later with an `IllegalArgumentException`. The SNMP sink 
already declares the same constraints in `SnmpSinkFactory.optionRule()`; this 
brings the source in line.
   
   ### What changed
   
   - `SnmpSourceFactory.optionRule()` now carries the constraints 
declaratively: `notBlank` on `host` and `community`, 
`greaterOrEqual(1).and(lessOrEqual(65535))` on `port`, `greaterThan(0)` on 
`timeout_millis` and `poll_interval_millis`, and `greaterOrEqual(0)` on 
`retries`. This mirrors the sink factory.
   - `FactoryUtil.createAndPrepareSource()` runs `ConfigValidator` against the 
factory rule before constructing the source, so these values are now rejected 
at `--check` time with an `OptionValidationException` that names the offending 
option.
   - Removed the now-redundant range and non-blank checks from 
`SnmpSourceConfig`. OID parsing stays there because it is semantic validation 
(numeric form, uniqueness) that declarative rules cannot express. Host trimming 
is unchanged.
   - No option name, type, default, or accepted range changed. The community 
value is never included in validation messages.
   
   ### Does this PR introduce any user-facing change?
   
   An invalid `port`, `timeout_millis`, `retries`, `poll_interval_millis`, or a 
blank `host`/`community` is now reported at `--check` time with a clear 
validation error naming the option, instead of failing later during source 
construction. Valid configurations are unaffected.
   
   ### How was this patch tested?
   
   - Extended `SnmpSourceFactoryTest` to validate the rule through 
`ConfigValidator`: accepted defaults and numeric boundaries (`port` 1 and 
65535, minimal and maximal timeout/retries/interval), rejected missing 
`host`/`community`/`oids`, rejected blank strings, rejected out-of-range 
numerics (`port` 0 and 65536, non-positive timeout and interval, negative 
retries), and confirmed error messages never disclose the community string.
   - Removed the two `SnmpSourceConfigTest` cases that asserted the constructor 
rejects range/port values, since that path is now covered at the factory. OID 
parsing and host-trim cases remain.
   
   ```
   ./mvnw -pl seatunnel-connectors-v2/connector-snmp -am -DskipTests install
   ./mvnw -pl seatunnel-connectors-v2/connector-snmp test
   ```
   
   Both pass on JDK 21.
   
   ---
   AI-assisted; directed, reviewed and tested by the author.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to