use of org.apache.mesos.Protos.Offer.Operation in project dcos-commons by mesosphere.
the class OfferEvaluatorPortsTest method testLaunchExpectedMultiplePortsCustomExecutor.
@Test
public void testLaunchExpectedMultiplePortsCustomExecutor() throws Exception {
useCustomExecutor();
// Launch for the first time: get ports 10000,10001
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(10000, 10001);
List<Resource> reserveResources = recordLaunchWithOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedPorts(10000, 10001));
Assert.assertEquals(reserveResources.toString(), 2, reserveResources.size());
String resourceId0 = getResourceId(reserveResources.get(0));
String resourceId1 = getResourceId(reserveResources.get(1));
// Now try relaunch:
List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getPortRequirement(10000, 10001), OfferTestUtils.getOffers(Arrays.asList(ResourceTestUtils.getReservedPorts(10000, 10000, resourceId0), ResourceTestUtils.getReservedPorts(10001, 10001, resourceId1))));
Assert.assertEquals(1, recommendations.size());
// Validate LAUNCH Operation
Operation launchOperation = recommendations.get(0).getOperation();
Assert.assertEquals(Operation.Type.LAUNCH, launchOperation.getType());
List<Resource> launchResources = launchOperation.getLaunch().getTaskInfos(0).getResourcesList();
Assert.assertEquals(launchResources.toString(), 2, launchResources.size());
Assert.assertEquals(resourceId0, getResourceId(launchResources.get(0)));
Assert.assertEquals(resourceId1, getResourceId(launchResources.get(1)));
}
use of org.apache.mesos.Protos.Offer.Operation in project dcos-commons by mesosphere.
the class OfferEvaluatorPortsTest method testReserveTaskMultipleDynamicPorts.
@Test
public void testReserveTaskMultipleDynamicPorts() throws Exception {
String portenv0 = TestConstants.PORT_ENV_NAME + "_DYN_ZERO";
String portenv1 = TestConstants.PORT_ENV_NAME + "_DYN_ONE";
Map<String, Integer> ports = new HashMap<>();
ports.put(portenv0, 0);
ports.put(portenv1, 0);
List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getPortRequirement(ports), OfferTestUtils.getCompleteOffers(ResourceTestUtils.getUnreservedPorts(10000, 10001)));
Assert.assertEquals(recommendations.toString(), 6, recommendations.size());
Operation reserveOperation = recommendations.get(0).getOperation();
Resource fulfilledPortResource1 = reserveOperation.getReserve().getResources(0);
Assert.assertEquals(10000, fulfilledPortResource1.getRanges().getRange(0).getBegin());
Assert.assertEquals(10000, fulfilledPortResource1.getRanges().getRange(0).getEnd());
reserveOperation = recommendations.get(1).getOperation();
Resource fulfilledPortResource2 = reserveOperation.getReserve().getResources(0);
Assert.assertEquals(10001, fulfilledPortResource2.getRanges().getRange(0).getBegin());
Assert.assertEquals(10001, fulfilledPortResource2.getRanges().getRange(0).getEnd());
Operation launchOperation = recommendations.get(5).getOperation();
TaskInfo taskInfo = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0);
Assert.assertEquals(getResourceId(taskInfo.getResources(0)), getResourceId(fulfilledPortResource1));
Assert.assertEquals(getResourceId(taskInfo.getResources(1)), getResourceId(fulfilledPortResource2));
Map<String, String> envvars = EnvUtils.toMap(TaskPackingUtils.unpack(taskInfo).getCommand().getEnvironment());
Assert.assertEquals(String.valueOf(10000), envvars.get(portenv0));
Assert.assertEquals(String.valueOf(10001), envvars.get(portenv1));
Assert.assertEquals(10000, taskInfo.getResources(0).getRanges().getRange(0).getBegin());
Assert.assertEquals(10000, taskInfo.getResources(0).getRanges().getRange(0).getEnd());
Assert.assertEquals(10001, taskInfo.getResources(1).getRanges().getRange(0).getBegin());
Assert.assertEquals(10001, taskInfo.getResources(1).getRanges().getRange(0).getEnd());
}
use of org.apache.mesos.Protos.Offer.Operation in project dcos-commons by mesosphere.
the class OfferEvaluatorPortsTest method testLaunchExpectedStaticPortCustomExecutor.
@Test
public void testLaunchExpectedStaticPortCustomExecutor() throws Exception {
useCustomExecutor();
// Launch for the first time: get port 555
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(555);
Resource reserveResource = recordLaunchWithOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedPorts(555, 555)).get(0);
String resourceId = getResourceId(reserveResource);
// Launch on previously reserved resources
List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, OfferTestUtils.getOffers(ResourceTestUtils.getReservedPorts(555, 555, resourceId)));
Assert.assertEquals(1, recommendations.size());
// Validate LAUNCH Operation
Protos.Offer.Operation launchOperation = recommendations.get(0).getOperation();
Assert.assertEquals(Protos.Offer.Operation.Type.LAUNCH, launchOperation.getType());
Protos.Resource launchResource = launchOperation.getLaunch().getTaskInfos(0).getResources(0);
Assert.assertEquals(resourceId, getResourceId(launchResource));
}
use of org.apache.mesos.Protos.Offer.Operation in project dcos-commons by mesosphere.
the class OfferEvaluatorPortsTest method testLaunchExpectedMultiplePorts.
@Test
public void testLaunchExpectedMultiplePorts() throws Exception {
// Launch for the first time: get ports 10000,10001
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(10000, 10001);
List<Resource> reserveResources = recordLaunchWithCompleteOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedPorts(10000, 10001));
Assert.assertEquals(reserveResources.toString(), 5, reserveResources.size());
String resourceId0 = getResourceId(reserveResources.get(0));
String resourceId1 = getResourceId(reserveResources.get(1));
Collection<Resource> expectedResources = getExpectedExecutorResources(stateStore.fetchTasks().iterator().next().getExecutor());
expectedResources.addAll(Arrays.asList(ResourceTestUtils.getReservedPorts(10000, 10000, resourceId0), ResourceTestUtils.getReservedPorts(10001, 10001, resourceId1)));
// Now try relaunch:
List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getPortRequirement(10000, 10001), 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());
List<Resource> launchResources = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0).getResourcesList();
Assert.assertEquals(launchResources.toString(), 2, launchResources.size());
Assert.assertEquals(resourceId0, getResourceId(launchResources.get(0)));
Assert.assertEquals(resourceId1, getResourceId(launchResources.get(1)));
}
use of org.apache.mesos.Protos.Offer.Operation 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));
}
Aggregations