YARN-7076. yarn application -list -appTypes is not working. Contributed by Jian He.

This commit is contained in:
Junping Du 2017-08-28 18:26:51 -07:00
parent a1e3f84afe
commit 312b1fd9da
4 changed files with 33 additions and 18 deletions

View File

@ -29,6 +29,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -766,20 +767,13 @@ public class ClientRMService extends AbstractService implements
return response; return response;
} }
@Override
public GetApplicationsResponse getApplications(
GetApplicationsRequest request) throws YarnException {
return getApplications(request, true);
}
/** /**
* Get applications matching the {@link GetApplicationsRequest}. If * Get applications matching the {@link GetApplicationsRequest}. If
* caseSensitive is set to false, applicationTypes in * caseSensitive is set to false, applicationTypes in
* GetApplicationRequest are expected to be in all-lowercase * GetApplicationRequest are expected to be in all-lowercase
*/ */
@Private @Override
public GetApplicationsResponse getApplications( public GetApplicationsResponse getApplications(GetApplicationsRequest request)
GetApplicationsRequest request, boolean caseSensitive)
throws YarnException { throws YarnException {
UserGroupInformation callerUGI; UserGroupInformation callerUGI;
try { try {
@ -789,7 +783,7 @@ public class ClientRMService extends AbstractService implements
throw RPCUtil.getRemoteException(ie); throw RPCUtil.getRemoteException(ie);
} }
Set<String> applicationTypes = request.getApplicationTypes(); Set<String> applicationTypes = getLowerCasedAppTypes(request);
EnumSet<YarnApplicationState> applicationStates = EnumSet<YarnApplicationState> applicationStates =
request.getApplicationStates(); request.getApplicationStates();
Set<String> users = request.getUsers(); Set<String> users = request.getUsers();
@ -853,9 +847,8 @@ public class ClientRMService extends AbstractService implements
} }
if (applicationTypes != null && !applicationTypes.isEmpty()) { if (applicationTypes != null && !applicationTypes.isEmpty()) {
String appTypeToMatch = caseSensitive String appTypeToMatch =
? application.getApplicationType() StringUtils.toLowerCase(application.getApplicationType());
: StringUtils.toLowerCase(application.getApplicationType());
if (!applicationTypes.contains(appTypeToMatch)) { if (!applicationTypes.contains(appTypeToMatch)) {
continue; continue;
} }
@ -915,6 +908,17 @@ public class ClientRMService extends AbstractService implements
return response; return response;
} }
private Set<String> getLowerCasedAppTypes(GetApplicationsRequest request) {
Set<String> applicationTypes = new HashSet<>();
if (request.getApplicationTypes() != null && !request.getApplicationTypes()
.isEmpty()) {
for (String type : request.getApplicationTypes()) {
applicationTypes.add(StringUtils.toLowerCase(type));
}
}
return applicationTypes;
}
@Override @Override
public GetClusterNodesResponse getClusterNodes(GetClusterNodesRequest request) public GetClusterNodesResponse getClusterNodes(GetClusterNodesRequest request)
throws YarnException { throws YarnException {

View File

@ -568,7 +568,7 @@ public class RMWebServices extends WebServices implements RMWebServiceProtocol {
List<ApplicationReport> appReports = null; List<ApplicationReport> appReports = null;
try { try {
appReports = rm.getClientRMService().getApplications(request, false) appReports = rm.getClientRMService().getApplications(request)
.getApplicationList(); .getApplicationList();
} catch (YarnException e) { } catch (YarnException e) {
LOG.error("Unable to retrieve apps from ClientRMService", e); LOG.error("Unable to retrieve apps from ClientRMService", e);

View File

@ -994,6 +994,18 @@ public class TestClientRMService {
Assert.assertEquals(appId2, Assert.assertEquals(appId2,
getAllApplicationsResponse.getApplicationList() getAllApplicationsResponse.getApplicationList()
.get(0).getApplicationId()); .get(0).getApplicationId());
// Test query with uppercase appType also works
appTypes = new HashSet<String>();
appTypes.add("MATCHTYPE");
getAllAppsRequest = GetApplicationsRequest.newInstance(appTypes);
getAllApplicationsResponse =
rmService.getApplications(getAllAppsRequest);
Assert.assertEquals(1,
getAllApplicationsResponse.getApplicationList().size());
Assert.assertEquals(appId2,
getAllApplicationsResponse.getApplicationList()
.get(0).getApplicationId());
} }
@Test @Test
@ -1087,7 +1099,7 @@ public class TestClientRMService {
assertEquals("Incorrect number of applications in queue", 2, assertEquals("Incorrect number of applications in queue", 2,
rmService.getApplications(request).getApplicationList().size()); rmService.getApplications(request).getApplicationList().size());
assertEquals("Incorrect number of applications in queue", 2, assertEquals("Incorrect number of applications in queue", 2,
rmService.getApplications(request, false).getApplicationList().size()); rmService.getApplications(request).getApplicationList().size());
queueSet.add(queues[1]); queueSet.add(queues[1]);
assertEquals("Incorrect number of applications in queue", 3, assertEquals("Incorrect number of applications in queue", 3,

View File

@ -22,7 +22,6 @@ import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseS
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.isA; import static org.mockito.Matchers.isA;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -647,8 +646,8 @@ public class TestRMWebServices extends JerseyTestBase {
when(mockAppsResponse.getApplicationList()) when(mockAppsResponse.getApplicationList())
.thenReturn(Arrays.asList(new ApplicationReport[] { mockReport })); .thenReturn(Arrays.asList(new ApplicationReport[] { mockReport }));
ClientRMService mockClientSvc = mock(ClientRMService.class); ClientRMService mockClientSvc = mock(ClientRMService.class);
when(mockClientSvc.getApplications(isA(GetApplicationsRequest.class), when(mockClientSvc.getApplications(isA(GetApplicationsRequest.class)))
anyBoolean())).thenReturn(mockAppsResponse); .thenReturn(mockAppsResponse);
ResourceManager mockRM = mock(ResourceManager.class); ResourceManager mockRM = mock(ResourceManager.class);
RMContextImpl rmContext = new RMContextImpl(null, null, null, null, null, RMContextImpl rmContext = new RMContextImpl(null, null, null, null, null,
null, null, null, null, null); null, null, null, null, null);