Search in sources :

Example 1 with ResourceRefinementCapabilityContext

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

the class OfferEvaluatorTest method testResourceRefinementFailsForDifferentPreReservation.

@SuppressWarnings("deprecated")
@Test
public void testResourceRefinementFailsForDifferentPreReservation() throws Exception {
    ResourceRefinementCapabilityContext context = new ResourceRefinementCapabilityContext(Capabilities.getInstance());
    try {
        ServiceSpec serviceSpec = getServiceSpec("resource-refinement.yml");
        Assert.assertEquals(TestConstants.PRE_RESERVED_ROLE, serviceSpec.getPods().get(0).getPreReservedRole());
        Offer badOffer = OfferTestUtils.getOffer(Arrays.asList(ResourceTestUtils.getUnreservedCpus(3.0).toBuilder().setRole(Constants.ANY_ROLE).addReservations(Resource.ReservationInfo.newBuilder().setRole("different-role").setType(Resource.ReservationInfo.Type.STATIC)).build()));
        PodSpec podSpec = serviceSpec.getPods().get(0);
        PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
        List<String> tasksToLaunch = Arrays.asList("test-task");
        PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, tasksToLaunch).build();
        List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(badOffer));
        Assert.assertEquals(0, recommendations.size());
    } finally {
        context.reset();
    }
}
Also used : ResourceRefinementCapabilityContext(com.mesosphere.sdk.dcos.ResourceRefinementCapabilityContext) Test(org.junit.Test)

Example 2 with ResourceRefinementCapabilityContext

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

the class OfferEvaluatorTest method testResourceRefinementSucceeds.

@SuppressWarnings("deprecated")
@Test
public void testResourceRefinementSucceeds() throws Exception {
    ResourceRefinementCapabilityContext context = new ResourceRefinementCapabilityContext(Capabilities.getInstance());
    try {
        ServiceSpec serviceSpec = getServiceSpec("resource-refinement.yml");
        Assert.assertEquals(TestConstants.PRE_RESERVED_ROLE, serviceSpec.getPods().get(0).getPreReservedRole());
        Offer sufficientOffer = OfferTestUtils.getCompleteOffer(Arrays.asList(// Include executor resources.
        ResourceTestUtils.getUnreservedCpus(0.1), ResourceTestUtils.getUnreservedMem(256), ResourceTestUtils.getUnreservedDisk(512), ResourceTestUtils.getUnreservedCpus(3.0)).stream().map(r -> r.toBuilder().setRole(Constants.ANY_ROLE).addReservations(Resource.ReservationInfo.newBuilder().setRole(TestConstants.PRE_RESERVED_ROLE).setType(Resource.ReservationInfo.Type.STATIC)).build()).collect(Collectors.toList()));
        PodSpec podSpec = serviceSpec.getPods().get(0);
        PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
        List<String> tasksToLaunch = Arrays.asList("test-task");
        PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, tasksToLaunch).build();
        List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(sufficientOffer));
        Assert.assertEquals(5, recommendations.size());
        Operation reserveOperation = recommendations.get(0).getOperation();
        Resource reserveResource = reserveOperation.getReserve().getResources(0);
        Assert.assertEquals(2, reserveResource.getReservationsCount());
        Resource.ReservationInfo preReservation = reserveResource.getReservations(0);
        Assert.assertEquals(Resource.ReservationInfo.Type.STATIC, preReservation.getType());
        Assert.assertEquals(TestConstants.PRE_RESERVED_ROLE, preReservation.getRole());
        Assert.assertFalse(preReservation.hasLabels());
        Resource.ReservationInfo dynamicReservation = reserveResource.getReservations(1);
        Assert.assertEquals(Resource.ReservationInfo.Type.DYNAMIC, dynamicReservation.getType());
        Assert.assertEquals(TestConstants.PRE_RESERVED_ROLE + "/hello-world-role", dynamicReservation.getRole());
        Assert.assertTrue(dynamicReservation.hasLabels());
    } finally {
        context.reset();
    }
}
Also used : Operation(org.apache.mesos.Protos.Offer.Operation) ResourceRefinementCapabilityContext(com.mesosphere.sdk.dcos.ResourceRefinementCapabilityContext) Test(org.junit.Test)

Example 3 with ResourceRefinementCapabilityContext

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

the class ResourceBuilderTest method testNewFromRootVolumeSpec.

/*
        name: "disk"
        type: SCALAR
        scalar {
          value: 10.0
        }
        role: "*"
        disk {
          persistence {
            id: "57bbc7c5-aba7-4508-94a0-3ad714c5e295"
            principal: "test-principal"
          }
          volume {
            container_path: "test-container-path"
            mode: RW
          }
        }
        reservations {
          principal: "test-principal"
          labels {
            labels {
              key: "resource_id"
              value: "0457e8d3-a892-48ed-b845-d38488876592"
            }
          }
          role: "test-role"
        }
    */
@Test
public void testNewFromRootVolumeSpec() {
    testNewFromRootVolumeSpec(Optional.empty());
    testNewFromRootVolumeSpec(Optional.of("foo"));
    ResourceRefinementCapabilityContext context = new ResourceRefinementCapabilityContext(Capabilities.getInstance());
    try {
        testNewFromRootVolumeSpec(Optional.empty());
        testNewFromRootVolumeSpec(Optional.of("foo"));
    } finally {
        context.reset();
    }
}
Also used : ResourceRefinementCapabilityContext(com.mesosphere.sdk.dcos.ResourceRefinementCapabilityContext) Test(org.junit.Test)

Example 4 with ResourceRefinementCapabilityContext

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

the class ResourceBuilderTest method testFromExistingMountVolume.

@Test
public void testFromExistingMountVolume() {
    testFromExistingMountVolume(Optional.empty());
    testFromExistingMountVolume(Optional.of("namespace/path"));
    ResourceRefinementCapabilityContext context = new ResourceRefinementCapabilityContext(Capabilities.getInstance());
    try {
        testFromExistingMountVolume(Optional.empty());
        testFromExistingMountVolume(Optional.of("namespace/path"));
    } finally {
        context.reset();
    }
}
Also used : ResourceRefinementCapabilityContext(com.mesosphere.sdk.dcos.ResourceRefinementCapabilityContext) Test(org.junit.Test)

Example 5 with ResourceRefinementCapabilityContext

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

the class ResourceBuilderTest method testRefineStaticResource.

/*
        name: "cpus"
        type: SCALAR
        scalar {
          value: 1.0
        }
        reservations {
          role: "base-role"
          type: STATIC
        }
        reservations {
          principal: "test-principal"
          labels {
            labels {
              key: "resource_id"
              value: "a395f14b-3cc8-4009-9dc4-51838b423aed"
            }
          }
          role: "test-role"
          type: DYNAMIC
        }
    */
private static void testRefineStaticResource(Optional<String> namespace) {
    ResourceRefinementCapabilityContext context = new ResourceRefinementCapabilityContext(Capabilities.getInstance());
    try {
        ResourceSpec resourceSpec = new DefaultResourceSpec("cpus", VALUE, TestConstants.ROLE, TestConstants.PRE_RESERVED_ROLE, TestConstants.PRINCIPAL);
        ResourceBuilder resourceBuilder = ResourceBuilder.fromSpec(resourceSpec, Optional.empty(), namespace);
        Protos.Resource resource = resourceBuilder.build();
        Assert.assertEquals(2, resource.getReservationsCount());
        validateScalarResourceRefined(resource, Optional.empty(), namespace);
        Assert.assertEquals(Protos.Resource.ReservationInfo.Type.STATIC, resource.getReservations(0).getType());
        Assert.assertEquals(TestConstants.PRE_RESERVED_ROLE, resource.getReservations(0).getRole());
    } finally {
        context.reset();
    }
}
Also used : Protos(org.apache.mesos.Protos) DefaultResourceSpec(com.mesosphere.sdk.specification.DefaultResourceSpec) DefaultResourceSpec(com.mesosphere.sdk.specification.DefaultResourceSpec) ResourceSpec(com.mesosphere.sdk.specification.ResourceSpec) ResourceRefinementCapabilityContext(com.mesosphere.sdk.dcos.ResourceRefinementCapabilityContext)

Aggregations

ResourceRefinementCapabilityContext (com.mesosphere.sdk.dcos.ResourceRefinementCapabilityContext)14 Test (org.junit.Test)12 Capabilities (com.mesosphere.sdk.dcos.Capabilities)1 DefaultResourceSpec (com.mesosphere.sdk.specification.DefaultResourceSpec)1 ResourceSpec (com.mesosphere.sdk.specification.ResourceSpec)1 Protos (org.apache.mesos.Protos)1 Operation (org.apache.mesos.Protos.Offer.Operation)1 BeforeClass (org.junit.BeforeClass)1