use of com.hubspot.singularity.SingularityPendingRequest in project Singularity by HubSpot.
the class SingularityDeployChecker method maybeUpdatePendingRequest.
private void maybeUpdatePendingRequest(SingularityPendingDeploy pendingDeploy, Optional<SingularityDeploy> deploy, SingularityRequest request, Optional<SingularityUpdatePendingDeployRequest> updatePendingDeployRequest, Optional<SingularityLoadBalancerUpdate> lbUpdate) {
if (updatePendingDeployRequest.isPresent() && pendingDeploy.getDeployProgress().isPresent()) {
SingularityDeployProgress newProgress = pendingDeploy.getDeployProgress().get().withNewTargetInstances(Math.min(updatePendingDeployRequest.get().getTargetActiveInstances(), request.getInstancesSafe()));
updatePendingDeploy(pendingDeploy, lbUpdate.or(pendingDeploy.getLastLoadBalancerUpdate()), DeployState.WAITING, Optional.of(newProgress));
requestManager.addToPendingQueue(new SingularityPendingRequest(request.getId(), pendingDeploy.getDeployMarker().getDeployId(), System.currentTimeMillis(), pendingDeploy.getDeployMarker().getUser(), PendingType.NEXT_DEPLOY_STEP, deploy.isPresent() ? deploy.get().getSkipHealthchecksOnDeploy() : Optional.<Boolean>absent(), pendingDeploy.getDeployMarker().getMessage()));
}
}
use of com.hubspot.singularity.SingularityPendingRequest in project Singularity by HubSpot.
the class ZkMigrationTest method testCmdLineArgsMigration.
@Test
public void testCmdLineArgsMigration() throws Exception {
metadataManager.setZkDataVersion("2");
// save some old stuff
SingularityPendingRequestPrevious p1 = new SingularityPendingRequestPrevious("r1", "d1", 23L, Optional.<String>absent(), PendingType.BOUNCE, Optional.<String>absent());
SingularityPendingRequestPrevious p2 = new SingularityPendingRequestPrevious("r2", "d3", 123L, Optional.of("user1"), PendingType.BOUNCE, Optional.of("cmd line args"));
byte[] p1b = objectMapper.writeValueAsBytes(p1);
byte[] p2b = objectMapper.writeValueAsBytes(p2);
curator.create().creatingParentsIfNeeded().forPath(getPendingPath("r1", "d1"), p1b);
curator.create().creatingParentsIfNeeded().forPath(getPendingPath("r2", "de"), p2b);
SingularityPendingTaskId pt1 = new SingularityPendingTaskId("r1", "d1", 23L, 3, PendingType.BOUNCE, 1L);
SingularityPendingTaskId pt2 = new SingularityPendingTaskId("r2", "d3", 231L, 1, PendingType.UNPAUSED, 23L);
curator.create().creatingParentsIfNeeded().forPath(getPendingPath(pt1));
curator.create().creatingParentsIfNeeded().forPath(getPendingPath(pt2), StringTranscoder.INSTANCE.toBytes("cmd line args"));
migrationRunner.checkMigrations();
Assert.assertTrue(!taskManager.getPendingTask(pt1).get().getCmdLineArgsList().isPresent());
Assert.assertTrue(taskManager.getPendingTask(pt2).get().getCmdLineArgsList().get().get(0).equals("cmd line args"));
Assert.assertTrue(taskManager.getPendingTask(pt2).get().getCmdLineArgsList().get().size() == 1);
Assert.assertTrue(taskManager.getPendingTaskIds().contains(pt1));
Assert.assertTrue(taskManager.getPendingTaskIds().contains(pt2));
Assert.assertTrue(requestManager.getPendingRequests().size() == 2);
for (SingularityPendingRequest r : requestManager.getPendingRequests()) {
if (r.getRequestId().equals("r1")) {
Assert.assertEquals(r.getDeployId(), p1.getDeployId());
Assert.assertEquals(r.getTimestamp(), p1.getTimestamp());
Assert.assertEquals(r.getPendingType(), p1.getPendingType());
Assert.assertTrue(!r.getCmdLineArgsList().isPresent());
Assert.assertEquals(r.getUser(), p1.getUser());
} else {
Assert.assertEquals(r.getDeployId(), p2.getDeployId());
Assert.assertEquals(r.getTimestamp(), p2.getTimestamp());
Assert.assertEquals(r.getPendingType(), p2.getPendingType());
Assert.assertTrue(r.getCmdLineArgsList().get().size() == 1);
Assert.assertTrue(r.getCmdLineArgsList().get().get(0).equals("cmd line args"));
Assert.assertEquals(r.getUser(), p2.getUser());
}
}
}
use of com.hubspot.singularity.SingularityPendingRequest in project Singularity by HubSpot.
the class RequestResource method scheduleImmediately.
@POST
@Path("/request/{requestId}/run")
@Consumes({ MediaType.APPLICATION_JSON })
@ApiOperation(value = "Schedule a one-off or scheduled Singularity request for immediate or delayed execution.", response = SingularityRequestParent.class)
@ApiResponses({ @ApiResponse(code = 400, message = "Singularity Request is not scheduled or one-off") })
public SingularityPendingRequestParent scheduleImmediately(@Auth SingularityUser user, @ApiParam("The request ID to run") @PathParam("requestId") String requestId, SingularityRunNowRequest runNowRequest) {
final Optional<SingularityRunNowRequest> maybeRunNowRequest = Optional.fromNullable(runNowRequest);
SingularityRequestWithState requestWithState = fetchRequestWithState(requestId, user);
authorizationHelper.checkForAuthorization(requestWithState.getRequest(), user, SingularityAuthorizationScope.WRITE);
checkConflict(requestWithState.getState() != RequestState.PAUSED, "Request %s is paused. Unable to run now (it must be manually unpaused first)", requestWithState.getRequest().getId());
final SingularityPendingRequest pendingRequest = validator.checkRunNowRequest(getAndCheckDeployId(requestId), user.getEmail(), requestWithState.getRequest(), maybeRunNowRequest, taskManager.getActiveTaskIdsForRequest(requestId), taskManager.getPendingTaskIdsForRequest(requestId));
SingularityCreateResult result = requestManager.addToPendingQueue(pendingRequest);
checkConflict(result != SingularityCreateResult.EXISTED, "%s is already pending, please try again soon", requestId);
return SingularityPendingRequestParent.fromSingularityRequestParent(fillEntireRequest(requestWithState), pendingRequest);
}
use of com.hubspot.singularity.SingularityPendingRequest in project Singularity by HubSpot.
the class RequestHelper method unpause.
public long unpause(SingularityRequest request, Optional<String> user, Optional<String> message, Optional<Boolean> skipHealthchecks) {
mailer.sendRequestUnpausedMail(request, user, message);
Optional<String> maybeDeployId = deployManager.getInUseDeployId(request.getId());
final long now = System.currentTimeMillis();
requestManager.unpause(request, now, user, message);
if (maybeDeployId.isPresent() && !request.isOneOff()) {
requestManager.addToPendingQueue(new SingularityPendingRequest(request.getId(), maybeDeployId.get(), now, user, PendingType.UNPAUSED, skipHealthchecks, message));
}
return now;
}
use of com.hubspot.singularity.SingularityPendingRequest in project Singularity by HubSpot.
the class StateManagerTest method itDoesntFlagPendingRequestsForUnderOrOverProvisioning.
@Test
public void itDoesntFlagPendingRequestsForUnderOrOverProvisioning() {
initRequest();
initFirstDeploy();
SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
requestManager.activate(request.toBuilder().setInstances(Optional.of(0)).build(), RequestHistoryType.UPDATED, System.currentTimeMillis(), Optional.<String>empty(), Optional.<String>empty());
requestManager.addToPendingQueue(new SingularityPendingRequest(request.getId(), firstDeployId, System.currentTimeMillis(), Optional.<String>empty(), PendingType.ONEOFF, Optional.<Boolean>empty(), Optional.<String>empty()));
Assertions.assertEquals(0, taskManager.getActiveTaskIds().size());
SingularityState state = stateManager.getState(true, false);
Assertions.assertEquals(0, state.getOverProvisionedRequests());
Assertions.assertEquals(0, state.getUnderProvisionedRequests());
}
Aggregations