Search in sources :

Example 1 with SingularityRequestBuilder

use of com.hubspot.singularity.SingularityRequestBuilder in project Singularity by HubSpot.

the class SingularitySchedulerTest method testMaxOnDemandTasks.

@Test
public void testMaxOnDemandTasks() {
    SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.ON_DEMAND);
    bldr.setInstances(Optional.of(1));
    requestResource.postRequest(bldr.build(), singularityUser);
    deploy("on_demand_deploy");
    deployChecker.checkDeploys();
    requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, "on_demand_deploy", System.currentTimeMillis(), Optional.<String>absent(), PendingType.ONEOFF, Optional.<List<String>>absent(), Optional.<String>absent(), Optional.<Boolean>absent(), Optional.<String>absent(), Optional.<String>absent()));
    requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, "on_demand_deploy", System.currentTimeMillis(), Optional.<String>absent(), PendingType.ONEOFF, Optional.<List<String>>absent(), Optional.<String>absent(), Optional.<Boolean>absent(), Optional.<String>absent(), Optional.<String>absent()));
    scheduler.drainPendingQueue();
    resourceOffers();
    Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with SingularityRequestBuilder

use of com.hubspot.singularity.SingularityRequestBuilder 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 SingularityRequestBuilder

use of com.hubspot.singularity.SingularityRequestBuilder in project Singularity by HubSpot.

the class SingularitySchedulerTest method testInvalidQuartzTimeZoneErrors.

@Test(expected = WebApplicationException.class)
public void testInvalidQuartzTimeZoneErrors() {
    SingularityRequest req = new SingularityRequestBuilder(requestId, RequestType.SCHEDULED).setQuartzSchedule(Optional.of("*/1 * * * * ? 2020")).setScheduleType(Optional.of(ScheduleType.QUARTZ)).setScheduleTimeZone(Optional.of("invalid_timezone")).build();
    requestResource.postRequest(req, singularityUser);
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityRequest(com.hubspot.singularity.SingularityRequest) Test(org.junit.Test)

Example 4 with SingularityRequestBuilder

use of com.hubspot.singularity.SingularityRequestBuilder in project Singularity by HubSpot.

the class SingularitySchedulerTest method testOneOffsDontRunByThemselves.

@Test
public void testOneOffsDontRunByThemselves() {
    SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.ON_DEMAND);
    requestResource.postRequest(bldr.build(), singularityUser);
    Assert.assertTrue(requestManager.getPendingRequests().isEmpty());
    deploy("d2");
    Assert.assertTrue(requestManager.getPendingRequests().isEmpty());
    deployChecker.checkDeploys();
    Assert.assertTrue(requestManager.getPendingRequests().isEmpty());
    requestResource.scheduleImmediately(singularityUser, requestId);
    resourceOffers();
    Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
    statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_FINISHED);
    resourceOffers();
    Assert.assertEquals(0, taskManager.getActiveTaskIds().size());
    Assert.assertEquals(0, taskManager.getPendingTaskIds().size());
    requestResource.scheduleImmediately(singularityUser, requestId);
    resourceOffers();
    Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
    statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_LOST);
    resourceOffers();
    Assert.assertEquals(0, taskManager.getActiveTaskIds().size());
    Assert.assertEquals(0, taskManager.getPendingTaskIds().size());
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) Test(org.junit.Test)

Example 5 with SingularityRequestBuilder

use of com.hubspot.singularity.SingularityRequestBuilder 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)

Aggregations

SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)52 Test (org.junit.Test)48 SingularityRequest (com.hubspot.singularity.SingularityRequest)37 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)22 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)17 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)12 SingularityTaskRequest (com.hubspot.singularity.SingularityTaskRequest)10 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)9 Resources (com.hubspot.mesos.Resources)8 SingularityDeployRequest (com.hubspot.singularity.api.SingularityDeployRequest)8 SingularityMesosTaskHolder (com.hubspot.singularity.helpers.SingularityMesosTaskHolder)8 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)7 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)5 SingularityContainerInfo (com.hubspot.mesos.SingularityContainerInfo)4 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)4 SingularityDockerInfo (com.hubspot.mesos.SingularityDockerInfo)3 SingularityDockerPortMapping (com.hubspot.mesos.SingularityDockerPortMapping)3 SingularityRunNowRequestBuilder (com.hubspot.singularity.SingularityRunNowRequestBuilder)3 SingularityTask (com.hubspot.singularity.SingularityTask)3 ArrayList (java.util.ArrayList)3