Search in sources :

Example 36 with OfferRecommendation

use of com.mesosphere.sdk.offer.OfferRecommendation in project dcos-commons by mesosphere.

the class OfferEvaluatorPortsTest method testReserveStaticPort.

@Test
public void testReserveStaticPort() throws Exception {
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(555);
    Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(555, 555);
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, OfferTestUtils.getCompleteOffers(offeredPorts));
    Assert.assertEquals(5, recommendations.size());
    Protos.Offer.Operation launchOperation = recommendations.get(4).getOperation();
    Protos.TaskInfo taskInfo = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0);
    Protos.Resource fulfilledPortResource = taskInfo.getResources(0);
    Assert.assertFalse(getResourceId(fulfilledPortResource).isEmpty());
    Protos.CommandInfo command = TaskPackingUtils.unpack(taskInfo).getCommand();
    Map<String, String> envvars = EnvUtils.toMap(command.getEnvironment());
    Assert.assertEquals(String.valueOf(555), envvars.get(TestConstants.PORT_ENV_NAME + "_555"));
}
Also used : Operation(org.apache.mesos.Protos.Offer.Operation) Protos(org.apache.mesos.Protos) Resource(org.apache.mesos.Protos.Resource) TaskInfo(org.apache.mesos.Protos.TaskInfo) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 37 with OfferRecommendation

use of com.mesosphere.sdk.offer.OfferRecommendation in project dcos-commons by mesosphere.

the class OfferEvaluatorPortsTest method testReserveStaticPortCustomExecutor.

@Test
public void testReserveStaticPortCustomExecutor() throws Exception {
    useCustomExecutor();
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(555);
    Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(555, 555);
    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());
    Protos.CommandInfo command = TaskPackingUtils.unpack(taskInfo).getCommand();
    Map<String, String> envvars = EnvUtils.toMap(command.getEnvironment());
    Assert.assertEquals(String.valueOf(555), envvars.get(TestConstants.PORT_ENV_NAME + "_555"));
}
Also used : Operation(org.apache.mesos.Protos.Offer.Operation) Protos(org.apache.mesos.Protos) Resource(org.apache.mesos.Protos.Resource) TaskInfo(org.apache.mesos.Protos.TaskInfo) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 38 with OfferRecommendation

use of com.mesosphere.sdk.offer.OfferRecommendation in project dcos-commons by mesosphere.

the class OfferEvaluatorPortsTest method testLaunchExpectedDynamicPort.

@Test
public void testLaunchExpectedDynamicPort() throws Exception {
    // Launch for the first time: get port 10000
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(0);
    Resource reserveResource = recordLaunchWithCompleteOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedPorts(10000, 10000)).get(0);
    String resourceId = getResourceId(reserveResource);
    Collection<Resource> expectedResources = getExpectedExecutorResources(stateStore.fetchTasks().iterator().next().getExecutor());
    expectedResources.add(ResourceTestUtils.getReservedPorts(10000, 10000, resourceId));
    // Relaunch: detect (from envvar) and reuse previously reserved dynamic port 10000
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getOffer(expectedResources)));
    Assert.assertEquals(1, recommendations.size());
    // Validate LAUNCH Operation
    Operation launchOperation = recommendations.get(0).getOperation();
    Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType());
    Resource launchResource = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0).getResources(0);
    Assert.assertEquals(resourceId, getResourceId(launchResource));
}
Also used : Resource(org.apache.mesos.Protos.Resource) Operation(org.apache.mesos.Protos.Offer.Operation) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 39 with OfferRecommendation

use of com.mesosphere.sdk.offer.OfferRecommendation in project dcos-commons by mesosphere.

the class OfferEvaluatorPortsTest method testLaunchExpectedStaticPort.

@Test
public void testLaunchExpectedStaticPort() throws Exception {
    // Launch for the first time: get port 555
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(555);
    Resource reserveResource = recordLaunchWithCompleteOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedPorts(555, 555)).get(0);
    String resourceId = getResourceId(reserveResource);
    Collection<Resource> expectedResources = getExpectedExecutorResources(stateStore.fetchTasks().iterator().next().getExecutor());
    expectedResources.add(ResourceTestUtils.getReservedPorts(555, 555, resourceId));
    // Launch on previously reserved resources
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getOffer(expectedResources)));
    Assert.assertEquals(1, recommendations.size());
    // Validate LAUNCH Operation
    Protos.Offer.Operation launchOperation = recommendations.get(0).getOperation();
    Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType());
    Protos.Resource launchResource = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0).getResources(0);
    Assert.assertEquals(resourceId, getResourceId(launchResource));
}
Also used : Operation(org.apache.mesos.Protos.Offer.Operation) Protos(org.apache.mesos.Protos) Resource(org.apache.mesos.Protos.Resource) Resource(org.apache.mesos.Protos.Resource) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 40 with OfferRecommendation

use of com.mesosphere.sdk.offer.OfferRecommendation in project dcos-commons by mesosphere.

the class OfferEvaluatorPortsTest method testReserveTaskDynamicPort.

@Test
public void testReserveTaskDynamicPort() throws Exception {
    Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(0);
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, OfferTestUtils.getCompleteOffers(offeredPorts));
    Assert.assertEquals(5, recommendations.size());
    Protos.Offer.Operation launchOperation = recommendations.get(4).getOperation();
    Protos.TaskInfo taskInfo = launchOperation.getLaunchGroup().getTaskGroup().getTasks(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"));
}
Also used : Operation(org.apache.mesos.Protos.Offer.Operation) Protos(org.apache.mesos.Protos) Resource(org.apache.mesos.Protos.Resource) TaskInfo(org.apache.mesos.Protos.TaskInfo) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) 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