use of com.mesosphere.sdk.scheduler.plan.DefaultPodInstance 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.scheduler.plan.DefaultPodInstance 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.scheduler.plan.DefaultPodInstance in project dcos-commons by mesosphere.
the class ServiceTestRunner method getTaskConfigs.
private Collection<ServiceTestResult.TaskConfig> getTaskConfigs(ServiceSpec serviceSpec, SchedulerConfig schedulerConfig) {
Collection<ServiceTestResult.TaskConfig> taskConfigs = new ArrayList<>();
for (PodSpec podSpec : serviceSpec.getPods()) {
PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
Map<String, String> customEnv = customPodEnvs.get(podSpec.getType());
for (TaskSpec taskSpec : podSpec.getTasks()) {
Map<String, String> taskEnv = getTaskEnv(serviceSpec, podInstance, taskSpec, schedulerConfig);
if (customEnv != null) {
taskEnv.putAll(customEnv);
}
for (ConfigFileSpec configFileSpec : taskSpec.getConfigFiles()) {
// If your test is failing here: did you forget to include custom values via setPodEnv()?
String content = TemplateUtils.renderMustacheThrowIfMissing(String.format("pod=%s task=%s config=%s", podSpec.getType(), taskSpec.getName(), configFileSpec.getName()), configFileSpec.getTemplateContent(), taskEnv);
taskConfigs.add(new ServiceTestResult.TaskConfig(podSpec.getType(), taskSpec.getName(), configFileSpec.getName(), content));
}
}
}
return taskConfigs;
}
use of com.mesosphere.sdk.scheduler.plan.DefaultPodInstance 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);
}
use of com.mesosphere.sdk.scheduler.plan.DefaultPodInstance in project dcos-commons by mesosphere.
the class PortEvaluationStageTest method testReadinessCheckPortEnvvarIsCorrectOnOverlay.
@Test
public void testReadinessCheckPortEnvvarIsCorrectOnOverlay() throws Exception {
DefaultPodInstance podInstance = getPodInstance("valid-port-readinesscheck-overlay.yml");
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, TaskUtils.getTaskNames(podInstance)).build();
PodInfoBuilder podInfoBuilder = getPodInfoBuilder(podInstanceRequirement, true);
Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
Protos.Offer offer = OfferTestUtils.getCompleteOffer(offeredPorts);
PortEvaluationStage portEvaluationStage = new PortEvaluationStage(getPortSpec(podInstance), TestConstants.TASK_NAME, Optional.empty(), Optional.empty());
EvaluationOutcome outcome = portEvaluationStage.evaluate(new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
Assert.assertTrue(outcome.isPassing());
Assert.assertEquals(0, outcome.getOfferRecommendations().size());
Protos.TaskInfo.Builder taskBuilder = podInfoBuilder.getTaskBuilders().stream().findFirst().get();
Assert.assertTrue(taskBuilder.getCommand().getEnvironment().getVariablesList().stream().filter(variable -> variable.getName().equals("PORT_TEST_PORT") && variable.getValue().equals("10000")).count() == 1);
Protos.CheckInfo readinessCheck = taskBuilder.hasCheck() ? taskBuilder.getCheck() : null;
Assert.assertTrue(readinessCheck != null);
Assert.assertTrue(readinessCheck.getCommand().getCommand().getEnvironment().getVariablesList().stream().filter(variable -> variable.getName().equals("PORT_TEST_PORT") && variable.getValue().equals("10000")).count() == 1);
}
Aggregations