|  | 
| 39 | 39 | import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceProfilesResponse; | 
| 40 | 40 | import org.apache.hadoop.yarn.api.protocolrecords.GetAttributesToNodesResponse; | 
| 41 | 41 | import org.apache.hadoop.yarn.api.protocolrecords.GetClusterNodeAttributesResponse; | 
|  | 42 | +import org.apache.hadoop.yarn.api.protocolrecords.GetNodesToAttributesResponse; | 
| 42 | 43 | import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; | 
| 43 | 44 | import org.apache.hadoop.yarn.api.records.ApplicationId; | 
| 44 | 45 | import org.apache.hadoop.yarn.api.records.ApplicationReport; | 
| @@ -659,8 +660,12 @@ public void testMergeAttributesToNodesResponse() { | 
| 659 | 660 |     Assert.assertEquals(2, response.getAttributesToNodes().size()); | 
| 660 | 661 | 
 | 
| 661 | 662 |     Map<NodeAttributeKey, List<NodeToAttributeValue>> attrs = response.getAttributesToNodes(); | 
| 662 |  | -    Assert.assertTrue(findHostnameAndValInMapping("node2", "docker0", | 
| 663 |  | -        attrs.get(docker.getAttributeKey()))); | 
|  | 663 | + | 
|  | 664 | +    NodeAttributeKey gpuKey = gpu.getAttributeKey(); | 
|  | 665 | +    Assert.assertEquals(attributeValue1.toString(), attrs.get(gpuKey).get(0).toString()); | 
|  | 666 | + | 
|  | 667 | +    NodeAttributeKey dockerKey = docker.getAttributeKey(); | 
|  | 668 | +    Assert.assertEquals(attributeValue2.toString(), attrs.get(dockerKey).get(0).toString()); | 
| 664 | 669 |   } | 
| 665 | 670 | 
 | 
| 666 | 671 |   @Test | 
| @@ -698,19 +703,53 @@ public void testMergeClusterNodeAttributesResponse() { | 
| 698 | 703 | 
 | 
| 699 | 704 |     Set<NodeAttributeInfo> nodeAttributeInfos = response.getNodeAttributes(); | 
| 700 | 705 |     Assert.assertEquals(2, nodeAttributeInfos.size()); | 
| 701 |  | - | 
| 702 |  | -    Object[] objectArr = nodeAttributeInfos.toArray(); | 
| 703 |  | -    Assert.assertEquals("rm.yarn.io/GPU(STRING)", objectArr[0].toString()); | 
| 704 |  | -    Assert.assertEquals("rm.yarn.io/CPU(STRING)", objectArr[1].toString()); | 
|  | 706 | +    Assert.assertTrue(nodeAttributeInfos.contains(nodeAttributeInfo1)); | 
|  | 707 | +    Assert.assertTrue(nodeAttributeInfos.contains(nodeAttributeInfo2)); | 
| 705 | 708 |   } | 
| 706 | 709 | 
 | 
| 707 |  | -  private boolean findHostnameAndValInMapping(String hostname, String attrVal, | 
| 708 |  | -      List<NodeToAttributeValue> mappingVals) { | 
| 709 |  | -    for (NodeToAttributeValue value : mappingVals) { | 
| 710 |  | -      if (value.getHostname().equals(hostname)) { | 
| 711 |  | -        return attrVal.equals(value.getAttributeValue()); | 
| 712 |  | -      } | 
| 713 |  | -    } | 
| 714 |  | -    return false; | 
|  | 710 | +  @Test | 
|  | 711 | +  public void testMergeNodesToAttributesResponse() { | 
|  | 712 | +    // normal response1 | 
|  | 713 | +    NodeAttribute gpu = NodeAttribute.newInstance(NodeAttribute.PREFIX_CENTRALIZED, "GPU", | 
|  | 714 | +        NodeAttributeType.STRING, "nvida"); | 
|  | 715 | +    NodeAttribute os = NodeAttribute.newInstance(NodeAttribute.PREFIX_CENTRALIZED, "OS", | 
|  | 716 | +        NodeAttributeType.STRING, "windows64"); | 
|  | 717 | +    NodeAttribute dist = NodeAttribute.newInstance(NodeAttribute.PREFIX_DISTRIBUTED, "VERSION", | 
|  | 718 | +        NodeAttributeType.STRING, "3_0_2"); | 
|  | 719 | +    Map<String, Set<NodeAttribute>> node1Map = new HashMap<>(); | 
|  | 720 | +    node1Map.put("node1", ImmutableSet.of(gpu, os, dist)); | 
|  | 721 | +    GetNodesToAttributesResponse response1 = GetNodesToAttributesResponse.newInstance(node1Map); | 
|  | 722 | + | 
|  | 723 | +    // normal response2 | 
|  | 724 | +    NodeAttribute docker = NodeAttribute.newInstance(NodeAttribute.PREFIX_DISTRIBUTED, "DOCKER", | 
|  | 725 | +        NodeAttributeType.STRING, "docker0"); | 
|  | 726 | +    Map<String, Set<NodeAttribute>> node2Map = new HashMap<>(); | 
|  | 727 | +    node2Map.put("node2", ImmutableSet.of(docker)); | 
|  | 728 | +    GetNodesToAttributesResponse response2 = GetNodesToAttributesResponse.newInstance(node2Map); | 
|  | 729 | + | 
|  | 730 | +    // empty response3 | 
|  | 731 | +    GetNodesToAttributesResponse response3 = GetNodesToAttributesResponse.newInstance(new HashMap<>()); | 
|  | 732 | + | 
|  | 733 | +    // null response4 | 
|  | 734 | +    GetNodesToAttributesResponse response4 = null; | 
|  | 735 | + | 
|  | 736 | +    List<GetNodesToAttributesResponse> responses = new ArrayList<>(); | 
|  | 737 | +    responses.add(response1); | 
|  | 738 | +    responses.add(response2); | 
|  | 739 | +    responses.add(response3); | 
|  | 740 | +    responses.add(response4); | 
|  | 741 | + | 
|  | 742 | +    GetNodesToAttributesResponse response = | 
|  | 743 | +        RouterYarnClientUtils.mergeNodesToAttributesResponse(responses); | 
|  | 744 | + | 
|  | 745 | +    Assert.assertNotNull(response); | 
|  | 746 | + | 
|  | 747 | +    Map<String, Set<NodeAttribute>> hostToAttrs = response.getNodeToAttributes(); | 
|  | 748 | +    Assert.assertNotNull(hostToAttrs); | 
|  | 749 | +    Assert.assertEquals(2, hostToAttrs.size()); | 
|  | 750 | +    Assert.assertTrue(hostToAttrs.get("node1").contains(dist)); | 
|  | 751 | +    Assert.assertTrue(hostToAttrs.get("node1").contains(gpu)); | 
|  | 752 | +    Assert.assertTrue(hostToAttrs.get("node1").contains(os)); | 
|  | 753 | +    Assert.assertTrue(hostToAttrs.get("node2").contains(docker)); | 
| 715 | 754 |   } | 
| 716 | 755 | } | 
0 commit comments