Search in sources :

Example 11 with Operation

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)));
}
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 12 with Operation

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

Example 13 with Operation

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));
}
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 14 with Operation

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)));
}
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 15 with Operation

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

Aggregations

Operation (org.apache.mesos.Protos.Offer.Operation)34 Test (org.junit.Test)34 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)22 Resource (org.apache.mesos.Protos.Resource)22 PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)11 Protos (org.apache.mesos.Protos)9 TaskInfo (org.apache.mesos.Protos.TaskInfo)9 DefaultVolumeSpec (com.mesosphere.sdk.specification.DefaultVolumeSpec)4 ResourceRefinementCapabilityContext (com.mesosphere.sdk.dcos.ResourceRefinementCapabilityContext)3 DefaultResourceSet (com.mesosphere.sdk.specification.DefaultResourceSet)3 ResourceSet (com.mesosphere.sdk.specification.ResourceSet)3 DiscoveryInfo (org.apache.mesos.Protos.DiscoveryInfo)3 Label (org.apache.mesos.Protos.Label)3 Port (org.apache.mesos.Protos.Port)3 Capabilities (com.mesosphere.sdk.dcos.Capabilities)2 Constants (com.mesosphere.sdk.offer.Constants)2 ResourceUtils (com.mesosphere.sdk.offer.ResourceUtils)2 PodInstanceRequirementTestUtils (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirementTestUtils)2 VolumeSpec (com.mesosphere.sdk.specification.VolumeSpec)2 OfferTestUtils (com.mesosphere.sdk.testutils.OfferTestUtils)2