Search in sources :

Example 1 with KillApplicationResponse

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

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

the class TestKillApplicationWithRMHA method killApplication.

private void killApplication(MockRM rm, ApplicationId appId, ApplicationAttemptId appAttemptId, RMAppState rmAppState) throws Exception {
    KillApplicationResponse response = rm.killApp(appId);
    Assert.assertTrue(response.getIsKillCompleted() == isFinalState(rmAppState));
    RMApp loadedApp0 = rm.getRMContext().getRMApps().get(appId);
    rm.waitForState(appId, RMAppState.KILLED);
    if (appAttemptId != null) {
        rm.waitForState(appAttemptId, RMAppAttemptState.KILLED);
    }
    // no new attempt is created.
    Assert.assertEquals(1, loadedApp0.getAppAttempts().size());
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) KillApplicationResponse(org.apache.hadoop.yarn.api.protocolrecords.KillApplicationResponse)

Example 3 with KillApplicationResponse

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

the class MockRM method killApp.

public KillApplicationResponse killApp(ApplicationId appId) throws Exception {
    ApplicationClientProtocol client = getClientRMService();
    KillApplicationRequest req = KillApplicationRequest.newInstance(appId);
    KillApplicationResponse response = client.forceKillApplication(req);
    drainEventsImplicitly();
    return response;
}
Also used : KillApplicationResponse(org.apache.hadoop.yarn.api.protocolrecords.KillApplicationResponse) KillApplicationRequest(org.apache.hadoop.yarn.api.protocolrecords.KillApplicationRequest) ApplicationClientProtocol(org.apache.hadoop.yarn.api.ApplicationClientProtocol)

Example 4 with KillApplicationResponse

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

the class TestRMRestart method testClientRetryOnKillingApplication.

// This is to test Killing application should be able to wait until app
// reaches killed state and also check that attempt state is saved before app
// state is saved.
@Test(timeout = 60000)
public void testClientRetryOnKillingApplication() throws Exception {
    MemoryRMStateStore memStore = new TestMemoryRMStateStore();
    memStore.init(conf);
    // start RM
    MockRM rm1 = createMockRM(conf, memStore);
    rm1.start();
    MockNM nm1 = new MockNM("127.0.0.1:1234", 15120, rm1.getResourceTrackerService());
    nm1.registerNode();
    RMApp app1 = rm1.submitApp(200, "name", "user", null, false, "default", 1, null, "myType");
    MockAM am1 = launchAM(app1, rm1, nm1);
    KillApplicationResponse response;
    int count = 0;
    while (true) {
        response = rm1.killApp(app1.getApplicationId());
        if (response.getIsKillCompleted()) {
            break;
        }
        Thread.sleep(100);
        count++;
    }
    // we expect at least 2 calls for killApp as the first killApp always return
    // false.
    Assert.assertTrue(count >= 1);
    rm1.waitForState(am1.getApplicationAttemptId(), RMAppAttemptState.KILLED);
    rm1.waitForState(app1.getApplicationId(), RMAppState.KILLED);
    Assert.assertEquals(1, ((TestMemoryRMStateStore) memStore).updateAttempt);
    Assert.assertEquals(2, ((TestMemoryRMStateStore) memStore).updateApp);
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) MemoryRMStateStore(org.apache.hadoop.yarn.server.resourcemanager.recovery.MemoryRMStateStore) KillApplicationResponse(org.apache.hadoop.yarn.api.protocolrecords.KillApplicationResponse) Test(org.junit.Test)

Example 5 with KillApplicationResponse

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

the class RMWebServices method killApp.

protected Response killApp(RMApp app, UserGroupInformation callerUGI, HttpServletRequest hsr, String diagnostic) throws IOException, InterruptedException {
    if (app == null) {
        throw new IllegalArgumentException("app cannot be null");
    }
    String userName = callerUGI.getUserName();
    final ApplicationId appid = app.getApplicationId();
    KillApplicationResponse resp = null;
    try {
        resp = callerUGI.doAs(new PrivilegedExceptionAction<KillApplicationResponse>() {

            @Override
            public KillApplicationResponse run() throws IOException, YarnException {
                KillApplicationRequest req = KillApplicationRequest.newInstance(appid);
                if (diagnostic != null) {
                    req.setDiagnostics(diagnostic);
                }
                return rm.getClientRMService().forceKillApplication(req);
            }
        });
    } catch (UndeclaredThrowableException ue) {
        // bubble that up to the user
        if (ue.getCause() instanceof YarnException) {
            YarnException ye = (YarnException) ue.getCause();
            if (ye.getCause() instanceof AccessControlException) {
                String appId = app.getApplicationId().toString();
                String msg = "Unauthorized attempt to kill appid " + appId + " by remote user " + userName;
                return Response.status(Status.FORBIDDEN).entity(msg).build();
            } else {
                throw ue;
            }
        } else {
            throw ue;
        }
    }
    AppState ret = new AppState();
    ret.setState(app.getState().toString());
    if (resp.getIsKillCompleted()) {
        RMAuditLogger.logSuccess(userName, AuditConstants.KILL_APP_REQUEST, "RMWebService", app.getApplicationId());
    } else {
        return Response.status(Status.ACCEPTED).entity(ret).header(HttpHeaders.LOCATION, hsr.getRequestURL()).build();
    }
    return Response.status(Status.OK).entity(ret).build();
}
Also used : KillApplicationResponse(org.apache.hadoop.yarn.api.protocolrecords.KillApplicationResponse) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) AccessControlException(java.security.AccessControlException) KillApplicationRequest(org.apache.hadoop.yarn.api.protocolrecords.KillApplicationRequest) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) AppState(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppState) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Aggregations

KillApplicationResponse (org.apache.hadoop.yarn.api.protocolrecords.KillApplicationResponse)6 KillApplicationRequest (org.apache.hadoop.yarn.api.protocolrecords.KillApplicationRequest)4 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)3 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)2 Test (org.junit.Test)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 AccessControlException (java.security.AccessControlException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 ApplicationClientProtocol (org.apache.hadoop.yarn.api.ApplicationClientProtocol)1 GetApplicationsRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest)1 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)1 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)1 MemoryRMStateStore (org.apache.hadoop.yarn.server.resourcemanager.recovery.MemoryRMStateStore)1 AppState (org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppState)1 Matchers.anyString (org.mockito.Matchers.anyString)1