SingleConstraintAppPlacementAllocator extends AppPlacementAllocator<N> { @VisibleForTesting String getTargetNodePartition() { return targetNodePartition; } SingleConstraintAppPlacementAllocator(); @Override @SuppressWarnings("unchecked") Iterator<N> getPreferredNodeIterator(
      CandidateNodeSet<N> candidateNodeSet); @Override PendingAskUpdateResult updatePendingAsk(
      Collection<ResourceRequest> requests,
      boolean recoverPreemptedRequestForAContainer); @Override PendingAskUpdateResult updatePendingAsk(
      SchedulerRequestKey schedulerRequestKey,
      SchedulingRequest newSchedulingRequest,
      boolean recoverPreemptedRequestForAContainer); @Override Map<String, ResourceRequest> getResourceRequests(); @Override PendingAsk getPendingAsk(String resourceName); @Override int getOutstandingAsksCount(String resourceName); @Override ContainerRequest allocate(SchedulerRequestKey schedulerKey,
      NodeType type, SchedulerNode node); @Override boolean canAllocate(NodeType type, SchedulerNode node); @Override boolean canDelayTo(String resourceName); @Override boolean precheckNode(SchedulerNode schedulerNode,
      SchedulingMode schedulingMode); @Override String getPrimaryRequestedNodePartition(); @Override int getUniqueLocationAsks(); @Override void showRequests(); @Override SchedulingRequest getSchedulingRequest(); @Override void initialize(AppSchedulingInfo appSchedulingInfo,
      SchedulerRequestKey schedulerRequestKey, RMContext rmContext);  }
@Test public void testSchedulingRequestValidation() { assertValidSchedulingRequest(SchedulingRequest.newBuilder().executionType( ExecutionTypeRequest.newInstance(ExecutionType.GUARANTEED)) .allocationRequestId(10L).priority(Priority.newInstance(1)) .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.NODE, PlacementConstraints.PlacementTargets .allocationTag("mapper", "reducer"), PlacementConstraints.PlacementTargets.nodePartition("")) .build()).resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) .build()); Assert.assertEquals("", allocator.getTargetNodePartition()); assertValidSchedulingRequest(SchedulingRequest.newBuilder().executionType( ExecutionTypeRequest.newInstance(ExecutionType.GUARANTEED)) .allocationRequestId(10L).priority(Priority.newInstance(1)) .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.NODE, PlacementConstraints.PlacementTargets .allocationTag("mapper", "reducer"), PlacementConstraints.PlacementTargets.nodePartition("x")) .build()).resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) .build()); Assert.assertEquals("x", allocator.getTargetNodePartition()); assertValidSchedulingRequest(SchedulingRequest.newBuilder().executionType( ExecutionTypeRequest.newInstance(ExecutionType.GUARANTEED)) .allocationRequestId(10L).priority(Priority.newInstance(1)) .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.NODE, PlacementConstraints.PlacementTargets .allocationTag("mapper", "reducer")).build()) .resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) .build()); Assert.assertEquals("", allocator.getTargetNodePartition()); assertValidSchedulingRequest(SchedulingRequest.newBuilder().executionType( ExecutionTypeRequest.newInstance(ExecutionType.GUARANTEED)) .allocationRequestId(10L).priority(Priority.newInstance(1)) .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.NODE, PlacementConstraints.PlacementTargets .allocationTag("mapper", "reducer")).build()) .resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) .build()); Assert.assertEquals("", allocator.getTargetNodePartition()); assertInvalidSchedulingRequest(SchedulingRequest.newBuilder().executionType( ExecutionTypeRequest.newInstance(ExecutionType.GUARANTEED)) .allocationRequestId(10L).priority(Priority.newInstance(1)) .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.NODE, PlacementConstraints.PlacementTargets .allocationTag("mapper", "reducer")).build()) .build(), true); assertInvalidSchedulingRequest(SchedulingRequest.newBuilder().executionType( ExecutionTypeRequest.newInstance(ExecutionType.GUARANTEED)) .allocationRequestId(10L).priority(Priority.newInstance(1)) .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.NODE).build()) .build(), true); assertInvalidSchedulingRequest(SchedulingRequest.newBuilder().executionType( ExecutionTypeRequest.newInstance(ExecutionType.OPPORTUNISTIC)) .allocationRequestId(10L).priority(Priority.newInstance(1)) .placementConstraintExpression(PlacementConstraints .targetNotIn(PlacementConstraints.NODE, PlacementConstraints.PlacementTargets .allocationTag("mapper", "reducer"), PlacementConstraints.PlacementTargets.nodePartition("")) .build()).resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) .build(), true); }