@Override
  public GetNewApplicationResponse getNewApplication(
      GetNewApplicationRequest request) throws YarnException, IOException {

    if (request == null) {
      routerMetrics.incrAppsFailedCreated();
      String errMsg = "Missing getNewApplication request.";
      RouterAuditLogger.logFailure(user.getShortUserName(), GET_NEW_APP, UNKNOWN,
          TARGET_CLIENT_RM_SERVICE, errMsg);
      RouterServerUtil.logAndThrowException(errMsg, null);
    }

    long startTime = clock.getTime();
    Map<SubClusterId, SubClusterInfo> subClustersActive =
        federationFacade.getSubClusters(true);

    // Try calling the getNewApplication method
    List<SubClusterId> blacklist = new ArrayList<>();
    int activeSubClustersCount = federationFacade.getActiveSubClustersCount();
    int actualRetryNums = Math.min(activeSubClustersCount, numSubmitRetries);

    try {
      GetNewApplicationResponse response =
          ((FederationActionRetry<GetNewApplicationResponse>) (retryCount) ->
          invokeGetNewApplication(subClustersActive, blacklist, request, retryCount)).
          runWithRetries(actualRetryNums, submitIntervalTime);

      if (response != null) {
        long stopTime = clock.getTime();
        routerMetrics.succeededAppsCreated(stopTime - startTime);
        return response;
      }
    } catch (Exception e) {
      routerMetrics.incrAppsFailedCreated();
      RouterAuditLogger.logFailure(user.getShortUserName(), GET_NEW_APP, UNKNOWN,
          TARGET_CLIENT_RM_SERVICE, e.getMessage());
      RouterServerUtil.logAndThrowException(e.getMessage(), e);
    }

    routerMetrics.incrAppsFailedCreated();
    String errMsg = "Failed to create a new application.";
    RouterAuditLogger.logFailure(user.getShortUserName(), GET_NEW_APP, UNKNOWN,
        TARGET_CLIENT_RM_SERVICE, errMsg);
    throw new YarnException(errMsg);
  }
@Test
  public void testGetNewApplication() throws YarnException, IOException {
    LOG.info("Test FederationClientInterceptor: Get New Application.");

    GetNewApplicationRequest request = GetNewApplicationRequest.newInstance();
    GetNewApplicationResponse response = interceptor.getNewApplication(request);

    Assert.assertNotNull(response);
    Assert.assertNotNull(response.getApplicationId());
    Assert.assertEquals(response.getApplicationId().getClusterTimestamp(),
        ResourceManager.getClusterTimeStamp());
  }