CapacityScheduler extends
    AbstractYarnScheduler<FiCaSchedulerApp, FiCaSchedulerNode> implements
    PreemptableResourceScheduler, CapacitySchedulerContext, Configurable,
    ResourceAllocationCommitter, MutableConfScheduler { @Override public long checkAndGetApplicationLifetime(String queueName, long lifetimeRequestedByApp) { readLock.lock(); try { CSQueue queue = getQueue(queueName); if (queue == null || !(queue instanceof LeafQueue)) { return lifetimeRequestedByApp; } long defaultApplicationLifetime = ((LeafQueue) queue).getDefaultApplicationLifetime(); long maximumApplicationLifetime = ((LeafQueue) queue).getMaximumApplicationLifetime(); if (maximumApplicationLifetime <= 0) { return (lifetimeRequestedByApp <= 0) ? defaultApplicationLifetime : lifetimeRequestedByApp; } if (lifetimeRequestedByApp <= 0) { return defaultApplicationLifetime; } else if (lifetimeRequestedByApp > maximumApplicationLifetime) { return maximumApplicationLifetime; } return lifetimeRequestedByApp; } finally { readLock.unlock(); } } CapacityScheduler(); @Override void setConf(Configuration conf); @Override Configuration getConf(); @Override QueueMetrics getRootQueueMetrics(); CSQueue getRootQueue(); @Override CapacitySchedulerConfiguration getConfiguration(); @Override RMContainerTokenSecretManager getContainerTokenSecretManager(); @Override ResourceCalculator getResourceCalculator(); @VisibleForTesting void setResourceCalculator(ResourceCalculator rc); @Override int getNumClusterNodes(); @Override RMContext getRMContext(); @Override void setRMContext(RMContext rmContext); @Override void serviceInit(Configuration conf); @Override void serviceStart(); @Override void serviceStop(); void reinitialize(Configuration newConf, RMContext rmContext,
         boolean validation); @Override void reinitialize(Configuration newConf, RMContext rmContext); @VisibleForTesting PlacementRule getUserGroupMappingPlacementRule(); PlacementRule getAppNameMappingPlacementRule(); @VisibleForTesting void updatePlacementRules(); @Override CSQueue getQueue(String queueName); String normalizeQueueName(String name); boolean isAmbiguous(String queueName); @Override @Lock(Lock.NoLock.class) Allocation allocate(ApplicationAttemptId applicationAttemptId,
      List<ResourceRequest> ask, List<SchedulingRequest> schedulingRequests,
      List<ContainerId> release, List<String> blacklistAdditions,
      List<String> blacklistRemovals, ContainerUpdates updateRequests); @Override @Lock(Lock.NoLock.class) QueueInfo getQueueInfo(String queueName,
      boolean includeChildQueues, boolean recursive); @Override @Lock(Lock.NoLock.class) List<QueueUserACLInfo> getQueueUserAclInfo(); @Override void handle(SchedulerEvent event); @Lock(Lock.NoLock.class) @VisibleForTesting @Override FiCaSchedulerApp getApplicationAttempt(
      ApplicationAttemptId applicationAttemptId); @Lock(Lock.NoLock.class) FiCaSchedulerNode getNode(NodeId nodeId); @Lock(Lock.NoLock.class) List<FiCaSchedulerNode> getAllNodes(); @Override @Lock(Lock.NoLock.class) void recover(RMState state); @Override void killReservedContainer(RMContainer container); @Override void markContainerForPreemption(ApplicationAttemptId aid,
      RMContainer cont); @VisibleForTesting @Override void killContainer(RMContainer container); void markContainerForKillable(
      RMContainer killableContainer); @Override boolean checkAccess(UserGroupInformation callerUGI,
      QueueACL acl, String queueName); @Override List<ApplicationAttemptId> getAppsInQueue(String queueName); boolean isSystemAppsLimitReached(); @Override void removeQueue(String queueName); @Override void addQueue(Queue queue); @Override void setEntitlement(String inQueue, QueueEntitlement entitlement); @Override String moveApplication(ApplicationId appId,
      String targetQueueName); @Override void preValidateMoveApplication(ApplicationId appId,
      String newQueue); @Override EnumSet<SchedulerResourceTypes> getSchedulingResourceTypes(); @Override Resource getMaximumResourceCapability(String queueName); @Override Set<String> getPlanQueues(); @Override Priority checkAndGetApplicationPriority(
          Priority priorityRequestedByApp, UserGroupInformation user,
          String queuePath, ApplicationId applicationId); @Override Priority updateApplicationPriority(Priority newPriority,
      ApplicationId applicationId, SettableFuture<Object> future,
      UserGroupInformation user); @Override PreemptionManager getPreemptionManager(); @Override ResourceUsage getClusterResourceUsage(); @VisibleForTesting void submitResourceCommitRequest(Resource cluster,
      CSAssignment csAssignment); @Override boolean attemptAllocationOnNode(SchedulerApplicationAttempt appAttempt,
      SchedulingRequest schedulingRequest, SchedulerNode schedulerNode); @VisibleForTesting ResourceCommitRequest<FiCaSchedulerApp, FiCaSchedulerNode> createResourceCommitRequest(CSAssignment csAssignment); @Override boolean tryCommit(Resource cluster, ResourceCommitRequest r,
      boolean updatePending); int getAsyncSchedulingPendingBacklogs(); @Override CapacitySchedulerQueueManager getCapacitySchedulerQueueManager(); WorkflowPriorityMappingsManager getWorkflowPriorityMappingsManager(); boolean moveReservedContainer(RMContainer toBeMovedContainer,
      FiCaSchedulerNode targetNode); @Override long checkAndGetApplicationLifetime(String queueName,
      long lifetimeRequestedByApp); @Override long getMaximumApplicationLifetime(String queueName); @Override boolean isConfigurationMutable(); @Override MutableConfigurationProvider getMutableConfProvider(); @Override void resetSchedulerMetrics(); boolean isMultiNodePlacementEnabled(); int getNumAsyncSchedulerThreads(); @VisibleForTesting void setMaxRunningAppsEnforcer(CSMaxRunningAppsEnforcer enforcer); @Override boolean placementConstraintEnabled(); @VisibleForTesting void setActivitiesManagerEnabled(boolean enabled);  }
@Test(timeout = 30000) public void testcheckAndGetApplicationLifetime() throws Exception { long maxLifetime = 10; long defaultLifetime = 5; CapacityScheduler cs = setUpCSQueue(maxLifetime, defaultLifetime); Assert.assertEquals(maxLifetime, cs.checkAndGetApplicationLifetime("default", 100)); Assert.assertEquals(9, cs.checkAndGetApplicationLifetime("default", 9)); Assert.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", -1)); Assert.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", 0)); Assert.assertEquals(maxLifetime, cs.getMaximumApplicationLifetime("default")); maxLifetime = -1; defaultLifetime = -1; cs = setUpCSQueue(maxLifetime, defaultLifetime); Assert.assertEquals(100, cs.checkAndGetApplicationLifetime("default", 100)); Assert.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", -1)); Assert.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", 0)); Assert.assertEquals(maxLifetime, cs.getMaximumApplicationLifetime("default")); maxLifetime = 10; defaultLifetime = 10; cs = setUpCSQueue(maxLifetime, defaultLifetime); Assert.assertEquals(maxLifetime, cs.checkAndGetApplicationLifetime("default", 100)); Assert.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", -1)); Assert.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", 0)); Assert.assertEquals(maxLifetime, cs.getMaximumApplicationLifetime("default")); maxLifetime = 0; defaultLifetime = 0; cs = setUpCSQueue(maxLifetime, defaultLifetime); Assert.assertEquals(100, cs.checkAndGetApplicationLifetime("default", 100)); Assert.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", -1)); Assert.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", 0)); maxLifetime = 10; defaultLifetime = -1; cs = setUpCSQueue(maxLifetime, defaultLifetime); Assert.assertEquals(maxLifetime, cs.checkAndGetApplicationLifetime("default", 100)); Assert.assertEquals(maxLifetime, cs.checkAndGetApplicationLifetime("default", -1)); Assert.assertEquals(maxLifetime, cs.checkAndGetApplicationLifetime("default", 0)); maxLifetime = 5; defaultLifetime = 10; try { setUpCSQueue(maxLifetime, defaultLifetime); Assert.fail("Expected to fails since maxLifetime < defaultLifetime."); } catch (ServiceStateException sse) { Throwable rootCause = sse.getCause().getCause(); Assert.assertTrue( rootCause.getMessage().contains("can't exceed maximum lifetime")); } maxLifetime = -1; defaultLifetime = 10; cs = setUpCSQueue(maxLifetime, defaultLifetime); Assert.assertEquals(100, cs.checkAndGetApplicationLifetime("default", 100)); Assert.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", -1)); Assert.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", 0)); }