mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 16:23:12 +09:00
Add instance config event for master plugins
Add onInstanceConfigFieldChanged hook for master plugin code which triggers when instance configs are changed on the master server.
This commit is contained in:
1 parent
8b857224dc
commit
322570f298
4 files changed
+28
-1
No files matched your search
@@ -286,6 +286,20 @@ class BaseMasterPlugin {
|
|||||||
*/
|
*/
|
||||||
async onInstanceStatusChanged(instance, prev) { }
|
async onInstanceStatusChanged(instance, prev) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the value of an instance config field changed.
|
||||||
|
*
|
||||||
|
* Invoked after the value of the config field given by `field` has
|
||||||
|
* changed on an instance.
|
||||||
|
*
|
||||||
|
* @param {Object} instance - The instance the config changed on.
|
||||||
|
* @param {module:lib/config.ConfigGroup} group -
|
||||||
|
* The group who's field got changed on.
|
||||||
|
* @param {string} field - Name of the field that changed.
|
||||||
|
* @param {*} prev - The previous value of the field.
|
||||||
|
*/
|
||||||
|
async onInstanceConfigFieldChanged(instance, group, field, prev) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called before collecting Prometheus metrics
|
* Called before collecting Prometheus metrics
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -174,6 +174,7 @@ class ControlConnection extends BaseConnection {
|
|||||||
let instance = { config: instanceConfig, status: "unassigned" };
|
let instance = { config: instanceConfig, status: "unassigned" };
|
||||||
this._master.instances.set(instanceId, instance);
|
this._master.instances.set(instanceId, instance);
|
||||||
await libPlugin.invokeHook(this._master.plugins, "onInstanceStatusChanged", instance, null);
|
await libPlugin.invokeHook(this._master.plugins, "onInstanceStatusChanged", instance, null);
|
||||||
|
this._master.addInstancePluginHooks(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteInstanceRequestHandler(message, request) {
|
async deleteInstanceRequestHandler(message, request) {
|
||||||
|
|||||||
@@ -151,6 +151,10 @@ class Master {
|
|||||||
this.userManager = new UserManager(this.config);
|
this.userManager = new UserManager(this.config);
|
||||||
await this.userManager.load(path.join(databaseDirectory, "users.json"));
|
await this.userManager.load(path.join(databaseDirectory, "users.json"));
|
||||||
|
|
||||||
|
for (let instance of this.instances.values()) {
|
||||||
|
this.addInstancePluginHooks(instance);
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure we're actually going to listen on a port
|
// Make sure we're actually going to listen on a port
|
||||||
let httpPort = this.config.get("master.http_port");
|
let httpPort = this.config.get("master.http_port");
|
||||||
let httpsPort = this.config.get("master.https_port");
|
let httpsPort = this.config.get("master.https_port");
|
||||||
@@ -305,7 +309,8 @@ class Master {
|
|||||||
let instanceConfig = new libConfig.InstanceConfig("master");
|
let instanceConfig = new libConfig.InstanceConfig("master");
|
||||||
await instanceConfig.load(serializedConfig);
|
await instanceConfig.load(serializedConfig);
|
||||||
let status = instanceConfig.get("instance.assigned_slave") === null ? "unassigned" : "unknown";
|
let status = instanceConfig.get("instance.assigned_slave") === null ? "unassigned" : "unknown";
|
||||||
instances.set(instanceConfig.get("instance.id"), { config: instanceConfig, status });
|
let instance = { config: instanceConfig, status };
|
||||||
|
instances.set(instanceConfig.get("instance.id"), instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -356,6 +361,12 @@ class Master {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addInstancePluginHooks(instance) {
|
||||||
|
instance.config.on("fieldChanged", (group, field, prev) => {
|
||||||
|
libPlugin.invokeHook(this.plugins, "onInstanceConfigFieldChanged", instance, group, field, prev);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async loadPlugins() {
|
async loadPlugins() {
|
||||||
for (let pluginInfo of this.pluginInfos) {
|
for (let pluginInfo of this.pluginInfos) {
|
||||||
if (!this.config.group(pluginInfo.name).get("load_plugin")) {
|
if (!this.config.group(pluginInfo.name).get("load_plugin")) {
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ class SlaveConnection extends BaseConnection {
|
|||||||
instanceConfig.set("instance.assigned_slave", this._id);
|
instanceConfig.set("instance.assigned_slave", this._id);
|
||||||
let newInstance = { config: instanceConfig, status: instanceData.status };
|
let newInstance = { config: instanceConfig, status: instanceData.status };
|
||||||
this._master.instances.set(instanceConfig.get("instance.id"), newInstance);
|
this._master.instances.set(instanceConfig.get("instance.id"), newInstance);
|
||||||
|
this._master.addInstancePluginHooks(newInstance);
|
||||||
await libLink.messages.assignInstance.send(this, {
|
await libLink.messages.assignInstance.send(this, {
|
||||||
instance_id: instanceConfig.get("instance.id"),
|
instance_id: instanceConfig.get("instance.id"),
|
||||||
serialized_config: instanceConfig.serialize("slave"),
|
serialized_config: instanceConfig.serialize("slave"),
|
||||||
|
|||||||
Reference in new issue
Block a user