SchedulerUtils { @Private @VisibleForTesting static void checkResourceRequestAgainstAvailableResource(Resource reqResource, Resource availableResource) throws InvalidResourceRequestException { for (int i = 0; i < ResourceUtils.getNumberOfKnownResourceTypes(); i++) { final ResourceInformation requestedRI = reqResource.getResourceInformation(i); final String reqResourceName = requestedRI.getName(); if (requestedRI.getValue() < 0) { throwInvalidResourceException(reqResource, availableResource, reqResourceName, InvalidResourceType.LESS_THAN_ZERO); } boolean valid = checkResource(requestedRI, availableResource); if (!valid) { throwInvalidResourceException(reqResource, availableResource, reqResourceName, InvalidResourceType.GREATER_THEN_MAX_ALLOCATION); } } }  static ContainerStatus createAbnormalContainerStatus(
      ContainerId containerId, String diagnostics); static ContainerStatus createKilledContainerStatus(
      ContainerId containerId, String diagnostics); static ContainerStatus createPreemptedContainerStatus(
      ContainerId containerId, String diagnostics); @VisibleForTesting static void normalizeRequest(
    ResourceRequest ask,
    ResourceCalculator resourceCalculator,
    Resource minimumResource,
    Resource maximumResource); static Resource getNormalizedResource(
      Resource ask,
      ResourceCalculator resourceCalculator,
      Resource minimumResource,
      Resource maximumResource,
      Resource incrementResource); static void normalizeAndValidateRequest(ResourceRequest resReq,
      Resource maximumAllocation, String queueName, YarnScheduler scheduler,
      boolean isRecovery, RMContext rmContext, QueueInfo queueInfo); static void normalizeAndValidateRequest(ResourceRequest resReq,
      Resource maximumAllocation, String queueName, YarnScheduler scheduler,
      RMContext rmContext, QueueInfo queueInfo); static MaxResourceValidationResult validateResourceRequestsAgainstQueueMaxResource(
      ResourceRequest resReq, Resource availableResource); static boolean checkQueueLabelExpression(Set<String> queueLabels,
      String labelExpression, RMContext rmContext); static AccessType toAccessType(QueueACL acl); @Private static boolean hasPendingResourceRequest(ResourceCalculator rc,
      ResourceUsage usage, String nodePartition, Resource cluster,
      SchedulingMode schedulingMode); static RMContainer createOpportunisticRmContainer(RMContext rmContext,
      Container container, boolean isRemotelyAllocated); static final String RELEASED_CONTAINER; static final String UPDATED_CONTAINER; static final String LOST_CONTAINER; static final String PREEMPTED_CONTAINER; static final String COMPLETED_APPLICATION; static final String EXPIRED_CONTAINER; static final String UNRESERVED_CONTAINER; }
@Test public void testCustomResourceRequestedUnitIsSmallerThanAvailableUnit() throws InvalidResourceRequestException { Resource requestedResource = ResourceTypesTestHelper.newResource(1, 1, ImmutableMap.of("custom-resource-1", "11")); Resource availableResource = ResourceTypesTestHelper.newResource(1, 1, ImmutableMap.of("custom-resource-1", "0G")); exception.expect(InvalidResourceRequestException.class); exception.expectMessage(InvalidResourceRequestExceptionMessageGenerator .create().withRequestedResourceType("custom-resource-1") .withRequestedResource(requestedResource) .withAvailableAllocation(availableResource) .withMaxAllocation(configuredMaxAllocation) .withInvalidResourceType(GREATER_THEN_MAX_ALLOCATION) .build()); SchedulerUtils.checkResourceRequestAgainstAvailableResource( requestedResource, availableResource); }
@Test public void testCustomResourceRequestedUnitIsSmallerThanAvailableUnit2() { Resource requestedResource = ResourceTypesTestHelper.newResource(1, 1, ImmutableMap.of("custom-resource-1", "11")); Resource availableResource = ResourceTypesTestHelper.newResource(1, 1, ImmutableMap.of("custom-resource-1", "1G")); try { SchedulerUtils.checkResourceRequestAgainstAvailableResource( requestedResource, availableResource); } catch (InvalidResourceRequestException e) { fail(String.format( "Resource request should be accepted. Requested: %s, available: %s", requestedResource, availableResource)); } }
@Test public void testCustomResourceRequestedUnitIsGreaterThanAvailableUnit() throws InvalidResourceRequestException { Resource requestedResource = ResourceTypesTestHelper.newResource(1, 1, ImmutableMap.of("custom-resource-1", "1M")); Resource availableResource = ResourceTypesTestHelper.newResource(1, 1, ImmutableMap.<String, String>builder().put("custom-resource-1", "120k") .build()); exception.expect(InvalidResourceRequestException.class); exception.expectMessage(InvalidResourceRequestExceptionMessageGenerator .create().withRequestedResourceType("custom-resource-1") .withRequestedResource(requestedResource) .withAvailableAllocation(availableResource) .withMaxAllocation(configuredMaxAllocation) .withInvalidResourceType(GREATER_THEN_MAX_ALLOCATION) .build()); SchedulerUtils.checkResourceRequestAgainstAvailableResource( requestedResource, availableResource); }
@Test public void testCustomResourceRequestedUnitIsGreaterThanAvailableUnit2() { Resource requestedResource = ResourceTypesTestHelper.newResource(1, 1, ImmutableMap.<String, String>builder().put("custom-resource-1", "11M") .build()); Resource availableResource = ResourceTypesTestHelper.newResource(1, 1, ImmutableMap.of("custom-resource-1", "1G")); try { SchedulerUtils.checkResourceRequestAgainstAvailableResource( requestedResource, availableResource); } catch (InvalidResourceRequestException e) { fail(String.format( "Resource request should be accepted. Requested: %s, available: %s", requestedResource, availableResource)); } }
@Test public void testCustomResourceRequestedUnitIsSameAsAvailableUnit() { Resource requestedResource = ResourceTypesTestHelper.newResource(1, 1, ImmutableMap.of("custom-resource-1", "11M")); Resource availableResource = ResourceTypesTestHelper.newResource(1, 1, ImmutableMap.of("custom-resource-1", "100M")); try { SchedulerUtils.checkResourceRequestAgainstAvailableResource( requestedResource, availableResource); } catch (InvalidResourceRequestException e) { fail(String.format( "Resource request should be accepted. Requested: %s, available: %s", requestedResource, availableResource)); } }
@Test public void testCustomResourceRequestedUnitIsSameAsAvailableUnit2() throws InvalidResourceRequestException { Resource requestedResource = ResourceTypesTestHelper.newResource(1, 1, ImmutableMap.of("custom-resource-1", "110M")); Resource availableResource = ResourceTypesTestHelper.newResource(1, 1, ImmutableMap.of("custom-resource-1", "100M")); exception.expect(InvalidResourceRequestException.class); exception.expectMessage(InvalidResourceRequestExceptionMessageGenerator .create().withRequestedResourceType("custom-resource-1") .withRequestedResource(requestedResource) .withAvailableAllocation(availableResource) .withInvalidResourceType(GREATER_THEN_MAX_ALLOCATION) .withMaxAllocation(configuredMaxAllocation) .build()); SchedulerUtils.checkResourceRequestAgainstAvailableResource( requestedResource, availableResource); }