mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 23:53:13 +09:00
Rename Master to Controller
The role of the master server as the party controlling every part of the cluster is not well reflected in its name and has caused confusion among users on several occasions. Rename master to controller to better reflects its role.
This commit is contained in:
1 parent
6ae4c8ef46
commit
70ad295a89
119 files changed
+1394
-1376
No files matched your search
@@ -8,6 +8,6 @@ Plugin for the Subpsace Storage mod.
|
||||
Run the following commands in the folder Clusterio is installed to:
|
||||
|
||||
npm install @clusterio/plugin-subspace_storage
|
||||
npx clusteriomaster plugin add @clusterio/plugin-subspace_storage
|
||||
npx clusteriocontroller plugin add @clusterio/plugin-subspace_storage
|
||||
|
||||
Substitute clusteriomaster with clusterioslave or clusterioctl if this a dedicate slave or ctl installation respectively.
|
||||
Substitute clusteriocontroller with clusterioslave or clusterioctl if this a dedicate slave or ctl installation respectively.
|
||||
@@ -22,15 +22,15 @@ const importCounter = new Counter(
|
||||
"Resources imported by instance",
|
||||
{ labels: ["instance_id", "resource"] }
|
||||
);
|
||||
const masterInventoryGauge = new Gauge(
|
||||
"clusterio_subspace_storage_master_inventory",
|
||||
"Amount of resources stored on master",
|
||||
const controllerInventoryGauge = new Gauge(
|
||||
"clusterio_subspace_storage_controller_inventory",
|
||||
"Amount of resources stored on controller",
|
||||
{ labels: ["resource"] }
|
||||
);
|
||||
|
||||
|
||||
async function loadDatabase(config, logger) {
|
||||
let itemsPath = path.resolve(config.get("master.database_directory"), "items.json");
|
||||
let itemsPath = path.resolve(config.get("controller.database_directory"), "items.json");
|
||||
logger.verbose(`Loading ${itemsPath}`);
|
||||
try {
|
||||
let content = await fs.readFile(itemsPath);
|
||||
@@ -45,9 +45,9 @@ async function loadDatabase(config, logger) {
|
||||
}
|
||||
}
|
||||
|
||||
async function saveDatabase(masterConfig, items, logger) {
|
||||
async function saveDatabase(controllerConfig, items, logger) {
|
||||
if (items && items.size < 50000) {
|
||||
let file = path.resolve(masterConfig.get("master.database_directory"), "items.json");
|
||||
let file = path.resolve(controllerConfig.get("controller.database_directory"), "items.json");
|
||||
logger.verbose(`writing ${file}`);
|
||||
let content = JSON.stringify(items.serialize());
|
||||
await libFileOps.safeOutputFile(file, content);
|
||||
@@ -56,10 +56,10 @@ async function saveDatabase(masterConfig, items, logger) {
|
||||
}
|
||||
}
|
||||
|
||||
class MasterPlugin extends libPlugin.BaseMasterPlugin {
|
||||
class ControllerPlugin extends libPlugin.BaseControllerPlugin {
|
||||
async init() {
|
||||
|
||||
this.items = await loadDatabase(this.master.config, this.logger);
|
||||
this.items = await loadDatabase(this.controller.config, this.logger);
|
||||
this.itemUpdateRateLimiter = new RateLimiter({
|
||||
maxRate: 1,
|
||||
action: () => {
|
||||
@@ -72,21 +72,21 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
|
||||
});
|
||||
this.itemsLastUpdate = new Map(this.items._items.entries());
|
||||
this.autosaveId = setInterval(() => {
|
||||
saveDatabase(this.master.config, this.items, this.logger).catch(err => {
|
||||
saveDatabase(this.controller.config, this.items, this.logger).catch(err => {
|
||||
this.logger.error(`Unexpected error autosaving items:\n${err.stack}`);
|
||||
});
|
||||
}, this.master.config.get("subspace_storage.autosave_interval") * 1000);
|
||||
}, this.controller.config.get("subspace_storage.autosave_interval") * 1000);
|
||||
|
||||
this.neuralDole = new dole.NeuralDole({ items: this.items });
|
||||
this.doleMagicId = setInterval(() => {
|
||||
if (this.master.config.get("subspace_storage.division_method") === "neural_dole") {
|
||||
if (this.controller.config.get("subspace_storage.division_method") === "neural_dole") {
|
||||
this.neuralDole.doMagic();
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
this.subscribedControlLinks = new Set();
|
||||
|
||||
routes.addApiRoutes(this.master.app, this.items);
|
||||
routes.addApiRoutes(this.controller.app, this.items);
|
||||
}
|
||||
|
||||
updateStorage() {
|
||||
@@ -128,7 +128,7 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
|
||||
|
||||
this.updateStorage();
|
||||
|
||||
if (this.master.config.get("subspace_storage.log_item_transfers")) {
|
||||
if (this.controller.config.get("subspace_storage.log_item_transfers")) {
|
||||
this.logger.verbose(
|
||||
`Imported the following from ${message.data.instance_id}:\n${JSON.stringify(message.data.items)}`
|
||||
);
|
||||
@@ -136,7 +136,7 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
|
||||
}
|
||||
|
||||
async removeRequestHandler(message) {
|
||||
let method = this.master.config.get("subspace_storage.division_method");
|
||||
let method = this.controller.config.get("subspace_storage.division_method");
|
||||
let instanceId = message.data.instance_id;
|
||||
|
||||
let itemsRemoved = [];
|
||||
@@ -153,7 +153,7 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
|
||||
}
|
||||
|
||||
} else {
|
||||
let instance = this.master.instances.get(instanceId);
|
||||
let instance = this.controller.instances.get(instanceId);
|
||||
let instanceName = instance ? instance.config.get("instance.name") : "unkonwn";
|
||||
|
||||
// use fancy neural net to calculate a "fair" dole division rate.
|
||||
@@ -171,7 +171,7 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
|
||||
let count = dole.doleDivider({
|
||||
object: { name: item[0], count: item[1], instanceId, instanceName },
|
||||
items: this.items,
|
||||
logItemTransfers: this.master.config.get("subspace_storage.log_item_transfers"),
|
||||
logItemTransfers: this.controller.config.get("subspace_storage.log_item_transfers"),
|
||||
logger: this.logger,
|
||||
});
|
||||
if (count > 0) {
|
||||
@@ -192,7 +192,7 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
|
||||
|
||||
this.updateStorage();
|
||||
|
||||
if (itemsRemoved.length && this.master.config.get("subspace_storage.log_item_transfers")) {
|
||||
if (itemsRemoved.length && this.controller.config.get("subspace_storage.log_item_transfers")) {
|
||||
this.logger.verbose(`Exported the following to ${instanceId}:\n${JSON.stringify(itemsRemoved)}`);
|
||||
}
|
||||
}
|
||||
@@ -219,7 +219,7 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
|
||||
onMetrics() {
|
||||
if (this.items) {
|
||||
for (let [key, count] of this.items._items) {
|
||||
masterInventoryGauge.labels(key).set(Number(count) || 0);
|
||||
controllerInventoryGauge.labels(key).set(Number(count) || 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -228,10 +228,10 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
|
||||
this.itemUpdateRateLimiter.cancel();
|
||||
clearInterval(this.autosaveId);
|
||||
clearInterval(this.doleMagicId);
|
||||
await saveDatabase(this.master.config, this.items, this.logger);
|
||||
await saveDatabase(this.controller.config, this.items, this.logger);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
MasterPlugin,
|
||||
ControllerPlugin,
|
||||
};
|
||||
@@ -25,9 +25,9 @@ function sigmoid3(x) {
|
||||
|
||||
// DOSE - Doses items for item X slave Y
|
||||
// Numreq - number of items that are requested for item X for slave Y
|
||||
// Instore - number of items for item X in master gauge (currently)
|
||||
// Instore - number of items for item X in controller gauge (currently)
|
||||
// store_last_tick -
|
||||
// Number of items for item X in master gauge at time of last tick
|
||||
// Number of items for item X in controller gauge at time of last tick
|
||||
// dole - Current dole for item X
|
||||
// carry - carry for item X slave Y
|
||||
// prev_req - Numreq for previous request for item X slave Y
|
||||
@@ -99,10 +99,10 @@ function dose(numreq, instore, store_last_tick, dole, carry, prev_req, numreq_to
|
||||
// TICK -
|
||||
// Updates values for item X, should be called once for each item for
|
||||
// each round of all slaves requesting that item Instore - number of
|
||||
// items for item X in master gauge (currently)
|
||||
// items for item X in controller gauge (currently)
|
||||
// dole - Current dole for item X
|
||||
// store_last_tick -
|
||||
// Number of items for item X in master gauge at time of last tick (not this one)
|
||||
// Number of items for item X in controller gauge at time of last tick (not this one)
|
||||
// * doleinfo_last -
|
||||
// Object with 2 values for last "tick period": numreq - total number or
|
||||
// requests for item, numslave - number of slaves requesting that item
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
"use strict";
|
||||
const { libConfig, libLink, libUsers } = require("@clusterio/lib");
|
||||
|
||||
class MasterConfigGroup extends libConfig.PluginConfigGroup {}
|
||||
MasterConfigGroup.defaultAccess = ["master", "slave", "control"];
|
||||
MasterConfigGroup.groupName = "subspace_storage";
|
||||
MasterConfigGroup.define({
|
||||
class ControllerConfigGroup extends libConfig.PluginConfigGroup {}
|
||||
ControllerConfigGroup.defaultAccess = ["controller", "slave", "control"];
|
||||
ControllerConfigGroup.groupName = "subspace_storage";
|
||||
ControllerConfigGroup.define({
|
||||
name: "autosave_interval",
|
||||
title: "Autosave Interval",
|
||||
description: "Interval the storage is autosaved at in seconds.",
|
||||
type: "number",
|
||||
initial_value: 60,
|
||||
});
|
||||
MasterConfigGroup.define({
|
||||
ControllerConfigGroup.define({
|
||||
name: "division_method",
|
||||
title: "Division Method",
|
||||
description: "Method for dividing resource requests between instances.",
|
||||
@@ -19,17 +19,17 @@ MasterConfigGroup.define({
|
||||
enum: ["simple", "dole", "neural_dole"],
|
||||
initial_value: "simple",
|
||||
});
|
||||
MasterConfigGroup.define({
|
||||
ControllerConfigGroup.define({
|
||||
name: "log_item_transfers",
|
||||
title: "Log Item Transfers",
|
||||
description: "Spam master console with item transfers done.",
|
||||
description: "Spam controller console with item transfers done.",
|
||||
type: "boolean",
|
||||
initial_value: false,
|
||||
});
|
||||
MasterConfigGroup.finalize();
|
||||
ControllerConfigGroup.finalize();
|
||||
|
||||
class InstanceConfigGroup extends libConfig.PluginConfigGroup {}
|
||||
InstanceConfigGroup.defaultAccess = ["master", "slave", "control"];
|
||||
InstanceConfigGroup.defaultAccess = ["controller", "slave", "control"];
|
||||
InstanceConfigGroup.groupName = "subspace_storage";
|
||||
InstanceConfigGroup.define({
|
||||
name: "log_item_transfers",
|
||||
@@ -68,8 +68,8 @@ module.exports = {
|
||||
instanceEntrypoint: "instance",
|
||||
InstanceConfigGroup,
|
||||
|
||||
masterEntrypoint: "master",
|
||||
MasterConfigGroup,
|
||||
controllerEntrypoint: "controller",
|
||||
ControllerConfigGroup,
|
||||
|
||||
webEntrypoint: "./web",
|
||||
routes: ["/storage"],
|
||||
@@ -78,8 +78,8 @@ module.exports = {
|
||||
// XXX this should be a request to be reliable
|
||||
place: new libLink.Event({
|
||||
type: "subspace_storage:place",
|
||||
links: ["instance-slave", "slave-master"],
|
||||
forwardTo: "master",
|
||||
links: ["instance-slave", "slave-controller"],
|
||||
forwardTo: "controller",
|
||||
eventProperties: {
|
||||
"instance_id": { type: "integer" },
|
||||
"items": items,
|
||||
@@ -87,8 +87,8 @@ module.exports = {
|
||||
}),
|
||||
remove: new libLink.Request({
|
||||
type: "subspace_storage:remove",
|
||||
links: ["instance-slave", "slave-master"],
|
||||
forwardTo: "master",
|
||||
links: ["instance-slave", "slave-controller"],
|
||||
forwardTo: "controller",
|
||||
requestProperties: {
|
||||
"instance_id": { type: "integer" },
|
||||
"items": items,
|
||||
@@ -99,16 +99,16 @@ module.exports = {
|
||||
}),
|
||||
getStorage: new libLink.Request({
|
||||
type: "subspace_storage:get_storage",
|
||||
links: ["instance-slave", "slave-master", "control-master"],
|
||||
links: ["instance-slave", "slave-controller", "control-controller"],
|
||||
permission: "subspace_storage.storage.view",
|
||||
forwardTo: "master",
|
||||
forwardTo: "controller",
|
||||
responseProperties: {
|
||||
"items": items,
|
||||
},
|
||||
}),
|
||||
updateStorage: new libLink.Event({
|
||||
type: "subspace_storage:update_storage",
|
||||
links: ["master-slave", "slave-instance", "master-control"],
|
||||
links: ["controller-slave", "slave-instance", "controller-control"],
|
||||
broadcastTo: "instance",
|
||||
eventProperties: {
|
||||
"items": items,
|
||||
@@ -117,7 +117,7 @@ module.exports = {
|
||||
|
||||
setStorageSubscription: new libLink.Request({
|
||||
type: "subspace_storage:set_storage_subscription",
|
||||
links: ["control-master"],
|
||||
links: ["control-controller"],
|
||||
permission: "subspace_storage.storage.view",
|
||||
requestProperties: {
|
||||
"storage": { type: "boolean" },
|
||||
|
||||
@@ -26,7 +26,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
||||
async onStart() {
|
||||
this.pingId = setInterval(() => {
|
||||
if (!this.slave.connected) {
|
||||
return; // Only ping if we are actually connected to the master.
|
||||
return; // Only ping if we are actually connected to the controller.
|
||||
}
|
||||
this.sendRcon(
|
||||
"/sc __subspace_storage__ global.ticksSinceMasterPinged = 0", true
|
||||
@@ -51,7 +51,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
||||
// provide items --------------------------------------------------------------
|
||||
async provideItems(items) {
|
||||
if (!this.slave.connector.hasSession) {
|
||||
// For now the items are voided if the master connection is
|
||||
// For now the items are voided if the controller connection is
|
||||
// down, which is no different from the previous behaviour.
|
||||
if (this.instance.config.get("subspace_storage.log_item_transfers")) {
|
||||
this.logger.verbose("Voided the following items:");
|
||||
@@ -66,7 +66,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
||||
});
|
||||
|
||||
if (this.instance.config.get("subspace_storage.log_item_transfers")) {
|
||||
this.logger.verbose("Exported the following to master:");
|
||||
this.logger.verbose("Exported the following to controller:");
|
||||
this.logger.verbose(JSON.stringify(items));
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
||||
}
|
||||
|
||||
if (this.instance.config.get("subspace_storage.log_item_transfers")) {
|
||||
this.logger.verbose("Imported following from master:");
|
||||
this.logger.verbose("Imported following from controller:");
|
||||
this.logger.verbose(JSON.stringify(response.items));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
function addApiRoutes(app, items) {
|
||||
|
||||
/**
|
||||
* GET endpoint to read the masters current inventory of items.
|
||||
* GET endpoint to read the controllers current inventory of items.
|
||||
*
|
||||
* @memberof clusterioMaster
|
||||
* @memberof clusterioController
|
||||
* @instance
|
||||
* @alias api/inventory
|
||||
* @returns {object[]} JSON [{name:"iron-plate", count:100},{name:"copper-plate",count:5}]
|
||||
@@ -22,9 +22,9 @@ function addApiRoutes(app, items) {
|
||||
});
|
||||
|
||||
/**
|
||||
* GET endpoint to read the masters inventory as an object with key:value pairs
|
||||
* GET endpoint to read the controllers inventory as an object with key:value pairs
|
||||
*
|
||||
* @memberof clusterioMaster
|
||||
* @memberof clusterioController
|
||||
* @instance
|
||||
* @alias api/inventoryAsObject
|
||||
* @returns {object} JSON {"iron-plate":100, "copper-plate":5}
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
"use strict";
|
||||
require("../instance");
|
||||
require("../master");
|
||||
require("../controller");
|
||||
require("../dole");
|
||||
require("../dole_nn_base");
|
||||
@@ -7,7 +7,7 @@ const { get } = require("../../../test/integration");
|
||||
|
||||
describe("subspace_storage endpoints", function() {
|
||||
describe("GET /api/inventory", function() {
|
||||
it("should return the masters current inventory", async function() {
|
||||
it("should return the controllers current inventory", async function() {
|
||||
let res = await get("/api/inventory");
|
||||
let inventory = res.body;
|
||||
assert.equal(typeof inventory, "object", "Inventory should be an object");
|
||||
|
||||
@@ -129,7 +129,7 @@ export class WebPlugin extends libPlugin.BaseWebPlugin {
|
||||
this.callbacks = [];
|
||||
}
|
||||
|
||||
onMasterConnectionEvent(event) {
|
||||
onControllerConnectionEvent(event) {
|
||||
if (event === "connect") {
|
||||
this.updateSubscription();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user