Search in sources :

Example 1 with SingularityDeployRequest

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));
}
Also used : SingularityDeployKey(com.hubspot.singularity.SingularityDeployKey) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) HttpResponse(com.hubspot.horizon.HttpResponse) SingularityRequestParent(com.hubspot.singularity.SingularityRequestParent)

Example 2 with SingularityDeployRequest

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());
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Test(org.junit.Test)

Example 3 with SingularityDeployRequest

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());
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Example 4 with SingularityDeployRequest

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();
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Test(org.junit.Test)

Example 5 with SingularityDeployRequest

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);
}
Also used : SingularityRunNowRequest(com.hubspot.singularity.api.SingularityRunNowRequest) SingularityRunNowRequestBuilder(com.hubspot.singularity.SingularityRunNowRequestBuilder) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Aggregations

SingularityDeployRequest (com.hubspot.singularity.api.SingularityDeployRequest)18 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)15 Test (org.junit.Test)14 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)10 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)8 SingularityRequest (com.hubspot.singularity.SingularityRequest)6 SingularityRunNowRequestBuilder (com.hubspot.singularity.SingularityRunNowRequestBuilder)3 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)3 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)3 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)2 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)2 SingularityTask (com.hubspot.singularity.SingularityTask)2 HttpResponse (com.hubspot.horizon.HttpResponse)1 Resources (com.hubspot.mesos.Resources)1 SingularityDeployKey (com.hubspot.singularity.SingularityDeployKey)1 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)1 SingularityPriorityFreezeParent (com.hubspot.singularity.SingularityPriorityFreezeParent)1 SingularityRequestParent (com.hubspot.singularity.SingularityRequestParent)1 SingularityPriorityFreeze (com.hubspot.singularity.api.SingularityPriorityFreeze)1 ArrayList (java.util.ArrayList)1