use of com.hubspot.mesos.Resources 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.mesos.Resources in project Singularity by HubSpot.
the class SingularitySchedulerTest method testRequestedPorts.
@Test
public void testRequestedPorts() {
final SingularityDeployBuilder deployBuilder = dockerDeployWithPorts();
initRequest();
initAndFinishDeploy(request, deployBuilder, Optional.of(new Resources(1, 64, 3, 0)));
requestResource.postRequest(request.toBuilder().setInstances(Optional.of(2)).build(), singularityUser);
scheduler.drainPendingQueue();
String[] portRangeWithNoRequestedPorts = { "65:70" };
sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1", Optional.<String>absent(), Collections.<String, String>emptyMap(), portRangeWithNoRequestedPorts)));
Assert.assertEquals(0, taskManager.getActiveTasks().size());
String[] portRangeWithSomeRequestedPorts = { "80:82" };
sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1", Optional.<String>absent(), Collections.<String, String>emptyMap(), portRangeWithSomeRequestedPorts)));
Assert.assertEquals(0, taskManager.getActiveTasks().size());
String[] portRangeWithRequestedButNotEnoughPorts = { "80:80", "8080:8080" };
sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1", Optional.<String>absent(), Collections.<String, String>emptyMap(), portRangeWithRequestedButNotEnoughPorts)));
Assert.assertEquals(0, taskManager.getActiveTasks().size());
String[] portRangeWithNeededPorts = { "80:83", "8080:8080" };
sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1", Optional.<String>absent(), Collections.<String, String>emptyMap(), portRangeWithNeededPorts)));
Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
}
use of com.hubspot.mesos.Resources in project Singularity by HubSpot.
the class SingularityMesosTaskBuilderTest method testGetPortByIndex.
@Test
public void testGetPortByIndex() throws Exception {
taskResources = new Resources(1, 1, 4, 0);
final Protos.Resource portsResource = Protos.Resource.newBuilder().setName("ports").setType(Protos.Value.Type.RANGES).setRanges(Protos.Value.Ranges.newBuilder().addRange(Protos.Value.Range.newBuilder().setBegin(31003).setEnd(31004).build()).addRange(Protos.Value.Range.newBuilder().setBegin(31000).setEnd(31001).build()).build()).build();
final SingularityRequest request = new SingularityRequestBuilder("test", RequestType.WORKER).build();
final SingularityDeploy deploy = new SingularityDeployBuilder("test", "1").setCommand(Optional.of("/bin/echo")).setArguments(Optional.of(Collections.singletonList("wat"))).build();
final SingularityTaskRequest taskRequest = new SingularityTaskRequest(request, deploy, pendingTask);
final SingularityMesosTaskHolder task = builder.buildTask(offerHolder, Collections.singletonList(portsResource), taskRequest, taskResources, executorResources);
assertEquals(31003L, task.getTask().getPortByIndex(2).get().longValue());
}
Aggregations