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

Artemis command to create broker instance uses correct JAVA_HOME #125

Conversation

herbertkb
Copy link
Contributor

@herbertkb herbertkb commented Jun 3, 2024

see https://issues.redhat.com/browse/AMWSUP-21

Given a VM where Java 8 is still the installed version of Java

When the amq_broker role is executed, the deployment fails. The task to run the artemis create command to create the broker instance fails because artemis was compiled with a more recent version of Java than Java8 can execute.

fatal: [192.168.122.70]: FAILED! => {"changed": true, "cmd": ["/opt/amq/apache-artemis-2.32.0/bin/artemis", "create", "/opt/amq/amq-broker", "--name", "amq-broker", "--require-login", "--user", "amq-broker", "--password", "amq-broker", "--host", "localhost", "--http-host", "0.0.0.0", "--http-port", "8161", "--no-autocreate", "--queues", "queue.in,queue.out", "--data", "/opt/amq/amq-broker/data"], "delta": "0:00:00.069105", "end": "2024-06-03 11:03:47.131194", "msg": "non-zero return code", "rc": 1, "start": "2024-06-03 11:03:47.062089", "stderr": "Error: A JNI error has occurred, please check your installation and try again\nException in thread \"main\" java.lang.UnsupportedClassVersionError: org/apache/activemq/artemis/boot/Artemis has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0\n\tat java.lang.ClassLoader.defineClass1(Native Method)\n\tat java.lang.ClassLoader.defineClass(ClassLoader.java:756)\n\tat java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)\n\tat java.net.URLClassLoader.defineClass(URLClassLoader.java:473)\n\tat java.net.URLClassLoader.access$100(URLClassLoader.java:74)\n\tat java.net.URLClassLoader$1.run(URLClassLoader.java:369)\n\tat java.net.URLClassLoader$1.run(URLClassLoader.java:363)\n\tat java.security.AccessController.doPrivileged(Native Method)\n\tat java.net.URLClassLoader.findClass(URLClassLoader.java:362)\n\tat java.lang.ClassLoader.loadClass(ClassLoader.java:418)\n\tat sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)\n\tat java.lang.ClassLoader.loadClass(ClassLoader.java:351)\n\tat sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)", "stderr_lines": ["Error: A JNI error has occurred, please check your installation and try again", "Exception in thread \"main\" java.lang.UnsupportedClassVersionError: org/apache/activemq/artemis/boot/Artemis has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0", "\tat java.lang.ClassLoader.defineClass1(Native Method)", "\tat java.lang.ClassLoader.defineClass(ClassLoader.java:756)", "\tat java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)", "\tat java.net.URLClassLoader.defineClass(URLClassLoader.java:473)", "\tat java.net.URLClassLoader.access$100(URLClassLoader.java:74)", "\tat java.net.URLClassLoader$1.run(URLClassLoader.java:369)", "\tat java.net.URLClassLoader$1.run(URLClassLoader.java:363)", "\tat java.security.AccessController.doPrivileged(Native Method)", "\tat java.net.URLClassLoader.findClass(URLClassLoader.java:362)", "\tat java.lang.ClassLoader.loadClass(ClassLoader.java:418)", "\tat sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)", "\tat java.lang.ClassLoader.loadClass(ClassLoader.java:351)", "\tat sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)"], "stdout": "", "stdout_lines": []}

Solution: set the JAVA_HOME envvar to match amq_broker_jvm_package.

Copy link
Member

@guidograzioli guidograzioli left a comment

Choose a reason for hiding this comment

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

Good catch!
environment here is a dictionary, not a list (and while you are here, can you please also set the PATH, like in here: https://github.com/ansible-middleware/keycloak/pull/211/files#diff-9c8ae367389a73fbea8f6569f448840c4ef96621d629804053473acf5ccf7547R6 )
Full interpolation of the JAVA_HOME also is here: https://github.com/ansible-middleware/amq/blob/main/roles/activemq/templates/amq_broker.sysconfig.j2#L3C1-L3C76

@guidograzioli guidograzioli added the bugfixes Fixes that resolve issues. SHOULD not be used for minor enhancements label Jun 3, 2024
@herbertkb
Copy link
Contributor Author

Good catch! environment here is a dictionary, not a list (and while you are here, can you please also set the PATH, like in here: https://github.com/ansible-middleware/keycloak/pull/211/files#diff-9c8ae367389a73fbea8f6569f448840c4ef96621d629804053473acf5ccf7547R6 )

Ah, that would explain why VSCode was highlighting it in red after I copied it over from my client laptop. Strange that it didn't complain there.

@herbertkb
Copy link
Contributor Author

herbertkb commented Jun 3, 2024

added PATH

    PATH: "{{ activemq_java_home  | default(activemq_rpm_java_home, true) }}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

@guidograzioli
Copy link
Member

added PATH

    PATH: "{{ activemq_java_home  | default(activemq_rpm_java_home, true) }}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

Thanks; sorry but activemq_rpm_java_home is not defined for this task; you'll need to use rpm_java_home (for which a set_fact exists at the top of systemd.yml)

@herbertkb
Copy link
Contributor Author

herbertkb commented Jun 3, 2024

fixed, and tested on a local VM. (Should have put together a local testing flow before opening the PR.)

Copy link
Member

@guidograzioli guidograzioli left a comment

Choose a reason for hiding this comment

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

LGTM

@guidograzioli
Copy link
Member

Merging; I'll have to reword the title and first comment a little (they are used/linked from the changelog)

@guidograzioli guidograzioli changed the title set JAVA_HOME when executing artemis command to create broker instance. Artemis command to create broker instance uses correct JAVA_HOME Jun 3, 2024
@guidograzioli guidograzioli merged commit 43285cd into ansible-middleware:main Jun 3, 2024
16 checks passed
@herbertkb herbertkb deleted the fix/javahome_for_artemis_create branch June 3, 2024 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfixes Fixes that resolve issues. SHOULD not be used for minor enhancements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants