Search in sources :

Example 11 with HadoopTaskInfo

use of org.apache.ignite.internal.processors.hadoop.HadoopTaskInfo in project ignite by apache.

the class HadoopTasksAllVersionsTest method testMapTask.

/**
 * Tests map task execution.
 *
 * @throws Exception If fails.
 */
@SuppressWarnings("ConstantConditions")
public void testMapTask() throws Exception {
    IgfsPath inDir = new IgfsPath(PATH_INPUT);
    igfs.mkdirs(inDir);
    IgfsPath inFile = new IgfsPath(inDir, HadoopWordCount2.class.getSimpleName() + "-input");
    URI inFileUri = URI.create(igfsScheme() + inFile.toString());
    try (PrintWriter pw = new PrintWriter(igfs.create(inFile, true))) {
        pw.println("hello0 world0");
        pw.println("world1 hello1");
    }
    HadoopFileBlock fileBlock1 = new HadoopFileBlock(HOSTS, inFileUri, 0, igfs.info(inFile).length() - 1);
    try (PrintWriter pw = new PrintWriter(igfs.append(inFile, false))) {
        pw.println("hello2 world2");
        pw.println("world3 hello3");
    }
    HadoopFileBlock fileBlock2 = new HadoopFileBlock(HOSTS, inFileUri, fileBlock1.length(), igfs.info(inFile).length() - fileBlock1.length());
    HadoopJobEx gridJob = getHadoopJob(igfsScheme() + inFile.toString(), igfsScheme() + PATH_OUTPUT);
    HadoopTaskInfo taskInfo = new HadoopTaskInfo(HadoopTaskType.MAP, gridJob.id(), 0, 0, fileBlock1);
    HadoopTestTaskContext ctx = new HadoopTestTaskContext(taskInfo, gridJob);
    ctx.mockOutput().clear();
    ctx.run();
    assertEquals("hello0,1; world0,1; world1,1; hello1,1", Joiner.on("; ").join(ctx.mockOutput()));
    ctx.mockOutput().clear();
    ctx.taskInfo(new HadoopTaskInfo(HadoopTaskType.MAP, gridJob.id(), 0, 0, fileBlock2));
    ctx.run();
    assertEquals("hello2,1; world2,1; world3,1; hello3,1", Joiner.on("; ").join(ctx.mockOutput()));
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) HadoopJobEx(org.apache.ignite.internal.processors.hadoop.HadoopJobEx) HadoopTaskInfo(org.apache.ignite.internal.processors.hadoop.HadoopTaskInfo) HadoopFileBlock(org.apache.ignite.internal.processors.hadoop.HadoopFileBlock) URI(java.net.URI) PrintWriter(java.io.PrintWriter)

Example 12 with HadoopTaskInfo

use of org.apache.ignite.internal.processors.hadoop.HadoopTaskInfo in project ignite by apache.

the class HadoopJobTracker method processNodeLeft.

/**
 * Processes node leave (or fail) event.
 *
 * @param evt Discovery event.
 */
@SuppressWarnings("ConstantConditions")
private void processNodeLeft(DiscoveryEvent evt) {
    if (log.isDebugEnabled())
        log.debug("Processing discovery event [locNodeId=" + ctx.localNodeId() + ", evt=" + evt + ']');
    // Check only if this node is responsible for job status updates.
    if (ctx.jobUpdateLeader()) {
        boolean checkSetup = evt.eventNode().order() < ctx.localNodeOrder();
        Iterable<IgniteCache.Entry<HadoopJobId, HadoopJobMetadata>> entries;
        try {
            entries = jobMetaCache().localEntries(OFFHEAP_PEEK_MODE);
        } catch (IgniteCheckedException e) {
            U.error(log, "Failed to get local entries", e);
            return;
        }
        // Iteration over all local entries is correct since system cache is REPLICATED.
        for (IgniteCache.Entry<HadoopJobId, HadoopJobMetadata> entry : entries) {
            HadoopJobMetadata meta = entry.getValue();
            HadoopJobId jobId = meta.jobId();
            HadoopMapReducePlan plan = meta.mapReducePlan();
            HadoopJobPhase phase = meta.phase();
            try {
                if (checkSetup && phase == PHASE_SETUP && !activeJobs.containsKey(jobId)) {
                    // Failover setup task.
                    HadoopJobEx job = job(jobId, meta.jobInfo());
                    Collection<HadoopTaskInfo> setupTask = setupTask(jobId);
                    assert setupTask != null;
                    ctx.taskExecutor().run(job, setupTask);
                } else if (phase == PHASE_MAP || phase == PHASE_REDUCE) {
                    // Must check all nodes, even that are not event node ID due to
                    // multiple node failure possibility.
                    Collection<HadoopInputSplit> cancelSplits = null;
                    for (UUID nodeId : plan.mapperNodeIds()) {
                        if (ctx.kernalContext().discovery().node(nodeId) == null) {
                            // Node has left the grid.
                            Collection<HadoopInputSplit> mappers = plan.mappers(nodeId);
                            if (cancelSplits == null)
                                cancelSplits = new HashSet<>();
                            cancelSplits.addAll(mappers);
                        }
                    }
                    Collection<Integer> cancelReducers = null;
                    for (UUID nodeId : plan.reducerNodeIds()) {
                        if (ctx.kernalContext().discovery().node(nodeId) == null) {
                            // Node has left the grid.
                            int[] reducers = plan.reducers(nodeId);
                            if (cancelReducers == null)
                                cancelReducers = new HashSet<>();
                            for (int rdc : reducers) cancelReducers.add(rdc);
                        }
                    }
                    if (cancelSplits != null || cancelReducers != null)
                        jobMetaCache().invoke(meta.jobId(), new CancelJobProcessor(null, new IgniteCheckedException("One or more nodes participating in map-reduce job execution failed."), cancelSplits, cancelReducers));
                }
            } catch (IgniteCheckedException e) {
                U.error(log, "Failed to cancel job: " + meta, e);
            }
        }
    }
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) HadoopJobId(org.apache.ignite.internal.processors.hadoop.HadoopJobId) HadoopMapReducePlan(org.apache.ignite.hadoop.HadoopMapReducePlan) MutableEntry(javax.cache.processor.MutableEntry) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) HadoopJobEx(org.apache.ignite.internal.processors.hadoop.HadoopJobEx) HadoopTaskInfo(org.apache.ignite.internal.processors.hadoop.HadoopTaskInfo) HadoopJobPhase(org.apache.ignite.internal.processors.hadoop.HadoopJobPhase) Collection(java.util.Collection) UUID(java.util.UUID)

Example 13 with HadoopTaskInfo

use of org.apache.ignite.internal.processors.hadoop.HadoopTaskInfo in project ignite by apache.

the class HadoopEmbeddedTaskExecutor method run.

/**
 * {@inheritDoc}
 */
@Override
public void run(final HadoopJobEx job, Collection<HadoopTaskInfo> tasks) throws IgniteCheckedException {
    if (log.isDebugEnabled())
        log.debug("Submitting tasks for local execution [locNodeId=" + ctx.localNodeId() + ", tasksCnt=" + tasks.size() + ']');
    Collection<HadoopRunnableTask> executedTasks = jobs.get(job.id());
    if (executedTasks == null) {
        executedTasks = new GridConcurrentHashSet<>();
        Collection<HadoopRunnableTask> extractedCol = jobs.put(job.id(), executedTasks);
        assert extractedCol == null;
    }
    final Collection<HadoopRunnableTask> finalExecutedTasks = executedTasks;
    for (final HadoopTaskInfo info : tasks) {
        assert info != null;
        HadoopRunnableTask task = new HadoopRunnableTask(log, job, ctx.shuffle().memory(), info, ctx.localNodeId()) {

            @Override
            protected void onTaskFinished(HadoopTaskStatus status) {
                if (log.isDebugEnabled())
                    log.debug("Finished task execution [jobId=" + job.id() + ", taskInfo=" + info + ", " + "waitTime=" + waitTime() + ", execTime=" + executionTime() + ']');
                finalExecutedTasks.remove(this);
                jobTracker.onTaskFinished(info, status);
            }

            @Override
            protected HadoopTaskInput createInput(HadoopTaskContext taskCtx) throws IgniteCheckedException {
                return ctx.shuffle().input(taskCtx);
            }

            @Override
            protected HadoopTaskOutput createOutput(HadoopTaskContext taskCtx) throws IgniteCheckedException {
                return ctx.shuffle().output(taskCtx);
            }
        };
        executedTasks.add(task);
        exec.submit(task);
    }
}
Also used : HadoopTaskInfo(org.apache.ignite.internal.processors.hadoop.HadoopTaskInfo) HadoopTaskContext(org.apache.ignite.internal.processors.hadoop.HadoopTaskContext)

Example 14 with HadoopTaskInfo

use of org.apache.ignite.internal.processors.hadoop.HadoopTaskInfo in project ignite by apache.

the class HadoopTaskFinishedMessage method readExternal.

/**
 * {@inheritDoc}
 */
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    taskInfo = new HadoopTaskInfo();
    taskInfo.readExternal(in);
    status = new HadoopTaskStatus();
    status.readExternal(in);
}
Also used : HadoopTaskStatus(org.apache.ignite.internal.processors.hadoop.taskexecutor.HadoopTaskStatus) HadoopTaskInfo(org.apache.ignite.internal.processors.hadoop.HadoopTaskInfo)

Aggregations

HadoopTaskInfo (org.apache.ignite.internal.processors.hadoop.HadoopTaskInfo)14 HadoopJobEx (org.apache.ignite.internal.processors.hadoop.HadoopJobEx)5 UUID (java.util.UUID)4 HadoopJobId (org.apache.ignite.internal.processors.hadoop.HadoopJobId)4 ArrayList (java.util.ArrayList)3 URI (java.net.URI)2 Collection (java.util.Collection)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 HadoopInputSplit (org.apache.ignite.hadoop.HadoopInputSplit)2 HadoopMapReducePlan (org.apache.ignite.hadoop.HadoopMapReducePlan)2 IgfsPath (org.apache.ignite.igfs.IgfsPath)2 HadoopFileBlock (org.apache.ignite.internal.processors.hadoop.HadoopFileBlock)2 HadoopTaskCancelledException (org.apache.ignite.internal.processors.hadoop.HadoopTaskCancelledException)2 HadoopTaskContext (org.apache.ignite.internal.processors.hadoop.HadoopTaskContext)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInput (java.io.DataInput)1 DataInputStream (java.io.DataInputStream)1 PrintWriter (java.io.PrintWriter)1 MutableEntry (javax.cache.processor.MutableEntry)1 IntWritable (org.apache.hadoop.io.IntWritable)1