Search in sources :

Example 11 with Resource

use of org.apache.mesos.Protos.Resource in project dcos-commons by mesosphere.

the class MesosResourcePoolTest method testMultipleUnreservedAtomicPool.

@Test
public void testMultipleUnreservedAtomicPool() {
    Resource resource = ResourceTestUtils.getUnreservedMountVolume(1000);
    Offer offer = OfferTestUtils.getOffer(Arrays.asList(resource, resource));
    MesosResourcePool pool = new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE));
    Assert.assertEquals(1, pool.getUnreservedAtomicPool().size());
    Assert.assertEquals(2, pool.getUnreservedAtomicPool().get("disk").size());
}
Also used : Offer(org.apache.mesos.Protos.Offer) Resource(org.apache.mesos.Protos.Resource) Test(org.junit.Test)

Example 12 with Resource

use of org.apache.mesos.Protos.Resource in project dcos-commons by mesosphere.

the class MesosResourcePoolTest method testConsumeInsufficientUnreservedMergedResource.

@Test
public void testConsumeInsufficientUnreservedMergedResource() {
    Resource desiredUnreservedResource = ResourceTestUtils.getUnreservedCpus(2.0);
    Protos.Value resourceValue = ValueUtils.getValue(desiredUnreservedResource);
    Resource offeredUnreservedResource = ResourceTestUtils.getUnreservedCpus(1.0);
    Offer offer = OfferTestUtils.getOffer(offeredUnreservedResource);
    MesosResourcePool pool = new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE));
    Assert.assertFalse(pool.consumeReservableMerged(desiredUnreservedResource.getName(), resourceValue, Constants.ANY_ROLE).isPresent());
}
Also used : Protos(org.apache.mesos.Protos) Offer(org.apache.mesos.Protos.Offer) Resource(org.apache.mesos.Protos.Resource) Test(org.junit.Test)

Example 13 with Resource

use of org.apache.mesos.Protos.Resource in project dcos-commons by mesosphere.

the class OfferEvaluatorVolumesTest method testReserveCreateLaunchRootVolume.

@Test
public void testReserveCreateLaunchRootVolume() throws Exception {
    Resource offeredCpuResource = ResourceTestUtils.getUnreservedCpus(1.0);
    Resource offeredDiskResource = ResourceTestUtils.getUnreservedDisk(2000);
    List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getRootVolumeRequirement(1.0, 1500), Arrays.asList(OfferTestUtils.getCompleteOffer(Arrays.asList(offeredDiskResource, offeredCpuResource))));
    // RESERVE, RESERVE, CREATE, RESERVE, RESERVE, RESERVE, LAUNCH
    Assert.assertEquals(7, recommendations.size());
    // Validate CPU RESERVE Operation
    Operation reserveOperation = recommendations.get(0).getOperation();
    Resource reserveResource = reserveOperation.getReserve().getResources(0);
    Resource.ReservationInfo reservation = ResourceUtils.getReservation(reserveResource).get();
    Assert.assertEquals(Operation.Type.RESERVE, reserveOperation.getType());
    Assert.assertEquals(1.0, reserveResource.getScalar().getValue(), 0.0);
    OfferEvaluatorTest.validateRole(reserveResource);
    Assert.assertEquals(TestConstants.ROLE, ResourceUtils.getRole(reserveResource));
    Assert.assertEquals(TestConstants.PRINCIPAL, reservation.getPrincipal());
    Assert.assertEquals(36, getResourceId(reserveResource).length());
    Assert.assertFalse(reserveResource.hasDisk());
    // Validate DISK RESERVE Operation
    reserveOperation = recommendations.get(1).getOperation();
    reserveResource = reserveOperation.getReserve().getResources(0);
    reservation = ResourceUtils.getReservation(reserveResource).get();
    Assert.assertEquals(Operation.Type.RESERVE, reserveOperation.getType());
    Assert.assertEquals(1500, reserveResource.getScalar().getValue(), 0.0);
    OfferEvaluatorTest.validateRole(reserveResource);
    Assert.assertEquals(TestConstants.ROLE, ResourceUtils.getRole(reserveResource));
    Assert.assertEquals(TestConstants.PRINCIPAL, reservation.getPrincipal());
    Assert.assertEquals(36, getResourceId(reserveResource).length());
    Assert.assertFalse(reserveResource.hasDisk());
    // Validate CREATE Operation
    String resourceId = getResourceId(reserveResource);
    Operation createOperation = recommendations.get(2).getOperation();
    Resource createResource = createOperation.getCreate().getVolumes(0);
    Assert.assertEquals(resourceId, getResourceId(createResource));
    Assert.assertEquals(36, createResource.getDisk().getPersistence().getId().length());
    Assert.assertEquals(TestConstants.PRINCIPAL, createResource.getDisk().getPersistence().getPrincipal());
    Assert.assertTrue(createResource.getDisk().hasVolume());
    // Validate LAUNCH Operation
    String persistenceId = createResource.getDisk().getPersistence().getId();
    Operation launchOperation = recommendations.get(6).getOperation();
    Resource launchResource = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0).getResources(1);
    Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType());
    Assert.assertEquals(resourceId, getResourceId(launchResource));
    Assert.assertEquals(persistenceId, launchResource.getDisk().getPersistence().getId());
    Assert.assertEquals(TestConstants.PRINCIPAL, launchResource.getDisk().getPersistence().getPrincipal());
}
Also used : Resource(org.apache.mesos.Protos.Resource) Operation(org.apache.mesos.Protos.Offer.Operation) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 14 with Resource

use of org.apache.mesos.Protos.Resource in project dcos-commons by mesosphere.

the class OfferEvaluatorVolumesTest method testConsumeMultipleMountVolumesFailure.

@Test
public void testConsumeMultipleMountVolumesFailure() throws Exception {
    Resource offeredResource = ResourceTestUtils.getUnreservedMountVolume(2000);
    ResourceSet volumeResourceSet = DefaultResourceSet.newBuilder(TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL).id(TestConstants.RESOURCE_SET_ID).cpus(1.0).addVolume(VolumeSpec.Type.MOUNT.name(), 1000.0, TestConstants.CONTAINER_PATH + "-A").addVolume(VolumeSpec.Type.MOUNT.name(), 1000.0, TestConstants.CONTAINER_PATH + "-B").build();
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getRequirement(volumeResourceSet, 0);
    Protos.Offer offer = OfferTestUtils.getCompleteOffer(Arrays.asList(offeredResource));
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(offer));
    Assert.assertEquals(0, recommendations.size());
}
Also used : Protos(org.apache.mesos.Protos) Resource(org.apache.mesos.Protos.Resource) ResourceSet(com.mesosphere.sdk.specification.ResourceSet) DefaultResourceSet(com.mesosphere.sdk.specification.DefaultResourceSet) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 15 with Resource

use of org.apache.mesos.Protos.Resource in project dcos-commons by mesosphere.

the class OfferEvaluatorVolumesTest method testCreateMultipleRootVolumes.

@Test
public void testCreateMultipleRootVolumes() throws Exception {
    ResourceSet resourceSet = DefaultResourceSet.newBuilder(TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL).id(TestConstants.RESOURCE_SET_ID).cpus(1.0).addVolume(VolumeSpec.Type.ROOT.name(), 1.0, TestConstants.CONTAINER_PATH + "-a").addVolume(VolumeSpec.Type.ROOT.name(), 2.0, TestConstants.CONTAINER_PATH + "-b").build();
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getRequirement(resourceSet, 0);
    Resource offeredDisk = ResourceTestUtils.getUnreservedDisk(3);
    Resource offeredCpu = ResourceTestUtils.getUnreservedCpus(1.0);
    Protos.Offer offer = OfferTestUtils.getCompleteOffer(Arrays.asList(offeredCpu, offeredDisk));
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(offer));
    Assert.assertEquals(9, recommendations.size());
    Assert.assertEquals(Operation.Type.RESERVE, recommendations.get(0).getOperation().getType());
    Assert.assertEquals(Operation.Type.RESERVE, recommendations.get(1).getOperation().getType());
    Assert.assertEquals(Operation.Type.CREATE, recommendations.get(2).getOperation().getType());
    Assert.assertEquals(Operation.Type.RESERVE, recommendations.get(3).getOperation().getType());
    Assert.assertEquals(Operation.Type.CREATE, recommendations.get(4).getOperation().getType());
    Assert.assertEquals(Operation.Type.LAUNCH_GROUP, recommendations.get(8).getOperation().getType());
    // Validate Create Operation
    Operation createOperation = recommendations.get(2).getOperation();
    Assert.assertEquals(TestConstants.CONTAINER_PATH + "-a", createOperation.getCreate().getVolumes(0).getDisk().getVolume().getContainerPath());
    // Validate Create Operation
    createOperation = recommendations.get(4).getOperation();
    Assert.assertEquals(TestConstants.CONTAINER_PATH + "-b", createOperation.getCreate().getVolumes(0).getDisk().getVolume().getContainerPath());
    // Validate Launch Operation
    Operation launchOperation = recommendations.get(8).getOperation();
    for (Protos.TaskInfo taskInfo : launchOperation.getLaunch().getTaskInfosList()) {
        for (Resource resource : taskInfo.getResourcesList()) {
            Assert.assertFalse(getResourceId(resource).isEmpty());
        }
    }
}
Also used : Protos(org.apache.mesos.Protos) Resource(org.apache.mesos.Protos.Resource) ResourceSet(com.mesosphere.sdk.specification.ResourceSet) DefaultResourceSet(com.mesosphere.sdk.specification.DefaultResourceSet) Operation(org.apache.mesos.Protos.Offer.Operation) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Aggregations

Resource (org.apache.mesos.Protos.Resource)40 Test (org.junit.Test)35 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)26 Operation (org.apache.mesos.Protos.Offer.Operation)25 PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)13 Protos (org.apache.mesos.Protos)13 TaskInfo (org.apache.mesos.Protos.TaskInfo)12 Offer (org.apache.mesos.Protos.Offer)9 DefaultResourceSet (com.mesosphere.sdk.specification.DefaultResourceSet)4 DefaultVolumeSpec (com.mesosphere.sdk.specification.DefaultVolumeSpec)4 ResourceSet (com.mesosphere.sdk.specification.ResourceSet)4 DiscoveryInfo (org.apache.mesos.Protos.DiscoveryInfo)4 Label (org.apache.mesos.Protos.Label)4 Port (org.apache.mesos.Protos.Port)4 ResourceUtils (com.mesosphere.sdk.offer.ResourceUtils)3 PodInstanceRequirementTestUtils (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirementTestUtils)3 OfferTestUtils (com.mesosphere.sdk.testutils.OfferTestUtils)3 ResourceTestUtils (com.mesosphere.sdk.testutils.ResourceTestUtils)3 TestConstants (com.mesosphere.sdk.testutils.TestConstants)3 Arrays (java.util.Arrays)3