Search in sources :

Example 6 with LoadTask

use of com.baidu.hugegraph.entity.load.LoadTask in project incubator-hugegraph-toolchain by apache.

the class LoadTaskService method buildLoadTask.

private LoadTask buildLoadTask(GraphConnection connection, FileMapping fileMapping) {
    try {
        LoadOptions options = this.buildLoadOptions(connection, fileMapping);
        // NOTE: For simplicity, one file corresponds to one import task
        LoadMapping mapping = this.buildLoadMapping(connection, fileMapping);
        this.bindMappingToOptions(options, mapping, fileMapping.getPath());
        return new LoadTask(options, connection, fileMapping);
    } catch (Exception e) {
        Throwable rootCause = Ex.rootCause(e);
        throw new ExternalException("load.build-task.failed", rootCause);
    }
}
Also used : LoadTask(com.baidu.hugegraph.entity.load.LoadTask) LoadOptions(com.baidu.hugegraph.loader.executor.LoadOptions) ExternalException(com.baidu.hugegraph.exception.ExternalException) LoadMapping(com.baidu.hugegraph.loader.mapping.LoadMapping) ExternalException(com.baidu.hugegraph.exception.ExternalException) IOException(java.io.IOException) InternalException(com.baidu.hugegraph.exception.InternalException)

Example 7 with LoadTask

use of com.baidu.hugegraph.entity.load.LoadTask in project incubator-hugegraph-toolchain by apache.

the class LoadTaskService method resume.

public LoadTask resume(int taskId) {
    LoadTask task = this.get(taskId);
    Ex.check(task.getStatus() == LoadStatus.PAUSED || task.getStatus() == LoadStatus.FAILED, "Can only resume the PAUSED or FAILED task");
    task.lock();
    try {
        // Set work mode in incrental mode, load from last breakpoint
        task.getOptions().incrementalMode = true;
        task.setStatus(LoadStatus.RUNNING);
        this.update(task);
        this.taskExecutor.execute(task, () -> this.update(task));
        this.runningTaskContainer.put(taskId, task);
    } finally {
        task.unlock();
    }
    return task;
}
Also used : LoadTask(com.baidu.hugegraph.entity.load.LoadTask)

Example 8 with LoadTask

use of com.baidu.hugegraph.entity.load.LoadTask in project incubator-hugegraph-toolchain by apache.

the class LoadTaskService method retry.

public LoadTask retry(int taskId) {
    LoadTask task = this.get(taskId);
    Ex.check(task.getStatus() == LoadStatus.FAILED || task.getStatus() == LoadStatus.STOPPED, "Can only retry the FAILED or STOPPED task");
    task.lock();
    try {
        // Set work mode in normal mode, load from begin
        task.getOptions().incrementalMode = false;
        task.setStatus(LoadStatus.RUNNING);
        task.setLastDuration(0L);
        task.setCurrDuration(0L);
        this.update(task);
        this.taskExecutor.execute(task, () -> this.update(task));
        this.runningTaskContainer.put(taskId, task);
    } finally {
        task.unlock();
    }
    return task;
}
Also used : LoadTask(com.baidu.hugegraph.entity.load.LoadTask)

Example 9 with LoadTask

use of com.baidu.hugegraph.entity.load.LoadTask in project incubator-hugegraph-toolchain by apache.

the class LoadTaskService method updateLoadTaskProgress.

/**
 * Update progress periodically
 */
@Async
@Scheduled(fixedDelay = 1 * 1000)
@Transactional(isolation = Isolation.READ_COMMITTED)
public void updateLoadTaskProgress() {
    for (LoadTask task : this.runningTaskContainer.values()) {
        if (!task.getStatus().inRunning()) {
            continue;
        }
        task.lock();
        try {
            if (task.getStatus().inRunning()) {
                LoadContext context = task.context();
                long readLines = context.newProgress().totalInputReaded();
                if (readLines == 0L) {
                    /*
                         * When the Context is just constructed, newProgress
                         * is empty. Only after parsing is started will use
                         * oldProgress and incrementally update newProgress,
                         * if get totalInputReaded value during this process,
                         * it will return 0, so need read it from oldProgress
                         */
                    readLines = context.oldProgress().totalInputReaded();
                }
                task.setFileReadLines(readLines);
                task.setCurrDuration(context.summary().totalTime());
                this.update(task);
            }
        } finally {
            task.unlock();
        }
    }
}
Also used : LoadTask(com.baidu.hugegraph.entity.load.LoadTask) LoadContext(com.baidu.hugegraph.loader.executor.LoadContext) Scheduled(org.springframework.scheduling.annotation.Scheduled) Async(org.springframework.scheduling.annotation.Async) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with LoadTask

use of com.baidu.hugegraph.entity.load.LoadTask in project incubator-hugegraph-toolchain by apache.

the class LoadTaskController method reason.

@GetMapping("{id}/reason")
public Response reason(@PathVariable("connId") int connId, @PathVariable("jobId") int jobId, @PathVariable("id") int id) {
    LoadTask task = this.service.get(id);
    if (task == null) {
        throw new ExternalException("load.task.not-exist.id", id);
    }
    JobManager jobEntity = this.jobService.get(jobId);
    Ex.check(jobEntity != null, "job-manager.not-exist.id", jobId);
    Integer fileId = task.getFileId();
    FileMapping mapping = this.fmService.get(fileId);
    String reason = this.service.readLoadFailedReason(mapping);
    return Response.builder().status(Constant.STATUS_OK).data(reason).build();
}
Also used : LoadTask(com.baidu.hugegraph.entity.load.LoadTask) FileMapping(com.baidu.hugegraph.entity.load.FileMapping) JobManager(com.baidu.hugegraph.entity.load.JobManager) ExternalException(com.baidu.hugegraph.exception.ExternalException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

LoadTask (com.baidu.hugegraph.entity.load.LoadTask)12 ExternalException (com.baidu.hugegraph.exception.ExternalException)5 JobManager (com.baidu.hugegraph.entity.load.JobManager)4 FileMapping (com.baidu.hugegraph.entity.load.FileMapping)3 ArrayList (java.util.ArrayList)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 GraphConnection (com.baidu.hugegraph.entity.GraphConnection)1 JobStatus (com.baidu.hugegraph.entity.enums.JobStatus)1 LoadStatus (com.baidu.hugegraph.entity.enums.LoadStatus)1 JobManagerReasonResult (com.baidu.hugegraph.entity.load.JobManagerReasonResult)1 InternalException (com.baidu.hugegraph.exception.InternalException)1 LoadContext (com.baidu.hugegraph.loader.executor.LoadContext)1 LoadOptions (com.baidu.hugegraph.loader.executor.LoadOptions)1 LoadMapping (com.baidu.hugegraph.loader.mapping.LoadMapping)1 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Async (org.springframework.scheduling.annotation.Async)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1