Search in sources :

Example 6 with MesosResourcePool

use of com.mesosphere.sdk.offer.MesosResourcePool in project dcos-commons by mesosphere.

the class ExecutorEvaluationStageTest method testAcceptOfferWithExpectedExecutorIdCustomExecutor.

@Test
public void testAcceptOfferWithExpectedExecutorIdCustomExecutor() throws Exception {
    useCustomExecutor();
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getCpuRequirement(1.0);
    // Record launch and RUNNING status
    String resourceId = getFirstResourceId(recordLaunchWithOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedCpus(1.0)));
    String taskName = stateStore.fetchTaskNames().stream().findFirst().get();
    Protos.TaskInfo taskInfo = stateStore.fetchTask(taskName).get();
    stateStore.storeStatus(taskInfo.getName(), Protos.TaskStatus.newBuilder().setState(Protos.TaskState.TASK_RUNNING).setTaskId(taskInfo.getTaskId()).build());
    Protos.Resource expectedTaskCpu = ResourceTestUtils.getReservedCpus(1.0, resourceId);
    Protos.Offer offer = OfferTestUtils.getOffer(Arrays.asList(expectedTaskCpu)).toBuilder().addExecutorIds(taskInfo.getExecutor().getExecutorId()).build();
    MesosResourcePool resources = new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE));
    ExecutorEvaluationStage executorEvaluationStage = new ExecutorEvaluationStage(TestConstants.SERVICE_NAME, Optional.of(taskInfo.getExecutor().getExecutorId()));
    PodInfoBuilder podInfoBuilder = new PodInfoBuilder(podInstanceRequirement, TestConstants.SERVICE_NAME, UUID.randomUUID(), ArtifactResource.getUrlFactory(TestConstants.SERVICE_NAME), SchedulerConfigTestUtils.getTestSchedulerConfig(), stateStore.fetchTasks(), frameworkStore.fetchFrameworkId().get(), false, Collections.emptyMap());
    EvaluationOutcome outcome = executorEvaluationStage.evaluate(resources, podInfoBuilder);
    Assert.assertTrue(outcome.isPassing());
    Protos.ExecutorID launchExecutorId = podInfoBuilder.getExecutorBuilder().get().getExecutorId();
    Assert.assertEquals(taskInfo.getExecutor().getExecutorId(), launchExecutorId);
}
Also used : MesosResourcePool(com.mesosphere.sdk.offer.MesosResourcePool) Protos(org.apache.mesos.Protos) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) Test(org.junit.Test)

Example 7 with MesosResourcePool

use of com.mesosphere.sdk.offer.MesosResourcePool in project dcos-commons by mesosphere.

the class ExecutorEvaluationStageTest method testAcceptOfferWithExpectedExecutorId.

@Test
public void testAcceptOfferWithExpectedExecutorId() throws Exception {
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getCpuRequirement(1.0);
    // Record launch and RUNNING status
    String resourceId = getFirstResourceId(recordLaunchWithCompleteOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedCpus(1.1), ResourceTestUtils.getUnreservedMem(256), ResourceTestUtils.getUnreservedDisk(512)));
    String taskName = stateStore.fetchTaskNames().stream().findFirst().get();
    Protos.TaskInfo taskInfo = stateStore.fetchTask(taskName).get();
    stateStore.storeStatus(taskInfo.getName(), Protos.TaskStatus.newBuilder().setState(Protos.TaskState.TASK_RUNNING).setTaskId(taskInfo.getTaskId()).build());
    Protos.Resource expectedTaskCpu = ResourceTestUtils.getReservedCpus(1.0, resourceId);
    Protos.Offer offer = OfferTestUtils.getCompleteOffer(Arrays.asList(expectedTaskCpu)).toBuilder().addExecutorIds(taskInfo.getExecutor().getExecutorId()).build();
    MesosResourcePool resources = new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE));
    ExecutorEvaluationStage executorEvaluationStage = new ExecutorEvaluationStage(TestConstants.SERVICE_NAME, Optional.of(taskInfo.getExecutor().getExecutorId()));
    PodInfoBuilder podInfoBuilder = new PodInfoBuilder(podInstanceRequirement, TestConstants.SERVICE_NAME, UUID.randomUUID(), ArtifactResource.getUrlFactory(TestConstants.SERVICE_NAME), SchedulerConfigTestUtils.getTestSchedulerConfig(), stateStore.fetchTasks(), frameworkStore.fetchFrameworkId().get(), true, Collections.emptyMap());
    EvaluationOutcome outcome = executorEvaluationStage.evaluate(resources, podInfoBuilder);
    Assert.assertTrue(outcome.isPassing());
    Protos.ExecutorID launchExecutorId = podInfoBuilder.getExecutorBuilder().get().getExecutorId();
    Assert.assertEquals(taskInfo.getExecutor().getExecutorId(), launchExecutorId);
}
Also used : MesosResourcePool(com.mesosphere.sdk.offer.MesosResourcePool) Protos(org.apache.mesos.Protos) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) Test(org.junit.Test)

Example 8 with MesosResourcePool

use of com.mesosphere.sdk.offer.MesosResourcePool in project dcos-commons by mesosphere.

the class LaunchEvaluationStageTest method regionAndZoneNotInjected.

@Test
public void regionAndZoneNotInjected() {
    stage.evaluate(new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
    Protos.TaskInfo.Builder taskBuilder = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME);
    Map<String, String> env = EnvUtils.toMap(taskBuilder.getCommand().getEnvironment());
    Assert.assertNull(env.get(EnvConstants.REGION_TASKENV));
    Assert.assertNull(env.get(EnvConstants.ZONE_TASKENV));
}
Also used : MesosResourcePool(com.mesosphere.sdk.offer.MesosResourcePool) Test(org.junit.Test)

Example 9 with MesosResourcePool

use of com.mesosphere.sdk.offer.MesosResourcePool in project dcos-commons by mesosphere.

the class LaunchEvaluationStageTest method regionAndZoneInjected.

@Test
public void regionAndZoneInjected() {
    offer = offer.toBuilder().setDomain(TestConstants.LOCAL_DOMAIN_INFO).build();
    stage.evaluate(new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
    Protos.TaskInfo.Builder taskBuilder = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME);
    Map<String, String> env = EnvUtils.toMap(taskBuilder.getCommand().getEnvironment());
    Assert.assertEquals(TestConstants.LOCAL_REGION, env.get(EnvConstants.REGION_TASKENV));
    Assert.assertEquals(TestConstants.ZONE, env.get(EnvConstants.ZONE_TASKENV));
}
Also used : MesosResourcePool(com.mesosphere.sdk.offer.MesosResourcePool) Test(org.junit.Test)

Example 10 with MesosResourcePool

use of com.mesosphere.sdk.offer.MesosResourcePool in project dcos-commons by mesosphere.

the class LaunchEvaluationStageTest method isPassing.

@Test
public void isPassing() {
    EvaluationOutcome outcome = stage.evaluate(new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
    Assert.assertTrue(outcome.isPassing());
}
Also used : MesosResourcePool(com.mesosphere.sdk.offer.MesosResourcePool) Test(org.junit.Test)

Aggregations

MesosResourcePool (com.mesosphere.sdk.offer.MesosResourcePool)18 Test (org.junit.Test)18 Protos (org.apache.mesos.Protos)15 PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)6 DiscoveryInfo (org.apache.mesos.Protos.DiscoveryInfo)4 EndpointUtils (com.mesosphere.sdk.http.EndpointUtils)2 PlacementRule (com.mesosphere.sdk.offer.evaluate.placement.PlacementRule)2 DefaultPodInstance (com.mesosphere.sdk.scheduler.plan.DefaultPodInstance)2 DefaultPodSpec (com.mesosphere.sdk.specification.DefaultPodSpec)2 PodInstance (com.mesosphere.sdk.specification.PodInstance)2 PodSpec (com.mesosphere.sdk.specification.PodSpec)2 IOException (java.io.IOException)1