Skip to content

[feat](fe) Add ClusterGuard SPI interface for cluster-level policy enforcement#62031

Open
morningman wants to merge 3 commits intoapache:masterfrom
morningman:cluster_guard
Open

[feat](fe) Add ClusterGuard SPI interface for cluster-level policy enforcement#62031
morningman wants to merge 3 commits intoapache:masterfrom
morningman:cluster_guard

Conversation

@morningman
Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: N/A

Problem Summary:
Add a ClusterGuard SPI (Service Provider Interface) abstraction in fe-core to
decouple cluster-level policy enforcement (e.g., node limits, time validity checks)
from business logic. The open-source fe-core depends only on the interface, while
commercial implementations can be plugged in at runtime via Java ServiceLoader
without any compile-time dependency on fe-core.

Key changes:

  • Add ClusterGuard interface with onStartup, checkTimeValidity, checkNodeLimit and getGuardInfo methods
  • Add ClusterGuardFactory using Java ServiceLoader to discover implementations at runtime
  • Add NoOpClusterGuard as the open-source no-op default implementation
  • Add ClusterGuardException for guard-related error reporting
  • Add ClusterGuardAction HTTP API at /api/cluster_guard/ for status query
  • Integrate ClusterGuardFactory.getGuard() into DorisFE.java (startup) and SystemInfoService.java (addBackend/dropBackend)

Release note

None

Check List (For Author)

  • Test: No need to test (internal SPI wiring, no behavior change in open-source build)
  • Behavior changed: No
  • Does this need documentation: No

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

…forcement

### What problem does this PR solve?

Issue Number: N/A

Problem Summary:
Add a ClusterGuard SPI (Service Provider Interface) abstraction in fe-core to
decouple cluster-level policy enforcement (e.g., node limits, time validity checks)
from business logic. The open-source fe-core depends only on the interface, while
commercial implementations can be plugged in at runtime via Java ServiceLoader
without any compile-time dependency on fe-core.

Key changes:
- Add `ClusterGuard` interface with `onStartup`, `checkTimeValidity`, `checkNodeLimit` and `getGuardInfo` methods
- Add `ClusterGuardFactory` using Java ServiceLoader to discover implementations at runtime
- Add `NoOpClusterGuard` as the open-source no-op default implementation
- Add `ClusterGuardException` for guard-related error reporting
- Add `ClusterGuardAction` HTTP API at `/api/cluster_guard/` for status query
- Integrate `ClusterGuardFactory.getGuard()` into `DorisFE.java` (startup) and `SystemInfoService.java` (addBackend/dropBackend)

### Release note

None

### Check List (For Author)

- Test: No need to test (internal SPI wiring, no behavior change in open-source build)
- Behavior changed: No
- Does this need documentation: No

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hello-stephen
Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

### What problem does this PR solve?

Issue Number: N/A

Problem Summary:
Add unit tests for the ClusterGuard SPI abstraction added in fe-core:
- NoOpClusterGuardTest: verifies all no-op methods pass without exception and getGuardInfo returns "{}"
- ClusterGuardExceptionTest: verifies message/cause constructors and checked-exception contract
- ClusterGuardFactoryTest: verifies singleton behavior, fallback to NoOpClusterGuard when no SPI provider is found, and correctness of custom guard injection

### Release note

None

### Check List (For Author)

- Test: Unit Test
- Behavior changed: No
- Does this need documentation: No

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@morningman
Copy link
Copy Markdown
Contributor Author

run buildall

Cast to Object before instanceof RuntimeException check to avoid
incompatible-types compile error — ClusterGuardException is statically
known to be a checked exception so the compiler rejects the direct cast.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@morningman
Copy link
Copy Markdown
Contributor Author

run feut

@hello-stephen
Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 33.01% (34/103) 🎉
Increment coverage report
Complete coverage report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants