use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.
the class OfferEvaluatorPortsTest method testReserveStaticPort.
@Test
public void testReserveStaticPort() throws Exception {
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(555);
Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(555, 555);
List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, OfferTestUtils.getCompleteOffers(offeredPorts));
Assert.assertEquals(5, recommendations.size());
Protos.Offer.Operation launchOperation = recommendations.get(4).getOperation();
Protos.TaskInfo taskInfo = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0);
Protos.Resource fulfilledPortResource = taskInfo.getResources(0);
Assert.assertFalse(getResourceId(fulfilledPortResource).isEmpty());
Protos.CommandInfo command = TaskPackingUtils.unpack(taskInfo).getCommand();
Map<String, String> envvars = EnvUtils.toMap(command.getEnvironment());
Assert.assertEquals(String.valueOf(555), envvars.get(TestConstants.PORT_ENV_NAME + "_555"));
}
use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.
the class OfferEvaluatorPortsTest method testReserveStaticPortCustomExecutor.
@Test
public void testReserveStaticPortCustomExecutor() throws Exception {
useCustomExecutor();
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(555);
Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(555, 555);
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());
Protos.CommandInfo command = TaskPackingUtils.unpack(taskInfo).getCommand();
Map<String, String> envvars = EnvUtils.toMap(command.getEnvironment());
Assert.assertEquals(String.valueOf(555), envvars.get(TestConstants.PORT_ENV_NAME + "_555"));
}
use of com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement in project dcos-commons by mesosphere.
the class OfferEvaluatorPortsTest method testLaunchExpectedDynamicPort.
@Test
public void testLaunchExpectedDynamicPort() throws Exception {
// Launch for the first time: get port 10000
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(0);
Resource reserveResource = recordLaunchWithCompleteOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedPorts(10000, 10000)).get(0);
String resourceId = getResourceId(reserveResource);
Collection<Resource> expectedResources = getExpectedExecutorResources(stateStore.fetchTasks().iterator().next().getExecutor());
expectedResources.add(ResourceTestUtils.getReservedPorts(10000, 10000, resourceId));
// Relaunch: detect (from envvar) and reuse previously reserved dynamic port 10000
List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getOffer(expectedResources)));
Assert.assertEquals(1, recommendations.size());
// Validate LAUNCH Operation
Operation launchOperation = recommendations.get(0).getOperation();
Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType());
Resource launchResource = launchOperation.getLaunchGroup().getTaskGroup().getTasks(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 testLaunchExpectedStaticPort.
@Test
public void testLaunchExpectedStaticPort() throws Exception {
// Launch for the first time: get port 555
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(555);
Resource reserveResource = recordLaunchWithCompleteOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedPorts(555, 555)).get(0);
String resourceId = getResourceId(reserveResource);
Collection<Resource> expectedResources = getExpectedExecutorResources(stateStore.fetchTasks().iterator().next().getExecutor());
expectedResources.add(ResourceTestUtils.getReservedPorts(555, 555, resourceId));
// Launch on previously reserved resources
List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getOffer(expectedResources)));
Assert.assertEquals(1, recommendations.size());
// Validate LAUNCH Operation
Protos.Offer.Operation launchOperation = recommendations.get(0).getOperation();
Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType());
Protos.Resource launchResource = launchOperation.getLaunchGroup().getTaskGroup().getTasks(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 testReserveTaskDynamicPort.
@Test
public void testReserveTaskDynamicPort() throws Exception {
Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(0);
List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, OfferTestUtils.getCompleteOffers(offeredPorts));
Assert.assertEquals(5, recommendations.size());
Protos.Offer.Operation launchOperation = recommendations.get(4).getOperation();
Protos.TaskInfo taskInfo = launchOperation.getLaunchGroup().getTaskGroup().getTasks(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"));
}
Aggregations