Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SupervisorManager: Add authorization checks to bulk endpoints. #8044

Merged
merged 1 commit into from
Jul 9, 2019
Merged
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 @@ -107,26 +107,6 @@ public boolean suspendOrResumeSupervisor(String id, boolean suspend)
}
}

public void stopAndRemoveAllSupervisors()
{
Preconditions.checkState(started, "SupervisorManager not started");

synchronized (lock) {
Preconditions.checkState(started, "SupervisorManager not started");
supervisors.keySet().forEach(id -> possiblyStopAndRemoveSupervisorInternal(id, true));
}
}

public void suspendOrResumeAllSupervisors(boolean suspend)
{
Preconditions.checkState(started, "SupervisorManager not started");

synchronized (lock) {
Preconditions.checkState(started, "SupervisorManager not started");
supervisors.keySet().forEach(id -> possiblySuspendOrResumeSupervisorInternal(id, suspend));
}
}

@LifecycleStart
public void start()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,27 +306,36 @@ public Response terminate(@PathParam("id") final String id)
@POST
@Path("/suspendAll")
@Produces(MediaType.APPLICATION_JSON)
public Response suspendAll()
public Response suspendAll(@Context final HttpServletRequest req)
{
return suspendOrResumeAll(true);
return suspendOrResumeAll(req, true);
}

@POST
@Path("/resumeAll")
@Produces(MediaType.APPLICATION_JSON)
public Response resumeAll()
public Response resumeAll(@Context final HttpServletRequest req)
{
return suspendOrResumeAll(false);
return suspendOrResumeAll(req, false);
}

@POST
@Path("/terminateAll")
@Produces(MediaType.APPLICATION_JSON)
public Response terminateAll()
public Response terminateAll(@Context final HttpServletRequest req)
{
return asLeaderWithSupervisorManager(
manager -> {
manager.stopAndRemoveAllSupervisors();
Set<String> authorizedSupervisorIds = filterAuthorizedSupervisorIds(
req,
manager,
manager.getSupervisorIds()
);

for (final String supervisorId : authorizedSupervisorIds) {
manager.stopAndRemoveSupervisor(supervisorId);
}

return Response.ok(ImmutableMap.of("status", "success")).build();
}
);
Expand Down Expand Up @@ -473,11 +482,20 @@ private Response specSuspendOrResume(final String id, boolean suspend)
);
}

private Response suspendOrResumeAll(boolean suspend)
private Response suspendOrResumeAll(final HttpServletRequest req, final boolean suspend)
{
return asLeaderWithSupervisorManager(
manager -> {
manager.suspendOrResumeAllSupervisors(suspend);
Set<String> authorizedSupervisorIds = filterAuthorizedSupervisorIds(
req,
manager,
manager.getSupervisorIds()
);

for (final String supervisorId : authorizedSupervisorIds) {
manager.suspendOrResumeSupervisor(supervisorId, suspend);
}

return Response.ok(ImmutableMap.of("status", "success")).build();
}
);
Expand Down
Loading