-
Notifications
You must be signed in to change notification settings - Fork 863
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a dynamic reload mechanism for Besu plugins. (#261)
* Implement a dynamic reload mechanism for Besu plugins. - Added `reloadConfiguration` method in `plugin-api`. - Added `admin_reloadPlugin` RPC endpoint. - if the first parameter is specified the API will attempt to reload the individual plugin if found in the map. - if no parameter is specified the API will attempt to reload all plugins. - Added method in `BesuPluginContextImpl` to retrieve a map of named plugins. Signed-off-by: Abdelhamid Bakhta <[email protected]>
- Loading branch information
1 parent
6e67988
commit 94b26dd
Showing
20 changed files
with
211 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...rg/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/PluginsReloadConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright ConsenSys AG. | ||
* | ||
* 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods; | ||
|
||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; | ||
import org.hyperledger.besu.plugin.BesuPlugin; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public class PluginsReloadConfiguration implements JsonRpcMethod { | ||
|
||
private static final Logger LOG = LogManager.getLogger(); | ||
private final Map<String, BesuPlugin> namedPlugins; | ||
|
||
public PluginsReloadConfiguration(final Map<String, BesuPlugin> namedPlugins) { | ||
this.namedPlugins = namedPlugins; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return RpcMethod.PLUGINS_RELOAD_CONFIG.getMethodName(); | ||
} | ||
|
||
@Override | ||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { | ||
try { | ||
final String pluginName = requestContext.getRequiredParameter(0, String.class); | ||
if (!namedPlugins.containsKey(pluginName)) { | ||
LOG.error( | ||
"Plugin cannot be reloaded because no plugin has been registered with specified name: {}.", | ||
pluginName); | ||
return new JsonRpcErrorResponse( | ||
requestContext.getRequest().getId(), JsonRpcError.INTERNAL_ERROR); | ||
} | ||
reloadPluginConfig(namedPlugins.get(pluginName)); | ||
return new JsonRpcSuccessResponse(requestContext.getRequest().getId()); | ||
} catch (InvalidJsonRpcParameters invalidJsonRpcParameters) { | ||
return new JsonRpcErrorResponse( | ||
requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS); | ||
} | ||
} | ||
|
||
private void reloadPluginConfig(final BesuPlugin plugin) { | ||
final String name = plugin.getName().orElseThrow(); | ||
LOG.info("Reloading plugin configuration: {}.", name); | ||
final CompletableFuture<Void> future = plugin.reloadConfiguration(); | ||
future.thenAcceptAsync(aVoid -> LOG.info("Plugin {} has been reloaded.", name)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...rc/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PluginsJsonRpcMethods.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright ConsenSys AG. | ||
* | ||
* 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.ethereum.api.jsonrpc.methods; | ||
|
||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.PluginsReloadConfiguration; | ||
import org.hyperledger.besu.plugin.BesuPlugin; | ||
|
||
import java.util.Map; | ||
|
||
public class PluginsJsonRpcMethods extends ApiGroupJsonRpcMethods { | ||
|
||
private final Map<String, BesuPlugin> namedPlugins; | ||
|
||
public PluginsJsonRpcMethods(final Map<String, BesuPlugin> namedPlugins) { | ||
this.namedPlugins = namedPlugins; | ||
} | ||
|
||
@Override | ||
protected RpcApi getApiGroup() { | ||
return RpcApis.PLUGINS; | ||
} | ||
|
||
@Override | ||
protected Map<String, JsonRpcMethod> create() { | ||
return mapOf(new PluginsReloadConfiguration(namedPlugins)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.