use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.
the class FileGraphPartition method output.
protected PartitionStat output() {
ComputerOutput output = this.context.config().createObject(ComputerOptions.OUTPUT_CLASS);
output.init(this.context.config(), this.partition);
try {
this.beforeOutput();
} catch (IOException e) {
throw new ComputerException("Error occurred when beforeOutput", e);
}
Value result = this.context.config().createObject(ComputerOptions.ALGORITHM_RESULT_CLASS);
while (this.vertexInput.hasNext()) {
Vertex vertex = this.vertexInput.next();
this.readVertexStatusAndValue(vertex, result);
Edges edges = this.edgesInput.edges(this.vertexInput.idPointer());
vertex.edges(edges);
output.write(vertex);
}
try {
this.afterOutput();
} catch (IOException e) {
throw new ComputerException("Error occurred when afterOutput", e);
}
output.close();
return new PartitionStat(this.partition, this.vertexCount, this.edgeCount, 0L);
}
use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.
the class EdgesInput method readEdges.
// TODO: use one reused Edges instance to read batches for each vertex.
private Edges readEdges(RandomAccessInput in) {
try {
int count = in.readFixedInt();
Edges edges = this.graphFactory.createEdges(count);
if (this.frequency == EdgeFrequency.SINGLE) {
for (int i = 0; i < count; i++) {
Edge edge = this.graphFactory.createEdge();
// Only use targetId as subKey, use props as subValue
edge.targetId(StreamGraphInput.readId(in));
// Read subValue
Properties props = this.graphFactory.createProperties();
props.read(in);
edge.properties(props);
edges.add(edge);
}
} else if (this.frequency == EdgeFrequency.SINGLE_PER_LABEL) {
for (int i = 0; i < count; i++) {
Edge edge = this.graphFactory.createEdge();
// Use label + targetId as subKey, use props as subValue
edge.label(StreamGraphInput.readLabel(in));
edge.targetId(StreamGraphInput.readId(in));
// Read subValue
Properties props = this.graphFactory.createProperties();
props.read(in);
edge.properties(props);
edges.add(edge);
}
} else {
assert this.frequency == EdgeFrequency.MULTIPLE;
for (int i = 0; i < count; i++) {
Edge edge = this.graphFactory.createEdge();
/*
* Use label + sortValues + targetId as subKey,
* use properties as subValue
*/
edge.label(StreamGraphInput.readLabel(in));
edge.name(StreamGraphInput.readLabel(in));
edge.targetId(StreamGraphInput.readId(in));
// Read subValue
Properties props = this.graphFactory.createProperties();
props.read(in);
edge.properties(props);
edges.add(edge);
}
}
return edges;
} catch (IOException e) {
throw new ComputerException("Failed to read edges from input '%s'", e, this.edgeFile.getAbsoluteFile());
}
}
use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.
the class FileGraphPartition method compute1.
private long compute1(ComputationContext context) {
Value result = this.context.config().createObject(ComputerOptions.ALGORITHM_RESULT_CLASS);
long activeVertexCount = 0L;
while (this.vertexInput.hasNext()) {
Vertex vertex = this.vertexInput.next();
this.readVertexStatusAndValue(vertex, result);
Iterator<Value> messageIter = this.messageInput.iterator(this.vertexInput.idPointer());
if (messageIter.hasNext()) {
vertex.reactivate();
}
/*
* If the vertex is inactive, it's edges will be skipped
* automatically at the next vertex.
*/
if (vertex.active()) {
Edges edges = this.edgesInput.edges(this.vertexInput.idPointer());
vertex.edges(edges);
this.computation.compute(context, vertex, messageIter);
}
// The vertex status may be changed after computation
if (vertex.active()) {
activeVertexCount++;
}
try {
this.saveVertexStatusAndValue(vertex);
} catch (IOException e) {
throw new ComputerException("Error occurred when saveVertex", e);
}
}
return activeVertexCount;
}
use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.
the class VertexValueCombiner method combine.
@Override
public Pointer combine(Pointer v1, Pointer v2) {
try {
RandomAccessInput input1 = v1.input();
RandomAccessInput input2 = v2.input();
input1.seek(v1.offset());
input2.seek(v2.offset());
String label1 = StreamGraphInput.readLabel(input1);
String label2 = StreamGraphInput.readLabel(input2);
assert label1.equals(label2);
this.v1.read(input1);
this.v2.read(input2);
this.combiner.combine(this.v1, this.v2, this.result);
this.output.seek(0L);
this.output.writeUTF(label1);
this.result.write(this.output);
return new InlinePointer(this.output.buffer(), this.output.position());
} catch (Exception e) {
throw new ComputerException("Failed to combine pointer1(offset=%s, length=%s) and " + "pointer2(offset=%s, length=%s)'", e, v1.offset(), v1.length(), v2.offset(), v2.length());
}
}
use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.
the class EtcdClient method getWithPrefix.
/**
* Get the values of keys with the specified prefix.
* If no key found, return empty list.
*/
public List<byte[]> getWithPrefix(String prefix) {
E.checkArgumentNotNull(prefix, "The prefix can't be null");
try {
ByteSequence prefixSeq = ByteSequence.from(prefix, ENCODING);
GetOption getOption = GetOption.newBuilder().withPrefix(prefixSeq).withSortOrder(SortOrder.ASCEND).build();
GetResponse response = this.kv.get(prefixSeq, getOption).get();
if (response.getCount() > 0) {
return getResponseValues(response);
} else {
return Collections.emptyList();
}
} catch (InterruptedException e) {
throw new ComputerException("Interrupted while getting with prefix='%s'", e, prefix);
} catch (ExecutionException e) {
throw new ComputerException("Error while getting with prefix='%s'", e, prefix);
}
}
Aggregations