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

Wait for jboss-modules to set module.path property #39

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 33 additions & 32 deletions src/main/java/com/redhat/insights/agent/AgentSubreport.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.function.Function;

public class AgentSubreport implements InsightsSubreport {
private static final long POLL_PROPERTY_TIMEOUT_MS = 10000L;
private static final InsightsLogger logger = AgentLogger.getLogger();

private static final Class<?>[] EMPTY_CLASS_ARRAY = new Class[0];
Expand Down Expand Up @@ -124,47 +125,47 @@ static String fingerprintJBoss(Class<?> moduleClass) {
try {
Method getBootModuleLoaderMethod =
getModuleClass().getDeclaredMethod("getBootModuleLoader", EMPTY_CLASS_ARRAY);
Object moduleLoader = getBootModuleLoaderMethod.invoke(null, EMPTY_OBJECT_ARRAY);
ClassLoader versionModuleClassLoader =
getModuleClassLoader(moduleLoader, "org.jboss.as.version");
String home = getJBossHome();
Class<?> moduleLoaderClass = getJBossModuleLoaderClass(moduleLoader.getClass());
Class<?> productConfigClass =
versionModuleClassLoader.loadClass("org.jboss.as.version.ProductConfig");
Method fromFilesystemSlotMethod =
productConfigClass.getDeclaredMethod(
"fromFilesystemSlot", moduleLoaderClass, String.class, Map.class);
Object productConfig =
fromFilesystemSlotMethod.invoke(
null, moduleLoaderClass.cast(moduleLoader), home, getPropertiesPrivileged());
return (String)
productConfigClass
.getDeclaredMethod("getPrettyVersionString", EMPTY_CLASS_ARRAY)
.invoke(productConfig, EMPTY_OBJECT_ARRAY);

} catch (NoSuchMethodException
| SecurityException
| ClassNotFoundException
| IllegalAccessException
| IllegalArgumentException
| InvocationTargetException ex) {
// ignore
// Wait until JBoss Modules initializes to avoid breaking their module loader
String modulePath = pollProperty("module.path");
if (modulePath == null) {
logger.debug("Module path did not become available");
} else {
Object moduleLoader = getBootModuleLoaderMethod.invoke(null, EMPTY_OBJECT_ARRAY);
ClassLoader versionModuleClassLoader =
getModuleClassLoader(moduleLoader, "org.jboss.as.version");
String home = pollProperty("jboss.home.dir");
Class<?> moduleLoaderClass = getJBossModuleLoaderClass(moduleLoader.getClass());
Class<?> productConfigClass =
versionModuleClassLoader.loadClass("org.jboss.as.version.ProductConfig");
Method fromFilesystemSlotMethod =
productConfigClass.getDeclaredMethod(
"fromFilesystemSlot", moduleLoaderClass, String.class, Map.class);
Object productConfig =
fromFilesystemSlotMethod.invoke(
null, moduleLoaderClass.cast(moduleLoader), home, getPropertiesPrivileged());
return (String)
productConfigClass
.getDeclaredMethod("getPrettyVersionString", EMPTY_CLASS_ARRAY)
.invoke(productConfig, EMPTY_OBJECT_ARRAY);
}
} catch (Exception ex) {
logger.debug("Ignoring exception during JBoss probe", ex);
}
return "Unknown EAP / Wildfly - possibly misconfigured";
}

private static String getJBossHome() {
long timeout = System.currentTimeMillis() + 3000L;
String home = getPropertyPrivileged("jboss.home.dir", null);
while (home == null && System.currentTimeMillis() < timeout) {
private static String pollProperty(String property) {
long timeout = System.currentTimeMillis() + POLL_PROPERTY_TIMEOUT_MS;
String value = getPropertyPrivileged(property, null);
while (value == null && System.currentTimeMillis() < timeout) {
try {
Thread.sleep(200);
home = getPropertyPrivileged("jboss.home.dir", null);
value = getPropertyPrivileged(property, null);
} catch (InterruptedException ex) {
return home;
return value;
}
}
return home;
return value;
}

private static String getPropertyPrivileged(final String property, final String defaultValue) {
Expand Down