Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JPA] [do not apply] Raw intermediary infrastructure to get a JPA deployment work in Shamrock #5

Merged
merged 6 commits into from
Aug 3, 2018

Conversation

emmanuelbernard
Copy link
Member

@Sanne FYI

@emmanuelbernard emmanuelbernard requested a review from Sanne August 2, 2018 11:44
@Sanne
Copy link
Member

Sanne commented Aug 2, 2018

Thanks, I'll look soon.

Did a blind build and got this:

[INFO] shamrock-strict-example 1.0.0.Alpha1-SNAPSHOT ...... FAILURE [ 0.109 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 34.544 s
[INFO] Finished at: 2018-08-02T13:41:13+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jboss.shamrock:shamrock-maven-plugin:1.0.0.Alpha1-SNAPSHOT:build (default) on project shamrock-strict-example: Failed to run: [Artifact org.jboss.shamrock:shamrock-core-deployment:jar:1.0.0.Alpha1-SNAPSHOT:compile is a deployment artifact, however it does not have scope required. This will result in unnecessary jars being included in the final image, Artifact org.jboss.shamrock:shamrock-jpa-deployment:jar:1.0.0.Alpha1-SNAPSHOT:compile is a deployment artifact, however it does not have scope required. This will result in unnecessary jars being included in the final image] -> [Help 1]

expected?

@Sanne
Copy link
Member

Sanne commented Aug 2, 2018

@stuartwdouglas that's not the usual Maven error. A shamrok specific validation?

@Override
public void process(ArchiveContext archiveContext, ProcessorContext processorContext) throws Exception {
// Hibernate specific reflective classes
processorContext.addReflectiveClass(org.hibernate.jpa.HibernatePersistenceProvider.class.getName());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice approach!

Just FYI we no longer need org.hibernate.jpa.HibernatePersistenceProvider, I actrually had to fully exclude it to get rid of the XML parser dependency.

But I get the idea, this is an example.

/**
* @author Emmanuel Bernard [email protected]
*/
public class JPADeploymentTemplate {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I start to "get" it, very useful thanks.

Just keep in mind we'll need to record a far more complex structure; in order of priority:

  • named containers: a separate JPADeployment for each PU
  • pre-parsed XML and configurations (and upfront validation)
  • entities will need to be pre-enhanced as needed
  • Some explicit classes and types; e.g. resolve the Dialect already so that only one dialect (for each PU) is included.
  • validatorFactory -> inject by instance an option?
  • cdiBeanManager -> inject by instance an option?
  • output of custom StandardServiceInitiator (more instances?) (optional?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep. To be fair, I think this template thing will go away and we will just boot your PersistenceProvider bypass as the solution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yet my "persistence bypass" will need to fetch such state from somewhere; and we'll need such a processor to define all reflection permissions.

In particular while we can hard code the "framework internal reflective needs", we'll need ad-hoc permissions generated on the user model so this angle will need to be used as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes the callback idea you had is how I am seeing it at the moment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably talk about this more, and get an idea about exactly what is needed from shamrock. It would be pretty easy to add the ability to serialise simple objects to the template, as long as they have getters and setters with a no arg constructor.

Looking at the current hibernate code it looks like all the parsing is done in static init, so it is pre-done for the native image, but when running in java mode it is still parsed at runtime.

@emmanuelbernard
Copy link
Member Author

@stuartwdouglas can you take that branch and look at it. There are things around the build process that I don't understand.

First off, master work for me when I do mvn clean install

This branch fails on the strict project claiming it cannot find the native image even though an old version of the image is there. The big difference is that I have added a new @RunWith(GraalTest.class) and I suspect the second one (JPA test) is messed up based on the state left by the first one (JAXRS test).

What is weird though is that it runs the tests before building the native image (I don't see logs running the native image).

When I go in cd example/strict and do mvn shamrock:native. it fails because of Invalid Path entry shamrock-strict-example-1.0.0.Alpha1-SNAPSHOT-runner.jar. Fair but building mvn package -Dnative.image.path=./shamrock-test-deployment-1.0.0.Alpha1-SNAPSHOT also fails. with some untertow binding error

18:38:50.049 [XNIO-1 task-6] DEBUG org.jboss.resteasy.resteasy_jaxrs.i18n - MessageBodyWriter: org.jboss.resteasy.spi.ResteasyProviderFactory$SortedKey
18:38:50.049 [XNIO-1 task-6] DEBUG org.jboss.resteasy.resteasy_jaxrs.i18n - MessageBodyWriter: org.jboss.resteasy.plugins.providers.StringTextStar
18:38:50.049 [XNIO-1 task-6] DEBUG org.jboss.resteasy.resteasy_jaxrs.i18n - MessageBodyWriter: org.jboss.resteasy.plugins.providers.StringTextStar
18:38:50.049 [XNIO-1 task-6] DEBUG org.jboss.resteasy.resteasy_jaxrs.i18n - Interceptor Context: org.jboss.resteasy.core.interception.ServerWriterInterceptorContext,  Method : proceed
18:38:50.049 [XNIO-1 task-6] DEBUG org.jboss.resteasy.resteasy_jaxrs.i18n - MessageBodyWriter: org.jboss.resteasy.spi.ResteasyProviderFactory$SortedKey
18:38:50.049 [XNIO-1 task-6] DEBUG org.jboss.resteasy.resteasy_jaxrs.i18n - MessageBodyWriter: org.jboss.resteasy.plugins.providers.StringTextStar
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.685 s - in org.jboss.shamrock.example.test.JaxRSTestCase
[INFO] Running org.jboss.shamrock.example.test.JPAReflectionInGraalTestCase
Executing ./shamrock-test-deployment-1.0.0.Alpha1-SNAPSHOT
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.lang.Throwable.<init>(Throwable.java:310)
        at java.lang.Exception.<init>(Exception.java:102)
        at java.lang.ReflectiveOperationException.<init>(ReflectiveOperationException.java:89)
        at java.lang.reflect.InvocationTargetException.<init>(InvocationTargetException.java:72)
        at com.oracle.svm.reflect.proxies.Proxy_401_Main_main.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:173)
Caused by: java.lang.RuntimeException: java.net.BindException: NioSocketError
        at java.lang.Throwable.<init>(Throwable.java:310)
        at java.lang.Exception.<init>(Exception.java:102)
        at java.lang.RuntimeException.<init>(RuntimeException.java:96)
        at io.undertow.Undertow.start(Undertow.java:250)
        at org.jboss.shamrock.undertow.runtime.UndertowDeploymentTemplate.deploy(UndertowDeploymentTemplate.java:70)
        at org.jboss.shamrock.deployment.Runner$ProcessorContextImpl$$Proxy4.deploy(Unknown Source)
        at org.jboss.shamrock.runner.Main.main(Unknown Source)
        ... 3 more
Caused by: java.net.BindException: NioSocketError
        at java.lang.Throwable.<init>(Throwable.java:265)
        at java.lang.Exception.<init>(Exception.java:66)
        at java.io.IOException.<init>(IOException.java:58)
        at java.net.SocketException.<init>(SocketException.java:47)
        at java.net.BindException.<init>(BindException.java:47)
        at com.oracle.svm.core.posix.PosixJavaNIOSubstitutions$Util_sun_nio_ch_Net.handleSocketError(PosixJavaNIOSubstitutions.java:1295)
        at com.oracle.svm.core.posix.PosixJavaNIOSubstitutions$Target_sun_nio_ch_Net.bind0(PosixJavaNIOSubstitutions.java:912)
        at sun.nio.ch.Net.bind(Net.java:433)
        at sun.nio.ch.Net.bind(Net.java:425)
        at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
        at org.xnio.nio.NioXnioWorker.createTcpConnectionServer(NioXnioWorker.java:160)
        at org.xnio.XnioWorker.createStreamConnectionServer(XnioWorker.java:243)
        at io.undertow.Undertow.start(Undertow.java:193)
        ... 6 more
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.008 s - in org.jboss.shamrock.example.test.JPAReflectionInGraalTestCase
[INFO] Running org.jboss.shamrock.example.test.ExternalIndexTestCase
18:38:51.068 [XNIO-1 task-7] DEBUG io.undertow.request.security - Attempting to authenticate /rest/shared, authentication required: false
18:38:51.068 [XNIO-1 task-7] DEBUG io.undertow.request.security - Authentication outcome was NOT_ATTEMPTED with method io.undertow.security.impl.CachedAuthenticatedSessionMechanism@33dad80d for /rest/shared
18:38:51.068 [XNIO-1 task-7] DEBUG io.undertow.request.security - Authentication result was ATTEMPTED for /rest/shared
18:38:51.069 [XNIO-1 task-7] DEBUG org.jboss.resteasy.resteasy_jaxrs.i18n - RESTEASY002315: PathInfo: /shared
construct(req,resp) public org.jboss.shamrock.example.shared.SharedResource()
CAN WE CDI? null
18:38:51.070 [XNIO-1 task-7] DEBUG org.jboss.resteasy.resteasy_jaxrs.i18n - MessageBodyWriter: org.jboss.resteasy.spi.ResteasyProviderFactory$SortedKey
18:38:51.070 [XNIO-1 task-7] DEBUG org.jboss.resteasy.resteasy_jaxrs.i18n - MessageBodyWriter: org.jboss.resteasy.plugins.providers.StringTextStar
18:38:51.070 [XNIO-1 task-7] DEBUG org.jboss.resteasy.resteasy_jaxrs.i18n - MessageBodyWriter: org.jboss.resteasy.plugins.providers.StringTextStar
18:38:51.070 [XNIO-1 task-7] DEBUG org.jboss.resteasy.resteasy_jaxrs.i18n - Interceptor Context: org.jboss.resteasy.core.interception.ServerWriterInterceptorContext,  Method : proceed
18:38:51.071 [XNIO-1 task-7] DEBUG org.jboss.resteasy.resteasy_jaxrs.i18n - MessageBodyWriter: org.jboss.resteasy.spi.ResteasyProviderFactory$SortedKey
18:38:51.071 [XNIO-1 task-7] DEBUG org.jboss.resteasy.resteasy_jaxrs.i18n - MessageBodyWriter: org.jboss.resteasy.plugins.providers.StringTextStar
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.011 s - in org.jboss.shamrock.example.test.ExternalIndexTestCase
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 9, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- shamrock-maven-plugin:1.0.0.Alpha1-SNAPSHOT:build (default) @ shamrock-strict-example ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.355 s
[INFO] Finished at: 2018-08-02T18:38:51+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jboss.shamrock:shamrock-maven-plugin:1.0.0.Alpha1-SNAPSHOT:build (default) on project shamrock-strict-example: Failed to run: [Artifact org.jboss.shamrock:shamrock-core-deployment:jar:1.0.0.Alpha1-SNAPSHOT:compile is a deployment artifact, however it does not have scope required. This will result in unnecessary jars being included in the final image, Artifact org.jboss.shamrock:shamrock-jpa-deployment:jar:1.0.0.Alpha1-SNAPSHOT:compile is a deployment artifact, however it does not have scope required. This will result in unnecessary jars being included in the final image] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
 

That makes me think the first test does not clean after itself.

Anyways, I'm a bit lost and any help would be appreciated @stuartwdouglas

*
* @author Emmanuel Bernard [email protected]
*/
@RunWith(ShamrockTest.class)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is running in JVM mode, so it does not really prove anything.

public class JPAReflectionInGraalTestCase {

@Test
public void testFieldAndGetterReflectionOnEntity() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is also run on the JVM (from the maven failsafe process).

If we want to be able to run unit tests like this in the native image then the GraalTest framework will need to somehow package up all the unit test code into a new test image. This should be possible, but I am not sure if it is worth worrying about for the Poc?

At the moment the graal based tests work via HTTP, so you send a HTTP request to the image and verify you get the correct result.

@emmanuelbernard
Copy link
Member Author

@Sanne you can try again, the tests should pass now.
We know have a test that makes sure entities are added to the closure whereas other ones are not.

@Sanne Sanne merged commit 989b4f0 into quarkusio:master Aug 3, 2018
@Sanne
Copy link
Member

Sanne commented Aug 3, 2018

merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants