use of com.hubspot.singularity.SingularityRequest in project Singularity by HubSpot.
the class RequestResource method checkAuthForGroupsUpdate.
@POST
@Path("/request/{requestId}/groups/auth-check")
@ApiOperation(value = "Check authorization for updating the group, readOnlyGroups, and readWriteGroups for a SingularityReques, without commiting the change")
@ApiResponses({ @ApiResponse(code = 200, message = "User is authorized to make these changes"), @ApiResponse(code = 401, message = "User is not authorized to make these updates") })
public Response checkAuthForGroupsUpdate(@Auth SingularityUser user, @PathParam("requestId") String requestId, @ApiParam("Updated groups") SingularityUpdateGroupsRequest updateGroupsRequest) {
Optional<SingularityRequestWithState> maybeOldRequestWithState = requestManager.getRequest(requestId, false);
if (!maybeOldRequestWithState.isPresent()) {
authorizationHelper.checkForAuthorization(user, Sets.union(updateGroupsRequest.getGroup().asSet(), updateGroupsRequest.getReadWriteGroups()), updateGroupsRequest.getReadOnlyGroups(), SingularityAuthorizationScope.WRITE, Optional.absent());
return Response.ok().build();
}
SingularityRequestWithState oldRequestWithState = maybeOldRequestWithState.get();
authorizationHelper.checkForAuthorization(oldRequestWithState.getRequest(), user, SingularityAuthorizationScope.WRITE);
SingularityRequest newRequest = oldRequestWithState.getRequest().toBuilder().setGroup(updateGroupsRequest.getGroup()).setReadWriteGroups(Optional.of(updateGroupsRequest.getReadWriteGroups())).setReadOnlyGroups(Optional.of(updateGroupsRequest.getReadOnlyGroups())).build();
authorizationHelper.checkForAuthorizedChanges(newRequest, oldRequestWithState.getRequest(), user);
return Response.ok().build();
}
use of com.hubspot.singularity.SingularityRequest in project Singularity by HubSpot.
the class RequestHelper method updateRequest.
public void updateRequest(SingularityRequest request, Optional<SingularityRequest> maybeOldRequest, RequestState requestState, Optional<RequestHistoryType> historyType, Optional<String> user, Optional<Boolean> skipHealthchecks, Optional<String> message, Optional<SingularityBounceRequest> maybeBounceRequest) {
SingularityRequestDeployHolder deployHolder = getDeployHolder(request.getId());
SingularityRequest newRequest = validator.checkSingularityRequest(request, maybeOldRequest, deployHolder.getActiveDeploy(), deployHolder.getPendingDeploy());
final long now = System.currentTimeMillis();
if (requestState == RequestState.FINISHED && maybeOldRequest.isPresent() && shouldReschedule(newRequest, maybeOldRequest.get())) {
requestState = RequestState.ACTIVE;
}
RequestHistoryType historyTypeToSet = null;
if (historyType.isPresent()) {
historyTypeToSet = historyType.get();
} else if (maybeOldRequest.isPresent()) {
historyTypeToSet = RequestHistoryType.UPDATED;
} else {
historyTypeToSet = RequestHistoryType.CREATED;
}
requestManager.save(newRequest, requestState, historyTypeToSet, now, user, message);
checkReschedule(newRequest, maybeOldRequest, user, now, skipHealthchecks, message, maybeBounceRequest);
}
use of com.hubspot.singularity.SingularityRequest in project Singularity by HubSpot.
the class SingularityStartup method checkActiveRequest.
private void checkActiveRequest(SingularityRequestWithState requestWithState, Map<SingularityDeployKey, SingularityPendingTaskId> deployKeyToPendingTaskId, final long timestamp) {
final SingularityRequest request = requestWithState.getRequest();
if (request.getRequestType() == RequestType.ON_DEMAND || request.getRequestType() == RequestType.RUN_ONCE) {
// There's no situation where we'd want to schedule an On Demand or Run Once request at startup, so don't even bother with them.
return;
}
Optional<SingularityRequestDeployState> requestDeployState = deployManager.getRequestDeployState(request.getId());
if (!requestDeployState.isPresent() || !requestDeployState.get().getActiveDeploy().isPresent()) {
LOG.debug("No active deploy for {} - not scheduling on startup", request.getId());
return;
}
final String activeDeployId = requestDeployState.get().getActiveDeploy().get().getDeployId();
if (request.isScheduled()) {
SingularityDeployKey deployKey = new SingularityDeployKey(request.getId(), activeDeployId);
SingularityPendingTaskId pendingTaskId = deployKeyToPendingTaskId.get(deployKey);
if (pendingTaskId != null && pendingTaskId.getCreatedAt() >= requestWithState.getTimestamp()) {
LOG.info("Not rescheduling {} because {} is newer than {}", request.getId(), pendingTaskId, requestWithState.getTimestamp());
return;
}
}
requestManager.addToPendingQueue(new SingularityPendingRequest(request.getId(), activeDeployId, timestamp, Optional.<String>absent(), PendingType.STARTUP, Optional.<Boolean>absent(), Optional.<String>absent()));
}
Aggregations