use of org.apache.mesos.Protos.Resource 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.Resource 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 org.apache.mesos.Protos.Resource in project dcos-commons by mesosphere.
the class MesosResourcePoolTest method testCreateSingleReservedAtomicPool.
@Test
public void testCreateSingleReservedAtomicPool() {
Resource resource = ResourceTestUtils.getReservedMountVolume(1000);
Offer offer = OfferTestUtils.getOffer(resource);
MesosResourcePool pool = new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE));
String resourceId = new MesosResource(resource).getResourceId().get();
Assert.assertEquals(0, pool.getUnreservedAtomicPool().size());
Assert.assertEquals(1, pool.getDynamicallyReservedPoolByResourceId().size());
Assert.assertEquals(resource, pool.getDynamicallyReservedPoolByResourceId().get(resourceId).getResource());
}
use of org.apache.mesos.Protos.Resource in project dcos-commons by mesosphere.
the class MesosResourcePoolTest method testConsumeUnreservedWhenNoUnreservedResources.
@Test
public void testConsumeUnreservedWhenNoUnreservedResources() {
Resource reservedCpu = ResourceTestUtils.getReservedCpus(1.0, UUID.randomUUID().toString());
Offer offer = OfferTestUtils.getOffer(reservedCpu);
MesosResourcePool pool = new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE));
Map<String, Protos.Value> map = pool.getUnreservedMergedPool();
Assert.assertTrue(map != null);
Assert.assertTrue(map.isEmpty());
}
use of org.apache.mesos.Protos.Resource in project dcos-commons by mesosphere.
the class OfferAccepterTest method testLaunchTransientCustomExecutor.
@Test
public void testLaunchTransientCustomExecutor() {
Resource resource = ResourceTestUtils.getUnreservedCpus(1.0);
Offer offer = OfferTestUtils.getOffer(resource);
TaskInfo.Builder taskInfoBuilder = TaskTestUtils.getTaskInfo(resource).toBuilder();
TestOperationRecorder recorder = new TestOperationRecorder();
OfferAccepter accepter = new OfferAccepter(Arrays.asList(recorder));
Driver.setDriver(driver);
accepter.accept(Arrays.asList(new LaunchOfferRecommendation(offer, taskInfoBuilder.build(), Protos.ExecutorInfo.newBuilder().setExecutorId(TestConstants.EXECUTOR_ID).build(), false, false)));
Assert.assertEquals(1, recorder.getLaunches().size());
verify(driver, times(0)).acceptOffers(anyCollectionOf(OfferID.class), anyCollectionOf(Operation.class), anyObject());
}
Aggregations