YARN-7076. yarn application -list -appTypes is not working. Contributed by Jian He.
This commit is contained in:
parent
a1e3f84afe
commit
312b1fd9da
|
@ -29,6 +29,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -765,21 +766,14 @@ public class ClientRMService extends AbstractService implements
|
|||
response.setClusterMetrics(ymetrics);
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetApplicationsResponse getApplications(
|
||||
GetApplicationsRequest request) throws YarnException {
|
||||
return getApplications(request, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get applications matching the {@link GetApplicationsRequest}. If
|
||||
* caseSensitive is set to false, applicationTypes in
|
||||
* GetApplicationRequest are expected to be in all-lowercase
|
||||
*/
|
||||
@Private
|
||||
public GetApplicationsResponse getApplications(
|
||||
GetApplicationsRequest request, boolean caseSensitive)
|
||||
@Override
|
||||
public GetApplicationsResponse getApplications(GetApplicationsRequest request)
|
||||
throws YarnException {
|
||||
UserGroupInformation callerUGI;
|
||||
try {
|
||||
|
@ -789,7 +783,7 @@ public class ClientRMService extends AbstractService implements
|
|||
throw RPCUtil.getRemoteException(ie);
|
||||
}
|
||||
|
||||
Set<String> applicationTypes = request.getApplicationTypes();
|
||||
Set<String> applicationTypes = getLowerCasedAppTypes(request);
|
||||
EnumSet<YarnApplicationState> applicationStates =
|
||||
request.getApplicationStates();
|
||||
Set<String> users = request.getUsers();
|
||||
|
@ -853,9 +847,8 @@ public class ClientRMService extends AbstractService implements
|
|||
}
|
||||
|
||||
if (applicationTypes != null && !applicationTypes.isEmpty()) {
|
||||
String appTypeToMatch = caseSensitive
|
||||
? application.getApplicationType()
|
||||
: StringUtils.toLowerCase(application.getApplicationType());
|
||||
String appTypeToMatch =
|
||||
StringUtils.toLowerCase(application.getApplicationType());
|
||||
if (!applicationTypes.contains(appTypeToMatch)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -915,6 +908,17 @@ public class ClientRMService extends AbstractService implements
|
|||
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
|
||||
public GetClusterNodesResponse getClusterNodes(GetClusterNodesRequest request)
|
||||
throws YarnException {
|
||||
|
|
|
@ -568,7 +568,7 @@ public class RMWebServices extends WebServices implements RMWebServiceProtocol {
|
|||
|
||||
List<ApplicationReport> appReports = null;
|
||||
try {
|
||||
appReports = rm.getClientRMService().getApplications(request, false)
|
||||
appReports = rm.getClientRMService().getApplications(request)
|
||||
.getApplicationList();
|
||||
} catch (YarnException e) {
|
||||
LOG.error("Unable to retrieve apps from ClientRMService", e);
|
||||
|
|
|
@ -994,6 +994,18 @@ public class TestClientRMService {
|
|||
Assert.assertEquals(appId2,
|
||||
getAllApplicationsResponse.getApplicationList()
|
||||
.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
|
||||
|
@ -1087,7 +1099,7 @@ public class TestClientRMService {
|
|||
assertEquals("Incorrect number of applications in queue", 2,
|
||||
rmService.getApplications(request).getApplicationList().size());
|
||||
assertEquals("Incorrect number of applications in queue", 2,
|
||||
rmService.getApplications(request, false).getApplicationList().size());
|
||||
rmService.getApplications(request).getApplicationList().size());
|
||||
|
||||
queueSet.add(queues[1]);
|
||||
assertEquals("Incorrect number of applications in queue", 3,
|
||||
|
|
|
@ -22,7 +22,6 @@ import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseS
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.isA;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
@ -647,8 +646,8 @@ public class TestRMWebServices extends JerseyTestBase {
|
|||
when(mockAppsResponse.getApplicationList())
|
||||
.thenReturn(Arrays.asList(new ApplicationReport[] { mockReport }));
|
||||
ClientRMService mockClientSvc = mock(ClientRMService.class);
|
||||
when(mockClientSvc.getApplications(isA(GetApplicationsRequest.class),
|
||||
anyBoolean())).thenReturn(mockAppsResponse);
|
||||
when(mockClientSvc.getApplications(isA(GetApplicationsRequest.class)))
|
||||
.thenReturn(mockAppsResponse);
|
||||
ResourceManager mockRM = mock(ResourceManager.class);
|
||||
RMContextImpl rmContext = new RMContextImpl(null, null, null, null, null,
|
||||
null, null, null, null, null);
|
||||
|
|
Loading…
Reference in New Issue