SchedulerUtils { public static void enforcePartitionExclusivity(ResourceRequest resReq, Set<String> enforcedPartitions, String appLabel) { if (enforcedPartitions == null || enforcedPartitions.isEmpty()) { return; } if (!enforcedPartitions.contains(appLabel) && enforcedPartitions.contains(resReq.getNodeLabelExpression())) { resReq.setNodeLabelExpression(appLabel); } if (enforcedPartitions.contains(appLabel)) { resReq.setNodeLabelExpression(appLabel); } }  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, boolean isRecovery,
      RMContext rmContext, QueueInfo queueInfo, boolean nodeLabelsEnabled); static void normalizeAndValidateRequest(ResourceRequest resReq,
      Resource maximumAllocation, String queueName, RMContext rmContext,
      QueueInfo queueInfo, boolean nodeLabelsEnabled); static void enforcePartitionExclusivity(ResourceRequest resReq,
      Set<String> enforcedPartitions, String appLabel); 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 testEnforcePartitionExclusivity() { String enforcedExclusiveLabel = "x"; Set<String> enforcedExclusiveLabelSet = Collections.singleton(enforcedExclusiveLabel); String dummyLabel = "y"; String appLabel = "appLabel"; ResourceRequest rr = BuilderUtils.newResourceRequest( mock(Priority.class), ResourceRequest.ANY, mock(Resource.class), 1); SchedulerUtils.enforcePartitionExclusivity(rr, enforcedExclusiveLabelSet, null); Assert.assertNull(rr.getNodeLabelExpression()); SchedulerUtils.enforcePartitionExclusivity(rr, enforcedExclusiveLabelSet, appLabel); Assert.assertNull(rr.getNodeLabelExpression()); rr.setNodeLabelExpression(dummyLabel); SchedulerUtils.enforcePartitionExclusivity(rr, enforcedExclusiveLabelSet, null); Assert.assertEquals(dummyLabel, rr.getNodeLabelExpression()); SchedulerUtils.enforcePartitionExclusivity(rr, enforcedExclusiveLabelSet, appLabel); Assert.assertEquals(dummyLabel, rr.getNodeLabelExpression()); rr.setNodeLabelExpression(enforcedExclusiveLabel); SchedulerUtils.enforcePartitionExclusivity(rr, enforcedExclusiveLabelSet, null); Assert.assertNull(rr.getNodeLabelExpression()); rr.setNodeLabelExpression(enforcedExclusiveLabel); SchedulerUtils.enforcePartitionExclusivity(rr, enforcedExclusiveLabelSet, appLabel); Assert.assertEquals(appLabel, rr.getNodeLabelExpression()); rr.setNodeLabelExpression(null); SchedulerUtils.enforcePartitionExclusivity(rr, enforcedExclusiveLabelSet, enforcedExclusiveLabel); Assert.assertEquals(enforcedExclusiveLabel, rr.getNodeLabelExpression()); rr.setNodeLabelExpression(dummyLabel); SchedulerUtils.enforcePartitionExclusivity(rr, enforcedExclusiveLabelSet, enforcedExclusiveLabel); Assert.assertEquals(enforcedExclusiveLabel, rr.getNodeLabelExpression()); rr.setNodeLabelExpression(enforcedExclusiveLabel); SchedulerUtils.enforcePartitionExclusivity(rr, enforcedExclusiveLabelSet, enforcedExclusiveLabel); Assert.assertEquals(enforcedExclusiveLabel, rr.getNodeLabelExpression()); rr.setNodeLabelExpression(null); SchedulerUtils.enforcePartitionExclusivity(rr, null, appLabel); Assert.assertNull(rr.getNodeLabelExpression()); rr.setNodeLabelExpression(dummyLabel); SchedulerUtils.enforcePartitionExclusivity(rr, null, appLabel); Assert.assertEquals(dummyLabel, rr.getNodeLabelExpression()); rr.setNodeLabelExpression(enforcedExclusiveLabel); SchedulerUtils.enforcePartitionExclusivity(rr, null, appLabel); Assert.assertEquals(enforcedExclusiveLabel, rr.getNodeLabelExpression()); }
@Test public void testEnforcePartitionExclusivityMultipleLabels() { String enforcedLabel1 = "x"; String enforcedLabel2 = "y"; Set<String> enforcedExclusiveLabelSet = new HashSet<>(); enforcedExclusiveLabelSet.add(enforcedLabel1); enforcedExclusiveLabelSet.add(enforcedLabel2); String dummyLabel = "dummyLabel"; String appLabel = "appLabel"; ResourceRequest rr = BuilderUtils.newResourceRequest( mock(Priority.class), ResourceRequest.ANY, mock(Resource.class), 1); SchedulerUtils.enforcePartitionExclusivity(rr, enforcedExclusiveLabelSet, null); Assert.assertNull(rr.getNodeLabelExpression()); SchedulerUtils.enforcePartitionExclusivity(rr, enforcedExclusiveLabelSet, appLabel); Assert.assertNull(rr.getNodeLabelExpression()); rr.setNodeLabelExpression(dummyLabel); SchedulerUtils.enforcePartitionExclusivity(rr, enforcedExclusiveLabelSet, null); Assert.assertEquals(dummyLabel, rr.getNodeLabelExpression()); SchedulerUtils.enforcePartitionExclusivity(rr, enforcedExclusiveLabelSet, appLabel); Assert.assertEquals(dummyLabel, rr.getNodeLabelExpression()); rr.setNodeLabelExpression(enforcedLabel1); SchedulerUtils.enforcePartitionExclusivity(rr, enforcedExclusiveLabelSet, null); Assert.assertNull(rr.getNodeLabelExpression()); rr.setNodeLabelExpression(enforcedLabel2); SchedulerUtils.enforcePartitionExclusivity(rr, enforcedExclusiveLabelSet, appLabel); Assert.assertEquals(appLabel, rr.getNodeLabelExpression()); rr.setNodeLabelExpression(null); SchedulerUtils.enforcePartitionExclusivity(rr, enforcedExclusiveLabelSet, enforcedLabel1); Assert.assertEquals(enforcedLabel1, rr.getNodeLabelExpression()); rr.setNodeLabelExpression(dummyLabel); SchedulerUtils.enforcePartitionExclusivity(rr, enforcedExclusiveLabelSet, enforcedLabel2); Assert.assertEquals(enforcedLabel2, rr.getNodeLabelExpression()); rr.setNodeLabelExpression(enforcedLabel1); SchedulerUtils.enforcePartitionExclusivity(rr, enforcedExclusiveLabelSet, enforcedLabel1); Assert.assertEquals(enforcedLabel1, rr.getNodeLabelExpression()); rr.setNodeLabelExpression(enforcedLabel2); SchedulerUtils.enforcePartitionExclusivity(rr, enforcedExclusiveLabelSet, enforcedLabel1); Assert.assertEquals(enforcedLabel1, rr.getNodeLabelExpression()); }