use of com.mesosphere.sdk.scheduler.plan.DefaultPodInstance in project dcos-commons by mesosphere.
the class PortEvaluationStageTest method getPodInstanceRequirement.
private PodInstanceRequirement getPodInstanceRequirement(PortSpec... portSpecs) {
// Build Pod
ResourceSet resourceSet = DefaultResourceSet.newBuilder(TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL).id("resourceSet").cpus(1.0).addResource(Arrays.asList(portSpecs)).build();
CommandSpec commandSpec = DefaultCommandSpec.newBuilder(Collections.emptyMap()).value("./cmd").build();
TaskSpec taskSpec = DefaultTaskSpec.newBuilder().name(TestConstants.TASK_NAME).commandSpec(commandSpec).goalState(GoalState.RUNNING).resourceSet(resourceSet).build();
PodSpec podSpec = DefaultPodSpec.newBuilder("executor-uri").addTask(taskSpec).count(1).type(TestConstants.POD_TYPE).build();
PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
return PodInstanceRequirement.newBuilder(podInstance, Arrays.asList(TestConstants.TASK_NAME)).build();
}
use of com.mesosphere.sdk.scheduler.plan.DefaultPodInstance in project dcos-commons by mesosphere.
the class PortEvaluationStageTest method testPortEnvvarOnReadinessCheckCustomExecutor.
@Test
public void testPortEnvvarOnReadinessCheckCustomExecutor() throws Exception {
DefaultPodInstance podInstance = getPodInstance("valid-port-readinesscheck.yml");
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, TaskUtils.getTaskNames(podInstance)).build();
PodInfoBuilder podInfoBuilder = getPodInfoBuilder(podInstanceRequirement, false);
Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
Protos.Offer offer = OfferTestUtils.getOffer(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(1, outcome.getOfferRecommendations().size());
OfferRecommendation recommendation = outcome.getOfferRecommendations().iterator().next();
Assert.assertEquals(Protos.Offer.Operation.Type.RESERVE, recommendation.getOperation().getType());
Protos.Resource resource = recommendation.getOperation().getReserve().getResources(0);
Assert.assertEquals(10000, resource.getRanges().getRange(0).getBegin(), resource.getRanges().getRange(0).getEnd());
Protos.TaskInfo.Builder taskBuilder = podInfoBuilder.getTaskBuilders().stream().findFirst().get();
boolean portInTaskEnv = false;
for (int i = 0; i < taskBuilder.getCommand().getEnvironment().getVariablesCount(); i++) {
Protos.Environment.Variable variable = taskBuilder.getCommand().getEnvironment().getVariables(i);
if (Objects.equals(variable.getName(), "PORT_TEST_PORT")) {
Assert.assertEquals(variable.getValue(), "10000");
portInTaskEnv = true;
}
}
Assert.assertTrue(portInTaskEnv);
}
use of com.mesosphere.sdk.scheduler.plan.DefaultPodInstance in project dcos-commons by mesosphere.
the class CassandraRecoveryPlanOverriderTest method getPodInstanceRequirement.
private PodInstanceRequirement getPodInstanceRequirement(int nodeIndex, RecoveryType recoveryType) throws Exception {
PodSpec podSpec = serviceSpec.getPods().get(0);
PodInstance podInstance = new DefaultPodInstance(podSpec, nodeIndex);
return PodInstanceRequirement.newBuilder(podInstance, Arrays.asList("server")).recoveryType(recoveryType).build();
}
use of com.mesosphere.sdk.scheduler.plan.DefaultPodInstance in project dcos-commons by mesosphere.
the class PortEvaluationStageTest method testPortEnvvarOnHealthCheck.
@Test
public void testPortEnvvarOnHealthCheck() throws Exception {
DefaultPodInstance podInstance = getPodInstance("valid-port-healthcheck.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(1, outcome.getOfferRecommendations().size());
OfferRecommendation recommendation = outcome.getOfferRecommendations().iterator().next();
Assert.assertEquals(Protos.Offer.Operation.Type.RESERVE, recommendation.getOperation().getType());
Protos.Resource resource = recommendation.getOperation().getReserve().getResources(0);
Assert.assertEquals(10000, resource.getRanges().getRange(0).getBegin(), resource.getRanges().getRange(0).getEnd());
Protos.TaskInfo.Builder taskBuilder = podInfoBuilder.getTaskBuilders().stream().findFirst().get();
boolean portInTaskEnv = false;
for (int i = 0; i < taskBuilder.getCommand().getEnvironment().getVariablesCount(); i++) {
Protos.Environment.Variable variable = taskBuilder.getCommand().getEnvironment().getVariables(i);
if (Objects.equals(variable.getName(), "PORT_TEST_PORT")) {
Assert.assertEquals(variable.getValue(), "10000");
portInTaskEnv = true;
}
}
Assert.assertTrue(portInTaskEnv);
boolean portInHealthEnv = false;
for (int i = 0; i < taskBuilder.getHealthCheck().getCommand().getEnvironment().getVariablesCount(); i++) {
Protos.Environment.Variable variable = taskBuilder.getHealthCheck().getCommand().getEnvironment().getVariables(i);
if (Objects.equals(variable.getName(), "PORT_TEST_PORT")) {
Assert.assertEquals(variable.getValue(), "10000");
portInHealthEnv = true;
}
}
Assert.assertTrue(portInHealthEnv);
}
use of com.mesosphere.sdk.scheduler.plan.DefaultPodInstance in project dcos-commons by mesosphere.
the class RoundRobinByAttributeRuleTest 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);
}
}
Aggregations