Search in sources :

Example 36 with Resource

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));
}
Also used : Operation(org.apache.mesos.Protos.Offer.Operation) Protos(org.apache.mesos.Protos) Resource(org.apache.mesos.Protos.Resource) Resource(org.apache.mesos.Protos.Resource) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 37 with Resource

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());
}
Also used : TaskInfo(org.apache.mesos.Protos.TaskInfo) OfferID(org.apache.mesos.Protos.OfferID) Offer(org.apache.mesos.Protos.Offer) Resource(org.apache.mesos.Protos.Resource) Operation(org.apache.mesos.Protos.Offer.Operation) Test(org.junit.Test)

Example 38 with Resource

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"));
}
Also used : Protos(org.apache.mesos.Protos) Offer(org.apache.mesos.Protos.Offer) Resource(org.apache.mesos.Protos.Resource) Test(org.junit.Test)

Example 39 with Resource

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());
}
Also used : Protos(org.apache.mesos.Protos) Offer(org.apache.mesos.Protos.Offer) Resource(org.apache.mesos.Protos.Resource) Test(org.junit.Test)

Example 40 with Resource

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());
}
Also used : Protos(org.apache.mesos.Protos) Offer(org.apache.mesos.Protos.Offer) Resource(org.apache.mesos.Protos.Resource) Test(org.junit.Test)

Aggregations

Resource (org.apache.mesos.Protos.Resource)40 Test (org.junit.Test)35 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)26 Operation (org.apache.mesos.Protos.Offer.Operation)25 PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)13 Protos (org.apache.mesos.Protos)13 TaskInfo (org.apache.mesos.Protos.TaskInfo)12 Offer (org.apache.mesos.Protos.Offer)9 DefaultResourceSet (com.mesosphere.sdk.specification.DefaultResourceSet)4 DefaultVolumeSpec (com.mesosphere.sdk.specification.DefaultVolumeSpec)4 ResourceSet (com.mesosphere.sdk.specification.ResourceSet)4 DiscoveryInfo (org.apache.mesos.Protos.DiscoveryInfo)4 Label (org.apache.mesos.Protos.Label)4 Port (org.apache.mesos.Protos.Port)4 ResourceUtils (com.mesosphere.sdk.offer.ResourceUtils)3 PodInstanceRequirementTestUtils (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirementTestUtils)3 OfferTestUtils (com.mesosphere.sdk.testutils.OfferTestUtils)3 ResourceTestUtils (com.mesosphere.sdk.testutils.ResourceTestUtils)3 TestConstants (com.mesosphere.sdk.testutils.TestConstants)3 Arrays (java.util.Arrays)3