ansible-middleware / amq

A collection to manage AMQ brokers
Apache License 2.0
13 stars 11 forks source link

Artemis command to create broker instance uses correct JAVA_HOME #125

Closed herbertkb closed 1 month ago

herbertkb commented 1 month ago

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.

herbertkb commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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

guidograzioli commented 1 month ago

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