use of com.baidu.hugegraph.entity.GraphConnection 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);
}
}
use of com.baidu.hugegraph.entity.GraphConnection 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);
}
}
use of com.baidu.hugegraph.entity.GraphConnection in project incubator-hugegraph-toolchain by apache.
the class GraphConnectionController method checkEntityUnique.
private void checkEntityUnique(GraphConnection newEntity, boolean creating) {
List<GraphConnection> oldEntities = this.connService.listAll();
for (GraphConnection oldEntity : oldEntities) {
// NOTE: create should check all, update check others
if (!creating && oldEntity.getId().equals(newEntity.getId())) {
continue;
}
Ex.check(!oldEntity.getName().equals(newEntity.getName()), "graph-connection.exist.name", oldEntity.getName());
Ex.check(!(oldEntity.getGraph().equals(newEntity.getGraph()) && oldEntity.getHost().equals(newEntity.getHost()) && oldEntity.getPort().equals(newEntity.getPort())), "graph-connection.exist.graph-host-port", oldEntity.getGraph(), oldEntity.getHost(), oldEntity.getPort());
}
}
use of com.baidu.hugegraph.entity.GraphConnection in project incubator-hugegraph-toolchain by apache.
the class GraphConnectionController method update.
@PutMapping("{id}")
public GraphConnection update(@PathVariable("id") int id, @RequestBody GraphConnection newEntity) {
this.checkIdSameAsBody(id, newEntity);
this.checkParamsValid(newEntity, false);
this.checkAddressSecurity(newEntity);
// Check exist connection with this id
GraphConnection oldEntity = this.connService.get(id);
if (oldEntity == null) {
throw new ExternalException("graph-connection.not-exist.id", id);
}
GraphConnection entity = this.mergeEntity(oldEntity, newEntity);
// Make sure the updated connection doesn't conflict with exists
this.checkEntityUnique(entity, false);
this.sslService.configSSL(this.config, entity);
HugeClient client = HugeClientUtil.tryConnect(entity);
this.connService.update(entity);
this.poolService.put(entity, client);
return entity;
}
use of com.baidu.hugegraph.entity.GraphConnection in project incubator-hugegraph-toolchain by apache.
the class GraphConnectionController method delete.
@DeleteMapping("{id}")
public GraphConnection delete(@PathVariable("id") int id) {
GraphConnection oldEntity = this.connService.get(id);
if (oldEntity == null) {
throw new ExternalException("graph-connection.not-exist.id", id);
}
this.connService.remove(id);
this.poolService.remove(oldEntity);
return oldEntity;
}
Aggregations