Search in sources :

Example 31 with Operation

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

the class OfferEvaluatorPortsTest method testLaunchExpectedStaticPort.

@Test
public void testLaunchExpectedStaticPort() throws Exception {
    // Launch for the first time: get port 555
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(555);
    Resource reserveResource = recordLaunchWithCompleteOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedPorts(555, 555)).get(0);
    String resourceId = getResourceId(reserveResource);
    Collection<Resource> expectedResources = getExpectedExecutorResources(stateStore.fetchTasks().iterator().next().getExecutor());
    expectedResources.add(ResourceTestUtils.getReservedPorts(555, 555, resourceId));
    // Launch on previously reserved resources
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getOffer(expectedResources)));
    Assert.assertEquals(1, recommendations.size());
    // Validate LAUNCH Operation
    Protos.Offer.Operation launchOperation = recommendations.get(0).getOperation();
    Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType());
    Protos.Resource launchResource = launchOperation.getLaunchGroup().getTaskGroup().getTasks(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 32 with Operation

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

the class OfferEvaluatorTest method testRelaunchFailedPod.

@Test
public void testRelaunchFailedPod() throws Exception {
    ServiceSpec serviceSpec = getServiceSpec("resource-set-seq.yml");
    PodSpec podSpec = serviceSpec.getPods().get(0);
    PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, Arrays.asList("format")).build();
    Offer sufficientOffer = OfferTestUtils.getCompleteOffer(Arrays.asList(ResourceTestUtils.getUnreservedCpus(3.0), ResourceTestUtils.getUnreservedDisk(500.0)));
    // Launch Task with ONCE goal state, for first time.
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(sufficientOffer));
    Assert.assertEquals(recommendations.toString(), 9, recommendations.size());
    // Validate node task operations
    Operation operation = recommendations.get(0).getOperation();
    Assert.assertEquals(Operation.Type.RESERVE, operation.getType());
    operation = recommendations.get(4).getOperation();
    Assert.assertEquals(Operation.Type.LAUNCH_GROUP, operation.getType());
    // Validate format task operations
    operation = recommendations.get(5).getOperation();
    Assert.assertEquals(Operation.Type.RESERVE, operation.getType());
    operation = recommendations.get(6).getOperation();
    Assert.assertEquals(Operation.Type.RESERVE, operation.getType());
    operation = recommendations.get(7).getOperation();
    Assert.assertEquals(Operation.Type.CREATE, operation.getType());
    operation = recommendations.get(8).getOperation();
    Assert.assertEquals(Operation.Type.LAUNCH_GROUP, operation.getType());
    recordOperations(recommendations);
    // Attempt to launch task again as non-failed.
    podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, Arrays.asList("node")).build();
    recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(sufficientOffer));
    // The pod is running fine according to the state store, so no new deployment is issued.
    Assert.assertEquals(recommendations.toString(), 0, recommendations.size());
    // Now the same operation except with the task flagged as having permanently failed.
    podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, Arrays.asList("node")).recoveryType(RecoveryType.PERMANENT).build();
    recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(sufficientOffer));
    // A new deployment replaces the prior one above.
    Assert.assertEquals(recommendations.toString(), 9, recommendations.size());
    // Validate format task operations
    operation = recommendations.get(0).getOperation();
    Assert.assertEquals(Operation.Type.RESERVE, operation.getType());
    operation = recommendations.get(1).getOperation();
    Assert.assertEquals(Operation.Type.RESERVE, operation.getType());
    operation = recommendations.get(2).getOperation();
    Assert.assertEquals(Operation.Type.CREATE, operation.getType());
    operation = recommendations.get(6).getOperation();
    Assert.assertEquals(Operation.Type.LAUNCH_GROUP, operation.getType());
    // Validate node task operations
    operation = recommendations.get(7).getOperation();
    Assert.assertEquals(Operation.Type.RESERVE, operation.getType());
    operation = recommendations.get(8).getOperation();
    Assert.assertEquals(Operation.Type.LAUNCH_GROUP, operation.getType());
}
Also used : Operation(org.apache.mesos.Protos.Offer.Operation) Test(org.junit.Test)

Example 33 with Operation

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

the class OfferEvaluatorTest method testRelaunchExpectedScalar.

@Test
public void testRelaunchExpectedScalar() throws Exception {
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getCpuRequirement(1.0);
    // Launch for the first time.
    String resourceId = getFirstResourceId(recordLaunchWithCompleteOfferedResources(podInstanceRequirement, ResourceTestUtils.getUnreservedCpus(2.0)));
    // Launch again on expected resources.
    Collection<Resource> expectedResources = getExpectedExecutorResources(stateStore.fetchTasks().iterator().next().getExecutor());
    expectedResources.add(ResourceTestUtils.getReservedCpus(1.0, resourceId));
    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();
    Resource launchResource = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0).getResources(0);
    Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType());
    Assert.assertEquals(resourceId, getResourceId(launchResource));
}
Also used : Operation(org.apache.mesos.Protos.Offer.Operation) Test(org.junit.Test)

Example 34 with Operation

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

the class OfferEvaluatorTest method testDecreaseReservationScalar.

@Test
public void testDecreaseReservationScalar() throws Exception {
    // Launch for the first time.
    Resource reserveResource = recordLaunchWithCompleteOfferedResources(PodInstanceRequirementTestUtils.getCpuRequirement(2.0), ResourceTestUtils.getUnreservedCpus(2.0)).get(0);
    String resourceId = getResourceId(reserveResource);
    Collection<Resource> offeredResources = getExpectedExecutorResources(stateStore.fetchTasks().iterator().next().getExecutor());
    // Launch again with fewer resources.
    PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getCpuRequirement(1.0);
    Resource offeredResource = ResourceTestUtils.getReservedCpus(2.0, resourceId);
    Resource unreservedResource = ResourceTestUtils.getUnreservedCpus(1.0);
    offeredResources.addAll(Arrays.asList(offeredResource, unreservedResource));
    List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getOffer(offeredResources)));
    Assert.assertEquals(2, recommendations.size());
    // Validate UNRESERVE Operation
    Operation unreserveOperation = recommendations.get(0).getOperation();
    Resource unreserveResource = unreserveOperation.getUnreserve().getResources(0);
    Resource.ReservationInfo reservation = ResourceUtils.getReservation(reserveResource).get();
    Assert.assertEquals(Operation.Type.UNRESERVE, unreserveOperation.getType());
    Assert.assertEquals(1.0, unreserveResource.getScalar().getValue(), 0.0);
    validateRole(unreserveResource);
    Assert.assertEquals(TestConstants.ROLE, ResourceUtils.getRole(unreserveResource));
    Assert.assertEquals(TestConstants.PRINCIPAL, reservation.getPrincipal());
    Assert.assertEquals(resourceId, getResourceId(unreserveResource));
    // Validate LAUNCH Operation
    Operation launchOperation = recommendations.get(1).getOperation();
    Resource launchResource = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0).getResources(0);
    Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType());
    Assert.assertEquals(resourceId, getResourceId(launchResource));
    Assert.assertEquals(1.0, launchResource.getScalar().getValue(), 0.0);
}
Also used : Operation(org.apache.mesos.Protos.Offer.Operation) 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