Search in sources :

Example 6 with PodInstance

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

the class RoundRobinByHostnameRuleTest method testRolloutWithoutAgentCount.

@Test
public void testRolloutWithoutAgentCount() throws TaskException, InvalidRequirementException {
    PlacementRule rule = new RoundRobinByHostnameRule(Optional.empty(), 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 fits on any of host1/host2/host3, as we don't yet know of other valid hosts:
    assertTrue(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 fits on any of host1/host2/host3, as all known hosts have the same amount:
    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:1, host3:1
    tasks.add(getTaskInfo("3", "host2"));
    // 4th task fits on any of host1/host2/host3, as all known hosts have the same amount:
    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 new host4:
    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 new 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 7 with PodInstance

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

the class PlanUtilsTest method beforeEach.

@Before
public void beforeEach() {
    MockitoAnnotations.initMocks(this);
    PodInstance podInstance = new DefaultPodInstance(POD_SPEC, 0);
    step = new DeploymentStep(TEST_STEP_NAME, PodInstanceRequirement.newBuilder(podInstance, TaskUtils.getTaskNames(podInstance)).build(), mockStateStore);
}
Also used : PodInstance(com.mesosphere.sdk.specification.PodInstance) Before(org.junit.Before)

Example 8 with PodInstance

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

the class DefaultPhaseFactory method getSteps.

private List<Step> getSteps(PodSpec podSpec) {
    List<Step> steps = new ArrayList<>();
    for (int i = 0; i < podSpec.getCount(); i++) {
        PodInstance podInstance = new DefaultPodInstance(podSpec, i);
        List<String> tasksToLaunch = podInstance.getPod().getTasks().stream().map(taskSpec -> taskSpec.getName()).collect(Collectors.toList());
        steps.add(stepFactory.getStep(podInstance, tasksToLaunch));
    }
    return steps;
}
Also used : PodSpec(com.mesosphere.sdk.specification.PodSpec) List(java.util.List) SerialStrategy(com.mesosphere.sdk.scheduler.plan.strategy.SerialStrategy) Strategy(com.mesosphere.sdk.scheduler.plan.strategy.Strategy) PodInstance(com.mesosphere.sdk.specification.PodInstance) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) PodInstance(com.mesosphere.sdk.specification.PodInstance) ArrayList(java.util.ArrayList)

Example 9 with PodInstance

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

the class PlacementRuleEvaluationStageTest method testOfferPassesPlacementRule.

@Test
public void testOfferPassesPlacementRule() throws Exception {
    String agent = "test-agent";
    Protos.Resource offered = ResourceTestUtils.getUnreservedCpus(1.0);
    PlacementRule rule = AgentRule.require(agent);
    Protos.Offer offer = offerWithAgent(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.assertTrue(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 10 with PodInstance

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

the class TimedFailureMonitor method hasFailed.

/**
 * Determines whether the given task has failed, by tracking the time delta between the first observed failure and
 * the current time.
 * <p>
 * The first time a task is noticed to be failed, we record that time into a map, keyed by the task's {@link
 * TaskID}. Then, we return true if at least the configured amount of time has passed since then.
 *
 * @param terminatedTask The task that stopped and might be failed
 * @return true if the task has been stopped for at least the configured interval
 */
@Override
public boolean hasFailed(TaskInfo terminatedTask) {
    if (super.hasFailed(terminatedTask)) {
        return true;
    }
    Date taskLaunchedTime;
    synchronized (firstFailureDetected) {
        if (!firstFailureDetected.containsKey(terminatedTask.getTaskId())) {
            firstFailureDetected.put(terminatedTask.getTaskId(), new Date());
        }
        taskLaunchedTime = firstFailureDetected.get(terminatedTask.getTaskId());
    }
    Date taskExpiredTime = new Date(taskLaunchedTime.getTime() + durationUntilFailed.toMillis());
    Date now = new Date();
    log.info("Looking at " + terminatedTask.getName() + " launchHappened at " + taskLaunchedTime + ", expires at " + taskExpiredTime + " which is " + now.after(taskExpiredTime));
    if (now.after(taskExpiredTime)) {
        try {
            PodInstance podInstance = TaskUtils.getPodInstance(configStore, terminatedTask);
            FailureUtils.setPermanentlyFailed(stateStore, podInstance);
        } catch (TaskException e) {
            log.error("Failed to get pod instance to mark as failed.", e);
        }
    }
    return super.hasFailed(terminatedTask);
}
Also used : TaskException(com.mesosphere.sdk.offer.TaskException) PodInstance(com.mesosphere.sdk.specification.PodInstance) Date(java.util.Date)

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