Search in sources :

Example 16 with OfferRecommendation

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

the class OfferEvaluatorVolumesTest method testCreateMultipleRootVolumes.

@Test
public void testCreateMultipleRootVolumes() throws Exception {
    ResourceSet resourceSet = DefaultResourceSet.newBuilder(TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL).id(TestConstants.RESOURCE_SET_ID).cpus(1.0).addVolume(VolumeSpec.Type.ROOT.name(), 1.0, TestConstants.CONTAINER_PATH + "-a").addVolume(VolumeSpec.Type.ROOT.name(), 2.0, TestConstants.CONTAINER_PATH + "-b").build();
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getRequirement(resourceSet, 0);
    Resource offeredDisk = ResourceTestUtils.getUnreservedDisk(3);
    Resource offeredCpu = ResourceTestUtils.getUnreservedCpus(1.0);
    Protos.Offer offer = OfferTestUtils.getCompleteOffer(Arrays.asList(offeredCpu, offeredDisk));
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(offer));
    Assert.assertEquals(9, recommendations.size());
    Assert.assertEquals(Operation.Type.RESERVE, recommendations.get(0).getOperation().getType());
    Assert.assertEquals(Operation.Type.RESERVE, recommendations.get(1).getOperation().getType());
    Assert.assertEquals(Operation.Type.CREATE, recommendations.get(2).getOperation().getType());
    Assert.assertEquals(Operation.Type.RESERVE, recommendations.get(3).getOperation().getType());
    Assert.assertEquals(Operation.Type.CREATE, recommendations.get(4).getOperation().getType());
    Assert.assertEquals(Operation.Type.LAUNCH_GROUP, recommendations.get(8).getOperation().getType());
    // Validate Create Operation
    Operation createOperation = recommendations.get(2).getOperation();
    Assert.assertEquals(TestConstants.CONTAINER_PATH + "-a", createOperation.getCreate().getVolumes(0).getDisk().getVolume().getContainerPath());
    // Validate Create Operation
    createOperation = recommendations.get(4).getOperation();
    Assert.assertEquals(TestConstants.CONTAINER_PATH + "-b", createOperation.getCreate().getVolumes(0).getDisk().getVolume().getContainerPath());
    // Validate Launch Operation
    Operation launchOperation = recommendations.get(8).getOperation();
    for (Protos.TaskInfo taskInfo : launchOperation.getLaunch().getTaskInfosList()) {
        for (Resource resource : taskInfo.getResourcesList()) {
            Assert.assertFalse(getResourceId(resource).isEmpty());
        }
    }
}
Also used : Protos(org.apache.mesos.Protos) Resource(org.apache.mesos.Protos.Resource) ResourceSet(com.mesosphere.sdk.specification.ResourceSet) DefaultResourceSet(com.mesosphere.sdk.specification.DefaultResourceSet) 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 17 with OfferRecommendation

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

the class OfferEvaluatorVolumesTest method testFailCreateRootVolume.

@Test
public void testFailCreateRootVolume() throws Exception {
    Resource offeredResource = ResourceTestUtils.getUnreservedDisk(1000);
    List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getRootVolumeRequirement(1.0, 1500), Arrays.asList(OfferTestUtils.getCompleteOffer(offeredResource)));
    Assert.assertEquals(0, recommendations.size());
}
Also used : Resource(org.apache.mesos.Protos.Resource) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 18 with OfferRecommendation

use of com.mesosphere.sdk.offer.OfferRecommendation 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 19 with OfferRecommendation

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

the class OfferEvaluatorPlacementTest method testAvoidAgentsCustomExecutor.

@Test
public void testAvoidAgentsCustomExecutor() throws Exception {
    useCustomExecutor();
    Protos.Resource offeredCpu = ResourceTestUtils.getUnreservedCpus(2.0);
    // Don't launch
    PlacementRule placementRule = PlacementUtils.getAgentPlacementRule(Arrays.asList(TestConstants.AGENT_ID.getValue()), Collections.emptyList()).get();
    PodSpec podSpec = PodInstanceRequirementTestUtils.getCpuRequirement(1.0).getPodInstance().getPod();
    podSpec = DefaultPodSpec.newBuilder(podSpec).placementRule(placementRule).build();
    PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, Arrays.asList(TestConstants.TASK_NAME)).build();
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getOffer(offeredCpu)));
    Assert.assertEquals(0, recommendations.size());
    // Launch
    placementRule = PlacementUtils.getAgentPlacementRule(Arrays.asList("some-random-agent"), Collections.emptyList()).get();
    podSpec = DefaultPodSpec.newBuilder(podSpec).placementRule(placementRule).build();
    podInstance = new DefaultPodInstance(podSpec, 0);
    podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, Arrays.asList(TestConstants.TASK_NAME)).build();
    recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getCompleteOffer(offeredCpu)));
    Assert.assertEquals(2, recommendations.size());
}
Also used : Protos(org.apache.mesos.Protos) DefaultPodSpec(com.mesosphere.sdk.specification.DefaultPodSpec) PodSpec(com.mesosphere.sdk.specification.PodSpec) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) PodInstance(com.mesosphere.sdk.specification.PodInstance) PlacementRule(com.mesosphere.sdk.offer.evaluate.placement.PlacementRule) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 20 with OfferRecommendation

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

the class OfferEvaluatorPlacementTest method testColocateAgentsCustomExecutor.

@Test
public void testColocateAgentsCustomExecutor() throws Exception {
    useCustomExecutor();
    Protos.Resource offeredCpu = ResourceTestUtils.getUnreservedCpus(2.0);
    // Don't launch
    PlacementRule placementRule = PlacementUtils.getAgentPlacementRule(Collections.emptyList(), Arrays.asList("some-random-agent")).get();
    PodSpec podSpec = PodInstanceRequirementTestUtils.getCpuRequirement(1.0).getPodInstance().getPod();
    podSpec = DefaultPodSpec.newBuilder(podSpec).placementRule(placementRule).build();
    PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, Arrays.asList(TestConstants.TASK_NAME)).build();
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getOffer(offeredCpu)));
    Assert.assertEquals(0, recommendations.size());
    // Launch
    placementRule = PlacementUtils.getAgentPlacementRule(Collections.emptyList(), Arrays.asList(TestConstants.AGENT_ID.getValue())).get();
    podSpec = DefaultPodSpec.newBuilder(podSpec).placementRule(placementRule).build();
    podInstance = new DefaultPodInstance(podSpec, 0);
    podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, Arrays.asList(TestConstants.TASK_NAME)).build();
    recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getCompleteOffer(offeredCpu)));
    Assert.assertEquals(2, recommendations.size());
}
Also used : Protos(org.apache.mesos.Protos) DefaultPodSpec(com.mesosphere.sdk.specification.DefaultPodSpec) PodSpec(com.mesosphere.sdk.specification.PodSpec) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) PodInstance(com.mesosphere.sdk.specification.PodInstance) PlacementRule(com.mesosphere.sdk.offer.evaluate.placement.PlacementRule) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Aggregations

OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)42 Test (org.junit.Test)39 Resource (org.apache.mesos.Protos.Resource)30 Operation (org.apache.mesos.Protos.Offer.Operation)26 PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)21 Protos (org.apache.mesos.Protos)21 TaskInfo (org.apache.mesos.Protos.TaskInfo)13 UnreserveOfferRecommendation (com.mesosphere.sdk.offer.UnreserveOfferRecommendation)6 CreateOfferRecommendation (com.mesosphere.sdk.offer.CreateOfferRecommendation)4 PlacementRule (com.mesosphere.sdk.offer.evaluate.placement.PlacementRule)4 DefaultPodInstance (com.mesosphere.sdk.scheduler.plan.DefaultPodInstance)4 DefaultPodSpec (com.mesosphere.sdk.specification.DefaultPodSpec)4 DefaultResourceSet (com.mesosphere.sdk.specification.DefaultResourceSet)4 DefaultVolumeSpec (com.mesosphere.sdk.specification.DefaultVolumeSpec)4 PodInstance (com.mesosphere.sdk.specification.PodInstance)4 PodSpec (com.mesosphere.sdk.specification.PodSpec)4 ResourceSet (com.mesosphere.sdk.specification.ResourceSet)4 ReserveOfferRecommendation (com.mesosphere.sdk.offer.ReserveOfferRecommendation)3 ReserveEvaluationOutcome (com.mesosphere.sdk.offer.evaluate.OfferEvaluationUtils.ReserveEvaluationOutcome)3 DefaultResourceSpec (com.mesosphere.sdk.specification.DefaultResourceSpec)3