SchedulerApplicationAttempt implements SchedulableEntity { public synchronized ApplicationResourceUsageReport getResourceUsageReport() { AggregateAppResourceUsage runningResourceUsage = getRunningAggregateAppResourceUsage(); Resource usedResourceClone = Resources.clone(attemptResourceUsage.getAllUsed()); Resource reservedResourceClone = Resources.clone(attemptResourceUsage.getReserved()); Resource cluster = rmContext.getScheduler().getClusterResource(); ResourceCalculator calc = rmContext.getScheduler().getResourceCalculator(); float queueUsagePerc = calc.divide(cluster, usedResourceClone, Resources .multiply(cluster, queue.getQueueInfo(false, false).getCapacity())) * 100; float clusterUsagePerc = calc.divide(cluster, usedResourceClone, cluster) * 100; return ApplicationResourceUsageReport.newInstance(liveContainers.size(), reservedContainers.size(), usedResourceClone, reservedResourceClone, Resources.add(usedResourceClone, reservedResourceClone), runningResourceUsage.getMemorySeconds(), runningResourceUsage.getVcoreSeconds(), queueUsagePerc, clusterUsagePerc); } SchedulerApplicationAttempt(ApplicationAttemptId applicationAttemptId, 
      String user, Queue queue, ActiveUsersManager activeUsersManager,
      RMContext rmContext); synchronized Collection<RMContainer> getLiveContainers(); AppSchedulingInfo getAppSchedulingInfo(); boolean isPending(); ApplicationAttemptId getApplicationAttemptId(); ApplicationId getApplicationId(); String getUser(); Map<String, ResourceRequest> getResourceRequests(Priority priority); Set<ContainerId> getPendingRelease(); long getNewContainerId(); Collection<Priority> getPriorities(); synchronized ResourceRequest getResourceRequest(Priority priority,
      String resourceName); synchronized int getTotalRequiredResources(Priority priority); synchronized Resource getResource(Priority priority); String getQueueName(); Resource getAMResource(); Resource getAMResource(String label); void setAMResource(Resource amResource); void setAMResource(String label, Resource amResource); boolean isAmRunning(); void setAmRunning(boolean bool); boolean getUnmanagedAM(); synchronized RMContainer getRMContainer(ContainerId id); synchronized int getReReservations(Priority priority); @Stable @Private synchronized Resource getCurrentReservation(); Queue getQueue(); synchronized boolean updateResourceRequests(
      List<ResourceRequest> requests); synchronized void recoverResourceRequests(
      List<ResourceRequest> requests); synchronized void stop(RMAppAttemptState rmAppAttemptFinalState); synchronized boolean isStopped(); synchronized List<RMContainer> getReservedContainers(); synchronized boolean reserveIncreasedContainer(SchedulerNode node,
      Priority priority, RMContainer rmContainer, Resource reservedResource); synchronized RMContainer reserve(SchedulerNode node,
      Priority priority, RMContainer rmContainer, Container container); synchronized boolean isReserved(SchedulerNode node, Priority priority); synchronized void setHeadroom(Resource globalLimit); synchronized Resource getHeadroom(); synchronized int getNumReservedContainers(Priority priority); @SuppressWarnings("unchecked") synchronized void containerLaunchedOnNode(ContainerId containerId,
      NodeId nodeId); synchronized void showRequests(); Resource getCurrentConsumption(); synchronized List<Container> pullNewlyAllocatedContainers(); synchronized List<Container> pullNewlyIncreasedContainers(); synchronized List<Container> pullNewlyDecreasedContainers(); synchronized List<NMToken> pullUpdatedNMTokens(); boolean isWaitingForAMContainer(); synchronized void updateBlacklist(
      List<String> blacklistAdditions, List<String> blacklistRemovals); synchronized void updateAMBlacklist(
      List<String> blacklistAdditions, List<String> blacklistRemovals); boolean isBlacklisted(String resourceName); synchronized int addMissedNonPartitionedRequestSchedulingOpportunity(
      Priority priority); synchronized void resetMissedNonPartitionedRequestSchedulingOpportunity(Priority priority); synchronized void addSchedulingOpportunity(Priority priority); synchronized void subtractSchedulingOpportunity(Priority priority); synchronized int getSchedulingOpportunities(Priority priority); synchronized void resetSchedulingOpportunities(Priority priority); synchronized void resetSchedulingOpportunities(Priority priority,
      long currentTimeMs); synchronized ApplicationResourceUsageReport getResourceUsageReport(); synchronized Map<ContainerId, RMContainer> getLiveContainersMap(); synchronized Resource getResourceLimit(); synchronized Map<Priority, Long> getLastScheduledContainer(); synchronized void transferStateFromPreviousAttempt(
      SchedulerApplicationAttempt appAttempt); synchronized void move(Queue newQueue); synchronized void recoverContainer(SchedulerNode node,
      RMContainer rmContainer); void incNumAllocatedContainers(NodeType containerType,
      NodeType requestType); void setApplicationHeadroomForMetrics(Resource headroom); void recordContainerRequestTime(long value); void recordContainerAllocationTime(long value); Set<String> getBlacklistedNodes(); @Private boolean hasPendingResourceRequest(ResourceCalculator rc,
      String nodePartition, Resource cluster,
      SchedulingMode schedulingMode); @VisibleForTesting ResourceUsage getAppAttemptResourceUsage(); @Override Priority getPriority(); void setPriority(Priority appPriority); @Override String getId(); @Override int compareInputOrderTo(SchedulableEntity other); @Override synchronized ResourceUsage getSchedulingResourceUsage(); synchronized boolean removeIncreaseRequest(NodeId nodeId,
      Priority priority, ContainerId containerId); synchronized boolean updateIncreaseRequests(
      List<SchedContainerChangeRequest> increaseRequests); synchronized void decreaseContainer(
      SchedContainerChangeRequest decreaseRequest); synchronized void increaseContainer(
      SchedContainerChangeRequest increaseRequest); void setAppAMNodePartitionName(String partitionName); String getAppAMNodePartitionName(); void updateAMContainerDiagnostics(AMState state,
      String diagnosticMessage);  }
@Test public void testAppPercentages() throws Exception { FifoScheduler scheduler = mock(FifoScheduler.class); when(scheduler.getClusterResource()) .thenReturn(Resource.newInstance(10 * 1024, 10)); when(scheduler.getResourceCalculator()) .thenReturn(new DefaultResourceCalculator()); ApplicationAttemptId appAttId = createAppAttemptId(0, 0); RMContext rmContext = mock(RMContext.class); when(rmContext.getEpoch()).thenReturn(3L); when(rmContext.getScheduler()).thenReturn(scheduler); final String user = "user1"; Queue queue = createQueue("test", null); SchedulerApplicationAttempt app = new SchedulerApplicationAttempt(appAttId, user, queue, queue.getActiveUsersManager(), rmContext); Resource requestedResource = Resource.newInstance(1536, 2); app.attemptResourceUsage.incUsed(requestedResource); assertEquals(15.0f, app.getResourceUsageReport().getQueueUsagePercentage(), 0.01f); assertEquals(15.0f, app.getResourceUsageReport().getClusterUsagePercentage(), 0.01f); queue = createQueue("test2", null, 0.5f); app = new SchedulerApplicationAttempt(appAttId, user, queue, queue.getActiveUsersManager(), rmContext); app.attemptResourceUsage.incUsed(requestedResource); assertEquals(30.0f, app.getResourceUsageReport().getQueueUsagePercentage(), 0.01f); assertEquals(15.0f, app.getResourceUsageReport().getClusterUsagePercentage(), 0.01f); app.attemptResourceUsage.incUsed(requestedResource); app.attemptResourceUsage.incUsed(requestedResource); app.attemptResourceUsage.incUsed(requestedResource); assertEquals(120.0f, app.getResourceUsageReport().getQueueUsagePercentage(), 0.01f); assertEquals(60.0f, app.getResourceUsageReport().getClusterUsagePercentage(), 0.01f); }