diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index 47463d2c997..d7ce4dfa539 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -3555,6 +3555,8 @@ private String generateConfigurationOverview() { builder.setTxPoolImplementation(buildTransactionPoolConfiguration().getTxPoolImplementation()); + builder.setPluginContext(besuComponent.getBesuPluginContext()); + return builder.build(); } } diff --git a/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java b/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java index e017caa9ddf..508b195a8eb 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java @@ -16,6 +16,7 @@ import org.hyperledger.besu.BesuInfo; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; +import org.hyperledger.besu.services.BesuPluginContextImpl; import org.hyperledger.besu.util.log.FramedLogMessage; import org.hyperledger.besu.util.platform.PlatformDetector; @@ -50,6 +51,7 @@ public class ConfigurationOverviewBuilder { private boolean isHighSpec = false; private TransactionPoolConfiguration.Implementation txPoolImplementation; private Map environment; + private BesuPluginContextImpl besuPluginContext; /** * @param logger the logger @@ -277,6 +279,12 @@ public String build() { lines.add("Total memory: " + normalizeSize(hardwareInfo.getMemory().getTotal())); lines.add("CPU cores: " + hardwareInfo.getProcessor().getLogicalProcessorCount()); + lines.add(""); + + if (besuPluginContext != null) { + lines.addAll(besuPluginContext.getPluginsSummaryLog()); + } + return FramedLogMessage.generate(lines); } @@ -308,4 +316,13 @@ private void detectJemalloc(final List lines) { private String normalizeSize(final long size) { return String.format("%.02f", (double) (size) / 1024 / 1024 / 1024) + " GB"; } + + /** + * set the plugin context + * + * @param besuPluginContext the plugin context + */ + public void setPluginContext(final BesuPluginContextImpl besuPluginContext) { + this.besuPluginContext = besuPluginContext; + } } diff --git a/besu/src/main/java/org/hyperledger/besu/cli/util/CommandLineUtils.java b/besu/src/main/java/org/hyperledger/besu/cli/util/CommandLineUtils.java index 0115420005e..a44e616bd3d 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/util/CommandLineUtils.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/util/CommandLineUtils.java @@ -110,7 +110,7 @@ public static void checkMultiOptionDependencies( } /** - * Fail if option doesnt meet requirement. + * Fail if option doesn't meet requirement. * * @param commandLine the command line * @param errorMessage the error message @@ -126,7 +126,8 @@ public static void failIfOptionDoesntMeetRequirement( final String affectedOptions = getAffectedOptions(commandLine, dependentOptionsNames); if (!affectedOptions.isEmpty()) { - throw new CommandLine.ParameterException(commandLine, errorMessage); + throw new CommandLine.ParameterException( + commandLine, errorMessage + " [" + affectedOptions + "]"); } } } diff --git a/besu/src/main/java/org/hyperledger/besu/services/BesuPluginContextImpl.java b/besu/src/main/java/org/hyperledger/besu/services/BesuPluginContextImpl.java index 0a0f5019a52..184c85f45de 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/BesuPluginContextImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/BesuPluginContextImpl.java @@ -21,7 +21,6 @@ import org.hyperledger.besu.plugin.BesuPlugin; import org.hyperledger.besu.plugin.services.BesuService; import org.hyperledger.besu.plugin.services.PluginVersionsProvider; -import org.hyperledger.besu.util.log.FramedLogMessage; import java.io.IOException; import java.net.MalformedURLException; @@ -76,6 +75,7 @@ private enum Lifecycle { private final Map, ? super BesuService> serviceRegistry = new HashMap<>(); private final List plugins = new ArrayList<>(); private final List pluginVersions = new ArrayList<>(); + final List lines = new ArrayList<>(); /** * Add service. @@ -105,9 +105,7 @@ public Optional getService(final Class serviceType * @param pluginsDir the plugins dir */ public void registerPlugins(final Path pluginsDir) { - final List lines = new ArrayList<>(); - lines.add("plugins dir " + pluginsDir.toAbsolutePath()); - lines.add(""); + lines.add("Plugins:"); checkState( state == Lifecycle.UNINITIALIZED, "Besu plugins have already been registered. Cannot register additional plugins."); @@ -120,11 +118,13 @@ public void registerPlugins(final Path pluginsDir) { final ServiceLoader serviceLoader = ServiceLoader.load(BesuPlugin.class, pluginLoader); + int pluginsCount = 0; for (final BesuPlugin plugin : serviceLoader) { + pluginsCount++; try { plugin.register(this); LOG.info("Registered plugin of type {}.", plugin.getClass().getName()); - lines.add(String.format("SUCCESS %s", plugin.getClass().getSimpleName())); + lines.add(String.format(plugin.getClass().getSimpleName())); addPluginVersion(plugin); } catch (final Exception e) { LOG.error( @@ -139,13 +139,23 @@ public void registerPlugins(final Path pluginsDir) { } LOG.debug("Plugin registration complete."); - lines.add(""); - lines.add("TOTAL = " + plugins.size()); - LOG.debug(FramedLogMessage.generate(lines)); + lines.add( + String.format( + "TOTAL = %d of %d plugins successfully loaded", plugins.size(), pluginsCount)); + lines.add(String.format("from %s", pluginsDir.toAbsolutePath())); state = Lifecycle.REGISTERED; } + /** + * get the summary log, as a list of string lines + * + * @return the summary + */ + public List getPluginsSummaryLog() { + return lines; + } + private void addPluginVersion(final BesuPlugin plugin) { final Package pluginPackage = plugin.getClass().getPackage(); final String implTitle = diff --git a/besu/src/main/java/org/hyperledger/besu/services/RpcEndpointServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/RpcEndpointServiceImpl.java index 4513bf0bf39..94bb5560839 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/RpcEndpointServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/RpcEndpointServiceImpl.java @@ -28,7 +28,7 @@ import java.util.function.Function; import java.util.stream.Collectors; -/** The Rpc endpoint service implementation. */ +/** The RPC endpoint service implementation. */ public class RpcEndpointServiceImpl implements RpcEndpointService { private final Map> rpcMethods = new HashMap<>();