Search in sources :

Example 6 with JobManager

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

the class LoadTaskController method create.

@PostMapping
public LoadTask create(@PathVariable("connId") int connId, @PathVariable("jobId") int jobId, @RequestBody LoadTask entity) {
    JobManager jobEntity = this.jobService.get(jobId);
    Ex.check(jobEntity != null, "job-manager.not-exist.id", jobId);
    Ex.check(jobEntity.getJobStatus() == JobStatus.SETTING, "load.task.create.no-permission");
    synchronized (this.service) {
        Ex.check(this.service.count() < LIMIT, "load.task.reached-limit", LIMIT);
        entity.setConnId(connId);
        this.service.save(entity);
    }
    return entity;
}
Also used : JobManager(com.baidu.hugegraph.entity.load.JobManager) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 7 with JobManager

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

the class LoadTaskController method resume.

@PostMapping("resume")
public LoadTask resume(@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.resume(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 8 with JobManager

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

the class LoadTaskController method retry.

@PostMapping("retry")
public LoadTask retry(@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.retry(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 9 with JobManager

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

the class FileUploadController method delete.

@DeleteMapping
public Boolean delete(@PathVariable("connId") int connId, @PathVariable("jobId") int jobId, @RequestParam("name") String fileName, @RequestParam("token") String token) {
    JobManager jobEntity = this.jobService.get(jobId);
    Ex.check(jobEntity != null, "job-manager.not-exist.id", jobId);
    Ex.check(jobEntity.getJobStatus() == JobStatus.UPLOADING || jobEntity.getJobStatus() == JobStatus.MAPPING || jobEntity.getJobStatus() == JobStatus.SETTING, "deleted.file.no-permission");
    FileMapping mapping = this.service.get(connId, jobId, fileName);
    Ex.check(mapping != null, "load.file-mapping.not-exist.name", fileName);
    ReadWriteLock lock = this.uploadingTokenLocks().get(token);
    if (lock != null) {
        lock.writeLock().lock();
    }
    try {
        this.service.deleteDiskFile(mapping);
        log.info("Prepare to remove file mapping {}", mapping.getId());
        this.service.remove(mapping.getId());
        long jobSize = jobEntity.getJobSize() - mapping.getTotalSize();
        jobEntity.setJobSize(jobSize);
        this.jobService.update(jobEntity);
        if (lock != null) {
            this.uploadingTokenLocks().remove(token);
        }
        return true;
    } finally {
        if (lock != null) {
            lock.writeLock().unlock();
        }
    }
}
Also used : FileMapping(com.baidu.hugegraph.entity.load.FileMapping) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) JobManager(com.baidu.hugegraph.entity.load.JobManager) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Example 10 with JobManager

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

the class FileUploadController 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.UPLOADING, "job.manager.status.unexpected", JobStatus.UPLOADING, jobEntity.getJobStatus());
    jobEntity.setJobStatus(JobStatus.MAPPING);
    this.jobService.update(jobEntity);
    return jobEntity;
}
Also used : JobManager(com.baidu.hugegraph.entity.load.JobManager) 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