Search in sources :

Example 1 with GetAMStatusResponseProto

use of org.apache.tez.dag.api.client.rpc.DAGClientAMProtocolRPC.GetAMStatusResponseProto in project tez by apache.

the class TezClient method getAppMasterStatus.

/**
 * Get the status of the App Master executing the DAG
 * In non-session mode it returns the status of the last submitted DAG App Master
 * In session mode, it returns the status of the App Master hosting the session
 *
 * @return State of the session
 * @throws TezException
 * @throws IOException
 */
public synchronized TezAppMasterStatus getAppMasterStatus() throws TezException, IOException {
    // Supporting per-DAG app master case since user may choose to run the same
    // code in that mode and the code should continue to work. Its easy to provide
    // the correct view for per-DAG app master too.
    ApplicationId appId = null;
    if (isSession) {
        appId = sessionAppId;
    } else {
        appId = lastSubmittedAppId;
    }
    Preconditions.checkState(appId != null, "Cannot get status without starting an application");
    try {
        ApplicationReport appReport = frameworkClient.getApplicationReport(appId);
        switch(appReport.getYarnApplicationState()) {
            case NEW:
            case NEW_SAVING:
            case ACCEPTED:
            case SUBMITTED:
                return TezAppMasterStatus.INITIALIZING;
            case FAILED:
            case KILLED:
                diagnostics = appReport.getDiagnostics();
                LOG.info("App did not succeed. Diagnostics: " + (appReport.getDiagnostics() != null ? appReport.getDiagnostics() : NO_CLUSTER_DIAGNOSTICS_MSG));
                return TezAppMasterStatus.SHUTDOWN;
            case FINISHED:
                return TezAppMasterStatus.SHUTDOWN;
            case RUNNING:
                try {
                    DAGClientAMProtocolBlockingPB proxy = getAMProxy(appId);
                    if (proxy == null) {
                        return TezAppMasterStatus.INITIALIZING;
                    }
                    GetAMStatusResponseProto response = proxy.getAMStatus(null, GetAMStatusRequestProto.newBuilder().build());
                    return DagTypeConverters.convertTezAppMasterStatusFromProto(response.getStatus());
                } catch (TezException e) {
                    LOG.info("Failed to retrieve AM Status via proxy", e);
                } catch (ServiceException e) {
                    LOG.info("Failed to retrieve AM Status via proxy", e);
                }
        }
    } catch (ApplicationNotFoundException e) {
        return TezAppMasterStatus.SHUTDOWN;
    } catch (YarnException e) {
        throw new TezException(e);
    }
    return TezAppMasterStatus.INITIALIZING;
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) TezException(org.apache.tez.dag.api.TezException) DAGClientAMProtocolBlockingPB(org.apache.tez.dag.api.client.rpc.DAGClientAMProtocolBlockingPB) ServiceException(com.google.protobuf.ServiceException) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) GetAMStatusResponseProto(org.apache.tez.dag.api.client.rpc.DAGClientAMProtocolRPC.GetAMStatusResponseProto) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Aggregations

ServiceException (com.google.protobuf.ServiceException)1 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)1 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)1 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)1 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)1 TezException (org.apache.tez.dag.api.TezException)1 DAGClientAMProtocolBlockingPB (org.apache.tez.dag.api.client.rpc.DAGClientAMProtocolBlockingPB)1 GetAMStatusResponseProto (org.apache.tez.dag.api.client.rpc.DAGClientAMProtocolRPC.GetAMStatusResponseProto)1