Search in sources :

Example 11 with PodInstance

use of com.mesosphere.sdk.specification.PodInstance in project dcos-commons by mesosphere.

the class OfferEvaluatorPlacementTest method testAvoidAgentsCustomExecutor.

@Test
public void testAvoidAgentsCustomExecutor() throws Exception {
    useCustomExecutor();
    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.getOffer(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(2, 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 12 with PodInstance

use of com.mesosphere.sdk.specification.PodInstance in project dcos-commons by mesosphere.

the class OfferEvaluatorPlacementTest method testColocateAgentsCustomExecutor.

@Test
public void testColocateAgentsCustomExecutor() throws Exception {
    useCustomExecutor();
    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.getOffer(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(2, 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 13 with PodInstance

use of com.mesosphere.sdk.specification.PodInstance in project dcos-commons by mesosphere.

the class RoundRobinByHostnameRuleTest method testRolloutWithAgentCount.

@Test
public void testRolloutWithAgentCount() throws TaskException, InvalidRequirementException {
    PlacementRule rule = new RoundRobinByHostnameRule(Optional.of(3), MATCHER);
    // throw in some preexisting tasks to be ignored by our matcher:
    List<TaskInfo> tasks = new ArrayList<>();
    tasks.add(getTaskInfo("ignored1", "host1"));
    tasks.add(getTaskInfo("ignored2", "host2"));
    tasks.add(getTaskInfo("ignored3", "host3"));
    tasks.add(getTaskInfo("ignored4", "host1"));
    tasks.add(getTaskInfo("ignored5", "host2"));
    // 1st task fits on host1:
    assertTrue(rule.filter(offerWithHost("host1"), POD, tasks).isPassing());
    TaskInfo taskInfo1 = getTaskInfo("1", "host1");
    PodInstance req1 = getPodInstance(taskInfo1);
    // host1:1
    tasks.add(taskInfo1);
    // 2nd task doesn't fit on host1 which already has something, but does fit on host2/host3:
    assertFalse(rule.filter(offerWithHost("host1"), POD, tasks).isPassing());
    assertTrue(rule.filter(offerWithHost("host2"), POD, tasks).isPassing());
    assertTrue(rule.filter(offerWithHost("host3"), POD, tasks).isPassing());
    TaskInfo taskInfo2 = getTaskInfo("2", "host3");
    PodInstance req2 = getPodInstance(taskInfo2);
    // host1:1, host3:1
    tasks.add(taskInfo2);
    // duplicates of preexisting tasks 1/3 fit on their previous hosts:
    assertTrue(rule.filter(offerWithHost("host1"), req1, tasks).isPassing());
    assertTrue(rule.filter(offerWithHost("host3"), req2, tasks).isPassing());
    // 3rd task doesnt fit on host1/host3, does fit on host2:
    assertFalse(rule.filter(offerWithHost("host1"), POD, tasks).isPassing());
    assertTrue(rule.filter(offerWithHost("host2"), POD, tasks).isPassing());
    assertFalse(rule.filter(offerWithHost("host3"), POD, tasks).isPassing());
    // host1:1, host2:1, host3:1
    tasks.add(getTaskInfo("3", "host2"));
    // 4th task fits on any host as the three hosts now have the same size:
    assertTrue(rule.filter(offerWithHost("host1"), POD, tasks).isPassing());
    assertTrue(rule.filter(offerWithHost("host2"), POD, tasks).isPassing());
    assertTrue(rule.filter(offerWithHost("host3"), POD, tasks).isPassing());
    // host1:1, host2:2, host3:1
    tasks.add(getTaskInfo("4", "host2"));
    // 5th task doesn't fit on host2 but does fit on host1/host3:
    assertTrue(rule.filter(offerWithHost("host1"), POD, tasks).isPassing());
    assertFalse(rule.filter(offerWithHost("host2"), POD, tasks).isPassing());
    assertTrue(rule.filter(offerWithHost("host3"), POD, tasks).isPassing());
    // host1:1, host2:2, host3:2
    tasks.add(getTaskInfo("5", "host3"));
    // 6th task is launched on erroneous host4 (host4 shouldn't exist: we were told there were only 3 hosts!)
    assertTrue(rule.filter(offerWithHost("host4"), POD, tasks).isPassing());
    // host1:1, host2:2, host3:2, host4:1
    tasks.add(getTaskInfo("6", "host4"));
    // 7th task is launched on host4 as well:
    assertTrue(rule.filter(offerWithHost("host4"), POD, tasks).isPassing());
    // host1:1, host2:2, host3:2, host4:2
    tasks.add(getTaskInfo("7", "host4"));
    // 8th task fails to launch on hosts2-4 as they now all have more occupancy than host1:
    assertFalse(rule.filter(offerWithHost("host2"), POD, tasks).isPassing());
    assertFalse(rule.filter(offerWithHost("host3"), POD, tasks).isPassing());
    assertFalse(rule.filter(offerWithHost("host4"), POD, tasks).isPassing());
    assertTrue(rule.filter(offerWithHost("host1"), POD, tasks).isPassing());
    // host1:2, host2:2, host3:2, host4:2
    tasks.add(getTaskInfo("8", "host1"));
    // now all hosts1-4 have equal occupancy = 2. adding a task to any of them should work:
    assertTrue(rule.filter(offerWithHost("host1"), POD, tasks).isPassing());
    assertTrue(rule.filter(offerWithHost("host2"), POD, tasks).isPassing());
    assertTrue(rule.filter(offerWithHost("host3"), POD, tasks).isPassing());
    assertTrue(rule.filter(offerWithHost("host4"), POD, tasks).isPassing());
}
Also used : TaskInfo(org.apache.mesos.Protos.TaskInfo) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) PodInstance(com.mesosphere.sdk.specification.PodInstance) Test(org.junit.Test)

Example 14 with PodInstance

use of com.mesosphere.sdk.specification.PodInstance in project dcos-commons by mesosphere.

the class PlacementRuleEvaluationStageTest method testOfferFailsPlacementRule.

@Test
public void testOfferFailsPlacementRule() throws Exception {
    String agent = "test-agent";
    Protos.Resource offered = ResourceTestUtils.getUnreservedCpus(1.0);
    PlacementRule rule = AgentRule.require(agent);
    Protos.Offer offer = offerWithAgent("other-agent", offered);
    MesosResourcePool mesosResourcePool = new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE));
    PodSpec podSpec = PodInstanceRequirementTestUtils.getCpuRequirement(1.0).getPodInstance().getPod();
    DefaultPodSpec.newBuilder(podSpec).placementRule(rule);
    PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
    List<String> taskNames = TaskUtils.getTaskNames(podInstance);
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, taskNames).build();
    PlacementRuleEvaluationStage placementRuleEvaluationStage = new PlacementRuleEvaluationStage(Collections.emptyList(), rule);
    EvaluationOutcome outcome = placementRuleEvaluationStage.evaluate(mesosResourcePool, new PodInfoBuilder(podInstanceRequirement, TestConstants.SERVICE_NAME, UUID.randomUUID(), ArtifactResource.getUrlFactory(TestConstants.SERVICE_NAME), SchedulerConfigTestUtils.getTestSchedulerConfig(), Collections.emptyList(), TestConstants.FRAMEWORK_ID, true, Collections.emptyMap()));
    Assert.assertFalse(outcome.isPassing());
    Assert.assertEquals(3, mesosResourcePool.getUnreservedMergedPool().size());
    Assert.assertTrue(Math.abs(mesosResourcePool.getUnreservedMergedPool().get("cpus").getScalar().getValue() - 1.1) < 0.01);
}
Also used : 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) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) MesosResourcePool(com.mesosphere.sdk.offer.MesosResourcePool) Protos(org.apache.mesos.Protos) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) Test(org.junit.Test)

Example 15 with PodInstance

use of com.mesosphere.sdk.specification.PodInstance in project dcos-commons by mesosphere.

the class DefaultPlanSchedulerTest method beforeEach.

@Before
public void beforeEach() throws Exception {
    MockitoAnnotations.initMocks(this);
    Driver.setDriver(mockSchedulerDriver);
    mockRecommendations = Arrays.asList(mockRecommendation);
    scheduler = new DefaultPlanScheduler(mockOfferAccepter, mockOfferEvaluator, mockStateStore);
    ClassLoader classLoader = getClass().getClassLoader();
    File file = new File(classLoader.getResource("valid-minimal.yml").getFile());
    DefaultServiceSpec serviceSpec = DefaultServiceSpec.newGenerator(file, SCHEDULER_CONFIG).build();
    PodSpec podSpec = serviceSpec.getPods().get(0);
    PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
    podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, TaskUtils.getTaskNames(podInstance)).build();
}
Also used : PodSpec(com.mesosphere.sdk.specification.PodSpec) PodInstance(com.mesosphere.sdk.specification.PodInstance) File(java.io.File) DefaultServiceSpec(com.mesosphere.sdk.specification.DefaultServiceSpec) Before(org.junit.Before)

Aggregations

PodInstance (com.mesosphere.sdk.specification.PodInstance)16 DefaultPodInstance (com.mesosphere.sdk.scheduler.plan.DefaultPodInstance)10 PodSpec (com.mesosphere.sdk.specification.PodSpec)10 Test (org.junit.Test)10 DefaultPodSpec (com.mesosphere.sdk.specification.DefaultPodSpec)8 Protos (org.apache.mesos.Protos)7 PlacementRule (com.mesosphere.sdk.offer.evaluate.placement.PlacementRule)6 PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)6 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)4 TaskInfo (org.apache.mesos.Protos.TaskInfo)4 MesosResourcePool (com.mesosphere.sdk.offer.MesosResourcePool)2 SerialStrategy (com.mesosphere.sdk.scheduler.plan.strategy.SerialStrategy)2 Collectors (java.util.stream.Collectors)2 Before (org.junit.Before)2 TaskException (com.mesosphere.sdk.offer.TaskException)1 EvaluationOutcome (com.mesosphere.sdk.offer.evaluate.EvaluationOutcome)1 com.mesosphere.sdk.scheduler.plan (com.mesosphere.sdk.scheduler.plan)1 Strategy (com.mesosphere.sdk.scheduler.plan.strategy.Strategy)1 RecoveryPlanOverrider (com.mesosphere.sdk.scheduler.recovery.RecoveryPlanOverrider)1 RecoveryStep (com.mesosphere.sdk.scheduler.recovery.RecoveryStep)1