Hi, sorry for the inconvenience I found your mail via giraph mailing
list. Im new in Giraph.
I want to run a giraph job via netbeans. I have imported all libs in
project , and installed hadoop 2.5.2 Giraph 1.1.0 in ubuntu 14.04.
I created Java classes FbGraphInputFormat, FbGraphMessage,
FbGraphOutputFormat,FbGraphState, KatzReduce
public class KatzReduce extends BasicComputation<Text, FbGraphState,
DoubleWritable, FbGraphMessage> {
public class FbGraphState implements Writable {
public class FbGraphOutputFormat extends
TextVertexOutputFormat<Text,FbGraphState,DoubleWritable>{
public class FbGraphInputFormat extends TextVertexInputFormat<Text,
FbGraphState, DoubleWritable> {
class FbGraphMessage implements Writable{
MY QUESTION is simple I want to run my java project from netbeans I dont
know how . I dont have a main class and do not know to start a giraph
job that does exactly what KatzReduce.java says.
I added in the run of the project the arguments infile_location_path
outfile_location_path
Do I create a main method saying what? I cannot find any documentation
on deploying giraph projects from scratch so any help would be of great
assistance.
Thanks in advance, Anna
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Fb_package;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.apache.giraph.edge.Edge;
import org.apache.giraph.edge.EdgeFactory;
import org.apache.giraph.graph.Vertex;
import org.apache.giraph.io.formats.TextVertexInputFormat;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
/**
*
* @author user
*/
public class FbGraphInputFormat extends TextVertexInputFormat<Text,
FbGraphState, DoubleWritable> {
@Override
public TextVertexReader createVertexReader(InputSplit is,
TaskAttemptContext tac) throws IOException {
return new FbGraphReader();
}
protected class FbGraphReader extends TextVertexReader {
@Override
public boolean nextVertex() throws IOException, InterruptedException {
return getRecordReader().nextKeyValue();
}
@Override
public Vertex<Text, FbGraphState, DoubleWritable> getCurrentVertex()
throws IOException, InterruptedException {
String line = getRecordReader().getCurrentValue().toString();
String[] tokens = line.trim().split("#");
if (tokens.length < 2) {
throw new IllegalArgumentException("Invalid line: (" + line +
")");
}
FbGraphState state = new FbGraphState();
Text id = new Text(tokens[0]);
state.setValue(id.toString());
state.setNodeWeight(1.0);
Map<Text, DoubleWritable> edgeMap = new HashMap<>();
ArrayList<Edge<Text, DoubleWritable>> edgesList = new ArrayList<>();
String[] edges = (tokens.length > 2) ? tokens[1].split(",") : new
String[0];
for (int i = 0; i < edges.length; i++) {
double weight = 1.0;
Text edgeKey = new Text(edges[i]);
edgeMap.put(edgeKey, new DoubleWritable(weight));
// edgesList.add(EdgeFactory.create(new
// LongWritable(edgeKey),new LongWritable(weight)));
}
for (Map.Entry<Text, DoubleWritable> entry
: edgeMap.entrySet()) {
edgesList.add(EdgeFactory.create(entry.getKey(),
entry.getValue()));
}
Vertex<Text, FbGraphState, DoubleWritable> vertex =
this.getConf().createVertex();
vertex.initialize(id, state, edgesList);
return vertex;
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Fb_package;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableUtils;
/**
*
* @author user
*/
class FbGraphMessage implements Writable{
private double katzWeight;
public FbGraphMessage(){}
public FbGraphMessage(double weight){
this();
this.katzWeight = weight;
}
public FbGraphMessage(FbGraphMessage other){
this(other.katzWeight);
}
@Override
public void write(DataOutput d) throws IOException {
throw new UnsupportedOperationException("Not supported yet."); //To
change body of generated methods, choose Tools | Templates.
}
@Override
public void readFields(DataInput di) throws IOException {
katzWeight= di.readDouble();
}
public double getKatzWeight() {
return katzWeight;
}
public void setKatzWeight(double katzWeight) {
this.katzWeight = katzWeight;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Fb_package;
import java.io.IOException;
import org.apache.giraph.edge.Edge;
import org.apache.giraph.graph.Vertex;
import org.apache.giraph.io.formats.TextVertexOutputFormat;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
/**
*
* @author user
*/
public class FbGraphOutputFormat extends
TextVertexOutputFormat<Text,FbGraphState,DoubleWritable>{
@Override
public TextVertexWriter createVertexWriter(TaskAttemptContext tac) throws
IOException, InterruptedException {
return new FbGraphWriter();
}
private static class FbGraphWriter extends TextVertexWriter {
public FbGraphWriter() {
}
@Override
public void writeVertex(Vertex<Text, FbGraphState, DoubleWritable>
vertex) throws IOException, InterruptedException {
StringBuilder b = new StringBuilder();
b.append(vertex.getValue().getValue());
b.append("\t");
b.append(vertex.getValue().getNodeWeight());
b.append("\t");
for (Edge<Text,DoubleWritable> e: vertex.getEdges()){
b.append(e.getTargetVertexId());
b.append(":");
b.append(e.getValue());
b.append(",");
}
b.setLength(b.length() - 1);
getRecordWriter().write(vertex.getId(), new
Text(b.toString()));
}
}
}/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Fb_package;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableUtils;
/**
*
* @author user
*/
public class FbGraphState implements Writable {
private String value;
private double nodeWeight;
private String birthday;
private String education_classes;
private String education_concentration_id;
private String education_degree_id;
private String education_school_id;
private String education_with_id;
private String education_type_id;
private String education_year_id;
private String first_name;
private String gender;
private String hometown_id;
private String languages_id;
private String last_name;
private String locale;
private String location_id;
private String work_employer_id;
private String work_end_date;
private String work_location;
private String work_position;
private String work_start_date;
private String work_with;
private String middle_name;
private String politcal ;
public FbGraphState() {
}
public void write(DataOutput d) throws IOException {
WritableUtils.writeString(d, value);
d.writeDouble(nodeWeight);
}
@Override
public void readFields(DataInput di) throws IOException {
value = WritableUtils.readString(di);
nodeWeight = di.readLong();
}
public void setValue(String value) {
this.value = value;
}
public void setNodeWeight(double nodeWeight) {
this.nodeWeight = nodeWeight;
}
public String getValue() {
return value;
}
public double getNodeWeight() {
return nodeWeight;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Fb_package;
import org.apache.giraph.graph.BasicComputation;
import org.apache.giraph.graph.Vertex;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Text;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author user
*/
public class KatzReduce extends BasicComputation<Text, FbGraphState,
DoubleWritable, FbGraphMessage> {
@Override
public void compute(
Vertex<Text, FbGraphState, DoubleWritable> vertex,
Iterable<FbGraphMessage> messages) throws IOException {
// nodes that have no edges send themselves a message on the step 0
if (getSuperstep() == 0 && !vertex.getEdges().iterator().hasNext()) {
vertex.voteToHalt();
return;
}
if (getSuperstep() == 0) {
sendMessageToAllEdges(vertex, new FbGraphMessage(0.5));
vertex.voteToHalt();
return;
}
if (getSuperstep()
== 1) {
double sum = 0;
List<Text> mEdges = new ArrayList<>();
for (FbGraphMessage message : messages) {
sum += message.getKatzWeight();
}
vertex.getValue().setNodeWeight(vertex.getValue().getNodeWeight() +
sum);
sendMessageToAllEdges(vertex, new FbGraphMessage(0.25));
vertex.voteToHalt();
return;
}
if (getSuperstep() == 2) {
double sum = 0;
List<Text> mEdges = new ArrayList<>();
for (FbGraphMessage message : messages) {
sum += message.getKatzWeight();
}
vertex.getValue().setNodeWeight(vertex.getValue().getNodeWeight() +
sum);
sendMessageToAllEdges(vertex, new FbGraphMessage(0.125));
vertex.voteToHalt();
return;
}
if (getSuperstep() == 3) {
double sum = 0;
for (FbGraphMessage message : messages) {
sum += message.getKatzWeight();
}
vertex.getValue().setNodeWeight(vertex.getValue().getNodeWeight() +
sum);
sendMessageToAllEdges(vertex, new FbGraphMessage(0.062));
vertex.voteToHalt();
return;
}
if (getSuperstep() == 4) {
double sum = 0;
for (FbGraphMessage message : messages) {
sum += message.getKatzWeight();
}
vertex.getValue().setNodeWeight(vertex.getValue().getNodeWeight() +
sum);
sendMessageToAllEdges(vertex, new FbGraphMessage(0.031));
vertex.voteToHalt();
return;
}
if (getSuperstep()
== 5) {
double sum = 0;
for (FbGraphMessage message : messages) {
sum += message.getKatzWeight();
}
vertex.getValue().setNodeWeight(vertex.getValue().getNodeWeight() +
sum);
sendMessageToAllEdges(vertex, new FbGraphMessage(0.015));
vertex.voteToHalt();
return;
}
if (getSuperstep()
> 5) {
double sum = 0;
for (FbGraphMessage message : messages) {
sum += message.getKatzWeight();
}
vertex.getValue().setNodeWeight(vertex.getValue().getNodeWeight() +
sum);
vertex.voteToHalt();
return;
}
}
}