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);
}
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);
}
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());
}
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());
}
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);
}
Aggregations