Search in sources :

Example 1 with TraverserManager

use of com.baidu.hugegraph.driver.TraverserManager in project incubator-hugegraph-toolchain by apache.

the class BackupManager method backupEdgeShard.

private void backupEdgeShard(Shard shard) {
    String desc = String.format("backing up edges[shard %s]", shard);
    Edges edges = null;
    String page = this.initPage();
    TraverserManager g = client.traverser();
    do {
        try {
            String p = page;
            if (page == null) {
                edges = retry(() -> g.edges(shard), desc);
            } else {
                edges = retry(() -> g.edges(shard, p), desc);
            }
        } catch (ToolsException e) {
            this.exceptionHandler(e, HugeType.EDGE, shard);
        }
        if (edges == null) {
            return;
        }
        List<Edge> edgeList = edges.results();
        if (edgeList == null || edgeList.isEmpty()) {
            return;
        }
        long count = this.backup(HugeType.EDGE, suffix.get(), edgeList);
        this.edgeCounter.getAndAdd(count);
        Printer.printInBackward(this.edgeCounter.get());
    } while ((page = edges.page()) != null);
}
Also used : ToolsException(com.baidu.hugegraph.exception.ToolsException) Edges(com.baidu.hugegraph.structure.graph.Edges) Edge(com.baidu.hugegraph.structure.graph.Edge) TraverserManager(com.baidu.hugegraph.driver.TraverserManager)

Example 2 with TraverserManager

use of com.baidu.hugegraph.driver.TraverserManager in project incubator-hugegraph-toolchain by apache.

the class OltpAlgoService method shortestPath.

public GremlinResult shortestPath(int connId, ShortestPath body) {
    HugeClient client = this.getClient(connId);
    TraverserManager traverser = client.traverser();
    Path result = traverser.shortestPath(body.getSource(), body.getTarget(), body.getDirection(), body.getLabel(), body.getMaxDepth(), body.getMaxDegree(), body.getSkipDegree(), body.getCapacity());
    JsonView jsonView = new JsonView();
    jsonView.setData(result.objects());
    Date createTime = HubbleUtil.nowDate();
    TableView tableView = this.buildPathTableView(result);
    GraphView graphView = this.buildPathGraphView(result);
    // Insert execute history
    ExecuteStatus status = ExecuteStatus.SUCCESS;
    ExecuteHistory history;
    history = new ExecuteHistory(null, connId, 0L, ExecuteType.ALGORITHM, body.toString(), status, AsyncTaskStatus.UNKNOWN, -1L, createTime);
    this.historyService.save(history);
    return GremlinResult.builder().type(GremlinResult.Type.PATH).jsonView(jsonView).tableView(tableView).graphView(graphView).build();
}
Also used : ShortestPath(com.baidu.hugegraph.entity.algorithm.ShortestPath) Path(com.baidu.hugegraph.structure.graph.Path) HugeClient(com.baidu.hugegraph.driver.HugeClient) ExecuteHistory(com.baidu.hugegraph.entity.query.ExecuteHistory) JsonView(com.baidu.hugegraph.entity.query.JsonView) ExecuteStatus(com.baidu.hugegraph.entity.enums.ExecuteStatus) GraphView(com.baidu.hugegraph.entity.query.GraphView) TraverserManager(com.baidu.hugegraph.driver.TraverserManager) Date(java.util.Date) TableView(com.baidu.hugegraph.entity.query.TableView)

Example 3 with TraverserManager

use of com.baidu.hugegraph.driver.TraverserManager in project incubator-hugegraph-toolchain by apache.

the class BackupManager method backupVertexShard.

private void backupVertexShard(Shard shard) {
    String desc = String.format("backing up vertices[shard:%s]", shard);
    Vertices vertices = null;
    String page = this.initPage();
    TraverserManager g = client.traverser();
    do {
        String p = page;
        try {
            if (page == null) {
                vertices = retry(() -> g.vertices(shard), desc);
            } else {
                vertices = retry(() -> g.vertices(shard, p), desc);
            }
        } catch (ToolsException e) {
            this.exceptionHandler(e, HugeType.VERTEX, shard);
        }
        if (vertices == null) {
            return;
        }
        List<Vertex> vertexList = vertices.results();
        if (vertexList == null || vertexList.isEmpty()) {
            return;
        }
        long count = this.backup(HugeType.VERTEX, suffix.get(), vertexList);
        this.vertexCounter.getAndAdd(count);
        Printer.printInBackward(this.vertexCounter.get());
    } while ((page = vertices.page()) != null);
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) ToolsException(com.baidu.hugegraph.exception.ToolsException) TraverserManager(com.baidu.hugegraph.driver.TraverserManager) Vertices(com.baidu.hugegraph.structure.graph.Vertices)

Aggregations

TraverserManager (com.baidu.hugegraph.driver.TraverserManager)3 ToolsException (com.baidu.hugegraph.exception.ToolsException)2 HugeClient (com.baidu.hugegraph.driver.HugeClient)1 ShortestPath (com.baidu.hugegraph.entity.algorithm.ShortestPath)1 ExecuteStatus (com.baidu.hugegraph.entity.enums.ExecuteStatus)1 ExecuteHistory (com.baidu.hugegraph.entity.query.ExecuteHistory)1 GraphView (com.baidu.hugegraph.entity.query.GraphView)1 JsonView (com.baidu.hugegraph.entity.query.JsonView)1 TableView (com.baidu.hugegraph.entity.query.TableView)1 Edge (com.baidu.hugegraph.structure.graph.Edge)1 Edges (com.baidu.hugegraph.structure.graph.Edges)1 Path (com.baidu.hugegraph.structure.graph.Path)1 Vertex (com.baidu.hugegraph.structure.graph.Vertex)1 Vertices (com.baidu.hugegraph.structure.graph.Vertices)1 Date (java.util.Date)1