Example usage for org.apache.hadoop.mapreduce OutputCommitter abortJob

List of usage examples for org.apache.hadoop.mapreduce OutputCommitter abortJob

Introduction

In this page you can find the example usage for org.apache.hadoop.mapreduce OutputCommitter abortJob.

Prototype

public void abortJob(JobContext jobContext, JobStatus.State state) throws IOException 

Source Link

Document

For aborting an unsuccessful job's output.

Usage

From source file:com.asakusafw.runtime.mapreduce.simple.SimpleJobRunner.java

License:Apache License

private void runJob(Job job) throws ClassNotFoundException, IOException, InterruptedException {
    assert job.getJobID() != null;
    TaskID taskId = newMapTaskId(job.getJobID(), 0);
    Configuration conf = job.getConfiguration();
    OutputFormat<?, ?> output = ReflectionUtils.newInstance(job.getOutputFormatClass(), conf);
    OutputCommitter committer = output
            .getOutputCommitter(newTaskAttemptContext(conf, newTaskAttemptId(taskId, 0)));
    boolean succeed = false;
    committer.setupJob(job);/*from  w ww.  j a v  a2  s  .  c  om*/
    try {
        if (job.getNumReduceTasks() == 0) {
            runMap(job, null);
        } else {
            try (KeyValueSorter<?, ?> sorter = createSorter(job, job.getMapOutputKeyClass(),
                    job.getMapOutputValueClass())) {
                runMap(job, sorter);
                runReduce(job, sorter);
            }
        }
        committer.commitJob(job);
        succeed = true;
    } finally {
        if (succeed == false) {
            try {
                committer.abortJob(job, State.FAILED);
            } catch (IOException e) {
                LOG.error(MessageFormat.format("error occurred while aborting job: {0} ({1})", job.getJobID(),
                        job.getJobName()), e);
            }
        }
    }
}

From source file:cz.seznam.euphoria.hadoop.output.HadoopSink.java

License:Apache License

@Override
@SneakyThrows/*from  w  w  w  . j  a  v a2s  .c om*/
public void rollback() {
    OutputCommitter committer = getHadoopFormatInstance()
            .getOutputCommitter(HadoopUtils.createTaskContext(conf.getWritable(), 0));

    committer.abortJob(HadoopUtils.createJobContext(conf.getWritable()), JobStatus.State.FAILED);
}

From source file:org.apache.giraph.io.internal.WrappedEdgeOutputFormat.java

License:Apache License

@Override
public OutputCommitter getOutputCommitter(TaskAttemptContext context) throws IOException, InterruptedException {

    final OutputCommitter outputCommitter = originalOutputFormat
            .getOutputCommitter(HadoopUtils.makeTaskAttemptContext(getConf(), context));

    return new OutputCommitter() {
        @Override//from w w  w . j  a v a2s .c  om
        public void setupJob(JobContext context) throws IOException {
            outputCommitter.setupJob(HadoopUtils.makeJobContext(getConf(), context));
        }

        @Override
        public void setupTask(TaskAttemptContext context) throws IOException {
            outputCommitter.setupTask(HadoopUtils.makeTaskAttemptContext(getConf(), context));
        }

        @Override
        public boolean needsTaskCommit(TaskAttemptContext context) throws IOException {
            return outputCommitter.needsTaskCommit(HadoopUtils.makeTaskAttemptContext(getConf(), context));
        }

        @Override
        public void commitTask(TaskAttemptContext context) throws IOException {
            outputCommitter.commitTask(HadoopUtils.makeTaskAttemptContext(getConf(), context));
        }

        @Override
        public void abortTask(TaskAttemptContext context) throws IOException {
            outputCommitter.abortTask(HadoopUtils.makeTaskAttemptContext(getConf(), context));
        }

        @Override
        public void cleanupJob(JobContext context) throws IOException {
            outputCommitter.cleanupJob(HadoopUtils.makeJobContext(getConf(), context));
        }

        /*if_not[HADOOP_NON_COMMIT_JOB]*/
        @Override
        public void commitJob(JobContext context) throws IOException {
            outputCommitter.commitJob(HadoopUtils.makeJobContext(getConf(), context));
        }

        @Override
        public void abortJob(JobContext context, JobStatus.State state) throws IOException {
            outputCommitter.abortJob(HadoopUtils.makeJobContext(getConf(), context), state);
        }
        /*end[HADOOP_NON_COMMIT_JOB]*/
    };
}

From source file:org.apache.giraph.io.internal.WrappedVertexOutputFormat.java

License:Apache License

@Override
public OutputCommitter getOutputCommitter(TaskAttemptContext context) throws IOException, InterruptedException {
    final OutputCommitter outputCommitter = originalOutputFormat
            .getOutputCommitter(HadoopUtils.makeTaskAttemptContext(getConf(), context));
    return new OutputCommitter() {
        @Override/*from   ww  w  .  j a va  2  s  .  co m*/
        public void setupJob(JobContext context) throws IOException {
            outputCommitter.setupJob(HadoopUtils.makeJobContext(getConf(), context));
        }

        @Override
        public void setupTask(TaskAttemptContext context) throws IOException {
            outputCommitter.setupTask(HadoopUtils.makeTaskAttemptContext(getConf(), context));
        }

        @Override
        public boolean needsTaskCommit(TaskAttemptContext context) throws IOException {
            return outputCommitter.needsTaskCommit(HadoopUtils.makeTaskAttemptContext(getConf(), context));
        }

        @Override
        public void commitTask(TaskAttemptContext context) throws IOException {
            outputCommitter.commitTask(HadoopUtils.makeTaskAttemptContext(getConf(), context));
        }

        @Override
        public void abortTask(TaskAttemptContext context) throws IOException {
            outputCommitter.abortTask(HadoopUtils.makeTaskAttemptContext(getConf(), context));
        }

        @Override
        public void cleanupJob(JobContext context) throws IOException {
            outputCommitter.cleanupJob(HadoopUtils.makeJobContext(getConf(), context));
        }

        /*if_not[HADOOP_NON_COMMIT_JOB]*/
        @Override
        public void commitJob(JobContext context) throws IOException {
            outputCommitter.commitJob(HadoopUtils.makeJobContext(getConf(), context));
        }

        @Override
        public void abortJob(JobContext context, JobStatus.State state) throws IOException {
            outputCommitter.abortJob(HadoopUtils.makeJobContext(getConf(), context), state);
        }
        /*end[HADOOP_NON_COMMIT_JOB]*/
    };
}

From source file:org.apache.ignite.internal.processors.hadoop.impl.v2.HadoopV2CleanupTask.java

License:Apache License

/** {@inheritDoc} */
@SuppressWarnings("ConstantConditions")
@Override//from   w  w  w . j a v  a  2  s . c  om
public void run0(HadoopV2TaskContext taskCtx) throws IgniteCheckedException {
    JobContextImpl jobCtx = taskCtx.jobContext();

    try {
        OutputFormat outputFormat = getOutputFormat(jobCtx);

        OutputCommitter committer = outputFormat.getOutputCommitter(hadoopContext());

        if (committer != null) {
            if (abort)
                committer.abortJob(jobCtx, JobStatus.State.FAILED);
            else
                committer.commitJob(jobCtx);
        }
    } catch (ClassNotFoundException | IOException e) {
        throw new IgniteCheckedException(e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();

        throw new IgniteInterruptedCheckedException(e);
    }
}

From source file:org.apache.ignite.internal.processors.hadoop.v2.GridHadoopV2CleanupTask.java

License:Apache License

/** {@inheritDoc} */
@SuppressWarnings("ConstantConditions")
@Override/*  w  ww .j av  a  2  s  .  co  m*/
public void run0(GridHadoopV2TaskContext taskCtx) throws IgniteCheckedException {
    JobContextImpl jobCtx = taskCtx.jobContext();

    try {
        OutputFormat outputFormat = getOutputFormat(jobCtx);

        OutputCommitter committer = outputFormat.getOutputCommitter(hadoopContext());

        if (committer != null) {
            if (abort)
                committer.abortJob(jobCtx, JobStatus.State.FAILED);
            else
                committer.commitJob(jobCtx);
        }
    } catch (ClassNotFoundException | IOException e) {
        throw new IgniteCheckedException(e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();

        throw new IgniteInterruptedCheckedException(e);
    }
}

From source file:org.gridgain.grid.kernal.processors.hadoop.v2.GridHadoopV2CleanupTask.java

License:Open Source License

/** {@inheritDoc} */
@SuppressWarnings("ConstantConditions")
@Override//from   www .j a  v  a  2  s.c  o  m
public void run0(GridHadoopV2TaskContext taskCtx) throws GridException {
    JobContextImpl jobCtx = taskCtx.jobContext();

    try {
        OutputFormat outputFormat = getOutputFormat(jobCtx);

        OutputCommitter committer = outputFormat.getOutputCommitter(hadoopContext());

        if (committer != null) {
            if (abort)
                committer.abortJob(jobCtx, JobStatus.State.FAILED);
            else
                committer.commitJob(jobCtx);
        }
    } catch (ClassNotFoundException | IOException e) {
        throw new GridException(e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();

        throw new GridInterruptedException(e);
    }
}

From source file:org.mrgeo.hadoop.multipleoutputs.DirectoryMultipleOutputsCommitter.java

License:Apache License

@Override
public void abortJob(JobContext jobContext, State state) throws IOException {
    for (final OutputCommitter that : committers) {
        that.abortJob(jobContext, state);
    }// w  w w . j  a  va2 s. c o  m
    super.abortJob(jobContext, state);
}