Commit d66e8313 authored by yorn's avatar yorn

Added an OutputFormat that shows IP addresses

parent 9994ad42
package no.uninett.yorn.giraph.format.io;
import java.io.IOException;
import org.apache.giraph.graph.Vertex;
import org.apache.giraph.io.formats.TextVertexOutputFormat;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
public class RankVertexOutputFormat extends TextVertexOutputFormat<LongWritable, IntWritable, LongWritable> {
static String intToIp(int ip) {
StringBuilder octetStrings = new StringBuilder();
for (byte i = 0;i < 4;i++) {
int shift = 24 - i*8;
octetStrings.append(ip >> shift & 255);
if (shift != 0) {
octetStrings.append('.');
}
}
return octetStrings.toString();
}
class RankVertexWriter extends TextVertexWriterToEachLine {
@Override
protected Text convertVertexToLine(
Vertex<LongWritable, IntWritable, LongWritable> vertex)
throws IOException {
long vertexId = vertex.getId().get();
String ip = intToIp((int) vertexId);
long port = vertexId >> 32;
return new Text(ip+':'+port+'\t'+vertex.getValue().get());
}
}
@Override
public org.apache.giraph.io.formats.TextVertexOutputFormat<LongWritable, IntWritable, LongWritable>.TextVertexWriterToEachLine createVertexWriter(
TaskAttemptContext context) throws IOException,
InterruptedException {
return new RankVertexWriter();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment