Search in sources :

Example 36 with SingularityRequestBuilder

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

the class ValidatorTest method whenRunNowItForbidsTooLongRunIds.

@Test(expected = WebApplicationException.class)
public void whenRunNowItForbidsTooLongRunIds() {
    String deployID = "deploy";
    Optional<String> userEmail = Optional.absent();
    SingularityRequest request = new SingularityRequestBuilder("request2", RequestType.SERVICE).build();
    Optional<SingularityRunNowRequest> runNowRequest = Optional.of(runNowRequest(tooLongId()));
    List<SingularityTaskId> activeTasks = Collections.emptyList();
    List<SingularityPendingTaskId> pendingTasks = Collections.emptyList();
    validator.checkRunNowRequest(deployID, userEmail, request, runNowRequest, activeTasks, pendingTasks);
}
Also used : SingularityRunNowRequest(com.hubspot.singularity.api.SingularityRunNowRequest) SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 37 with SingularityRequestBuilder

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

the class ValidatorTest method itForbidsQuotesInDeployIds.

@Test
public void itForbidsQuotesInDeployIds() throws Exception {
    final String badDeployId = "deployKey'";
    SingularityDeploy singularityDeploy = SingularityDeploy.newBuilder(badDeployId, badDeployId).build();
    SingularityRequest singularityRequest = new SingularityRequestBuilder(badDeployId, RequestType.SERVICE).build();
    WebApplicationException exn = (WebApplicationException) catchThrowable(() -> validator.checkDeploy(singularityRequest, singularityDeploy, Collections.emptyList(), Collections.emptyList()));
    assertThat((String) exn.getResponse().getEntity()).contains("[a-zA-Z0-9_.]");
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) WebApplicationException(javax.ws.rs.WebApplicationException) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Example 38 with SingularityRequestBuilder

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

the class SingularitySchedulerTest method testMultipleRunOnceTasks.

@Test
public void testMultipleRunOnceTasks() {
    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);
    deployChecker.checkDeploys();
    Assert.assertEquals(1, requestManager.getSizeOfPendingQueue());
    deployResource.deploy(new SingularityDeployRequest(new SingularityDeployBuilder(requestId, "d2").setCommand(Optional.of("cmd")).build(), Optional.absent(), Optional.absent()), singularityUser);
    deployChecker.checkDeploys();
    Assert.assertEquals(2, requestManager.getSizeOfPendingQueue());
    scheduler.drainPendingQueue();
    resourceOffers();
    Assert.assertEquals(2, taskManager.getActiveTaskIds().size());
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Test(org.junit.Test)

Example 39 with SingularityRequestBuilder

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

the class SingularitySchedulerTest method testNotAcceptOfferWithRoleForRequestWithoutRole.

@Test
public void testNotAcceptOfferWithRoleForRequestWithoutRole() {
    SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.ON_DEMAND);
    requestResource.postRequest(bldr.build(), singularityUser);
    deploy("d2");
    SingularityRunNowRequest runNowRequest = new SingularityRunNowRequestBuilder().setResources(new Resources(2, 2, 0)).build();
    requestResource.scheduleImmediately(singularityUser, requestId, runNowRequest);
    scheduler.drainPendingQueue();
    SingularityPendingTask pendingTaskWithResources = taskManager.getPendingTasks().get(0);
    Assert.assertTrue(pendingTaskWithResources.getResources().isPresent());
    Assert.assertEquals(pendingTaskWithResources.getResources().get().getCpus(), 2, 0.0);
    sms.resourceOffers(Arrays.asList(createOffer(5, 5, 5, Optional.of("test-role"))));
    pendingTaskWithResources = taskManager.getPendingTasks().get(0);
    Assert.assertTrue(pendingTaskWithResources.getResources().isPresent());
    Assert.assertEquals(pendingTaskWithResources.getResources().get().getCpus(), 2, 0.0);
}
Also used : SingularityRunNowRequest(com.hubspot.singularity.api.SingularityRunNowRequest) SingularityRunNowRequestBuilder(com.hubspot.singularity.SingularityRunNowRequestBuilder) SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) Resources(com.hubspot.mesos.Resources) Test(org.junit.Test)

Example 40 with SingularityRequestBuilder

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

the class SingularitySchedulerTest method testSchedulerPriority.

@Test
public void testSchedulerPriority() {
    final SingularityRequest lowPriorityRequest = new SingularityRequestBuilder("lowPriorityRequest", RequestType.WORKER).setTaskPriorityLevel(Optional.of(.25)).build();
    saveRequest(lowPriorityRequest);
    final SingularityRequest mediumPriorityRequest = new SingularityRequestBuilder("mediumPriorityRequest", RequestType.WORKER).setTaskPriorityLevel(Optional.of(.5)).build();
    saveRequest(mediumPriorityRequest);
    final SingularityRequest highPriorityRequest = new SingularityRequestBuilder("highPriorityRequest", RequestType.WORKER).setTaskPriorityLevel(Optional.of(.75)).build();
    saveRequest(highPriorityRequest);
    final SingularityDeploy lowPriorityDeploy = initAndFinishDeploy(lowPriorityRequest, "lowPriorityDeploy");
    final SingularityDeploy mediumPriorityDeploy = initAndFinishDeploy(mediumPriorityRequest, "mediumPriorityDeploy");
    final SingularityDeploy highPriorityDeploy = initAndFinishDeploy(highPriorityRequest, "highPriorityDeploy");
    // Task requests launched at ~ the same time should be in priority order
    long now = System.currentTimeMillis();
    List<SingularityTaskRequest> requestsByPriority = Arrays.asList(buildTaskRequest(lowPriorityRequest, lowPriorityDeploy, now), buildTaskRequest(mediumPriorityRequest, mediumPriorityDeploy, now), buildTaskRequest(highPriorityRequest, highPriorityDeploy, now));
    List<SingularityTaskRequest> sortedRequestsByPriority = taskPrioritizer.getSortedDueTasks(requestsByPriority);
    Assert.assertEquals(sortedRequestsByPriority.get(0).getRequest().getId(), highPriorityRequest.getId());
    Assert.assertEquals(sortedRequestsByPriority.get(1).getRequest().getId(), mediumPriorityRequest.getId());
    Assert.assertEquals(sortedRequestsByPriority.get(2).getRequest().getId(), lowPriorityRequest.getId());
    // A lower priority task that is long overdue should be run before a higher priority task
    now = System.currentTimeMillis();
    List<SingularityTaskRequest> requestsByOverdueAndPriority = Arrays.asList(// 2 min overdue
    buildTaskRequest(lowPriorityRequest, lowPriorityDeploy, now - 120000), // 60s overdue
    buildTaskRequest(mediumPriorityRequest, mediumPriorityDeploy, now - 30000), // Not overdue
    buildTaskRequest(highPriorityRequest, highPriorityDeploy, now));
    List<SingularityTaskRequest> sortedRequestsByOverdueAndPriority = taskPrioritizer.getSortedDueTasks(requestsByOverdueAndPriority);
    Assert.assertEquals(sortedRequestsByOverdueAndPriority.get(0).getRequest().getId(), lowPriorityRequest.getId());
    Assert.assertEquals(sortedRequestsByOverdueAndPriority.get(1).getRequest().getId(), mediumPriorityRequest.getId());
    Assert.assertEquals(sortedRequestsByOverdueAndPriority.get(2).getRequest().getId(), highPriorityRequest.getId());
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityTaskRequest(com.hubspot.singularity.SingularityTaskRequest) 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