From 8771e41b0386c1846f0c1407a4b29ea1d6dba77f Mon Sep 17 00:00:00 2001 From: "James R. Perkins" Date: Mon, 9 Sep 2024 13:31:52 -0700 Subject: [PATCH] [WFMP-244] Allow the known management configuration system properties jboss.management.http.port, jboss.management.https.port, jboss.socket.binding.port-offset and jboss.bind.address.management to allow overriding client connections. Signed-off-by: James R. Perkins --- .../plugin/cli/ExecuteCommandsMojo.java | 32 +++++++++++++++++++ .../common/AbstractServerConnection.java | 12 +++++-- .../plugin/server/AbstractStartMojo.java | 32 +++++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/java/org/wildfly/plugin/cli/ExecuteCommandsMojo.java b/plugin/src/main/java/org/wildfly/plugin/cli/ExecuteCommandsMojo.java index 02c0b39d..6fe5d967 100644 --- a/plugin/src/main/java/org/wildfly/plugin/cli/ExecuteCommandsMojo.java +++ b/plugin/src/main/java/org/wildfly/plugin/cli/ExecuteCommandsMojo.java @@ -268,6 +268,38 @@ public void execute() throws MojoExecutionException, MojoFailureException { } } + @Override + protected int getManagementPort() { + // Check the java-opts for a management port override + if (javaOpts != null) { + for (String opt : javaOpts) { + if (opt.startsWith("-Djboss.management.http.port=") || opt.startsWith("-Djboss.management.https.port=")) { + final int equals = opt.indexOf('='); + return Integer.parseInt(opt.substring(equals + 1).trim()); + } + if (opt.startsWith("-Djboss.socket.binding.port-offset=")) { + final int equals = opt.indexOf('='); + return super.getManagementPort() + Integer.parseInt(opt.substring(equals + 1).trim()); + } + } + } + return super.getManagementPort(); + } + + @Override + protected String getManagementHostName() { + // Check the java-opts for a management port override + if (javaOpts != null) { + for (String opt : javaOpts) { + if (opt.startsWith("-Djboss.bind.address.management=")) { + final int equals = opt.indexOf('='); + return opt.substring(equals + 1).trim(); + } + } + } + return super.getManagementHostName(); + } + /** * Allows the {@link #javaOpts} to be set as a string. The string is assumed to be space delimited. * diff --git a/plugin/src/main/java/org/wildfly/plugin/common/AbstractServerConnection.java b/plugin/src/main/java/org/wildfly/plugin/common/AbstractServerConnection.java index c05cd4e5..e9adf24b 100644 --- a/plugin/src/main/java/org/wildfly/plugin/common/AbstractServerConnection.java +++ b/plugin/src/main/java/org/wildfly/plugin/common/AbstractServerConnection.java @@ -162,8 +162,8 @@ protected synchronized MavenModelControllerClientConfiguration getClientConfigur } final ModelControllerClientConfiguration.Builder builder = new ModelControllerClientConfiguration.Builder() .setProtocol(protocol) - .setHostName(hostname) - .setPort(port) + .setHostName(getManagementHostName()) + .setPort(getManagementPort()) .setConnectionTimeout(timeout * 1000); if (authenticationConfig != null) { try { @@ -175,6 +175,14 @@ protected synchronized MavenModelControllerClientConfiguration getClientConfigur return new MavenModelControllerClientConfiguration(builder.build(), username, password); } + protected int getManagementPort() { + return port; + } + + protected String getManagementHostName() { + return hostname; + } + private String decrypt(final Server server) { SettingsDecryptionResult decrypt = settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(server)); return decrypt.getServer().getPassword(); diff --git a/plugin/src/main/java/org/wildfly/plugin/server/AbstractStartMojo.java b/plugin/src/main/java/org/wildfly/plugin/server/AbstractStartMojo.java index 292c40a8..da75c5ca 100644 --- a/plugin/src/main/java/org/wildfly/plugin/server/AbstractStartMojo.java +++ b/plugin/src/main/java/org/wildfly/plugin/server/AbstractStartMojo.java @@ -273,4 +273,36 @@ protected ServerContext actOnServerState(final ModelControllerClient client, fin } return context; } + + @Override + protected int getManagementPort() { + // Check the java-opts for a management port override + if (javaOpts != null) { + for (String opt : javaOpts) { + if (opt.startsWith("-Djboss.management.http.port=") || opt.startsWith("-Djboss.management.https.port=")) { + final int equals = opt.indexOf('='); + return Integer.parseInt(opt.substring(equals + 1).trim()); + } + if (opt.startsWith("-Djboss.socket.binding.port-offset=")) { + final int equals = opt.indexOf('='); + return super.getManagementPort() + Integer.parseInt(opt.substring(equals + 1).trim()); + } + } + } + return super.getManagementPort(); + } + + @Override + protected String getManagementHostName() { + // Check the java-opts for a management port override + if (javaOpts != null) { + for (String opt : javaOpts) { + if (opt.startsWith("-Djboss.bind.address.management=")) { + final int equals = opt.indexOf('='); + return opt.substring(equals + 1).trim(); + } + } + } + return super.getManagementHostName(); + } }