Search in sources :

Example 1 with RequestMessage

use of org.apache.tinkerpop.gremlin.driver.message.RequestMessage in project cypher-for-gremlin by opencypher.

the class CypherOpProcessor method traversal.

private GraphTraversalSource traversal(Context context) throws OpProcessorException {
    RequestMessage msg = context.getRequestMessage();
    GraphManager graphManager = context.getGraphManager();
    Optional<Map<String, String>> aliasesOptional = msg.optionalArgs(Tokens.ARGS_ALIASES);
    String gAlias = aliasesOptional.map(aliases -> aliases.get(Tokens.VAL_TRAVERSAL_SOURCE_ALIAS)).orElse(null);
    if (gAlias == null) {
        return graphManager.getGraphNames().stream().findFirst().map(graphManager::getGraph).map(Graph::traversal).orElseThrow(() -> opProcessorException(msg, "No graphs found on the server"));
    }
    Graph graph = graphManager.getGraph(gAlias);
    if (graph != null) {
        return graph.traversal();
    }
    TraversalSource traversalSource = graphManager.getTraversalSource(gAlias);
    if (traversalSource instanceof GraphTraversalSource) {
        return (GraphTraversalSource) traversalSource;
    }
    throw opProcessorException(msg, "Traversable alias '" + gAlias + "' not found");
}
Also used : Optional.empty(java.util.Optional.empty) OpProcessor(org.apache.tinkerpop.gremlin.server.OpProcessor) EXPLAIN(org.opencypher.gremlin.translation.StatementOption.EXPLAIN) ThrowingConsumer(org.apache.tinkerpop.gremlin.util.function.ThrowingConsumer) Graph(org.apache.tinkerpop.gremlin.structure.Graph) Tokens(org.apache.tinkerpop.gremlin.driver.Tokens) Translator(org.opencypher.gremlin.translation.translator.Translator) HashMap(java.util.HashMap) RequestMessage(org.apache.tinkerpop.gremlin.driver.message.RequestMessage) Collections.singletonList(java.util.Collections.singletonList) AbstractEvalOpProcessor(org.apache.tinkerpop.gremlin.server.op.AbstractEvalOpProcessor) LinkedHashMap(java.util.LinkedHashMap) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ResponseMessage(org.apache.tinkerpop.gremlin.driver.message.ResponseMessage) GraphManager(org.apache.tinkerpop.gremlin.server.GraphManager) Map(java.util.Map) SERVER_ERROR(org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode.SERVER_ERROR) GroovyPredicate(org.opencypher.gremlin.translation.groovy.GroovyPredicate) OpProcessorException(org.apache.tinkerpop.gremlin.server.op.OpProcessorException) P(org.apache.tinkerpop.gremlin.process.traversal.P) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) ReturnNormalizer(org.opencypher.gremlin.traversal.ReturnNormalizer) Logger(org.slf4j.Logger) CYPHER_OP_PROCESSOR_NAME(org.opencypher.gremlin.ClientServerCommunication.CYPHER_OP_PROCESSOR_NAME) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) ResponseStatusCode(org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode) TraversalSource(org.apache.tinkerpop.gremlin.process.traversal.TraversalSource) Context(org.apache.tinkerpop.gremlin.server.Context) CypherAstWrapper(org.opencypher.gremlin.translation.CypherAstWrapper) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) GraphManager(org.apache.tinkerpop.gremlin.server.GraphManager) Graph(org.apache.tinkerpop.gremlin.structure.Graph) TraversalSource(org.apache.tinkerpop.gremlin.process.traversal.TraversalSource) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) RequestMessage(org.apache.tinkerpop.gremlin.driver.message.RequestMessage) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with RequestMessage

use of org.apache.tinkerpop.gremlin.driver.message.RequestMessage in project cypher-for-gremlin by opencypher.

the class ClientServerCommunicationTest method createRequestTest.

@Test
public void createRequestTest() throws Exception {
    RequestMessage request = buildRequest("cypher").create();
    assertThat(request.getOp()).isEqualTo(Tokens.OPS_EVAL);
    assertThat(request.getProcessor()).isEqualTo(CYPHER_OP_PROCESSOR_NAME);
    assertThat(request.getArgs()).containsOnly(entry(Tokens.ARGS_GREMLIN, "cypher"));
}
Also used : RequestMessage(org.apache.tinkerpop.gremlin.driver.message.RequestMessage) Test(org.junit.Test)

Example 3 with RequestMessage

use of org.apache.tinkerpop.gremlin.driver.message.RequestMessage in project janusgraph by JanusGraph.

the class JanusGraphIoRegistryTest method serializationTest.

private void serializationTest(GraphTraversal[] traversals) throws SerializationException {
    Builder mapper = GryoMapper.build().addRegistry(JanusGraphIoRegistry.getInstance());
    MessageSerializer binarySerializer = new GryoMessageSerializerV1d0(mapper);
    for (GraphTraversal traversal : traversals) {
        Bytecode expectedBytecode = traversal.asAdmin().getBytecode();
        RequestMessage requestMessage = RequestMessage.build(Tokens.OPS_BYTECODE).processor("traversal").addArg(Tokens.ARGS_GREMLIN, expectedBytecode).create();
        ByteBuf bb = binarySerializer.serializeRequestAsBinary(requestMessage, allocator);
        final int mimeLen = bb.readByte();
        bb.readBytes(new byte[mimeLen]);
        RequestMessage deser = binarySerializer.deserializeRequest(bb);
        Bytecode result = (Bytecode) deser.getArgs().get(Tokens.ARGS_GREMLIN);
        assertEquals(expectedBytecode, result);
    }
}
Also used : MessageSerializer(org.apache.tinkerpop.gremlin.driver.MessageSerializer) Builder(org.apache.tinkerpop.gremlin.structure.io.gryo.GryoMapper.Builder) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) RequestMessage(org.apache.tinkerpop.gremlin.driver.message.RequestMessage) Bytecode(org.apache.tinkerpop.gremlin.process.traversal.Bytecode) ByteBuf(io.netty.buffer.ByteBuf) GryoMessageSerializerV1d0(org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0)

Example 4 with RequestMessage

use of org.apache.tinkerpop.gremlin.driver.message.RequestMessage in project cypher-for-gremlin by opencypher.

the class OpProcessorCypherGremlinClient method submitAsync.

@Override
public CompletableFuture<CypherResultSet> submitAsync(String cypher, Map<String, ?> parameters) {
    RequestMessage requestMessage = buildRequest(cypher, parameters).create();
    CompletableFuture<ResultSet> resultSetFuture = client.submitAsync(requestMessage);
    return resultSetFuture.thenApply(ResultSet::iterator).thenApply(CypherResultSet::new);
}
Also used : RequestMessage(org.apache.tinkerpop.gremlin.driver.message.RequestMessage) ResultSet(org.apache.tinkerpop.gremlin.driver.ResultSet)

Aggregations

RequestMessage (org.apache.tinkerpop.gremlin.driver.message.RequestMessage)4 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)2 ByteBuf (io.netty.buffer.ByteBuf)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Optional.empty (java.util.Optional.empty)1 MessageSerializer (org.apache.tinkerpop.gremlin.driver.MessageSerializer)1 ResultSet (org.apache.tinkerpop.gremlin.driver.ResultSet)1 Tokens (org.apache.tinkerpop.gremlin.driver.Tokens)1 ResponseMessage (org.apache.tinkerpop.gremlin.driver.message.ResponseMessage)1 ResponseStatusCode (org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode)1 SERVER_ERROR (org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode.SERVER_ERROR)1 GryoMessageSerializerV1d0 (org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0)1 Bytecode (org.apache.tinkerpop.gremlin.process.traversal.Bytecode)1 P (org.apache.tinkerpop.gremlin.process.traversal.P)1 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)1