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

Force besu to stop on plugin initialization errors #7662

Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- k8s (KUBERNETES) Nat method is now deprecated and will be removed in a future release

### Breaking Changes
- Besu will now fail to start if any plugins encounter errors during initialization. To allow Besu to continue running despite plugin errors, use the `--plugin-continue-on-error` option. [#7662](https://github.com/hyperledger/besu/pull/7662)

### Additions and Improvements
- Remove privacy test classes support [#7569](https://github.com/hyperledger/besu/pull/7569)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,9 @@ public BesuPluginContextImpl providePluginContext(
besuPluginContext.addService(PermissioningService.class, permissioningService);
besuPluginContext.addService(PrivacyPluginService.class, new PrivacyPluginServiceImpl());

besuPluginContext.registerPlugins(
besuPluginContext.initialize(
new PluginConfiguration.Builder().pluginsDir(pluginsPath).build());
besuPluginContext.registerPlugins();
commandLine.parseArgs(extraCLIOptions.toArray(new String[0]));

// register built-in plugins
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright ConsenSys AG.
* Copyright contributors to Hyperledger Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -32,16 +32,25 @@
public class TestPicoCLIPlugin implements BesuPlugin {
private static final Logger LOG = LoggerFactory.getLogger(TestPicoCLIPlugin.class);

private static final String UNSET = "UNSET";
private static final String FAIL_REGISTER = "FAILREGISTER";
private static final String FAIL_BEFORE_EXTERNAL_SERVICES = "FAILBEFOREEXTERNALSERVICES";
private static final String FAIL_START = "FAILSTART";
private static final String FAIL_AFTER_EXTERNAL_SERVICE_POST_MAIN_LOOP =
"FAILAFTEREXTERNALSERVICEPOSTMAINLOOP";
private static final String FAIL_STOP = "FAILSTOP";
private static final String PLUGIN_LIFECYCLE_PREFIX = "pluginLifecycle.";

@Option(
names = {"--Xplugin-test-option"},
hidden = true,
defaultValue = "UNSET")
defaultValue = UNSET)
String testOption = System.getProperty("testPicoCLIPlugin.testOption");

@Option(
names = {"--plugin-test-stable-option"},
hidden = true,
defaultValue = "UNSET")
defaultValue = UNSET)
String stableOption = "";

private String state = "uninited";
Expand All @@ -52,7 +61,7 @@ public void register(final BesuContext context) {
LOG.info("Registering. Test Option is '{}'", testOption);
state = "registering";

if ("FAILREGISTER".equals(testOption)) {
if (FAIL_REGISTER.equals(testOption)) {
state = "failregister";
throw new RuntimeException("I was told to fail at registration");
}
Expand All @@ -66,12 +75,26 @@ public void register(final BesuContext context) {
state = "registered";
}

@Override
public void beforeExternalServices() {
LOG.info("Before external services. Test Option is '{}'", testOption);
state = "beforeExternalServices";

if (FAIL_BEFORE_EXTERNAL_SERVICES.equals(testOption)) {
state = "failbeforeExternalServices";
throw new RuntimeException("I was told to fail before external services");
}

writeSignal("beforeExternalServices");
state = "beforeExternalServicesFinished";
}

@Override
public void start() {
LOG.info("Starting. Test Option is '{}'", testOption);
state = "starting";

if ("FAILSTART".equals(testOption)) {
if (FAIL_START.equals(testOption)) {
state = "failstart";
throw new RuntimeException("I was told to fail at startup");
}
Expand All @@ -80,12 +103,26 @@ public void start() {
state = "started";
}

@Override
public void afterExternalServicePostMainLoop() {
LOG.info("After external services post main loop. Test Option is '{}'", testOption);
state = "afterExternalServicePostMainLoop";

if (FAIL_AFTER_EXTERNAL_SERVICE_POST_MAIN_LOOP.equals(testOption)) {
state = "failafterExternalServicePostMainLoop";
throw new RuntimeException("I was told to fail after external services post main loop");
}

writeSignal("afterExternalServicePostMainLoop");
state = "afterExternalServicePostMainLoopFinished";
}

@Override
public void stop() {
LOG.info("Stopping. Test Option is '{}'", testOption);
state = "stopping";

if ("FAILSTOP".equals(testOption)) {
if (FAIL_STOP.equals(testOption)) {
state = "failstop";
throw new RuntimeException("I was told to fail at stop");
}
Expand All @@ -103,7 +140,7 @@ public String getState() {
@SuppressWarnings("ResultOfMethodCallIgnored")
private void writeSignal(final String signal) {
try {
final File callbackFile = new File(callbackDir, "pluginLifecycle." + signal);
final File callbackFile = new File(callbackDir, PLUGIN_LIFECYCLE_PREFIX + signal);
if (!callbackFile.getParentFile().exists()) {
callbackFile.getParentFile().mkdirs();
callbackFile.getParentFile().deleteOnExit();
Expand Down
Loading
Loading