Search in sources :

Example 11 with LoadTask

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

the class LoadTaskController method delete.

@DeleteMapping("{id}")
public void delete(@PathVariable("id") int id) {
    LoadTask task = this.service.get(id);
    if (task == null) {
        throw new ExternalException("load.task.not-exist.id", id);
    }
    this.service.remove(id);
}
Also used : LoadTask(com.baidu.hugegraph.entity.load.LoadTask) ExternalException(com.baidu.hugegraph.exception.ExternalException) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Example 12 with LoadTask

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

the class LoadTaskController method start.

@PostMapping("start")
public List<LoadTask> start(@PathVariable("connId") int connId, @PathVariable("jobId") int jobId, @RequestParam("file_mapping_ids") List<Integer> fileIds) {
    GraphConnection connection = this.connService.get(connId);
    if (connection == null) {
        throw new ExternalException("graph-connection.not-exist.id", connId);
    }
    JobManager jobEntity = this.jobService.get(jobId);
    Ex.check(jobEntity != null, "job-manager.not-exist.id", jobId);
    Ex.check(jobEntity.getJobStatus() == JobStatus.SETTING, "load.task.start.no-permission");
    boolean existError = false;
    try {
        List<LoadTask> tasks = new ArrayList<>();
        for (Integer fileId : fileIds) {
            FileMapping fileMapping = this.fmService.get(fileId);
            if (fileMapping == null) {
                throw new ExternalException("file-mapping.not-exist.id", fileId);
            }
            tasks.add(this.service.start(connection, fileMapping));
        }
        return tasks;
    } catch (Exception e) {
        existError = true;
        throw e;
    } finally {
        if (existError) {
            jobEntity.setJobStatus(JobStatus.FAILED);
        } else {
            jobEntity.setJobStatus(JobStatus.LOADING);
        }
        jobEntity.setUpdateTime(HubbleUtil.nowDate());
        this.jobService.update(jobEntity);
    }
}
Also used : LoadTask(com.baidu.hugegraph.entity.load.LoadTask) FileMapping(com.baidu.hugegraph.entity.load.FileMapping) GraphConnection(com.baidu.hugegraph.entity.GraphConnection) ArrayList(java.util.ArrayList) JobManager(com.baidu.hugegraph.entity.load.JobManager) ExternalException(com.baidu.hugegraph.exception.ExternalException) ExternalException(com.baidu.hugegraph.exception.ExternalException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

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