Skip to content

Commit fc85c27

Browse files
author
slfan1989
committed
YARN-11161. Support getAttributesToNodes, getClusterNodeAttributes, getNodesToAttributes API's for Federation.
1 parent c5b57e8 commit fc85c27

File tree

1 file changed

+103
-0
lines changed
  • hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm

1 file changed

+103
-0
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestRouterYarnClientUtils.java

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceTypeInfoResponse;
3838
import org.apache.hadoop.yarn.api.protocolrecords.GetResourceProfileResponse;
3939
import org.apache.hadoop.yarn.api.protocolrecords.GetAllResourceProfilesResponse;
40+
import org.apache.hadoop.yarn.api.protocolrecords.GetAttributesToNodesResponse;
41+
import org.apache.hadoop.yarn.api.protocolrecords.GetClusterNodeAttributesResponse;
4042
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
4143
import org.apache.hadoop.yarn.api.records.ApplicationId;
4244
import org.apache.hadoop.yarn.api.records.ApplicationReport;
@@ -53,6 +55,11 @@
5355
import org.apache.hadoop.yarn.api.records.ReservationDefinition;
5456
import org.apache.hadoop.yarn.api.records.ReservationId;
5557
import org.apache.hadoop.yarn.api.records.ResourceTypeInfo;
58+
import org.apache.hadoop.yarn.api.records.NodeAttribute;
59+
import org.apache.hadoop.yarn.api.records.NodeAttributeType;
60+
import org.apache.hadoop.yarn.api.records.NodeAttributeKey;
61+
import org.apache.hadoop.yarn.api.records.NodeToAttributeValue;
62+
import org.apache.hadoop.yarn.api.records.NodeAttributeInfo;
5663
import org.apache.hadoop.yarn.util.Records;
5764
import org.apache.hadoop.yarn.server.uam.UnmanagedApplicationManager;
5865
import org.junit.Assert;
@@ -610,4 +617,100 @@ public void testMergeResourceProfile() {
610617
Assert.assertEquals(3, resource.getVirtualCores());
611618
Assert.assertEquals(3072, resource.getMemorySize());
612619
}
620+
621+
@Test
622+
public void testMergeAttributesToNodesResponse() {
623+
// normal response1
624+
NodeAttribute gpu = NodeAttribute.newInstance(NodeAttribute.PREFIX_CENTRALIZED, "GPU",
625+
NodeAttributeType.STRING, "nvidia");
626+
Map<NodeAttributeKey, List<NodeToAttributeValue>> map1 = new HashMap<>();
627+
List<NodeToAttributeValue> lists1 = new ArrayList<>();
628+
NodeToAttributeValue attributeValue1 = NodeToAttributeValue.newInstance("node1", gpu.getAttributeValue());
629+
lists1.add(attributeValue1);
630+
map1.put(gpu.getAttributeKey(), lists1);
631+
GetAttributesToNodesResponse response1 = GetAttributesToNodesResponse.newInstance(map1);
632+
633+
// normal response2
634+
NodeAttribute docker = NodeAttribute.newInstance(NodeAttribute.PREFIX_DISTRIBUTED, "DOCKER",
635+
NodeAttributeType.STRING, "docker0");
636+
Map<NodeAttributeKey, List<NodeToAttributeValue>> map2 = new HashMap<>();
637+
List<NodeToAttributeValue> lists2 = new ArrayList<>();
638+
NodeToAttributeValue attributeValue2 = NodeToAttributeValue.newInstance("node2", docker.getAttributeValue());
639+
lists2.add(attributeValue2);
640+
map2.put(docker.getAttributeKey(), lists2);
641+
GetAttributesToNodesResponse response2 = GetAttributesToNodesResponse.newInstance(map2);
642+
643+
// empty response3
644+
GetAttributesToNodesResponse response3 = GetAttributesToNodesResponse.newInstance(new HashMap<>());
645+
646+
// null response4
647+
GetAttributesToNodesResponse response4 = null;
648+
649+
List<GetAttributesToNodesResponse> responses = new ArrayList<>();
650+
responses.add(response1);
651+
responses.add(response2);
652+
responses.add(response3);
653+
responses.add(response4);
654+
655+
GetAttributesToNodesResponse response =
656+
RouterYarnClientUtils.mergeAttributesToNodesResponse(responses);
657+
658+
Assert.assertNotNull(response);
659+
Assert.assertEquals(2, response.getAttributesToNodes().size());
660+
661+
Map<NodeAttributeKey, List<NodeToAttributeValue>> attrs = response.getAttributesToNodes();
662+
Assert.assertTrue(findHostnameAndValInMapping("node2", "docker0",
663+
attrs.get(docker.getAttributeKey())));
664+
}
665+
666+
@Test
667+
public void testMergeClusterNodeAttributesResponse() {
668+
// normal response1
669+
NodeAttributeInfo nodeAttributeInfo1 =
670+
NodeAttributeInfo.newInstance(NodeAttributeKey.newInstance("GPU"), NodeAttributeType.STRING);
671+
Set<NodeAttributeInfo> attributes1 = new HashSet<>();
672+
attributes1.add(nodeAttributeInfo1);
673+
GetClusterNodeAttributesResponse response1 = GetClusterNodeAttributesResponse.newInstance(attributes1);
674+
675+
// normal response2
676+
NodeAttributeInfo nodeAttributeInfo2 =
677+
NodeAttributeInfo.newInstance(NodeAttributeKey.newInstance("CPU"), NodeAttributeType.STRING);
678+
Set<NodeAttributeInfo> attributes2 = new HashSet<>();
679+
attributes2.add(nodeAttributeInfo2);
680+
GetClusterNodeAttributesResponse response2 = GetClusterNodeAttributesResponse.newInstance(attributes2);
681+
682+
// empty response3
683+
GetClusterNodeAttributesResponse response3 = GetClusterNodeAttributesResponse.newInstance(new HashSet<>());
684+
685+
// null response4
686+
GetClusterNodeAttributesResponse response4 = null;
687+
688+
List<GetClusterNodeAttributesResponse> responses = new ArrayList<>();
689+
responses.add(response1);
690+
responses.add(response2);
691+
responses.add(response3);
692+
responses.add(response4);
693+
694+
GetClusterNodeAttributesResponse response =
695+
RouterYarnClientUtils.mergeClusterNodeAttributesResponse(responses);
696+
697+
Assert.assertNotNull(response);
698+
699+
Set<NodeAttributeInfo> nodeAttributeInfos = response.getNodeAttributes();
700+
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());
705+
}
706+
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;
715+
}
613716
}

0 commit comments

Comments
 (0)