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());
}
}
}
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());
}
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());
}
}
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());
}
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());
}
Aggregations