use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.
the class OfferEvaluatorPortsTest method testLaunchExpectedDynamicPortCustomExecutor.
@Test
public void testLaunchExpectedDynamicPortCustomExecutor() throws Exception {
useCustomExecutor();
// Launch for the first time: get port 10000
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(0);
Resource reserveResource = recordLaunchWithOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedPorts(10000, 10000)).get(0);
String resourceId = getResourceId(reserveResource);
// Relaunch: detect (from envvar) and reuse previously reserved dynamic port 10000
List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, OfferTestUtils.getOffers(ResourceTestUtils.getReservedPorts(10000, 10000, resourceId)));
Assert.assertEquals(1, recommendations.size());
// Validate LAUNCH Operation
Operation launchOperation = recommendations.get(0).getOperation();
Assert.assertEquals(Operation.Type.LAUNCH, launchOperation.getType());
Resource launchResource = launchOperation.getLaunch().getTaskInfos(0).getResources(0);
Assert.assertEquals(resourceId, getResourceId(launchResource));
}
use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.
the class OfferEvaluatorPortsTest method testReserveTaskDynamicPortCustomExecutor.
@Test
public void testReserveTaskDynamicPortCustomExecutor() throws Exception {
useCustomExecutor();
Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(0);
List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, OfferTestUtils.getOffers(offeredPorts));
Assert.assertEquals(2, recommendations.size());
Protos.Offer.Operation launchOperation = recommendations.get(1).getOperation();
Protos.TaskInfo taskInfo = launchOperation.getLaunch().getTaskInfos(0);
Protos.Resource fulfilledPortResource = taskInfo.getResources(0);
Assert.assertFalse(getResourceId(fulfilledPortResource).isEmpty());
Map<String, String> envvars = EnvUtils.toMap(TaskPackingUtils.unpack(taskInfo).getCommand().getEnvironment());
Assert.assertEquals(envvars.toString(), String.valueOf(10000), envvars.get(TestConstants.PORT_ENV_NAME + "_0"));
}
use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.
the class LaunchEvaluationStageTest method beforeEach.
@Before
public void beforeEach() throws InvalidRequirementException {
Protos.Resource offeredResource = ResourceTestUtils.getUnreservedCpus(2.0);
stage = new LaunchEvaluationStage(TestConstants.SERVICE_NAME, TestConstants.TASK_NAME, true, true);
offer = OfferTestUtils.getOffer(offeredResource);
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getCpuRequirement(1.0);
podInfoBuilder = new PodInfoBuilder(podInstanceRequirement, TestConstants.SERVICE_NAME, UUID.randomUUID(), ArtifactResource.getUrlFactory(TestConstants.SERVICE_NAME), SchedulerConfigTestUtils.getTestSchedulerConfig(), Collections.emptyList(), TestConstants.FRAMEWORK_ID, true, Collections.emptyMap());
}
use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.
the class ExecutorEvaluationStageTest method testRejectOfferWithoutExpectedExecutorId.
@Test
public void testRejectOfferWithoutExpectedExecutorId() 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);
MesosResourcePool resources = new MesosResourcePool(OfferTestUtils.getCompleteOffer(Arrays.asList(expectedTaskCpu)), Optional.of(Constants.ANY_ROLE));
ExecutorEvaluationStage executorEvaluationStage = new ExecutorEvaluationStage(TestConstants.SERVICE_NAME, Optional.of(taskInfo.getExecutor().getExecutorId()));
EvaluationOutcome outcome = executorEvaluationStage.evaluate(resources, new PodInfoBuilder(podInstanceRequirement, TestConstants.SERVICE_NAME, UUID.randomUUID(), ArtifactResource.getUrlFactory(TestConstants.SERVICE_NAME), SchedulerConfigTestUtils.getTestSchedulerConfig(), stateStore.fetchTasks(), frameworkStore.fetchFrameworkId().get(), true, Collections.emptyMap()));
Assert.assertFalse(outcome.isPassing());
}
use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement 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);
}
Aggregations