use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.
the class DefaultPlanGeneratorTest method validatePhase.
private void validatePhase(Phase phase, List<List<String>> stepTasks) {
Assert.assertEquals(phase.getChildren().size(), stepTasks.size());
for (int i = 0; i < stepTasks.size(); i++) {
PodInstanceRequirement podInstanceRequirement = phase.getChildren().get(i).start().get();
List<String> tasksToLaunch = new ArrayList<>(podInstanceRequirement.getTasksToLaunch());
for (int j = 0; j < tasksToLaunch.size(); j++) {
Assert.assertEquals(tasksToLaunch.get(j), stepTasks.get(i).get(j));
}
}
}
use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.
the class CassandraRecoveryPlanOverriderTest method replaceSeed.
@Test
public void replaceSeed() throws Exception {
int nonSeedIndex = 1;
String taskName = "node-" + nonSeedIndex + "-server";
StateStoreUtils.storeTaskStatusAsProperty(stateStore, taskName, getFailedTaskStatus(taskName));
PodInstanceRequirement podInstanceRequirement = getReplacePodInstanceRequirement(nonSeedIndex);
Optional<Phase> phase = planOverrider.override(podInstanceRequirement);
Assert.assertTrue(phase.isPresent());
Assert.assertEquals(3, phase.get().getChildren().size());
Assert.assertEquals(RecoveryType.PERMANENT, phase.get().getChildren().get(0).getPodInstanceRequirement().get().getRecoveryType());
Assert.assertEquals(RecoveryType.TRANSIENT, phase.get().getChildren().get(1).getPodInstanceRequirement().get().getRecoveryType());
Assert.assertEquals(RecoveryType.TRANSIENT, phase.get().getChildren().get(2).getPodInstanceRequirement().get().getRecoveryType());
}
use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement 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.PodInstanceRequirement in project dcos-commons by mesosphere.
the class PortEvaluationStageTest method testPortResourceIsIgnoredOnOverlay.
@Test
public void testPortResourceIsIgnoredOnOverlay() throws Exception {
Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
Protos.Offer offer = OfferTestUtils.getOffer(offeredPorts);
// request a port that's not available in the offer.
Integer requestedPort = 80;
String expectedPortEnvVar = "PORT_TEST_IGNORED";
String expectedPortName = "overlay-port-name";
PortSpec portSpec = new PortSpec(getPort(requestedPort), TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL, expectedPortEnvVar, expectedPortName, TestConstants.PORT_VISIBILITY, getOverlayNetworkNames());
PodInstanceRequirement podInstanceRequirement = getPodInstanceRequirement(portSpec);
PodInfoBuilder podInfoBuilder = getPodInfoBuilder(podInstanceRequirement, true);
PortEvaluationStage portEvaluationStage = new PortEvaluationStage(portSpec, 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.getTaskBuilder(TestConstants.TASK_NAME);
checkDiscoveryInfo(taskBuilder.getDiscovery(), expectedPortName, 80);
Assert.assertTrue("TaskInfo builder missing DiscoveryInfo", taskBuilder.hasDiscovery());
Assert.assertEquals(0, taskBuilder.getResourcesCount());
List<Protos.Environment.Variable> portEnvVars = taskBuilder.getCommand().getEnvironment().getVariablesList().stream().filter(variable -> variable.getName().equals(expectedPortEnvVar)).collect(Collectors.toList());
Assert.assertEquals(1, portEnvVars.size());
Protos.Environment.Variable variable = portEnvVars.get(0);
Assert.assertEquals(variable.getName(), expectedPortEnvVar);
Assert.assertEquals(variable.getValue(), requestedPort.toString());
}
use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.
the class PortEvaluationStageTest method testDynamicPortResourceOnOverlayAndRequestedPort.
@Test
public void testDynamicPortResourceOnOverlayAndRequestedPort() throws Exception {
Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
Protos.Offer offer = OfferTestUtils.getOffer(offeredPorts);
Integer expectedExplicitOverlayPort = DcosConstants.OVERLAY_DYNAMIC_PORT_RANGE_START;
Integer expectedDynamicOverlayPort = DcosConstants.OVERLAY_DYNAMIC_PORT_RANGE_START + 1;
String expectedExplicitOverlayPortEnvvar = "PORT_TEST_EXPLICIT";
String expextedDynamicOverlayPortEnvvar = "PORT_TEST_DYNAMIC";
String expectedExplicitPortName = "explicit-port";
String expectedDynamicPortName = "dynamic-port";
PortSpec portSpec = new PortSpec(getPort(DcosConstants.OVERLAY_DYNAMIC_PORT_RANGE_START), TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL, expectedExplicitOverlayPortEnvvar, expectedExplicitPortName, TestConstants.PORT_VISIBILITY, getOverlayNetworkNames());
PortSpec dynamPortSpec = new PortSpec(getPort(0), TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL, expextedDynamicOverlayPortEnvvar, expectedDynamicPortName, TestConstants.PORT_VISIBILITY, getOverlayNetworkNames());
PodInstanceRequirement podInstanceRequirement = getPodInstanceRequirement(portSpec, dynamPortSpec);
PodInfoBuilder podInfoBuilder = getPodInfoBuilder(podInstanceRequirement, true);
Assert.assertTrue(String.format("podInfoBuilder has incorrect number of pre-assigned overlay ports " + "should be 1, got %s", podInfoBuilder.getAssignedOverlayPorts().size()), podInfoBuilder.getAssignedOverlayPorts().size() == 1);
PortEvaluationStage portEvaluationStage_ = new PortEvaluationStage(portSpec, TestConstants.TASK_NAME, Optional.empty(), Optional.empty());
EvaluationOutcome outcome0 = portEvaluationStage_.evaluate(new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
Assert.assertTrue(outcome0.isPassing());
Assert.assertEquals(0, outcome0.getOfferRecommendations().size());
PortEvaluationStage portEvaluationStage = new PortEvaluationStage(dynamPortSpec, TestConstants.TASK_NAME, Optional.empty(), Optional.empty());
EvaluationOutcome outcome1 = portEvaluationStage.evaluate(new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
Assert.assertTrue(outcome1.isPassing());
Assert.assertEquals(0, outcome1.getOfferRecommendations().size());
Assert.assertTrue(String.format("podInfoBuilder has incorrect number of assigned overlay ports, " + "should be 2 got %s", podInfoBuilder.getAssignedOverlayPorts().size()), podInfoBuilder.getAssignedOverlayPorts().size() == 2);
Protos.TaskInfo.Builder taskBuilder = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME);
checkDiscoveryInfo(taskBuilder.getDiscovery(), expectedExplicitPortName, expectedExplicitOverlayPort);
checkDiscoveryInfo(taskBuilder.getDiscovery(), expectedDynamicPortName, expectedDynamicOverlayPort);
Assert.assertEquals(0, taskBuilder.getResourcesCount());
Map<String, String> portEnvVarMap = taskBuilder.getCommand().getEnvironment().getVariablesList().stream().filter(variable -> variable.getName().equals(expectedExplicitOverlayPortEnvvar) || variable.getName().equals(expextedDynamicOverlayPortEnvvar)).collect(Collectors.toMap(Protos.Environment.Variable::getName, Protos.Environment.Variable::getValue));
Assert.assertEquals(2, portEnvVarMap.size());
Assert.assertTrue(portEnvVarMap.containsKey(expectedExplicitOverlayPortEnvvar));
Assert.assertTrue(portEnvVarMap.containsKey(expextedDynamicOverlayPortEnvvar));
Assert.assertTrue(portEnvVarMap.get(expectedExplicitOverlayPortEnvvar).equals(expectedExplicitOverlayPort.toString()));
Assert.assertTrue(portEnvVarMap.get(expextedDynamicOverlayPortEnvvar).equals(expectedDynamicOverlayPort.toString()));
}
Aggregations