use of com.hubspot.singularity.api.SingularityRunNowRequest 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);
}
use of com.hubspot.singularity.api.SingularityRunNowRequest in project Singularity by HubSpot.
the class SingularitySchedulerTest method testAcceptOffersWithRoleForRequestWithRole.
@Test
public void testAcceptOffersWithRoleForRequestWithRole() {
SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.ON_DEMAND);
bldr.setRequiredRole(Optional.of("test-role"));
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)));
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"))));
SingularityTask task = taskManager.getActiveTasks().get(0);
Assert.assertEquals(MesosUtils.getNumCpus(mesosProtosUtils.toResourceList(task.getMesosTask().getResources()), Optional.of("test-role")), 2.0, 0.0);
}
use of com.hubspot.singularity.api.SingularityRunNowRequest in project Singularity by HubSpot.
the class SingularityDeploysTest method testDeployWithImmediateRunIsLaunchedImmediately.
@Test
public void testDeployWithImmediateRunIsLaunchedImmediately() {
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();
Assert.assertEquals(1, taskManager.getNumActiveTasks());
Assert.assertEquals(0, taskManager.getNumScheduledTasks());
SingularityTaskId taskId = taskManager.getActiveTaskIdsForDeploy(requestId, deployId).get(0);
SingularityTask task = taskManager.getTask(taskId).get();
Map<String, Object> command = (Map<String, Object>) task.getMesosTask().getAllOtherFields().get("command");
Assert.assertEquals("printenv > tmp.txt", (String) command.get("value"));
}
use of com.hubspot.singularity.api.SingularityRunNowRequest in project Singularity by HubSpot.
the class RequestResource method scheduleImmediately.
@POST
@Path("/request/{requestId}/run")
@Consumes({ MediaType.APPLICATION_JSON })
@ApiOperation(value = "Schedule a one-off or scheduled Singularity request for immediate or delayed execution.", response = SingularityRequestParent.class)
@ApiResponses({ @ApiResponse(code = 400, message = "Singularity Request is not scheduled or one-off") })
public SingularityPendingRequestParent scheduleImmediately(@Auth SingularityUser user, @ApiParam("The request ID to run") @PathParam("requestId") String requestId, SingularityRunNowRequest runNowRequest) {
final Optional<SingularityRunNowRequest> maybeRunNowRequest = Optional.fromNullable(runNowRequest);
SingularityRequestWithState requestWithState = fetchRequestWithState(requestId, user);
authorizationHelper.checkForAuthorization(requestWithState.getRequest(), user, SingularityAuthorizationScope.WRITE);
checkConflict(requestWithState.getState() != RequestState.PAUSED, "Request %s is paused. Unable to run now (it must be manually unpaused first)", requestWithState.getRequest().getId());
final SingularityPendingRequest pendingRequest = validator.checkRunNowRequest(getAndCheckDeployId(requestId), user.getEmail(), requestWithState.getRequest(), maybeRunNowRequest, taskManager.getActiveTaskIdsForRequest(requestId), taskManager.getPendingTaskIdsForRequest(requestId));
SingularityCreateResult result = requestManager.addToPendingQueue(pendingRequest);
checkConflict(result != SingularityCreateResult.EXISTED, "%s is already pending, please try again soon", requestId);
return SingularityPendingRequestParent.fromSingularityRequestParent(fillEntireRequest(requestWithState), pendingRequest);
}
Aggregations