use of org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException in project tez by apache.
the class DAGClientImpl method getDAGStatusViaRM.
/**
* Get the DAG status via the YARN ResourceManager
* @return the dag status, inferred from the RM App state. Does not return null.
* @throws TezException
* @throws IOException
*/
@VisibleForTesting
protected DAGStatus getDAGStatusViaRM() throws TezException, IOException {
if (LOG.isDebugEnabled()) {
LOG.debug("GetDAGStatus via AM for app: " + appId + " dag:" + dagId);
}
ApplicationReport appReport;
try {
appReport = frameworkClient.getApplicationReport(appId);
} catch (ApplicationNotFoundException e) {
LOG.info("DAG is no longer running - application not found by YARN", e);
throw new DAGNotRunningException(e);
} catch (YarnException e) {
throw new TezException(e);
}
if (appReport == null) {
throw new TezException("Unknown/Invalid appId: " + appId);
}
DAGProtos.DAGStatusProto.Builder builder = DAGProtos.DAGStatusProto.newBuilder();
DAGStatus dagStatus = new DAGStatus(builder, DagStatusSource.RM);
DAGProtos.DAGStatusStateProto dagState;
switch(appReport.getYarnApplicationState()) {
case NEW:
case NEW_SAVING:
case SUBMITTED:
case ACCEPTED:
dagState = DAGProtos.DAGStatusStateProto.DAG_SUBMITTED;
break;
case RUNNING:
dagState = DAGProtos.DAGStatusStateProto.DAG_RUNNING;
break;
case FAILED:
dagState = DAGProtos.DAGStatusStateProto.DAG_FAILED;
break;
case KILLED:
dagState = DAGProtos.DAGStatusStateProto.DAG_KILLED;
break;
case FINISHED:
switch(appReport.getFinalApplicationStatus()) {
case UNDEFINED:
case FAILED:
dagState = DAGProtos.DAGStatusStateProto.DAG_FAILED;
break;
case KILLED:
dagState = DAGProtos.DAGStatusStateProto.DAG_KILLED;
break;
case SUCCEEDED:
dagState = DAGProtos.DAGStatusStateProto.DAG_SUCCEEDED;
break;
default:
throw new TezUncheckedException("Encountered unknown final application" + " status from YARN" + ", appState=" + appReport.getYarnApplicationState() + ", finalStatus=" + appReport.getFinalApplicationStatus());
}
break;
default:
throw new TezUncheckedException("Encountered unknown application state" + " from YARN, appState=" + appReport.getYarnApplicationState());
}
builder.setState(dagState);
// workaround before YARN-2560 is fixed
if (appReport.getFinalApplicationStatus() == FinalApplicationStatus.FAILED || appReport.getFinalApplicationStatus() == FinalApplicationStatus.KILLED) {
long startTime = System.currentTimeMillis();
while ((appReport.getDiagnostics() == null || appReport.getDiagnostics().isEmpty()) && (System.currentTimeMillis() - startTime) < diagnoticsWaitTimeout) {
try {
Thread.sleep(100);
appReport = frameworkClient.getApplicationReport(appId);
} catch (YarnException e) {
throw new TezException(e);
} catch (InterruptedException e) {
throw new TezException(e);
}
}
}
if (appReport.getDiagnostics() != null) {
builder.addAllDiagnostics(Collections.singleton(appReport.getDiagnostics()));
}
return dagStatus;
}
use of org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException in project hadoop by apache.
the class ClientRMService method getApplicationReport.
/**
* It gives response which includes application report if the application
* present otherwise throws ApplicationNotFoundException.
*/
@Override
public GetApplicationReportResponse getApplicationReport(GetApplicationReportRequest request) throws YarnException {
ApplicationId applicationId = request.getApplicationId();
if (applicationId == null) {
throw new ApplicationNotFoundException("Invalid application id: null");
}
UserGroupInformation callerUGI;
try {
callerUGI = UserGroupInformation.getCurrentUser();
} catch (IOException ie) {
LOG.info("Error getting UGI ", ie);
throw RPCUtil.getRemoteException(ie);
}
RMApp application = this.rmContext.getRMApps().get(applicationId);
if (application == null) {
// ApplicationNotFoundException and let client to handle.
throw new ApplicationNotFoundException("Application with id '" + applicationId + "' doesn't exist in RM. Please check " + "that the job submission was successful.");
}
boolean allowAccess = checkAccess(callerUGI, application.getUser(), ApplicationAccessType.VIEW_APP, application);
ApplicationReport report = application.createAndGetApplicationReport(callerUGI.getUserName(), allowAccess);
GetApplicationReportResponse response = recordFactory.newRecordInstance(GetApplicationReportResponse.class);
response.setApplicationReport(report);
return response;
}
use of org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException in project hadoop by apache.
the class ClientRMService method getContainers.
/*
* (non-Javadoc)
*
* we're going to fix the issue of showing non-running containers of the
* running application in YARN-1794"
*/
@Override
public GetContainersResponse getContainers(GetContainersRequest request) throws YarnException, IOException {
ApplicationAttemptId appAttemptId = request.getApplicationAttemptId();
ApplicationId appId = appAttemptId.getApplicationId();
UserGroupInformation callerUGI;
try {
callerUGI = UserGroupInformation.getCurrentUser();
} catch (IOException ie) {
LOG.info("Error getting UGI ", ie);
throw RPCUtil.getRemoteException(ie);
}
RMApp application = this.rmContext.getRMApps().get(appId);
if (application == null) {
// ApplicationNotFoundException and let client to handle.
throw new ApplicationNotFoundException("Application with id '" + appId + "' doesn't exist in RM. Please check that the job submission " + "was successful.");
}
boolean allowAccess = checkAccess(callerUGI, application.getUser(), ApplicationAccessType.VIEW_APP, application);
GetContainersResponse response = null;
if (allowAccess) {
RMAppAttempt appAttempt = application.getAppAttempts().get(appAttemptId);
if (appAttempt == null) {
throw new ApplicationAttemptNotFoundException("ApplicationAttempt with id '" + appAttemptId + "' doesn't exist in RM.");
}
Collection<RMContainer> rmContainers = Collections.emptyList();
SchedulerAppReport schedulerAppReport = this.rmContext.getScheduler().getSchedulerAppInfo(appAttemptId);
if (schedulerAppReport != null) {
rmContainers = schedulerAppReport.getLiveContainers();
}
List<ContainerReport> listContainers = new ArrayList<ContainerReport>();
for (RMContainer rmContainer : rmContainers) {
listContainers.add(rmContainer.createContainerReport());
}
response = GetContainersResponse.newInstance(listContainers);
} else {
throw new YarnException("User " + callerUGI.getShortUserName() + " does not have privilege to see this application " + appId);
}
return response;
}
use of org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException in project hadoop by apache.
the class ClientRMService method failApplicationAttempt.
@SuppressWarnings("unchecked")
@Override
public FailApplicationAttemptResponse failApplicationAttempt(FailApplicationAttemptRequest request) throws YarnException {
ApplicationAttemptId attemptId = request.getApplicationAttemptId();
ApplicationId applicationId = attemptId.getApplicationId();
UserGroupInformation callerUGI;
try {
callerUGI = UserGroupInformation.getCurrentUser();
} catch (IOException ie) {
LOG.info("Error getting UGI ", ie);
RMAuditLogger.logFailure("UNKNOWN", AuditConstants.FAIL_ATTEMPT_REQUEST, "UNKNOWN", "ClientRMService", "Error getting UGI", applicationId, attemptId);
throw RPCUtil.getRemoteException(ie);
}
RMApp application = this.rmContext.getRMApps().get(applicationId);
if (application == null) {
RMAuditLogger.logFailure(callerUGI.getUserName(), AuditConstants.FAIL_ATTEMPT_REQUEST, "UNKNOWN", "ClientRMService", "Trying to fail an attempt of an absent application", applicationId, attemptId);
throw new ApplicationNotFoundException("Trying to fail an attempt " + attemptId + " of an absent application " + applicationId);
}
RMAppAttempt appAttempt = application.getAppAttempts().get(attemptId);
if (appAttempt == null) {
throw new ApplicationAttemptNotFoundException("ApplicationAttempt with id '" + attemptId + "' doesn't exist in RM.");
}
if (!checkAccess(callerUGI, application.getUser(), ApplicationAccessType.MODIFY_APP, application)) {
RMAuditLogger.logFailure(callerUGI.getShortUserName(), AuditConstants.FAIL_ATTEMPT_REQUEST, "User doesn't have permissions to " + ApplicationAccessType.MODIFY_APP.toString(), "ClientRMService", AuditConstants.UNAUTHORIZED_USER, applicationId);
throw RPCUtil.getRemoteException(new AccessControlException("User " + callerUGI.getShortUserName() + " cannot perform operation " + ApplicationAccessType.MODIFY_APP.name() + " on " + applicationId));
}
FailApplicationAttemptResponse response = recordFactory.newRecordInstance(FailApplicationAttemptResponse.class);
if (!ACTIVE_APP_STATES.contains(application.getState())) {
if (COMPLETED_APP_STATES.contains(application.getState())) {
RMAuditLogger.logSuccess(callerUGI.getShortUserName(), AuditConstants.FAIL_ATTEMPT_REQUEST, "ClientRMService", applicationId);
return response;
}
}
this.rmContext.getDispatcher().getEventHandler().handle(new RMAppAttemptEvent(attemptId, RMAppAttemptEventType.FAIL, "Attempt failed by user."));
RMAuditLogger.logSuccess(callerUGI.getShortUserName(), AuditConstants.FAIL_ATTEMPT_REQUEST, "ClientRMService", applicationId, attemptId);
return response;
}
use of org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException 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());
}
Aggregations