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 class AMRMClientImpl<T extends ContainerRequest> extends AMRMClient<T> {
List<LinkedHashSet<T>> list = new LinkedList<LinkedHashSet<T>>(); List<LinkedHashSet<T>> list = new LinkedList<LinkedHashSet<T>>();
RemoteRequestsTable remoteRequestsTable = getTable(0); RemoteRequestsTable remoteRequestsTable = getTable(0);
List<ResourceRequestInfo<T>> matchingRequests =
remoteRequestsTable.getMatchingRequests(priority, resourceName, if (null != remoteRequestsTable) {
executionType, capability); List<ResourceRequestInfo<T>> matchingRequests =
// If no exact match. Container may be larger than what was requested. remoteRequestsTable.getMatchingRequests(priority, resourceName,
// get all resources <= capability. map is reverse sorted. executionType, capability);
for (ResourceRequestInfo<T> resReqInfo : matchingRequests) { if (null != matchingRequests) {
if (canFit(resReqInfo.remoteRequest.getCapability(), capability) && // If no exact match. Container may be larger than what was requested.
!resReqInfo.containerRequests.isEmpty()) { // get all resources <= capability. map is reverse sorted.
list.add(resReqInfo.containerRequests); for (ResourceRequestInfo<T> resReqInfo : matchingRequests) {
if (canFit(resReqInfo.remoteRequest.getCapability(), capability) &&
!resReqInfo.containerRequests.isEmpty()) {
list.add(resReqInfo.containerRequests);
}
}
} }
} }
// no match found // no match found

View File

@ -235,6 +235,20 @@ public class TestAMRMClient {
yarnCluster.stop(); 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) @Test (timeout=60000)
public void testAMRMClientMatchingFit() throws YarnException, IOException { public void testAMRMClientMatchingFit() throws YarnException, IOException {