Skip to content

optimize(api): disable GraphSpaceAPI and ManagerAPI in standalone mode#2966

Open
contrueCT wants to merge 5 commits intoapache:masterfrom
contrueCT:feat/disable-graphspace-manager-api-in-standalone
Open

optimize(api): disable GraphSpaceAPI and ManagerAPI in standalone mode#2966
contrueCT wants to merge 5 commits intoapache:masterfrom
contrueCT:feat/disable-graphspace-manager-api-in-standalone

Conversation

@contrueCT
Copy link
Contributor

Purpose of the PR

Main Changes

The issue requires GraphSpaceAPI to return a friendly response in standalone mode. During code investigation, I found that ManagerAPI has a similar problem: in standalone mode, manager.graphSpace(name) returns a fake new GraphSpace("DEFAULT"), which causes ManagerAPI.validGraphSpace() to pass incorrectly. As a result, ManagerAPI can still enter logic that is not actually supported in standalone mode, leading to unfriendly errors or behavior that does not match the API semantics. For consistency and correctness, I applied the same standalone-mode guard to ManagerAPI as well.

  • Add public isUsePD() accessor to GraphManager to expose PD status
  • Add checkPdModeEnabled() helper in API base class
  • Call checkPdModeEnabled() in all public methods of GraphSpaceAPI (list/get/create/manage/delete)
  • Call checkPdModeEnabled() in all public methods of ManagerAPI (createManager/delete/list/checkRole/getRolesInGs)
  • Returns HTTP 400 with message 'GraphSpace management is not supported in standalone mode'
  • Add standalone-mode rejection tests in GraphSpaceApiTest and ManagerApiTest

Verifying these changes

  • Trivial rework / code cleanup without any test coverage. (No Need)
  • Already covered by existing tests, such as (please modify tests here).
  • Need tests and can be verified as follows:
    • xxx

Does this PR potentially affect the following parts?

Documentation Status

  • Doc - TODO
  • Doc - Done
  • Doc - No Need

contrueCT and others added 3 commits March 10, 2026 17:34
- Add public isUsePD() accessor to GraphManager to expose PD status
- Add checkPdModeEnabled() helper in API base class
- Call checkPdModeEnabled() in all public methods of GraphSpaceAPI (list/get/create/manage/delete)
- Call checkPdModeEnabled() in all public methods of ManagerAPI (createManager/delete/list/checkRole/getRolesInGs)
- Returns HTTP 400 with message 'GraphSpace management is not supported in standalone mode'
- Add standalone-mode rejection tests in GraphSpaceApiTest and ManagerApiTest
@imbajin imbajin requested a review from Copilot March 10, 2026 12:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses issue #2964 by disabling GraphSpaceAPI and ManagerAPI endpoints in standalone (non-PD) mode, returning a friendly HTTP 400 error instead of allowing logic that doesn't apply outside of PD mode.

Changes:

  • Added isUsePD() public accessor to GraphManager to expose PD status
  • Added checkPdModeEnabled() static helper in API base class, called at the start of all public methods in GraphSpaceAPI and ManagerAPI
  • Added standalone-mode rejection tests in GraphSpaceApiTest and ManagerApiTest

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
GraphManager.java Exposes isUsePD() as a public method
API.java Adds checkPdModeEnabled() helper throwing HTTP 400 in non-PD mode
GraphSpaceAPI.java Guards all public endpoints with checkPdModeEnabled()
ManagerAPI.java Guards all public endpoints with checkPdModeEnabled()
GraphSpaceApiTest.java Tests that all GraphSpaceAPI endpoints return 400 in standalone mode
ManagerApiTest.java Tests that all ManagerAPI endpoints return 400 in standalone mode

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


public static void checkPdModeEnabled(GraphManager manager) {
if (!manager.isUsePD()) {
throw new HugeException(
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HugeException is a general internal exception and will typically be mapped to an HTTP 500 response, not 400 as intended and as tested. The tests assert HTTP 400 (assertResponseStatus(400, r)), but using HugeException directly will likely result in a 500. You should throw the appropriate exception type that maps to HTTP 400 (e.g., IllegalArgumentException or a BadRequestException), or use an existing API-level exception that carries the desired status code.

Suggested change
throw new HugeException(
throw new IllegalArgumentException(

Copilot uses AI. Check for mistakes.
Comment on lines +283 to +285
public boolean isUsePD() {
return this.PDExist;
}
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The private usePD() method and the newly added public isUsePD() method have identical implementations. The private method should be removed or replaced by delegating to the public one to avoid duplicated logic.

Copilot uses AI. Check for mistakes.
@Produces(APPLICATION_JSON_WITH_CHARSET)
public Object list(@Context GraphManager manager,
@Context SecurityContext sc) {
checkPdModeEnabled(manager);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

‼️ checkPdModeEnabled() is added to the other GraphSpace endpoints, but /graphspaces/profile is still unguarded. In standalone mode this method will continue to return a different result instead of the new 400, so the API contract remains inconsistent. Please add the same guard to listProfile() and extend the standalone coverage to hit /graphspaces/profile as well.


@Test
public void testStandaloneModeForbidsAllEndpoints() {
Assume.assumeFalse("skip this test for hstore (PD mode)",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This standalone test never actually runs. ManagerApiTest#setUpClass() has a class-level Assume.assumeTrue(... hstore ...), so JUnit skips the whole class before the method-level assumeFalse() is reached here. That means this PR adds no regression coverage for the new standalone behavior. Please move these assertions into a test class that is allowed to run without PD, or relax the class-level guard so this method can execute.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will create a new test class for standalone test.

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.

[Bug] protect GraphSpaceAPI in non-hstore status

3 participants