@Test public void testGetApplicationAttempts() throws YarnException, IOException { ClientRMService rmService = createRMService(); RecordFactory recordFactory = RecordFactoryProvider.getRecordFactory(null); GetApplicationAttemptsRequest request = recordFactory .newRecordInstance(GetApplicationAttemptsRequest.class); ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance( ApplicationId.newInstance(123456, 1), 1); request.setApplicationId(ApplicationId.newInstance(123456, 1)); try { GetApplicationAttemptsResponse response = rmService .getApplicationAttempts(request); Assert.assertEquals(1, response.getApplicationAttemptList().size()); Assert.assertEquals(attemptId, response.getApplicationAttemptList() .get(0).getApplicationAttemptId()); } catch (ApplicationNotFoundException ex) { Assert.fail(ex.getMessage()); } }
@Test public void testApplicationAttempts() throws IOException, YarnException { ApplicationId appId = ApplicationId.newInstance(0, 1); ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1); ApplicationAttemptId appAttemptId1 = ApplicationAttemptId.newInstance(appId, 2); GetApplicationAttemptsRequest request = GetApplicationAttemptsRequest.newInstance(appId); GetApplicationAttemptsResponse response = clientService.getApplicationAttempts(request); List<ApplicationAttemptReport> attemptReports = response.getApplicationAttemptList(); Assert.assertNotNull(attemptReports); Assert.assertEquals(appAttemptId, attemptReports.get(0) .getApplicationAttemptId()); Assert.assertEquals(appAttemptId1, attemptReports.get(1) .getApplicationAttemptId()); }
@Override public List<ApplicationAttemptReport> getApplicationAttempts( ApplicationId appId) throws YarnException, IOException { try { GetApplicationAttemptsRequest request = Records .newRecord(GetApplicationAttemptsRequest.class); request.setApplicationId(appId); GetApplicationAttemptsResponse response = rmClient .getApplicationAttempts(request); return response.getApplicationAttemptList(); } catch (YarnException e) { if (!historyServiceEnabled) { // Just throw it as usual if historyService is not enabled. throw e; } // Even if history-service is enabled, treat all exceptions still the same // except the following if (e.getClass() != ApplicationNotFoundException.class) { throw e; } return historyClient.getApplicationAttempts(appId); } }
@Test public void testApplicationAttempts() throws IOException, YarnException { ApplicationId appId = ApplicationId.newInstance(0, 1); ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1); ApplicationAttemptId appAttemptId1 = ApplicationAttemptId.newInstance(appId, 2); GetApplicationAttemptsRequest request = GetApplicationAttemptsRequest.newInstance(appId); GetApplicationAttemptsResponse response = clientService.getClientHandler().getApplicationAttempts(request); List<ApplicationAttemptReport> attemptReports = response.getApplicationAttemptList(); Assert.assertNotNull(attemptReports); Collections.sort(attemptReports, new Comparator<ApplicationAttemptReport>() { @Override public int compare(ApplicationAttemptReport o1, ApplicationAttemptReport o2) { return o1.getApplicationAttemptId().compareTo(o2.getApplicationAttemptId()); } }); Assert.assertEquals(appAttemptId, attemptReports.get(0) .getApplicationAttemptId()); Assert.assertEquals(appAttemptId1, attemptReports.get(1) .getApplicationAttemptId()); }
@Test public void testApplicationAttempts() throws IOException, YarnException { ApplicationId appId = ApplicationId.newInstance(0, 1); ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1); ApplicationAttemptId appAttemptId1 = ApplicationAttemptId.newInstance(appId, 2); writeApplicationAttemptStartData(appAttemptId); writeApplicationAttemptFinishData(appAttemptId); writeApplicationAttemptStartData(appAttemptId1); writeApplicationAttemptFinishData(appAttemptId1); GetApplicationAttemptsRequest request = GetApplicationAttemptsRequest.newInstance(appId); GetApplicationAttemptsResponse response = historyServer.getClientService().getClientHandler() .getApplicationAttempts(request); List<ApplicationAttemptReport> attemptReports = response.getApplicationAttemptList(); Assert.assertNotNull(attemptReports); Assert.assertEquals(appAttemptId, attemptReports.get(0) .getApplicationAttemptId()); Assert.assertEquals(appAttemptId1, attemptReports.get(1) .getApplicationAttemptId()); }
@Override public GetApplicationAttemptsResponse getApplicationAttempts( GetApplicationAttemptsRequest request) throws YarnException, IOException { GetApplicationAttemptsRequestProto requestProto = ((GetApplicationAttemptsRequestPBImpl) request).getProto(); try { return new GetApplicationAttemptsResponsePBImpl( proxy.getApplicationAttempts(null, requestProto)); } catch (ServiceException e) { RPCUtil.unwrapAndThrowException(e); return null; } }
@Override public GetApplicationAttemptsResponse getApplicationAttempts( GetApplicationAttemptsRequest request) throws YarnException, IOException { ApplicationId appId = request.getApplicationId(); UserGroupInformation callerUGI; try { callerUGI = UserGroupInformation.getCurrentUser(); } catch (IOException ie) { LOG.info("Error getting UGI ", ie); throw RPCUtil.getRemoteException(ie); } RMApp application = this.rmContext.getRMApps().get(appId); if (application == null) { // If the RM doesn't have the application, throw // ApplicationNotFoundException and let client to handle. throw new ApplicationNotFoundException("Application with id '" + appId + "' doesn't exist in RM."); } boolean allowAccess = checkAccess(callerUGI, application.getUser(), ApplicationAccessType.VIEW_APP, application); GetApplicationAttemptsResponse response = null; if (allowAccess) { Map<ApplicationAttemptId, RMAppAttempt> attempts = application .getAppAttempts(); List<ApplicationAttemptReport> listAttempts = new ArrayList<ApplicationAttemptReport>(); Iterator<Map.Entry<ApplicationAttemptId, RMAppAttempt>> iter = attempts .entrySet().iterator(); while (iter.hasNext()) { listAttempts.add(iter.next().getValue() .createApplicationAttemptReport()); } response = GetApplicationAttemptsResponse.newInstance(listAttempts); } else { throw new YarnException("User " + callerUGI.getShortUserName() + " does not have privilage to see this aplication " + appId); } return response; }
@Override public GetApplicationAttemptsResponse getApplicationAttempts( GetApplicationAttemptsRequest request) throws YarnException, IOException { GetApplicationAttemptsResponse response = GetApplicationAttemptsResponse .newInstance(new ArrayList<ApplicationAttemptReport>(history .getApplicationAttempts(request.getApplicationId()).values())); return response; }
@Override public List<ApplicationAttemptReport> getApplicationAttempts( ApplicationId appId) throws YarnException, IOException { GetApplicationAttemptsRequest request = GetApplicationAttemptsRequest .newInstance(appId); GetApplicationAttemptsResponse response = ahsClient .getApplicationAttempts(request); return response.getApplicationAttemptList(); }
@Override public GetApplicationAttemptsResponse getApplicationAttempts( GetApplicationAttemptsRequest request) throws YarnException, IOException { resetStartFailoverFlag(true); // make sure failover has been triggered Assert.assertTrue(waittingForFailOver()); // return fake ApplicationAttemptReports return GetApplicationAttemptsResponse .newInstance(createFakeApplicationAttemptReports()); }