Search in sources :

Example 1 with GetApplicationAttemptsRequest

use of org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest 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 2 with GetApplicationAttemptsRequest

use of org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest 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 3 with GetApplicationAttemptsRequest

use of org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest 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 4 with GetApplicationAttemptsRequest

use of org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest 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)

Example 5 with GetApplicationAttemptsRequest

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

the class AppBlock method render.

@Override
protected void render(Block html) {
    String webUiType = $(WEB_UI_TYPE);
    String aid = $(APPLICATION_ID);
    if (aid.isEmpty()) {
        puts("Bad request: requires Application ID");
        return;
    }
    try {
        appID = Apps.toAppID(aid);
    } catch (Exception e) {
        puts("Invalid Application ID: " + aid);
        return;
    }
    UserGroupInformation callerUGI = getCallerUGI();
    ApplicationReport appReport;
    try {
        final GetApplicationReportRequest request = GetApplicationReportRequest.newInstance(appID);
        if (callerUGI == null) {
            throw new AuthenticationException("Failed to get user name from request");
        } else {
            appReport = callerUGI.doAs(new PrivilegedExceptionAction<ApplicationReport>() {

                @Override
                public ApplicationReport run() throws Exception {
                    return appBaseProt.getApplicationReport(request).getApplicationReport();
                }
            });
        }
    } catch (Exception e) {
        String message = "Failed to read the application " + appID + ".";
        LOG.error(message, e);
        html.p()._(message)._();
        return;
    }
    if (appReport == null) {
        puts("Application not found: " + aid);
        return;
    }
    AppInfo app = new AppInfo(appReport);
    setTitle(join("Application ", aid));
    if (webUiType != null && webUiType.equals(YarnWebParams.RM_WEB_UI) && conf.getBoolean(YarnConfiguration.RM_WEBAPP_UI_ACTIONS_ENABLED, YarnConfiguration.DEFAULT_RM_WEBAPP_UI_ACTIONS_ENABLED)) {
        // Application Kill
        html.div().button().$onclick("confirmAction()").b("Kill Application")._()._();
        StringBuilder script = new StringBuilder();
        script.append("function confirmAction() {").append(" b = confirm(\"Are you sure?\");").append(" if (b == true) {").append(" $.ajax({").append(" type: 'PUT',").append(" url: '/ws/v1/cluster/apps/").append(aid).append("/state',").append(" contentType: 'application/json',").append(getCSRFHeaderString(conf)).append(" data: '{\"state\":\"KILLED\"}',").append(" dataType: 'json'").append(" }).done(function(data){").append(" setTimeout(function(){").append(" location.href = '/cluster/app/").append(aid).append("';").append(" }, 1000);").append(" }).fail(function(data){").append(" console.log(data);").append(" });").append(" }").append("}");
        html.script().$type("text/javascript")._(script.toString())._();
    }
    String schedulerPath = WebAppUtils.getResolvedRMWebAppURLWithScheme(conf) + "/cluster/scheduler?openQueues=" + app.getQueue();
    generateOverviewTable(app, schedulerPath, webUiType, appReport);
    Collection<ApplicationAttemptReport> attempts;
    try {
        final GetApplicationAttemptsRequest request = GetApplicationAttemptsRequest.newInstance(appID);
        attempts = callerUGI.doAs(new PrivilegedExceptionAction<Collection<ApplicationAttemptReport>>() {

            @Override
            public Collection<ApplicationAttemptReport> run() throws Exception {
                return appBaseProt.getApplicationAttempts(request).getApplicationAttemptList();
            }
        });
    } catch (Exception e) {
        String message = "Failed to read the attempts of the application " + appID + ".";
        LOG.error(message, e);
        html.p()._(message)._();
        return;
    }
    createApplicationMetricsTable(html);
    html._(InfoBlock.class);
    generateApplicationTable(html, callerUGI, attempts);
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) GetApplicationReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest) ApplicationAttemptReport(org.apache.hadoop.yarn.api.records.ApplicationAttemptReport) AuthenticationException(org.apache.hadoop.security.authentication.client.AuthenticationException) GetApplicationAttemptsRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) AuthenticationException(org.apache.hadoop.security.authentication.client.AuthenticationException) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) AppInfo(org.apache.hadoop.yarn.server.webapp.dao.AppInfo)

Aggregations

GetApplicationAttemptsRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest)6 GetApplicationAttemptsResponse (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsResponse)4 ApplicationAttemptReport (org.apache.hadoop.yarn.api.records.ApplicationAttemptReport)3 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)3 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)2 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)2 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)2 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)2 ContainerNotFoundException (org.apache.hadoop.yarn.exceptions.ContainerNotFoundException)2 Test (org.junit.Test)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 AuthenticationException (org.apache.hadoop.security.authentication.client.AuthenticationException)1 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)1 GetApplicationReportRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest)1 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)1 ApplicationAttemptNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException)1 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)1 RecordFactory (org.apache.hadoop.yarn.factories.RecordFactory)1 AppAttemptInfo (org.apache.hadoop.yarn.server.webapp.dao.AppAttemptInfo)1