org.apache.mesos.Protos.Offer.Operation Java Examples
The following examples show how to use
org.apache.mesos.Protos.Offer.Operation.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UnreserveOfferRecommendation.java From dcos-commons with Apache License 2.0 | 6 votes |
public UnreserveOfferRecommendation(Offer offer, Resource resource) { this.offer = offer; Resource.Builder resourceBuilder = resource.toBuilder(); Resource resourceR; // If non-root disk resource, we want to clear ALL fields except for the field indicating the disk source. if (resource.hasDisk() && resource.getDisk().hasSource()) { resourceR = resourceBuilder .setDisk(Resource.DiskInfo.newBuilder().setSource(resource.getDisk().getSource())) .build(); } else { resourceR = resourceBuilder.clearDisk().clearRevocable().build(); } this.operation = Operation.newBuilder() .setType(Operation.Type.UNRESERVE) .setUnreserve( Operation.Unreserve.newBuilder().addAllResources(Collections.singletonList(resourceR)) ) .build(); this.resource = resourceR; }
Example #2
Source File: OfferEvaluatorPortsTest.java From dcos-commons with Apache License 2.0 | 6 votes |
@Test public void testReserveTaskDynamicPort() throws Exception { Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000); PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(0); List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, OfferTestUtils.getCompleteOffers(offeredPorts)); Assert.assertEquals(6, recommendations.size()); Protos.Offer.Operation launchOperation = recommendations.get(4).getOperation().get(); Assert.assertFalse(recommendations.get(5).getOperation().isPresent()); Protos.TaskInfo taskInfo = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0); Protos.Resource fulfilledPortResource = taskInfo.getResources(0); Assert.assertFalse(getResourceId(fulfilledPortResource).isEmpty()); Map<String, Protos.Environment.Variable> envvars = EnvUtils.toMap(taskInfo.getCommand().getEnvironment()); Assert.assertEquals(envvars.toString(), String.valueOf(10000), envvars.get(TestConstants.PORT_ENV_NAME + "_0").getValue()); }
Example #3
Source File: OfferEvaluatorPortsTest.java From dcos-commons with Apache License 2.0 | 5 votes |
@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(6, recommendations.size()); Operation launchOperation = recommendations.get(4).getOperation().get(); Assert.assertFalse(recommendations.get(5).getOperation().isPresent()); 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, Protos.Environment.Variable> envvars = EnvUtils.toMap(taskInfo.getCommand().getEnvironment()); Assert.assertEquals(String.valueOf(10000), envvars.get(TestConstants.PORT_ENV_NAME + "_VIP_0").getValue()); }
Example #4
Source File: SchedulerDriverService.java From attic-aurora with Apache License 2.0 | 5 votes |
@Override public void acceptOffers( Protos.OfferID offerId, Collection<Protos.Offer.Operation> operations, Protos.Filters filter) { ensureRunning(); OfferID convertedOfferId = ProtosConversion.convert(offerId); Collection<Operation> convertedOperations = Collections2.transform(operations, ProtosConversion::convert); Filters convertedFilter = ProtosConversion.convert(filter); Futures.getUnchecked(driverFuture) .acceptOffers(ImmutableList.of(convertedOfferId), convertedOperations, convertedFilter); }
Example #5
Source File: OfferEvaluatorPortsTest.java From dcos-commons with Apache License 2.0 | 5 votes |
@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(6, recommendations.size()); Operation launchOperation = recommendations.get(4).getOperation().get(); Assert.assertFalse(recommendations.get(5).getOperation().isPresent()); 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, Protos.Environment.Variable> envvars = EnvUtils.toMap(taskInfo.getCommand().getEnvironment()); Assert.assertEquals(String.valueOf(10000), envvars.get(TestConstants.PORT_ENV_NAME + "_VIP_10000").getValue()); }
Example #6
Source File: OfferEvaluatorPortsTest.java From dcos-commons with Apache License 2.0 | 5 votes |
@Test public void testLaunchExpectedMultiplePorts() throws Exception { // Launch for the first time: get ports 10000,10001 PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(10000, 10001); List<Resource> reserveResources = recordLaunchWithCompleteOfferedResources( podInstanceRequirement, ResourceTestUtils.getUnreservedPorts(10000, 10001)); Assert.assertEquals(reserveResources.toString(), 5, reserveResources.size()); String resourceId0 = getResourceId(reserveResources.get(3)); String resourceId1 = getResourceId(reserveResources.get(4)); Collection<Resource> expectedResources = getExpectedExecutorResources( stateStore.fetchTasks().iterator().next().getExecutor()); expectedResources.addAll(Arrays.asList( ResourceTestUtils.getReservedPorts(10000, 10000, resourceId0), ResourceTestUtils.getReservedPorts(10001, 10001, resourceId1))); // Now try relaunch: List<OfferRecommendation> recommendations = evaluator.evaluate( PodInstanceRequirementTestUtils.getPortRequirement(10000, 10001), Arrays.asList(OfferTestUtils.getOffer(expectedResources))); Assert.assertEquals(2, recommendations.size()); // Validate LAUNCH Operation Operation launchOperation = recommendations.get(0).getOperation().get(); Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType()); List<Resource> launchResources = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0).getResourcesList(); Assert.assertEquals(launchResources.toString(), 2, launchResources.size()); Assert.assertEquals(resourceId0, getResourceId(launchResources.get(0))); Assert.assertEquals(resourceId1, getResourceId(launchResources.get(1))); Assert.assertFalse(recommendations.get(1).getOperation().isPresent()); }
Example #7
Source File: OfferEvaluatorPortsTest.java From dcos-commons with Apache License 2.0 | 5 votes |
@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(3); 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(Arrays.asList( Protos.Offer.Operation.Type.UNRESERVE, Protos.Offer.Operation.Type.RESERVE, Offer.Operation.Type.LAUNCH_GROUP, null), recommendations.stream() .map(rec -> rec.getOperation().isPresent() ? rec.getOperation().get().getType() : null) .collect(Collectors.toList())); Operation launchOperation = recommendations.get(2).getOperation().get(); TaskInfo taskInfo = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0); Map<String, Protos.Environment.Variable> envvars = EnvUtils.toMap(taskInfo.getCommand().getEnvironment()); Assert.assertEquals(String.valueOf(666), envvars.get(TestConstants.PORT_ENV_NAME + "_666").getValue()); }
Example #8
Source File: OfferEvaluatorPortsTest.java From dcos-commons with Apache License 2.0 | 5 votes |
@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(3); 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(Arrays.asList( Protos.Offer.Operation.Type.UNRESERVE, Protos.Offer.Operation.Type.RESERVE, Offer.Operation.Type.LAUNCH_GROUP, null), recommendations.stream() .map(rec -> rec.getOperation().isPresent() ? rec.getOperation().get().getType() : null) .collect(Collectors.toList())); Operation launchOperation = recommendations.get(2).getOperation().get(); TaskInfo taskInfo = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0); Map<String, Protos.Environment.Variable> envvars = EnvUtils.toMap(taskInfo.getCommand().getEnvironment()); Assert.assertEquals(String.valueOf(666), envvars.get(TestConstants.PORT_ENV_NAME + "_666").getValue()); }
Example #9
Source File: OfferEvaluatorPortsTest.java From dcos-commons with Apache License 2.0 | 5 votes |
@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(3); 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(2, recommendations.size()); // Validate LAUNCH Operation Operation launchOperation = recommendations.get(0).getOperation().get(); Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType()); Resource launchResource = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0).getResources(0); Assert.assertEquals(resourceId, getResourceId(launchResource)); Assert.assertFalse(recommendations.get(1).getOperation().isPresent()); }
Example #10
Source File: OfferEvaluatorPortsTest.java From dcos-commons with Apache License 2.0 | 5 votes |
@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(3); 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(2, recommendations.size()); // Validate LAUNCH Operation Protos.Offer.Operation launchOperation = recommendations.get(0).getOperation().get(); Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType()); Protos.Resource launchResource = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0).getResources(0); Assert.assertEquals(resourceId, getResourceId(launchResource)); Assert.assertFalse(recommendations.get(1).getOperation().isPresent()); }
Example #11
Source File: OfferEvaluatorPortsTest.java From dcos-commons with Apache License 2.0 | 5 votes |
@Test public void testReserveStaticPort() throws Exception { PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(555); Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(555, 555); List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, OfferTestUtils.getCompleteOffers(offeredPorts)); Assert.assertEquals(Arrays.asList( Protos.Offer.Operation.Type.RESERVE, Protos.Offer.Operation.Type.RESERVE, Protos.Offer.Operation.Type.RESERVE, Protos.Offer.Operation.Type.RESERVE, Offer.Operation.Type.LAUNCH_GROUP, null), recommendations.stream() .map(rec -> rec.getOperation().isPresent() ? rec.getOperation().get().getType() : null) .collect(Collectors.toList())); Protos.Offer.Operation launchOperation = recommendations.get(4).getOperation().get(); Protos.TaskInfo taskInfo = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0); Protos.Resource fulfilledPortResource = taskInfo.getResources(0); Assert.assertFalse(getResourceId(fulfilledPortResource).isEmpty()); Map<String, Protos.Environment.Variable> envvars = EnvUtils.toMap(taskInfo.getCommand().getEnvironment()); Assert.assertEquals(String.valueOf(555), envvars.get(TestConstants.PORT_ENV_NAME + "_555").getValue()); }
Example #12
Source File: OfferEvaluatorPortsTest.java From dcos-commons with Apache License 2.0 | 4 votes |
@Test public void testReserveTaskMultipleDynamicPorts() throws Exception { 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.getCompleteOffers(ResourceTestUtils.getUnreservedPorts(10000, 10001))); Assert.assertEquals(Arrays.asList( Protos.Offer.Operation.Type.RESERVE, Protos.Offer.Operation.Type.RESERVE, Protos.Offer.Operation.Type.RESERVE, Protos.Offer.Operation.Type.RESERVE, Protos.Offer.Operation.Type.RESERVE, Offer.Operation.Type.LAUNCH_GROUP, null), recommendations.stream() .map(rec -> rec.getOperation().isPresent() ? rec.getOperation().get().getType() : null) .collect(Collectors.toList())); Operation reserveOperation = recommendations.get(3).getOperation().get(); 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(4).getOperation().get(); 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(5).getOperation().get(); TaskInfo taskInfo = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0); Assert.assertEquals(getResourceId(taskInfo.getResources(0)), getResourceId(fulfilledPortResource1)); Assert.assertEquals(getResourceId(taskInfo.getResources(1)), getResourceId(fulfilledPortResource2)); Map<String, Protos.Environment.Variable> envvars = EnvUtils.toMap(taskInfo.getCommand().getEnvironment()); Assert.assertEquals(String.valueOf(10000), envvars.get(portenv0).getValue()); Assert.assertEquals(String.valueOf(10001), envvars.get(portenv1).getValue()); 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()); }
Example #13
Source File: OfferEvaluatorVolumesTest.java From dcos-commons with Apache License 2.0 | 4 votes |
@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_GROUP, null: Assert.assertEquals(8, recommendations.size()); // Validate CPU RESERVE Operation Operation reserveOperation = recommendations.get(3).getOperation().get(); 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()); Assert.assertEquals(TestConstants.FRAMEWORK_ID.getValue(), ResourceUtils.getFrameworkId(reserveResource).get()); // Validate DISK RESERVE Operation reserveOperation = recommendations.get(4).getOperation().get(); 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()); Assert.assertEquals(TestConstants.FRAMEWORK_ID.getValue(), ResourceUtils.getFrameworkId(reserveResource).get()); // Validate CREATE Operation String resourceId = getResourceId(reserveResource); Operation createOperation = recommendations.get(5).getOperation().get(); 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().get(); 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()); }
Example #14
Source File: OfferEvaluatorVolumesTest.java From dcos-commons with Apache License 2.0 | 4 votes |
@Test public void testExpectedRootVolume() throws Exception { // Launch for the first time. Resource offeredCpuResource = ResourceTestUtils.getUnreservedCpus(1.0); Resource offeredDiskResource = ResourceTestUtils.getUnreservedDisk(2000); PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getRootVolumeRequirement(1.0, 1500); List<OfferRecommendation> recommendations = evaluator.evaluate( podInstanceRequirement, Arrays.asList(OfferTestUtils.getCompleteOffer(Arrays.asList(offeredDiskResource, offeredCpuResource)))); String executorCpuResourceId = ResourceTestUtils.getResourceId( recommendations.get(0).getOperation().get().getReserve().getResources(0)); String executorDiskResourceId = ResourceTestUtils.getResourceId( recommendations.get(1).getOperation().get().getReserve().getResources(0)); String executorMemResourceId = ResourceTestUtils.getResourceId( recommendations.get(2).getOperation().get().getReserve().getResources(0)); String cpuResourceId = ResourceTestUtils.getResourceId( recommendations.get(3).getOperation().get().getReserve().getResources(0)); Operation createOperation = recommendations.get(5).getOperation().get(); Resource createResource = createOperation.getCreate().getVolumes(0); String diskResourceId = ResourceTestUtils.getResourceId(createResource); String persistenceId = ResourceTestUtils.getPersistenceId(createResource); // Last entry is a StoreTaskInfoRecommendation, which doesn't have an Operation: Operation launchOperation = recommendations.get(recommendations.size()-2).getOperation().get(); Protos.ExecutorInfo executorInfo = launchOperation.getLaunchGroup().getExecutor(); Collection<Protos.TaskInfo> taskInfos = launchOperation.getLaunchGroup().getTaskGroup().getTasksList().stream() .map(t -> t.toBuilder().setExecutor(executorInfo).build()) .collect(Collectors.toList()); stateStore.storeTasks(taskInfos); // Launch again on expected resources. Resource expectedCpu = ResourceTestUtils.getReservedCpus(1.0, cpuResourceId); Resource expectedDisk = ResourceTestUtils.getReservedRootVolume(1500, diskResourceId, persistenceId); Resource expectedExecutorCpu = ResourceTestUtils.getReservedCpus(0.1, executorCpuResourceId); Resource expectedExecutorMem = ResourceTestUtils.getReservedMem(32, executorMemResourceId); Resource expectedExecutorDisk = ResourceTestUtils.getReservedDisk(256, executorDiskResourceId); recommendations = evaluator.evaluate( podInstanceRequirement, Arrays.asList(OfferTestUtils.getOffer(Arrays.asList( expectedCpu, expectedDisk, expectedExecutorCpu, expectedExecutorMem, expectedExecutorDisk)))); // Launch + StoreTask: Assert.assertEquals(2, recommendations.size()); launchOperation = recommendations.get(0).getOperation().get(); Protos.TaskInfo launchTask = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0); Assert.assertEquals(recommendations.toString(), 2, launchTask.getResourcesCount()); Resource launchResource = launchTask.getResources(1); Resource.ReservationInfo reservation = ResourceUtils.getReservation(launchResource).get(); Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType()); Assert.assertEquals(1500, launchResource.getScalar().getValue(), 0.0); OfferEvaluatorTest.validateRole(launchResource); Assert.assertEquals(TestConstants.ROLE, ResourceUtils.getRole(launchResource)); Assert.assertEquals(persistenceId, launchResource.getDisk().getPersistence().getId()); Assert.assertEquals(TestConstants.PRINCIPAL, launchResource.getDisk().getPersistence().getPrincipal()); Assert.assertEquals(TestConstants.PRINCIPAL, reservation.getPrincipal()); Assert.assertEquals(diskResourceId, getResourceId(launchResource)); Assert.assertFalse(recommendations.get(1).getOperation().isPresent()); }
Example #15
Source File: OfferEvaluatorVolumesTest.java From dcos-commons with Apache License 2.0 | 4 votes |
@Test public void testReserveCreateLaunchMountVolume() throws Exception { Resource offeredCpuResource = ResourceTestUtils.getUnreservedCpus(1.0); Resource offeredDiskResource = ResourceTestUtils.getUnreservedMountVolume(2000, Optional.empty()); List<OfferRecommendation> recommendations = evaluator.evaluate( PodInstanceRequirementTestUtils.getMountVolumeRequirement(1.0, 1500), Arrays.asList(OfferTestUtils.getCompleteOffer(Arrays.asList(offeredCpuResource, offeredDiskResource)))); Assert.assertEquals(Arrays.asList( Operation.Type.RESERVE, Operation.Type.RESERVE, Operation.Type.RESERVE, Operation.Type.RESERVE, Operation.Type.RESERVE, Operation.Type.CREATE, Operation.Type.LAUNCH_GROUP, null), recommendations.stream() .map(r -> r.getOperation().isPresent() ? r.getOperation().get().getType() : null) .collect(Collectors.toList())); // Validate RESERVE Operation Operation reserveOperation = recommendations.get(4).getOperation().get(); 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_DISK_SOURCE, reserveResource.getDisk().getSource()); 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(5).getOperation().get(); Resource createResource = createOperation.getCreate().getVolumes(0); Assert.assertEquals(resourceId, getResourceId(createResource)); Assert.assertEquals(36, createResource.getDisk().getPersistence().getId().length()); Assert.assertEquals(TestConstants.MOUNT_DISK_SOURCE, createResource.getDisk().getSource()); Assert.assertEquals(TestConstants.PRINCIPAL, createResource.getDisk().getPersistence().getPrincipal()); Assert.assertTrue(createResource.getDisk().hasVolume()); Assert.assertEquals(TestConstants.FRAMEWORK_ID.getValue(), ResourceUtils.getFrameworkId(reserveResource).get()); // Validate LAUNCH Operation String persistenceId = createResource.getDisk().getPersistence().getId(); Operation launchOperation = recommendations.get(6).getOperation().get(); 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_DISK_SOURCE, launchResource.getDisk().getSource()); Assert.assertEquals(TestConstants.PRINCIPAL, launchResource.getDisk().getPersistence().getPrincipal()); Assert.assertEquals(2000, launchResource.getScalar().getValue(), 0.0); }
Example #16
Source File: OfferEvaluatorVolumesTest.java From dcos-commons with Apache License 2.0 | 4 votes |
@Test public void testExpectedMountVolume() throws Exception { // Launch for the first time. Resource offeredCpuResource = ResourceTestUtils.getUnreservedCpus(1.0); Resource offeredDiskResource = ResourceTestUtils.getUnreservedMountVolume(2000, Optional.empty()); PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getMountVolumeRequirement(1.0, 1500); List<OfferRecommendation> recommendations = evaluator.evaluate( podInstanceRequirement, Arrays.asList(OfferTestUtils.getCompleteOffer(Arrays.asList(offeredDiskResource, offeredCpuResource)))); String executorCpuResourceId = ResourceTestUtils.getResourceId( recommendations.get(0).getOperation().get().getReserve().getResources(0)); String executorDiskResourceId = ResourceTestUtils.getResourceId( recommendations.get(1).getOperation().get().getReserve().getResources(0)); String executorMemResourceId = ResourceTestUtils.getResourceId( recommendations.get(2).getOperation().get().getReserve().getResources(0)); String cpuResourceId = ResourceTestUtils.getResourceId( recommendations.get(3).getOperation().get().getReserve().getResources(0)); Resource createResource = recommendations.get(5).getOperation().get().getCreate().getVolumes(0); String diskResourceId = ResourceTestUtils.getResourceId(createResource); String persistenceId = ResourceTestUtils.getPersistenceId(createResource); // Last entry is a StoreTaskInfoRecommendation, which doesn't have an Operation: Operation launchOperation = recommendations.get(recommendations.size()-2).getOperation().get(); Protos.ExecutorInfo executorInfo = launchOperation.getLaunchGroup().getExecutor(); Collection<Protos.TaskInfo> taskInfos = launchOperation.getLaunchGroup().getTaskGroup().getTasksList().stream() .map(t -> t.toBuilder().setExecutor(executorInfo).build()) .collect(Collectors.toList()); stateStore.storeTasks(taskInfos); // Launch again on expected resources. Resource expectedCpu = ResourceTestUtils.getReservedCpus(1.0, cpuResourceId); Resource expectedDisk = ResourceTestUtils.getReservedMountVolume(2000, Optional.empty(), diskResourceId, persistenceId); Resource expectedExecutorCpu = ResourceTestUtils.getReservedCpus(0.1, executorCpuResourceId); Resource expectedExecutorMem = ResourceTestUtils.getReservedMem(32, executorMemResourceId); Resource expectedExecutorDisk = ResourceTestUtils.getReservedDisk(256, executorDiskResourceId); recommendations = evaluator.evaluate( podInstanceRequirement, Arrays.asList(OfferTestUtils.getCompleteOffer(Arrays.asList( expectedCpu, expectedDisk, expectedExecutorCpu, expectedExecutorMem, expectedExecutorDisk)))); // Launch + StoreTask: Assert.assertEquals(2, recommendations.size()); launchOperation = recommendations.get(0).getOperation().get(); Protos.TaskInfo launchTask = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0); Assert.assertEquals(recommendations.toString(), 2, launchTask.getResourcesCount()); Resource launchResource = launchTask.getResources(1); Assert.assertEquals(Operation.Type.LAUNCH_GROUP, launchOperation.getType()); Assert.assertEquals(2000, launchResource.getScalar().getValue(), 0.0); OfferEvaluatorTest.validateRole(launchResource); Assert.assertEquals(TestConstants.ROLE, ResourceUtils.getRole(launchResource)); Assert.assertEquals(TestConstants.MOUNT_DISK_SOURCE, launchResource.getDisk().getSource()); Assert.assertEquals(persistenceId, launchResource.getDisk().getPersistence().getId()); Assert.assertEquals(TestConstants.PRINCIPAL, launchResource.getDisk().getPersistence().getPrincipal()); validatePrincipal(launchResource); Assert.assertEquals(diskResourceId, getResourceId(launchResource)); Assert.assertFalse(recommendations.get(1).getOperation().isPresent()); }
Example #17
Source File: OfferEvaluatorVolumesTest.java From dcos-commons with Apache License 2.0 | 4 votes |
@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) .addRootVolume(1.0, TestConstants.CONTAINER_PATH + "-a") .addRootVolume(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(10, recommendations.size()); Assert.assertEquals(Arrays.asList( Operation.Type.RESERVE, Operation.Type.RESERVE, Operation.Type.RESERVE, Operation.Type.RESERVE, Operation.Type.RESERVE, Operation.Type.CREATE, Operation.Type.RESERVE, Operation.Type.CREATE, Operation.Type.LAUNCH_GROUP, null), recommendations.stream() .map(r -> r.getOperation().isPresent() ? r.getOperation().get().getType() : null) .collect(Collectors.toList())); // Validate Create Operation Operation createOperation = recommendations.get(5).getOperation().get(); Assert.assertEquals( TestConstants.CONTAINER_PATH + "-a", createOperation.getCreate().getVolumes(0).getDisk().getVolume().getContainerPath()); // Validate Create Operation createOperation = recommendations.get(7).getOperation().get(); Assert.assertEquals( TestConstants.CONTAINER_PATH + "-b", createOperation.getCreate().getVolumes(0).getDisk().getVolume().getContainerPath()); // Validate Launch Operation Operation launchOperation = recommendations.get(8).getOperation().get(); for (Protos.TaskInfo taskInfo : launchOperation.getLaunch().getTaskInfosList()) { for (Resource resource : taskInfo.getResourcesList()) { Assert.assertFalse(getResourceId(resource).isEmpty()); } } }
Example #18
Source File: OfferEvaluatorVolumesTest.java From dcos-commons with Apache License 2.0 | 4 votes |
@Test public void testCreateMultipleProfileMountVolumes() throws Exception { ResourceSet resourceSet = DefaultResourceSet.newBuilder(TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL) .id(TestConstants.RESOURCE_SET_ID) .cpus(1.0) .addMountVolume(1.0, TestConstants.CONTAINER_PATH + "-a", Arrays.asList("x")) .addMountVolume(1.0, TestConstants.CONTAINER_PATH + "-b", Arrays.asList("x", "y")) .addMountVolume(1.0, TestConstants.CONTAINER_PATH + "-c", Collections.emptyList()) .build(); PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getRequirement(resourceSet, 0); List<Resource> offeredResources = Arrays.asList( ResourceTestUtils.getUnreservedCpus(1.0), ResourceTestUtils.getUnreservedMountVolume(1.0, Optional.empty()), ResourceTestUtils.getUnreservedMountVolume(1.0, Optional.of("x")), ResourceTestUtils.getUnreservedMountVolume(1.0, Optional.of("y"))); Protos.Offer offer = OfferTestUtils.getCompleteOffer(offeredResources); List<OfferRecommendation> recommendations = evaluator.evaluate( podInstanceRequirement, Arrays.asList(offer)); Assert.assertEquals(Arrays.asList( Operation.Type.RESERVE, Operation.Type.RESERVE, Operation.Type.RESERVE, Operation.Type.RESERVE, Operation.Type.RESERVE, Operation.Type.CREATE, Operation.Type.RESERVE, Operation.Type.CREATE, Operation.Type.RESERVE, Operation.Type.CREATE, Operation.Type.LAUNCH_GROUP, null), recommendations.stream() .map(r -> r.getOperation().isPresent() ? r.getOperation().get().getType() : null) .collect(Collectors.toList())); // Validate Create Operation Operation createOperation = recommendations.get(5).getOperation().get(); Assert.assertEquals( TestConstants.CONTAINER_PATH + "-a", createOperation.getCreate().getVolumes(0).getDisk().getVolume().getContainerPath()); Assert.assertEquals("x", createOperation.getCreate().getVolumes(0).getDisk().getSource().getProfile()); // Validate Create Operation createOperation = recommendations.get(7).getOperation().get(); Assert.assertEquals( TestConstants.CONTAINER_PATH + "-b", createOperation.getCreate().getVolumes(0).getDisk().getVolume().getContainerPath()); Assert.assertEquals("y", createOperation.getCreate().getVolumes(0).getDisk().getSource().getProfile()); // Validate Create Operation createOperation = recommendations.get(9).getOperation().get(); Assert.assertEquals( TestConstants.CONTAINER_PATH + "-c", createOperation.getCreate().getVolumes(0).getDisk().getVolume().getContainerPath()); Assert.assertFalse(createOperation.getCreate().getVolumes(0).getDisk().getSource().hasProfile()); // Validate Launch Operation Operation launchOperation = recommendations.get(10).getOperation().get(); for (Protos.TaskInfo taskInfo : launchOperation.getLaunch().getTaskInfosList()) { for (Resource resource : taskInfo.getResourcesList()) { Assert.assertFalse(getResourceId(resource).isEmpty()); } } }
Example #19
Source File: OfferEvaluatorVolumesTest.java From dcos-commons with Apache License 2.0 | 4 votes |
@Test public void testReserveCreateExecutorVolume() throws Exception { List<Resource> offeredResources = Arrays.asList( ResourceTestUtils.getUnreservedMountVolume(2000, Optional.empty()), ResourceTestUtils.getUnreservedCpus(1.0)); Protos.Offer offer = OfferTestUtils.getCompleteOffer(offeredResources); PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getExecutorRequirement( PodInstanceRequirementTestUtils.getCpuResourceSet(1.0), Arrays.asList( DefaultVolumeSpec.createMountVolume( 1000, TestConstants.CONTAINER_PATH, Collections.emptyList(), TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL)), TestConstants.POD_TYPE, 0); List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(offer)); Assert.assertEquals(8, recommendations.size()); // Validate just the operations pertaining to the executor // Validate RESERVE Operation Operation reserveOperation = recommendations.get(0).getOperation().get(); Resource reserveResource = reserveOperation.getReserve().getResources(0); Assert.assertEquals(Operation.Type.RESERVE, reserveOperation.getType()); Assert.assertEquals(2000, reserveResource.getScalar().getValue(), 0.0); OfferEvaluatorTest.validateRole(reserveResource); Assert.assertEquals(TestConstants.ROLE, ResourceUtils.getRole(reserveResource)); Assert.assertEquals(TestConstants.MOUNT_DISK_SOURCE, reserveResource.getDisk().getSource()); validatePrincipal(reserveResource); Assert.assertEquals(36, getResourceId(reserveResource).length()); // Validate CREATE Operation String resourceId = getResourceId(reserveResource); Operation createOperation = recommendations.get(1).getOperation().get(); Resource createResource = createOperation.getCreate().getVolumes(0); Assert.assertEquals(resourceId, getResourceId(createResource)); Assert.assertEquals(36, createResource.getDisk().getPersistence().getId().length()); Assert.assertEquals(TestConstants.MOUNT_DISK_SOURCE, createResource.getDisk().getSource()); Assert.assertEquals(TestConstants.PRINCIPAL, createResource.getDisk().getPersistence().getPrincipal()); Assert.assertTrue(createResource.getDisk().hasVolume()); }
Example #20
Source File: OfferEvaluatorVolumesTest.java From dcos-commons with Apache License 2.0 | 4 votes |
@Test public void testRelaunchExecutorVolumeFailure() throws Exception { // Create for the first time. List<Resource> offeredResources = Arrays.asList( ResourceTestUtils.getUnreservedMountVolume(2000, Optional.empty()), ResourceTestUtils.getUnreservedCpus(1.0)); Protos.Offer offer = OfferTestUtils.getCompleteOffer(offeredResources); PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getExecutorRequirement( PodInstanceRequirementTestUtils.getCpuResourceSet(1.0), Arrays.asList( DefaultVolumeSpec.createMountVolume( 1000, TestConstants.CONTAINER_PATH, Collections.emptyList(), TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL)), TestConstants.POD_TYPE, 0); List<OfferRecommendation> recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(offer)); Assert.assertEquals(Arrays.asList( Operation.Type.RESERVE, Operation.Type.CREATE, Operation.Type.RESERVE, Operation.Type.RESERVE, Operation.Type.RESERVE, Operation.Type.RESERVE, Operation.Type.LAUNCH_GROUP, null), recommendations.stream() .map(r -> r.getOperation().isPresent() ? r.getOperation().get().getType() : null) .collect(Collectors.toList())); // Validate RESERVE Operation Operation reserveOperation = recommendations.get(0).getOperation().get(); Resource reserveResource = reserveOperation.getReserve().getResources(0); String resourceId = getResourceId(reserveResource); // Validate CREATE Operation Operation createOperation = recommendations.get(1).getOperation().get(); Resource createResource = createOperation.getCreate().getVolumes(0); String persistenceId = createResource.getDisk().getPersistence().getId(); // Evaluation for a second time offeredResources = Arrays.asList( ResourceTestUtils.getReservedMountVolume(2000, Optional.empty(), resourceId, persistenceId), ResourceTestUtils.getReservedCpus(1.0, resourceId)); offer = OfferTestUtils.getCompleteOffer(offeredResources); recommendations = evaluator.evaluate(podInstanceRequirement, Arrays.asList(offer)); Assert.assertEquals(0, recommendations.size()); }
Example #21
Source File: MockSchedulerDriver.java From incubator-myriad with Apache License 2.0 | 4 votes |
@Override public Status acceptOffers(Collection<OfferID> offerIds, Collection<Operation> operations, Filters filters) { return null; }
Example #22
Source File: UnreserveOfferRecommendation.java From dcos-commons with Apache License 2.0 | 4 votes |
@Override public Optional<Protos.Offer.Operation> getOperation() { return Optional.of(operation); }