@Override
  public NodesToAttributesMappingResponse mapAttributesToNodes(
      NodesToAttributesMappingRequest request) throws YarnException, IOException {
    // parameter verification.
    if (request == null) {
      routerMetrics.incrMapAttributesToNodesFailedRetrieved();
      RouterServerUtil.logAndThrowException("Missing mapAttributesToNodes request.", null);
    }

    String subClusterId = request.getSubClusterId();
    if (StringUtils.isBlank(subClusterId)) {
      routerMetrics.incrMapAttributesToNodesFailedRetrieved();
      RouterServerUtil.logAndThrowException("Missing mapAttributesToNodes SubClusterId.", null);
    }

    try {
      long startTime = clock.getTime();
      RMAdminProtocolMethod remoteMethod = new RMAdminProtocolMethod(
          new Class[]{NodesToAttributesMappingRequest.class}, new Object[]{request});
      Collection<NodesToAttributesMappingResponse> mapAttributesToNodesResps =
          remoteMethod.invokeConcurrent(this, NodesToAttributesMappingResponse.class,
          subClusterId);
      if (CollectionUtils.isNotEmpty(mapAttributesToNodesResps)) {
        long stopTime = clock.getTime();
        routerMetrics.succeededMapAttributesToNodesRetrieved(stopTime - startTime);
        return NodesToAttributesMappingResponse.newInstance();
      }
    } catch (YarnException e) {
      routerMetrics.incrMapAttributesToNodesFailedRetrieved();
      RouterServerUtil.logAndThrowException(e,
          "Unable to mapAttributesToNodes due to exception. " + e.getMessage());
    }

    routerMetrics.incrMapAttributesToNodesFailedRetrieved();
    throw new YarnException("Unable to mapAttributesToNodes.");
  }
@Test
  public void testMapAttributesToNodesRequest() throws Exception {
    // null request1.
    LambdaTestUtils.intercept(YarnException.class, "Missing mapAttributesToNodes request.",
        () -> interceptor.mapAttributesToNodes(null));

    // null request2.
    NodeAttribute nodeAttribute = NodeAttribute.newInstance(NodeAttribute.PREFIX_CENTRALIZED, "x",
        NodeAttributeType.STRING, "dfasdf");
    List<NodeAttribute> nodeAttributeList = Collections.singletonList(nodeAttribute);
    NodeToAttributes nodeToAttributes = NodeToAttributes.newInstance("host1", nodeAttributeList);
    List<NodeToAttributes> nodeToAttributesList = Collections.singletonList(nodeToAttributes);
    NodesToAttributesMappingRequest request = NodesToAttributesMappingRequest.newInstance(
        AttributeMappingOperationType.ADD, nodeToAttributesList, true, null);
    LambdaTestUtils.intercept(YarnException.class, "Missing mapAttributesToNodes SubClusterId.",
        () -> interceptor.mapAttributesToNodes(request));
  }