Search in sources :

Example 1 with GetApplicationAttemptsResponse

use of org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsResponse in project hadoop by apache.

the class TestClientRMService method testGetApplicationAttempts.

@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());
    }
}
Also used : RecordFactory(org.apache.hadoop.yarn.factories.RecordFactory) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) GetApplicationAttemptsRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) GetApplicationAttemptsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsResponse) Test(org.junit.Test)

Example 2 with GetApplicationAttemptsResponse

use of org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsResponse in project hadoop by apache.

the class ClientRMService method getApplicationAttempts.

@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) {
        // ApplicationNotFoundException and let client to handle.
        throw new ApplicationNotFoundException("Application with id '" + appId + "' doesn't exist in RM. Please check that the job submission " + "was successful.");
    }
    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 privilege to see this application " + appId);
    }
    return response;
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) RMAppAttempt(org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt) ApplicationAttemptReport(org.apache.hadoop.yarn.api.records.ApplicationAttemptReport) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) GetApplicationAttemptsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsResponse) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 3 with GetApplicationAttemptsResponse

use of org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsResponse in project hadoop by apache.

the class TestApplicationHistoryClientService method testApplicationAttempts.

@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());
}
Also used : ApplicationAttemptReport(org.apache.hadoop.yarn.api.records.ApplicationAttemptReport) GetApplicationAttemptsRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) GetApplicationAttemptsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsResponse) Test(org.junit.Test)

Example 4 with GetApplicationAttemptsResponse

use of org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsResponse in project hadoop by apache.

the class YarnClientImpl method getApplicationAttempts.

@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;
        }
        // except the following
        if (e.getClass() != ApplicationNotFoundException.class) {
            throw e;
        }
        return historyClient.getApplicationAttempts(appId);
    }
}
Also used : ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) GetApplicationAttemptsRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest) GetApplicationAttemptsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsResponse) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 5 with GetApplicationAttemptsResponse

use of org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsResponse in project hadoop by apache.

the class AHSClientImpl method getApplicationAttempts.

@Override
public List<ApplicationAttemptReport> getApplicationAttempts(ApplicationId appId) throws YarnException, IOException {
    GetApplicationAttemptsRequest request = GetApplicationAttemptsRequest.newInstance(appId);
    GetApplicationAttemptsResponse response = ahsClient.getApplicationAttempts(request);
    return response.getApplicationAttemptList();
}
Also used : GetApplicationAttemptsRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest) GetApplicationAttemptsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsResponse)

Aggregations

GetApplicationAttemptsResponse (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsResponse)5 GetApplicationAttemptsRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest)4 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)3 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)3 ApplicationAttemptReport (org.apache.hadoop.yarn.api.records.ApplicationAttemptReport)2 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)2 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 RecordFactory (org.apache.hadoop.yarn.factories.RecordFactory)1 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)1 RMAppAttempt (org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt)1