Search in sources :

Example 1 with ExecuteHistory

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

the class ExecuteHistoryService method remove.

@Transactional(isolation = Isolation.READ_COMMITTED)
public void remove(int connId, int id) {
    ExecuteHistory history = this.mapper.selectById(id);
    HugeClient client = this.getClient(connId);
    if (history.getType().equals(ExecuteType.GREMLIN_ASYNC)) {
        client.task().delete(history.getAsyncId());
    }
    if (this.mapper.deleteById(id) != 1) {
        throw new InternalException("entity.delete.failed", history);
    }
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) ExecuteHistory(com.baidu.hugegraph.entity.query.ExecuteHistory) InternalException(com.baidu.hugegraph.exception.InternalException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ExecuteHistory

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

the class ExecuteHistoryService method get.

public ExecuteHistory get(int connId, int id) {
    HugeClient client = this.getClient(connId);
    ExecuteHistory history = this.mapper.selectById(id);
    if (history.getType().equals(ExecuteType.GREMLIN_ASYNC)) {
        try {
            Task task = client.task().get(history.getAsyncId());
            history.setDuration(task.updateTime() - task.createTime());
            history.setAsyncStatus(task.status().toUpperCase());
        } catch (Exception e) {
            history.setDuration(0L);
            history.setAsyncStatus(AsyncTaskStatus.UNKNOWN);
        }
    }
    return history;
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) Task(com.baidu.hugegraph.structure.Task) ExecuteHistory(com.baidu.hugegraph.entity.query.ExecuteHistory) InternalException(com.baidu.hugegraph.exception.InternalException)

Example 3 with ExecuteHistory

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

the class GremlinQueryController method executeAsyncTask.

@PostMapping("async-task")
public ExecuteStatus executeAsyncTask(@PathVariable("connId") int connId, @RequestBody GremlinQuery query) {
    this.checkParamsValid(query);
    Date createTime = HubbleUtil.nowDate();
    // Insert execute history
    ExecuteStatus status = ExecuteStatus.ASYNC_TASK_RUNNING;
    ExecuteHistory history;
    history = new ExecuteHistory(null, connId, 0L, ExecuteType.GREMLIN_ASYNC, query.getContent(), status, AsyncTaskStatus.UNKNOWN, -1L, createTime);
    this.historyService.save(history);
    StopWatch timer = StopWatch.createStarted();
    long asyncId = 0L;
    try {
        asyncId = this.queryService.executeAsyncTask(connId, query);
        status = ExecuteStatus.ASYNC_TASK_SUCCESS;
        return status;
    } catch (Throwable e) {
        status = ExecuteStatus.ASYNC_TASK_FAILED;
        throw e;
    } finally {
        timer.stop();
        long duration = timer.getTime(TimeUnit.MILLISECONDS);
        history.setStatus(status);
        history.setDuration(duration);
        history.setAsyncId(asyncId);
        this.historyService.update(history);
    }
}
Also used : ExecuteHistory(com.baidu.hugegraph.entity.query.ExecuteHistory) 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)

Example 4 with ExecuteHistory

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

the class ExecuteHistoryController method delete.

@DeleteMapping("{id}")
public ExecuteHistory delete(@PathVariable("connId") int connId, @PathVariable("id") int id) {
    ExecuteHistory oldEntity = this.service.get(connId, id);
    if (oldEntity == null) {
        throw new ExternalException("execute-history.not-exist.id", id);
    }
    this.service.remove(connId, id);
    return oldEntity;
}
Also used : ExecuteHistory(com.baidu.hugegraph.entity.query.ExecuteHistory) ExternalException(com.baidu.hugegraph.exception.ExternalException) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Example 5 with ExecuteHistory

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

the class ExecuteHistoryService method list.

public IPage<ExecuteHistory> list(int connId, long current, long pageSize) {
    HugeClient client = this.getClient(connId);
    QueryWrapper<ExecuteHistory> query = Wrappers.query();
    query.eq("conn_id", connId).orderByDesc("create_time");
    Page<ExecuteHistory> page = new Page<>(current, pageSize);
    IPage<ExecuteHistory> results = this.mapper.selectPage(page, query);
    int limit = this.config.get(HubbleOptions.EXECUTE_HISTORY_SHOW_LIMIT);
    if (results.getTotal() > limit) {
        log.debug("Execute history total records: {}", results.getTotal());
        results.setTotal(limit);
    }
    // Get the status of successful execution of asynchronous tasks
    Instant now = HubbleUtil.nowTime();
    results.getRecords().forEach((p) -> {
        if (p.getType().equals(ExecuteType.GREMLIN_ASYNC)) {
            try {
                Task task = client.task().get(p.getAsyncId());
                long endDate = task.updateTime() > 0 ? task.updateTime() : now.getLong(ChronoField.INSTANT_SECONDS);
                p.setDuration(endDate - task.createTime());
                p.setAsyncStatus(task.status().toUpperCase());
            } catch (Exception e) {
                p.setDuration(0L);
                p.setAsyncStatus(AsyncTaskStatus.UNKNOWN);
            }
        }
    });
    return results;
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) Task(com.baidu.hugegraph.structure.Task) ExecuteHistory(com.baidu.hugegraph.entity.query.ExecuteHistory) Instant(java.time.Instant) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) InternalException(com.baidu.hugegraph.exception.InternalException)

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