Search in sources :

Example 11 with JobManager

use of com.baidu.hugegraph.entity.load.JobManager 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)

Example 12 with JobManager

use of com.baidu.hugegraph.entity.load.JobManager 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)

Example 13 with JobManager

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

the class LoadTaskController method pause.

@PostMapping("pause")
public LoadTask pause(@PathVariable("connId") int connId, @PathVariable("jobId") int jobId, @RequestParam("task_id") int taskId) {
    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.LOADING, "load.task.pause.no-permission");
    try {
        return this.service.pause(taskId);
    } finally {
        jobEntity.setJobStatus(JobStatus.LOADING);
        jobEntity.setUpdateTime(HubbleUtil.nowDate());
        this.jobService.update(jobEntity);
    }
}
Also used : GraphConnection(com.baidu.hugegraph.entity.GraphConnection) JobManager(com.baidu.hugegraph.entity.load.JobManager) ExternalException(com.baidu.hugegraph.exception.ExternalException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 14 with JobManager

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

the class FileMappingController method nextStep.

@PutMapping("next-step")
public JobManager nextStep(@PathVariable("jobId") int jobId) {
    JobManager jobEntity = this.jobService.get(jobId);
    Ex.check(jobEntity != null, "job-manager.not-exist.id", jobId);
    Ex.check(jobEntity.getJobStatus() == JobStatus.MAPPING, "job.manager.status.unexpected", JobStatus.MAPPING, jobEntity.getJobStatus());
    jobEntity.setJobStatus(JobStatus.SETTING);
    this.jobService.update(jobEntity);
    return jobEntity;
}
Also used : JobManager(com.baidu.hugegraph.entity.load.JobManager) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 15 with JobManager

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

the class JobManagerController method update.

@PutMapping("{id}")
public JobManager update(@PathVariable("connId") int connId, @PathVariable("id") int id, @RequestBody JobManager newEntity) {
    Ex.check(newEntity.getJobName().length() <= 48, "job.manager.job-name.reached-limit");
    Ex.check(newEntity.getJobName() != null, () -> Constant.COMMON_NAME_PATTERN.matcher(newEntity.getJobName()).matches(), "job.manager.job-name.unmatch-regex");
    Ex.check(!StringUtils.isEmpty(newEntity.getJobRemarks()), () -> Constant.COMMON_REMARK_PATTERN.matcher(newEntity.getJobRemarks()).matches(), "job.manager.job-remarks.unmatch-regex");
    // Check exist Job Manager with this id
    JobManager entity = this.service.get(id);
    if (entity == null) {
        throw new ExternalException("job-manager.not-exist.id", id);
    }
    if (!newEntity.getJobName().equals(entity.getJobName()) && this.service.getTask(newEntity.getJobName(), connId) != null) {
        throw new InternalException("job.manager.job-name.repeated");
    }
    entity.setJobName(newEntity.getJobName());
    entity.setJobRemarks(newEntity.getJobRemarks());
    this.service.update(entity);
    return entity;
}
Also used : JobManager(com.baidu.hugegraph.entity.load.JobManager) ExternalException(com.baidu.hugegraph.exception.ExternalException) InternalException(com.baidu.hugegraph.exception.InternalException) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Aggregations

JobManager (com.baidu.hugegraph.entity.load.JobManager)15 ExternalException (com.baidu.hugegraph.exception.ExternalException)9 PostMapping (org.springframework.web.bind.annotation.PostMapping)7 GraphConnection (com.baidu.hugegraph.entity.GraphConnection)5 FileMapping (com.baidu.hugegraph.entity.load.FileMapping)5 LoadTask (com.baidu.hugegraph.entity.load.LoadTask)4 PutMapping (org.springframework.web.bind.annotation.PutMapping)3 ArrayList (java.util.ArrayList)2 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)2 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)2 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 JobStatus (com.baidu.hugegraph.entity.enums.JobStatus)1 FileUploadResult (com.baidu.hugegraph.entity.load.FileUploadResult)1 JobManagerReasonResult (com.baidu.hugegraph.entity.load.JobManagerReasonResult)1 InternalException (com.baidu.hugegraph.exception.InternalException)1 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 File (java.io.File)1 Date (java.util.Date)1