Search in sources :

Example 31 with OfferRecommendation

use of com.mesosphere.sdk.offer.OfferRecommendation in project dcos-commons by mesosphere.

the class OfferEvaluatorPortsTest method testUpdateDynamicToStaticPort.

@Test
public void testUpdateDynamicToStaticPort() throws Exception {
    // Launch for the first time: get port 555 from dynamic port
    Resource reserveResource = recordLaunchWithCompleteOfferedResources(PodInstanceRequirementTestUtils.getPortRequirement(0), ResourceTestUtils.getUnreservedPorts(555, 555)).get(0);
    String resourceId = getResourceId(reserveResource);
    Collection<Resource> expectedResources = getExpectedExecutorResources(stateStore.fetchTasks().iterator().next().getExecutor());
    expectedResources.addAll(Arrays.asList(ResourceTestUtils.getReservedPorts(555, 555, resourceId), ResourceTestUtils.getUnreservedPorts(666, 666)));
    // Now lets move to port 666:
    List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getPortRequirement(666), Arrays.asList(OfferTestUtils.getOffer(expectedResources)));
    // 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_GROUP, recommendations.get(2).getOperation().getType());
    Operation launchOperation = recommendations.get(2).getOperation();
    TaskInfo taskInfo = launchOperation.getLaunchGroup().getTaskGroup().getTasks(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 32 with OfferRecommendation

use of com.mesosphere.sdk.offer.OfferRecommendation 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 33 with OfferRecommendation

use of com.mesosphere.sdk.offer.OfferRecommendation 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 34 with OfferRecommendation

use of com.mesosphere.sdk.offer.OfferRecommendation 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 35 with OfferRecommendation

use of com.mesosphere.sdk.offer.OfferRecommendation 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)

Aggregations

OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)42 Test (org.junit.Test)39 Resource (org.apache.mesos.Protos.Resource)30 Operation (org.apache.mesos.Protos.Offer.Operation)26 PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)21 Protos (org.apache.mesos.Protos)21 TaskInfo (org.apache.mesos.Protos.TaskInfo)13 UnreserveOfferRecommendation (com.mesosphere.sdk.offer.UnreserveOfferRecommendation)6 CreateOfferRecommendation (com.mesosphere.sdk.offer.CreateOfferRecommendation)4 PlacementRule (com.mesosphere.sdk.offer.evaluate.placement.PlacementRule)4 DefaultPodInstance (com.mesosphere.sdk.scheduler.plan.DefaultPodInstance)4 DefaultPodSpec (com.mesosphere.sdk.specification.DefaultPodSpec)4 DefaultResourceSet (com.mesosphere.sdk.specification.DefaultResourceSet)4 DefaultVolumeSpec (com.mesosphere.sdk.specification.DefaultVolumeSpec)4 PodInstance (com.mesosphere.sdk.specification.PodInstance)4 PodSpec (com.mesosphere.sdk.specification.PodSpec)4 ResourceSet (com.mesosphere.sdk.specification.ResourceSet)4 ReserveOfferRecommendation (com.mesosphere.sdk.offer.ReserveOfferRecommendation)3 ReserveEvaluationOutcome (com.mesosphere.sdk.offer.evaluate.OfferEvaluationUtils.ReserveEvaluationOutcome)3 DefaultResourceSpec (com.mesosphere.sdk.specification.DefaultResourceSpec)3