Search in sources :

Example 31 with PodInstanceRequirement

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());
}
Also used : PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) Test(org.junit.Test)

Example 32 with PodInstanceRequirement

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());
}
Also used : PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) Test(org.junit.Test)

Example 33 with PodInstanceRequirement

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();
}
Also used : OfferOutcomeTracker(com.mesosphere.sdk.offer.history.OfferOutcomeTracker) Protos(org.apache.mesos.Protos) SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig) java.util(java.util) com.mesosphere.sdk.offer(com.mesosphere.sdk.offer) Logger(org.slf4j.Logger) IOException(java.io.IOException) RecoveryType(com.mesosphere.sdk.scheduler.recovery.RecoveryType) TaskLabelReader(com.mesosphere.sdk.offer.taskdata.TaskLabelReader) ArtifactQueries(com.mesosphere.sdk.http.queries.ArtifactQueries) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) com.mesosphere.sdk.specification(com.mesosphere.sdk.specification) StateStore(com.mesosphere.sdk.state.StateStore) GoalStateOverride(com.mesosphere.sdk.state.GoalStateOverride) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FailureUtils(com.mesosphere.sdk.scheduler.recovery.FailureUtils) TextFormat(com.google.protobuf.TextFormat) OfferOutcome(com.mesosphere.sdk.offer.history.OfferOutcome) FrameworkStore(com.mesosphere.sdk.state.FrameworkStore) GoalStateOverride(com.mesosphere.sdk.state.GoalStateOverride) OfferOutcome(com.mesosphere.sdk.offer.history.OfferOutcome) Protos(org.apache.mesos.Protos)

Example 34 with PodInstanceRequirement

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));
}
Also used : Protos(org.apache.mesos.Protos) Arrays(java.util.Arrays) TestConstants(com.mesosphere.sdk.testutils.TestConstants) Collection(java.util.Collection) Operation(org.apache.mesos.Protos.Offer.Operation) PodInstanceRequirementTestUtils(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirementTestUtils) Test(org.junit.Test) OfferTestUtils(com.mesosphere.sdk.testutils.OfferTestUtils) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Collectors(java.util.stream.Collectors) Resource(org.apache.mesos.Protos.Resource) ResourceSet(com.mesosphere.sdk.specification.ResourceSet) Capabilities(com.mesosphere.sdk.dcos.Capabilities) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) List(java.util.List) ResourceRefinementCapabilityContext(com.mesosphere.sdk.dcos.ResourceRefinementCapabilityContext) DefaultVolumeSpec(com.mesosphere.sdk.specification.DefaultVolumeSpec) VolumeSpec(com.mesosphere.sdk.specification.VolumeSpec) ResourceUtils(com.mesosphere.sdk.offer.ResourceUtils) DefaultResourceSet(com.mesosphere.sdk.specification.DefaultResourceSet) Constants(com.mesosphere.sdk.offer.Constants) Assert(org.junit.Assert) ResourceTestUtils(com.mesosphere.sdk.testutils.ResourceTestUtils) 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) Protos(org.apache.mesos.Protos) Test(org.junit.Test)

Example 35 with PodInstanceRequirement

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

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