Search in sources :

Example 6 with ExecuteHistory

use of com.baidu.hugegraph.entity.query.ExecuteHistory 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 7 with ExecuteHistory

use of com.baidu.hugegraph.entity.query.ExecuteHistory in project incubator-hugegraph-toolchain by apache.

the class GremlinQueryController method execute.

@PostMapping
public GremlinResult execute(@PathVariable("connId") int connId, @RequestBody GremlinQuery query) {
    this.checkParamsValid(query);
    Date createTime = HubbleUtil.nowDate();
    // Insert execute history
    ExecuteStatus status = ExecuteStatus.RUNNING;
    ExecuteHistory history;
    history = new ExecuteHistory(null, connId, 0L, ExecuteType.GREMLIN, query.getContent(), status, AsyncTaskStatus.UNKNOWN, -1L, createTime);
    this.historyService.save(history);
    StopWatch timer = StopWatch.createStarted();
    try {
        GremlinResult result = this.queryService.executeQuery(connId, query);
        status = ExecuteStatus.SUCCESS;
        return result;
    } catch (Throwable e) {
        status = ExecuteStatus.FAILED;
        throw e;
    } finally {
        timer.stop();
        long duration = timer.getTime(TimeUnit.MILLISECONDS);
        history.setStatus(status);
        history.setDuration(duration);
        this.historyService.update(history);
    }
}
Also used : ExecuteHistory(com.baidu.hugegraph.entity.query.ExecuteHistory) GremlinResult(com.baidu.hugegraph.entity.query.GremlinResult) ExecuteStatus(com.baidu.hugegraph.entity.enums.ExecuteStatus) Date(java.util.Date) StopWatch(org.apache.commons.lang3.time.StopWatch) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

ExecuteHistory (com.baidu.hugegraph.entity.query.ExecuteHistory)7 HugeClient (com.baidu.hugegraph.driver.HugeClient)4 ExecuteStatus (com.baidu.hugegraph.entity.enums.ExecuteStatus)3 InternalException (com.baidu.hugegraph.exception.InternalException)3 Date (java.util.Date)3 Task (com.baidu.hugegraph.structure.Task)2 StopWatch (org.apache.commons.lang3.time.StopWatch)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 TraverserManager (com.baidu.hugegraph.driver.TraverserManager)1 ShortestPath (com.baidu.hugegraph.entity.algorithm.ShortestPath)1 GraphView (com.baidu.hugegraph.entity.query.GraphView)1 GremlinResult (com.baidu.hugegraph.entity.query.GremlinResult)1 JsonView (com.baidu.hugegraph.entity.query.JsonView)1 TableView (com.baidu.hugegraph.entity.query.TableView)1 ExternalException (com.baidu.hugegraph.exception.ExternalException)1 Path (com.baidu.hugegraph.structure.graph.Path)1 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 Instant (java.time.Instant)1 Transactional (org.springframework.transaction.annotation.Transactional)1