Search in sources :

Example 1 with ReserveEvaluationOutcome

use of com.mesosphere.sdk.offer.evaluate.OfferEvaluationUtils.ReserveEvaluationOutcome 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 ReserveEvaluationOutcome

use of com.mesosphere.sdk.offer.evaluate.OfferEvaluationUtils.ReserveEvaluationOutcome 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 ReserveEvaluationOutcome

use of com.mesosphere.sdk.offer.evaluate.OfferEvaluationUtils.ReserveEvaluationOutcome in project dcos-commons by mesosphere.

the class OfferEvaluationUtilsTest method testResourceDecrease.

private void testResourceDecrease(Optional<String> namespace) {
    String resourceId = UUID.randomUUID().toString();
    Protos.Value current = getValue(5);
    Protos.Value desired = getValue(4);
    Protos.Value toSubtract = ValueUtils.subtract(current, desired);
    ResourceSpec resourceSpec = getResourceSpec(desired);
    when(mockPool.consumeReserved(RESOURCE_NAME, desired, resourceId)).thenReturn(Optional.of(getMesosResource(getResourceSpec(current), resourceId, namespace)));
    when(mockPool.consumeReservableMerged(RESOURCE_NAME, desired, Constants.ANY_ROLE)).thenReturn(Optional.of(getMesosResource(toSubtract)));
    ReserveEvaluationOutcome outcome = OfferEvaluationUtils.evaluateSimpleResource(mockStage, resourceSpec, Optional.of(resourceId), namespace, mockPool);
    Assert.assertTrue(outcome.getEvaluationOutcome().isPassing());
    OfferRecommendation recommendation = outcome.getEvaluationOutcome().getOfferRecommendations().get(0);
    Assert.assertTrue(recommendation instanceof UnreserveOfferRecommendation);
    Assert.assertTrue(outcome.getResourceId().isPresent());
    Protos.Resource resource = recommendation.getOperation().getUnreserve().getResources(0);
    Assert.assertEquals(toSubtract.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) UnreserveOfferRecommendation(com.mesosphere.sdk.offer.UnreserveOfferRecommendation) ReserveEvaluationOutcome(com.mesosphere.sdk.offer.evaluate.OfferEvaluationUtils.ReserveEvaluationOutcome) UnreserveOfferRecommendation(com.mesosphere.sdk.offer.UnreserveOfferRecommendation) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) ReserveOfferRecommendation(com.mesosphere.sdk.offer.ReserveOfferRecommendation)

Example 4 with ReserveEvaluationOutcome

use of com.mesosphere.sdk.offer.evaluate.OfferEvaluationUtils.ReserveEvaluationOutcome in project dcos-commons by mesosphere.

the class OfferEvaluationUtilsTest method testResourceInsufficient.

private void testResourceInsufficient(Optional<String> resourceId, Optional<String> namespace) {
    Protos.Value desired = getValue(5);
    if (resourceId.isPresent()) {
        when(mockPool.consumeReserved(RESOURCE_NAME, desired, resourceId.get())).thenReturn(Optional.empty());
    } else {
        when(mockPool.consumeReservableMerged(RESOURCE_NAME, desired, Constants.ANY_ROLE)).thenReturn(Optional.empty());
    }
    ReserveEvaluationOutcome outcome = OfferEvaluationUtils.evaluateSimpleResource(mockStage, getResourceSpec(desired), 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) ReserveEvaluationOutcome(com.mesosphere.sdk.offer.evaluate.OfferEvaluationUtils.ReserveEvaluationOutcome)

Example 5 with ReserveEvaluationOutcome

use of com.mesosphere.sdk.offer.evaluate.OfferEvaluationUtils.ReserveEvaluationOutcome in project dcos-commons by mesosphere.

the class OfferEvaluationUtilsTest method testResourceIncreaseSufficient.

private void testResourceIncreaseSufficient(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.of(getMesosResource(toAdd)));
    ReserveEvaluationOutcome outcome = OfferEvaluationUtils.evaluateSimpleResource(mockStage, resourceSpec, Optional.of(resourceId), namespace, mockPool);
    Assert.assertTrue(outcome.getEvaluationOutcome().isPassing());
    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(toAdd.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)

Aggregations

ReserveEvaluationOutcome (com.mesosphere.sdk.offer.evaluate.OfferEvaluationUtils.ReserveEvaluationOutcome)5 Protos (org.apache.mesos.Protos)5 DefaultResourceSpec (com.mesosphere.sdk.specification.DefaultResourceSpec)4 ResourceSpec (com.mesosphere.sdk.specification.ResourceSpec)4 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)3 ReserveOfferRecommendation (com.mesosphere.sdk.offer.ReserveOfferRecommendation)3 UnreserveOfferRecommendation (com.mesosphere.sdk.offer.UnreserveOfferRecommendation)3