use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.
the class VolumeEvaluationStageTest method testCreateSucceeds.
@Test
public void testCreateSucceeds() throws Exception {
Protos.Resource offeredResource = ResourceTestUtils.getUnreservedMountVolume(2000);
Protos.Offer offer = OfferTestUtils.getCompleteOffer(offeredResource);
MesosResourcePool mesosResourcePool = new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE));
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getMountVolumeRequirement(1.0, 1000);
VolumeEvaluationStage volumeEvaluationStage = VolumeEvaluationStage.getNew(getVolumeSpec(podInstanceRequirement.getPodInstance()), getTaskName(podInstanceRequirement.getPodInstance()), Optional.empty(), true);
EvaluationOutcome outcome = volumeEvaluationStage.evaluate(mesosResourcePool, new PodInfoBuilder(podInstanceRequirement, TestConstants.SERVICE_NAME, UUID.randomUUID(), ArtifactResource.getUrlFactory(TestConstants.SERVICE_NAME), SchedulerConfigTestUtils.getTestSchedulerConfig(), Collections.emptyList(), TestConstants.FRAMEWORK_ID, true, Collections.emptyMap()));
Assert.assertTrue(outcome.isPassing());
List<OfferRecommendation> recommendations = new ArrayList<>(outcome.getOfferRecommendations());
Assert.assertEquals(2, outcome.getOfferRecommendations().size());
OfferRecommendation reserveRecommendation = recommendations.get(0);
Assert.assertEquals(Protos.Offer.Operation.Type.RESERVE, reserveRecommendation.getOperation().getType());
Protos.Resource resource = reserveRecommendation.getOperation().getReserve().getResources(0);
Assert.assertEquals("disk", resource.getName());
Assert.assertEquals(resource.getScalar(), offeredResource.getScalar());
Protos.Resource.ReservationInfo reservationInfo = ResourceUtils.getReservation(resource).get();
Protos.Label reservationLabel = reservationInfo.getLabels().getLabels(0);
Assert.assertEquals(reservationLabel.getKey(), "resource_id");
Assert.assertNotEquals(reservationLabel.getValue(), "");
OfferRecommendation createRecommendation = recommendations.get(1);
resource = createRecommendation.getOperation().getCreate().getVolumes(0);
Assert.assertEquals(Protos.Offer.Operation.Type.CREATE, createRecommendation.getOperation().getType());
Assert.assertEquals("disk", resource.getName());
Assert.assertEquals(resource.getScalar(), offeredResource.getScalar());
reservationInfo = ResourceUtils.getReservation(resource).get();
reservationLabel = reservationInfo.getLabels().getLabels(0);
Assert.assertEquals(reservationLabel.getKey(), "resource_id");
Assert.assertNotEquals(reservationLabel.getValue(), "");
Assert.assertNotEquals(resource.getDisk().getPersistence().getId(), "");
}
use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.
the class VolumeEvaluationStageTest method testCreateFails.
@Test
public void testCreateFails() throws Exception {
Protos.Resource offeredResource = ResourceTestUtils.getUnreservedMountVolume(1000);
Protos.Offer offer = OfferTestUtils.getCompleteOffer(offeredResource);
MesosResourcePool mesosResourcePool = new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE));
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getMountVolumeRequirement(1.0, 2000);
VolumeEvaluationStage volumeEvaluationStage = VolumeEvaluationStage.getNew(getVolumeSpec(podInstanceRequirement.getPodInstance()), getTaskName(podInstanceRequirement.getPodInstance()), Optional.empty(), true);
EvaluationOutcome outcome = volumeEvaluationStage.evaluate(mesosResourcePool, new PodInfoBuilder(podInstanceRequirement, TestConstants.SERVICE_NAME, UUID.randomUUID(), ArtifactResource.getUrlFactory(TestConstants.SERVICE_NAME), SchedulerConfigTestUtils.getTestSchedulerConfig(), Collections.emptyList(), TestConstants.FRAMEWORK_ID, true, Collections.emptyMap()));
Assert.assertFalse(outcome.isPassing());
Assert.assertEquals(0, outcome.getOfferRecommendations().size());
}
use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.
the class OfferEvaluatorVolumesTest method testConsumeMultipleMountVolumesFailure.
@Test
public void testConsumeMultipleMountVolumesFailure() throws Exception {
Resource offeredResource = ResourceTestUtils.getUnreservedMountVolume(2000);
ResourceSet volumeResourceSet = DefaultResourceSet.newBuilder(TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL).id(TestConstants.RESOURCE_SET_ID).cpus(1.0).addVolume(VolumeSpec.Type.MOUNT.name(), 1000.0, TestConstants.CONTAINER_PATH + "-A").addVolume(VolumeSpec.Type.MOUNT.name(), 1000.0, TestConstants.CONTAINER_PATH + "-B").build();
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getRequirement(volumeResourceSet, 0);
Protos.Offer offer = OfferTestUtils.getCompleteOffer(Arrays.asList(offeredResource));
List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(offer));
Assert.assertEquals(0, recommendations.size());
}
use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.
the class PlacementRuleEvaluationStageTest method testOfferPassesPlacementRule.
@Test
public void testOfferPassesPlacementRule() throws Exception {
String agent = "test-agent";
Protos.Resource offered = ResourceTestUtils.getUnreservedCpus(1.0);
PlacementRule rule = AgentRule.require(agent);
Protos.Offer offer = offerWithAgent(agent, offered);
MesosResourcePool mesosResourcePool = new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE));
PodSpec podSpec = PodInstanceRequirementTestUtils.getCpuRequirement(1.0).getPodInstance().getPod();
DefaultPodSpec.newBuilder(podSpec).placementRule(rule);
PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
List<String> taskNames = TaskUtils.getTaskNames(podInstance);
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, taskNames).build();
PlacementRuleEvaluationStage placementRuleEvaluationStage = new PlacementRuleEvaluationStage(Collections.emptyList(), rule);
EvaluationOutcome outcome = placementRuleEvaluationStage.evaluate(mesosResourcePool, new PodInfoBuilder(podInstanceRequirement, TestConstants.SERVICE_NAME, UUID.randomUUID(), ArtifactResource.getUrlFactory(TestConstants.SERVICE_NAME), SchedulerConfigTestUtils.getTestSchedulerConfig(), Collections.emptyList(), TestConstants.FRAMEWORK_ID, true, Collections.emptyMap()));
Assert.assertTrue(outcome.isPassing());
Assert.assertEquals(3, mesosResourcePool.getUnreservedMergedPool().size());
Assert.assertTrue(Math.abs(mesosResourcePool.getUnreservedMergedPool().get("cpus").getScalar().getValue() - 1.1) < 0.01);
}
use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement 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());
}
}
}
Aggregations