use of org.apache.mesos.Protos.Resource 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 org.apache.mesos.Protos.Resource in project dcos-commons by mesosphere.
the class OfferAccepterTest method testLaunchTransient.
@Test
public void testLaunchTransient() {
Resource resource = ResourceTestUtils.getUnreservedCpus(1.0);
Offer offer = OfferTestUtils.getCompleteOffer(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, true)));
Assert.assertEquals(1, recorder.getLaunches().size());
verify(driver, times(0)).acceptOffers(anyCollectionOf(OfferID.class), anyCollectionOf(Operation.class), anyObject());
}
use of org.apache.mesos.Protos.Resource in project dcos-commons by mesosphere.
the class MesosResourcePoolTest method testConsumeUnreservedMergedResource.
@Test
public void testConsumeUnreservedMergedResource() {
Resource resource = ResourceTestUtils.getUnreservedCpus(1.0);
Protos.Value resourceValue = ValueUtils.getValue(resource);
Offer offer = OfferTestUtils.getOffer(resource);
MesosResourcePool pool = new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE));
Assert.assertEquals(1, pool.getUnreservedMergedPool().size());
Assert.assertEquals(resource.getScalar().getValue(), pool.getUnreservedMergedPool().get("cpus").getScalar().getValue(), 0.0);
MesosResource resourceToConsume = pool.consumeReservableMerged(resource.getName(), resourceValue, Constants.ANY_ROLE).get();
Assert.assertEquals(resource, resourceToConsume.getResource());
Assert.assertEquals(ValueUtils.getZero(Protos.Value.Type.SCALAR), pool.getUnreservedMergedPool().get("cpus"));
}
use of org.apache.mesos.Protos.Resource in project dcos-commons by mesosphere.
the class MesosResourcePoolTest method testConsumeReservedMergedResource.
@Test
public void testConsumeReservedMergedResource() {
Resource resource = ResourceTestUtils.getReservedCpus(1.0, TestConstants.RESOURCE_ID);
Protos.Value resourceValue = ValueUtils.getValue(resource);
String resourceId = ResourceTestUtils.getResourceId(resource);
Offer offer = OfferTestUtils.getOffer(resource);
MesosResourcePool pool = new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE));
Assert.assertEquals(1, pool.getDynamicallyReservedPoolByResourceId().size());
MesosResource resourceToConsume = pool.consumeReserved(resource.getName(), resourceValue, resourceId).get();
Assert.assertEquals(resource, resourceToConsume.getResource());
Assert.assertEquals(0, pool.getDynamicallyReservedPoolByResourceId().size());
}
use of org.apache.mesos.Protos.Resource in project dcos-commons by mesosphere.
the class MesosResourcePoolTest method testConsumeUnreservedAtomicResource.
@Test
public void testConsumeUnreservedAtomicResource() {
Resource offerResource = ResourceTestUtils.getUnreservedMountVolume(1000);
Protos.Value resourceValue = ValueUtils.getValue(offerResource);
Offer offer = OfferTestUtils.getOffer(offerResource);
MesosResourcePool pool = new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE));
Assert.assertEquals(1, pool.getUnreservedAtomicPool().size());
MesosResource resourceToConsume = pool.consumeAtomic(offerResource.getName(), resourceValue).get();
Assert.assertEquals(offerResource, resourceToConsume.getResource());
Assert.assertEquals(0, pool.getUnreservedAtomicPool().size());
}
Aggregations