use of org.apache.mesos.Protos.Offer.Operation in project dcos-commons by mesosphere.
the class OfferEvaluatorPortsTest method testReserveTaskNamedVIPPort.
@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
@Test
public void testReserveTaskNamedVIPPort() throws Exception {
List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getVIPRequirement(80, 10000), 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 + "-10000:80");
Map<String, String> envvars = EnvUtils.toMap(TaskPackingUtils.unpack(taskInfo).getCommand().getEnvironment());
Assert.assertEquals(String.valueOf(10000), envvars.get(TestConstants.PORT_ENV_NAME + "_VIP_10000"));
}
use of org.apache.mesos.Protos.Offer.Operation in project dcos-commons by mesosphere.
the class OfferEvaluatorTest method testReplaceDeployStep.
@Test
public void testReplaceDeployStep() throws Exception {
ServiceSpec serviceSpec = getServiceSpec("valid-minimal-volume.yml");
PodSpec podSpec = serviceSpec.getPods().get(0);
PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement.newBuilder(podInstance, Arrays.asList("task-name")).build();
DeploymentStep deploymentStep = new DeploymentStep("test-step", podInstanceRequirement, stateStore);
Offer sufficientOffer = OfferTestUtils.getCompleteOffer(Arrays.asList(ResourceTestUtils.getUnreservedCpus(3.0), ResourceTestUtils.getUnreservedMem(1024), ResourceTestUtils.getUnreservedDisk(500.0)));
List<OfferRecommendation> recommendations = evaluator.evaluate(deploymentStep.start().get(), Arrays.asList(sufficientOffer));
Assert.assertEquals(recommendations.toString(), 8, recommendations.size());
Operation launchOperation = recommendations.get(7).getOperation();
TaskInfo taskInfo = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0);
recordOperations(recommendations);
deploymentStep.updateOfferStatus(recommendations);
Assert.assertEquals(com.mesosphere.sdk.scheduler.plan.Status.STARTING, deploymentStep.getStatus());
// Simulate an initial failure to deploy. Perhaps the CREATE operation failed
deploymentStep.update(TaskStatus.newBuilder().setTaskId(taskInfo.getTaskId()).setState(TaskState.TASK_ERROR).build());
Assert.assertEquals(com.mesosphere.sdk.scheduler.plan.Status.PENDING, deploymentStep.getStatus());
FailureUtils.setPermanentlyFailed(stateStore, deploymentStep.getPodInstanceRequirement().get().getPodInstance());
Assert.assertTrue(FailureUtils.isPermanentlyFailed(stateStore.fetchTask(taskInfo.getName()).get()));
recommendations = evaluator.evaluate(deploymentStep.start().get(), Arrays.asList(sufficientOffer));
Assert.assertEquals(recommendations.toString(), 8, recommendations.size());
Operation 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.RESERVE, operation.getType());
operation = recommendations.get(3).getOperation();
Assert.assertEquals(Operation.Type.CREATE, operation.getType());
operation = recommendations.get(7).getOperation();
Assert.assertEquals(Operation.Type.LAUNCH_GROUP, operation.getType());
}
use of org.apache.mesos.Protos.Offer.Operation in project dcos-commons by mesosphere.
the class OfferEvaluatorTest method testIncreasePreReservedReservationScalar.
@Test
public void testIncreasePreReservedReservationScalar() throws Exception {
final String preReservedRole = "slave_public";
// Launch for the first time with 2.0 cpus offered, 1.0 cpus required.
String resourceId = getFirstResourceId(recordLaunchWithCompleteOfferedResources(PodInstanceRequirementTestUtils.getCpuRequirement(1.0, preReservedRole), preReservedRole, ResourceTestUtils.getUnreservedCpus(2.0, preReservedRole)));
// Launch again with 1.0 cpus reserved, 1.0 cpus unreserved, and 2.0 cpus required.
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getCpuRequirement(2.0, preReservedRole);
Resource offeredResource = ResourceTestUtils.getReservedCpus(1.0, resourceId);
Resource unreservedResource = ResourceTestUtils.getUnreservedCpus(1.0, preReservedRole);
Collection<Resource> expectedResources = getExpectedExecutorResources(stateStore.fetchTasks().iterator().next().getExecutor());
expectedResources.addAll(Arrays.asList(offeredResource, unreservedResource));
List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getOffer(expectedResources)));
Assert.assertEquals(2, recommendations.size());
// Validate 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);
validateRole(reserveResource);
Assert.assertEquals(TestConstants.ROLE, ResourceUtils.getRole(reserveResource));
Assert.assertEquals(TestConstants.PRINCIPAL, reservation.getPrincipal());
Assert.assertEquals(resourceId, getResourceId(reserveResource));
// 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(2.0, launchResource.getScalar().getValue(), 0.0);
}
use of org.apache.mesos.Protos.Offer.Operation in project dcos-commons by mesosphere.
the class OfferEvaluatorTest method testLaunchNotOnFirstOffer.
@Test
public void testLaunchNotOnFirstOffer() throws Exception {
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getCpuRequirement(1.0);
Resource insufficientOffer = ResourceTestUtils.getUnreservedMem(2.0);
Resource sufficientOffer = ResourceTestUtils.getUnreservedCpus(2.0);
List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getCompleteOffer(insufficientOffer), OfferTestUtils.getCompleteOffer(sufficientOffer)));
Assert.assertEquals(5, recommendations.size());
// Validate RESERVE Operation
Operation reserveOperation = recommendations.get(0).getOperation();
Assert.assertEquals(Operation.Type.RESERVE, reserveOperation.getType());
// Validate LAUNCH Operation
Operation launchOperation = recommendations.get(4).getOperation();
Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType());
}
use of org.apache.mesos.Protos.Offer.Operation in project dcos-commons by mesosphere.
the class OfferEvaluatorTest method testIncreaseReservationScalar.
@Test
public void testIncreaseReservationScalar() throws Exception {
// Launch for the first time with 2.0 cpus offered, 1.0 cpus required.
String resourceId = getFirstResourceId(recordLaunchWithCompleteOfferedResources(PodInstanceRequirementTestUtils.getCpuRequirement(1.0), ResourceTestUtils.getUnreservedCpus(2.0)));
// Launch again with 1.0 cpus reserved, 1.0 cpus unreserved, and 2.0 cpus required.
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getCpuRequirement(2.0);
Resource offeredResource = ResourceTestUtils.getReservedCpus(1.0, resourceId);
Resource unreservedResource = ResourceTestUtils.getUnreservedCpus(1.0);
Collection<Resource> expectedResources = getExpectedExecutorResources(stateStore.fetchTasks().iterator().next().getExecutor());
expectedResources.addAll(Arrays.asList(offeredResource, unreservedResource));
List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(OfferTestUtils.getOffer(expectedResources)));
Assert.assertEquals(2, recommendations.size());
// Validate 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);
validateRole(reserveResource);
Assert.assertEquals(TestConstants.ROLE, ResourceUtils.getRole(reserveResource));
Assert.assertEquals(TestConstants.PRINCIPAL, reservation.getPrincipal());
Assert.assertEquals(resourceId, getResourceId(reserveResource));
// 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(2.0, launchResource.getScalar().getValue(), 0.0);
}
Aggregations