Search in sources :

Example 1 with UnreserveOfferRecommendation

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

the class DecommissionRecorderTest method testUnreserveNotFound.

@Test
public void testUnreserveNotFound() throws Exception {
    when(mockStateStore.fetchGoalOverrideStatus(TestConstants.TASK_NAME)).thenReturn(DecommissionPlanFactory.DECOMMISSIONING_STATUS);
    recorder.record(new UnreserveOfferRecommendation(null, otherResource));
    verify(mockStateStore, times(0)).storeTasks(any());
}
Also used : UnreserveOfferRecommendation(com.mesosphere.sdk.offer.UnreserveOfferRecommendation) Test(org.junit.Test)

Example 2 with UnreserveOfferRecommendation

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

the class ResourceCleanupStepTest method testMatchingUpdateOfferStatus.

@Test
public void testMatchingUpdateOfferStatus() throws Exception {
    OfferRecommendation offerRecommendation = new UnreserveOfferRecommendation(null, ResourceTestUtils.getReservedCpus(1.0, TestConstants.RESOURCE_ID));
    resourceCleanupStep.start();
    resourceCleanupStep.updateOfferStatus(Collections.singletonList(offerRecommendation));
    assert resourceCleanupStep.getStatus().equals(Status.COMPLETE);
}
Also used : UnreserveOfferRecommendation(com.mesosphere.sdk.offer.UnreserveOfferRecommendation) UnreserveOfferRecommendation(com.mesosphere.sdk.offer.UnreserveOfferRecommendation) CreateOfferRecommendation(com.mesosphere.sdk.offer.CreateOfferRecommendation) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 3 with UnreserveOfferRecommendation

use of com.mesosphere.sdk.offer.UnreserveOfferRecommendation 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 UnreserveOfferRecommendation

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

the class ResourceCleanupStepTest method testNonMatchingUpdateOfferStatus.

@Test
public void testNonMatchingUpdateOfferStatus() throws Exception {
    OfferRecommendation offerRecommendation = new UnreserveOfferRecommendation(null, ResourceTestUtils.getReservedCpus(1.0, DIFFERENT_RESOURCE_ID));
    resourceCleanupStep.start();
    resourceCleanupStep.updateOfferStatus(Collections.singletonList(offerRecommendation));
    assert resourceCleanupStep.getStatus().equals(Status.PREPARED);
}
Also used : UnreserveOfferRecommendation(com.mesosphere.sdk.offer.UnreserveOfferRecommendation) UnreserveOfferRecommendation(com.mesosphere.sdk.offer.UnreserveOfferRecommendation) CreateOfferRecommendation(com.mesosphere.sdk.offer.CreateOfferRecommendation) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 5 with UnreserveOfferRecommendation

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

the class ResourceCleanupStepTest method testMixedUpdateOfferStatus.

@Test
public void testMixedUpdateOfferStatus() throws Exception {
    OfferRecommendation rec1 = new CreateOfferRecommendation(null, ResourceTestUtils.getReservedRootVolume(999.0));
    OfferRecommendation rec2 = new UnreserveOfferRecommendation(null, ResourceTestUtils.getReservedCpus(1.0, TestConstants.RESOURCE_ID));
    resourceCleanupStep.start();
    resourceCleanupStep.updateOfferStatus(Arrays.asList(rec1, rec2));
    assert resourceCleanupStep.getStatus().equals(Status.COMPLETE);
}
Also used : UnreserveOfferRecommendation(com.mesosphere.sdk.offer.UnreserveOfferRecommendation) UnreserveOfferRecommendation(com.mesosphere.sdk.offer.UnreserveOfferRecommendation) CreateOfferRecommendation(com.mesosphere.sdk.offer.CreateOfferRecommendation) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) CreateOfferRecommendation(com.mesosphere.sdk.offer.CreateOfferRecommendation) Test(org.junit.Test)

Aggregations

UnreserveOfferRecommendation (com.mesosphere.sdk.offer.UnreserveOfferRecommendation)7 Test (org.junit.Test)6 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)4 CreateOfferRecommendation (com.mesosphere.sdk.offer.CreateOfferRecommendation)3 ReserveOfferRecommendation (com.mesosphere.sdk.offer.ReserveOfferRecommendation)1 ReserveEvaluationOutcome (com.mesosphere.sdk.offer.evaluate.OfferEvaluationUtils.ReserveEvaluationOutcome)1 DefaultResourceSpec (com.mesosphere.sdk.specification.DefaultResourceSpec)1 ResourceSpec (com.mesosphere.sdk.specification.ResourceSpec)1 Protos (org.apache.mesos.Protos)1