Search in sources :

Example 1 with SingularityRunNowRequestBuilder

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

the class SingularitySchedulerTest method testCustomResourcesWithRunNowRequest.

@Test
public void testCustomResourcesWithRunNowRequest() {
    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 pendingTaskWithResourcs = taskManager.getPendingTasks().get(0);
    Assert.assertTrue(pendingTaskWithResourcs.getResources().isPresent());
    Assert.assertEquals(pendingTaskWithResourcs.getResources().get().getCpus(), 2, 0.0);
    sms.resourceOffers(Arrays.asList(createOffer(5, 5, 5, "slave1", "host1", Optional.of("rack1"))));
    SingularityTask task = taskManager.getActiveTasks().get(0);
    Assert.assertEquals(MesosUtils.getNumCpus(mesosProtosUtils.toResourceList(task.getMesosTask().getResources()), Optional.<String>absent()), 2.0, 0.0);
}
Also used : SingularityRunNowRequest(com.hubspot.singularity.api.SingularityRunNowRequest) SingularityRunNowRequestBuilder(com.hubspot.singularity.SingularityRunNowRequestBuilder) SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) Resources(com.hubspot.mesos.Resources) Test(org.junit.Test)

Example 2 with SingularityRunNowRequestBuilder

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

Example 3 with SingularityRunNowRequestBuilder

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

the class SingularityDeploysTest method testDeployWithImmediateRunSchedulesAfterRunningImmediately.

@Test
public void testDeployWithImmediateRunSchedulesAfterRunningImmediately() {
    initRequestWithType(RequestType.SCHEDULED, false);
    String deployId = "d1";
    SingularityRunNowRequest runNowRequest = new SingularityRunNowRequestBuilder().setMessage("Message").build();
    SingularityDeploy deploy = new SingularityDeployBuilder(requestId, deployId).setRunImmediately(Optional.of(runNowRequest)).setCommand(Optional.of("printenv > tmp.txt")).build();
    SingularityDeployRequest deployRequest = new SingularityDeployRequest(deploy, Optional.absent(), Optional.absent());
    deployResource.deploy(deployRequest, singularityUser);
    deployChecker.checkDeploys();
    scheduler.drainPendingQueue();
    resourceOffers();
    SingularityTaskId taskId = taskManager.getActiveTaskIdsForDeploy(requestId, deployId).get(0);
    SingularityTask task = taskManager.getTask(taskId).get();
    statusUpdate(task, TaskState.TASK_RUNNING);
    statusUpdate(task, TaskState.TASK_FINISHED);
    scheduler.drainPendingQueue();
    resourceOffers();
    Assert.assertEquals(0, taskManager.getNumActiveTasks());
    Assert.assertEquals(1, taskManager.getNumScheduledTasks());
}
Also used : SingularityRunNowRequest(com.hubspot.singularity.api.SingularityRunNowRequest) SingularityRunNowRequestBuilder(com.hubspot.singularity.SingularityRunNowRequestBuilder) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 4 with SingularityRunNowRequestBuilder

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

the class SingularitySchedulerTest method testRunNowScheduledJobDoesNotRetry.

@Test
public void testRunNowScheduledJobDoesNotRetry() {
    initScheduledRequest();
    SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
    SingularityRequest newRequest = request.toBuilder().setNumRetriesOnFailure(Optional.of(2)).build();
    requestResource.postRequest(newRequest, singularityUser);
    initFirstDeploy();
    requestResource.scheduleImmediately(singularityUser, requestId, new SingularityRunNowRequestBuilder().build());
    resourceOffers();
    SingularityTask task = taskManager.getActiveTasks().get(0);
    statusUpdate(task, TaskState.TASK_FAILED);
    scheduler.drainPendingQueue();
    SingularityDeployStatistics deployStatistics = deployManager.getDeployStatistics(task.getTaskId().getRequestId(), task.getTaskId().getDeployId()).get();
    Assert.assertEquals(MesosTaskState.TASK_FAILED, deployStatistics.getLastTaskState().get().toTaskState().get());
    Assert.assertEquals(PendingType.TASK_DONE, taskManager.getPendingTaskIds().get(0).getPendingType());
    Assert.assertEquals(1, deployStatistics.getNumFailures());
    Assert.assertEquals(0, deployStatistics.getNumSequentialRetries());
    Assert.assertEquals(Optional.<Long>absent(), deployStatistics.getAverageRuntimeMillis());
}
Also used : SingularityRunNowRequestBuilder(com.hubspot.singularity.SingularityRunNowRequestBuilder) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityDeployStatistics(com.hubspot.singularity.SingularityDeployStatistics) Test(org.junit.Test)

Example 5 with SingularityRunNowRequestBuilder

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

Aggregations

SingularityRunNowRequestBuilder (com.hubspot.singularity.SingularityRunNowRequestBuilder)9 Test (org.junit.Test)9 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)6 SingularityTask (com.hubspot.singularity.SingularityTask)5 Resources (com.hubspot.mesos.Resources)3 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)3 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)3 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)3 SingularityDeployRequest (com.hubspot.singularity.api.SingularityDeployRequest)3 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)2 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)2 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)2 SingularityDeployStatistics (com.hubspot.singularity.SingularityDeployStatistics)1 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)1 SingularityRequest (com.hubspot.singularity.SingularityRequest)1 Map (java.util.Map)1