Search in sources :

Example 6 with Resource

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

Example 7 with Resource

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

Example 8 with Resource

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

Example 9 with Resource

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

Example 10 with Resource

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());
}
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)

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