Search in sources :

Example 36 with PodInstanceRequirement

use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement 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);
}
Also used : Protos(org.apache.mesos.Protos) SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig) java.util(java.util) com.mesosphere.sdk.offer(com.mesosphere.sdk.offer) TestPlacementUtils(com.mesosphere.sdk.offer.evaluate.placement.TestPlacementUtils) com.mesosphere.sdk.testutils(com.mesosphere.sdk.testutils) Test(org.junit.Test) ArtifactResource(com.mesosphere.sdk.http.endpoints.ArtifactResource) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) Collectors(java.util.stream.Collectors) File(java.io.File) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) com.mesosphere.sdk.specification(com.mesosphere.sdk.specification) Assert(org.junit.Assert) DcosConstants(com.mesosphere.sdk.dcos.DcosConstants) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) Protos(org.apache.mesos.Protos) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) Test(org.junit.Test)

Example 37 with PodInstanceRequirement

use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement 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);
}
Also used : PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) Protos(org.apache.mesos.Protos) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) Test(org.junit.Test)

Example 38 with PodInstanceRequirement

use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.

the class OfferEvaluatorVolumesTest method testRelaunchExecutorVolumeFailure.

@Test
public void testRelaunchExecutorVolumeFailure() throws Exception {
    // Create for the first time.
    List<Resource> offeredResources = Arrays.asList(ResourceTestUtils.getUnreservedMountVolume(2000), ResourceTestUtils.getUnreservedCpus(1.0));
    Protos.Offer offer = OfferTestUtils.getCompleteOffer(offeredResources);
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getExecutorRequirement(PodInstanceRequirementTestUtils.getCpuResourceSet(1.0), Arrays.asList(new DefaultVolumeSpec(1000, VolumeSpec.Type.MOUNT, TestConstants.CONTAINER_PATH, TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL)), TestConstants.POD_TYPE, 0);
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(offer));
    Assert.assertEquals(7, recommendations.size());
    // Validate RESERVE Operation
    Operation reserveOperation = recommendations.get(0).getOperation();
    Resource reserveResource = reserveOperation.getReserve().getResources(0);
    String resourceId = getResourceId(reserveResource);
    // Validate CREATE Operation
    Operation createOperation = recommendations.get(1).getOperation();
    Resource createResource = createOperation.getCreate().getVolumes(0);
    String persistenceId = createResource.getDisk().getPersistence().getId();
    // Evaluation for a second time
    offeredResources = Arrays.asList(ResourceTestUtils.getReservedMountVolume(2000, resourceId, persistenceId), ResourceTestUtils.getReservedCpus(1.0, resourceId));
    offer = OfferTestUtils.getCompleteOffer(offeredResources);
    recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(offer));
    Assert.assertEquals(0, recommendations.size());
}
Also used : Protos(org.apache.mesos.Protos) Resource(org.apache.mesos.Protos.Resource) DefaultVolumeSpec(com.mesosphere.sdk.specification.DefaultVolumeSpec) Operation(org.apache.mesos.Protos.Offer.Operation) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 39 with PodInstanceRequirement

use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.

the class OfferEvaluatorVolumesTest method testExpectedMountVolume.

@Test
public void testExpectedMountVolume() throws Exception {
    // Launch for the first time.
    Resource offeredCpuResource = ResourceTestUtils.getUnreservedCpus(1.0);
    Resource offeredDiskResource = ResourceTestUtils.getUnreservedMountVolume(2000);
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getMountVolumeRequirement(1.0, 1500);
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getCompleteOffer(Arrays.asList(offeredDiskResource, offeredCpuResource))));
    String cpuResourceId = ResourceTestUtils.getResourceId(recommendations.get(0).getOperation().getReserve().getResources(0));
    Resource createResource = recommendations.get(2).getOperation().getCreate().getVolumes(0);
    String executorCpuResourceId = ResourceTestUtils.getResourceId(recommendations.get(3).getOperation().getReserve().getResources(0));
    String executorMemResourceId = ResourceTestUtils.getResourceId(recommendations.get(4).getOperation().getReserve().getResources(0));
    String executorDiskResourceId = ResourceTestUtils.getResourceId(recommendations.get(5).getOperation().getReserve().getResources(0));
    String diskResourceId = ResourceTestUtils.getResourceId(createResource);
    String persistenceId = ResourceTestUtils.getPersistenceId(createResource);
    Operation launchOperation = recommendations.get(recommendations.size() - 1).getOperation();
    Protos.ExecutorInfo executorInfo = launchOperation.getLaunchGroup().getExecutor();
    Collection<Protos.TaskInfo> taskInfos = launchOperation.getLaunchGroup().getTaskGroup().getTasksList().stream().map(t -> t.toBuilder().setExecutor(executorInfo).build()).collect(Collectors.toList());
    stateStore.storeTasks(taskInfos);
    // Launch again on expected resources.
    Resource expectedCpu = ResourceTestUtils.getReservedCpus(1.0, cpuResourceId);
    Resource expectedDisk = ResourceTestUtils.getReservedMountVolume(2000, diskResourceId, persistenceId);
    Resource expectedExecutorCpu = ResourceTestUtils.getReservedCpus(0.1, executorCpuResourceId);
    Resource expectedExecutorMem = ResourceTestUtils.getReservedMem(32, executorMemResourceId);
    Resource expectedExecutorDisk = ResourceTestUtils.getReservedDisk(256, executorDiskResourceId);
    recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getCompleteOffer(Arrays.asList(expectedCpu, expectedDisk, expectedExecutorCpu, expectedExecutorMem, expectedExecutorDisk))));
    Assert.assertEquals(1, recommendations.size());
    launchOperation = recommendations.get(0).getOperation();
    Protos.TaskInfo launchTask = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0);
    Assert.assertEquals(recommendations.toString(), 2, launchTask.getResourcesCount());
    Resource launchResource = launchTask.getResources(1);
    Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType());
    Assert.assertEquals(2000, launchResource.getScalar().getValue(), 0.0);
    OfferEvaluatorTest.validateRole(launchResource);
    Assert.assertEquals(TestConstants.ROLE, ResourceUtils.getRole(launchResource));
    Assert.assertEquals(TestConstants.MOUNT_ROOT, launchResource.getDisk().getSource().getMount().getRoot());
    Assert.assertEquals(persistenceId, launchResource.getDisk().getPersistence().getId());
    Assert.assertEquals(TestConstants.PRINCIPAL, launchResource.getDisk().getPersistence().getPrincipal());
    validatePrincipal(launchResource);
    Assert.assertEquals(diskResourceId, getResourceId(launchResource));
}
Also used : Protos(org.apache.mesos.Protos) Arrays(java.util.Arrays) TestConstants(com.mesosphere.sdk.testutils.TestConstants) Collection(java.util.Collection) Operation(org.apache.mesos.Protos.Offer.Operation) PodInstanceRequirementTestUtils(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirementTestUtils) Test(org.junit.Test) OfferTestUtils(com.mesosphere.sdk.testutils.OfferTestUtils) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Collectors(java.util.stream.Collectors) Resource(org.apache.mesos.Protos.Resource) ResourceSet(com.mesosphere.sdk.specification.ResourceSet) Capabilities(com.mesosphere.sdk.dcos.Capabilities) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) List(java.util.List) ResourceRefinementCapabilityContext(com.mesosphere.sdk.dcos.ResourceRefinementCapabilityContext) DefaultVolumeSpec(com.mesosphere.sdk.specification.DefaultVolumeSpec) VolumeSpec(com.mesosphere.sdk.specification.VolumeSpec) ResourceUtils(com.mesosphere.sdk.offer.ResourceUtils) DefaultResourceSet(com.mesosphere.sdk.specification.DefaultResourceSet) Constants(com.mesosphere.sdk.offer.Constants) Assert(org.junit.Assert) ResourceTestUtils(com.mesosphere.sdk.testutils.ResourceTestUtils) Protos(org.apache.mesos.Protos) Resource(org.apache.mesos.Protos.Resource) Operation(org.apache.mesos.Protos.Offer.Operation) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 40 with PodInstanceRequirement

use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.

the class OfferEvaluatorVolumesTest method testReserveCreateExecutorVolume.

@Test
public void testReserveCreateExecutorVolume() throws Exception {
    List<Resource> offeredResources = Arrays.asList(ResourceTestUtils.getUnreservedMountVolume(2000), ResourceTestUtils.getUnreservedCpus(1.0));
    Protos.Offer offer = OfferTestUtils.getCompleteOffer(offeredResources);
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getExecutorRequirement(PodInstanceRequirementTestUtils.getCpuResourceSet(1.0), Arrays.asList(new DefaultVolumeSpec(1000, VolumeSpec.Type.MOUNT, TestConstants.CONTAINER_PATH, TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL)), TestConstants.POD_TYPE, 0);
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(offer));
    Assert.assertEquals(7, recommendations.size());
    // Validate just the operations pertaining to the executor
    // Validate RESERVE Operation
    Operation reserveOperation = recommendations.get(0).getOperation();
    Resource reserveResource = reserveOperation.getReserve().getResources(0);
    Assert.assertEquals(Operation.Type.RESERVE, reserveOperation.getType());
    Assert.assertEquals(2000, reserveResource.getScalar().getValue(), 0.0);
    OfferEvaluatorTest.validateRole(reserveResource);
    Assert.assertEquals(TestConstants.ROLE, ResourceUtils.getRole(reserveResource));
    Assert.assertEquals(TestConstants.MOUNT_ROOT, reserveResource.getDisk().getSource().getMount().getRoot());
    validatePrincipal(reserveResource);
    Assert.assertEquals(36, getResourceId(reserveResource).length());
    // Validate CREATE Operation
    String resourceId = getResourceId(reserveResource);
    Operation createOperation = recommendations.get(1).getOperation();
    Resource createResource = createOperation.getCreate().getVolumes(0);
    Assert.assertEquals(resourceId, getResourceId(createResource));
    Assert.assertEquals(36, createResource.getDisk().getPersistence().getId().length());
    Assert.assertEquals(TestConstants.MOUNT_ROOT, createResource.getDisk().getSource().getMount().getRoot());
    Assert.assertEquals(TestConstants.PRINCIPAL, createResource.getDisk().getPersistence().getPrincipal());
    Assert.assertTrue(createResource.getDisk().hasVolume());
}
Also used : Protos(org.apache.mesos.Protos) Resource(org.apache.mesos.Protos.Resource) DefaultVolumeSpec(com.mesosphere.sdk.specification.DefaultVolumeSpec) Operation(org.apache.mesos.Protos.Offer.Operation) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Aggregations

PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)51 Test (org.junit.Test)47 Protos (org.apache.mesos.Protos)38 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)21 Resource (org.apache.mesos.Protos.Resource)17 DefaultPodInstance (com.mesosphere.sdk.scheduler.plan.DefaultPodInstance)16 Operation (org.apache.mesos.Protos.Offer.Operation)15 Collectors (java.util.stream.Collectors)10 com.mesosphere.sdk.specification (com.mesosphere.sdk.specification)8 java.util (java.util)8 Assert (org.junit.Assert)8 ArtifactResource (com.mesosphere.sdk.http.endpoints.ArtifactResource)7 MesosResourcePool (com.mesosphere.sdk.offer.MesosResourcePool)7 SchedulerConfig (com.mesosphere.sdk.scheduler.SchedulerConfig)7 com.mesosphere.sdk.offer (com.mesosphere.sdk.offer)6 PlacementRule (com.mesosphere.sdk.offer.evaluate.placement.PlacementRule)6 TaskLabelWriter (com.mesosphere.sdk.offer.taskdata.TaskLabelWriter)6 DefaultPodSpec (com.mesosphere.sdk.specification.DefaultPodSpec)6 PodInstance (com.mesosphere.sdk.specification.PodInstance)6 PodSpec (com.mesosphere.sdk.specification.PodSpec)6