I am a beginner with both java and Eclipse. I would like to know how to prepare Eclipse to make a Giraph program? I have set Giraph up and it's working. And is there a way to run a written program from Eclipse on Giraph?
Thank you
Yes, it is possible to run Giraph from a single Java application without a Hadoop cluster.
Your main class is like this:
public class GiraphHelloWorld extends BasicComputation<IntWritable, IntWritable, NullWritable, NullWritable> {
@Override
public void compute(Vertex<IntWritable, IntWritable, NullWritable> vertex,
Iterable<NullWritable> messages) {
System.out.print("Hello world from : " + vertex.getId().toString()
+ " friends are:");
for (Edge<IntWritable, NullWritable> e : vertex.getEdges()) {
System.out.print(" " + e.getTargetVertexId());
}
System.out.println("");
vertex.voteToHalt();
}
public static void main(String[] args) throws Exception {
System.exit(ToolRunner.run(new GiraphRunner(), args));
}
}
Your starter class is like this:
public class TestGiraphApp {
final static String[] graphSeed = new String[] { "seed\t0" };
@Test
public void testNumberOfVertices() throws Exception {
GiraphConfiguration conf = new GiraphConfiguration();
conf.setComputationClass(GiraphHelloWorld.class);
conf.setVertexInputFormatClass(IntIntNullTextInputFormat.class);
conf.setVertexOutputFormatClass(AdjacencyListTextVertexOutputFormat.class);
Iterable<String> results = InternalVertexRunner.run(conf, graphSeed);
}
}
The pom.xml
file must include Giraph and Hadoop:
<dependency>
<groupId>org.apache.giraph</groupId>
<artifactId>giraph-core</artifactId>
version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.2.1</version>
</dependency>
The example is based on the source code for the Practical Graph Analytics with Apache Giraph book.
1. "... how to prepare Eclipse to make a Giraph program?":
I tried it ~7 months ago, without any success. I ended up using the Community Edition of IntelliJ IDEA - with that it works smoothly. You can than just clone the giraph repository and start working with the examples, as well as creating your own examples. This way you don't need to set up a maven config file, ...
2. "... is there a way to run a written program from Eclipse on Giraph?"
If you have added your code to the examples, you can just rebuild the whole giraph project with
mvn clean install -DskipTests
and run that giraph version. Otherwise you need to build your own jar file to run it with giraph. There is no way to just press the "run" button and have the whole debug experience of IntelliJ (or Eclipse)