Search in sources :

Example 21 with OfferRecommendation

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"));
}
Also used : TaskInfo(org.apache.mesos.Protos.TaskInfo) Resource(org.apache.mesos.Protos.Resource) Operation(org.apache.mesos.Protos.Offer.Operation) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 22 with OfferRecommendation

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());
}
Also used : Protos(org.apache.mesos.Protos) Resource(org.apache.mesos.Protos.Resource) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 23 with OfferRecommendation

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());
    }
}
Also used : Protos(org.apache.mesos.Protos) DefaultResourceSpec(com.mesosphere.sdk.specification.DefaultResourceSpec) ResourceSpec(com.mesosphere.sdk.specification.ResourceSpec) ReserveEvaluationOutcome(com.mesosphere.sdk.offer.evaluate.OfferEvaluationUtils.ReserveEvaluationOutcome) ReserveOfferRecommendation(com.mesosphere.sdk.offer.ReserveOfferRecommendation) UnreserveOfferRecommendation(com.mesosphere.sdk.offer.UnreserveOfferRecommendation) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) ReserveOfferRecommendation(com.mesosphere.sdk.offer.ReserveOfferRecommendation)

Example 24 with OfferRecommendation

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);
}
Also used : Counter(com.codahale.metrics.Counter) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) LaunchOfferRecommendation(com.mesosphere.sdk.offer.LaunchOfferRecommendation) Test(org.junit.Test)

Example 25 with OfferRecommendation

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);
}
Also used : Resource(org.apache.mesos.Protos.Resource) Operation(org.apache.mesos.Protos.Offer.Operation) 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