Search in sources :

Example 26 with Operation

use of org.apache.mesos.Protos.Offer.Operation in project dcos-commons by mesosphere.

the class OfferEvaluatorPortsTest method testReserveTaskDynamicVIPPortCustomExecutor.

@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
@Test
public void testReserveTaskDynamicVIPPortCustomExecutor() throws Exception {
    useCustomExecutor();
    List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getVIPRequirement(80, 0), OfferTestUtils.getOffers(ResourceTestUtils.getUnreservedPorts(10000, 10000)));
    Assert.assertEquals(2, recommendations.size());
    Operation launchOperation = recommendations.get(1).getOperation();
    TaskInfo taskInfo = launchOperation.getLaunch().getTaskInfos(0);
    Resource fulfilledPortResource = taskInfo.getResources(0);
    Assert.assertEquals(10000, fulfilledPortResource.getRanges().getRange(0).getBegin());
    Assert.assertFalse(getResourceId(fulfilledPortResource).isEmpty());
    DiscoveryInfo discoveryInfo = taskInfo.getDiscovery();
    Assert.assertEquals(discoveryInfo.getName(), taskInfo.getName());
    Assert.assertEquals(discoveryInfo.getVisibility(), DiscoveryInfo.Visibility.CLUSTER);
    Port discoveryPort = discoveryInfo.getPorts().getPorts(0);
    Assert.assertEquals(discoveryPort.getProtocol(), "tcp");
    Assert.assertEquals(discoveryPort.getVisibility(), DiscoveryInfo.Visibility.EXTERNAL);
    Assert.assertEquals(discoveryPort.getNumber(), 10000);
    Label vipLabel = discoveryPort.getLabels().getLabels(0);
    Assert.assertTrue(vipLabel.getKey().startsWith("VIP_"));
    Assert.assertEquals(vipLabel.getValue(), TestConstants.VIP_NAME + "-0:80");
    Map<String, String> envvars = EnvUtils.toMap(TaskPackingUtils.unpack(taskInfo).getCommand().getEnvironment());
    Assert.assertEquals(String.valueOf(10000), envvars.get(TestConstants.PORT_ENV_NAME + "_VIP_0"));
}
Also used : TaskInfo(org.apache.mesos.Protos.TaskInfo) DiscoveryInfo(org.apache.mesos.Protos.DiscoveryInfo) Port(org.apache.mesos.Protos.Port) Resource(org.apache.mesos.Protos.Resource) Label(org.apache.mesos.Protos.Label) Operation(org.apache.mesos.Protos.Offer.Operation) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 27 with Operation

use of org.apache.mesos.Protos.Offer.Operation in project dcos-commons by mesosphere.

the class OfferEvaluatorPortsTest method testUpdateDynamicToStaticPortCustomExecutor.

@Test
public void testUpdateDynamicToStaticPortCustomExecutor() throws Exception {
    useCustomExecutor();
    // Launch for the first time: get port 555 from dynamic port
    Resource reserveResource = recordLaunchWithOfferedResources(PodInstanceRequirementTestUtils.getPortRequirement(0), ResourceTestUtils.getUnreservedPorts(555, 555)).get(0);
    String resourceId = getResourceId(reserveResource);
    // Now lets move to port 666:
    List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getPortRequirement(666), OfferTestUtils.getOffers(Arrays.asList(ResourceTestUtils.getReservedPorts(555, 555, resourceId), ResourceTestUtils.getUnreservedPorts(666, 666))));
    // RESERVE, UNRESERVE, LAUNCH
    Assert.assertEquals(recommendations.toString(), 3, recommendations.size());
    Assert.assertEquals(Operation.Type.UNRESERVE, recommendations.get(0).getOperation().getType());
    Assert.assertEquals(Operation.Type.RESERVE, recommendations.get(1).getOperation().getType());
    Assert.assertEquals(Operation.Type.LAUNCH, recommendations.get(2).getOperation().getType());
    Operation launchOperation = recommendations.get(2).getOperation();
    TaskInfo taskInfo = launchOperation.getLaunch().getTaskInfos(0);
    Map<String, String> envvars = EnvUtils.toMap(TaskPackingUtils.unpack(taskInfo).getCommand().getEnvironment());
    Assert.assertEquals(String.valueOf(666), envvars.get(TestConstants.PORT_ENV_NAME + "_666"));
}
Also used : TaskInfo(org.apache.mesos.Protos.TaskInfo) Resource(org.apache.mesos.Protos.Resource) Operation(org.apache.mesos.Protos.Offer.Operation) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 28 with Operation

use of org.apache.mesos.Protos.Offer.Operation in project dcos-commons by mesosphere.

the class OfferEvaluatorPortsTest method testReserveTaskMultipleDynamicPortsCustomExecutor.

@Test
public void testReserveTaskMultipleDynamicPortsCustomExecutor() throws Exception {
    useCustomExecutor();
    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.getOffers(ResourceTestUtils.getUnreservedPorts(10000, 10001)));
    Assert.assertEquals(recommendations.toString(), 3, 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(2).getOperation();
    TaskInfo taskInfo = launchOperation.getLaunch().getTaskInfos(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 29 with Operation

use of org.apache.mesos.Protos.Offer.Operation in project dcos-commons by mesosphere.

the class OfferEvaluatorPortsTest method testReserveTaskDynamicVIPPort.

@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
@Test
public void testReserveTaskDynamicVIPPort() throws Exception {
    List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getVIPRequirement(80, 0), OfferTestUtils.getCompleteOffers(ResourceTestUtils.getUnreservedPorts(10000, 10000)));
    Assert.assertEquals(5, recommendations.size());
    Operation launchOperation = recommendations.get(4).getOperation();
    TaskInfo taskInfo = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0);
    Resource fulfilledPortResource = taskInfo.getResources(0);
    Assert.assertEquals(10000, fulfilledPortResource.getRanges().getRange(0).getBegin());
    Assert.assertFalse(getResourceId(fulfilledPortResource).isEmpty());
    DiscoveryInfo discoveryInfo = taskInfo.getDiscovery();
    Assert.assertEquals(discoveryInfo.getName(), taskInfo.getName());
    Assert.assertEquals(discoveryInfo.getVisibility(), DiscoveryInfo.Visibility.CLUSTER);
    Port discoveryPort = discoveryInfo.getPorts().getPorts(0);
    Assert.assertEquals(discoveryPort.getProtocol(), "tcp");
    Assert.assertEquals(discoveryPort.getVisibility(), DiscoveryInfo.Visibility.EXTERNAL);
    Assert.assertEquals(discoveryPort.getNumber(), 10000);
    Label vipLabel = discoveryPort.getLabels().getLabels(0);
    Assert.assertTrue(vipLabel.getKey().startsWith("VIP_"));
    Assert.assertEquals(vipLabel.getValue(), TestConstants.VIP_NAME + "-0:80");
    Map<String, String> envvars = EnvUtils.toMap(TaskPackingUtils.unpack(taskInfo).getCommand().getEnvironment());
    Assert.assertEquals(String.valueOf(10000), envvars.get(TestConstants.PORT_ENV_NAME + "_VIP_0"));
}
Also used : TaskInfo(org.apache.mesos.Protos.TaskInfo) DiscoveryInfo(org.apache.mesos.Protos.DiscoveryInfo) Port(org.apache.mesos.Protos.Port) Resource(org.apache.mesos.Protos.Resource) Label(org.apache.mesos.Protos.Label) Operation(org.apache.mesos.Protos.Offer.Operation) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 30 with Operation

use of org.apache.mesos.Protos.Offer.Operation in project dcos-commons by mesosphere.

the class OfferEvaluatorPortsTest method testLaunchExpectedDynamicPort.

@Test
public void testLaunchExpectedDynamicPort() throws Exception {
    // Launch for the first time: get port 10000
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(0);
    Resource reserveResource = recordLaunchWithCompleteOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedPorts(10000, 10000)).get(0);
    String resourceId = getResourceId(reserveResource);
    Collection<Resource> expectedResources = getExpectedExecutorResources(stateStore.fetchTasks().iterator().next().getExecutor());
    expectedResources.add(ResourceTestUtils.getReservedPorts(10000, 10000, resourceId));
    // Relaunch: detect (from envvar) and reuse previously reserved dynamic port 10000
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, 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());
    Resource launchResource = launchOperation.getLaunchGroup().getTaskGroup().getTasks(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