Search in sources :

Example 1 with KillApplicationRequest

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

the class TestClientRMService method testForceKillApplication.

@Test
public void testForceKillApplication() throws Exception {
    YarnConfiguration conf = new YarnConfiguration();
    conf.setBoolean(MockRM.ENABLE_WEBAPP, true);
    MockRM rm = new MockRM(conf);
    rm.init(conf);
    rm.start();
    ClientRMService rmService = rm.getClientRMService();
    GetApplicationsRequest getRequest = GetApplicationsRequest.newInstance(EnumSet.of(YarnApplicationState.KILLED));
    RMApp app1 = rm.submitApp(1024);
    RMApp app2 = rm.submitApp(1024, true);
    assertEquals("Incorrect number of apps in the RM", 0, rmService.getApplications(getRequest).getApplicationList().size());
    KillApplicationRequest killRequest1 = KillApplicationRequest.newInstance(app1.getApplicationId());
    String diagnostic = "message1";
    killRequest1.setDiagnostics(diagnostic);
    KillApplicationRequest killRequest2 = KillApplicationRequest.newInstance(app2.getApplicationId());
    int killAttemptCount = 0;
    for (int i = 0; i < 100; i++) {
        KillApplicationResponse killResponse1 = rmService.forceKillApplication(killRequest1);
        killAttemptCount++;
        if (killResponse1.getIsKillCompleted()) {
            break;
        }
        Thread.sleep(10);
    }
    assertTrue("Kill attempt count should be greater than 1 for managed AMs", killAttemptCount > 1);
    assertEquals("Incorrect number of apps in the RM", 1, rmService.getApplications(getRequest).getApplicationList().size());
    assertTrue("Diagnostic message is incorrect", app1.getDiagnostics().toString().contains(diagnostic));
    KillApplicationResponse killResponse2 = rmService.forceKillApplication(killRequest2);
    assertTrue("Killing UnmanagedAM should falsely acknowledge true", killResponse2.getIsKillCompleted());
    for (int i = 0; i < 100; i++) {
        if (2 == rmService.getApplications(getRequest).getApplicationList().size()) {
            break;
        }
        Thread.sleep(10);
    }
    assertEquals("Incorrect number of apps in the RM", 2, rmService.getApplications(getRequest).getApplicationList().size());
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) KillApplicationResponse(org.apache.hadoop.yarn.api.protocolrecords.KillApplicationResponse) KillApplicationRequest(org.apache.hadoop.yarn.api.protocolrecords.KillApplicationRequest) Matchers.anyString(org.mockito.Matchers.anyString) GetApplicationsRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest) Test(org.junit.Test)

Example 2 with KillApplicationRequest

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

the class TestClientRMService method testForceKillNonExistingApplication.

@Test
public void testForceKillNonExistingApplication() throws YarnException {
    RMContext rmContext = mock(RMContext.class);
    when(rmContext.getRMApps()).thenReturn(new ConcurrentHashMap<ApplicationId, RMApp>());
    ClientRMService rmService = new ClientRMService(rmContext, null, null, null, null, null);
    ApplicationId applicationId = BuilderUtils.newApplicationId(System.currentTimeMillis(), 0);
    KillApplicationRequest request = KillApplicationRequest.newInstance(applicationId);
    try {
        rmService.forceKillApplication(request);
        Assert.fail();
    } catch (ApplicationNotFoundException ex) {
        Assert.assertEquals(ex.getMessage(), "Trying to kill an absent " + "application " + request.getApplicationId());
    }
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) KillApplicationRequest(org.apache.hadoop.yarn.api.protocolrecords.KillApplicationRequest) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Test(org.junit.Test)

Example 3 with KillApplicationRequest

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

the class TestApplicationACLs method verifyFriendAccess.

private void verifyFriendAccess() throws Exception {
    AccessControlList viewACL = new AccessControlList("");
    viewACL.addGroup(FRIENDLY_GROUP);
    AccessControlList modifyACL = new AccessControlList("");
    modifyACL.addUser(FRIEND);
    ApplicationId applicationId = submitAppAndGetAppId(viewACL, modifyACL);
    final GetApplicationReportRequest appReportRequest = recordFactory.newRecordInstance(GetApplicationReportRequest.class);
    appReportRequest.setApplicationId(applicationId);
    final KillApplicationRequest finishAppRequest = recordFactory.newRecordInstance(KillApplicationRequest.class);
    finishAppRequest.setApplicationId(applicationId);
    ApplicationClientProtocol friendClient = getRMClientForUser(FRIEND);
    // View as the friend
    friendClient.getApplicationReport(appReportRequest);
    // List apps as friend
    Assert.assertEquals("App view by a friend should list the apps!!", 3, friendClient.getApplications(recordFactory.newRecordInstance(GetApplicationsRequest.class)).getApplicationList().size());
    // Kill app as the friend
    friendClient.forceKillApplication(finishAppRequest);
    resourceManager.waitForState(applicationId, RMAppState.KILLED);
}
Also used : AccessControlList(org.apache.hadoop.security.authorize.AccessControlList) GetApplicationReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest) KillApplicationRequest(org.apache.hadoop.yarn.api.protocolrecords.KillApplicationRequest) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ApplicationClientProtocol(org.apache.hadoop.yarn.api.ApplicationClientProtocol)

Example 4 with KillApplicationRequest

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

the class TestApplicationACLs method verifyEnemyAccess.

private void verifyEnemyAccess() throws Exception {
    AccessControlList viewACL = new AccessControlList("");
    viewACL.addGroup(FRIENDLY_GROUP);
    AccessControlList modifyACL = new AccessControlList("");
    modifyACL.addUser(FRIEND);
    ApplicationId applicationId = submitAppAndGetAppId(viewACL, modifyACL);
    final GetApplicationReportRequest appReportRequest = recordFactory.newRecordInstance(GetApplicationReportRequest.class);
    appReportRequest.setApplicationId(applicationId);
    final KillApplicationRequest finishAppRequest = recordFactory.newRecordInstance(KillApplicationRequest.class);
    finishAppRequest.setApplicationId(applicationId);
    ApplicationClientProtocol enemyRmClient = getRMClientForUser(ENEMY);
    // View as the enemy
    ApplicationReport appReport = enemyRmClient.getApplicationReport(appReportRequest).getApplicationReport();
    verifyEnemyAppReport(appReport);
    // List apps as enemy
    List<ApplicationReport> appReports = enemyRmClient.getApplications(recordFactory.newRecordInstance(GetApplicationsRequest.class)).getApplicationList();
    Assert.assertEquals("App view by enemy should list the apps!!", 4, appReports.size());
    for (ApplicationReport report : appReports) {
        verifyEnemyAppReport(report);
    }
    // Kill app as the enemy
    try {
        enemyRmClient.forceKillApplication(finishAppRequest);
        Assert.fail("App killing by the enemy should fail!!");
    } catch (YarnException e) {
        LOG.info("Got exception while killing app as the enemy", e);
        Assert.assertTrue(e.getMessage().contains("User enemy cannot perform operation MODIFY_APP on " + applicationId));
    }
    rmClient.forceKillApplication(finishAppRequest);
}
Also used : AccessControlList(org.apache.hadoop.security.authorize.AccessControlList) ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) GetApplicationReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest) KillApplicationRequest(org.apache.hadoop.yarn.api.protocolrecords.KillApplicationRequest) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ApplicationClientProtocol(org.apache.hadoop.yarn.api.ApplicationClientProtocol) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 5 with KillApplicationRequest

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

the class QueueACLsTestBase method verifyKillAppSuccess.

private void verifyKillAppSuccess(String submitter, String killer, String queueName, boolean setupACLs) throws Exception {
    ApplicationId applicationId = submitAppAndGetAppId(submitter, queueName, setupACLs);
    final KillApplicationRequest finishAppRequest = KillApplicationRequest.newInstance(applicationId);
    ApplicationClientProtocol ownerClient = getRMClientForUser(killer);
    // Kill app as killer
    ownerClient.forceKillApplication(finishAppRequest);
    resourceManager.waitForState(applicationId, RMAppState.KILLED);
}
Also used : KillApplicationRequest(org.apache.hadoop.yarn.api.protocolrecords.KillApplicationRequest) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ApplicationClientProtocol(org.apache.hadoop.yarn.api.ApplicationClientProtocol)

Aggregations

KillApplicationRequest (org.apache.hadoop.yarn.api.protocolrecords.KillApplicationRequest)13 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)9 ApplicationClientProtocol (org.apache.hadoop.yarn.api.ApplicationClientProtocol)7 AccessControlList (org.apache.hadoop.security.authorize.AccessControlList)5 GetApplicationReportRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest)5 KillApplicationResponse (org.apache.hadoop.yarn.api.protocolrecords.KillApplicationResponse)4 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)4 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)3 Test (org.junit.Test)3 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 AccessControlException (java.security.AccessControlException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 GetApplicationsRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest)1 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)1 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)1 AbstractEvent (org.apache.hadoop.yarn.event.AbstractEvent)1 Dispatcher (org.apache.hadoop.yarn.event.Dispatcher)1 DrainDispatcher (org.apache.hadoop.yarn.event.DrainDispatcher)1 Event (org.apache.hadoop.yarn.event.Event)1 EventHandler (org.apache.hadoop.yarn.event.EventHandler)1