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.usePD()) {
throw new HugeException(
"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);
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 All @@ -106,6 +108,7 @@ public Object get(@Context GraphManager manager,
public Object listProfile(@Context GraphManager manager,
@QueryParam("prefix") String prefix,
@Context SecurityContext sc) {
checkPdModeEnabled(manager);
Set<String> spaces = manager.graphSpaces();
List<Map<String, Object>> spaceList = new ArrayList<>();
List<Map<String, Object>> result = new ArrayList<>();
Expand Down Expand Up @@ -155,7 +158,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 +189,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 +318,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 @@ -276,7 +276,7 @@ private static String serviceId(String graphSpace, Service.ServiceType type,
.replace("_", "-").toLowerCase();
}

private boolean usePD() {
public boolean usePD() {
return this.PDExist;
}

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