Search in sources :

Example 6 with GetApplicationReportRequest

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

the class WebServices method getApp.

public AppInfo getApp(HttpServletRequest req, HttpServletResponse res, String appId) {
    UserGroupInformation callerUGI = getUser(req);
    final ApplicationId id = parseApplicationId(appId);
    ApplicationReport app = null;
    try {
        if (callerUGI == null) {
            GetApplicationReportRequest request = GetApplicationReportRequest.newInstance(id);
            app = appBaseProt.getApplicationReport(request).getApplicationReport();
        } else {
            app = callerUGI.doAs(new PrivilegedExceptionAction<ApplicationReport>() {

                @Override
                public ApplicationReport run() throws Exception {
                    GetApplicationReportRequest request = GetApplicationReportRequest.newInstance(id);
                    return appBaseProt.getApplicationReport(request).getApplicationReport();
                }
            });
        }
    } catch (Exception e) {
        rewrapAndThrowException(e);
    }
    if (app == null) {
        throw new NotFoundException("app with id: " + appId + " not found");
    }
    return new AppInfo(app);
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) GetApplicationReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ForbiddenException(org.apache.hadoop.yarn.webapp.ForbiddenException) AuthorizationException(org.apache.hadoop.security.authorize.AuthorizationException) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) WebApplicationException(javax.ws.rs.WebApplicationException) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) AppInfo(org.apache.hadoop.yarn.server.webapp.dao.AppInfo)

Example 7 with GetApplicationReportRequest

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

the class TestApplicationLifetimeMonitor method testApplicationLifetimeMonitor.

@Test(timeout = 60000)
public void testApplicationLifetimeMonitor() throws Exception {
    MockRM rm = null;
    try {
        rm = new MockRM(conf);
        rm.start();
        Priority appPriority = Priority.newInstance(0);
        MockNM nm1 = rm.registerNode("127.0.0.1:1234", 16 * 1024);
        Map<ApplicationTimeoutType, Long> timeouts = new HashMap<ApplicationTimeoutType, Long>();
        timeouts.put(ApplicationTimeoutType.LIFETIME, 10L);
        RMApp app1 = rm.submitApp(1024, appPriority, timeouts);
        // 20L seconds
        timeouts.put(ApplicationTimeoutType.LIFETIME, 20L);
        RMApp app2 = rm.submitApp(1024, appPriority, timeouts);
        nm1.nodeHeartbeat(true);
        // Send launch Event
        MockAM am1 = rm.sendAMLaunched(app1.getCurrentAppAttempt().getAppAttemptId());
        am1.registerAppAttempt();
        rm.waitForState(app1.getApplicationId(), RMAppState.KILLED);
        Assert.assertTrue("Application killed before lifetime value", (System.currentTimeMillis() - app1.getSubmitTime()) > 10000);
        Map<ApplicationTimeoutType, String> updateTimeout = new HashMap<ApplicationTimeoutType, String>();
        long newLifetime = 10L;
        // update 10L seconds more to timeout
        String formatISO8601 = Times.formatISO8601(System.currentTimeMillis() + newLifetime * 1000);
        updateTimeout.put(ApplicationTimeoutType.LIFETIME, formatISO8601);
        UpdateApplicationTimeoutsRequest request = UpdateApplicationTimeoutsRequest.newInstance(app2.getApplicationId(), updateTimeout);
        Map<ApplicationTimeoutType, Long> applicationTimeouts = app2.getApplicationTimeouts();
        // has old timeout time
        long beforeUpdate = applicationTimeouts.get(ApplicationTimeoutType.LIFETIME);
        // update app2 lifetime to new time i.e now + timeout
        rm.getRMContext().getClientRMService().updateApplicationTimeouts(request);
        applicationTimeouts = app2.getApplicationTimeouts();
        long afterUpdate = applicationTimeouts.get(ApplicationTimeoutType.LIFETIME);
        Assert.assertTrue("Application lifetime value not updated", afterUpdate > beforeUpdate);
        // verify for application report.
        RecordFactory recordFactory = RecordFactoryProvider.getRecordFactory(null);
        GetApplicationReportRequest appRequest = recordFactory.newRecordInstance(GetApplicationReportRequest.class);
        appRequest.setApplicationId(app2.getApplicationId());
        Map<ApplicationTimeoutType, ApplicationTimeout> appTimeouts = rm.getRMContext().getClientRMService().getApplicationReport(appRequest).getApplicationReport().getApplicationTimeouts();
        Assert.assertTrue("Application Timeout are empty.", !appTimeouts.isEmpty());
        ApplicationTimeout timeout = appTimeouts.get(ApplicationTimeoutType.LIFETIME);
        Assert.assertEquals("Application timeout string is incorrect.", formatISO8601, timeout.getExpiryTime());
        Assert.assertTrue("Application remaining time is incorrect", timeout.getRemainingTime() > 0);
        rm.waitForState(app2.getApplicationId(), RMAppState.KILLED);
        // verify for app killed with updated lifetime
        Assert.assertTrue("Application killed before lifetime value", app2.getFinishTime() > afterUpdate);
    } finally {
        stopRM(rm);
    }
}
Also used : GetApplicationReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest) HashMap(java.util.HashMap) Priority(org.apache.hadoop.yarn.api.records.Priority) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) ApplicationTimeoutType(org.apache.hadoop.yarn.api.records.ApplicationTimeoutType) MockRM(org.apache.hadoop.yarn.server.resourcemanager.MockRM) UpdateApplicationTimeoutsRequest(org.apache.hadoop.yarn.api.protocolrecords.UpdateApplicationTimeoutsRequest) RecordFactory(org.apache.hadoop.yarn.factories.RecordFactory) ApplicationTimeout(org.apache.hadoop.yarn.api.records.ApplicationTimeout) MockAM(org.apache.hadoop.yarn.server.resourcemanager.MockAM) Test(org.junit.Test)

Example 8 with GetApplicationReportRequest

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

the class TestClientToAMTokens method testClientToAMTokens.

@Test
public void testClientToAMTokens() throws Exception {
    conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
    // Set RPC engine to protobuf RPC engine
    RPC.setProtocolEngine(conf, CustomProtocol.class, ProtobufRpcEngine.class);
    UserGroupInformation.setConfiguration(conf);
    ContainerManagementProtocol containerManager = mock(ContainerManagementProtocol.class);
    StartContainersResponse mockResponse = mock(StartContainersResponse.class);
    when(containerManager.startContainers((StartContainersRequest) any())).thenReturn(mockResponse);
    final DrainDispatcher dispatcher = new DrainDispatcher();
    MockRM rm = new MockRMWithCustomAMLauncher(conf, containerManager) {

        protected ClientRMService createClientRMService() {
            return new ClientRMService(this.rmContext, scheduler, this.rmAppManager, this.applicationACLsManager, this.queueACLsManager, getRMContext().getRMDelegationTokenSecretManager());
        }

        ;

        @Override
        protected Dispatcher createDispatcher() {
            return dispatcher;
        }

        @Override
        protected void doSecureLogin() throws IOException {
        }
    };
    rm.start();
    // Submit an app
    RMApp app = rm.submitApp(1024);
    // Set up a node.
    MockNM nm1 = rm.registerNode("localhost:1234", 3072);
    nm1.nodeHeartbeat(true);
    dispatcher.await();
    nm1.nodeHeartbeat(true);
    dispatcher.await();
    ApplicationAttemptId appAttempt = app.getCurrentAppAttempt().getAppAttemptId();
    final MockAM mockAM = new MockAM(rm.getRMContext(), rm.getApplicationMasterService(), app.getCurrentAppAttempt().getAppAttemptId());
    UserGroupInformation appUgi = UserGroupInformation.createRemoteUser(appAttempt.toString());
    RegisterApplicationMasterResponse response = appUgi.doAs(new PrivilegedAction<RegisterApplicationMasterResponse>() {

        @Override
        public RegisterApplicationMasterResponse run() {
            RegisterApplicationMasterResponse response = null;
            try {
                response = mockAM.registerAppAttempt();
            } catch (Exception e) {
                Assert.fail("Exception was not expected");
            }
            return response;
        }
    });
    // Get the app-report.
    GetApplicationReportRequest request = Records.newRecord(GetApplicationReportRequest.class);
    request.setApplicationId(app.getApplicationId());
    GetApplicationReportResponse reportResponse = rm.getClientRMService().getApplicationReport(request);
    ApplicationReport appReport = reportResponse.getApplicationReport();
    org.apache.hadoop.yarn.api.records.Token originalClientToAMToken = appReport.getClientToAMToken();
    // ClientToAMToken master key should have been received on register
    // application master response.
    Assert.assertNotNull(response.getClientToAMTokenMasterKey());
    Assert.assertTrue(response.getClientToAMTokenMasterKey().array().length > 0);
    // Start the AM with the correct shared-secret.
    ApplicationAttemptId appAttemptId = app.getAppAttempts().keySet().iterator().next();
    Assert.assertNotNull(appAttemptId);
    final CustomAM am = new CustomAM(appAttemptId, response.getClientToAMTokenMasterKey().array());
    am.init(conf);
    am.start();
    // Now the real test!
    // Set up clients to be able to pick up correct tokens.
    SecurityUtil.setSecurityInfoProviders(new CustomSecurityInfo());
    // Verify denial for unauthenticated user
    try {
        CustomProtocol client = RPC.getProxy(CustomProtocol.class, 1L, am.address, conf);
        client.ping(null, TestRpcBase.newEmptyRequest());
        fail("Access by unauthenticated user should fail!!");
    } catch (Exception e) {
        Assert.assertFalse(am.pinged);
    }
    Token<ClientToAMTokenIdentifier> token = ConverterUtils.convertFromYarn(originalClientToAMToken, am.address);
    // Verify denial for a malicious user with tampered ID
    verifyTokenWithTamperedID(conf, am, token);
    // Verify denial for a malicious user with tampered user-name
    verifyTokenWithTamperedUserName(conf, am, token);
    // Now for an authenticated user
    verifyValidToken(conf, am, token);
    // Verify for a new version token
    verifyNewVersionToken(conf, am, token, rm);
    am.stop();
    rm.stop();
}
Also used : DrainDispatcher(org.apache.hadoop.yarn.event.DrainDispatcher) RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) MockRMWithCustomAMLauncher(org.apache.hadoop.yarn.server.resourcemanager.MockRMWithCustomAMLauncher) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) MockRM(org.apache.hadoop.yarn.server.resourcemanager.MockRM) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) GetApplicationReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest) StartContainersResponse(org.apache.hadoop.yarn.api.protocolrecords.StartContainersResponse) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) ServiceException(com.google.protobuf.ServiceException) SaslException(javax.security.sasl.SaslException) IOException(java.io.IOException) RemoteException(org.apache.hadoop.ipc.RemoteException) YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) ClientRMService(org.apache.hadoop.yarn.server.resourcemanager.ClientRMService) ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) ClientToAMTokenIdentifier(org.apache.hadoop.yarn.security.client.ClientToAMTokenIdentifier) ContainerManagementProtocol(org.apache.hadoop.yarn.api.ContainerManagementProtocol) RegisterApplicationMasterResponse(org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse) MockAM(org.apache.hadoop.yarn.server.resourcemanager.MockAM) GetApplicationReportResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse) Test(org.junit.Test)

Example 9 with GetApplicationReportRequest

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

the class AppReportFetcher method getApplicationReport.

/**
   * Get an application report for the specified application id from the RM and
   * fall back to the Application History Server if not found in RM.
   * @param appId id of the application to get.
   * @return the ApplicationReport for the appId.
   * @throws YarnException on any error.
   * @throws IOException
   */
public FetchedAppReport getApplicationReport(ApplicationId appId) throws YarnException, IOException {
    GetApplicationReportRequest request = recordFactory.newRecordInstance(GetApplicationReportRequest.class);
    request.setApplicationId(appId);
    ApplicationReport appReport;
    FetchedAppReport fetchedAppReport;
    try {
        appReport = applicationsManager.getApplicationReport(request).getApplicationReport();
        fetchedAppReport = new FetchedAppReport(appReport, AppReportSource.RM);
    } catch (ApplicationNotFoundException e) {
        if (!isAHSEnabled) {
            // Just throw it as usual if historyService is not enabled.
            throw e;
        }
        //Fetch the application report from AHS
        appReport = historyManager.getApplicationReport(request).getApplicationReport();
        fetchedAppReport = new FetchedAppReport(appReport, AppReportSource.AHS);
    }
    return fetchedAppReport;
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) GetApplicationReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)

Example 10 with GetApplicationReportRequest

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

the class TestApplicationHistoryClientService method testApplicationReport.

@Test
public void testApplicationReport() throws IOException, YarnException {
    ApplicationId appId = null;
    appId = ApplicationId.newInstance(0, 1);
    GetApplicationReportRequest request = GetApplicationReportRequest.newInstance(appId);
    GetApplicationReportResponse response = clientService.getApplicationReport(request);
    ApplicationReport appReport = response.getApplicationReport();
    Assert.assertNotNull(appReport);
    Assert.assertEquals(123, appReport.getApplicationResourceUsageReport().getMemorySeconds());
    Assert.assertEquals(345, appReport.getApplicationResourceUsageReport().getVcoreSeconds());
    Assert.assertEquals("application_0_0001", appReport.getApplicationId().toString());
    Assert.assertEquals("test app type", appReport.getApplicationType().toString());
    Assert.assertEquals("test queue", appReport.getQueue().toString());
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) GetApplicationReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) GetApplicationReportResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse) Test(org.junit.Test)

Aggregations

GetApplicationReportRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest)24 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)14 GetApplicationReportResponse (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse)13 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)11 Test (org.junit.Test)8 ApplicationClientProtocol (org.apache.hadoop.yarn.api.ApplicationClientProtocol)7 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)6 AccessControlList (org.apache.hadoop.security.authorize.AccessControlList)5 KillApplicationRequest (org.apache.hadoop.yarn.api.protocolrecords.KillApplicationRequest)5 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)4 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)4 IOException (java.io.IOException)3 ContainerNotFoundException (org.apache.hadoop.yarn.exceptions.ContainerNotFoundException)3 RecordFactory (org.apache.hadoop.yarn.factories.RecordFactory)3 ClientRMService (org.apache.hadoop.yarn.server.resourcemanager.ClientRMService)3 MockAM (org.apache.hadoop.yarn.server.resourcemanager.MockAM)3 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)3 MockRM (org.apache.hadoop.yarn.server.resourcemanager.MockRM)3 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)3 ServiceException (com.google.protobuf.ServiceException)2