YARN-5753. fix NPE in AMRMClientImpl.getMatchingRequests() (haibochen via rkanter)

This commit is contained in:
Robert Kanter 2016-10-25 23:59:39 -07:00
parent d3bb69a667
commit 44fdf00964
2 changed files with 28 additions and 9 deletions

View File

@ -664,15 +664,20 @@ public synchronized List<? extends Collection<T>> getMatchingRequests(
List<LinkedHashSet<T>> list = new LinkedList<LinkedHashSet<T>>();
RemoteRequestsTable remoteRequestsTable = getTable(0);
List<ResourceRequestInfo<T>> matchingRequests =
remoteRequestsTable.getMatchingRequests(priority, resourceName,
executionType, capability);
// If no exact match. Container may be larger than what was requested.
// get all resources <= capability. map is reverse sorted.
for (ResourceRequestInfo<T> resReqInfo : matchingRequests) {
if (canFit(resReqInfo.remoteRequest.getCapability(), capability) &&
!resReqInfo.containerRequests.isEmpty()) {
list.add(resReqInfo.containerRequests);
if (null != remoteRequestsTable) {
List<ResourceRequestInfo<T>> matchingRequests =
remoteRequestsTable.getMatchingRequests(priority, resourceName,
executionType, capability);
if (null != matchingRequests) {
// If no exact match. Container may be larger than what was requested.
// get all resources <= capability. map is reverse sorted.
for (ResourceRequestInfo<T> resReqInfo : matchingRequests) {
if (canFit(resReqInfo.remoteRequest.getCapability(), capability) &&
!resReqInfo.containerRequests.isEmpty()) {
list.add(resReqInfo.containerRequests);
}
}
}
}
// no match found

View File

@ -235,6 +235,20 @@ public static void tearDown() {
yarnCluster.stop();
}
}
@Test (timeout = 60000)
public void testAMRMClientNoMatchingRequests()
throws IOException, YarnException {
AMRMClient<ContainerRequest> amClient = AMRMClient.createAMRMClient();
amClient.init(conf);
amClient.start();
amClient.registerApplicationMaster("Host", 10000, "");
Resource testCapability1 = Resource.newInstance(1024, 2);
List<? extends Collection<ContainerRequest>> matches =
amClient.getMatchingRequests(priority, node, testCapability1);
assertEquals("Expected no macthing requests.", matches.size(), 0);
}
@Test (timeout=60000)
public void testAMRMClientMatchingFit() throws YarnException, IOException {