Search in sources :

Example 1 with ResourceSpec

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

the class OfferEvaluationUtilsTest method testResourceIncreaseInsufficient.

private void testResourceIncreaseInsufficient(Optional<String> namespace) {
    String resourceId = UUID.randomUUID().toString();
    Protos.Value current = getValue(4);
    Protos.Value desired = getValue(5);
    Protos.Value toAdd = ValueUtils.subtract(desired, current);
    ResourceSpec resourceSpec = getResourceSpec(desired);
    when(mockPool.consumeReserved(RESOURCE_NAME, desired, resourceId)).thenReturn(Optional.of(getMesosResource(getResourceSpec(current), resourceId, namespace)));
    when(mockPool.consumeReservableMerged(RESOURCE_NAME, toAdd, Constants.ANY_ROLE)).thenReturn(Optional.empty());
    ReserveEvaluationOutcome outcome = OfferEvaluationUtils.evaluateSimpleResource(mockStage, resourceSpec, Optional.of(resourceId), namespace, mockPool);
    Assert.assertFalse(outcome.getEvaluationOutcome().isPassing());
    Assert.assertTrue(outcome.getEvaluationOutcome().getOfferRecommendations().isEmpty());
    Assert.assertFalse(outcome.getResourceId().isPresent());
}
Also used : Protos(org.apache.mesos.Protos) DefaultResourceSpec(com.mesosphere.sdk.specification.DefaultResourceSpec) ResourceSpec(com.mesosphere.sdk.specification.ResourceSpec) ReserveEvaluationOutcome(com.mesosphere.sdk.offer.evaluate.OfferEvaluationUtils.ReserveEvaluationOutcome)

Example 2 with ResourceSpec

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

the class OfferEvaluationUtilsTest method testResourceSufficient.

private void testResourceSufficient(Optional<String> resourceId, Optional<String> namespace) {
    Protos.Value desired = getValue(5);
    ResourceSpec resourceSpec = getResourceSpec(desired);
    if (resourceId.isPresent()) {
        when(mockPool.consumeReserved(RESOURCE_NAME, desired, resourceId.get())).thenReturn(Optional.of(getMesosResource(resourceSpec, resourceId.get(), namespace)));
    } else {
        when(mockPool.consumeReservableMerged(RESOURCE_NAME, desired, Constants.ANY_ROLE)).thenReturn(Optional.of(getMesosResource(desired)));
    }
    ReserveEvaluationOutcome outcome = OfferEvaluationUtils.evaluateSimpleResource(mockStage, resourceSpec, resourceId, namespace, mockPool);
    Assert.assertTrue(outcome.getEvaluationOutcome().isPassing());
    if (resourceId.isPresent()) {
        Assert.assertTrue(outcome.getEvaluationOutcome().getOfferRecommendations().isEmpty());
        Assert.assertEquals(resourceId.get(), outcome.getResourceId().get());
    } else {
        OfferRecommendation recommendation = outcome.getEvaluationOutcome().getOfferRecommendations().get(0);
        Assert.assertTrue(recommendation instanceof ReserveOfferRecommendation);
        Assert.assertTrue(outcome.getResourceId().isPresent());
        Protos.Resource resource = recommendation.getOperation().getReserve().getResources(0);
        Assert.assertEquals(desired.getScalar(), resource.getScalar());
        if (namespace.isPresent()) {
            Assert.assertEquals(namespace.get(), ResourceUtils.getNamespace(resource).get());
        } else {
            Assert.assertFalse(ResourceUtils.getNamespace(resource).isPresent());
        }
    }
}
Also used : Protos(org.apache.mesos.Protos) DefaultResourceSpec(com.mesosphere.sdk.specification.DefaultResourceSpec) ResourceSpec(com.mesosphere.sdk.specification.ResourceSpec) ReserveEvaluationOutcome(com.mesosphere.sdk.offer.evaluate.OfferEvaluationUtils.ReserveEvaluationOutcome) ReserveOfferRecommendation(com.mesosphere.sdk.offer.ReserveOfferRecommendation) UnreserveOfferRecommendation(com.mesosphere.sdk.offer.UnreserveOfferRecommendation) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) ReserveOfferRecommendation(com.mesosphere.sdk.offer.ReserveOfferRecommendation)

Example 3 with ResourceSpec

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

the class ResourceBuilderTest method testExistingFromResourceSpec.

private static void testExistingFromResourceSpec(Optional<String> namespace) {
    Optional<String> resourceId = Optional.of(UUID.randomUUID().toString());
    ResourceSpec resourceSpec = new DefaultResourceSpec("cpus", VALUE, TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL);
    validateScalarResource(ResourceBuilder.fromSpec(resourceSpec, resourceId, namespace).build(), resourceId, namespace);
}
Also used : DefaultResourceSpec(com.mesosphere.sdk.specification.DefaultResourceSpec) DefaultResourceSpec(com.mesosphere.sdk.specification.DefaultResourceSpec) ResourceSpec(com.mesosphere.sdk.specification.ResourceSpec)

Example 4 with ResourceSpec

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

the class ResourceBuilderTest method testNewFromResourceSpec.

private static void testNewFromResourceSpec(Optional<String> namespace) {
    ResourceSpec resourceSpec = new DefaultResourceSpec("cpus", VALUE, TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL);
    ResourceBuilder resourceBuilder = ResourceBuilder.fromSpec(resourceSpec, Optional.empty(), namespace);
    Protos.Resource resource = resourceBuilder.build();
    validateScalarResource(resource, Optional.empty(), namespace);
}
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)

Example 5 with ResourceSpec

use of com.mesosphere.sdk.specification.ResourceSpec 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

ResourceSpec (com.mesosphere.sdk.specification.ResourceSpec)13 Protos (org.apache.mesos.Protos)10 DefaultResourceSpec (com.mesosphere.sdk.specification.DefaultResourceSpec)8 ReserveEvaluationOutcome (com.mesosphere.sdk.offer.evaluate.OfferEvaluationUtils.ReserveEvaluationOutcome)4 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)3 ReserveOfferRecommendation (com.mesosphere.sdk.offer.ReserveOfferRecommendation)3 UnreserveOfferRecommendation (com.mesosphere.sdk.offer.UnreserveOfferRecommendation)3 VolumeSpec (com.mesosphere.sdk.specification.VolumeSpec)3 TaskSpec (com.mesosphere.sdk.specification.TaskSpec)2 Collectors (java.util.stream.Collectors)2 TextFormat (com.google.protobuf.TextFormat)1 DcosConstants (com.mesosphere.sdk.dcos.DcosConstants)1 ResourceRefinementCapabilityContext (com.mesosphere.sdk.dcos.ResourceRefinementCapabilityContext)1 com.mesosphere.sdk.offer (com.mesosphere.sdk.offer)1 Constants (com.mesosphere.sdk.offer.Constants)1 com.mesosphere.sdk.offer.taskdata (com.mesosphere.sdk.offer.taskdata)1 PodSpec (com.mesosphere.sdk.specification.PodSpec)1 PortSpec (com.mesosphere.sdk.specification.PortSpec)1 TestConstants (com.mesosphere.sdk.testutils.TestConstants)1 java.util (java.util)1