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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations