Search in sources :

Example 1 with RMAppKillByClientEvent

use of org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppKillByClientEvent in project hadoop by apache.

the class ClientRMService method forceKillApplication.

@SuppressWarnings("unchecked")
@Override
public KillApplicationResponse forceKillApplication(KillApplicationRequest request) throws YarnException {
    ApplicationId applicationId = request.getApplicationId();
    CallerContext callerContext = CallerContext.getCurrent();
    UserGroupInformation callerUGI;
    try {
        callerUGI = UserGroupInformation.getCurrentUser();
    } catch (IOException ie) {
        LOG.info("Error getting UGI ", ie);
        RMAuditLogger.logFailure("UNKNOWN", AuditConstants.KILL_APP_REQUEST, "UNKNOWN", "ClientRMService", "Error getting UGI", applicationId, callerContext);
        throw RPCUtil.getRemoteException(ie);
    }
    RMApp application = this.rmContext.getRMApps().get(applicationId);
    if (application == null) {
        RMAuditLogger.logFailure(callerUGI.getUserName(), AuditConstants.KILL_APP_REQUEST, "UNKNOWN", "ClientRMService", "Trying to kill an absent application", applicationId, callerContext);
        throw new ApplicationNotFoundException("Trying to kill an absent" + " application " + applicationId);
    }
    if (!checkAccess(callerUGI, application.getUser(), ApplicationAccessType.MODIFY_APP, application)) {
        RMAuditLogger.logFailure(callerUGI.getShortUserName(), AuditConstants.KILL_APP_REQUEST, "User doesn't have permissions to " + ApplicationAccessType.MODIFY_APP.toString(), "ClientRMService", AuditConstants.UNAUTHORIZED_USER, applicationId, callerContext);
        throw RPCUtil.getRemoteException(new AccessControlException("User " + callerUGI.getShortUserName() + " cannot perform operation " + ApplicationAccessType.MODIFY_APP.name() + " on " + applicationId));
    }
    if (application.isAppFinalStateStored()) {
        return KillApplicationResponse.newInstance(true);
    }
    StringBuilder message = new StringBuilder();
    message.append("Application ").append(applicationId).append(" was killed by user ").append(callerUGI.getShortUserName());
    InetAddress remoteAddress = Server.getRemoteIp();
    if (null != remoteAddress) {
        message.append(" at ").append(remoteAddress.getHostAddress());
    }
    String diagnostics = org.apache.commons.lang.StringUtils.trimToNull(request.getDiagnostics());
    if (diagnostics != null) {
        message.append(" with diagnostic message: ");
        message.append(diagnostics);
    }
    this.rmContext.getDispatcher().getEventHandler().handle(new RMAppKillByClientEvent(applicationId, message.toString(), callerUGI, remoteAddress));
    // For UnmanagedAMs, return true so they don't retry
    return KillApplicationResponse.newInstance(application.getApplicationSubmissionContext().getUnmanagedAM());
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) CallerContext(org.apache.hadoop.ipc.CallerContext) RMAppKillByClientEvent(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppKillByClientEvent) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) AccessControlException(java.security.AccessControlException) IOException(java.io.IOException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) InetAddress(java.net.InetAddress) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Aggregations

IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 AccessControlException (java.security.AccessControlException)1 CallerContext (org.apache.hadoop.ipc.CallerContext)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)1 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)1 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)1 RMAppKillByClientEvent (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppKillByClientEvent)1