Search in sources :

Example 6 with DefaultVolumeSpec

use of com.mesosphere.sdk.specification.DefaultVolumeSpec in project dcos-commons by mesosphere.

the class OfferEvaluatorVolumesTest method testRelaunchExecutorVolumeFailure.

@Test
public void testRelaunchExecutorVolumeFailure() throws Exception {
    // Create for the first time.
    List<Resource> offeredResources = Arrays.asList(ResourceTestUtils.getUnreservedMountVolume(2000), ResourceTestUtils.getUnreservedCpus(1.0));
    Protos.Offer offer = OfferTestUtils.getCompleteOffer(offeredResources);
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getExecutorRequirement(PodInstanceRequirementTestUtils.getCpuResourceSet(1.0), Arrays.asList(new DefaultVolumeSpec(1000, VolumeSpec.Type.MOUNT, TestConstants.CONTAINER_PATH, TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL)), TestConstants.POD_TYPE, 0);
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(offer));
    Assert.assertEquals(7, recommendations.size());
    // Validate RESERVE Operation
    Operation reserveOperation = recommendations.get(0).getOperation();
    Resource reserveResource = reserveOperation.getReserve().getResources(0);
    String resourceId = getResourceId(reserveResource);
    // Validate CREATE Operation
    Operation createOperation = recommendations.get(1).getOperation();
    Resource createResource = createOperation.getCreate().getVolumes(0);
    String persistenceId = createResource.getDisk().getPersistence().getId();
    // Evaluation for a second time
    offeredResources = Arrays.asList(ResourceTestUtils.getReservedMountVolume(2000, resourceId, persistenceId), ResourceTestUtils.getReservedCpus(1.0, resourceId));
    offer = OfferTestUtils.getCompleteOffer(offeredResources);
    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) DefaultVolumeSpec(com.mesosphere.sdk.specification.DefaultVolumeSpec) Operation(org.apache.mesos.Protos.Offer.Operation) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 7 with DefaultVolumeSpec

use of com.mesosphere.sdk.specification.DefaultVolumeSpec in project dcos-commons by mesosphere.

the class OfferEvaluatorVolumesTest method testReserveCreateExecutorVolume.

@Test
public void testReserveCreateExecutorVolume() throws Exception {
    List<Resource> offeredResources = Arrays.asList(ResourceTestUtils.getUnreservedMountVolume(2000), ResourceTestUtils.getUnreservedCpus(1.0));
    Protos.Offer offer = OfferTestUtils.getCompleteOffer(offeredResources);
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getExecutorRequirement(PodInstanceRequirementTestUtils.getCpuResourceSet(1.0), Arrays.asList(new DefaultVolumeSpec(1000, VolumeSpec.Type.MOUNT, TestConstants.CONTAINER_PATH, TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL)), TestConstants.POD_TYPE, 0);
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(offer));
    Assert.assertEquals(7, recommendations.size());
    // Validate just the operations pertaining to the executor
    // Validate RESERVE Operation
    Operation reserveOperation = recommendations.get(0).getOperation();
    Resource reserveResource = reserveOperation.getReserve().getResources(0);
    Assert.assertEquals(Operation.Type.RESERVE, reserveOperation.getType());
    Assert.assertEquals(2000, reserveResource.getScalar().getValue(), 0.0);
    OfferEvaluatorTest.validateRole(reserveResource);
    Assert.assertEquals(TestConstants.ROLE, ResourceUtils.getRole(reserveResource));
    Assert.assertEquals(TestConstants.MOUNT_ROOT, reserveResource.getDisk().getSource().getMount().getRoot());
    validatePrincipal(reserveResource);
    Assert.assertEquals(36, getResourceId(reserveResource).length());
    // Validate CREATE Operation
    String resourceId = getResourceId(reserveResource);
    Operation createOperation = recommendations.get(1).getOperation();
    Resource createResource = createOperation.getCreate().getVolumes(0);
    Assert.assertEquals(resourceId, getResourceId(createResource));
    Assert.assertEquals(36, createResource.getDisk().getPersistence().getId().length());
    Assert.assertEquals(TestConstants.MOUNT_ROOT, createResource.getDisk().getSource().getMount().getRoot());
    Assert.assertEquals(TestConstants.PRINCIPAL, createResource.getDisk().getPersistence().getPrincipal());
    Assert.assertTrue(createResource.getDisk().hasVolume());
}
Also used : Protos(org.apache.mesos.Protos) Resource(org.apache.mesos.Protos.Resource) DefaultVolumeSpec(com.mesosphere.sdk.specification.DefaultVolumeSpec) Operation(org.apache.mesos.Protos.Offer.Operation) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 8 with DefaultVolumeSpec

use of com.mesosphere.sdk.specification.DefaultVolumeSpec in project dcos-commons by mesosphere.

the class ResourceBuilderTest method testExistingFromMountVolumeSpec.

private static void testExistingFromMountVolumeSpec(Optional<String> namespace) {
    VolumeSpec volumeSpec = new DefaultVolumeSpec(10, VolumeSpec.Type.MOUNT, TestConstants.CONTAINER_PATH, TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL);
    Optional<String> resourceId = Optional.of(UUID.randomUUID().toString());
    Optional<String> persistenceId = Optional.of(UUID.randomUUID().toString());
    ResourceBuilder resourceBuilder = ResourceBuilder.fromSpec(volumeSpec, resourceId, namespace, persistenceId, Optional.of(TestConstants.MOUNT_SOURCE_ROOT));
    Protos.Resource resource = resourceBuilder.build();
    validateDisk(resource, resourceId, namespace);
    Protos.Resource.DiskInfo diskInfo = resource.getDisk();
    Assert.assertTrue(diskInfo.hasSource());
    Protos.Resource.DiskInfo.Source source = diskInfo.getSource();
    Assert.assertEquals("MOUNT", source.getType().toString());
    Assert.assertTrue(source.hasMount());
    Assert.assertEquals(TestConstants.MOUNT_SOURCE_ROOT, source.getMount().getRoot());
    Assert.assertEquals(persistenceId.get(), resource.getDisk().getPersistence().getId());
}
Also used : DefaultVolumeSpec(com.mesosphere.sdk.specification.DefaultVolumeSpec) VolumeSpec(com.mesosphere.sdk.specification.VolumeSpec) Protos(org.apache.mesos.Protos) DefaultVolumeSpec(com.mesosphere.sdk.specification.DefaultVolumeSpec)

Aggregations

DefaultVolumeSpec (com.mesosphere.sdk.specification.DefaultVolumeSpec)8 Protos (org.apache.mesos.Protos)8 VolumeSpec (com.mesosphere.sdk.specification.VolumeSpec)6 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)2 PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)2 Operation (org.apache.mesos.Protos.Offer.Operation)2 Resource (org.apache.mesos.Protos.Resource)2 Test (org.junit.Test)2