Search in sources :

Example 16 with Operation

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

the class OfferEvaluatorVolumesTest method testReserveCreateLaunchRootVolume.

@Test
public void testReserveCreateLaunchRootVolume() throws Exception {
    Resource offeredCpuResource = ResourceTestUtils.getUnreservedCpus(1.0);
    Resource offeredDiskResource = ResourceTestUtils.getUnreservedDisk(2000);
    List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getRootVolumeRequirement(1.0, 1500), Arrays.asList(OfferTestUtils.getCompleteOffer(Arrays.asList(offeredDiskResource, offeredCpuResource))));
    // RESERVE, RESERVE, CREATE, RESERVE, RESERVE, RESERVE, LAUNCH
    Assert.assertEquals(7, recommendations.size());
    // Validate CPU RESERVE Operation
    Operation reserveOperation = recommendations.get(0).getOperation();
    Resource reserveResource = reserveOperation.getReserve().getResources(0);
    Resource.ReservationInfo reservation = ResourceUtils.getReservation(reserveResource).get();
    Assert.assertEquals(Operation.Type.RESERVE, reserveOperation.getType());
    Assert.assertEquals(1.0, reserveResource.getScalar().getValue(), 0.0);
    OfferEvaluatorTest.validateRole(reserveResource);
    Assert.assertEquals(TestConstants.ROLE, ResourceUtils.getRole(reserveResource));
    Assert.assertEquals(TestConstants.PRINCIPAL, reservation.getPrincipal());
    Assert.assertEquals(36, getResourceId(reserveResource).length());
    Assert.assertFalse(reserveResource.hasDisk());
    // Validate DISK RESERVE Operation
    reserveOperation = recommendations.get(1).getOperation();
    reserveResource = reserveOperation.getReserve().getResources(0);
    reservation = ResourceUtils.getReservation(reserveResource).get();
    Assert.assertEquals(Operation.Type.RESERVE, reserveOperation.getType());
    Assert.assertEquals(1500, reserveResource.getScalar().getValue(), 0.0);
    OfferEvaluatorTest.validateRole(reserveResource);
    Assert.assertEquals(TestConstants.ROLE, ResourceUtils.getRole(reserveResource));
    Assert.assertEquals(TestConstants.PRINCIPAL, reservation.getPrincipal());
    Assert.assertEquals(36, getResourceId(reserveResource).length());
    Assert.assertFalse(reserveResource.hasDisk());
    // Validate CREATE Operation
    String resourceId = getResourceId(reserveResource);
    Operation createOperation = recommendations.get(2).getOperation();
    Resource createResource = createOperation.getCreate().getVolumes(0);
    Assert.assertEquals(resourceId, getResourceId(createResource));
    Assert.assertEquals(36, createResource.getDisk().getPersistence().getId().length());
    Assert.assertEquals(TestConstants.PRINCIPAL, createResource.getDisk().getPersistence().getPrincipal());
    Assert.assertTrue(createResource.getDisk().hasVolume());
    // Validate LAUNCH Operation
    String persistenceId = createResource.getDisk().getPersistence().getId();
    Operation launchOperation = recommendations.get(6).getOperation();
    Resource launchResource = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0).getResources(1);
    Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType());
    Assert.assertEquals(resourceId, getResourceId(launchResource));
    Assert.assertEquals(persistenceId, launchResource.getDisk().getPersistence().getId());
    Assert.assertEquals(TestConstants.PRINCIPAL, launchResource.getDisk().getPersistence().getPrincipal());
}
Also used : Resource(org.apache.mesos.Protos.Resource) Operation(org.apache.mesos.Protos.Offer.Operation) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 17 with Operation

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

the class OfferEvaluatorVolumesTest method testCreateMultipleRootVolumes.

@Test
public void testCreateMultipleRootVolumes() throws Exception {
    ResourceSet resourceSet = DefaultResourceSet.newBuilder(TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL).id(TestConstants.RESOURCE_SET_ID).cpus(1.0).addVolume(VolumeSpec.Type.ROOT.name(), 1.0, TestConstants.CONTAINER_PATH + "-a").addVolume(VolumeSpec.Type.ROOT.name(), 2.0, TestConstants.CONTAINER_PATH + "-b").build();
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getRequirement(resourceSet, 0);
    Resource offeredDisk = ResourceTestUtils.getUnreservedDisk(3);
    Resource offeredCpu = ResourceTestUtils.getUnreservedCpus(1.0);
    Protos.Offer offer = OfferTestUtils.getCompleteOffer(Arrays.asList(offeredCpu, offeredDisk));
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(offer));
    Assert.assertEquals(9, recommendations.size());
    Assert.assertEquals(Operation.Type.RESERVE, recommendations.get(0).getOperation().getType());
    Assert.assertEquals(Operation.Type.RESERVE, recommendations.get(1).getOperation().getType());
    Assert.assertEquals(Operation.Type.CREATE, recommendations.get(2).getOperation().getType());
    Assert.assertEquals(Operation.Type.RESERVE, recommendations.get(3).getOperation().getType());
    Assert.assertEquals(Operation.Type.CREATE, recommendations.get(4).getOperation().getType());
    Assert.assertEquals(Operation.Type.LAUNCH_GROUP, recommendations.get(8).getOperation().getType());
    // Validate Create Operation
    Operation createOperation = recommendations.get(2).getOperation();
    Assert.assertEquals(TestConstants.CONTAINER_PATH + "-a", createOperation.getCreate().getVolumes(0).getDisk().getVolume().getContainerPath());
    // Validate Create Operation
    createOperation = recommendations.get(4).getOperation();
    Assert.assertEquals(TestConstants.CONTAINER_PATH + "-b", createOperation.getCreate().getVolumes(0).getDisk().getVolume().getContainerPath());
    // Validate Launch Operation
    Operation launchOperation = recommendations.get(8).getOperation();
    for (Protos.TaskInfo taskInfo : launchOperation.getLaunch().getTaskInfosList()) {
        for (Resource resource : taskInfo.getResourcesList()) {
            Assert.assertFalse(getResourceId(resource).isEmpty());
        }
    }
}
Also used : Protos(org.apache.mesos.Protos) Resource(org.apache.mesos.Protos.Resource) ResourceSet(com.mesosphere.sdk.specification.ResourceSet) DefaultResourceSet(com.mesosphere.sdk.specification.DefaultResourceSet) 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 18 with Operation

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

the class OfferEvaluatorTest method testLaunchAttributesEmbedded.

@Test
public void testLaunchAttributesEmbedded() throws Exception {
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getCpuRequirement(1.0);
    // Launch for the first time.
    String resourceId = getFirstResourceId(recordLaunchWithCompleteOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedCpus(2.0)));
    Collection<Resource> expectedResources = getExpectedExecutorResources(stateStore.fetchTasks().iterator().next().getExecutor());
    expectedResources.add(ResourceTestUtils.getReservedCpus(1.0, resourceId));
    Offer.Builder offerBuilder = OfferTestUtils.getOffer(expectedResources).toBuilder();
    Attribute.Builder attrBuilder = offerBuilder.addAttributesBuilder().setName("rack").setType(Value.Type.TEXT);
    attrBuilder.getTextBuilder().setValue("foo");
    attrBuilder = offerBuilder.addAttributesBuilder().setName("diskspeed").setType(Value.Type.SCALAR);
    attrBuilder.getScalarBuilder().setValue(1234.5678);
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(offerBuilder.build()));
    Assert.assertEquals(1, recommendations.size());
    // Validate LAUNCH Operation
    Operation launchOperation = recommendations.get(0).getOperation();
    Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType());
    // Validate that TaskInfo has embedded the Attributes from the selected offer:
    TaskInfo launchTask = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0);
    Assert.assertEquals(Arrays.asList("rack:foo", "diskspeed:1234.568"), new TaskLabelReader(launchTask).getOfferAttributeStrings());
    Resource launchResource = launchTask.getResources(0);
    Assert.assertEquals(resourceId, getResourceId(launchResource));
}
Also used : TaskLabelReader(com.mesosphere.sdk.offer.taskdata.TaskLabelReader) Operation(org.apache.mesos.Protos.Offer.Operation) Test(org.junit.Test)

Example 19 with Operation

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

the class OfferEvaluatorPortsTest method testUpdateStaticToStaticPort.

@Test
public void testUpdateStaticToStaticPort() throws Exception {
    // Launch for the first time: get port 555
    Resource reserveResource = recordLaunchWithCompleteOfferedResources(PodInstanceRequirementTestUtils.getPortRequirement(555), 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)));
    // UNRESERVE, RESERVE, 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 20 with Operation

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

the class OfferEvaluatorVolumesTest method testReserveCreateLaunchMountVolume.

@Test
public void testReserveCreateLaunchMountVolume() throws Exception {
    Resource offeredCpuResource = ResourceTestUtils.getUnreservedCpus(1.0);
    Resource offeredDiskResource = ResourceTestUtils.getUnreservedMountVolume(2000);
    List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getMountVolumeRequirement(1.0, 1500), Arrays.asList(OfferTestUtils.getCompleteOffer(Arrays.asList(offeredCpuResource, offeredDiskResource))));
    // RESERVE, RESERVE, CREATE, RESERVE, RESERVE, RESERVE, LAUNCH
    Assert.assertEquals(7, recommendations.size());
    // Validate RESERVE Operation
    Operation reserveOperation = recommendations.get(1).getOperation();
    Resource reserveResource = reserveOperation.getReserve().getResources(0);
    Resource.ReservationInfo reservation = ResourceUtils.getReservation(reserveResource).get();
    Assert.assertEquals(Operation.Type.RESERVE, reserveOperation.getType());
    Assert.assertEquals(2000, reserveResource.getScalar().getValue(), 0.0);
    Assert.assertEquals(TestConstants.MOUNT_ROOT, reserveResource.getDisk().getSource().getMount().getRoot());
    Assert.assertEquals(TestConstants.PRINCIPAL, reservation.getPrincipal());
    Assert.assertEquals(36, getResourceId(reserveResource).length());
    Assert.assertTrue(reserveResource.hasDisk());
    Assert.assertFalse(reserveResource.getDisk().hasPersistence());
    Assert.assertFalse(reserveResource.getDisk().hasVolume());
    // Validate CREATE Operation
    String resourceId = getResourceId(reserveResource);
    Operation createOperation = recommendations.get(2).getOperation();
    Resource createResource = createOperation.getCreate().getVolumes(0);
    Assert.assertEquals(resourceId, getResourceId(createResource));
    Assert.assertEquals(36, createResource.getDisk().getPersistence().getId().length());
    Assert.assertEquals(TestConstants.MOUNT_ROOT, createResource.getDisk().getSource().getMount().getRoot());
    Assert.assertEquals(TestConstants.PRINCIPAL, createResource.getDisk().getPersistence().getPrincipal());
    Assert.assertTrue(createResource.getDisk().hasVolume());
    // Validate LAUNCH Operation
    String persistenceId = createResource.getDisk().getPersistence().getId();
    Operation launchOperation = recommendations.get(6).getOperation();
    Resource launchResource = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0).getResources(1);
    Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType());
    Assert.assertEquals(resourceId, getResourceId(launchResource));
    Assert.assertEquals(persistenceId, launchResource.getDisk().getPersistence().getId());
    Assert.assertEquals(TestConstants.MOUNT_ROOT, launchResource.getDisk().getSource().getMount().getRoot());
    Assert.assertEquals(TestConstants.PRINCIPAL, launchResource.getDisk().getPersistence().getPrincipal());
    Assert.assertEquals(2000, launchResource.getScalar().getValue(), 0.0);
}
Also used : Resource(org.apache.mesos.Protos.Resource) Operation(org.apache.mesos.Protos.Offer.Operation) 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