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

[MINOR] ux improvements #6049

Merged
merged 11 commits into from
Oct 19, 2023
2 changes: 2 additions & 0 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3555,6 +3555,8 @@ private String generateConfigurationOverview() {

builder.setTxPoolImplementation(buildTransactionPoolConfiguration().getTxPoolImplementation());

builder.setPluginContext(besuComponent.getBesuPluginContext());

return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -50,6 +51,7 @@ public class ConfigurationOverviewBuilder {
private boolean isHighSpec = false;
private TransactionPoolConfiguration.Implementation txPoolImplementation;
private Map<String, String> environment;
private BesuPluginContextImpl besuPluginContext;

/**
* @param logger the logger
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -308,4 +316,13 @@ private void detectJemalloc(final List<String> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 + "]");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,6 +75,7 @@ private enum Lifecycle {
private final Map<Class<?>, ? super BesuService> serviceRegistry = new HashMap<>();
private final List<BesuPlugin> plugins = new ArrayList<>();
private final List<String> pluginVersions = new ArrayList<>();
final List<String> lines = new ArrayList<>();

/**
* Add service.
Expand Down Expand Up @@ -105,9 +105,7 @@ public <T extends BesuService> Optional<T> getService(final Class<T> serviceType
* @param pluginsDir the plugins dir
*/
public void registerPlugins(final Path pluginsDir) {
final List<String> 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.");
Expand All @@ -120,11 +118,13 @@ public void registerPlugins(final Path pluginsDir) {
final ServiceLoader<BesuPlugin> 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(
Expand All @@ -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<String> getPluginsSummaryLog() {
return lines;
}

private void addPluginVersion(final BesuPlugin plugin) {
final Package pluginPackage = plugin.getClass().getPackage();
final String implTitle =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Function<PluginRpcRequest, ?>> rpcMethods = new HashMap<>();

Expand Down