Search in sources :

Example 1 with TaskBasedLocationAffinity

use of org.apache.tez.dag.api.TaskLocationHint.TaskBasedLocationAffinity in project tez by apache.

the class TaskSchedulerManager method handleTaLaunchRequest.

private void handleTaLaunchRequest(AMSchedulerEventTALaunchRequest event) {
    TaskAttempt taskAttempt = event.getTaskAttempt();
    TaskLocationHint locationHint = event.getLocationHint();
    String[] hosts = null;
    String[] racks = null;
    if (locationHint != null) {
        TaskBasedLocationAffinity taskAffinity = locationHint.getAffinitizedTask();
        if (taskAffinity != null) {
            Vertex vertex = appContext.getCurrentDAG().getVertex(taskAffinity.getVertexName());
            Preconditions.checkNotNull(vertex, "Invalid vertex in task based affinity " + taskAffinity + " for attempt: " + taskAttempt.getID());
            int taskIndex = taskAffinity.getTaskIndex();
            Preconditions.checkState(taskIndex >= 0 && taskIndex < vertex.getTotalTasks(), "Invalid taskIndex in task based affinity " + taskAffinity + " for attempt: " + taskAttempt.getID());
            TaskAttempt affinityAttempt = vertex.getTask(taskIndex).getSuccessfulAttempt();
            if (affinityAttempt != null) {
                Preconditions.checkNotNull(affinityAttempt.getAssignedContainerID(), affinityAttempt.getID());
                try {
                    taskSchedulers[event.getSchedulerId()].allocateTask(taskAttempt, event.getCapability(), affinityAttempt.getAssignedContainerID(), Priority.newInstance(event.getPriority()), event.getContainerContext(), event);
                } catch (Exception e) {
                    String msg = "Error in TaskScheduler for handling Task Allocation" + ", eventType=" + event.getType() + ", scheduler=" + Utils.getTaskSchedulerIdentifierString(event.getSchedulerId(), appContext) + ", taskAttemptId=" + taskAttempt.getID();
                    LOG.error(msg, e);
                    sendEvent(new DAGAppMasterEventUserServiceFatalError(DAGAppMasterEventType.TASK_SCHEDULER_SERVICE_FATAL_ERROR, msg, e));
                }
                return;
            }
            LOG.info("No attempt for task affinity to " + taskAffinity + " for attempt " + taskAttempt.getID() + " Ignoring.");
        // fall through with null hosts/racks
        } else {
            hosts = (locationHint.getHosts() != null) ? locationHint.getHosts().toArray(new String[locationHint.getHosts().size()]) : null;
            racks = (locationHint.getRacks() != null) ? locationHint.getRacks().toArray(new String[locationHint.getRacks().size()]) : null;
        }
    }
    try {
        taskSchedulers[event.getSchedulerId()].allocateTask(taskAttempt, event.getCapability(), hosts, racks, Priority.newInstance(event.getPriority()), event.getContainerContext(), event);
    } catch (Exception e) {
        String msg = "Error in TaskScheduler for handling Task Allocation" + ", eventType=" + event.getType() + ", scheduler=" + Utils.getTaskSchedulerIdentifierString(event.getSchedulerId(), appContext) + ", taskAttemptId=" + taskAttempt.getID();
        LOG.error(msg, e);
        sendEvent(new DAGAppMasterEventUserServiceFatalError(DAGAppMasterEventType.TASK_SCHEDULER_SERVICE_FATAL_ERROR, msg, e));
    }
}
Also used : TaskLocationHint(org.apache.tez.dag.api.TaskLocationHint) DAGAppMasterEventUserServiceFatalError(org.apache.tez.dag.app.dag.event.DAGAppMasterEventUserServiceFatalError) TaskBasedLocationAffinity(org.apache.tez.dag.api.TaskLocationHint.TaskBasedLocationAffinity) Vertex(org.apache.tez.dag.app.dag.Vertex) TaskAttempt(org.apache.tez.dag.app.dag.TaskAttempt) TaskLocationHint(org.apache.tez.dag.api.TaskLocationHint) TezUncheckedException(org.apache.tez.dag.api.TezUncheckedException) TezException(org.apache.tez.dag.api.TezException)

Aggregations

TaskLocationHint (org.apache.tez.dag.api.TaskLocationHint)1 TaskBasedLocationAffinity (org.apache.tez.dag.api.TaskLocationHint.TaskBasedLocationAffinity)1 TezException (org.apache.tez.dag.api.TezException)1 TezUncheckedException (org.apache.tez.dag.api.TezUncheckedException)1 TaskAttempt (org.apache.tez.dag.app.dag.TaskAttempt)1 Vertex (org.apache.tez.dag.app.dag.Vertex)1 DAGAppMasterEventUserServiceFatalError (org.apache.tez.dag.app.dag.event.DAGAppMasterEventUserServiceFatalError)1