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