Search in sources :

Example 36 with ExternalException

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

the class FileMappingController method delete.

@DeleteMapping("{id}")
public void delete(@PathVariable("id") int id) {
    FileMapping mapping = this.service.get(id);
    if (mapping == null) {
        throw new ExternalException("load.file-mapping.not-exist.id", id);
    }
    this.service.deleteDiskFile(mapping);
    this.service.remove(id);
}
Also used : FileMapping(com.baidu.hugegraph.entity.load.FileMapping) ExternalException(com.baidu.hugegraph.exception.ExternalException) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Example 37 with ExternalException

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

the class FileMappingController method updateVertexMapping.

@PutMapping("{id}/vertex-mappings/{vmid}")
public FileMapping updateVertexMapping(@PathVariable("connId") int connId, @PathVariable("id") int id, @PathVariable("vmid") String vmId, @RequestBody VertexMapping newEntity) {
    FileMapping mapping = this.service.get(id);
    if (mapping == null) {
        throw new ExternalException("load.file-mapping.not-exist.id", id);
    }
    this.checkVertexMappingValid(connId, newEntity, mapping);
    VertexMapping vertexMapping = mapping.getVertexMapping(vmId);
    Ex.check(vertexMapping != null, "load.file-mapping.vertex-mapping.not-exist.id", vmId);
    newEntity.setId(vmId);
    Set<VertexMapping> vertexMappings = mapping.getVertexMappings();
    vertexMappings.remove(vertexMapping);
    vertexMappings.add(newEntity);
    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) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 38 with ExternalException

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

the class FileMappingController method addVertexMapping.

@PostMapping("{id}/vertex-mappings")
public FileMapping addVertexMapping(@PathVariable("connId") int connId, @PathVariable("id") int id, @RequestBody VertexMapping newEntity) {
    FileMapping mapping = this.service.get(id);
    if (mapping == null) {
        throw new ExternalException("load.file-mapping.not-exist.id", id);
    }
    this.checkVertexMappingValid(connId, newEntity, mapping);
    newEntity.setId(HubbleUtil.generateSimpleId());
    mapping.getVertexMappings().add(newEntity);
    this.service.update(mapping);
    return mapping;
}
Also used : FileMapping(com.baidu.hugegraph.entity.load.FileMapping) ExternalException(com.baidu.hugegraph.exception.ExternalException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 39 with ExternalException

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

Example 40 with ExternalException

use of com.baidu.hugegraph.exception.ExternalException 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;
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) GraphConnection(com.baidu.hugegraph.entity.GraphConnection) ExternalException(com.baidu.hugegraph.exception.ExternalException) PutMapping(org.springframework.web.bind.annotation.PutMapping)

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