Search in sources :

Example 26 with ExternalException

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

the class GremlinQueryService method getRealVertexId.

private Object getRealVertexId(int connId, AdjacentQuery query) {
    VertexLabelEntity entity = this.vlService.get(query.getVertexLabel(), connId);
    IdStrategy idStrategy = entity.getIdStrategy();
    String rawVertexId = query.getVertexId();
    try {
        if (idStrategy == IdStrategy.AUTOMATIC || idStrategy == IdStrategy.CUSTOMIZE_NUMBER) {
            return Long.parseLong(rawVertexId);
        } else if (idStrategy == IdStrategy.CUSTOMIZE_UUID) {
            return UUID.fromString(rawVertexId);
        }
    } catch (Exception e) {
        throw new ExternalException("gremlin.convert-vertex-id.failed", e, rawVertexId, idStrategy);
    }
    assert idStrategy == IdStrategy.PRIMARY_KEY || idStrategy == IdStrategy.CUSTOMIZE_STRING;
    return rawVertexId;
}
Also used : IdStrategy(com.baidu.hugegraph.structure.constant.IdStrategy) ExternalException(com.baidu.hugegraph.exception.ExternalException) VertexLabelEntity(com.baidu.hugegraph.entity.schema.VertexLabelEntity) ServerException(com.baidu.hugegraph.exception.ServerException) ExternalException(com.baidu.hugegraph.exception.ExternalException) ClientException(com.baidu.hugegraph.rest.ClientException) IllegalGremlinException(com.baidu.hugegraph.exception.IllegalGremlinException) InternalException(com.baidu.hugegraph.exception.InternalException)

Example 27 with ExternalException

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

the class EdgeLabelService method get.

public EdgeLabelEntity get(String name, int connId) {
    HugeClient client = this.client(connId);
    try {
        EdgeLabel edgeLabel = client.schema().getEdgeLabel(name);
        List<IndexLabel> indexLabels = client.schema().getIndexLabels();
        return convert(edgeLabel, indexLabels);
    } catch (ServerException e) {
        if (e.status() == Constant.STATUS_NOT_FOUND) {
            throw new ExternalException("schema.edgelabel.not-exist", e, name);
        }
        throw new ExternalException("schema.edgelabel.get.failed", e, name);
    }
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) ServerException(com.baidu.hugegraph.exception.ServerException) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) ExternalException(com.baidu.hugegraph.exception.ExternalException)

Example 28 with ExternalException

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

the class VertexLabelService method reuse.

public void reuse(ConflictDetail detail, int connId) {
    // Assume that the conflict detail is valid
    Ex.check(!detail.hasConflict(), "schema.cannot-reuse-conflict");
    HugeClient client = this.client(connId);
    List<PropertyKey> propertyKeys = this.pkService.filter(detail, client);
    if (!propertyKeys.isEmpty()) {
        try {
            this.pkService.addBatch(propertyKeys, client);
        } catch (Exception e) {
            throw new ExternalException("schema.propertykey.reuse.failed", e);
        }
    }
    List<VertexLabel> vertexLabels = this.filter(detail, client);
    // Filter propertykeys and propertyindexes
    if (!vertexLabels.isEmpty()) {
        try {
            this.addBatch(vertexLabels, client);
        } catch (Exception e) {
            this.pkService.removeBatch(propertyKeys, client);
            throw new ExternalException("schema.vertexlabel.reuse.failed", e);
        }
    }
    List<IndexLabel> indexLabels = this.piService.filter(detail, client);
    if (!indexLabels.isEmpty()) {
        try {
            this.piService.addBatch(indexLabels, client);
        } catch (Exception e) {
            this.removeBatch(vertexLabels, client);
            this.pkService.removeBatch(propertyKeys, client);
            throw new ExternalException("schema.propertyindex.reuse.failed", e);
        }
    }
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ExternalException(com.baidu.hugegraph.exception.ExternalException) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey) ServerException(com.baidu.hugegraph.exception.ServerException) ExternalException(com.baidu.hugegraph.exception.ExternalException)

Example 29 with ExternalException

use of com.baidu.hugegraph.exception.ExternalException 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();
}
Also used : LoadTask(com.baidu.hugegraph.entity.load.LoadTask) FileMapping(com.baidu.hugegraph.entity.load.FileMapping) JobManager(com.baidu.hugegraph.entity.load.JobManager) ExternalException(com.baidu.hugegraph.exception.ExternalException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 30 with ExternalException

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

the class LoadTaskController method delete.

@DeleteMapping("{id}")
public void delete(@PathVariable("id") int id) {
    LoadTask task = this.service.get(id);
    if (task == null) {
        throw new ExternalException("load.task.not-exist.id", id);
    }
    this.service.remove(id);
}
Also used : LoadTask(com.baidu.hugegraph.entity.load.LoadTask) 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