microsoft / spring-data-gremlin

We are in the process of deprecating Spring Data Gremlin. -- Provide generic annotation oriented programming form based on gremlin for graph database
Other
129 stars 76 forks source link

Exception "No such property: g for class: Script" when working with JanusGraph on IBM Cloud #197

Closed frenki-d closed 3 years ago

frenki-d commented 5 years ago

Hi! I created a JanusGraph Server using IBM Compose and tried to run your example on it.

Connection with my remote JanusGraph server is established, but any method that works with data in my graph fails with exception: com.microsoft.spring.data.gremlin.exception.GremlinQueryException: unable to complete query from gremlin; nested exception is java.util.concurrent.ExecutionException: org.apache.tinkerpop.gremlin.driver.exception.ResponseException: No such property: g for class: Script22

What am I doing wrong? From Gremlin console everything works fine.

Incarnation-p-lee commented 5 years ago

@frenki-d Can you provide more sample code and information about this issue ? By the way, this package focus on gremlin-server which independent to backend db. If backend graph db has some specific implemenation, you may got some unexpecte result.

frenki-d commented 5 years ago

@Incarnation-p-lee, I checked out https://github.com/Microsoft/spring-data-gremlin/tree/master/examples, changed application.yml to:

 gremlin:
   endpoint: ....1243096254.composedb.com
   port: 31226
   username: admin
   password: ...
   sslEnabled: true
   telemetryAllowed: false

and ran example.springdata.gremlin.Application. But it failed with:

2019-02-05 14:36:02.224 ERROR 10536 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'application': Invocation of init method failed; nested exception is com.microsoft.spring.data.gremlin.exception.GremlinQueryException: unable to complete query from gremlin; nested exception is java.util.concurrent.ExecutionException: org.apache.tinkerpop.gremlin.driver.exception.ResponseException: No such property: g for class: Script24
    at com.microsoft.spring.data.gremlin.query.GremlinTemplate.lambda$executeQueryParallel$2(GremlinTemplate.java:101) ~[spring-data-gremlin-2.1.0.jar:2.1.0]
    at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:267) ~[na:1.8.0_192]
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382) ~[na:1.8.0_192]
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_192]
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_192]
    at java.util.stream.ReduceOps$ReduceTask.doLeaf(ReduceOps.java:747) ~[na:1.8.0_192]
    at java.util.stream.ReduceOps$ReduceTask.doLeaf(ReduceOps.java:721) ~[na:1.8.0_192]
    at java.util.stream.AbstractTask.compute(AbstractTask.java:316) ~[na:1.8.0_192]
    at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731) ~[na:1.8.0_192]
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) ~[na:1.8.0_192]
    at java.util.concurrent.ForkJoinTask.doInvoke(ForkJoinTask.java:401) ~[na:1.8.0_192]
    at java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:734) ~[na:1.8.0_192]
    at java.util.stream.ReduceOps$ReduceOp.evaluateParallel(ReduceOps.java:714) ~[na:1.8.0_192]
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233) ~[na:1.8.0_192]
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_192]
    at com.microsoft.spring.data.gremlin.query.GremlinTemplate.executeQueryParallel(GremlinTemplate.java:104) ~[spring-data-gremlin-2.1.0.jar:2.1.0]
    at com.microsoft.spring.data.gremlin.query.GremlinTemplate.lambda$executeQuery$0(GremlinTemplate.java:90) ~[spring-data-gremlin-2.1.0.jar:2.1.0]
    at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:267) ~[na:1.8.0_192]
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382) ~[na:1.8.0_192]
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_192]
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_192]
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_192]
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_192]
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_192]
    at com.microsoft.spring.data.gremlin.query.GremlinTemplate.executeQuery(GremlinTemplate.java:90) ~[spring-data-gremlin-2.1.0.jar:2.1.0]
    at com.microsoft.spring.data.gremlin.query.GremlinTemplate.deleteAll(GremlinTemplate.java:112) ~[spring-data-gremlin-2.1.0.jar:2.1.0]
    at com.microsoft.spring.data.gremlin.repository.support.SimpleGremlinRepository.deleteAll(SimpleGremlinRepository.java:114) ~[spring-data-gremlin-2.1.0.jar:2.1.0]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_192]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_192]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_192]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_192]
    at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:359) ~[spring-data-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200) ~[spring-data-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:644) ~[spring-data-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:608) ~[spring-data-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595) ~[spring-data-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595) ~[spring-data-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) ~[spring-data-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) ~[spring-aop-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) ~[spring-data-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at com.sun.proxy.$Proxy79.deleteAll(Unknown Source) ~[na:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_192]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_192]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_192]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_192]
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) ~[spring-aop-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at com.sun.proxy.$Proxy79.deleteAll(Unknown Source) ~[na:na]
    at example.springdata.gremlin.Application.setup(Application.java:72) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_192]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_192]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_192]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_192]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:363) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:307) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
Incarnation-p-lee commented 5 years ago

@frenki-d As we have no env of JanuseGraph and I can only suggestion you 2 ways to validation.

https://github.com/Microsoft/spring-data-gremlin/blob/91a7a627f0a700df551c35ed2d2d112d5ef50b6a/.travis.yml#L5-L11

frenki-d commented 5 years ago

@Incarnation-p-lee Everything works fine with apache-tinkerpop-gremlin-server-3.3.5. So the cause of the problem may be in JanusGraph server settings, but I can't change them. I even have no read access to config files of JanusGraph created by IBM Compose.

May be they don't execute empty-sample.groovy script. It's the only place where I found something similar to my "g":

// define the default TraversalSource to bind queries to - this one will be named "g".
globals << [g : graph.traversal()]

I deleted this string from script, restarted apache-tinkerpop-gremlin-server and ran Application once again. And yes, I got my exception

com.microsoft.spring.data.gremlin.exception.GremlinQueryException: unable to complete query from gremlin; nested exception is java.util.concurrent.ExecutionException: org.apache.tinkerpop.gremlin.driver.exception.ResponseException: No such property: g for class: Script3

So, this error can't be fixed in this lib, it's an IBM Compose "feature" ((

jespersm commented 5 years ago

So, this error can't be fixed in this lib, it's an IBM Compose "feature" ((

JanusGraph supports multiple named graphs, not just the 'graph' and 'g' traversals.

The Gremlin client allows you to specify the name of the graph as an alias to DriverRemoteConnection.using(Client client, String remoteTraversalSourceName) which would be very useful to configure in com.microsoft.spring.data.gremlin.common.GremlinConfig. So yes, it really is a feature.

jespersm commented 5 years ago

Oh, I forgot that this library uses the (old-style) scripts, not TraversalSource. In that case, you can either allow the 'g' used in building the queries to be aliased, or supply an alias map using org.apache.tinkerpop.gremlin.driver.Client.alias(Map<String,String> aliases).

frenki-d commented 5 years ago

In that case, you can either allow the 'g' used in building the queries to be aliased

And how can do it? As far as I understand, I can create new graph named "example" by calling from Gremlin console def graph = ConfiguredGraphFactory.create("example"). To create a traversal for this graph I should just call graph.traversal(). But how can I tell my JanusGraph to save this traversal name as "g" (for example), so that queries from my Java code will work fine?

jespersm commented 5 years ago

And how can do it? As far as I understand, I can create new graph named "example" by calling from Gremlin console def graph = ConfiguredGraphFactory.create("example"). To create a traversal for this graph I should just call graph.traversal(). But how can I tell my JanusGraph to save this traversal name as "g" (for example), so that queries from my Java code will work fine?

See https://docs.janusgraph.org/latest/configuredgraphfactory.html#graph-and-traversal-bindings - you should use _traversal.

But you can't really use this project against a Gremlin Server in practice as is, since it uses scripts instead of TraversalSources, and the literals are written into the scrips, and not passed as parameters. This requires every script to be compiled as a Groovy source and then dynamically loaded in the server proces. It will be very slow. I assume CosmosDB is implemented in a different fashion.

frenki-d commented 5 years ago

See https://docs.janusgraph.org/latest/configuredgraphfactory.html#graph-and-traversal-bindings - you should use _traversal.

Looks like it doesn't work now without server restart: https://github.com/JanusGraph/janusgraph/issues/1269. That's why I got Could not alias [g] to [example_traversal] as [example_traversal] not in the Graph or TraversalSource global bindings

jespersm commented 5 years ago

@frenki-d : As I read the docs, it should work, possibly pending a 20 second cluster sync period. I'd advice you to try out the user mailing list or Gitter channel for JanusGraph, they are pretty responsive.

Incarnation-p-lee commented 5 years ago

@frenki-d I am not sure if we can add some specific configuration when creating gremlin client instance to solve this issue. If we can add one optional config for this.

@jespersm We leverage old style because when start the repo, the newest gremlin driver with genetate Traversal script will hang forever when executing the script. I did some investigation on both community and stackoverflow but failure to find perfect solution. As the deadline and time limination, we choose old styple for now. We will plan to investigate that from newest version later.

chenrujun commented 3 years ago

Closing this issue. Because it's not active for a long time. If anyone have similar issue, please create issue in new repo: https://github.com/Azure/azure-sdk-for-java/issues