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);
}
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);
}
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));
}
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));
}
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());
}
Aggregations