use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.
the class TaskUtilsTest method testRelaunchFailedNonEssentialTaskInMixedPod.
@Test
public void testRelaunchFailedNonEssentialTaskInMixedPod() throws ConfigStoreException {
// layout: 3 'server' pod instances, each with 2 essential + 2 nonessential tasks
// failed: server-0-nonessential0, server-0-nonessential1, server-1-nonessential1
List<PodInstanceRequirement> reqs = TaskUtils.getPodRequirements(TWO_ESSENTIAL_TWO_NONESSENTIAL, filterTasksByName(TWO_ESSENTIAL_TWO_NONESSENTIAL_TASKS, "server-0-nonessential0", "server-0-nonessential1", "server-1-nonessential1"), TWO_ESSENTIAL_TWO_NONESSENTIAL_TASKS);
Assert.assertEquals(2, reqs.size());
PodInstanceRequirement req = reqs.get(0);
Assert.assertEquals("server-0:[nonessential0, nonessential1]", req.getName());
Assert.assertEquals(Arrays.asList("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 TaskUtilsTest method testRelaunchFailedEssentialTasksInEssentialPod.
@Test
public void testRelaunchFailedEssentialTasksInEssentialPod() throws ConfigStoreException {
// layout: 3 'server' pod instances, each with 2 essential tasks (only)
// failed: server-0-essential0, server-0-essential1, server-1-essential1
List<PodInstanceRequirement> reqs = TaskUtils.getPodRequirements(TWO_ESSENTIAL, filterTasksByName(TWO_ESSENTIAL_TASKS, "server-0-essential0", "server-0-essential1", "server-1-essential1"), TWO_ESSENTIAL_TASKS);
Assert.assertEquals(reqs.toString(), 2, reqs.size());
PodInstanceRequirement req = reqs.get(0);
Assert.assertEquals("server-0:[essential0, essential1]", req.getName());
Assert.assertEquals(Arrays.asList("essential0", "essential1"), req.getTasksToLaunch());
req = reqs.get(1);
Assert.assertEquals("server-1:[essential0, essential1]", req.getName());
Assert.assertEquals(Arrays.asList("essential0", "essential1"), req.getTasksToLaunch());
}
use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.
the class OfferEvaluator method evaluate.
public List<OfferRecommendation> evaluate(PodInstanceRequirement podInstanceRequirement, List<Protos.Offer> offers) throws InvalidRequirementException, IOException {
// All tasks in the service (used by some PlacementRules):
Map<String, Protos.TaskInfo> allTasks = stateStore.fetchTasks().stream().collect(Collectors.toMap(Protos.TaskInfo::getName, Function.identity()));
// Preexisting tasks for this pod (if any):
Map<String, Protos.TaskInfo> thisPodTasks = TaskUtils.getTaskNames(podInstanceRequirement.getPodInstance()).stream().map(taskName -> allTasks.get(taskName)).filter(taskInfo -> taskInfo != null).collect(Collectors.toMap(Protos.TaskInfo::getName, Function.identity()));
for (int i = 0; i < offers.size(); ++i) {
List<OfferEvaluationStage> evaluationStages = getEvaluationPipeline(podInstanceRequirement, allTasks.values(), thisPodTasks);
Protos.Offer offer = offers.get(i);
MesosResourcePool resourcePool = new MesosResourcePool(offer, OfferEvaluationUtils.getRole(podInstanceRequirement.getPodInstance().getPod()));
Map<TaskSpec, GoalStateOverride> overrideMap = new HashMap<>();
for (TaskSpec taskSpec : podInstanceRequirement.getPodInstance().getPod().getTasks()) {
GoalStateOverride override = stateStore.fetchGoalOverrideStatus(TaskSpec.getInstanceName(podInstanceRequirement.getPodInstance(), taskSpec)).target;
overrideMap.put(taskSpec, override);
}
PodInfoBuilder podInfoBuilder = new PodInfoBuilder(podInstanceRequirement, serviceName, getTargetConfig(podInstanceRequirement, thisPodTasks.values()), templateUrlFactory, schedulerConfig, thisPodTasks.values(), frameworkStore.fetchFrameworkId().get(), useDefaultExecutor, overrideMap);
List<EvaluationOutcome> outcomes = new ArrayList<>();
int failedOutcomeCount = 0;
for (OfferEvaluationStage evaluationStage : evaluationStages) {
EvaluationOutcome outcome = evaluationStage.evaluate(resourcePool, podInfoBuilder);
outcomes.add(outcome);
if (!outcome.isPassing()) {
failedOutcomeCount++;
}
}
StringBuilder outcomeDetails = new StringBuilder();
for (EvaluationOutcome outcome : outcomes) {
logOutcome(outcomeDetails, outcome, "");
}
if (outcomeDetails.length() != 0) {
// trim extra trailing newline:
outcomeDetails.deleteCharAt(outcomeDetails.length() - 1);
}
if (failedOutcomeCount != 0) {
logger.info("Offer {}, {}: failed {} of {} evaluation stages:\n{}", i + 1, offer.getId().getValue(), failedOutcomeCount, evaluationStages.size(), outcomeDetails.toString());
offerOutcomeTracker.track(new OfferOutcome(podInstanceRequirement.getName(), false, offer, outcomeDetails.toString()));
} else {
List<OfferRecommendation> recommendations = outcomes.stream().map(outcome -> outcome.getOfferRecommendations()).flatMap(xs -> xs.stream()).collect(Collectors.toList());
logger.info("Offer {}: passed all {} evaluation stages, returning {} recommendations:\n{}", i + 1, evaluationStages.size(), recommendations.size(), outcomeDetails.toString());
offerOutcomeTracker.track(new OfferOutcome(podInstanceRequirement.getName(), true, offer, outcomeDetails.toString()));
return recommendations;
}
}
return Collections.emptyList();
}
use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.
the class OfferEvaluatorVolumesTest method testExpectedRootVolume.
@Test
public void testExpectedRootVolume() throws Exception {
// Launch for the first time.
Resource offeredCpuResource = ResourceTestUtils.getUnreservedCpus(1.0);
Resource offeredDiskResource = ResourceTestUtils.getUnreservedDisk(2000);
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getRootVolumeRequirement(1.0, 1500);
List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getCompleteOffer(Arrays.asList(offeredDiskResource, offeredCpuResource))));
String cpuResourceId = ResourceTestUtils.getResourceId(recommendations.get(0).getOperation().getReserve().getResources(0));
Operation createOperation = recommendations.get(2).getOperation();
Resource createResource = createOperation.getCreate().getVolumes(0);
String diskResourceId = ResourceTestUtils.getResourceId(createResource);
String persistenceId = ResourceTestUtils.getPersistenceId(createResource);
String executorCpuResourceId = ResourceTestUtils.getResourceId(recommendations.get(3).getOperation().getReserve().getResources(0));
String executorMemResourceId = ResourceTestUtils.getResourceId(recommendations.get(4).getOperation().getReserve().getResources(0));
String executorDiskResourceId = ResourceTestUtils.getResourceId(recommendations.get(5).getOperation().getReserve().getResources(0));
Operation launchOperation = recommendations.get(recommendations.size() - 1).getOperation();
Protos.ExecutorInfo executorInfo = launchOperation.getLaunchGroup().getExecutor();
Collection<Protos.TaskInfo> taskInfos = launchOperation.getLaunchGroup().getTaskGroup().getTasksList().stream().map(t -> t.toBuilder().setExecutor(executorInfo).build()).collect(Collectors.toList());
stateStore.storeTasks(taskInfos);
// Launch again on expected resources.
Resource expectedCpu = ResourceTestUtils.getReservedCpus(1.0, cpuResourceId);
Resource expectedDisk = ResourceTestUtils.getReservedRootVolume(1500, diskResourceId, persistenceId);
Resource expectedExecutorCpu = ResourceTestUtils.getReservedCpus(0.1, executorCpuResourceId);
Resource expectedExecutorMem = ResourceTestUtils.getReservedMem(32, executorMemResourceId);
Resource expectedExecutorDisk = ResourceTestUtils.getReservedDisk(256, executorDiskResourceId);
recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getOffer(Arrays.asList(expectedCpu, expectedDisk, expectedExecutorCpu, expectedExecutorMem, expectedExecutorDisk))));
Assert.assertEquals(1, recommendations.size());
launchOperation = recommendations.get(0).getOperation();
Protos.TaskInfo launchTask = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0);
Assert.assertEquals(recommendations.toString(), 2, launchTask.getResourcesCount());
Resource launchResource = launchTask.getResources(1);
Resource.ReservationInfo reservation = ResourceUtils.getReservation(launchResource).get();
Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType());
Assert.assertEquals(1500, launchResource.getScalar().getValue(), 0.0);
OfferEvaluatorTest.validateRole(launchResource);
Assert.assertEquals(TestConstants.ROLE, ResourceUtils.getRole(launchResource));
Assert.assertEquals(persistenceId, launchResource.getDisk().getPersistence().getId());
Assert.assertEquals(TestConstants.PRINCIPAL, launchResource.getDisk().getPersistence().getPrincipal());
Assert.assertEquals(TestConstants.PRINCIPAL, reservation.getPrincipal());
Assert.assertEquals(diskResourceId, getResourceId(launchResource));
}
use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement 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);
}
Aggregations