Rename Slave to Host

The role of a slave as a host for Factorio servers is not well reflected
in its name and has caused confusion among users.  Rename slave to host
to better reflect its role as a host of Factorio servers.
This commit is contained in:
Hornwitser committed 2023-02-22 15:30:51 +01:00
1 parent 70ad295a89
commit 6fc3abafd5
101 files changed
+1168 -1168

No files matched your search

+1 -1
View File
@@ -1,5 +1,5 @@
# Common Library for Clusterio
This package contains functionality shared between controller, slave, ctl and/or plugins of Clusterio.
This package contains functionality shared between controller, host, ctl and/or plugins of Clusterio.
See [the Clusterio repository](https://github.com/clusterio/clusterio) for more information on Clusterio.
+18 -18
View File
@@ -135,35 +135,35 @@ class CommandTree {
/**
* Resolve a string into a slave ID
* Resolve a string into a host ID
*
* Resolves a string with either an slave name or an id into an integer with
* the slave ID.
* Resolves a string with either an host name or an id into an integer with
* the host ID.
*
* @param {module:lib/link.Link} client - link to controller to query slave on.
* @param {string} slaveName - string with name or id of slave.
* @returns {Promise<number>} slave ID.
* @param {module:lib/link.Link} client - link to controller to query host on.
* @param {string} hostName - string with name or id of host.
* @returns {Promise<number>} host ID.
* @static
*/
async function resolveSlave(client, slaveName) {
let slaveId;
if (/^-?\d+$/.test(slaveName)) {
slaveId = parseInt(slaveName, 10);
async function resolveHost(client, hostName) {
let hostId;
if (/^-?\d+$/.test(hostName)) {
hostId = parseInt(hostName, 10);
} else {
let response = await libLink.messages.listSlaves.send(client);
for (let slave of response.list) {
if (slave.name === slaveName) {
slaveId = slave.id;
let response = await libLink.messages.listHosts.send(client);
for (let host of response.list) {
if (host.name === hostName) {
hostId = host.id;
break;
}
}
if (slaveId === undefined) {
throw new libErrors.CommandError(`No slave named ${slaveName}`);
if (hostId === undefined) {
throw new libErrors.CommandError(`No host named ${hostName}`);
}
}
return slaveId;
return hostId;
}
/**
@@ -275,7 +275,7 @@ module.exports = {
Command,
CommandTree,
resolveSlave,
resolveHost,
resolveInstance,
resolveModPack,
retrieveRole,
+34 -34
View File
@@ -10,7 +10,7 @@ const classes = require("./classes");
* @memberof module:lib/config
*/
class ControllerGroup extends classes.ConfigGroup { }
ControllerGroup.defaultAccess = ["controller", "slave", "control"];
ControllerGroup.defaultAccess = ["controller", "host", "control"];
ControllerGroup.groupName = "controller";
ControllerGroup.define({
name: "name",
@@ -110,7 +110,7 @@ ControllerGroup.define({
ControllerGroup.define({
name: "metrics_timeout",
title: "Metrics Timeout",
description: "Timeout in seconds for metrics gathering from slaves.",
description: "Timeout in seconds for metrics gathering from hosts.",
type: "number",
initial_value: 8,
});
@@ -148,95 +148,95 @@ ControllerConfig.registerGroup(ControllerGroup);
/**
* Slave config group for {@link module:lib/config.SlaveConfig}
* Host config group for {@link module:lib/config.HostConfig}
* @extends module:lib/config.ConfigGroup
* @memberof module:lib/config
*/
class SlaveGroup extends classes.ConfigGroup {}
SlaveGroup.defaultAccess = ["controller", "slave", "control"];
SlaveGroup.groupName = "slave";
SlaveGroup.define({
class HostGroup extends classes.ConfigGroup {}
HostGroup.defaultAccess = ["controller", "host", "control"];
HostGroup.groupName = "host";
HostGroup.define({
name: "name",
description: "Name of the slave",
description: "Name of the host",
type: "string",
initial_value: "New Slave",
initial_value: "New Host",
});
SlaveGroup.define({
HostGroup.define({
name: "id",
description: "ID of the slave",
description: "ID of the host",
type: "number",
initial_value: () => Math.random() * 2**31 | 0,
});
SlaveGroup.define({
HostGroup.define({
name: "factorio_directory",
description: "Path to directory to look for factorio installs",
type: "string",
initial_value: "factorio",
});
SlaveGroup.define({
HostGroup.define({
name: "mods_directory",
title: "Mods Directory",
description: "Path to directory where mods for instances are cached.",
type: "string",
initial_value: "mods",
});
SlaveGroup.define({
HostGroup.define({
name: "mods_directory_is_shared",
title: "Mods Directory is Shared",
description: "True if the mods directory is shared with the controller.",
type: "boolean",
initial_value: true,
});
SlaveGroup.define({
HostGroup.define({
name: "instances_directory",
description: "Path to directory to store instances in.",
restartRequired: true,
type: "string",
initial_value: "instances",
});
SlaveGroup.define({
HostGroup.define({
name: "controller_url",
description: "URL to connect to the controller at",
restartRequired: true,
type: "string",
initial_value: "http://localhost:8080/",
});
SlaveGroup.define({
HostGroup.define({
name: "controller_token",
description: "Token to authenticate to controller with.",
restartRequired: true,
type: "string",
initial_value: "enter token here",
});
SlaveGroup.define({
HostGroup.define({
name: "tls_ca",
description: "Path to Certificate Authority to validate TLS connection to controller against.",
restartRequired: true,
type: "string",
optional: true,
});
SlaveGroup.define({
HostGroup.define({
name: "public_address",
description: "Public facing address players should connect to in order to join instances on this slave",
description: "Public facing address players should connect to in order to join instances on this host",
type: "string",
initial_value: "localhost",
});
SlaveGroup.define({
HostGroup.define({
name: "max_reconnect_delay",
title: "Max Reconnect Delay",
description: "Maximum delay to wait before attempting to reconnect WebSocket",
type: "number",
initial_value: 60,
});
SlaveGroup.finalize();
HostGroup.finalize();
/**
* Slave Config class
* Host Config class
* @extends module:lib/config.Config
* @memberof module:lib/config
*/
class SlaveConfig extends classes.Config { }
SlaveConfig.registerGroup(SlaveGroup);
class HostConfig extends classes.Config { }
HostConfig.registerGroup(HostGroup);
/**
@@ -245,7 +245,7 @@ SlaveConfig.registerGroup(SlaveGroup);
* @memberof module:lib/config
*/
class InstanceGroup extends classes.ConfigGroup { }
InstanceGroup.defaultAccess = ["controller", "slave", "control"];
InstanceGroup.defaultAccess = ["controller", "host", "control"];
InstanceGroup.groupName = "instance";
InstanceGroup.define({
name: "name",
@@ -259,13 +259,13 @@ InstanceGroup.define({
initial_value: () => Math.random() * 2**31 | 0,
});
InstanceGroup.define({
name: "assigned_slave",
name: "assigned_host",
type: "number",
optional: true,
});
InstanceGroup.define({
name: "auto_start",
description: "Automatically start this instance when the slave hosting it is started up",
description: "Automatically start this instance when the host hosting it is started up",
type: "boolean",
initial_value: false,
});
@@ -277,7 +277,7 @@ InstanceGroup.finalize();
* @memberof module:lib/config
*/
class FactorioGroup extends classes.ConfigGroup { }
FactorioGroup.defaultAccess = ["controller", "slave", "control"];
FactorioGroup.defaultAccess = ["controller", "host", "control"];
FactorioGroup.groupName = "factorio";
FactorioGroup.define({
name: "version",
@@ -478,7 +478,7 @@ function registerPluginConfigGroups(pluginInfos) {
} else {
class ControllerConfigGroup extends classes.PluginConfigGroup { }
ControllerConfigGroup.defaultAccess = ["controller", "slave", "control"];
ControllerConfigGroup.defaultAccess = ["controller", "host", "control"];
ControllerConfigGroup.groupName = pluginInfo.name;
ControllerConfigGroup.finalize();
ControllerConfig.registerGroup(ControllerConfigGroup);
@@ -491,7 +491,7 @@ function registerPluginConfigGroups(pluginInfos) {
} else {
class InstanceConfigGroup extends classes.PluginConfigGroup { }
InstanceConfigGroup.defaultAccess = ["controller", "slave", "control"];
InstanceConfigGroup.defaultAccess = ["controller", "host", "control"];
InstanceConfigGroup.groupName = pluginInfo.name;
InstanceConfigGroup.finalize();
InstanceConfig.registerGroup(InstanceConfigGroup);
@@ -507,20 +507,20 @@ function registerPluginConfigGroups(pluginInfos) {
*/
function finalizeConfigs() {
ControllerConfig.finalize();
SlaveConfig.finalize();
HostConfig.finalize();
InstanceConfig.finalize();
ControlConfig.finalize();
}
module.exports = {
ControllerGroup,
SlaveGroup,
HostGroup,
InstanceGroup,
FactorioGroup,
ControlGroup,
ControllerConfig,
SlaveConfig,
HostConfig,
InstanceConfig,
ControlConfig,
+2 -2
View File
@@ -34,8 +34,8 @@ async function generateExportMod(server) {
clean: false,
build: true,
pack: true,
// XXX fix path when moving lib/factorio to slave
sourceDir: path.join(__dirname, "..", "..", "slave", "lua", "export"),
// XXX fix path when moving lib/factorio to host
sourceDir: path.join(__dirname, "..", "..", "host", "lua", "export"),
outputDir: server.writePath("mods"),
bumpPatch: false,
factorioVersion: server.version.replace(/\.\d+$/, ""),
+61 -61
View File
@@ -278,7 +278,7 @@ class Request extends Message {
let messages = {};
// Connection requests
let wsLinks = ["controller-control", "control-controller", "controller-slave", "slave-controller"];
let wsLinks = ["controller-control", "control-controller", "controller-host", "host-controller"];
messages.prepareDisconnect = new Request({
type: "prepare_disconnect",
links: wsLinks,
@@ -287,7 +287,7 @@ messages.prepareDisconnect = new Request({
messages.prepareControllerDisconnect = new Request({
type: "prepare_controller_disconnect",
links: ["slave-instance"],
links: ["host-instance"],
});
messages.ping = new Request({
@@ -335,7 +335,7 @@ messages.setControllerConfigProp = new Request({
},
});
let slaveProperties = {
let hostProperties = {
"agent": { type: "string" },
"version": { type: "string" },
"name": { type: "string" },
@@ -344,29 +344,29 @@ let slaveProperties = {
"public_address": { type: ["null", "string"] },
};
messages.listSlaves = new Request({
type: "list_slaves",
messages.listHosts = new Request({
type: "list_hosts",
links: ["control-controller"],
permission: "core.slave.list",
permission: "core.host.list",
responseProperties: {
"list": {
type: "array",
items: {
additionalProperties: false,
required: ["agent", "version", "name", "id", "connected"],
properties: slaveProperties,
properties: hostProperties,
},
},
},
});
messages.setSlaveSubscriptions = new Request({
type: "set_slave_subscriptions",
messages.setHostSubscriptions = new Request({
type: "set_host_subscriptions",
links: ["control-controller"],
permission: "core.slave.subscribe",
permission: "core.host.subscribe",
requestProperties: {
"all": { type: "boolean" },
"slave_ids": {
"host_ids": {
type: "array",
items: { type: "integer" },
},
@@ -376,7 +376,7 @@ messages.setSlaveSubscriptions = new Request({
let instanceProperties = {
"name": { type: "string" },
"id": { type: "integer" },
"assigned_slave": { type: ["null", "integer"] },
"assigned_host": { type: ["null", "integer"] },
"game_port": { type: ["null", "integer"] },
"status": { enum: [
"unknown", "unassigned", "stopped", "starting", "running", "stopping",
@@ -403,7 +403,7 @@ messages.listInstances = new Request({
type: "array",
items: {
additionalProperties: false,
required: ["name", "id", "assigned_slave", "status"],
required: ["name", "id", "assigned_host", "status"],
properties: instanceProperties,
},
},
@@ -423,22 +423,22 @@ messages.setInstanceSubscriptions = new Request({
},
});
messages.generateSlaveToken = new Request({
type: "generate_slave_token",
messages.generateHostToken = new Request({
type: "generate_host_token",
links: ["control-controller"],
permission: "core.slave.generate_token",
permission: "core.host.generate_token",
requestProperties: {
"slave_id": { type: ["integer", "null"] },
"host_id": { type: ["integer", "null"] },
},
responseProperties: {
"token": { type: "string" },
},
});
messages.createSlaveConfig = new Request({
type: "create_slave_config",
messages.createHostConfig = new Request({
type: "create_host_config",
links: ["control-controller"],
permission: "core.slave.create_config",
permission: "core.host.create_config",
requestProperties: {
"id": { type: ["integer", "null"] },
"name": { type: ["string", "null"] },
@@ -500,13 +500,13 @@ messages.assignInstanceCommand = new Request({
permission: "core.instance.assign",
requestProperties: {
"instance_id": { type: "integer" },
"slave_id": { type: ["integer", "null"] },
"host_id": { type: ["integer", "null"] },
},
});
messages.startInstance = new Request({
type: "start_instance",
links: ["control-controller", "controller-slave", "slave-instance"],
links: ["control-controller", "controller-host", "host-instance"],
permission: "core.instance.start",
requestProperties: {
"save": { type: ["string", "null"] },
@@ -533,7 +533,7 @@ let saveList = {
messages.listSaves = new Request({
type: "list_saves",
links: ["control-controller", "controller-slave", "slave-instance"],
links: ["control-controller", "controller-host", "host-instance"],
permission: "core.instance.save.list",
forwardTo: "instance",
responseProperties: {
@@ -543,7 +543,7 @@ messages.listSaves = new Request({
messages.createSave = new Request({
type: "create_save",
links: ["control-controller", "controller-slave", "slave-instance"],
links: ["control-controller", "controller-host", "host-instance"],
permission: "core.instance.save.create",
forwardTo: "instance",
requestProperties: {
@@ -556,7 +556,7 @@ messages.createSave = new Request({
messages.renameSave = new Request({
type: "rename_save",
links: ["control-controller", "controller-slave"],
links: ["control-controller", "controller-host"],
permission: "core.instance.save.rename",
forwardTo: "instance",
requestProperties: {
@@ -567,7 +567,7 @@ messages.renameSave = new Request({
messages.copySave = new Request({
type: "copy_save",
links: ["control-controller", "controller-slave"],
links: ["control-controller", "controller-host"],
permission: "core.instance.save.copy",
forwardTo: "instance",
requestProperties: {
@@ -578,7 +578,7 @@ messages.copySave = new Request({
messages.deleteSave = new Request({
type: "delete_save",
links: ["control-controller", "controller-slave"],
links: ["control-controller", "controller-host"],
permission: "core.instance.save.delete",
forwardTo: "instance",
requestProperties: {
@@ -601,7 +601,7 @@ messages.downloadSave = new Request({
messages.transferSave = new Request({
type: "transfer_save",
links: ["control-controller", "controller-slave"],
links: ["control-controller", "controller-host"],
permission: "core.instance.save.transfer",
requestProperties: {
"instance_id": { type: "integer" },
@@ -617,7 +617,7 @@ messages.transferSave = new Request({
messages.pullSave = new Request({
type: "pull_save",
links: ["controller-slave"],
links: ["controller-host"],
requestProperties: {
"instance_id": { type: "integer" },
"stream_id": { type: "string" },
@@ -630,7 +630,7 @@ messages.pullSave = new Request({
messages.pushSave = new Request({
type: "push_save",
links: ["controller-slave"],
links: ["controller-host"],
requestProperties: {
"instance_id": { type: "integer" },
"stream_id": { type: "string" },
@@ -653,7 +653,7 @@ messages.setSaveListSubscriptions = new Request({
messages.loadScenario = new Request({
type: "load_scenario",
links: ["control-controller", "controller-slave", "slave-instance"],
links: ["control-controller", "controller-host", "host-instance"],
permission: "core.instance.load_scenario",
forwardTo: "instance",
requestProperties: {
@@ -666,42 +666,42 @@ messages.loadScenario = new Request({
messages.exportData = new Request({
type: "export_data",
links: ["control-controller", "controller-slave", "slave-instance"],
links: ["control-controller", "controller-host", "host-instance"],
permission: "core.instance.export_data",
forwardTo: "instance",
});
messages.extractPlayers = new Request({
type: "extract_players",
links: ["control-controller", "controller-slave", "slave-instance"],
links: ["control-controller", "controller-host", "host-instance"],
permission: "core.instance.extract_players",
forwardTo: "instance",
});
messages.stopInstance = new Request({
type: "stop_instance",
links: ["control-controller", "controller-slave", "slave-instance"],
links: ["control-controller", "controller-host", "host-instance"],
permission: "core.instance.stop",
forwardTo: "instance",
});
messages.killInstance = new Request({
type: "kill_instance",
links: ["control-controller", "controller-slave", "slave-instance"],
links: ["control-controller", "controller-host", "host-instance"],
permission: "core.instance.kill",
forwardTo: "instance",
});
messages.deleteInstance = new Request({
type: "delete_instance",
links: ["control-controller", "controller-slave"],
links: ["control-controller", "controller-host"],
permission: "core.instance.delete",
forwardTo: "instance",
});
messages.sendRcon = new Request({
type: "send_rcon",
links: ["control-controller", "controller-slave", "slave-instance"],
links: ["control-controller", "controller-host", "host-instance"],
permission: "core.instance.send_rcon",
forwardTo: "instance",
requestProperties: {
@@ -714,7 +714,7 @@ messages.sendRcon = new Request({
messages.getModPack = new Request({
type: "get_mod_pack",
links: ["control-controller", "instance-slave", "slave-controller"],
links: ["control-controller", "instance-host", "host-controller"],
permission: "core.mod_pack.get",
forwardTo: "controller",
requestProperties: {
@@ -727,7 +727,7 @@ messages.getModPack = new Request({
messages.getDefaultModPack = new Request({
type: "get_default_mod_pack",
links: ["control-controller", "instance-slave", "slave-controller"],
links: ["control-controller", "instance-host", "host-controller"],
permission: "core.mod_pack.get",
forwardTo: "controller",
responseProperties: {
@@ -1107,7 +1107,7 @@ messages.setLogSubscriptions = new Request({
requestProperties: {
"all": { type: "boolean" },
"controller": { type: "boolean" },
"slave_ids": {
"host_ids": {
type: "array",
items: { type: "integer" },
},
@@ -1126,7 +1126,7 @@ messages.queryLog = new Request({
requestProperties: {
"all": { type: "boolean" },
"controller": { type: "boolean" },
"slave_ids": {
"host_ids": {
type: "array",
items: { type: "integer" },
},
@@ -1150,7 +1150,7 @@ messages.queryLog = new Request({
// Internal requests
messages.updateInstances = new Request({
type: "update_instances",
links: ["slave-controller"],
links: ["host-controller"],
requestProperties: {
"instances": {
type: "array",
@@ -1171,7 +1171,7 @@ messages.updateInstances = new Request({
messages.assignInstance = new Request({
type: "assign_instance",
links: ["controller-slave"],
links: ["controller-host"],
requestProperties: {
"serialized_config": { type: "object" },
},
@@ -1180,13 +1180,13 @@ messages.assignInstance = new Request({
messages.unassignInstance = new Request({
type: "unassigne_instance",
links: ["controller-slave"],
links: ["controller-host"],
forwardTo: "instance",
});
messages.getMetrics = new Request({
type: "get_metrics",
links: ["controller-slave", "slave-instance"],
links: ["controller-host", "host-instance"],
responseProperties: {
"results": { type: "array" },
},
@@ -1221,8 +1221,8 @@ class Event extends Message {
* Optional target to broadcast this event to. Only 'instance' is
* currently supported. An event will only be broadcast towards
* links that are downstream, so sending an event set to instance
* broadcast that's sent to a slave will only be broadcast to that
* slave's instances.
* broadcast that's sent to a host will only be broadcast to that
* host's instances.
* @param {?Array<string>} eventRequired -
* List of properties required to be present in the event payload.
* Defaults to all.
@@ -1307,7 +1307,7 @@ class Event extends Message {
if (
this.broadcastTo === "instance"
&& [
"instance-slave", "slave-controller", "control-controller", "controller-slave",
"instance-host", "host-controller", "control-controller", "controller-host",
].includes(`${link.target}-${link.source}`)
) {
if (!handler) {
@@ -1387,7 +1387,7 @@ messages.accountUpdate = new Event({
messages.logMessage = new Event({
type: "log_message",
links: ["slave-controller", "controller-control"],
links: ["host-controller", "controller-control"],
eventProperties: {
"info": {
type: "object",
@@ -1400,16 +1400,16 @@ messages.logMessage = new Event({
},
});
messages.slaveUpdate = new Event({
type: "slave_update",
messages.hostUpdate = new Event({
type: "host_update",
links: ["controller-control"],
eventProperties: slaveProperties,
eventProperties: hostProperties,
});
messages.instanceInitialized = new Event({
type: "instance_initialized",
links: ["instance-slave"],
links: ["instance-host"],
eventProperties: {
"instance_id": { type: "integer" },
"plugins": {
@@ -1420,7 +1420,7 @@ messages.instanceInitialized = new Event({
});
messages.instanceStatusChanged = new Event({
type: "instance_status_changed",
links: ["instance-slave", "slave-controller"],
links: ["instance-host", "host-controller"],
eventRequired: ["instance_id", "status"],
eventProperties: {
"instance_id": { type: "integer" },
@@ -1439,7 +1439,7 @@ messages.instanceUpdate = new Event({
messages.saveListUpdate = new Event({
type: "save_list_update",
links: ["instance-slave", "slave-controller", "controller-control"],
links: ["instance-host", "host-controller", "controller-control"],
forwardTo: "controller",
eventProperties: {
"instance_id": { type: "integer" },
@@ -1472,7 +1472,7 @@ messages.userUpdate = new Event({
messages.controllerConnectionEvent = new Event({
type: "controller_connection_event",
links: ["slave-instance"],
links: ["host-instance"],
eventProperties: {
"event": { type: "string" },
},
@@ -1480,7 +1480,7 @@ messages.controllerConnectionEvent = new Event({
messages.syncUserLists = new Event({
type: "sync_user_lists",
links: ["controller-slave"],
links: ["controller-host"],
eventProperties: {
"adminlist": {
type: "array",
@@ -1503,7 +1503,7 @@ messages.syncUserLists = new Event({
messages.banlistUpdate = new Event({
type: "banlist_update",
links: ["controller-slave", "slave-instance"],
links: ["controller-host", "host-instance"],
broadcastTo: "instance",
eventProperties: {
"name": { type: "string" },
@@ -1514,7 +1514,7 @@ messages.banlistUpdate = new Event({
messages.adminlistUpdate = new Event({
type: "adminlist_update",
links: ["controller-slave", "slave-instance"],
links: ["controller-host", "host-instance"],
eventProperties: {
"name": { type: "string" },
"admin": { type: "boolean" },
@@ -1524,7 +1524,7 @@ messages.adminlistUpdate = new Event({
messages.whitelistUpdate = new Event({
type: "whitelist_update",
links: ["controller-slave", "slave-instance"],
links: ["controller-host", "host-instance"],
eventProperties: {
"name": { type: "string" },
"whitelisted": { type: "boolean" },
@@ -1534,7 +1534,7 @@ messages.whitelistUpdate = new Event({
messages.playerEvent = new Event({
type: "player_event",
links: ["instance-slave", "slave-controller"],
links: ["instance-host", "host-controller"],
forwardTo: "controller",
eventRequired: ["instance_id", "type", "name"],
eventProperties: {
+11 -11
View File
@@ -63,8 +63,8 @@ class WebConsoleFormat {
transform(info, options) {
let src = " ";
if (info.slave_id !== undefined) {
src += `s:${info.slave_name} - `;
if (info.host_id !== undefined) {
src += `s:${info.host_name} - `;
}
if (info.instance_id !== undefined) {
src += `i:${info.instance_name}`;
@@ -88,12 +88,12 @@ class WebConsoleFormat {
* @property {string} [max_level] -
* Maximum log level to include. Higher levels are more verbose.
* @property {boolean} [all] -
* Include log entries from controller, all slaves and all instances.
* Include log entries from controller, all hosts and all instances.
* @property {boolean} [controller] -
* Include log entries from the controller.
* @property {Array<number>} [slave_ids] -
* Include log entries for the given slaves and instances of those
* slaves by id.
* @property {Array<number>} [host_ids] -
* Include log entries for the given hosts and instances of those
* hosts by id.
* @property {Array<number>} [instance_ids] -
* Include log entries for the given instances by id.
*/
@@ -107,7 +107,7 @@ class WebConsoleFormat {
* filter returning true for log entries that match it.
* @static
*/
function logFilter({ all, controller, slave_ids, instance_ids, max_level }) {
function logFilter({ all, controller, host_ids, instance_ids, max_level }) {
return info => {
// Note: reversed to filter out undefined levels
if (max_level && !(levels[info.level] <= levels[max_level])) {
@@ -117,14 +117,14 @@ function logFilter({ all, controller, slave_ids, instance_ids, max_level }) {
if (all) {
return true;
}
if (controller && info.slave_id === undefined) {
if (controller && info.host_id === undefined) {
return true;
}
if (
slave_ids
&& info.slave_id !== undefined
host_ids
&& info.host_id !== undefined
&& info.instance_id === undefined
&& slave_ids.includes(info.slave_id)
&& host_ids.includes(info.host_id)
) {
return true;
}
+13 -13
View File
@@ -90,8 +90,8 @@ class TerminalFormat {
if (info.instance_name) {
src += `i:${info.instance_name} `;
} else if (info.slave_name) {
src += `s:${info.slave_name} `;
} else if (info.host_name) {
src += `s:${info.host_name} `;
}
if (info.plugin) {
src += `${info.plugin}: `;
@@ -158,7 +158,7 @@ class LogIndex {
this.index.set(file, {
levels: new Set(serializedEntry.levels),
controller: serializedEntry.controller,
slave_ids: new Set(serializedEntry.slave_ids),
host_ids: new Set(serializedEntry.host_ids),
instance_ids: new Set(serializedEntry.instance_ids),
});
}
@@ -174,7 +174,7 @@ class LogIndex {
serialized.files[file] = {
levels: [...entry.levels],
controller: entry.controller,
slave_ids: [...entry.slave_ids],
host_ids: [...entry.host_ids],
instance_ids: [...entry.instance_ids],
};
}
@@ -225,7 +225,7 @@ class LogIndex {
let entry = {
levels: new Set(),
controller: false,
slave_ids: new Set(),
host_ids: new Set(),
instance_ids: new Set(),
};
for await (let line of lineStream) {
@@ -240,10 +240,10 @@ class LogIndex {
if (info.level) {
entry.levels.add(info.level);
}
if (info.slave_id === undefined) {
if (info.host_id === undefined) {
entry.controller = true;
} else if (info.instance_id === undefined) {
entry.slave_ids.add(info.slave_id);
entry.host_ids.add(info.host_id);
}
if (info.instance_id !== undefined) {
entry.instance_ids.add(info.instance_id);
@@ -279,7 +279,7 @@ class LogIndex {
* @returns {boolean}
* true if the file may contain entries included by the filter.
*/
filterIncludesFile(file, { max_level, all, controller, instance_ids, slave_ids }) {
filterIncludesFile(file, { max_level, all, controller, instance_ids, host_ids }) {
let entry = this.index.get(file);
if (!entry) {
return true;
@@ -301,7 +301,7 @@ class LogIndex {
if (controller && entry.controller) {
return true;
}
if (slave_ids && slave_ids.some(id => entry.slave_ids.has(id))) {
if (host_ids && host_ids.some(id => entry.host_ids.has(id))) {
return true;
}
if (instance_ids && instance_ids.some(id => entry.instance_ids.has(id))) {
@@ -321,12 +321,12 @@ class LogIndex {
* @property {string} [max_level] -
* Maximum log level to include. Higher levels are more verbose.
* @property {boolean} [all] -
* Include log entries from controller, all slaves and all instances.
* Include log entries from controller, all hosts and all instances.
* @property {boolean} [controller] -
* Include log entries from the controller.
* @property {Array<number>} [slave_ids] -
* Include log entries for the given slaves and instances of those
* slaves by id.
* @property {Array<number>} [host_ids] -
* Include log entries for the given hosts and instances of those
* hosts by id.
* @property {Array<number>} [instance_ids] -
* Include log entries for the given instances by id.
*/
+49 -49
View File
@@ -19,7 +19,7 @@ const helpers = require("./helpers");
* Base class for instance plugins
*
* Instance plugins are subclasses of this class which get instantiated by
* the slave when it brings up an instance with the plugin enabled in the
* the host when it brings up an instance with the plugin enabled in the
* config. To be discovered the class must be exported under the name
* `InstancePlugin` in the module specified by the `instanceEntrypoint` in
* the plugin's info.js file.
@@ -31,7 +31,7 @@ const helpers = require("./helpers");
* @static
*/
class BaseInstancePlugin {
constructor(info, instance, slave) {
constructor(info, instance, host) {
/**
* The plugin's own info module
*/
@@ -39,19 +39,19 @@ class BaseInstancePlugin {
/**
* Instance the plugin started for
* @type {module:slave/src/Instance}
* @type {module:host/src/Instance}
*/
this.instance = instance;
/**
* Slave running the instance
* Host running the instance
*
* With the exepction of accessing the slave's config you should
* avoid ineracting with the slave object directly.
* With the exepction of accessing the host's config you should
* avoid ineracting with the host object directly.
*
* @type {module:slave/src/Slave}
* @type {module:host/src/Host}
*/
this.slave = slave;
this.host = host;
/**
* Logger for this plugin
@@ -161,12 +161,12 @@ class BaseInstancePlugin {
*
* ##### drop
*
* Invoked when a connection loss is detected between the slave and the
* Invoked when a connection loss is detected between the host and the
* controller. Plugins should respond to this event by throtteling messages
* it is sending to the controller to an absolute minimum.
*
* Messages sent over a dropped controller connection will get queued up in
* memory on the slave and sent all in one go when the connection is
* memory on the host and sent all in one go when the connection is
* re-established again.
*
* ##### resume
@@ -186,17 +186,17 @@ class BaseInstancePlugin {
onControllerConnectionEvent(event) { }
/**
* Called when the controller is preparing to disconnect from the slave
* Called when the controller is preparing to disconnect from the host
*
* Invoked when the controller has requested the disconnection from
* the slave. This typically happens when it is in the process of
* the host. This typically happens when it is in the process of
* shutting down.
*
* Plugins must stop sending messages to the controller, or are forwarded
* via the controller after the prepare disconnect has been handled.
*
* @param {module:controller/src/SlaveConnection} connection -
* The connection to the slave preparing to disconnect.
* @param {module:controller/src/HostConnection} connection -
* The connection to the host preparing to disconnect.
*/
async onPrepareControllerDisconnect(connection) { }
@@ -324,12 +324,12 @@ class BaseControllerPlugin {
* Called when the status of an instance changes
*
* Invoked when the controller has changed the status of an instance
* or received notice from a slave that the status of an instance has
* or received notice from a host that the status of an instance has
* changed. The possible statuses that can be notified about are:
* - `unassigned:`: Instance is no longer asssigned to a slave.
* - `unknown`: Slave assigned to instance is offline.
* - `unassigned:`: Instance is no longer asssigned to a host.
* - `unknown`: Host assigned to instance is offline.
* - `stopped`: Instance is no longer running or was just assigned to a
* slave.
* host.
* - `starting`: Instance is in the process of starting up.
* - `running`: Instance startup completed and is now running.
* - `stopping`: Instance is in the processing stopping.
@@ -339,20 +339,20 @@ class BaseControllerPlugin {
* - `deleted`: Instance was deleted.
*
* On controller startup all known instances gets the status `unknown` if
* they are assigned to a slave, when the slave then connects to the
* they are assigned to a host, when the host then connects to the
* controller and informs of the current status of its instances this hook
* is invoked for all those instances. You can detect this situation by
* checking if prev equals `unknown`. If the slave disconnects the
* checking if prev equals `unknown`. If the host disconnects the
* instances will again get the `unknown` status.
*
* When instances are created on the controller they will notify of a status
* change with prev set to null. While the status of new instances is
* in most cases `unassigned` it's possible for the created instance to
* start with any state in some slave connection corner cases.
* start with any state in some host connection corner cases.
*
* Note that it's possible for status change notification to get lost in
* the case of network outages if reconnect fails to re-establish the
* session between the controller and the slave.
* session between the controller and the host.
*
* @param {Object} instance - the instance that changed.
* @param {?string} prev - the previous status of the instance.
@@ -409,22 +409,22 @@ class BaseControllerPlugin {
async onShutdown() { }
/**
* Called when an event on a slave connection happens
* Called when an event on a host connection happens
*
* The event param may be one of connect, drop, resume and close and has
* the following meaning:
*
* ##### connect
*
* Invoked when a new connection to the slave has been established.
* Invoked when a new connection to the host has been established.
*
* ##### drop
*
* Invoked when a connection loss is detected between the controller and a
* slave. Plugins should respond to this event by throtteling messages
* it is sending to the given slave connection to an absolute minimum.
* host. Plugins should respond to this event by throtteling messages
* it is sending to the given host connection to an absolute minimum.
*
* Messages sent over a dropped slave connection will get queued up in
* Messages sent over a dropped host connection will get queued up in
* memory on the controller and sent all in one go when the connection is
* re-established again.
*
@@ -435,13 +435,13 @@ class BaseControllerPlugin {
*
* ##### close
*
* Invoked when the connection to the slave has been closed.
* Invoked when the connection to the host has been closed.
*
* @param {module:controller/src/SlaveConnection} connection -
* @param {module:controller/src/HostConnection} connection -
* The connection the event occured on.
* @param {string} event - one of connect, drop, resume and close
*/
onSlaveConnectionEvent(connection, event) { }
onHostConnectionEvent(connection, event) { }
/**
* Called when an avent on a control connection happens
@@ -480,18 +480,18 @@ class BaseControllerPlugin {
onControlConnectionEvent(connection, event) { }
/**
* Called when a slave is preparing to disconnect from the controller
* Called when a host is preparing to disconnect from the controller
*
* Invoked when a slave has requested the disconnection from the controller.
* Invoked when a host has requested the disconnection from the controller.
* This typically happens when it is in the process of shutting down.
*
* Plugins must stop sending messages to the slave in question after the
* Plugins must stop sending messages to the host in question after the
* prepare disconnect has been handled.
*
* @param {module:controller/src/SlaveConnection} connection -
* The connection to the slave preparing to disconnect.
* @param {module:controller/src/HostConnection} connection -
* The connection to the host preparing to disconnect.
*/
async onPrepareSlaveDisconnect(connection) { }
async onPrepareHostDisconnect(connection) { }
/**
* Called when a mod pack is updated
@@ -536,22 +536,22 @@ class BaseControllerPlugin {
async onPlayerEvent(instance, event) { }
/**
* Broadcast event to all connected slaves
* Broadcast event to all connected hosts
*
* Sends the given event to all slaves connected to the controller.
* This does not include slaves that are in the process of closing the
* Sends the given event to all hosts connected to the controller.
* This does not include hosts that are in the process of closing the
* connection, which typically happens when they are shutting down.
*
* @param {module:lib/link.Event} event - Event to send
* @param {Object} data - Data ta pass with the event.
*/
broadcastEventToSlaves(event, data={}) {
for (let slaveConnection of this.controller.wsServer.slaveConnections.values()) {
broadcastEventToHosts(event, data={}) {
for (let hostConnection of this.controller.wsServer.hostConnections.values()) {
if (
!slaveConnection.connector.closing
&& (!event.plugin || slaveConnection.plugins.has(event.plugin))
!hostConnection.connector.closing
&& (!event.plugin || hostConnection.plugins.has(event.plugin))
) {
event.send(slaveConnection, data);
event.send(hostConnection, data);
}
}
}
@@ -702,11 +702,11 @@ class BaseWebPlugin {
* @type {object}
* @property {React.ComponentType} ControllerPage -
* Placed at the end of the controller page.
* @property {React.ComponentType} SlavesPage -
* Placed at the end of the slaves list page.
* @property {React.ComponentType} SlaveViewPage -
* Placed at the end of each slave page. Takes a `slave` param
* which is the slave the page is displayed for.
* @property {React.ComponentType} HostsPage -
* Placed at the end of the hosts list page.
* @property {React.ComponentType} HostViewPage -
* Placed at the end of each host page. Takes a `host` param
* which is the host the page is displayed for.
* @property {React.ComponentType} InstancesPage -
* Placed at the end of the instance list page.
* @property {React.ComponentType} InstanceViewPage -
+1 -1
View File
@@ -168,7 +168,7 @@ const clientHandshake = ajv.compile({
anyOf: [
{
properties: {
"type": { const: "register_slave" },
"type": { const: "register_host" },
"data": {
additionalProperties: false,
required: ["token", "agent", "version", "name", "id", "plugins"],
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Implementation of commands shared between controller/slave/ctl.
* Implementation of commands shared between controller/host/ctl.
* @module lib/shared_commands
*/
"use strict";
+13 -13
View File
@@ -365,26 +365,26 @@ definePermission({
description: "Modify the controller config or entries of the controller config.",
});
definePermission({
name: "core.slave.list",
title: "List slaves",
description: "Get the full list of slaves in the cluster.",
name: "core.host.list",
title: "List hosts",
description: "Get the full list of hosts in the cluster.",
grantByDefault: true,
});
definePermission({
name: "core.slave.subscribe",
title: "Subscribe to slave updates",
description: "Subscribe to be notified on updates on the details of slaves.",
name: "core.host.subscribe",
title: "Subscribe to host updates",
description: "Subscribe to be notified on updates on the details of hosts.",
grantByDefault: true,
});
definePermission({
name: "core.slave.generate_token",
title: "Generate slave token",
description: "Generate tokens for slaves to connect to the cluster with.",
name: "core.host.generate_token",
title: "Generate host token",
description: "Generate tokens for hosts to connect to the cluster with.",
});
definePermission({
name: "core.slave.create_config",
title: "Create slave config",
description: "Create slave configs via the controller.",
name: "core.host.create_config",
title: "Create host config",
description: "Create host configs via the controller.",
});
definePermission({
@@ -423,7 +423,7 @@ definePermission({
definePermission({
name: "core.instance.assign",
title: "Assign instance",
description: "Assign or reassign instances to a slave.",
description: "Assign or reassign instances to a host.",
});
definePermission({
name: "core.instance.save.list",