1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */1819package org.apache.giraph.bsp;
2021import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
22import org.apache.hadoop.io.Text;
23import org.apache.hadoop.mapreduce.JobContext;
24import org.apache.hadoop.mapreduce.OutputCommitter;
25import org.apache.hadoop.mapreduce.OutputFormat;
26import org.apache.hadoop.mapreduce.RecordWriter;
27import org.apache.hadoop.mapreduce.TaskAttemptContext;
28import org.apache.log4j.Logger;
2930import java.io.IOException;
3132/**33 * This is for internal use only. Allows the vertex output format routines34 * to be called as if a normal Hadoop job.35 */36publicclassBspOutputFormatextends OutputFormat<Text, Text> {
37/** Class logger */38privatestatic Logger LOG = Logger.getLogger(BspOutputFormat.class);
3940 @Override
41publicvoid checkOutputSpecs(JobContext context)
42throws IOException, InterruptedException {
43ImmutableClassesGiraphConfiguration conf =
44newImmutableClassesGiraphConfiguration(context.getConfiguration());
45if (!conf.hasVertexOutputFormat() && !conf.hasEdgeOutputFormat()) {
46 LOG.warn("checkOutputSpecs: ImmutableOutputCommiter" +
47" will not check anything");
48return;
49 }
5051if (conf.hasVertexOutputFormat()) {
52 conf.createWrappedVertexOutputFormat().checkOutputSpecs(context);
53 }
54if (conf.hasEdgeOutputFormat()) {
55 conf.createWrappedEdgeOutputFormat().checkOutputSpecs(context);
56 }
57 }
5859 @Override
60public OutputCommitter getOutputCommitter(TaskAttemptContext context)
61throws IOException, InterruptedException {
62ImmutableClassesGiraphConfiguration conf =
63newImmutableClassesGiraphConfiguration(context.getConfiguration());
64if (!conf.hasVertexOutputFormat() && !conf.hasEdgeOutputFormat()) {
65 LOG.warn("getOutputCommitter: Returning " +
66"ImmutableOutputCommiter (does nothing).");
67returnnewImmutableOutputCommitter();
68 }
6970if (conf.hasVertexOutputFormat()) {
71return conf.createWrappedVertexOutputFormat().getOutputCommitter(context);
72 } else {
73return conf.createWrappedEdgeOutputFormat().getOutputCommitter(context);
74 }
75 }
7677 @Override
78public RecordWriter<Text, Text> getRecordWriter(TaskAttemptContext context)
79throws IOException, InterruptedException {
80returnnewBspRecordWriter();
81 }
82 }