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);
}
}
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;
}
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;
}
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();
}
}
}
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();
}
Aggregations