Search in sources :

Example 26 with PodInstanceRequirement

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

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

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

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

the class TaskUtilsTest method testRelaunchFailedMixedTasksInMixedPod.

@Test
public void testRelaunchFailedMixedTasksInMixedPod() throws ConfigStoreException {
    // layout: 3 'server' pod instances, each with 2 essential + 2 nonessential tasks
    // failed: server-0-essential0, server-0-nonessential0, server-1-nonessential1
    List<PodInstanceRequirement> reqs = TaskUtils.getPodRequirements(TWO_ESSENTIAL_TWO_NONESSENTIAL, filterTasksByName(TWO_ESSENTIAL_TWO_NONESSENTIAL_TASKS, "server-0-essential0", "server-0-nonessential0", "server-1-nonessential1"), TWO_ESSENTIAL_TWO_NONESSENTIAL_TASKS);
    Assert.assertEquals(2, reqs.size());
    PodInstanceRequirement req = reqs.get(0);
    Assert.assertEquals("server-0:[essential0, essential1, nonessential0, nonessential1]", req.getName());
    Assert.assertEquals(Arrays.asList("essential0", "essential1", "nonessential0", "nonessential1"), req.getTasksToLaunch());
    req = reqs.get(1);
    Assert.assertEquals("server-1:[nonessential1]", req.getName());
    Assert.assertEquals(Arrays.asList("nonessential1"), req.getTasksToLaunch());
}
Also used : PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) Test(org.junit.Test)

Example 30 with PodInstanceRequirement

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

the class ExecutorEvaluationStageTest method testRejectOfferWithoutExpectedExecutorIdCustomExecutor.

@Test
public void testRejectOfferWithoutExpectedExecutorIdCustomExecutor() throws Exception {
    useCustomExecutor();
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getCpuRequirement(1.0);
    // Record launch and RUNNING status
    String resourceId = getFirstResourceId(recordLaunchWithOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedCpus(1.0)));
    String taskName = stateStore.fetchTaskNames().stream().findFirst().get();
    Protos.TaskInfo taskInfo = stateStore.fetchTask(taskName).get();
    stateStore.storeStatus(taskInfo.getName(), Protos.TaskStatus.newBuilder().setState(Protos.TaskState.TASK_RUNNING).setTaskId(taskInfo.getTaskId()).build());
    Protos.Resource expectedTaskCpu = ResourceTestUtils.getReservedCpus(1.0, resourceId);
    MesosResourcePool resources = new MesosResourcePool(OfferTestUtils.getOffer(Arrays.asList(expectedTaskCpu)), Optional.of(Constants.ANY_ROLE));
    ExecutorEvaluationStage executorEvaluationStage = new ExecutorEvaluationStage(TestConstants.SERVICE_NAME, Optional.of(taskInfo.getExecutor().getExecutorId()));
    EvaluationOutcome outcome = executorEvaluationStage.evaluate(resources, new PodInfoBuilder(podInstanceRequirement, TestConstants.SERVICE_NAME, UUID.randomUUID(), ArtifactResource.getUrlFactory(TestConstants.SERVICE_NAME), SchedulerConfigTestUtils.getTestSchedulerConfig(), stateStore.fetchTasks(), frameworkStore.fetchFrameworkId().get(), false, Collections.emptyMap()));
    Assert.assertFalse(outcome.isPassing());
}
Also used : MesosResourcePool(com.mesosphere.sdk.offer.MesosResourcePool) Protos(org.apache.mesos.Protos) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) 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