Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@ public static boolean checkAndParseAction(String action) {
}
}

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.
"GraphSpace management is not supported in standalone mode");
}
}

public static boolean hasAdminPerm(GraphManager manager, String user) {
return manager.authManager().isAdminManager(user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public String createManager(@Context GraphManager manager,
@PathParam("graphspace") String graphSpace,
JsonManager jsonManager) {
LOG.debug("Create manager: {}", jsonManager);
checkPdModeEnabled(manager);
String user = jsonManager.user;
HugePermission type = jsonManager.type;
// graphSpace now comes from @PathParam instead of JsonManager
Expand Down Expand Up @@ -117,6 +118,7 @@ public void delete(@Context GraphManager manager,
@QueryParam("user") String user,
@QueryParam("type") HugePermission type) {
LOG.debug("Delete graph manager: {} {} {}", user, type, graphSpace);
checkPdModeEnabled(manager);
E.checkArgument(!"admin".equals(user) ||
type != HugePermission.ADMIN,
"User 'admin' can't be removed from ADMIN");
Expand Down Expand Up @@ -160,7 +162,7 @@ public String list(@Context GraphManager manager,
@PathParam("graphspace") String graphSpace,
@QueryParam("type") HugePermission type) {
LOG.debug("list graph manager: {} {}", type, graphSpace);

checkPdModeEnabled(manager);
AuthManager authManager = manager.authManager();
validType(type);
List<String> adminManagers;
Expand Down Expand Up @@ -190,7 +192,7 @@ public String checkRole(@Context GraphManager manager,
@PathParam("graphspace") String graphSpace,
@QueryParam("type") HugePermission type) {
LOG.debug("check if current user is graph manager: {} {}", type, graphSpace);

checkPdModeEnabled(manager);
validType(type);
AuthManager authManager = manager.authManager();
String user = HugeGraphAuthProxy.username();
Expand Down Expand Up @@ -222,6 +224,7 @@ public String getRolesInGs(@Context GraphManager manager,
@PathParam("graphspace") String graphSpace,
@QueryParam("user") String user) {
LOG.debug("get user [{}]'s role in graph space [{}]", user, graphSpace);
checkPdModeEnabled(manager);
AuthManager authManager = manager.authManager();
List<HugePermission> result = new ArrayList<>();
validGraphSpace(manager, graphSpace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class GraphSpaceAPI extends API {
@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.

Set<String> spaces = manager.graphSpaces();
return ImmutableMap.of("graphSpaces", spaces);
}
Expand All @@ -86,6 +87,7 @@ public Object list(@Context GraphManager manager,
@Produces(APPLICATION_JSON_WITH_CHARSET)
public Object get(@Context GraphManager manager,
@PathParam("graphspace") String graphSpace) {
checkPdModeEnabled(manager);
manager.getSpaceStorage(graphSpace);
GraphSpace gs = space(manager, graphSpace);

Expand Down Expand Up @@ -155,7 +157,7 @@ public Object listProfile(@Context GraphManager manager,
@RolesAllowed({"admin"})
public String create(@Context GraphManager manager,
JsonGraphSpace jsonGraphSpace) {

checkPdModeEnabled(manager);
jsonGraphSpace.checkCreate(false);

String creator = HugeGraphAuthProxy.username();
Expand Down Expand Up @@ -186,7 +188,7 @@ public boolean isPrefix(Map<String, Object> profile, String prefix) {
public Map<String, Object> manage(@Context GraphManager manager,
@PathParam("name") String name,
Map<String, Object> actionMap) {

checkPdModeEnabled(manager);
E.checkArgument(actionMap != null && actionMap.size() == 2 &&
actionMap.containsKey(GRAPH_SPACE_ACTION),
"Invalid request body '%s'", actionMap);
Expand Down Expand Up @@ -315,6 +317,7 @@ public Map<String, Object> manage(@Context GraphManager manager,
@RolesAllowed({"admin"})
public void delete(@Context GraphManager manager,
@PathParam("name") String name) {
checkPdModeEnabled(manager);
manager.dropGraphSpace(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ private boolean usePD() {
return this.PDExist;
}

public boolean isUsePD() {
return this.PDExist;
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

GraphManager already has a private usePD() helper used internally; adding a separate public isUsePD() with the same implementation duplicates the source of truth and risks divergence over time. Consider either making usePD() public (or package-private) and using it consistently, or having isUsePD() delegate to usePD().

Suggested change
return this.PDExist;
return this.usePD();

Copilot uses AI. Check for mistakes.
}
Comment on lines +283 to +285
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.

private static void registerCacheMetrics(Map<String, Cache<?, ?>> caches) {
Set<String> names = MetricManager.INSTANCE.getRegistry().getNames();
for (Map.Entry<String, Cache<?, ?>> entry : caches.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
CypherApiTest.class,
ArthasApiTest.class,
GraphSpaceApiTest.class,
GraphSpaceApiStandaloneTest.class,
ManagerApiStandaloneTest.class,
})
public class ApiTestSuite {

Expand Down
Loading
Loading