Example usage for org.apache.hadoop.ipc RemoteException toString

List of usage examples for org.apache.hadoop.ipc RemoteException toString

Introduction

In this page you can find the example usage for org.apache.hadoop.ipc RemoteException toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:org.apache.tez.dag.app.taskcomm.TezTestServiceTaskCommunicatorImpl.java

License:Apache License

@Override
public void registerRunningTaskAttempt(final ContainerId containerId, final TaskSpec taskSpec,
        Map<String, LocalResource> additionalResources, Credentials credentials, boolean credentialsChanged,
        int priority) {
    super.registerRunningTaskAttempt(containerId, taskSpec, additionalResources, credentials,
            credentialsChanged, priority);
    SubmitWorkRequestProto requestProto = null;
    try {// w  ww. java  2 s  .  c  om
        requestProto = constructSubmitWorkRequest(containerId, taskSpec);
    } catch (IOException e) {
        throw new RuntimeException("Failed to construct request", e);
    }
    ContainerInfo containerInfo = getContainerInfo(containerId);
    String host;
    int port;
    if (containerInfo != null) {
        synchronized (containerInfo) {
            host = containerInfo.host;
            port = containerInfo.port;
        }
    } else {
        // TODO Handle this properly
        throw new RuntimeException("ContainerInfo not found for container: " + containerId
                + ", while trying to launch task: " + taskSpec.getTaskAttemptID());
    }
    // Have to register this up front right now. Otherwise, it's possible for the task to start
    // sending out status/DONE/KILLED/FAILED messages before TAImpl knows how to handle them.
    getContext().taskStartedRemotely(taskSpec.getTaskAttemptID(), containerId);
    communicator.submitWork(requestProto, host, port,
            new TezTestServiceCommunicator.ExecuteRequestCallback<SubmitWorkResponseProto>() {
                @Override
                public void setResponse(SubmitWorkResponseProto response) {
                    LOG.info("Successfully launched task: " + taskSpec.getTaskAttemptID());
                }

                @Override
                public void indicateError(Throwable t) {
                    // TODO Handle this error. This is where an API on the context to indicate failure / rejection comes in.
                    LOG.info("Failed to run task: " + taskSpec.getTaskAttemptID() + " on containerId: "
                            + containerId, t);
                    if (t instanceof ServiceException) {
                        ServiceException se = (ServiceException) t;
                        t = se.getCause();
                    }
                    if (t instanceof RemoteException) {
                        RemoteException re = (RemoteException) t;
                        String message = re.toString();
                        if (message.contains(RejectedExecutionException.class.getName())) {
                            getContext().taskKilled(taskSpec.getTaskAttemptID(),
                                    TaskAttemptEndReason.EXECUTOR_BUSY, "Service Busy");
                        } else {
                            getContext().taskFailed(taskSpec.getTaskAttemptID(), TaskFailureType.NON_FATAL,
                                    TaskAttemptEndReason.OTHER, t.toString());
                        }
                    } else {
                        if (t instanceof IOException) {
                            getContext().taskKilled(taskSpec.getTaskAttemptID(),
                                    TaskAttemptEndReason.COMMUNICATION_ERROR, "Communication Error");
                        } else {
                            getContext().taskFailed(taskSpec.getTaskAttemptID(), TaskFailureType.NON_FATAL,
                                    TaskAttemptEndReason.OTHER, t.getMessage());
                        }
                    }
                }
            });
}