use of com.hubspot.singularity.api.SingularityDeployRequest in project Singularity by HubSpot.
the class SingularityClient method createDeployForSingularityRequest.
public SingularityRequestParent createDeployForSingularityRequest(String requestId, SingularityDeploy pendingDeploy, Optional<Boolean> deployUnpause, Optional<String> message, Optional<SingularityRequest> updatedRequest) {
final Function<String, String> requestUri = (String host) -> String.format(DEPLOYS_FORMAT, getApiBase(host));
HttpResponse response = post(requestUri, String.format("new deploy %s", new SingularityDeployKey(requestId, pendingDeploy.getId())), Optional.of(new SingularityDeployRequest(pendingDeploy, deployUnpause, message, updatedRequest)));
return getAndLogRequestAndDeployStatus(response.getAs(SingularityRequestParent.class));
}
use of com.hubspot.singularity.api.SingularityDeployRequest in project Singularity by HubSpot.
the class SingularitySchedulerTest method testRetries.
@Test
public void testRetries() {
SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.RUN_ONCE);
request = bldr.setNumRetriesOnFailure(Optional.of(2)).build();
saveRequest(request);
deployResource.deploy(new SingularityDeployRequest(new SingularityDeployBuilder(requestId, "d1").setCommand(Optional.of("cmd")).build(), Optional.absent(), Optional.absent()), singularityUser);
scheduler.drainPendingQueue();
deployChecker.checkDeploys();
resourceOffers();
Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_LOST);
resourceOffers();
Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_LOST);
resourceOffers();
Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_LOST);
resourceOffers();
Assert.assertTrue(taskManager.getActiveTaskIds().isEmpty());
}
use of com.hubspot.singularity.api.SingularityDeployRequest in project Singularity by HubSpot.
the class SingularitySchedulerTest method testCronScheduleChanges.
@Test
public void testCronScheduleChanges() throws Exception {
final String requestId = "test-change-cron";
final String oldSchedule = "*/5 * * * *";
final String oldScheduleQuartz = "0 */5 * * * ?";
final String newSchedule = "*/30 * * * *";
final String newScheduleQuartz = "0 */30 * * * ?";
SingularityRequest request = new SingularityRequestBuilder(requestId, RequestType.SCHEDULED).setSchedule(Optional.of(oldSchedule)).build();
request = validator.checkSingularityRequest(request, Optional.<SingularityRequest>absent(), Optional.<SingularityDeploy>absent(), Optional.<SingularityDeploy>absent());
saveRequest(request);
Assert.assertEquals(oldScheduleQuartz, requestManager.getRequest(requestId).get().getRequest().getQuartzScheduleSafe());
initAndFinishDeploy(request, "1");
scheduler.drainPendingQueue();
final SingularityRequest newRequest = request.toBuilder().setSchedule(Optional.of(newSchedule)).setQuartzSchedule(Optional.<String>absent()).build();
final SingularityDeploy newDeploy = new SingularityDeployBuilder(request.getId(), "2").setCommand(Optional.of("sleep 100")).build();
deployResource.deploy(new SingularityDeployRequest(newDeploy, Optional.absent(), Optional.absent(), Optional.of(newRequest)), singularityUser);
deployChecker.checkDeploys();
scheduler.drainPendingQueue();
Assert.assertEquals(newScheduleQuartz, requestManager.getRequest(requestId).get().getRequest().getQuartzScheduleSafe());
}
use of com.hubspot.singularity.api.SingularityDeployRequest in project Singularity by HubSpot.
the class SingularitySchedulerTest method testRunOnceDontMoveDuringDecomission.
@Test
public void testRunOnceDontMoveDuringDecomission() {
SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.RUN_ONCE);
request = bldr.build();
saveRequest(request);
deployResource.deploy(new SingularityDeployRequest(new SingularityDeployBuilder(requestId, "d1").setCommand(Optional.of("cmd")).build(), Optional.absent(), Optional.absent()), singularityUser);
scheduler.drainPendingQueue();
deployChecker.checkDeploys();
validateTaskDoesntMoveDuringDecommission();
}
use of com.hubspot.singularity.api.SingularityDeployRequest in project Singularity by HubSpot.
the class SingularitySchedulerTest method testSchedulerDropsMultipleScheduledTaskInstances.
@Test
public void testSchedulerDropsMultipleScheduledTaskInstances() {
initScheduledRequest();
SingularityDeploy deploy = SingularityDeploy.newBuilder(requestId, firstDeployId).setCommand(Optional.of("sleep 100")).build();
SingularityDeployRequest singularityDeployRequest = new SingularityDeployRequest(deploy, Optional.absent(), Optional.absent(), Optional.absent());
deployResource.deploy(singularityDeployRequest, singularityUser);
scheduler.drainPendingQueue();
requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, firstDeployId, Instant.now().plus(3, ChronoUnit.DAYS).toEpochMilli(), Optional.absent(), PendingType.NEW_DEPLOY, Optional.absent(), Optional.absent()));
SingularityRunNowRequest runNowRequest = new SingularityRunNowRequestBuilder().build();
requestResource.scheduleImmediately(singularityUser, requestId, runNowRequest);
Assert.assertEquals("Both requests make it into the pending queue", 2, requestManager.getPendingRequests().size());
Assert.assertEquals(PendingType.IMMEDIATE, requestManager.getPendingRequests().get(0).getPendingType());
Assert.assertEquals(PendingType.NEW_DEPLOY, requestManager.getPendingRequests().get(1).getPendingType());
scheduler.drainPendingQueue();
Assertions.assertThat(taskManager.getPendingTaskIds()).describedAs("Only the immediate request gets run").hasSize(1).extracting(SingularityPendingTaskId::getPendingType).containsExactly(PendingType.IMMEDIATE);
Assertions.assertThat(requestManager.getPendingRequests()).describedAs("The scheduled request is dropped from the pending queue").hasSize(0);
}
Aggregations