Search in sources :

Example 1 with PodInstanceRequirement

use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.

the class OfferEvaluatorPlacementTest method testColocateAgents.

@Test
public void testColocateAgents() throws Exception {
    Protos.Resource offeredCpu = ResourceTestUtils.getUnreservedCpus(2.0);
    // Don't launch
    PlacementRule placementRule = PlacementUtils.getAgentPlacementRule(Collections.emptyList(), Arrays.asList("some-random-agent")).get();
    PodSpec podSpec = PodInstanceRequirementTestUtils.getCpuRequirement(1.0).getPodInstance().getPod();
    podSpec = DefaultPodSpec.newBuilder(podSpec).placementRule(placementRule).build();
    PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, Arrays.asList(TestConstants.TASK_NAME)).build();
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getCompleteOffer(offeredCpu)));
    Assert.assertEquals(0, recommendations.size());
    // Launch
    placementRule = PlacementUtils.getAgentPlacementRule(Collections.emptyList(), Arrays.asList(TestConstants.AGENT_ID.getValue())).get();
    podSpec = DefaultPodSpec.newBuilder(podSpec).placementRule(placementRule).build();
    podInstance = new DefaultPodInstance(podSpec, 0);
    podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, Arrays.asList(TestConstants.TASK_NAME)).build();
    recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getCompleteOffer(offeredCpu)));
    Assert.assertEquals(5, recommendations.size());
}
Also used : Protos(org.apache.mesos.Protos) DefaultPodSpec(com.mesosphere.sdk.specification.DefaultPodSpec) PodSpec(com.mesosphere.sdk.specification.PodSpec) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) PodInstance(com.mesosphere.sdk.specification.PodInstance) PlacementRule(com.mesosphere.sdk.offer.evaluate.placement.PlacementRule) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 2 with PodInstanceRequirement

use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.

the class OfferEvaluatorPlacementTest method testAvoidAgents.

@Test
public void testAvoidAgents() throws Exception {
    Protos.Resource offeredCpu = ResourceTestUtils.getUnreservedCpus(2.0);
    // Don't launch
    PlacementRule placementRule = PlacementUtils.getAgentPlacementRule(Arrays.asList(TestConstants.AGENT_ID.getValue()), Collections.emptyList()).get();
    PodSpec podSpec = PodInstanceRequirementTestUtils.getCpuRequirement(1.0).getPodInstance().getPod();
    podSpec = DefaultPodSpec.newBuilder(podSpec).placementRule(placementRule).build();
    PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, Arrays.asList(TestConstants.TASK_NAME)).build();
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getCompleteOffer(offeredCpu)));
    Assert.assertEquals(0, recommendations.size());
    // Launch
    placementRule = PlacementUtils.getAgentPlacementRule(Arrays.asList("some-random-agent"), Collections.emptyList()).get();
    podSpec = DefaultPodSpec.newBuilder(podSpec).placementRule(placementRule).build();
    podInstance = new DefaultPodInstance(podSpec, 0);
    podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, Arrays.asList(TestConstants.TASK_NAME)).build();
    recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getCompleteOffer(offeredCpu)));
    Assert.assertEquals(5, recommendations.size());
}
Also used : Protos(org.apache.mesos.Protos) DefaultPodSpec(com.mesosphere.sdk.specification.DefaultPodSpec) PodSpec(com.mesosphere.sdk.specification.PodSpec) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) PodInstance(com.mesosphere.sdk.specification.PodInstance) PlacementRule(com.mesosphere.sdk.offer.evaluate.placement.PlacementRule) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 3 with PodInstanceRequirement

use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement 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 4 with PodInstanceRequirement

use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement 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 5 with PodInstanceRequirement

use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement 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)

Aggregations

PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)51 Test (org.junit.Test)47 Protos (org.apache.mesos.Protos)38 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)21 Resource (org.apache.mesos.Protos.Resource)17 DefaultPodInstance (com.mesosphere.sdk.scheduler.plan.DefaultPodInstance)16 Operation (org.apache.mesos.Protos.Offer.Operation)15 Collectors (java.util.stream.Collectors)10 com.mesosphere.sdk.specification (com.mesosphere.sdk.specification)8 java.util (java.util)8 Assert (org.junit.Assert)8 ArtifactResource (com.mesosphere.sdk.http.endpoints.ArtifactResource)7 MesosResourcePool (com.mesosphere.sdk.offer.MesosResourcePool)7 SchedulerConfig (com.mesosphere.sdk.scheduler.SchedulerConfig)7 com.mesosphere.sdk.offer (com.mesosphere.sdk.offer)6 PlacementRule (com.mesosphere.sdk.offer.evaluate.placement.PlacementRule)6 TaskLabelWriter (com.mesosphere.sdk.offer.taskdata.TaskLabelWriter)6 DefaultPodSpec (com.mesosphere.sdk.specification.DefaultPodSpec)6 PodInstance (com.mesosphere.sdk.specification.PodInstance)6 PodSpec (com.mesosphere.sdk.specification.PodSpec)6