From 572622489d529edd337c0f6501d0afabce85be0c Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Wed, 15 Aug 2018 22:21:04 +0300 Subject: [PATCH] [grid] Fixing configuration information in console servlet --- .../grid/internal/cli/GridHubCliOptions.java | 6 ++++ .../configuration/GridHubConfiguration.java | 7 +++++ .../web/servlet/console/ConsoleServlet.java | 28 +++++++++++++------ 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/java/server/src/org/openqa/grid/internal/cli/GridHubCliOptions.java b/java/server/src/org/openqa/grid/internal/cli/GridHubCliOptions.java index 4b214e9aaf698..aa896b4e11ab1 100644 --- a/java/server/src/org/openqa/grid/internal/cli/GridHubCliOptions.java +++ b/java/server/src/org/openqa/grid/internal/cli/GridHubCliOptions.java @@ -26,7 +26,10 @@ public class GridHubCliOptions extends CommonGridCliOptions { + private String[] rawArgs; + public JCommander parse(String... args) { + rawArgs = args; JCommander commander = JCommander.newBuilder().addObject(this).build(); commander.parse(args); return commander; @@ -111,4 +114,7 @@ public String getRegistry() { return registry; } + public String[] getRawArgs() { + return rawArgs; + } } diff --git a/java/server/src/org/openqa/grid/internal/utils/configuration/GridHubConfiguration.java b/java/server/src/org/openqa/grid/internal/utils/configuration/GridHubConfiguration.java index d208bd173c2eb..6215915abc608 100644 --- a/java/server/src/org/openqa/grid/internal/utils/configuration/GridHubConfiguration.java +++ b/java/server/src/org/openqa/grid/internal/utils/configuration/GridHubConfiguration.java @@ -75,6 +75,8 @@ public class GridHubConfiguration extends GridConfiguration { public String registry; + private GridHubCliOptions cliConfig; + /** * Creates a new configuration using the default values. */ @@ -96,6 +98,7 @@ public GridHubConfiguration(HubJsonConfiguration jsonConfig) { public GridHubConfiguration(GridHubCliOptions cliConfig) { this(ofNullable(cliConfig.getConfigFile()).map(HubJsonConfiguration::loadFromResourceOrFile) .orElse(DEFAULT_CONFIG_FROM_JSON)); + this.cliConfig = cliConfig; super.merge(cliConfig); ofNullable(cliConfig.getNewSessionWaitTimeout()).ifPresent(v -> newSessionWaitTimeout = v); ofNullable(cliConfig.getThrowOnCapabilityNotPresent()).ifPresent(v -> throwOnCapabilityNotPresent = v); @@ -191,4 +194,8 @@ public String toString(String format) { return sb.toString(); } + + public GridHubCliOptions getCliConfig() { + return cliConfig; + } } diff --git a/java/server/src/org/openqa/grid/web/servlet/console/ConsoleServlet.java b/java/server/src/org/openqa/grid/web/servlet/console/ConsoleServlet.java index 64d3e4973cb7c..3c0ac295abd56 100644 --- a/java/server/src/org/openqa/grid/web/servlet/console/ConsoleServlet.java +++ b/java/server/src/org/openqa/grid/web/servlet/console/ConsoleServlet.java @@ -28,10 +28,15 @@ import org.openqa.selenium.remote.DesiredCapabilities; import java.io.ByteArrayInputStream; +import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -215,20 +220,25 @@ private String getConfigInfo(boolean verbose) { builder.append(prettyHtmlPrint(config)); if (verbose) { - GridHubConfiguration tmp = new GridHubConfiguration(); - builder.append("Config details :
"); - builder.append("hub launched with :"); - builder.append(config.toString()); - - builder.append("
the final configuration comes from :
"); + builder.append("
The final configuration comes from:
"); builder.append("the default :
"); builder.append(prettyHtmlPrint(tmp)); - builder.append("
updated with params :
"); - tmp.merge(config); - builder.append(prettyHtmlPrint(tmp)); + if (config.getCliConfig() != null) { + builder.append("updated with command line options:
"); + builder.append(String.join(" ", config.getCliConfig().getRawArgs())); + + if (config.getCliConfig().getConfigFile() != null) { + builder.append("
and configuration loaded from ").append(config.getCliConfig().getConfigFile()).append(":
"); + try { + builder.append(String.join("
", Files.readAllLines(new File(config.getCliConfig().getConfigFile()).toPath()))); + } catch (IOException e) { + builder.append("").append(e.getMessage()).append(""); + } + } + } } builder.append(""); return builder.toString();