Search in sources :

Example 31 with ExternalException

use of com.baidu.hugegraph.exception.ExternalException 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 32 with ExternalException

use of com.baidu.hugegraph.exception.ExternalException 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 33 with ExternalException

use of com.baidu.hugegraph.exception.ExternalException in project incubator-hugegraph-toolchain by apache.

the class FileMappingController method updateEdgeMapping.

@PutMapping("{id}/edge-mappings/{emid}")
public FileMapping updateEdgeMapping(@PathVariable("connId") int connId, @PathVariable("id") int id, @PathVariable("emid") String emId, @RequestBody EdgeMapping newEntity) {
    FileMapping mapping = this.service.get(id);
    if (mapping == null) {
        throw new ExternalException("load.file-mapping.not-exist.id", id);
    }
    this.checkEdgeMappingValid(connId, newEntity, mapping);
    EdgeMapping edgeMapping = mapping.getEdgeMapping(emId);
    Ex.check(edgeMapping != null, "load.file-mapping.edge-mapping.not-exist.id", emId);
    newEntity.setId(emId);
    Set<EdgeMapping> edgeMappings = mapping.getEdgeMappings();
    edgeMappings.remove(edgeMapping);
    edgeMappings.add(newEntity);
    this.service.update(mapping);
    return mapping;
}
Also used : FileMapping(com.baidu.hugegraph.entity.load.FileMapping) EdgeMapping(com.baidu.hugegraph.entity.load.EdgeMapping) ExternalException(com.baidu.hugegraph.exception.ExternalException) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 34 with ExternalException

use of com.baidu.hugegraph.exception.ExternalException in project incubator-hugegraph-toolchain by apache.

the class FileMappingController method deleteVertexMapping.

@DeleteMapping("{id}/vertex-mappings/{vmid}")
public FileMapping deleteVertexMapping(@PathVariable("id") int id, @PathVariable("vmid") String vmid) {
    FileMapping mapping = this.service.get(id);
    if (mapping == null) {
        throw new ExternalException("load.file-mapping.not-exist.id", id);
    }
    VertexMapping vertexMapping = mapping.getVertexMapping(vmid);
    boolean removed = mapping.getVertexMappings().remove(vertexMapping);
    if (!removed) {
        throw new ExternalException("load.file-mapping.vertex-mapping.not-exist.id", vmid);
    }
    this.service.update(mapping);
    return mapping;
}
Also used : FileMapping(com.baidu.hugegraph.entity.load.FileMapping) VertexMapping(com.baidu.hugegraph.entity.load.VertexMapping) ExternalException(com.baidu.hugegraph.exception.ExternalException) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Example 35 with ExternalException

use of com.baidu.hugegraph.exception.ExternalException in project incubator-hugegraph-toolchain by apache.

the class FileMappingController method deleteEdgeMapping.

@DeleteMapping("{id}/edge-mappings/{emid}")
public FileMapping deleteEdgeMapping(@PathVariable("id") int id, @PathVariable("emid") String emid) {
    FileMapping mapping = this.service.get(id);
    if (mapping == null) {
        throw new ExternalException("load.file-mapping.not-exist.id", id);
    }
    EdgeMapping edgeMapping = mapping.getEdgeMapping(emid);
    boolean removed = mapping.getEdgeMappings().remove(edgeMapping);
    if (!removed) {
        throw new ExternalException("load.file-mapping.edge-mapping.not-exist.id", emid);
    }
    this.service.update(mapping);
    return mapping;
}
Also used : FileMapping(com.baidu.hugegraph.entity.load.FileMapping) EdgeMapping(com.baidu.hugegraph.entity.load.EdgeMapping) ExternalException(com.baidu.hugegraph.exception.ExternalException) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Aggregations

ExternalException (com.baidu.hugegraph.exception.ExternalException)42 HugeClient (com.baidu.hugegraph.driver.HugeClient)14 FileMapping (com.baidu.hugegraph.entity.load.FileMapping)11 ServerException (com.baidu.hugegraph.exception.ServerException)11 GraphConnection (com.baidu.hugegraph.entity.GraphConnection)9 JobManager (com.baidu.hugegraph.entity.load.JobManager)9 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)9 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)8 PostMapping (org.springframework.web.bind.annotation.PostMapping)8 LoadTask (com.baidu.hugegraph.entity.load.LoadTask)5 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)5 PutMapping (org.springframework.web.bind.annotation.PutMapping)5 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)4 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)4 InternalException (com.baidu.hugegraph.exception.InternalException)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 EdgeMapping (com.baidu.hugegraph.entity.load.EdgeMapping)2 VertexMapping (com.baidu.hugegraph.entity.load.VertexMapping)2 GremlinCollection (com.baidu.hugegraph.entity.query.GremlinCollection)2 ClientException (com.baidu.hugegraph.rest.ClientException)2