use of com.mesosphere.sdk.offer.OfferRecommendation in project dcos-commons by mesosphere.
the class OfferEvaluatorPortsTest method testUpdateStaticToStaticPort.
@Test
public void testUpdateStaticToStaticPort() throws Exception {
// Launch for the first time: get port 555
Resource reserveResource = recordLaunchWithCompleteOfferedResources(PodInstanceRequirementTestUtils.getPortRequirement(555), ResourceTestUtils.getUnreservedPorts(555, 555)).get(0);
String resourceId = getResourceId(reserveResource);
Collection<Resource> expectedResources = getExpectedExecutorResources(stateStore.fetchTasks().iterator().next().getExecutor());
expectedResources.addAll(Arrays.asList(ResourceTestUtils.getReservedPorts(555, 555, resourceId), ResourceTestUtils.getUnreservedPorts(666, 666)));
// Now lets move to port 666:
List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getPortRequirement(666), Arrays.asList(OfferTestUtils.getOffer(expectedResources)));
// UNRESERVE, RESERVE, LAUNCH
Assert.assertEquals(recommendations.toString(), 3, recommendations.size());
Assert.assertEquals(Operation.Type.UNRESERVE, recommendations.get(0).getOperation().getType());
Assert.assertEquals(Operation.Type.RESERVE, recommendations.get(1).getOperation().getType());
Assert.assertEquals(Operation.Type.LAUNCH_GROUP, recommendations.get(2).getOperation().getType());
Operation launchOperation = recommendations.get(2).getOperation();
TaskInfo taskInfo = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0);
Map<String, String> envvars = EnvUtils.toMap(TaskPackingUtils.unpack(taskInfo).getCommand().getEnvironment());
Assert.assertEquals(String.valueOf(666), envvars.get(TestConstants.PORT_ENV_NAME + "_666"));
}
use of com.mesosphere.sdk.offer.OfferRecommendation in project dcos-commons by mesosphere.
the class OfferEvaluatorPortsTest method testReserveStaticPortFailure.
@Test
public void testReserveStaticPortFailure() throws Exception {
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(555);
Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(666, 666);
List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, OfferTestUtils.getCompleteOffers(offeredPorts));
Assert.assertEquals(0, recommendations.size());
}
use of com.mesosphere.sdk.offer.OfferRecommendation in project dcos-commons by mesosphere.
the class OfferEvaluationUtilsTest method testResourceIncreaseSufficient.
private void testResourceIncreaseSufficient(Optional<String> namespace) {
String resourceId = UUID.randomUUID().toString();
Protos.Value current = getValue(4);
Protos.Value desired = getValue(5);
Protos.Value toAdd = ValueUtils.subtract(desired, current);
ResourceSpec resourceSpec = getResourceSpec(desired);
when(mockPool.consumeReserved(RESOURCE_NAME, desired, resourceId)).thenReturn(Optional.of(getMesosResource(getResourceSpec(current), resourceId, namespace)));
when(mockPool.consumeReservableMerged(RESOURCE_NAME, toAdd, Constants.ANY_ROLE)).thenReturn(Optional.of(getMesosResource(toAdd)));
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 ReserveOfferRecommendation);
Assert.assertTrue(outcome.getResourceId().isPresent());
Protos.Resource resource = recommendation.getOperation().getReserve().getResources(0);
Assert.assertEquals(toAdd.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 MetricsTest method taskLaunches.
@Test
public void taskLaunches() throws Exception {
OfferRecommendation realRecommendation = getRecommendation(true);
Assert.assertTrue(((LaunchOfferRecommendation) realRecommendation).shouldLaunch());
OfferRecommendation suppressedRecommendation = getRecommendation(false);
Assert.assertFalse(((LaunchOfferRecommendation) suppressedRecommendation).shouldLaunch());
Counter launchCounter = Metrics.getRegistry().counter("operation.launch_group");
long val = launchCounter.getCount();
Metrics.OperationsCounter.getInstance().record(realRecommendation);
Metrics.OperationsCounter.getInstance().record(realRecommendation);
Metrics.OperationsCounter.getInstance().record(realRecommendation);
Assert.assertEquals(3, launchCounter.getCount() - val);
val = launchCounter.getCount();
Metrics.OperationsCounter.getInstance().record(suppressedRecommendation);
Metrics.OperationsCounter.getInstance().record(suppressedRecommendation);
Assert.assertEquals(0, launchCounter.getCount() - val);
}
use of com.mesosphere.sdk.offer.OfferRecommendation in project dcos-commons by mesosphere.
the class OfferEvaluatorVolumesTest method testReserveCreateLaunchMountVolume.
@Test
public void testReserveCreateLaunchMountVolume() throws Exception {
Resource offeredCpuResource = ResourceTestUtils.getUnreservedCpus(1.0);
Resource offeredDiskResource = ResourceTestUtils.getUnreservedMountVolume(2000);
List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getMountVolumeRequirement(1.0, 1500), Arrays.asList(OfferTestUtils.getCompleteOffer(Arrays.asList(offeredCpuResource, offeredDiskResource))));
// RESERVE, RESERVE, CREATE, RESERVE, RESERVE, RESERVE, LAUNCH
Assert.assertEquals(7, recommendations.size());
// Validate RESERVE Operation
Operation reserveOperation = recommendations.get(1).getOperation();
Resource reserveResource = reserveOperation.getReserve().getResources(0);
Resource.ReservationInfo reservation = ResourceUtils.getReservation(reserveResource).get();
Assert.assertEquals(Operation.Type.RESERVE, reserveOperation.getType());
Assert.assertEquals(2000, reserveResource.getScalar().getValue(), 0.0);
Assert.assertEquals(TestConstants.MOUNT_ROOT, reserveResource.getDisk().getSource().getMount().getRoot());
Assert.assertEquals(TestConstants.PRINCIPAL, reservation.getPrincipal());
Assert.assertEquals(36, getResourceId(reserveResource).length());
Assert.assertTrue(reserveResource.hasDisk());
Assert.assertFalse(reserveResource.getDisk().hasPersistence());
Assert.assertFalse(reserveResource.getDisk().hasVolume());
// 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.MOUNT_ROOT, createResource.getDisk().getSource().getMount().getRoot());
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.MOUNT_ROOT, launchResource.getDisk().getSource().getMount().getRoot());
Assert.assertEquals(TestConstants.PRINCIPAL, launchResource.getDisk().getPersistence().getPrincipal());
Assert.assertEquals(2000, launchResource.getScalar().getValue(), 0.0);
}
Aggregations