use of com.hubspot.singularity.api.SingularityRunNowRequest in project Singularity by HubSpot.
the class SingularityValidator method checkRunNowRequest.
public SingularityPendingRequest checkRunNowRequest(String deployId, Optional<String> userEmail, SingularityRequest request, Optional<SingularityRunNowRequest> maybeRunNowRequest, List<SingularityTaskId> activeTasks, List<SingularityPendingTaskId> pendingTasks) {
SingularityRunNowRequest runNowRequest = fillRunNowRequest(maybeRunNowRequest);
PendingType pendingType;
if (request.isScheduled()) {
pendingType = PendingType.IMMEDIATE;
checkConflict(activeTasks.isEmpty(), "Cannot request immediate run of a scheduled job which is currently running (%s)", activeTasks);
} else if (request.isOneOff()) {
pendingType = PendingType.ONEOFF;
if (request.getInstances().isPresent()) {
checkRateLimited(activeTasks.size() + pendingTasks.size() < request.getInstances().get(), "No more than %s tasks allowed to run concurrently for request %s (%s active, %s pending)", request.getInstances().get(), request, activeTasks.size(), pendingTasks.size());
}
} else {
throw badRequest("Can not request an immediate run of a non-scheduled / always running request (%s)", request);
}
if (runNowRequest.getRunAt().isPresent() && runNowRequest.getRunAt().get() > (System.currentTimeMillis() + TimeUnit.DAYS.toMillis(maxRunNowTaskLaunchDelay))) {
throw badRequest("Task launch delay can be at most %d days from now.", maxRunNowTaskLaunchDelay);
}
return new SingularityPendingRequest(request.getId(), deployId, System.currentTimeMillis(), userEmail, pendingType, runNowRequest.getCommandLineArgs(), Optional.of(getRunId(runNowRequest.getRunId())), runNowRequest.getSkipHealthchecks(), runNowRequest.getMessage(), Optional.absent(), runNowRequest.getResources(), runNowRequest.getS3UploaderAdditionalFiles(), runNowRequest.getRunAsUserOverride(), runNowRequest.getEnvOverrides(), runNowRequest.getExtraArtifacts(), runNowRequest.getRunAt());
}
use of com.hubspot.singularity.api.SingularityRunNowRequest 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.api.SingularityRunNowRequest 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.api.SingularityRunNowRequest 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.api.SingularityRunNowRequest in project Singularity by HubSpot.
the class ValidatorTest method itForbidsRunNowOfScheduledWhenAlreadyRunning.
@Test(expected = WebApplicationException.class)
public void itForbidsRunNowOfScheduledWhenAlreadyRunning() {
String deployID = "deploy";
Optional<String> userEmail = Optional.absent();
SingularityRequest request = new SingularityRequestBuilder("request2", RequestType.SCHEDULED).setInstances(Optional.of(1)).build();
Optional<SingularityRunNowRequest> runNowRequest = Optional.absent();
List<SingularityTaskId> activeTasks = Collections.singletonList(activeTask());
List<SingularityPendingTaskId> pendingTasks = Collections.emptyList();
validator.checkRunNowRequest(deployID, userEmail, request, runNowRequest, activeTasks, pendingTasks);
}
Aggregations