Search in sources :

Example 1 with LoadTask

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

the class LoadTaskService method pause.

public LoadTask pause(int taskId) {
    LoadTask task = this.runningTaskContainer.get(taskId);
    Ex.check(task.getStatus() == LoadStatus.RUNNING, "Can only pause the RUNNING task");
    // Mark status as paused, should set before context.stopLoading()
    task.setStatus(LoadStatus.PAUSED);
    // Let HugeGraphLoader stop
    task.stop();
    task.lock();
    try {
        this.update(task);
        this.runningTaskContainer.remove(taskId);
    } finally {
        task.unlock();
    }
    return task;
}
Also used : LoadTask(com.baidu.hugegraph.entity.load.LoadTask)

Example 2 with LoadTask

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

the class LoadTaskService method start.

public LoadTask start(GraphConnection connection, FileMapping fileMapping) {
    this.sslService.configSSL(this.config, connection);
    LoadTask task = this.buildLoadTask(connection, fileMapping);
    this.save(task);
    // Executed in other threads
    this.taskExecutor.execute(task, () -> this.update(task));
    // Save current load task
    this.runningTaskContainer.put(task.getId(), task);
    return task;
}
Also used : LoadTask(com.baidu.hugegraph.entity.load.LoadTask)

Example 3 with LoadTask

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

the class JobManagerService method list.

public IPage<JobManager> list(int connId, int pageNo, int pageSize, String content) {
    QueryWrapper<JobManager> query = Wrappers.query();
    query.eq("conn_id", connId);
    if (!content.isEmpty()) {
        query.like("job_name", content);
    }
    query.orderByDesc("create_time");
    Page<JobManager> page = new Page<>(pageNo, pageSize);
    IPage<JobManager> list = this.mapper.selectPage(page, query);
    list.getRecords().forEach(task -> {
        if (task.getJobStatus() == JobStatus.LOADING) {
            List<LoadTask> tasks = this.taskService.taskListByJob(task.getId());
            JobStatus status = JobStatus.SUCCESS;
            for (LoadTask loadTask : tasks) {
                if (loadTask.getStatus().inRunning() || loadTask.getStatus() == LoadStatus.PAUSED || loadTask.getStatus() == LoadStatus.STOPPED) {
                    status = JobStatus.LOADING;
                    break;
                }
                if (loadTask.getStatus() == LoadStatus.FAILED) {
                    status = JobStatus.FAILED;
                    break;
                }
            }
            if (status == JobStatus.SUCCESS || status == JobStatus.FAILED) {
                task.setJobStatus(status);
                this.update(task);
            }
        }
        Date endDate = task.getJobStatus() == JobStatus.FAILED || task.getJobStatus() == JobStatus.SUCCESS ? task.getUpdateTime() : HubbleUtil.nowDate();
        task.setJobDuration(endDate.getTime() - task.getCreateTime().getTime());
    });
    return list;
}
Also used : LoadTask(com.baidu.hugegraph.entity.load.LoadTask) JobStatus(com.baidu.hugegraph.entity.enums.JobStatus) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) JobManager(com.baidu.hugegraph.entity.load.JobManager) Date(java.util.Date)

Example 4 with LoadTask

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

the class JobManagerController method reason.

@GetMapping("{id}/reason")
public Response reason(@PathVariable("connId") int connId, @PathVariable("id") int id) {
    JobManager job = this.service.get(id);
    if (job == null) {
        throw new ExternalException("job.manager.not-exist.id", id);
    }
    List<LoadTask> tasks = this.taskService.batchTasks(job.getId());
    List<JobManagerReasonResult> reasonResults = new ArrayList<>();
    tasks.forEach(task -> {
        JobManagerReasonResult reasonResult = new JobManagerReasonResult();
        int fileId = task.getFileId();
        String reason = "";
        if (task.getStatus() == LoadStatus.FAILED) {
            FileMapping mapping = this.fmService.get(fileId);
            reason = this.taskService.readLoadFailedReason(mapping);
        }
        reasonResult.setTaskId(task.getJobId());
        reasonResult.setFileId(task.getFileId());
        reasonResult.setFileName(task.getFileName());
        reasonResult.setReason(reason);
        reasonResults.add(reasonResult);
    });
    return Response.builder().status(Constant.STATUS_OK).data(reasonResults).build();
}
Also used : LoadTask(com.baidu.hugegraph.entity.load.LoadTask) FileMapping(com.baidu.hugegraph.entity.load.FileMapping) ArrayList(java.util.ArrayList) JobManager(com.baidu.hugegraph.entity.load.JobManager) ExternalException(com.baidu.hugegraph.exception.ExternalException) JobManagerReasonResult(com.baidu.hugegraph.entity.load.JobManagerReasonResult) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 5 with LoadTask

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

the class LoadTaskService method stop.

public LoadTask stop(int taskId) {
    LoadTask task = this.runningTaskContainer.get(taskId);
    if (task == null) {
        task = this.get(taskId);
    }
    LoadStatus status = task.getStatus();
    Ex.check(status == LoadStatus.RUNNING || status == LoadStatus.PAUSED, "Can only stop the RUNNING or PAUSED task");
    // Mark status as stopped
    task.setStatus(LoadStatus.STOPPED);
    if (status == LoadStatus.RUNNING) {
        task.stop();
    }
    task.lock();
    try {
        this.update(task);
        this.runningTaskContainer.remove(taskId);
    } finally {
        task.unlock();
    }
    return task;
}
Also used : LoadTask(com.baidu.hugegraph.entity.load.LoadTask) LoadStatus(com.baidu.hugegraph.entity.enums.LoadStatus)

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