Search in sources :

Example 1 with Status

use of com.baidu.hugegraph.api.filter.StatusFilter.Status in project incubator-hugegraph by apache.

the class EdgeAPI method create.

@POST
@Timed(name = "batch-create")
@Decompress
@Path("batch")
@Status(Status.CREATED)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin", "$owner=$graph $action=edge_write" })
public String create(@Context HugeConfig config, @Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("check_vertex") @DefaultValue("true") boolean checkVertex, List<JsonEdge> jsonEdges) {
    LOG.debug("Graph [{}] create edges: {}", graph, jsonEdges);
    checkCreatingBody(jsonEdges);
    checkBatchSize(config, jsonEdges);
    HugeGraph g = graph(manager, graph);
    TriFunction<HugeGraph, Object, String, Vertex> getVertex = checkVertex ? EdgeAPI::getVertex : EdgeAPI::newVertex;
    return this.commit(config, g, jsonEdges.size(), () -> {
        List<Id> ids = new ArrayList<>(jsonEdges.size());
        for (JsonEdge jsonEdge : jsonEdges) {
            /*
                 * NOTE: If the query param 'checkVertex' is false,
                 * then the label is correct and not matched id,
                 * it will be allowed currently
                 */
            Vertex srcVertex = getVertex.apply(g, jsonEdge.source, jsonEdge.sourceLabel);
            Vertex tgtVertex = getVertex.apply(g, jsonEdge.target, jsonEdge.targetLabel);
            Edge edge = srcVertex.addEdge(jsonEdge.label, tgtVertex, jsonEdge.properties());
            ids.add((Id) edge.id());
        }
        return manager.serializer(g).writeIds(ids);
    });
}
Also used : HugeVertex(com.baidu.hugegraph.structure.HugeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HugeGraph(com.baidu.hugegraph.HugeGraph) ArrayList(java.util.ArrayList) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Path(jakarta.ws.rs.Path) Status(com.baidu.hugegraph.api.filter.StatusFilter.Status) RolesAllowed(jakarta.annotation.security.RolesAllowed) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) Decompress(com.baidu.hugegraph.api.filter.DecompressInterceptor.Decompress)

Example 2 with Status

use of com.baidu.hugegraph.api.filter.StatusFilter.Status in project incubator-hugegraph by apache.

the class EdgeAPI method create.

@POST
@Timed(name = "single-create")
@Status(Status.CREATED)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin", "$owner=$graph $action=edge_write" })
public String create(@Context GraphManager manager, @PathParam("graph") String graph, JsonEdge jsonEdge) {
    LOG.debug("Graph [{}] create edge: {}", graph, jsonEdge);
    checkCreatingBody(jsonEdge);
    HugeGraph g = graph(manager, graph);
    if (jsonEdge.sourceLabel != null && jsonEdge.targetLabel != null) {
        /*
             * NOTE: If the vertex id is correct but label not match with id,
             * we allow to create it here
             */
        vertexLabel(g, jsonEdge.sourceLabel, "Invalid source vertex label '%s'");
        vertexLabel(g, jsonEdge.targetLabel, "Invalid target vertex label '%s'");
    }
    Vertex srcVertex = getVertex(g, jsonEdge.source, jsonEdge.sourceLabel);
    Vertex tgtVertex = getVertex(g, jsonEdge.target, jsonEdge.targetLabel);
    Edge edge = commit(g, () -> {
        return srcVertex.addEdge(jsonEdge.label, tgtVertex, jsonEdge.properties());
    });
    return manager.serializer(g).writeEdge(edge);
}
Also used : HugeVertex(com.baidu.hugegraph.structure.HugeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HugeGraph(com.baidu.hugegraph.HugeGraph) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Status(com.baidu.hugegraph.api.filter.StatusFilter.Status) RolesAllowed(jakarta.annotation.security.RolesAllowed) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed)

Example 3 with Status

use of com.baidu.hugegraph.api.filter.StatusFilter.Status in project incubator-hugegraph by apache.

the class VertexAPI method create.

@POST
@Timed(name = "batch-create")
@Decompress
@Path("batch")
@Status(Status.CREATED)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin", "$owner=$graph $action=vertex_write" })
public String create(@Context HugeConfig config, @Context GraphManager manager, @PathParam("graph") String graph, List<JsonVertex> jsonVertices) {
    LOG.debug("Graph [{}] create vertices: {}", graph, jsonVertices);
    checkCreatingBody(jsonVertices);
    checkBatchSize(config, jsonVertices);
    HugeGraph g = graph(manager, graph);
    return this.commit(config, g, jsonVertices.size(), () -> {
        List<Id> ids = new ArrayList<>(jsonVertices.size());
        for (JsonVertex vertex : jsonVertices) {
            ids.add((Id) g.addVertex(vertex.properties()).id());
        }
        return manager.serializer(g).writeIds(ids);
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) ArrayList(java.util.ArrayList) Id(com.baidu.hugegraph.backend.id.Id) Path(jakarta.ws.rs.Path) Status(com.baidu.hugegraph.api.filter.StatusFilter.Status) RolesAllowed(jakarta.annotation.security.RolesAllowed) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) Decompress(com.baidu.hugegraph.api.filter.DecompressInterceptor.Decompress)

Example 4 with Status

use of com.baidu.hugegraph.api.filter.StatusFilter.Status in project incubator-hugegraph by apache.

the class RaftAPI method addPeer.

@POST
@Timed
@Status(Status.OK)
@Path("add_peer")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin" })
public Map<String, String> addPeer(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("group") @DefaultValue("default") String group, @QueryParam("endpoint") String endpoint) {
    LOG.debug("Graph [{}] prepare to add peer: {}", graph, endpoint);
    HugeGraph g = graph(manager, graph);
    RaftGroupManager raftManager = raftGroupManager(g, group, "add_peer");
    String peerId = raftManager.addPeer(endpoint);
    return ImmutableMap.of(raftManager.group(), peerId);
}
Also used : RaftGroupManager(com.baidu.hugegraph.backend.store.raft.RaftGroupManager) HugeGraph(com.baidu.hugegraph.HugeGraph) Status(com.baidu.hugegraph.api.filter.StatusFilter.Status) Path(jakarta.ws.rs.Path) RolesAllowed(jakarta.annotation.security.RolesAllowed) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed)

Example 5 with Status

use of com.baidu.hugegraph.api.filter.StatusFilter.Status in project incubator-hugegraph by apache.

the class IndexLabelAPI method create.

@POST
@Timed
@Status(Status.ACCEPTED)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin", "$owner=$graph $action=index_label_write" })
public String create(@Context GraphManager manager, @PathParam("graph") String graph, JsonIndexLabel jsonIndexLabel) {
    LOG.debug("Graph [{}] create index label: {}", graph, jsonIndexLabel);
    checkCreatingBody(jsonIndexLabel);
    HugeGraph g = graph(manager, graph);
    IndexLabel.Builder builder = jsonIndexLabel.convert2Builder(g);
    SchemaElement.TaskWithSchema il = builder.createWithTask();
    il.indexLabel(mapIndexLabel(il.indexLabel()));
    return manager.serializer(g).writeTaskWithSchema(il);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) SchemaElement(com.baidu.hugegraph.schema.SchemaElement) Status(com.baidu.hugegraph.api.filter.StatusFilter.Status) RolesAllowed(jakarta.annotation.security.RolesAllowed) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

Status (com.baidu.hugegraph.api.filter.StatusFilter.Status)30 Timed (com.codahale.metrics.annotation.Timed)30 Produces (jakarta.ws.rs.Produces)30 HugeGraph (com.baidu.hugegraph.HugeGraph)29 Consumes (jakarta.ws.rs.Consumes)26 RolesAllowed (jakarta.annotation.security.RolesAllowed)21 POST (jakarta.ws.rs.POST)20 Path (jakarta.ws.rs.Path)18 PUT (jakarta.ws.rs.PUT)5 RaftGroupManager (com.baidu.hugegraph.backend.store.raft.RaftGroupManager)4 DELETE (jakarta.ws.rs.DELETE)4 Id (com.baidu.hugegraph.backend.id.Id)3 SchemaElement (com.baidu.hugegraph.schema.SchemaElement)3 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)3 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)3 Decompress (com.baidu.hugegraph.api.filter.DecompressInterceptor.Decompress)2 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)2 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)2 BadRequestException (jakarta.ws.rs.BadRequestException)2 ArrayList (java.util.ArrayList)2