use of com.mesosphere.sdk.offer.OfferRecommendation in project dcos-commons by mesosphere.
the class OfferEvaluatorPortsTest method testReserveTaskDynamicPortCustomExecutor.
@Test
public void testReserveTaskDynamicPortCustomExecutor() throws Exception {
useCustomExecutor();
Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(0);
List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, OfferTestUtils.getOffers(offeredPorts));
Assert.assertEquals(2, recommendations.size());
Protos.Offer.Operation launchOperation = recommendations.get(1).getOperation();
Protos.TaskInfo taskInfo = launchOperation.getLaunch().getTaskInfos(0);
Protos.Resource fulfilledPortResource = taskInfo.getResources(0);
Assert.assertFalse(getResourceId(fulfilledPortResource).isEmpty());
Map<String, String> envvars = EnvUtils.toMap(TaskPackingUtils.unpack(taskInfo).getCommand().getEnvironment());
Assert.assertEquals(envvars.toString(), String.valueOf(10000), envvars.get(TestConstants.PORT_ENV_NAME + "_0"));
}
use of com.mesosphere.sdk.offer.OfferRecommendation in project dcos-commons by mesosphere.
the class UninstallRecorderTest method testHandlingOfUnexpectedOfferRecommendation.
@Test
public void testHandlingOfUnexpectedOfferRecommendation() throws Exception {
Protos.Resource resource = ResourceTestUtils.getUnreservedCpus(1.0);
OfferRecommendation unsupportedOfferRecommendation = new CreateOfferRecommendation(null, resource);
StateStore mockStateStore = mock(StateStore.class);
OperationRecorder operationRecorder = new UninstallRecorder(mockStateStore, null);
// should just return without error
operationRecorder.record(unsupportedOfferRecommendation);
}
use of com.mesosphere.sdk.offer.OfferRecommendation 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);
}
use of com.mesosphere.sdk.offer.OfferRecommendation in project dcos-commons by mesosphere.
the class OfferEvaluatorVolumesTest method testReserveCreateLaunchRootVolume.
@Test
public void testReserveCreateLaunchRootVolume() throws Exception {
Resource offeredCpuResource = ResourceTestUtils.getUnreservedCpus(1.0);
Resource offeredDiskResource = ResourceTestUtils.getUnreservedDisk(2000);
List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getRootVolumeRequirement(1.0, 1500), Arrays.asList(OfferTestUtils.getCompleteOffer(Arrays.asList(offeredDiskResource, offeredCpuResource))));
// RESERVE, RESERVE, CREATE, RESERVE, RESERVE, RESERVE, LAUNCH
Assert.assertEquals(7, recommendations.size());
// Validate CPU RESERVE Operation
Operation reserveOperation = recommendations.get(0).getOperation();
Resource reserveResource = reserveOperation.getReserve().getResources(0);
Resource.ReservationInfo reservation = ResourceUtils.getReservation(reserveResource).get();
Assert.assertEquals(Operation.Type.RESERVE, reserveOperation.getType());
Assert.assertEquals(1.0, reserveResource.getScalar().getValue(), 0.0);
OfferEvaluatorTest.validateRole(reserveResource);
Assert.assertEquals(TestConstants.ROLE, ResourceUtils.getRole(reserveResource));
Assert.assertEquals(TestConstants.PRINCIPAL, reservation.getPrincipal());
Assert.assertEquals(36, getResourceId(reserveResource).length());
Assert.assertFalse(reserveResource.hasDisk());
// Validate DISK RESERVE Operation
reserveOperation = recommendations.get(1).getOperation();
reserveResource = reserveOperation.getReserve().getResources(0);
reservation = ResourceUtils.getReservation(reserveResource).get();
Assert.assertEquals(Operation.Type.RESERVE, reserveOperation.getType());
Assert.assertEquals(1500, reserveResource.getScalar().getValue(), 0.0);
OfferEvaluatorTest.validateRole(reserveResource);
Assert.assertEquals(TestConstants.ROLE, ResourceUtils.getRole(reserveResource));
Assert.assertEquals(TestConstants.PRINCIPAL, reservation.getPrincipal());
Assert.assertEquals(36, getResourceId(reserveResource).length());
Assert.assertFalse(reserveResource.hasDisk());
// Validate CREATE Operation
String resourceId = getResourceId(reserveResource);
Operation createOperation = recommendations.get(2).getOperation();
Resource createResource = createOperation.getCreate().getVolumes(0);
Assert.assertEquals(resourceId, getResourceId(createResource));
Assert.assertEquals(36, createResource.getDisk().getPersistence().getId().length());
Assert.assertEquals(TestConstants.PRINCIPAL, createResource.getDisk().getPersistence().getPrincipal());
Assert.assertTrue(createResource.getDisk().hasVolume());
// Validate LAUNCH Operation
String persistenceId = createResource.getDisk().getPersistence().getId();
Operation launchOperation = recommendations.get(6).getOperation();
Resource launchResource = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0).getResources(1);
Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType());
Assert.assertEquals(resourceId, getResourceId(launchResource));
Assert.assertEquals(persistenceId, launchResource.getDisk().getPersistence().getId());
Assert.assertEquals(TestConstants.PRINCIPAL, launchResource.getDisk().getPersistence().getPrincipal());
}
use of com.mesosphere.sdk.offer.OfferRecommendation 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());
}
Aggregations