Search in sources :

Example 16 with Resources

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);
}
Also used : SingularityRunNowRequest(com.hubspot.singularity.api.SingularityRunNowRequest) SingularityRunNowRequestBuilder(com.hubspot.singularity.SingularityRunNowRequestBuilder) SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) Resources(com.hubspot.mesos.Resources) Test(org.junit.Test)

Example 17 with Resources

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());
}
Also used : SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Resources(com.hubspot.mesos.Resources) Test(org.junit.Test)

Example 18 with Resources

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());
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) Protos(org.apache.mesos.v1.Protos) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityMesosTaskHolder(com.hubspot.singularity.helpers.SingularityMesosTaskHolder) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Resources(com.hubspot.mesos.Resources) SingularityTaskRequest(com.hubspot.singularity.SingularityTaskRequest) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Aggregations

Resources (com.hubspot.mesos.Resources)18 Test (org.junit.Test)12 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)10 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)8 SingularityTask (com.hubspot.singularity.SingularityTask)7 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)6 SingularityTaskRequest (com.hubspot.singularity.SingularityTaskRequest)6 SingularityMesosTaskHolder (com.hubspot.singularity.helpers.SingularityMesosTaskHolder)6 SingularityContainerInfo (com.hubspot.mesos.SingularityContainerInfo)5 SingularityRequest (com.hubspot.singularity.SingularityRequest)5 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)5 SingularityDockerInfo (com.hubspot.mesos.SingularityDockerInfo)4 SingularityDockerPortMapping (com.hubspot.mesos.SingularityDockerPortMapping)4 SingularityPortMapping (com.hubspot.mesos.SingularityPortMapping)3 SingularityVolume (com.hubspot.mesos.SingularityVolume)3 HashMap (java.util.HashMap)3 Protos (org.apache.mesos.v1.Protos)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ByteString (com.google.protobuf.ByteString)2 HealthcheckOptions (com.hubspot.deploy.HealthcheckOptions)2