use of com.mesosphere.sdk.specification.PodSpec 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.PodSpec 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.specification.PodSpec 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.specification.PodSpec in project dcos-commons by mesosphere.
the class RoundRobinByHostnameRuleTest method getPodInstance.
private static PodInstance getPodInstance(TaskInfo taskInfo) {
try {
TaskLabelReader labels = new TaskLabelReader(taskInfo);
ResourceSet resourceSet = PodInstanceRequirementTestUtils.getCpuResourceSet(1.0);
PodSpec podSpec = PodInstanceRequirementTestUtils.getRequirement(resourceSet, labels.getType(), labels.getIndex()).getPodInstance().getPod();
return new DefaultPodInstance(podSpec, labels.getIndex());
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
use of com.mesosphere.sdk.specification.PodSpec in project dcos-commons by mesosphere.
the class DefaultConfigurationUpdater method needsConfigUpdate.
private static boolean needsConfigUpdate(Protos.TaskInfo taskInfo, ServiceSpec targetConfig, ServiceSpec taskConfig) {
if (targetConfig.equals(taskConfig)) {
LOGGER.info("Task '{}' is up to date: Task's target ServiceSpec matches the current ServiceSpec", taskInfo.getName());
return false;
}
final String podType;
final boolean isPermanentlyFailed;
try {
TaskLabelReader reader = new TaskLabelReader(taskInfo);
podType = reader.getType();
isPermanentlyFailed = reader.isPermanentlyFailed();
} catch (TaskException e) {
LOGGER.error(String.format("Unable to extract pod type from task '%s'. Will assume the task needs a configuration update", taskInfo.getName()), e);
return true;
}
// to transition from their former config to the new target.
if (isPermanentlyFailed) {
return false;
}
Optional<PodSpec> targetSpecOptional = getPodSpec(targetConfig, podType);
Optional<PodSpec> taskSpecOptional = getPodSpec(taskConfig, podType);
if (!targetSpecOptional.isPresent() || !taskSpecOptional.isPresent()) {
LOGGER.info("Task '{}' needs a configuration update: " + "PodSpec '{}' was {} in task's config, but is {} in current target config", taskInfo.getName(), podType, taskSpecOptional.isPresent() ? "present" : "missing", targetSpecOptional.isPresent() ? "present" : "missing");
return true;
}
boolean updateNeeded = !areMatching(targetSpecOptional.get(), taskSpecOptional.get());
if (updateNeeded) {
LOGGER.info("Task '{}' needs a configuration update: PodSpec '{}' has changed", taskInfo.getName(), podType);
} else {
LOGGER.info("Task '{}' is up to date: PodSpec '{}' is the same", taskInfo.getName(), podType);
}
return updateNeeded;
}
Aggregations