use of com.hubspot.singularity.SingularityPendingTask in project Singularity by HubSpot.
the class SingularitySchedulerTest method testSchedulerIsolatesPendingTasksBasedOnDeploy.
@Test
public void testSchedulerIsolatesPendingTasksBasedOnDeploy() {
initRequest();
initFirstDeploy();
initSecondDeploy();
SingularityPendingTask p1 = pendingTask(requestId, firstDeployId, PendingType.ONEOFF);
SingularityPendingTask p2 = pendingTask(requestId, firstDeployId, PendingType.TASK_DONE);
SingularityPendingTask p3 = pendingTask(requestId, secondDeployId, PendingType.TASK_DONE);
taskManager.savePendingTask(p1);
taskManager.savePendingTask(p2);
taskManager.savePendingTask(p3);
requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, secondDeployId, System.currentTimeMillis(), Optional.<String>absent(), PendingType.NEW_DEPLOY, Optional.<Boolean>absent(), Optional.<String>absent()));
scheduler.drainPendingQueue();
// we expect there to be 3 pending tasks :
List<SingularityPendingTask> returnedScheduledTasks = taskManager.getPendingTasks();
Assert.assertEquals(3, returnedScheduledTasks.size());
Assert.assertTrue(returnedScheduledTasks.contains(p1));
Assert.assertTrue(returnedScheduledTasks.contains(p2));
Assert.assertTrue(!returnedScheduledTasks.contains(p3));
boolean found = false;
for (SingularityPendingTask pendingTask : returnedScheduledTasks) {
if (pendingTask.getPendingTaskId().getDeployId().equals(secondDeployId)) {
found = true;
Assert.assertEquals(PendingType.NEW_DEPLOY, pendingTask.getPendingTaskId().getPendingType());
}
}
Assert.assertTrue(found);
}
use of com.hubspot.singularity.SingularityPendingTask 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.SingularityPendingTask in project Singularity by HubSpot.
the class SingularitySchedulerTestBase method prepTask.
protected SingularityTask prepTask(SingularityRequest request, SingularityDeploy deploy, long launchTime, int instanceNo, boolean separateHosts, Optional<String> runId) {
SingularityPendingTask pendingTask = buildPendingTask(request, deploy, launchTime, instanceNo, runId);
SingularityTaskRequest taskRequest = new SingularityTaskRequest(request, deploy, pendingTask);
Offer offer;
if (separateHosts) {
offer = createOffer(125, 1024, 2048, String.format("slave%s", instanceNo), String.format("host%s", instanceNo));
} else {
offer = createOffer(125, 1024, 2048);
}
SingularityTaskId taskId = new SingularityTaskId(request.getId(), deploy.getId(), launchTime, instanceNo, offer.getHostname(), "rack1");
TaskID taskIdProto = TaskID.newBuilder().setValue(taskId.toString()).build();
TaskInfo taskInfo = TaskInfo.newBuilder().setAgentId(offer.getAgentId()).setExecutor(ExecutorInfo.newBuilder().setExecutorId(ExecutorID.newBuilder().setValue("executorID"))).setTaskId(taskIdProto).setName("name").build();
SingularityTask task = new SingularityTask(taskRequest, taskId, Collections.singletonList(mesosProtosUtils.offerFromProtos(offer)), mesosProtosUtils.taskFromProtos(taskInfo), Optional.of("rack1"));
taskManager.savePendingTask(pendingTask);
return task;
}
use of com.hubspot.singularity.SingularityPendingTask in project Singularity by HubSpot.
the class SingularityDeploysTest method testDeployManagerHandlesFailedLBTask.
@Test
public void testDeployManagerHandlesFailedLBTask() {
initLoadBalancedRequest();
initFirstDeploy();
SingularityTask firstTask = startTask(firstDeploy);
initSecondDeploy();
SingularityTask secondTask = startTask(secondDeploy);
// this should cause an LB call to happen:
deployChecker.checkDeploys();
Assert.assertTrue(taskManager.getLoadBalancerState(secondTask.getTaskId(), LoadBalancerRequestType.ADD).isPresent());
Assert.assertTrue(!taskManager.getLoadBalancerState(secondTask.getTaskId(), LoadBalancerRequestType.DEPLOY).isPresent());
Assert.assertTrue(!taskManager.getLoadBalancerState(secondTask.getTaskId(), LoadBalancerRequestType.REMOVE).isPresent());
statusUpdate(secondTask, TaskState.TASK_FAILED);
statusUpdate(firstTask, TaskState.TASK_FAILED);
scheduler.drainPendingQueue();
deployChecker.checkDeploys();
Assert.assertTrue(deployManager.getDeployResult(requestId, secondDeployId).get().getDeployState() == DeployState.FAILED);
List<SingularityPendingTask> pendingTasks = taskManager.getPendingTasks();
Assert.assertTrue(pendingTasks.size() == 1);
Assert.assertTrue(pendingTasks.get(0).getPendingTaskId().getDeployId().equals(firstDeployId));
}
use of com.hubspot.singularity.SingularityPendingTask in project Singularity by HubSpot.
the class SingularityMesosTaskBuilderTest method testEnvironmentVariableOverrides.
@Test
public void testEnvironmentVariableOverrides() {
Map<String, String> overrideVariables = new HashMap<>();
overrideVariables.put("MY_NEW_ENV_VAR", "test");
overrideVariables.put("STARTED_BY_USER", "notTestUser");
final SingularityRequest request = new SingularityRequestBuilder("test", RequestType.WORKER).build();
final SingularityDeploy deploy = new SingularityDeployBuilder("test", "1").setCommand(Optional.of("/bin/echo hi")).build();
final SingularityPendingTask pendingTask = new SingularityPendingTaskBuilder().setPendingTaskId(new SingularityPendingTaskId("test", "1", 0, 1, PendingType.IMMEDIATE, 0)).setUser(user).setEnvOverrides(overrideVariables).build();
final SingularityTaskRequest taskRequest = new SingularityTaskRequest(request, deploy, pendingTask);
final TaskInfo task = builder.buildTask(offerHolder, null, taskRequest, taskResources, executorResources).getMesosTask();
Map<String, String> environmentVariables = task.getCommand().getEnvironment().getVariablesList().stream().collect(Collectors.toMap(Variable::getName, Variable::getValue));
for (String key : overrideVariables.keySet()) {
assertEquals("Environment variable " + key + " not overridden.", environmentVariables.get(key), overrideVariables.get(key));
}
}
Aggregations