Search in sources :

Example 6 with OfferRecommendation

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

the class OfferEvaluatorPortsTest method testLaunchExpectedMultiplePortsCustomExecutor.

@Test
public void testLaunchExpectedMultiplePortsCustomExecutor() throws Exception {
    useCustomExecutor();
    // Launch for the first time: get ports 10000,10001
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(10000, 10001);
    List<Resource> reserveResources = recordLaunchWithOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedPorts(10000, 10001));
    Assert.assertEquals(reserveResources.toString(), 2, reserveResources.size());
    String resourceId0 = getResourceId(reserveResources.get(0));
    String resourceId1 = getResourceId(reserveResources.get(1));
    // Now try relaunch:
    List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getPortRequirement(10000, 10001), OfferTestUtils.getOffers(Arrays.asList(ResourceTestUtils.getReservedPorts(10000, 10000, resourceId0), ResourceTestUtils.getReservedPorts(10001, 10001, resourceId1))));
    Assert.assertEquals(1, recommendations.size());
    // Validate LAUNCH Operation
    Operation launchOperation = recommendations.get(0).getOperation();
    Assert.assertEquals(Operation.Type.LAUNCH, launchOperation.getType());
    List<Resource> launchResources = launchOperation.getLaunch().getTaskInfos(0).getResourcesList();
    Assert.assertEquals(launchResources.toString(), 2, launchResources.size());
    Assert.assertEquals(resourceId0, getResourceId(launchResources.get(0)));
    Assert.assertEquals(resourceId1, getResourceId(launchResources.get(1)));
}
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 7 with OfferRecommendation

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

the class OfferEvaluatorPortsTest method testReserveTaskMultipleDynamicPorts.

@Test
public void testReserveTaskMultipleDynamicPorts() throws Exception {
    String portenv0 = TestConstants.PORT_ENV_NAME + "_DYN_ZERO";
    String portenv1 = TestConstants.PORT_ENV_NAME + "_DYN_ONE";
    Map<String, Integer> ports = new HashMap<>();
    ports.put(portenv0, 0);
    ports.put(portenv1, 0);
    List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getPortRequirement(ports), OfferTestUtils.getCompleteOffers(ResourceTestUtils.getUnreservedPorts(10000, 10001)));
    Assert.assertEquals(recommendations.toString(), 6, recommendations.size());
    Operation reserveOperation = recommendations.get(0).getOperation();
    Resource fulfilledPortResource1 = reserveOperation.getReserve().getResources(0);
    Assert.assertEquals(10000, fulfilledPortResource1.getRanges().getRange(0).getBegin());
    Assert.assertEquals(10000, fulfilledPortResource1.getRanges().getRange(0).getEnd());
    reserveOperation = recommendations.get(1).getOperation();
    Resource fulfilledPortResource2 = reserveOperation.getReserve().getResources(0);
    Assert.assertEquals(10001, fulfilledPortResource2.getRanges().getRange(0).getBegin());
    Assert.assertEquals(10001, fulfilledPortResource2.getRanges().getRange(0).getEnd());
    Operation launchOperation = recommendations.get(5).getOperation();
    TaskInfo taskInfo = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0);
    Assert.assertEquals(getResourceId(taskInfo.getResources(0)), getResourceId(fulfilledPortResource1));
    Assert.assertEquals(getResourceId(taskInfo.getResources(1)), getResourceId(fulfilledPortResource2));
    Map<String, String> envvars = EnvUtils.toMap(TaskPackingUtils.unpack(taskInfo).getCommand().getEnvironment());
    Assert.assertEquals(String.valueOf(10000), envvars.get(portenv0));
    Assert.assertEquals(String.valueOf(10001), envvars.get(portenv1));
    Assert.assertEquals(10000, taskInfo.getResources(0).getRanges().getRange(0).getBegin());
    Assert.assertEquals(10000, taskInfo.getResources(0).getRanges().getRange(0).getEnd());
    Assert.assertEquals(10001, taskInfo.getResources(1).getRanges().getRange(0).getBegin());
    Assert.assertEquals(10001, taskInfo.getResources(1).getRanges().getRange(0).getEnd());
}
Also used : TaskInfo(org.apache.mesos.Protos.TaskInfo) HashMap(java.util.HashMap) Resource(org.apache.mesos.Protos.Resource) Operation(org.apache.mesos.Protos.Offer.Operation) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 8 with OfferRecommendation

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

the class OfferEvaluatorPortsTest method testLaunchExpectedStaticPortCustomExecutor.

@Test
public void testLaunchExpectedStaticPortCustomExecutor() throws Exception {
    useCustomExecutor();
    // Launch for the first time: get port 555
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(555);
    Resource reserveResource = recordLaunchWithOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedPorts(555, 555)).get(0);
    String resourceId = getResourceId(reserveResource);
    // Launch on previously reserved resources
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, OfferTestUtils.getOffers(ResourceTestUtils.getReservedPorts(555, 555, resourceId)));
    Assert.assertEquals(1, recommendations.size());
    // Validate LAUNCH Operation
    Protos.Offer.Operation launchOperation = recommendations.get(0).getOperation();
    Assert.assertEquals(Protos.Offer.Operation.Type.LAUNCH, launchOperation.getType());
    Protos.Resource launchResource = launchOperation.getLaunch().getTaskInfos(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 9 with OfferRecommendation

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

the class OfferEvaluatorPortsTest method testLaunchExpectedMultiplePorts.

@Test
public void testLaunchExpectedMultiplePorts() throws Exception {
    // Launch for the first time: get ports 10000,10001
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(10000, 10001);
    List<Resource> reserveResources = recordLaunchWithCompleteOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedPorts(10000, 10001));
    Assert.assertEquals(reserveResources.toString(), 5, reserveResources.size());
    String resourceId0 = getResourceId(reserveResources.get(0));
    String resourceId1 = getResourceId(reserveResources.get(1));
    Collection<Resource> expectedResources = getExpectedExecutorResources(stateStore.fetchTasks().iterator().next().getExecutor());
    expectedResources.addAll(Arrays.asList(ResourceTestUtils.getReservedPorts(10000, 10000, resourceId0), ResourceTestUtils.getReservedPorts(10001, 10001, resourceId1)));
    // Now try relaunch:
    List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getPortRequirement(10000, 10001), 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());
    List<Resource> launchResources = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0).getResourcesList();
    Assert.assertEquals(launchResources.toString(), 2, launchResources.size());
    Assert.assertEquals(resourceId0, getResourceId(launchResources.get(0)));
    Assert.assertEquals(resourceId1, getResourceId(launchResources.get(1)));
}
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 10 with OfferRecommendation

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

the class OfferEvaluatorPortsTest method testLaunchExpectedDynamicPortCustomExecutor.

@Test
public void testLaunchExpectedDynamicPortCustomExecutor() throws Exception {
    useCustomExecutor();
    // Launch for the first time: get port 10000
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(0);
    Resource reserveResource = recordLaunchWithOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedPorts(10000, 10000)).get(0);
    String resourceId = getResourceId(reserveResource);
    // Relaunch: detect (from envvar) and reuse previously reserved dynamic port 10000
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, OfferTestUtils.getOffers(ResourceTestUtils.getReservedPorts(10000, 10000, resourceId)));
    Assert.assertEquals(1, recommendations.size());
    // Validate LAUNCH Operation
    Operation launchOperation = recommendations.get(0).getOperation();
    Assert.assertEquals(Operation.Type.LAUNCH, launchOperation.getType());
    Resource launchResource = launchOperation.getLaunch().getTaskInfos(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)

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