Search in sources :

Example 26 with ComputerException

use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.

the class IOFactory method createGraphOutput.

public static GraphOutput createGraphOutput(ComputerContext context, OutputFormat format, RandomAccessOutput out) {
    switch(format) {
        case BIN:
            EntryOutput entryOutput = new EntryOutputImpl(out);
            return new StreamGraphOutput(context, entryOutput);
        case CSV:
            StructRandomAccessOutput srao;
            srao = new StructRandomAccessOutput(out);
            return new CsvStructGraphOutput(context, srao);
        case JSON:
            srao = new StructRandomAccessOutput(out);
            return new JsonStructGraphOutput(context, srao);
        default:
            throw new ComputerException("Can't create GraphOutput for %s", format);
    }
}
Also used : EntryOutput(com.baidu.hugegraph.computer.core.store.entry.EntryOutput) EntryOutputImpl(com.baidu.hugegraph.computer.core.store.entry.EntryOutputImpl) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 27 with ComputerException

use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.

the class EdgesInputTest method checkEdgesInput.

private void checkEdgesInput(EdgesInput edgesInput, EdgeFrequency freq) throws IOException {
    for (long i = 0L; i < 200L; i += 2) {
        Id id = BytesId.of(i);
        ReusablePointer idPointer = idToReusablePointer(id);
        Edges edges = edgesInput.edges(idPointer);
        Iterator<Edge> edgesIt = edges.iterator();
        Assert.assertEquals(i, edges.size());
        for (int j = 0; j < edges.size(); j++) {
            Assert.assertTrue(edgesIt.hasNext());
            Edge edge = edgesIt.next();
            switch(freq) {
                case SINGLE:
                    Assert.assertEquals(BytesId.of(j), edge.targetId());
                    break;
                case SINGLE_PER_LABEL:
                    Assert.assertEquals(BytesId.of(j), edge.targetId());
                    Assert.assertEquals(String.valueOf(j), edge.label());
                    break;
                case MULTIPLE:
                    Assert.assertEquals(BytesId.of(j), edge.targetId());
                    Assert.assertEquals(String.valueOf(j), edge.label());
                    Assert.assertEquals(String.valueOf(j), edge.name());
                    break;
                default:
                    throw new ComputerException("Illegal edge frequency %s", freq);
            }
        }
        Assert.assertFalse(edgesIt.hasNext());
    }
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) ConnectionId(com.baidu.hugegraph.computer.core.network.ConnectionId) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 28 with ComputerException

use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.

the class EdgesInputTest method addEdgeBuffer.

private static void addEdgeBuffer(Consumer<NetworkBuffer> consumer, EdgeFrequency freq) throws IOException {
    for (long i = 0L; i < 200L; i++) {
        Vertex vertex = graphFactory().createVertex();
        vertex.id(BytesId.of(i));
        int count = (int) i;
        if (count == 0) {
            continue;
        }
        Edges edges = graphFactory().createEdges(count);
        for (long j = 0; j < count; j++) {
            Edge edge = graphFactory().createEdge();
            switch(freq) {
                case SINGLE:
                    edge.targetId(BytesId.of(j));
                    break;
                case SINGLE_PER_LABEL:
                    edge.label(String.valueOf(j));
                    edge.targetId(BytesId.of(j));
                    break;
                case MULTIPLE:
                    edge.name(String.valueOf(j));
                    edge.label(String.valueOf(j));
                    edge.targetId(BytesId.of(j));
                    break;
                default:
                    throw new ComputerException("Illegal edge frequency %s", freq);
            }
            Properties properties = graphFactory().createProperties();
            properties.put("p1", new LongValue(i));
            edge.properties(properties);
            edges.add(edge);
        }
        vertex.edges(edges);
        ReceiverUtil.consumeBuffer(writeEdges(vertex, freq), consumer);
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 29 with ComputerException

use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.

the class ExceptionTest method testComputerException.

@Test
public void testComputerException() {
    Assert.assertThrows(ComputerException.class, () -> {
        throw new ComputerException("computer exception");
    }, e -> {
        Assert.assertEquals("computer exception", e.getMessage());
        Assert.assertNull(e.getCause());
    });
    Assert.assertThrows(ComputerException.class, () -> {
        throw new ComputerException("computer exception", new IOException());
    }, e -> {
        Assert.assertEquals("computer exception", e.getMessage());
        Assert.assertEquals(IOException.class, e.getCause().getClass());
    });
    Assert.assertThrows(ComputerException.class, () -> {
        throw new ComputerException("computer exception at step %s", 1);
    }, e -> {
        Assert.assertEquals("computer exception at step 1", e.getMessage());
        Assert.assertNull(e.getCause());
    });
    Assert.assertThrows(ComputerException.class, () -> {
        throw new ComputerException("computer exception at step %s", new IOException(), 1);
    }, e -> {
        Assert.assertEquals("computer exception at step 1", e.getMessage());
        Assert.assertEquals(IOException.class, e.getCause().getClass());
    });
    Throwable rootCause = new IllegalCharsetNameException("invalid");
    Assert.assertThrows(ComputerException.class, () -> {
        throw new ComputerException("computer exception", new IOException(rootCause));
    }, e -> {
        Assert.assertEquals("computer exception", e.getMessage());
        Assert.assertEquals(IOException.class, e.getCause().getClass());
        Assert.assertEquals(rootCause, ComputerException.rootCause(e));
    });
}
Also used : IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) IOException(java.io.IOException) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException) Test(org.junit.Test)

Example 30 with ComputerException

use of com.baidu.hugegraph.computer.core.common.exception.ComputerException in project hugegraph-computer by hugegraph.

the class ComputerContextUtil method initContext.

public static Config initContext(Map<String, String> params) {
    // Set algorithm's parameters
    String algorithmParamsName = params.get(ComputerOptions.ALGORITHM_PARAMS_CLASS.name());
    AlgorithmParams algorithmParams;
    try {
        algorithmParams = (AlgorithmParams) Class.forName(algorithmParamsName).newInstance();
    } catch (Exception e) {
        throw new ComputerException("Can't create algorithmParams, " + "algorithmParamsName = {}", algorithmParamsName);
    }
    algorithmParams.setAlgorithmParameters(params);
    Config config = new DefaultConfig(params);
    GraphFactory graphFactory = new BuiltinGraphFactory();
    Allocator allocator = new DefaultAllocator(config, graphFactory);
    ComputerContext.initContext(config, graphFactory, allocator);
    return config;
}
Also used : BuiltinGraphFactory(com.baidu.hugegraph.computer.core.graph.BuiltinGraphFactory) Allocator(com.baidu.hugegraph.computer.core.allocator.Allocator) DefaultAllocator(com.baidu.hugegraph.computer.core.allocator.DefaultAllocator) GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) BuiltinGraphFactory(com.baidu.hugegraph.computer.core.graph.BuiltinGraphFactory) AlgorithmParams(com.baidu.hugegraph.computer.algorithm.AlgorithmParams) Config(com.baidu.hugegraph.computer.core.config.Config) DefaultConfig(com.baidu.hugegraph.computer.core.config.DefaultConfig) DefaultConfig(com.baidu.hugegraph.computer.core.config.DefaultConfig) DefaultAllocator(com.baidu.hugegraph.computer.core.allocator.DefaultAllocator) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Aggregations

ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)61 IOException (java.io.IOException)27 ExecutionException (java.util.concurrent.ExecutionException)13 Edges (com.baidu.hugegraph.computer.core.graph.edge.Edges)10 ByteSequence (io.etcd.jetcd.ByteSequence)9 ArrayList (java.util.ArrayList)8 GetResponse (io.etcd.jetcd.kv.GetResponse)7 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)6 RandomAccessInput (com.baidu.hugegraph.computer.core.io.RandomAccessInput)6 PartitionStat (com.baidu.hugegraph.computer.core.graph.partition.PartitionStat)5 GetOption (io.etcd.jetcd.options.GetOption)5 Map (java.util.Map)5 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)4 BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)3 Value (com.baidu.hugegraph.computer.core.graph.value.Value)3 MessageStat (com.baidu.hugegraph.computer.core.receiver.MessageStat)3 KeyValue (io.etcd.jetcd.KeyValue)3 DeleteResponse (io.etcd.jetcd.kv.DeleteResponse)3