mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 08:13:12 +09:00
Merge pull request #481 from Hornwitser/rename-master-slave
Rename master/slave terminology to controller/host
This commit is contained in:
144 files changed
+2464
-2407
No files matched your search
@@ -26,7 +26,7 @@ jobs:
|
|||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node-version }}
|
||||||
- run: pnpm i --no-optional --no-frozen-lockfile
|
- run: pnpm i --no-optional --no-frozen-lockfile
|
||||||
- run: wget -q -O factorio.tar.gz https://www.factorio.com/get-download/latest/headless/linux64 && tar -xf factorio.tar.gz && rm factorio.tar.gz
|
- run: wget -q -O factorio.tar.gz https://www.factorio.com/get-download/latest/headless/linux64 && tar -xf factorio.tar.gz && rm factorio.tar.gz
|
||||||
- run: node packages/lib/build_mod --source-dir packages/slave/lua/clusterio_lib --output-dir temp/test/mods
|
- run: node packages/lib/build_mod --source-dir packages/host/lua/clusterio_lib --output-dir temp/test/mods
|
||||||
- run: wget -q -O temp/test/mods/subspace_storage_1.99.8.zip -L https://github.com/clusterio/subspace_storage/releases/download/1.99.6/subspace_storage_1.99.8.zip
|
- run: wget -q -O temp/test/mods/subspace_storage_1.99.8.zip -L https://github.com/clusterio/subspace_storage/releases/download/1.99.6/subspace_storage_1.99.8.zip
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
if: ${{ matrix.node-version != '12.x' }}
|
if: ${{ matrix.node-version != '12.x' }}
|
||||||
|
|||||||
+2
-2
@@ -35,9 +35,9 @@ Factorio*
|
|||||||
/mods
|
/mods
|
||||||
/database
|
/database
|
||||||
/plugin-list.json
|
/plugin-list.json
|
||||||
/config-master.json
|
/config-controller.json
|
||||||
/config-control.json
|
/config-control.json
|
||||||
/config-slave.json
|
/config-host.json
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
mod_cache.json
|
mod_cache.json
|
||||||
/static/
|
/static/
|
||||||
|
|||||||
+22
-21
@@ -8,11 +8,11 @@
|
|||||||
Removed the Hotpatch scenario and the depency on it for getting code into the game.
|
Removed the Hotpatch scenario and the depency on it for getting code into the game.
|
||||||
Added a save patcher than runs before starting up Factorio that patches in lua modules based on the event_loader lib into the savegame.
|
Added a save patcher than runs before starting up Factorio that patches in lua modules based on the event_loader lib into the savegame.
|
||||||
Regular freeplay games can now be used with Clusterio and will be compatible without having to convert them to Hotpatch.
|
Regular freeplay games can now be used with Clusterio and will be compatible without having to convert them to Hotpatch.
|
||||||
- Daemonized slaves.
|
- Daemonized hosts.
|
||||||
Slaves now have the ability to run multiple Factorio instances, starting and stopping them individually.
|
Hosts now have the ability to run multiple Factorio instances, starting and stopping them individually.
|
||||||
To manage this the local command line interface has been replaced with a remote interface on the master server that can be accessed through the clusterioctl cli tool.
|
To manage this the local command line interface has been replaced with a remote interface on the controller that can be accessed through the clusterioctl cli tool.
|
||||||
- Rewritten the communication between slaves and the master from scratch.
|
- Rewritten the communication between hosts and the controller from scratch.
|
||||||
The new system is based on a WebSocket connection between the slaves and the master server and provides efficient validated bi-directonal communication.
|
The new system is based on a WebSocket connection between the hosts and the controller and provides efficient validated bi-directonal communication.
|
||||||
- Rewritten the plugin system from scratch.
|
- Rewritten the plugin system from scratch.
|
||||||
Plugins now inherit from a base class and use the same WebSocket connection Clusterio uses to communicate.
|
Plugins now inherit from a base class and use the same WebSocket connection Clusterio uses to communicate.
|
||||||
- New configuration system with support for initializing configs when needed, modifying config entries using built-in commands, and updating instance configuration remotely.
|
- New configuration system with support for initializing configs when needed, modifying config entries using built-in commands, and updating instance configuration remotely.
|
||||||
@@ -24,9 +24,9 @@
|
|||||||
### Features
|
### Features
|
||||||
|
|
||||||
- Added export of pollution statitics.
|
- Added export of pollution statitics.
|
||||||
- Reconnection logic that esures no data is dropped talking to the master server provided the session can be resumed.
|
- Reconnection logic that esures no data is dropped talking to the controller provided the session can be resumed.
|
||||||
- Added support for having multiple Factorio installs and selecting which version to use on a per instance basis.
|
- Added support for having multiple Factorio installs and selecting which version to use on a per instance basis.
|
||||||
- Added config to specify which path the master interface is accessed under, allowing it to be proxied behind web-server.
|
- Added config to specify which path the controller interface is accessed under, allowing it to be proxied behind web-server.
|
||||||
- Added WebSocket usage statistics.
|
- Added WebSocket usage statistics.
|
||||||
- Added commands sent statistic.
|
- Added commands sent statistic.
|
||||||
- Added Factorio server CPU and memory usage statistic.
|
- Added Factorio server CPU and memory usage statistic.
|
||||||
@@ -37,18 +37,18 @@
|
|||||||
Previously this was handled by the playerManager plugin.
|
Previously this was handled by the playerManager plugin.
|
||||||
- Added stripping of long paths in the Factorio server log.
|
- Added stripping of long paths in the Factorio server log.
|
||||||
- Added option to configure maximum number of commands to send in parallel.
|
- Added option to configure maximum number of commands to send in parallel.
|
||||||
- Added option to auto start instances on slave startup.
|
- Added option to auto start instances on host startup.
|
||||||
- Added metric mapping of slave and instance ids to their names, allowing them to be displayed by name in queries that join with the mapping.
|
- Added metric mapping of host and instance ids to their names, allowing them to be displayed by name in queries that join with the mapping.
|
||||||
- Added option to configure timeout for exported Prometheus metrics.
|
- Added option to configure timeout for exported Prometheus metrics.
|
||||||
- Added option to set address to bind HTTP(S) port to.
|
- Added option to set address to bind HTTP(S) port to.
|
||||||
- Added an overview of the installed plugins to the web interface.
|
- Added an overview of the installed plugins to the web interface.
|
||||||
- Added clusterioctl command to list plugins on the master server.
|
- Added clusterioctl command to list plugins on the controller.
|
||||||
- Added Player Auth plugin for logging in to the web interface by proving the ability to log in to a server as a given user.
|
- Added Player Auth plugin for logging in to the web interface by proving the ability to log in to a server as a given user.
|
||||||
- Added Node.js based installer to simplify setting up a cluster.
|
- Added Node.js based installer to simplify setting up a cluster.
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
|
|
||||||
- Added error handling during master startup.
|
- Added error handling during controller startup.
|
||||||
- Factorio game and rcon port now defaults to a random port above 49151.
|
- Factorio game and rcon port now defaults to a random port above 49151.
|
||||||
- Removed unimplemented mods update command.
|
- Removed unimplemented mods update command.
|
||||||
- Fixed rcon password being generated with Math.random().
|
- Fixed rcon password being generated with Math.random().
|
||||||
@@ -69,15 +69,16 @@
|
|||||||
- Removed factorio_version from config.
|
- Removed factorio_version from config.
|
||||||
The version installed is auto detected and used instead.
|
The version installed is auto detected and used instead.
|
||||||
- Removed the playerManager specific command CLI tools/delete_player.js.
|
- Removed the playerManager specific command CLI tools/delete_player.js.
|
||||||
- Creating an instance, assigning it to a slave, creating a save for an instance and starting an instance is now four separate commands.
|
- Creating an instance, assigning it to a host, creating a save for an instance and starting an instance is now four separate commands.
|
||||||
- Removed oddball limits to slaves.json size.
|
- Removed oddball limits to hosts.json size.
|
||||||
- Moved slave specific and instance specific configuration into their own configuration files.
|
- Moved host specific and instance specific configuration into their own configuration files.
|
||||||
- Removed unused binary option from plugin config.
|
- Removed unused binary option from plugin config.
|
||||||
- Removed info and shout command from globalChat plugin - Removed mirrorAllChat and enableCrossServerShout configuration options for globalChat plugin.
|
- Removed info and shout command from globalChat plugin - Removed mirrorAllChat and enableCrossServerShout configuration options for globalChat plugin.
|
||||||
- Removed UPSdisplay plugin.
|
- Removed UPSdisplay plugin.
|
||||||
UPS statistics is exported by the statistics exporter plugin.
|
UPS statistics is exported by the statistics exporter plugin.
|
||||||
- Master server now defaults to hosting on https on port 8443.
|
- Controller now defaults to hosting on https on port 8443.
|
||||||
- Renamed client to slave.
|
- Renamed master to controller.
|
||||||
|
- Renamed slave/client to host.
|
||||||
- Removed rotation of factorio-current.log files.
|
- Removed rotation of factorio-current.log files.
|
||||||
|
|
||||||
### Breaking Changes
|
### Breaking Changes
|
||||||
@@ -100,7 +101,7 @@
|
|||||||
- Removed the remoteCommands plugin and the old runCommand interface.
|
- Removed the remoteCommands plugin and the old runCommand interface.
|
||||||
Breaks playerManager and external tools sending commands.
|
Breaks playerManager and external tools sending commands.
|
||||||
- Removed broken serverManager plugin.
|
- Removed broken serverManager plugin.
|
||||||
- Removed fields info, time, rconPort, rconPassword, serverPort, unique, mods, instanceName, playerCount, mac, and meta from the slaves in the slave database.
|
- Removed fields info, time, rconPort, rconPassword, serverPort, unique, mods, instanceName, playerCount, mac, and meta from the hosts in the host database.
|
||||||
- Removed getInstanceName and lib/clusterTools.
|
- Removed getInstanceName and lib/clusterTools.
|
||||||
Breaks playerManager, and discordChat.
|
Breaks playerManager, and discordChat.
|
||||||
- Removed the /api/rconPasswords, and /api/slaves endpoints.
|
- Removed the /api/rconPasswords, and /api/slaves endpoints.
|
||||||
@@ -109,7 +110,7 @@
|
|||||||
Breaks researchSync, and UPSdisplay.
|
Breaks researchSync, and UPSdisplay.
|
||||||
- Removed the hello event from the socket connection handshake.
|
- Removed the hello event from the socket connection handshake.
|
||||||
Breaks playerManager, trainTeleports, serverSelect, and discordChat
|
Breaks playerManager, trainTeleports, serverSelect, and discordChat
|
||||||
- Changed the format of database/slaves.json.
|
- Changed the format of database/hosts.json.
|
||||||
- Removed the output file subscription system.
|
- Removed the output file subscription system.
|
||||||
Breaks inventoryImports, playerManager, trainTeleports, serverSelect and researchSync.
|
Breaks inventoryImports, playerManager, trainTeleports, serverSelect and researchSync.
|
||||||
- Removed the factorioOutput hook from instance plugins.
|
- Removed the factorioOutput hook from instance plugins.
|
||||||
@@ -134,13 +135,13 @@
|
|||||||
- Removed msBetweenCommands config option.
|
- Removed msBetweenCommands config option.
|
||||||
The RCON is instead limited to 5 concurrent commands.
|
The RCON is instead limited to 5 concurrent commands.
|
||||||
- Removed allowRemoteCommandExecution config option.
|
- Removed allowRemoteCommandExecution config option.
|
||||||
Remote commands are always allowed with the move to master managing slaves/instances.
|
Remote commands are always allowed with the move to controller managing hosts/instances.
|
||||||
- Removed `--databaseDirectory`, `--masterPort`, and `--sslPort` command line arguments from the master server.
|
- Removed `--databaseDirectory`, `--controllerPort`, and `--sslPort` command line arguments from the controller.
|
||||||
- Implemented a new config system that replaces the old.
|
- Implemented a new config system that replaces the old.
|
||||||
Breaks all plugins.
|
Breaks all plugins.
|
||||||
- Removed usage of socket.io entirely in favor of a plain WebSocket connection.
|
- Removed usage of socket.io entirely in favor of a plain WebSocket connection.
|
||||||
- Renamed clusterioMod plugin to subspace_storage.
|
- Renamed clusterioMod plugin to subspace_storage.
|
||||||
- Master no longer creates secret-api-token.txt.
|
- Controller no longer creates secret-api-token.txt.
|
||||||
- Removed automatic creation of self-signed TLS certificate.
|
- Removed automatic creation of self-signed TLS certificate.
|
||||||
- Node.js versions below 12 are no longer supported.
|
- Node.js versions below 12 are no longer supported.
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -20,12 +20,12 @@ RUN pnpm install
|
|||||||
# Install plugins. This is intended as a reasonable default, enabling plugins to make for fun gameplay.
|
# Install plugins. This is intended as a reasonable default, enabling plugins to make for fun gameplay.
|
||||||
# If you want a different set of plugins, consider using this as the base image for your own.
|
# If you want a different set of plugins, consider using this as the base image for your own.
|
||||||
#RUN pnpm install @clusterio/plugin-subspace_storage
|
#RUN pnpm install @clusterio/plugin-subspace_storage
|
||||||
#RUN npx clusteriomaster plugin add @clusterio/plugin-subspace_storage
|
#RUN npx clusteriocontroller plugin add @clusterio/plugin-subspace_storage
|
||||||
|
|
||||||
COPY --from=subspace_storage_builder /subspace_storage/dist/ /clusterio/mods/
|
COPY --from=subspace_storage_builder /subspace_storage/dist/ /clusterio/mods/
|
||||||
|
|
||||||
# Build Lua library mod
|
# Build Lua library mod
|
||||||
RUN node packages/lib/build_mod --build --source-dir packages/slave/lua/clusterio_lib \
|
RUN node packages/lib/build_mod --build --source-dir packages/host/lua/clusterio_lib \
|
||||||
&& mv dist/* mods/ \
|
&& mv dist/* mods/ \
|
||||||
&& mkdir temp \
|
&& mkdir temp \
|
||||||
&& mkdir temp/test \
|
&& mkdir temp/test \
|
||||||
|
|||||||
@@ -33,11 +33,11 @@ If you are starting a new cluster, it's highly recommended to use the 2.0 alpha.
|
|||||||
* [Windows setup](#windows-setup)
|
* [Windows setup](#windows-setup)
|
||||||
* [MacOS setup](#macos-setup)
|
* [MacOS setup](#macos-setup)
|
||||||
* [Installing Plugins](#installing-plugins)
|
* [Installing Plugins](#installing-plugins)
|
||||||
* [Configure Master Server](#configure-master-server)
|
* [Configure Controller](#configure-controller)
|
||||||
* [Managing Factorio mods](#managing-factorio-mods)
|
* [Managing Factorio mods](#managing-factorio-mods)
|
||||||
* [Setting up shared storage](#setting-up-shared-storage)
|
* [Setting up shared storage](#setting-up-shared-storage)
|
||||||
* [Running Clusterio](#running-clusterio)
|
* [Running Clusterio](#running-clusterio)
|
||||||
* [Setting up remote slaves](#setting-up-remote-slaves)
|
* [Setting up remote hosts](#setting-up-remote-hosts)
|
||||||
* [Setting up clusterioctl](#setting-up-clusterioctl)
|
* [Setting up clusterioctl](#setting-up-clusterioctl)
|
||||||
* [Common problems](#Common-problems)
|
* [Common problems](#Common-problems)
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ These are the plugins supported and maintained by the Clusterio developers:
|
|||||||
|
|
||||||
- [Global Chat](/plugins/global_chat/README.md): share the in-game chat between servers.
|
- [Global Chat](/plugins/global_chat/README.md): share the in-game chat between servers.
|
||||||
- [Research Sync](/plugins/research_sync/README.md): synchronize research progress and technologies unlocked between servers.
|
- [Research Sync](/plugins/research_sync/README.md): synchronize research progress and technologies unlocked between servers.
|
||||||
- [Statistics Exporter](/plugins/statistics_exporter/README.md): collect in-game statistics from all the servers and makes it available to the Prometheus endpoint on the master server.
|
- [Statistics Exporter](/plugins/statistics_exporter/README.md): collect in-game statistics from all the servers and makes it available to the Prometheus endpoint on the controller.
|
||||||
- [Subspace Storage](https://github.com/clusterio/subspace_storage): Provide shared storage that can transport items between servers via teleport chests.
|
- [Subspace Storage](https://github.com/clusterio/subspace_storage): Provide shared storage that can transport items between servers via teleport chests.
|
||||||
- [Player Auth](/plugins/player_auth/README.md): Provides authentication to the cluster via logging into a Factorio server.
|
- [Player Auth](/plugins/player_auth/README.md): Provides authentication to the cluster via logging into a Factorio server.
|
||||||
- [Inventory Sync](/plugins/inventory_sync/README.md): Synchronizes your inventory between servers.
|
- [Inventory Sync](/plugins/inventory_sync/README.md): Synchronizes your inventory between servers.
|
||||||
@@ -126,9 +126,9 @@ Clusterio has *very* limited support for using docker.
|
|||||||
|
|
||||||
sudo docker build -t clusterio --no-cache --force-rm clusterio
|
sudo docker build -t clusterio --no-cache --force-rm clusterio
|
||||||
|
|
||||||
sudo docker run --name master -e MODE=master -p 1234:8080 -d -it --restart=unless-stopped danielvestol/clusterio
|
sudo docker run --name controller -e MODE=controller -p 1234:8080 -d -it --restart=unless-stopped danielvestol/clusterio
|
||||||
|
|
||||||
sudo docker run --name slave -e MODE=slave -e INSTANCE=world1 -v /srv/clusterio/instances:/clusterio/instances -p 1235:34167 -it --restart=unless-stopped danielvestol/clusterio
|
sudo docker run --name host -e MODE=host -e INSTANCE=world1 -v /srv/clusterio/instances:/clusterio/instances -p 1235:34167 -it --restart=unless-stopped danielvestol/clusterio
|
||||||
|
|
||||||
The -v flag is used to specify the instance directory.
|
The -v flag is used to specify the instance directory.
|
||||||
Your instances (save files etc) will be stored there.
|
Your instances (save files etc) will be stored there.
|
||||||
@@ -173,42 +173,42 @@ First install the package the plugin is provided by via npm, for example
|
|||||||
|
|
||||||
Then tell clusterio that this plugin exists by adding it as a plugin.
|
Then tell clusterio that this plugin exists by adding it as a plugin.
|
||||||
|
|
||||||
npx clusteriomaster plugin add @clusterio/plugin-subspace_storage
|
npx clusteriocontroller plugin add @clusterio/plugin-subspace_storage
|
||||||
|
|
||||||
This adds it to the default `plugin-list.json` file which in the shared folder setup is loaded by master, slave and ctl.
|
This adds it to the default `plugin-list.json` file which in the shared folder setup is loaded by controller, host and ctl.
|
||||||
If you have slaves or ctl installed on separate computers (or directories) then you need to repeat the plugin install process for all of them.
|
If you have hosts or ctl installed on separate computers (or directories) then you need to repeat the plugin install process for all of them.
|
||||||
The clusteriomaster, clusterioslave and clusterioctl commands has the plugin sub-command so you do not need to install clusteriomaster to add plugins, instead use the clusterio command you have available.
|
The clusteriocontroller, clusteriohost and clusterioctl commands has the plugin sub-command so you do not need to install clusteriocontroller to add plugins, instead use the clusterio command you have available.
|
||||||
|
|
||||||
For development purposes the `plugin add` command supports adding plugins by the absolute path to them, or a relative path that must start with either . or .. (which will then be resolved to an absolute path).
|
For development purposes the `plugin add` command supports adding plugins by the absolute path to them, or a relative path that must start with either . or .. (which will then be resolved to an absolute path).
|
||||||
|
|
||||||
|
|
||||||
## Configure Master Server
|
## Configure Controller
|
||||||
|
|
||||||
By default the master server will listen for HTTP on port 8080.
|
By default the controller will listen for HTTP on port 8080.
|
||||||
You can change the port used with the command
|
You can change the port used with the command
|
||||||
|
|
||||||
npx clusteriomaster config set master.http_port 1234
|
npx clusteriocontroller config set controller.http_port 1234
|
||||||
|
|
||||||
When changing the port you will also need to change the address slaves connect with.
|
When changing the port you will also need to change the address hosts connect with.
|
||||||
For the standalone installation mode you can use
|
For the standalone installation mode you can use
|
||||||
|
|
||||||
npx clusterioslave config set slave.master_url http://localhost:1234/
|
npx clusteriohost config set host.controller_url http://localhost:1234/
|
||||||
|
|
||||||
If you plan to make your cluster available externally set the address
|
If you plan to make your cluster available externally set the address
|
||||||
that it will be accessible under with, for example
|
that it will be accessible under with, for example
|
||||||
|
|
||||||
npx clusteriomaster config set master.external_address http://203.0.113.4:1234/
|
npx clusteriocontroller config set controller.external_address http://203.0.113.4:1234/
|
||||||
|
|
||||||
Change the url to reflect the IP, protocol, and port the master server is accessible under, dns names are also supported.
|
Change the url to reflect the IP, protocol, and port the controller is accessible under, dns names are also supported.
|
||||||
If you're planning on making the master server accessible on the internet it's recommended to set up TLS, see the [Setting Up TLS](/docs/setting-up-tls.md) document for more details.
|
If you're planning on making the controller accessible on the internet it's recommended to set up TLS, see the [Setting Up TLS](/docs/setting-up-tls.md) document for more details.
|
||||||
|
|
||||||
You can list the config of the master server with the `npx clusteriomaster config list` command.
|
You can list the config of the controller with the `npx clusteriocontroller config list` command.
|
||||||
See the [readme for @clusterio/master](/packages/master/README.md) for more information.
|
See the [readme for @clusterio/controller](/packages/controller/README.md) for more information.
|
||||||
|
|
||||||
|
|
||||||
## Managing Factorio mods
|
## Managing Factorio mods
|
||||||
|
|
||||||
Clusterio currently only provides a manual method for running mods on servers by copying them either to each instance's individual `mods` folder, or by copying them into a slave installation's `sharedMods` folder which will link/copy them to the `mods` folder of each instance on that slave if the file doesn't already exist in the `mods` folder for that instance.
|
Clusterio currently only provides a manual method for running mods on servers by copying them either to each instance's individual `mods` folder, or by copying them into a host installation's `sharedMods` folder which will link/copy them to the `mods` folder of each instance on that host if the file doesn't already exist in the `mods` folder for that instance.
|
||||||
Mods are copied from `sharedMods` on Windows and symlinked on Linux, this means that when mods are removed from `sharedMods` the mods will also be removed from the instance's `mods` folder on Linux if it got there by being linked by Clusterio, but not on Windows.
|
Mods are copied from `sharedMods` on Windows and symlinked on Linux, this means that when mods are removed from `sharedMods` the mods will also be removed from the instance's `mods` folder on Linux if it got there by being linked by Clusterio, but not on Windows.
|
||||||
|
|
||||||
For managing the mod settings, the `mod-settings.dat` and `mod-list.json` files will also be linked/copied over if present in `sharedMods`, but since Factorio creates these files automatically it might be necessary to delete them from each instance's `mods` folder for changes to them in `sharedMods` to take effect.
|
For managing the mod settings, the `mod-settings.dat` and `mod-list.json` files will also be linked/copied over if present in `sharedMods`, but since Factorio creates these files automatically it might be necessary to delete them from each instance's `mods` folder for changes to them in `sharedMods` to take effect.
|
||||||
@@ -218,51 +218,51 @@ Better remote management of mods is a planned feature.
|
|||||||
|
|
||||||
## Setting up shared storage
|
## Setting up shared storage
|
||||||
|
|
||||||
The chests teleporting items to and from the shared storage on the master server has been moved into the Subspace Storage mod and plugin.
|
The chests teleporting items to and from the shared storage on the controller has been moved into the Subspace Storage mod and plugin.
|
||||||
To get this to work you will need to install the Subspace Storage plugin and copy the [Subspace Storage mod](https://mods.factorio.com/mod/subspace_storage) and the [Clusterio Lib mod](https://mods.factorio.com/mod/clusterio_lib) into the `sharedMods` folder on each slave installation.
|
To get this to work you will need to install the Subspace Storage plugin and copy the [Subspace Storage mod](https://mods.factorio.com/mod/subspace_storage) and the [Clusterio Lib mod](https://mods.factorio.com/mod/clusterio_lib) into the `sharedMods` folder on each host installation.
|
||||||
|
|
||||||
Do not install the [Clusterio mod](https://mods.factorio.com/mod/clusterio), this was for the old 1.2.x version of Clusterio and is not compatible with Clusterio 2.0.
|
Do not install the [Clusterio mod](https://mods.factorio.com/mod/clusterio), this was for the old 1.2.x version of Clusterio and is not compatible with Clusterio 2.0.
|
||||||
|
|
||||||
|
|
||||||
## Running Clusterio
|
## Running Clusterio
|
||||||
|
|
||||||
After completing the installation start up the master server and at least one slave separately.
|
After completing the installation start up the controller and at least one host separately.
|
||||||
The installer provides the `run-master` and `run-slave` scripts to make this simple.
|
The installer provides the `run-controller` and `run-host` scripts to make this simple.
|
||||||
Once the master process is running you can log into the web interface which is hosted by default on http://localhost:8080/ (adjust the port number if you changed it), use the admin authentication token provided from the installation to log in.
|
Once the controller process is running you can log into the web interface which is hosted by default on http://localhost:8080/ (adjust the port number if you changed it), use the admin authentication token provided from the installation to log in.
|
||||||
|
|
||||||
The basics of setting up a Factorio server from the web interface is to create an instance, assign it to a slave and then click start.
|
The basics of setting up a Factorio server from the web interface is to create an instance, assign it to a host and then click start.
|
||||||
|
|
||||||
### Running via Systemd
|
### Running via Systemd
|
||||||
|
|
||||||
The install script creates systemd service scripts for clusteriomaster and clusterioslave (if applicable) to start up as the user than ran the installer.
|
The install script creates systemd service scripts for clusteriocontroller and clusteriohost (if applicable) to start up as the user than ran the installer.
|
||||||
If you have copied these files over to `/etc/systemd/system/` then you can startup Clusterio as a background service using:
|
If you have copied these files over to `/etc/systemd/system/` then you can startup Clusterio as a background service using:
|
||||||
|
|
||||||
#### To start as a service run:
|
#### To start as a service run:
|
||||||
|
|
||||||
sudo systemctl start clusteriomaster # for the master server
|
sudo systemctl start clusteriocontroller # for the controller
|
||||||
sudo systemctl start clusterioslave # for each server hosting a slave
|
sudo systemctl start clusteriohost # for each physical server intended to host Factorio servers
|
||||||
|
|
||||||
#### To automatically get it to start on boot:
|
#### To automatically get it to start on boot:
|
||||||
|
|
||||||
sudo systemctl enable clusteriomaster # for the master server
|
sudo systemctl enable clusteriocontroller # for the controller
|
||||||
sudo systemctl enable clusterioslave # for each server hosting a slave
|
sudo systemctl enable clusteriohost # for each physical server intended to host Factorio servers
|
||||||
|
|
||||||
|
|
||||||
## Setting up remote slaves
|
## Setting up remote hosts
|
||||||
|
|
||||||
Run the installer as described in the installation section and choose "Slave only" as the operating mode to install, it'll ask for a master URL and an authentication token.
|
Run the installer as described in the installation section and choose "Host only" as the operating mode to install, it'll ask for a controller URL and an authentication token.
|
||||||
The URL is the same as what is needed to connect to the web interface, and the authentication token can be generated on the Slaves page in the web interface.
|
The URL is the same as what is needed to connect to the web interface, and the authentication token can be generated on the Hosts page in the web interface.
|
||||||
Once you start up the slave it should show up in the Slaves list and be available for assigning and running instances on.
|
Once you start up the host it should show up in the Hosts list and be available for assigning and running instances on.
|
||||||
|
|
||||||
|
|
||||||
## Setting up clusterioctl
|
## Setting up clusterioctl
|
||||||
|
|
||||||
There's a command line interface available for Clusterio which is installed separately with the same installer as for the master and slave.
|
There's a command line interface available for Clusterio which is installed separately with the same installer as for the controller and host.
|
||||||
Run the installer as described in the installation section and choose "Ctl only" as the operating mode to install, you can do this in the same directory as you have installed other Clusterio component(s) to.
|
Run the installer as described in the installation section and choose "Ctl only" as the operating mode to install, you can do this in the same directory as you have installed other Clusterio component(s) to.
|
||||||
The installer will ask for a master URL and an authentication token, these are the same as you would use to connect to the web interface.
|
The installer will ask for a controller URL and an authentication token, these are the same as you would use to connect to the web interface.
|
||||||
If you want to use a different user for the command line interface, you can generate an authentication token for an existing user with
|
If you want to use a different user for the command line interface, you can generate an authentication token for an existing user with
|
||||||
|
|
||||||
npx clusteriomaster bootstrap generate-user-token <username>
|
npx clusteriocontroller bootstrap generate-user-token <username>
|
||||||
|
|
||||||
|
|
||||||
## Common problems
|
## Common problems
|
||||||
@@ -276,7 +276,7 @@ According to [this link](https://askubuntu.com/questions/839520/open-port-443-fo
|
|||||||
|
|
||||||
sudo setcap 'cap_net_bind_service=+ep' $(readlink -f $(which node))
|
sudo setcap 'cap_net_bind_service=+ep' $(readlink -f $(which node))
|
||||||
|
|
||||||
### Port forwarding doesn't work on the master server when running under WSL
|
### Port forwarding doesn't work on the controller when running under WSL
|
||||||
|
|
||||||
If you follow the ubuntu guide on WSL (Windows Subsystem for Linux, Bash on Ubuntu on Windows specifically), you will find that the website works on localhost and on your local ip, but not on the global ip.
|
If you follow the ubuntu guide on WSL (Windows Subsystem for Linux, Bash on Ubuntu on Windows specifically), you will find that the website works on localhost and on your local ip, but not on the global ip.
|
||||||
This is also true when you correctly port-forwarded the correct ports.
|
This is also true when you correctly port-forwarded the correct ports.
|
||||||
|
|||||||
+4
-4
@@ -1,9 +1,9 @@
|
|||||||
version: '3'
|
version: '3'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
master:
|
controller:
|
||||||
build: .
|
build: .
|
||||||
command: npx clusteriomaster run
|
command: npx clusteriocontroller run
|
||||||
slave:
|
host:
|
||||||
build: .
|
build: .
|
||||||
command: npx clusterioslave run
|
command: npx clusteriohost run
|
||||||
@@ -11,8 +11,8 @@ Links represents one side of a two way communication pipe, connectors deal with
|
|||||||
The Link class represents one side of a two way communication channel where the actual communication is done by a connector associated with the link.
|
The Link class represents one side of a two way communication channel where the actual communication is done by a connector associated with the link.
|
||||||
The link also knows what the endpoint types it's connected to are via the source and target attributes.
|
The link also knows what the endpoint types it's connected to are via the source and target attributes.
|
||||||
|
|
||||||
The endpoint types currently implemented are master, slave, instance, and control.
|
The endpoint types currently implemented are controller, host, instance, and control.
|
||||||
Although slave and instances run in the same Node.js program they use virtual links to communicate between them in order to simplify the communication architecture.
|
Although host and instances run in the same Node.js program they use virtual links to communicate between them in order to simplify the communication architecture.
|
||||||
|
|
||||||
Upon creation the link will register with the connector in order to receive and process messages from it.
|
Upon creation the link will register with the connector in order to receive and process messages from it.
|
||||||
The messages received are validated using the validator registered for the type of the message.
|
The messages received are validated using the validator registered for the type of the message.
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
<sub>This document describes the implementation and inner working of the configuration system in Clusterio, and unless you're developing Clusterio it's probably not going to be very useful for you.</sub>
|
<sub>This document describes the implementation and inner working of the configuration system in Clusterio, and unless you're developing Clusterio it's probably not going to be very useful for you.</sub>
|
||||||
|
|
||||||
Clusterio uses a group based configuration system to manage settings for the master server, instances, slaves, and the clusterioctl utility.
|
Clusterio uses a group based configuration system to manage settings for the controller, instances, hosts, and the clusterioctl utility.
|
||||||
Plugins get their own config group for the master server and instances which they can add their own fields to.
|
Plugins get their own config group for the controller and instances which they can add their own fields to.
|
||||||
The fields are defined early in the startup, and the groups and their fields for disabled plugins will still be created.
|
The fields are defined early in the startup, and the groups and their fields for disabled plugins will still be created.
|
||||||
|
|
||||||
The built-in config groups and their fields are defined in [packages/lib/config/definitions.js](/packages/lib/config/definitions.js) while plugins can add their own config groups to the `MasterConfigGroup` and `InstanceConfigGroup` properties of the `info.js` export using subclasses of `PluginConfigGroup`.
|
The built-in config groups and their fields are defined in [packages/lib/config/definitions.js](/packages/lib/config/definitions.js) while plugins can add their own config groups to the `ControllerConfigGroup` and `InstanceConfigGroup` properties of the `info.js` export using subclasses of `PluginConfigGroup`.
|
||||||
The plugin group has the enabled field pre-defined on it, and it's used to enable/disable plugins.
|
The plugin group has the enabled field pre-defined on it, and it's used to enable/disable plugins.
|
||||||
|
|
||||||
|
|
||||||
@@ -17,10 +17,10 @@ The `define` method takes an object as argument with the following properties:
|
|||||||
|
|
||||||
**access**:
|
**access**:
|
||||||
The locations this config field can be read and modified from.
|
The locations this config field can be read and modified from.
|
||||||
This is an array of strings which can contain the values `"master"`, `"slave"` and `"control"`.
|
This is an array of strings which can contain the values `"controller"`, `"host"` and `"control"`.
|
||||||
If a party is missing in this array then that party will not receive the value of this field when the config is shared, and will be unable to modify the field.
|
If a party is missing in this array then that party will not receive the value of this field when the config is shared, and will be unable to modify the field.
|
||||||
Takes the value of `defaultAccess` set on the config group class if not passed.
|
Takes the value of `defaultAccess` set on the config group class if not passed.
|
||||||
Note that instance config groups should have both `"master"` and `"slave"` for all of its fields or unexpected behaviour may occur.
|
Note that instance config groups should have both `"controller"` and `"host"` for all of its fields or unexpected behaviour may occur.
|
||||||
|
|
||||||
**type**:
|
**type**:
|
||||||
The type of config value this field will support.
|
The type of config value this field will support.
|
||||||
@@ -73,6 +73,6 @@ Values for all config fields are created when the config is initialized, as well
|
|||||||
Once a field has a value it is never automatically removed, even if the field or group it was part of no longer exists.
|
Once a field has a value it is never automatically removed, even if the field or group it was part of no longer exists.
|
||||||
This ensures that plugin configuration is not lost should the server be started up without the plugins that defined the configuration installed.
|
This ensures that plugin configuration is not lost should the server be started up without the plugins that defined the configuration installed.
|
||||||
|
|
||||||
For instance configs, they are kept on the master server and serialized and sent over to the relevant slaves on startup.
|
For instance configs, they are kept on the controller and serialized and sent over to the relevant hosts on startup.
|
||||||
This makes it possible to edit instance configs when the slave the instance is on is offline.
|
This makes it possible to edit instance configs when the host the instance is on is offline.
|
||||||
A copy is also stored in the instance directory on the slave, and this config will be deliverd to the master server on slave startup, which enables instances to be copied between clusters as long as their IDs are unique.
|
A copy is also stored in the instance directory on the host, and this config will be deliverd to the controller on host startup, which enables instances to be copied between clusters as long as their IDs are unique.
|
||||||
+67
-67
@@ -1,9 +1,9 @@
|
|||||||
# Configuration
|
# Configuration
|
||||||
|
|
||||||
|
|
||||||
## Master Configuration
|
## Controller Configuration
|
||||||
|
|
||||||
### master.name
|
### controller.name
|
||||||
|
|
||||||
Name of the cluster.
|
Name of the cluster.
|
||||||
Used to distinguish it from other clusters and is prepended to the name of servers in the server list.
|
Used to distinguish it from other clusters and is prepended to the name of servers in the server list.
|
||||||
@@ -11,37 +11,37 @@ Used to distinguish it from other clusters and is prepended to the name of serve
|
|||||||
Defaluts to "Your Cluster".
|
Defaluts to "Your Cluster".
|
||||||
|
|
||||||
|
|
||||||
### master.database_directory
|
### controller.database_directory
|
||||||
|
|
||||||
Directory used to store cluster data to.
|
Directory used to store cluster data to.
|
||||||
Needs to be writeable by the master server.
|
Needs to be writeable by the controller.
|
||||||
This is also used by plugins to store its data.
|
This is also used by plugins to store its data.
|
||||||
|
|
||||||
Defaults to "database".
|
Defaults to "database".
|
||||||
|
|
||||||
|
|
||||||
### master.http_port
|
### controller.http_port
|
||||||
|
|
||||||
Port to host HTTP server on.
|
Port to host HTTP server on.
|
||||||
If set to null no HTTP server will be exposed.
|
If set to null no HTTP server will be exposed.
|
||||||
At least one of this and master.https_port needs to be set to a port.
|
At least one of this and controller.https_port needs to be set to a port.
|
||||||
|
|
||||||
Defaults to 8080.
|
Defaults to 8080.
|
||||||
|
|
||||||
|
|
||||||
### master.https_port
|
### controller.https_port
|
||||||
|
|
||||||
Port to host HTTPS server on.
|
Port to host HTTPS server on.
|
||||||
Uses master.tls_certificate and master.tls_private_key as the certificate and private key for the HTTPS server.
|
Uses controller.tls_certificate and controller.tls_private_key as the certificate and private key for the HTTPS server.
|
||||||
If set to null no HTTPS server will be exposed.
|
If set to null no HTTPS server will be exposed.
|
||||||
At least one of this and master.http_port needs to be set to a port.
|
At least one of this and controller.http_port needs to be set to a port.
|
||||||
|
|
||||||
See the [Setting up TLS](/docs/setting-up-tls.md) document for a guide to setting up HTTPS with Clusterio.
|
See the [Setting up TLS](/docs/setting-up-tls.md) document for a guide to setting up HTTPS with Clusterio.
|
||||||
|
|
||||||
Defaults to null.
|
Defaults to null.
|
||||||
|
|
||||||
|
|
||||||
### master.bind_address
|
### controller.bind_address
|
||||||
|
|
||||||
IP address to bind the HTTP and HTTPS ports on.
|
IP address to bind the HTTP and HTTPS ports on.
|
||||||
Useful to limit which interface to accept connections from.
|
Useful to limit which interface to accept connections from.
|
||||||
@@ -51,39 +51,39 @@ interfaces.
|
|||||||
Defaults to null.
|
Defaults to null.
|
||||||
|
|
||||||
|
|
||||||
### master.external_address
|
### controller.external_address
|
||||||
|
|
||||||
External address the master server is accessible on.
|
External address the controller is accessible on.
|
||||||
Currently only used for `clusteriomaster bootstrap create-ctl-config` in order to give the right url to connect to.
|
Currently only used for `clusteriocontroller bootstrap create-ctl-config` in order to give the right url to connect to.
|
||||||
This should be a full URL ending with a /.
|
This should be a full URL ending with a /.
|
||||||
|
|
||||||
Defaults to null meaning assume localhost.
|
Defaults to null meaning assume localhost.
|
||||||
|
|
||||||
|
|
||||||
### master.tls_certificate
|
### controller.tls_certificate
|
||||||
|
|
||||||
Path to TLS certificate to use for the HTTPS server when master.https_port is configured.
|
Path to TLS certificate to use for the HTTPS server when controller.https_port is configured.
|
||||||
|
|
||||||
Defaults to "database/certificates/cert.crt".
|
Defaults to "database/certificates/cert.crt".
|
||||||
|
|
||||||
|
|
||||||
### master.tls_private_key
|
### controller.tls_private_key
|
||||||
|
|
||||||
Path to TLS private key to use for the HTTPS server when master.https_port is configured.
|
Path to TLS private key to use for the HTTPS server when controller.https_port is configured.
|
||||||
|
|
||||||
Defaults to "database/certificates/cert.key".
|
Defaults to "database/certificates/cert.key".
|
||||||
|
|
||||||
|
|
||||||
### master.auth_secret
|
### controller.auth_secret
|
||||||
|
|
||||||
Base64 encoded authentication secret used to verify tokens issued to slaves, users, and sessions.
|
Base64 encoded authentication secret used to verify tokens issued to hosts, users, and sessions.
|
||||||
This should contain 256 bytes of random data, and if changed will cause all tokens become invalid.
|
This should contain 256 bytes of random data, and if changed will cause all tokens become invalid.
|
||||||
Keep this secret if leaked an attacker could easily compromise the cluster.
|
Keep this secret if leaked an attacker could easily compromise the cluster.
|
||||||
|
|
||||||
Defaults to null which means generate a secure secret on startup.
|
Defaults to null which means generate a secure secret on startup.
|
||||||
|
|
||||||
|
|
||||||
### master.heartbeat_interval
|
### controller.heartbeat_interval
|
||||||
|
|
||||||
Interval in seconds heartbeats are sent out at for WebSocket connections.
|
Interval in seconds heartbeats are sent out at for WebSocket connections.
|
||||||
If a WebSocket connection hasn't received a heartbeat in 2 times the heartbeat interval it will be considered stale and closed.
|
If a WebSocket connection hasn't received a heartbeat in 2 times the heartbeat interval it will be considered stale and closed.
|
||||||
@@ -92,33 +92,33 @@ A lower value means less time between connections going stale and them being clo
|
|||||||
Defaults to 15.
|
Defaults to 15.
|
||||||
|
|
||||||
|
|
||||||
### master.session_timeout
|
### controller.session_timeout
|
||||||
|
|
||||||
Time in seconds from the connection is closed following a heartbeat timeout until the session is invalidated and data loss occurs.
|
Time in seconds from the connection is closed following a heartbeat timeout until the session is invalidated and data loss occurs.
|
||||||
A higher timeout gives more time for a client to recconect and resume an active session over a connection that was dropped, but also leads to stale connections taking longer to clear out.
|
A higher timeout gives more time for a client to recconect and resume an active session over a connection that was dropped, but also leads to stale connections taking longer to clear out.
|
||||||
In the case of the master or client crashing the data loss is unavoidable.
|
In the case of the controller or client crashing the data loss is unavoidable.
|
||||||
|
|
||||||
Value should not be less than the configured `max_reconnect_delay` of the clients and it should be greater than 2 times `master.heartbeat_interval`.
|
Value should not be less than the configured `max_reconnect_delay` of the clients and it should be greater than 2 times `controller.heartbeat_interval`.
|
||||||
Defaults to 60.
|
Defaults to 60.
|
||||||
|
|
||||||
|
|
||||||
### master.metrics_timeout
|
### controller.metrics_timeout
|
||||||
|
|
||||||
Timeout in seconds before a call to gather metrics from a slave times out.
|
Timeout in seconds before a call to gather metrics from a host times out.
|
||||||
This should be less than both the timeout and collection interval configured for the collection job in Prometheus.
|
This should be less than both the timeout and collection interval configured for the collection job in Prometheus.
|
||||||
|
|
||||||
Defaults to 8.
|
Defaults to 8.
|
||||||
|
|
||||||
|
|
||||||
### master.stream_timeout
|
### controller.stream_timeout
|
||||||
|
|
||||||
Timeout in seconds for proxy streams through the master that has been created but is not yet sending data to be automatically closed.
|
Timeout in seconds for proxy streams through the controller that has been created but is not yet sending data to be automatically closed.
|
||||||
Streams that have started sending data before this timeout is not affected.
|
Streams that have started sending data before this timeout is not affected.
|
||||||
|
|
||||||
Defaults to 15.
|
Defaults to 15.
|
||||||
|
|
||||||
|
|
||||||
### master.default_role_id
|
### controller.default_role_id
|
||||||
|
|
||||||
Role to automatically grant to new users.
|
Role to automatically grant to new users.
|
||||||
If null no role is granted.
|
If null no role is granted.
|
||||||
@@ -128,30 +128,30 @@ Defaults to 1 which correspond to the default Player role.
|
|||||||
|
|
||||||
### <plugin_name>.load_plugin
|
### <plugin_name>.load_plugin
|
||||||
|
|
||||||
Whether to load the plugin on the master server.
|
Whether to load the plugin on the controller.
|
||||||
Plugins not loaded on the master server will not be loaded on instances.
|
Plugins not loaded on the controller will not be loaded on instances.
|
||||||
|
|
||||||
Defaults to true.
|
Defaults to true.
|
||||||
|
|
||||||
|
|
||||||
## Slave Configuration
|
## Host Configuration
|
||||||
|
|
||||||
### slave.name
|
### host.name
|
||||||
|
|
||||||
Name of the slave.
|
Name of the host.
|
||||||
Shows up in slave lists and is used to reference this slave in the clusterioctl command line interface.
|
Shows up in host lists and is used to reference this host in the clusterioctl command line interface.
|
||||||
|
|
||||||
Defaults to "New Slave".
|
Defaults to "New Host".
|
||||||
|
|
||||||
|
|
||||||
### slave.id
|
### host.id
|
||||||
|
|
||||||
Immutable numeric id of the slave which uniquely identifies this slave in the cluster.
|
Immutable numeric id of the host which uniquely identifies this host in the cluster.
|
||||||
|
|
||||||
Defaults to a random 31 bit number.
|
Defaults to a random 31 bit number.
|
||||||
|
|
||||||
|
|
||||||
### slave.factorio_directory
|
### host.factorio_directory
|
||||||
|
|
||||||
Directory to look for the Factorio server(s) in.
|
Directory to look for the Factorio server(s) in.
|
||||||
This can either point to a Factorio server directory, or to a directory containing multiple versions of the Factorio server.
|
This can either point to a Factorio server directory, or to a directory containing multiple versions of the Factorio server.
|
||||||
@@ -159,48 +159,48 @@ This can either point to a Factorio server directory, or to a directory containi
|
|||||||
Defaults to "factorio".
|
Defaults to "factorio".
|
||||||
|
|
||||||
|
|
||||||
### slave.instances_directory
|
### host.instances_directory
|
||||||
|
|
||||||
Directory to store instances in.
|
Directory to store instances in.
|
||||||
One sub-directory will be created in it for each instance assigned to this slave and these sub-directories will contain logs, saves, and various auto generated configuration files for the instances.
|
One sub-directory will be created in it for each instance assigned to this host and these sub-directories will contain logs, saves, and various auto generated configuration files for the instances.
|
||||||
|
|
||||||
Defaults to "instances".
|
Defaults to "instances".
|
||||||
|
|
||||||
|
|
||||||
### slave.master_url
|
### host.controller_url
|
||||||
|
|
||||||
URL to connect to the master server to.
|
URL to connect to the controller to.
|
||||||
|
|
||||||
Defaults to "http://localhost:8080/".
|
Defaults to "http://localhost:8080/".
|
||||||
|
|
||||||
|
|
||||||
### slave.master_token
|
### host.controller_token
|
||||||
|
|
||||||
Access token used for authenticating with the master server.
|
Access token used for authenticating with the controller.
|
||||||
You can generate an access token with `clusterioctl slave generate-token --id <slave-id>`, or use the `clusterioctl slave create-config` to create a new slave config with the correct url and token in it.
|
You can generate an access token with `clusterioctl host generate-token --id <host-id>`, or use the `clusterioctl host create-config` to create a new host config with the correct url and token in it.
|
||||||
|
|
||||||
Defaults to "enter token here".
|
Defaults to "enter token here".
|
||||||
|
|
||||||
|
|
||||||
### slave.tls_ca
|
### host.tls_ca
|
||||||
|
|
||||||
Path to certificate in PEM format to use for validating a TLS connection to the master server.
|
Path to certificate in PEM format to use for validating a TLS connection to the controller.
|
||||||
If you have a self signed certificate on the master server you will need to copy the certificate to your slaves and set it as the certificate authority with this option.
|
If you have a self signed certificate on the controller you will need to copy the certificate to your hosts and set it as the certificate authority with this option.
|
||||||
|
|
||||||
Defaults to null meaning use Node.js's default set of trusted certificate authorities.
|
Defaults to null meaning use Node.js's default set of trusted certificate authorities.
|
||||||
|
|
||||||
|
|
||||||
### slave.public_address
|
### host.public_address
|
||||||
|
|
||||||
External address instances hosted on this slave can be accessed on.
|
External address instances hosted on this host can be accessed on.
|
||||||
This is used by plugins like Server Select to give the correct address to switch between instances in-game.
|
This is used by plugins like Server Select to give the correct address to switch between instances in-game.
|
||||||
|
|
||||||
Defaults to "localhost".
|
Defaults to "localhost".
|
||||||
|
|
||||||
|
|
||||||
### slave.max_reconnect_delay
|
### host.max_reconnect_delay
|
||||||
|
|
||||||
Maximum delay in seconds to wait after connection to the master server is dropped before attempting to reconnect to it.
|
Maximum delay in seconds to wait after connection to the controller is dropped before attempting to reconnect to it.
|
||||||
The actual delay on each reconnect will be a random number between 0 and this configured value to avoid all clients trying to reconnect at the same time.
|
The actual delay on each reconnect will be a random number between 0 and this configured value to avoid all clients trying to reconnect at the same time.
|
||||||
|
|
||||||
Defaults to 60.
|
Defaults to 60.
|
||||||
@@ -222,19 +222,19 @@ Imutable numeric id of the instance which uniquely identifies this instance in t
|
|||||||
Defaluts to a random 31 bit integer.
|
Defaluts to a random 31 bit integer.
|
||||||
|
|
||||||
|
|
||||||
### instance.assigned_slave
|
### instance.assigned_host
|
||||||
|
|
||||||
Slave this instance is assigned to.
|
Host this instance is assigned to.
|
||||||
To change this you need to use the separate assign instance interface.
|
To change this you need to use the separate assign instance interface.
|
||||||
After being assigned to a slave the directory for the instance is created on the slave.
|
After being assigned to a host the directory for the instance is created on the host.
|
||||||
|
|
||||||
Defaults to null meaning not assigned.
|
Defaults to null meaning not assigned.
|
||||||
|
|
||||||
|
|
||||||
### instance.auto_start
|
### instance.auto_start
|
||||||
|
|
||||||
If enabled start this instance when the slave it is assigned to is started up.
|
If enabled start this instance when the host it is assigned to is started up.
|
||||||
Does not affect start or stop of the instance while the slave is running.
|
Does not affect start or stop of the instance while the host is running.
|
||||||
|
|
||||||
Defaults to false.
|
Defaults to false.
|
||||||
|
|
||||||
@@ -242,7 +242,7 @@ Defaults to false.
|
|||||||
### factorio.version
|
### factorio.version
|
||||||
|
|
||||||
Version of Factorio to use for this instance.
|
Version of Factorio to use for this instance.
|
||||||
Can be a version like "1.0.0" or special string "latest" meaning the latest version of Factorio found on the slave.
|
Can be a version like "1.0.0" or special string "latest" meaning the latest version of Factorio found on the host.
|
||||||
|
|
||||||
Defaults to "latest".
|
Defaults to "latest".
|
||||||
|
|
||||||
@@ -383,39 +383,39 @@ Defaults to 5.
|
|||||||
### <plugin_name>.load_plugin
|
### <plugin_name>.load_plugin
|
||||||
|
|
||||||
Whether to load the given plugin on the instance.
|
Whether to load the given plugin on the instance.
|
||||||
Note that plugins need to be loaded on the master server in order for them to be loaded on instances.
|
Note that plugins need to be loaded on the controller in order for them to be loaded on instances.
|
||||||
|
|
||||||
Defaults to true.
|
Defaults to true.
|
||||||
|
|
||||||
|
|
||||||
## Control Configuration
|
## Control Configuration
|
||||||
|
|
||||||
### control.master_url
|
### control.controller_url
|
||||||
|
|
||||||
URL to connect to the master server to.
|
URL to connect to the controller to.
|
||||||
|
|
||||||
Defaults to null meaning complain about it not being set and exit.
|
Defaults to null meaning complain about it not being set and exit.
|
||||||
|
|
||||||
|
|
||||||
### control.master_token
|
### control.controller_token
|
||||||
|
|
||||||
Access token used for authenticating with the master server.
|
Access token used for authenticating with the controller.
|
||||||
You can generate an access token with `clusteriomaster bootstrap generate-user-token <username>`, or use the `clusteriomaster bootstrap create-ctl-config <username>` to create a new ctl config with the correct url and token in it.
|
You can generate an access token with `clusteriocontroller bootstrap generate-user-token <username>`, or use the `clusteriocontroller bootstrap create-ctl-config <username>` to create a new ctl config with the correct url and token in it.
|
||||||
|
|
||||||
Defaults to null meaning complain about it not being set and exit.
|
Defaults to null meaning complain about it not being set and exit.
|
||||||
|
|
||||||
|
|
||||||
### control.tls_ca
|
### control.tls_ca
|
||||||
|
|
||||||
Path to certificate in PEM format to use for validating a TLS connection to the master server.
|
Path to certificate in PEM format to use for validating a TLS connection to the controller.
|
||||||
If you have a self signed certificate on the master server you will need to copy the certificate to the computer you run clusterctl from and set it as the certificate authority with this option.
|
If you have a self signed certificate on the controller you will need to copy the certificate to the computer you run clusterctl from and set it as the certificate authority with this option.
|
||||||
|
|
||||||
Defaults to null meaning use Node.js's default set of trusted certificate authorities.
|
Defaults to null meaning use Node.js's default set of trusted certificate authorities.
|
||||||
|
|
||||||
|
|
||||||
### control.max_reconnect_delay
|
### control.max_reconnect_delay
|
||||||
|
|
||||||
Max duration in seconds to wait before attempting to reconnect with the master server after the connection is dropped.
|
Max duration in seconds to wait before attempting to reconnect with the controller after the connection is dropped.
|
||||||
The actual delay on each reconnect will be a random number between 0 and this configured value to avoid all clients trying to reconnect at the same time.
|
The actual delay on each reconnect will be a random number between 0 and this configured value to avoid all clients trying to reconnect at the same time.
|
||||||
|
|
||||||
Defaults to 60.
|
Defaults to 60.
|
||||||
@@ -68,17 +68,17 @@ The `plugins/` directory contains the core plugins for the project and can be ad
|
|||||||
|
|
||||||
The documentation uses the binaries provided by the packages, but for the development environment you will need to call the packages directly:
|
The documentation uses the binaries provided by the packages, but for the development environment you will need to call the packages directly:
|
||||||
|
|
||||||
npx clusteriomaster -> node packages/master
|
npx clusteriocontroller -> node packages/controller
|
||||||
npx clusterioslave -> node packages/slave
|
npx clusteriohost -> node packages/host
|
||||||
npx clusterioctl -> node packages/ctl
|
npx clusterioctl -> node packages/ctl
|
||||||
|
|
||||||
Note that to use `clusterioctl` you will have to create a control config first:
|
Note that to use `clusterioctl` you will have to create a control config first:
|
||||||
|
|
||||||
node packages/master bootstrap create-ctl-config [admin-user]
|
node packages/controller bootstrap create-ctl-config [admin-user]
|
||||||
|
|
||||||
Once you've set up the cluster you can use `node packages/master run` to run the master server and `node packages/slave run` to run the slave which connects to the master server.
|
Once you've set up the cluster you can use `node packages/controller run` to run the controller and `node packages/host run` to run the host which connects to the controller.
|
||||||
|
|
||||||
For web development on the master there are also the following flags:
|
For web development on the controller there are also the following flags:
|
||||||
|
|
||||||
`--dev` - Recompile the `web_ui` package on the fly providing live reloading of it.
|
`--dev` - Recompile the `web_ui` package on the fly providing live reloading of it.
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ For web development on the master there are also the following flags:
|
|||||||
|
|
||||||
These options can be combined and multiple plugins can be actived for dev mode.
|
These options can be combined and multiple plugins can be actived for dev mode.
|
||||||
Keep in mind if you're working on external plugins the `--dev-plugin` option is likely to only work if the plugin is placed inside the `external_plugins` directory and its dependencies are installed with pnpm as part of the clusterio repository workspace.
|
Keep in mind if you're working on external plugins the `--dev-plugin` option is likely to only work if the plugin is placed inside the `external_plugins` directory and its dependencies are installed with pnpm as part of the clusterio repository workspace.
|
||||||
Note that webpack is configured to delete the web interface build when using these options, so you will have to run `pnpm run -r --if-present prepare` before you start the master without these flags again.
|
Note that webpack is configured to delete the web interface build when using these options, so you will have to run `pnpm run -r --if-present prepare` before you start the controller without these flags again.
|
||||||
|
|
||||||
|
|
||||||
### Starting a Feature Branch
|
### Starting a Feature Branch
|
||||||
|
|||||||
+23
-23
@@ -12,9 +12,9 @@ Events and requests are defined as instances of the `Request` and `Event` classe
|
|||||||
All messages sent and received are validated with JSON schemas to catch potential errors in sending messages and avoid having to write lots of validation code in message handlers.
|
All messages sent and received are validated with JSON schemas to catch potential errors in sending messages and avoid having to write lots of validation code in message handlers.
|
||||||
|
|
||||||
Messages are sent by calling the `.send()` method of the message instance and passing a `Link` instance to send it over and the data to send.
|
Messages are sent by calling the `.send()` method of the message instance and passing a `Link` instance to send it over and the data to send.
|
||||||
For the master server there's a `Link` instance for each slave and control connection stored in the `WsServer` class.
|
For the controller there's a `Link` instance for each host and control connection stored in the `WsServer` class.
|
||||||
For slaves the `Slave` instance is a link to the master server, and each `Instance` instance is an in-memory link to the `Slave` instance and has a corresponding `InstanceConnection` link stored on the `Slave` instance.
|
For hosts the `Host` instance is a link to the controller, and each `Instance` instance is an in-memory link to the `Host` instance and has a corresponding `InstanceConnection` link stored on the `Host` instance.
|
||||||
For ctl and web_ui there's a `Control` instance that acts as the link to the master server.
|
For ctl and web_ui there's a `Control` instance that acts as the link to the controller.
|
||||||
|
|
||||||
Messages received invokes message handlers that were registered when the link was brought up.
|
Messages received invokes message handlers that were registered when the link was brought up.
|
||||||
These handlers are named after the name of the property the message is stored under with `EventHandler` appended for events and `RequestHandler` appended for requests.
|
These handlers are named after the name of the property the message is stored under with `EventHandler` appended for events and `RequestHandler` appended for requests.
|
||||||
@@ -24,7 +24,7 @@ The handlers are defined on the link class itself for core messages, and on the
|
|||||||
## Connection flow
|
## Connection flow
|
||||||
|
|
||||||
Clients connect via WebSocket to the `/api/socket` endpoint and upon establishing connection to the server the connection is in the handshake phase and the server will send a `hello` message to the client.
|
Clients connect via WebSocket to the `/api/socket` endpoint and upon establishing connection to the server the connection is in the handshake phase and the server will send a `hello` message to the client.
|
||||||
If the client has no previous session with the server it sends a `register_slave` or `register_control` message depending on what kind of client it is to the server.
|
If the client has no previous session with the server it sends a `register_host` or `register_control` message depending on what kind of client it is to the server.
|
||||||
If the register is valid then the server will respond with a `ready` message with a session token and the connection has left the handshake phase, otherwise the server will close the connection with a WebSocket close code indicating the kind of failure.
|
If the register is valid then the server will respond with a `ready` message with a session token and the connection has left the handshake phase, otherwise the server will close the connection with a WebSocket close code indicating the kind of failure.
|
||||||
|
|
||||||
Upon leaving the handshake phase both parties should start sending heartbeat messages with the sequence number of the last received message.
|
Upon leaving the handshake phase both parties should start sending heartbeat messages with the sequence number of the last received message.
|
||||||
@@ -33,7 +33,7 @@ Messages sent over the link should be stored in a send buffer and only cleared f
|
|||||||
If the connection goes stale or is unexpectedly closed the client can reastablish the same session by connecting to the server again and sending a `resume` message after received the `hello` from the server.
|
If the connection goes stale or is unexpectedly closed the client can reastablish the same session by connecting to the server again and sending a `resume` message after received the `hello` from the server.
|
||||||
If the session resume is successful then the server will respond with a `continue` message and the connection is active again.
|
If the session resume is successful then the server will respond with a `continue` message and the connection is active again.
|
||||||
The client should then re-send all messages it has in its send buffer that is greater than the `last_seq` number in the `continue` message.
|
The client should then re-send all messages it has in its send buffer that is greater than the `last_seq` number in the `continue` message.
|
||||||
Otherwise the server will respond with `invalidate` and the client is expected to drop its send buffer start a new session with `register_slave` or `register_control`.
|
Otherwise the server will respond with `invalidate` and the client is expected to drop its send buffer start a new session with `register_host` or `register_control`.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -96,23 +96,23 @@ The following messages are the only valid messages that can be sent during the h
|
|||||||
|
|
||||||
#### `hello`
|
#### `hello`
|
||||||
|
|
||||||
Sent by the master server when the WebSocket connection has been opened.
|
Sent by the controller when the WebSocket connection has been opened.
|
||||||
|
|
||||||
- `version: string` - The version of the master, e.g. "2.0.0".
|
- `version: string` - The version of the controller, e.g. "2.0.0".
|
||||||
- `plugins: Object<string, string>` -
|
- `plugins: Object<string, string>` -
|
||||||
Object mapping plugin names to plugin version for plugins that are loaded on the master server.
|
Object mapping plugin names to plugin version for plugins that are loaded on the controller.
|
||||||
|
|
||||||
#### `register_slave`
|
#### `register_host`
|
||||||
|
|
||||||
Slave handshake for establishing a new connection session.
|
Host handshake for establishing a new connection session.
|
||||||
|
|
||||||
- `token: string` - Authentication token.
|
- `token: string` - Authentication token.
|
||||||
- `agent: string` - Human readable string of the software connecting.
|
- `agent: string` - Human readable string of the software connecting.
|
||||||
- `version: string` - The protocol version of the slave, e.g. "2.0.0".
|
- `version: string` - The protocol version of the host, e.g. "2.0.0".
|
||||||
- `name: string` - Name of the slave.
|
- `name: string` - Name of the host.
|
||||||
- `id: integer` - ID of the slave.
|
- `id: integer` - ID of the host.
|
||||||
- `plugins: Object<string, string>` -
|
- `plugins: Object<string, string>` -
|
||||||
Object mapping plugin names to plugin version for plugins that are available on the slave.
|
Object mapping plugin names to plugin version for plugins that are available on the host.
|
||||||
|
|
||||||
#### `register_control`
|
#### `register_control`
|
||||||
|
|
||||||
@@ -131,12 +131,12 @@ Handshake for resuming an existing connection session where the connection had d
|
|||||||
|
|
||||||
#### `invalidate`
|
#### `invalidate`
|
||||||
|
|
||||||
Sent by the master server in reply to a resume for a session that cannot be resumed.
|
Sent by the controller in reply to a resume for a session that cannot be resumed.
|
||||||
The client should start a new session with a register\_\* message in response.
|
The client should start a new session with a register\_\* message in response.
|
||||||
|
|
||||||
#### `continue`
|
#### `continue`
|
||||||
|
|
||||||
Sent by the master server to signal resuming the session was successful.
|
Sent by the controller to signal resuming the session was successful.
|
||||||
|
|
||||||
- `last_seq: integer | null` - Last message seq received by the server.
|
- `last_seq: integer | null` - Last message seq received by the server.
|
||||||
- `session_timeout: integer` - Session timeout in seconds.
|
- `session_timeout: integer` - Session timeout in seconds.
|
||||||
@@ -144,7 +144,7 @@ Sent by the master server to signal resuming the session was successful.
|
|||||||
|
|
||||||
#### `ready`
|
#### `ready`
|
||||||
|
|
||||||
Sent by the master server to signal the connection has been established with a new session.
|
Sent by the controller to signal the connection has been established with a new session.
|
||||||
|
|
||||||
- `session_token: string` - Token to resume the session with.
|
- `session_token: string` - Token to resume the session with.
|
||||||
- `session_timeout: integer` - Session timeout in seconds.
|
- `session_timeout: integer` - Session timeout in seconds.
|
||||||
@@ -159,7 +159,7 @@ The heartbeat should contain the `seq` of the last received message, and receivi
|
|||||||
|
|
||||||
#### `heartbeat`
|
#### `heartbeat`
|
||||||
|
|
||||||
Sent by both the master server and clients at the interval given in the continue/ready messages.
|
Sent by both the controller and clients at the interval given in the continue/ready messages.
|
||||||
|
|
||||||
- `last_seq: integer` - Last message seq received over the link.
|
- `last_seq: integer` - Last message seq received over the link.
|
||||||
|
|
||||||
@@ -235,15 +235,15 @@ Server hello after opening the WebSocket.
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Slave registering a new connection session.
|
Host registering a new connection session.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"seq": null,
|
"seq": null,
|
||||||
"type": "register_slave",
|
"type": "register_host",
|
||||||
"data": {
|
"data": {
|
||||||
"token": "xyzabc123",
|
"token": "xyzabc123",
|
||||||
"agent": "Clusterio Slave",
|
"agent": "Clusterio Host",
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"name": "Foo",
|
"name": "Foo",
|
||||||
"id": 123
|
"id": 123
|
||||||
@@ -251,7 +251,7 @@ Slave registering a new connection session.
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Master server reply signaling the session is established and ready.
|
Controller reply signaling the session is established and ready.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
@@ -265,4 +265,4 @@ Master server reply signaling the session is established and ready.
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Slave and master can now send events and requests over the connection.
|
Host and controller can now send events and requests over the connection.
|
||||||
@@ -11,6 +11,6 @@ This can be disabled with the `factorio.enable_save_patching` config on a per in
|
|||||||
|
|
||||||
## User Accounts
|
## User Accounts
|
||||||
|
|
||||||
The master server creates and stores accounts for all Factorio users that log into instances under its control.
|
The controller creates and stores accounts for all Factorio users that log into instances under its control.
|
||||||
These accounts are used to store per player data and authorize management of the cluster.
|
These accounts are used to store per player data and authorize management of the cluster.
|
||||||
By default users accounts are assigned a Player role that gives a limited read access to the cluster resources, and admins of the cluster can be assigned a Cluster Admin role to get access to manage it.
|
By default users accounts are assigned a Player role that gives a limited read access to the cluster resources, and admins of the cluster can be assigned a Cluster Admin role to get access to manage it.
|
||||||
+4
-4
@@ -11,10 +11,10 @@
|
|||||||
},
|
},
|
||||||
"source": {
|
"source": {
|
||||||
"include": [
|
"include": [
|
||||||
"packages/master/src/",
|
"packages/controller/src/",
|
||||||
"packages/master/master.js",
|
"packages/controller/controller.js",
|
||||||
"packages/slave/src/",
|
"packages/host/src/",
|
||||||
"packages/slave/slave.js",
|
"packages/host/host.js",
|
||||||
"packages/ctl/src/",
|
"packages/ctl/src/",
|
||||||
"packages/ctl/ctl.js",
|
"packages/ctl/ctl.js",
|
||||||
"packages/lib/",
|
"packages/lib/",
|
||||||
|
|||||||
+14
-14
@@ -1,32 +1,32 @@
|
|||||||
# Managing a Cluster
|
# Managing a Cluster
|
||||||
|
|
||||||
Clusterio clusters are managed through the master server by using the `clusterioctl` command line interface which is invoked by running `npx clusterioctl <command>` in the clusterio directory.
|
Clusterio clusters are managed through the controller by using the `clusterioctl` command line interface which is invoked by running `npx clusterioctl <command>` in the clusterio directory.
|
||||||
This document uses the shorthand `ctl> foo` to indicate `npx clusterioctl foo` should be executed.
|
This document uses the shorthand `ctl> foo` to indicate `npx clusterioctl foo` should be executed.
|
||||||
Mandatory parameters are shown in `<angles bracket>` and optional pameters are in `[square brackets]`.
|
Mandatory parameters are shown in `<angles bracket>` and optional pameters are in `[square brackets]`.
|
||||||
|
|
||||||
Before `clusterioctl` can be used it needs to be configured for the cluster it will connect to.
|
Before `clusterioctl` can be used it needs to be configured for the cluster it will connect to.
|
||||||
The easiest way to do this is to run `npx clusteriomaster bootstrap create-ctl-config <username>` on the master server, which creates the necessary `config-control.json` for managing the cluster as the given user.
|
The easiest way to do this is to run `npx clusteriocontroller bootstrap create-ctl-config <username>` on the controller, which creates the necessary `config-control.json` for managing the cluster as the given user.
|
||||||
|
|
||||||
|
|
||||||
## Slaves
|
## Hosts
|
||||||
|
|
||||||
### List slaves
|
### List hosts
|
||||||
|
|
||||||
ctl> slave list
|
ctl> host list
|
||||||
|
|
||||||
Lists all slaves.
|
Lists all hosts.
|
||||||
|
|
||||||
### Generate token
|
### Generate token
|
||||||
|
|
||||||
ctl> slave generate-token [--id <slave id>]
|
ctl> host generate-token [--id <host id>]
|
||||||
|
|
||||||
Generate a token for a slave. `--id` is the slave id.
|
Generate a token for a host. `--id` is the host id.
|
||||||
|
|
||||||
### Create config
|
### Create config
|
||||||
|
|
||||||
ctl> slave create-config [--id <slave id>] [--name <slave name>] [--generate-token <bool>] [--output <path to output>]
|
ctl> host create-config [--id <host id>] [--name <host name>] [--generate-token <bool>] [--output <path to output>]
|
||||||
|
|
||||||
Create a slave config. `--id` id the slave id. `--name` is the slave name. `--generate-token` decides whether to also generate a token, defaulting to `0`. `--output` is the filename for the output of the config; Default is "config-slave.json", "-" for stdout.
|
Create a host config. `--id` id the host id. `--name` is the host name. `--generate-token` decides whether to also generate a token, defaulting to `0`. `--output` is the filename for the output of the config; Default is "config-host.json", "-" for stdout.
|
||||||
|
|
||||||
## Instances
|
## Instances
|
||||||
|
|
||||||
@@ -85,11 +85,11 @@ To be written.
|
|||||||
|
|
||||||
Edit instance config in a text editor. Once file is saved and editor has been exited, config values will be read back in. `instance` is the instance to edit, `editor` is the editor to use. If `editor` is not given, clusterioctl will read from the `EDITOR` or `VISUAL` enviroment variables.
|
Edit instance config in a text editor. Once file is saved and editor has been exited, config values will be read back in. `instance` is the instance to edit, `editor` is the editor to use. If `editor` is not given, clusterioctl will read from the `EDITOR` or `VISUAL` enviroment variables.
|
||||||
|
|
||||||
### Assign instance to slave
|
### Assign instance to host
|
||||||
|
|
||||||
ctl> instace assign <instance> [slave]
|
ctl> instace assign <instance> [host]
|
||||||
|
|
||||||
Assigns instance to slave. `instance` is instance to assign, `slave` is slave to assign to. If `slave` is not provided, instance will be unassigned.
|
Assigns instance to host. `instance` is instance to assign, `host` is host to assign to. If `host` is not provided, instance will be unassigned.
|
||||||
|
|
||||||
## Users
|
## Users
|
||||||
|
|
||||||
@@ -189,7 +189,7 @@ By default there's a roled named Cluster Admin which grants access to everything
|
|||||||
|
|
||||||
ctl> user delete <name>
|
ctl> user delete <name>
|
||||||
|
|
||||||
Deletes everything stored on the master server for this user.
|
Deletes everything stored on the controller for this user.
|
||||||
|
|
||||||
Note: If the player is banned from the cluster this will effectively unban them, as the ban status is stored with the user account.
|
Note: If the player is banned from the cluster this will effectively unban them, as the ban status is stored with the user account.
|
||||||
|
|
||||||
|
|||||||
+11
-11
@@ -1,7 +1,7 @@
|
|||||||
# Setting up TLS
|
# Setting up TLS
|
||||||
|
|
||||||
By default Clusterio will listen for connections over HTTP which is fine for local networks but over the Internet it should idealy be over HTTPS as there are some credentials that could be exposed to eavesdroppers.
|
By default Clusterio will listen for connections over HTTP which is fine for local networks but over the Internet it should idealy be over HTTPS as there are some credentials that could be exposed to eavesdroppers.
|
||||||
The recommended setup is to have an ordinary HTTPS server software like Apache or Nginx to act as a reverse proxy in front of the Clusterio master server.
|
The recommended setup is to have an ordinary HTTPS server software like Apache or Nginx to act as a reverse proxy in front of the Clusterio controller.
|
||||||
The reverse proxy would then be set up with a TLS certificate from a Certificate Authoritiy like [Let's Encrypt](https://letsencrypt.org).
|
The reverse proxy would then be set up with a TLS certificate from a Certificate Authoritiy like [Let's Encrypt](https://letsencrypt.org).
|
||||||
Alternatively you can have Clusterio listen for connections over HTTPS directly by providing it with a TLS certificate and private key.
|
Alternatively you can have Clusterio listen for connections over HTTPS directly by providing it with a TLS certificate and private key.
|
||||||
|
|
||||||
@@ -11,17 +11,17 @@ See the last section for how to create and use a self-signed certificate for an
|
|||||||
|
|
||||||
## Using a reverse proxy
|
## Using a reverse proxy
|
||||||
|
|
||||||
Configure the proxy to forward requests over HTTP to the port the master server is listening to so that for example a request to `https://example.com/instances/` is forwarded to `http://localhost:8080/instances/`.
|
Configure the proxy to forward requests over HTTP to the port the controller is listening to so that for example a request to `https://example.com/instances/` is forwarded to `http://localhost:8080/instances/`.
|
||||||
It is possible to host the interface under a sub-path, in that case a request under the sub-path should be mapped to the master server with the sub-path stripped out.
|
It is possible to host the interface under a sub-path, in that case a request under the sub-path should be mapped to the controller with the sub-path stripped out.
|
||||||
For example `https://example.com/sub/path/instances/` would be mapped to `http://localhost:8080/instances`.
|
For example `https://example.com/sub/path/instances/` would be mapped to `http://localhost:8080/instances`.
|
||||||
|
|
||||||
Additianlly WebSocket connections to `/api/socket` also needs to be forwarded.
|
Additianlly WebSocket connections to `/api/socket` also needs to be forwarded.
|
||||||
Typically this requires explicit configuration and support for forwarding WebSocket connections.
|
Typically this requires explicit configuration and support for forwarding WebSocket connections.
|
||||||
If the interface hosted under a sub-path the `/api/socket` address is relative to the sub-path and the sub-path also needs to be stripped out when forwarded.
|
If the interface hosted under a sub-path the `/api/socket` address is relative to the sub-path and the sub-path also needs to be stripped out when forwarded.
|
||||||
|
|
||||||
You can also optionally set the master server to listen only on the loopback interface to prevent it being directly connected to from the outside.
|
You can also optionally set the controller to listen only on the loopback interface to prevent it being directly connected to from the outside.
|
||||||
|
|
||||||
npx clusteriomaster config set master.bind_address 127.0.0.1
|
npx clusteriocontroller config set controller.bind_address 127.0.0.1
|
||||||
|
|
||||||
|
|
||||||
### Apache Config
|
### Apache Config
|
||||||
@@ -44,7 +44,7 @@ Pay attention to the use of trailing slashes, as they are important.
|
|||||||
|
|
||||||
## Hosting HTTPS directly from Node.js
|
## Hosting HTTPS directly from Node.js
|
||||||
|
|
||||||
Listening on HTTPS is supported by the Clusterio master server via the `master.https_port` option provided paths to a certificate file and a private key file is configured for the `master.tls_certificate` and `master.tls_private_key` options.
|
Listening on HTTPS is supported by the Clusterio controller via the `controller.https_port` option provided paths to a certificate file and a private key file is configured for the `controller.tls_certificate` and `controller.tls_private_key` options.
|
||||||
Both of these are expected to be unencrypted PEM files.
|
Both of these are expected to be unencrypted PEM files.
|
||||||
|
|
||||||
|
|
||||||
@@ -58,14 +58,14 @@ substituting `<ip>` with the IP address the server will be accessed under, for e
|
|||||||
Multiple addresses can be given by supplying a comma sepparated list of `IP:address` pairs and DNS names can also be specified using the `DNS:example.com` format.
|
Multiple addresses can be given by supplying a comma sepparated list of `IP:address` pairs and DNS names can also be specified using the `DNS:example.com` format.
|
||||||
You need to supply every name you want to connect to the server under the subjectAltName field, for example to connect to the HTTPS port locally via an address like `https://localhost:4443/` you need to add `DNS:localhost`.
|
You need to supply every name you want to connect to the server under the subjectAltName field, for example to connect to the HTTPS port locally via an address like `https://localhost:4443/` you need to add `DNS:localhost`.
|
||||||
|
|
||||||
This creates a private key file named `key.pem` and a public certificate file named `cert.pem` and these are used for the `master.tls_certificate` and `master.tls_private_key` config options respectively on the master server:
|
This creates a private key file named `key.pem` and a public certificate file named `cert.pem` and these are used for the `controller.tls_certificate` and `controller.tls_private_key` config options respectively on the controller:
|
||||||
|
|
||||||
npx clusteriomaster config set master.tls_certificate cert.pem
|
npx clusteriocontroller config set controller.tls_certificate cert.pem
|
||||||
npx clusteriomaster config set master.tls_private_key key.pem
|
npx clusteriocontroller config set controller.tls_private_key key.pem
|
||||||
|
|
||||||
Additionally you will need copy the `cert.pem` file to all of the computers you want to set up as slaves and configure it as the `slave.tls_ca` option:
|
Additionally you will need copy the `cert.pem` file to all of the computers you want to set up as hosts and configure it as the `host.tls_ca` option:
|
||||||
|
|
||||||
npx clusterioslave config set slave.tls_ca cert.pem
|
npx clusteriohost config set host.tls_ca cert.pem
|
||||||
|
|
||||||
You will also need to copy the `cert.pem` file to all of the computers you want to remotely manage the cluster via clusterctl and configure it as `control.tls_ca` option:
|
You will also need to copy the `cert.pem` file to all of the computers you want to remotely manage the cluster via clusterctl and configure it as `control.tls_ca` option:
|
||||||
|
|
||||||
|
|||||||
+63
-63
@@ -27,7 +27,7 @@ The basic file structure of a plugin is the following.
|
|||||||
plugin_name/
|
plugin_name/
|
||||||
+- info.js
|
+- info.js
|
||||||
+- package.json
|
+- package.json
|
||||||
+- master.js
|
+- controller.js
|
||||||
+- instance.js
|
+- instance.js
|
||||||
+- control.js
|
+- control.js
|
||||||
+- test/
|
+- test/
|
||||||
@@ -41,7 +41,7 @@ The usual guides for creating such packages apply.
|
|||||||
At minimum the `package.json` file must contain a version entry.
|
At minimum the `package.json` file must contain a version entry.
|
||||||
|
|
||||||
A possible workflow for developing plugins is to place the plugin in a sub-directory of where clusterio has been installed, and rely on Node.js searching up the folder heirarchy for it to find `@clusterio/lib`.
|
A possible workflow for developing plugins is to place the plugin in a sub-directory of where clusterio has been installed, and rely on Node.js searching up the folder heirarchy for it to find `@clusterio/lib`.
|
||||||
To add it to `plugin-list.json` so that it gets loaded use the `plugin add <path>` sub-command to either clusteriomaster, clusterioslave or clusterioctl.
|
To add it to `plugin-list.json` so that it gets loaded use the `plugin add <path>` sub-command to either clusteriocontroller, clusteriohost or clusterioctl.
|
||||||
Note that it's important that the path starts with ./ or ../ (use .\ or ..\ on Windows).
|
Note that it's important that the path starts with ./ or ../ (use .\ or ..\ on Windows).
|
||||||
|
|
||||||
For a plugin the most important file is the `info.js` file.
|
For a plugin the most important file is the `info.js` file.
|
||||||
@@ -56,7 +56,7 @@ module.exports = {
|
|||||||
title: "Foo Frobber",
|
title: "Foo Frobber",
|
||||||
description: "Does advanced frobnication",
|
description: "Does advanced frobnication",
|
||||||
instanceEntrypoint: "instance",
|
instanceEntrypoint: "instance",
|
||||||
masterEntrypoint: "master",
|
controllerEntrypoint: "controller",
|
||||||
messages: {
|
messages: {
|
||||||
/* See below */
|
/* See below */
|
||||||
},
|
},
|
||||||
@@ -80,19 +80,19 @@ The following properties are recognized:
|
|||||||
**instanceEntrypoint**:
|
**instanceEntrypoint**:
|
||||||
Path to a Node.js module relative to the plugin directory which contains the InstancePlugin class definition for this plugin.
|
Path to a Node.js module relative to the plugin directory which contains the InstancePlugin class definition for this plugin.
|
||||||
This is an optional paramater.
|
This is an optional paramater.
|
||||||
A plugin may have code only for instances but it must still be loaded on the master in order for it to be possible to load it on an instance.
|
A plugin may have code only for instances but it must still be loaded on the controller in order for it to be possible to load it on an instance.
|
||||||
|
|
||||||
**InstanceConfigGroup**:
|
**InstanceConfigGroup**:
|
||||||
Subclass of `PluginConfigGroup` for defining the per instance configuration fields for this plugin.
|
Subclass of `PluginConfigGroup` for defining the per instance configuration fields for this plugin.
|
||||||
See [Plugin Configuration](#plugin-configuration)
|
See [Plugin Configuration](#plugin-configuration)
|
||||||
|
|
||||||
**masterEntrypoint**:
|
**controllerEntrypoint**:
|
||||||
Path to a Node.js module relative to the plugin directory which contains the MasterPlugin class definiton for this plugin.
|
Path to a Node.js module relative to the plugin directory which contains the ControllerPlugin class definiton for this plugin.
|
||||||
This is an optional parameter.
|
This is an optional parameter.
|
||||||
A plugin can be made that only runs on the master server.
|
A plugin can be made that only runs on the controller.
|
||||||
|
|
||||||
**MasterConfigGroup**:
|
**ControllerConfigGroup**:
|
||||||
Subclass of `PluginConfigGroup` for defining the master server configuration fields for this plugin.
|
Subclass of `PluginConfigGroup` for defining the controller configuration fields for this plugin.
|
||||||
See [Plugin Configuration](#plugin-configuration)
|
See [Plugin Configuration](#plugin-configuration)
|
||||||
|
|
||||||
**controlEntrypoint**:
|
**controlEntrypoint**:
|
||||||
@@ -108,21 +108,21 @@ The optional module folder contains a Clusterio module that will be patched into
|
|||||||
See the section on [Clusterio Modules](developing-for-clusterio.md) in the Developing for Clusterio document.
|
See the section on [Clusterio Modules](developing-for-clusterio.md) in the Developing for Clusterio document.
|
||||||
The only restriction imposed on modules embedded into plugins is that they must be named the same as the plugin.
|
The only restriction imposed on modules embedded into plugins is that they must be named the same as the plugin.
|
||||||
|
|
||||||
While there is no standard for how to organize a plugin it's recommended to put the MasterPlugin class definition into master.js and the InstancePlugin class definition into instance.js.
|
While there is no standard for how to organize a plugin it's recommended to put the ControllerPlugin class definition into controller.js and the InstancePlugin class definition into instance.js.
|
||||||
You can put them into whatever file you want (even the same one for both).
|
You can put them into whatever file you want (even the same one for both).
|
||||||
|
|
||||||
For both instanceEntrypoint and masterEntrypoint the path should not end with .js and it should use forward slashes for directory separators if any.
|
For both instanceEntrypoint and controllerEntrypoint the path should not end with .js and it should use forward slashes for directory separators if any.
|
||||||
|
|
||||||
|
|
||||||
## Defining the plugin class
|
## Defining the plugin class
|
||||||
|
|
||||||
The plugin class should derive from its respective base class defined in `lib/plugin`.
|
The plugin class should derive from its respective base class defined in `lib/plugin`.
|
||||||
For example, to define a MasterPlugin class the following code can be used:
|
For example, to define a ControllerPlugin class the following code can be used:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const libPlugin = require("@clusterio/lib/plugin");
|
const libPlugin = require("@clusterio/lib/plugin");
|
||||||
|
|
||||||
class MasterPlugin extends libPlugin.BaseMasterPlugin {
|
class ControllerPlugin extends libPlugin.BaseControllerPlugin {
|
||||||
async init() {
|
async init() {
|
||||||
this.foo = 42;
|
this.foo = 42;
|
||||||
await this.startFrobnication();
|
await this.startFrobnication();
|
||||||
@@ -132,11 +132,11 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
MasterPlugin,
|
ControllerPlugin,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
For the instance plugin it's exactly the same except "Master" is replaced with "Instance", and for the clusterioctl plugin "Control" is used.
|
For the instance plugin it's exactly the same except "Controller" is replaced with "Instance", and for the clusterioctl plugin "Control" is used.
|
||||||
The available hooks that you can override are documented in the base class [in lib/plugin.js](/packages/lib/plugin.js).
|
The available hooks that you can override are documented in the base class [in lib/plugin.js](/packages/lib/plugin.js).
|
||||||
|
|
||||||
It's best to avoid defining a constructor, but if you insist on defining one, forward all arguments to the base class.
|
It's best to avoid defining a constructor, but if you insist on defining one, forward all arguments to the base class.
|
||||||
@@ -157,7 +157,7 @@ The async init method is always called immediatly after the constructor, so ther
|
|||||||
## Logging Messages
|
## Logging Messages
|
||||||
|
|
||||||
The base plugin classes provide a winston logger for logging messages to the shared cluster log.
|
The base plugin classes provide a winston logger for logging messages to the shared cluster log.
|
||||||
For instances a copy of the log is also stored on the slave the instance is on.
|
For instances a copy of the log is also stored on the host the instance is on.
|
||||||
To use it, pass a string to one of the log levels functions, for example:
|
To use it, pass a string to one of the log levels functions, for example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
@@ -202,39 +202,39 @@ For plugin hooks expections thrown are automatically catched and logged, but for
|
|||||||
## Plugin Configuration
|
## Plugin Configuration
|
||||||
|
|
||||||
Clusterio provides a configuration system that handles storing, distributing, editing and validating config fields for you.
|
Clusterio provides a configuration system that handles storing, distributing, editing and validating config fields for you.
|
||||||
You can take advantage of it by subclassing `PluginConfigGroup`, setting `defaultAccess` to where config entries can be accessed from, setting the `groupName` to your plugin name, defining fields on it, finalizing it, and passing it as either `MasterConfigGroup` or `InstanceConfigGroup` in the `info.js` export.
|
You can take advantage of it by subclassing `PluginConfigGroup`, setting `defaultAccess` to where config entries can be accessed from, setting the `groupName` to your plugin name, defining fields on it, finalizing it, and passing it as either `ControllerConfigGroup` or `InstanceConfigGroup` in the `info.js` export.
|
||||||
For example in info.js:
|
For example in info.js:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const libConfig = require("@clusterio/lib/config");
|
const libConfig = require("@clusterio/lib/config");
|
||||||
|
|
||||||
class MasterConfigGroup extends libConfig.PluginConfigGroup { }
|
class ControllerConfigGroup extends libConfig.PluginConfigGroup { }
|
||||||
MasterConfigGroup.defaultAccess = ["master", "slave", "control"];
|
ControllerConfigGroup.defaultAccess = ["controller", "host", "control"];
|
||||||
MasterConfigGroup.groupName = "foo_frobber";
|
ControllerConfigGroup.groupName = "foo_frobber";
|
||||||
MasterConfigGroup.define({
|
ControllerConfigGroup.define({
|
||||||
name: "level",
|
name: "level",
|
||||||
description: "Level of frobnication done",
|
description: "Level of frobnication done",
|
||||||
type: "number",
|
type: "number",
|
||||||
initial_value: 2,
|
initial_value: 2,
|
||||||
});
|
});
|
||||||
MasterConfigGroup.finalize();
|
ControllerConfigGroup.finalize();
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
...
|
...
|
||||||
MasterConfigGroup: MasterConfigGroup,
|
ControllerConfigGroup: ControllerConfigGroup,
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
Code inside the `MasterPlugin` class will then be able to access the level config field through the `Config` object at `this.master.config`, for example in the MasterPluginClass:
|
Code inside the `ControllerPlugin` class will then be able to access the level config field through the `Config` object at `this.controller.config`, for example in the ControllerPluginClass:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
async init() {
|
async init() {
|
||||||
let level = this.master.config.get("foo_frobber.level");
|
let level = this.controller.config.get("foo_frobber.level");
|
||||||
this.logger.info(`I got a frobnication level of ${level}`);
|
this.logger.info(`I got a frobnication level of ${level}`);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The same applies for instance configs, replace "master" with "instance" where appropriate.
|
The same applies for instance configs, replace "controller" with "instance" where appropriate.
|
||||||
See [Configuration System](config-system.md) for more details on how this system works.
|
See [Configuration System](config-system.md) for more details on how this system works.
|
||||||
|
|
||||||
|
|
||||||
@@ -313,8 +313,8 @@ For RCON, commands longer than 50 characters may end up being executed after sho
|
|||||||
|
|
||||||
## Defining Link Messages
|
## Defining Link Messages
|
||||||
|
|
||||||
You will most likely have to communicate with the master or other instances in your plugin for it to do anything useful.
|
You will most likely have to communicate with the controller or other instances in your plugin for it to do anything useful.
|
||||||
For this there's a WebSocket communication channel established between the slaves and the master server that plugins can define their own messages to send over it.
|
For this there's a WebSocket communication channel established between the hosts and the controller that plugins can define their own messages to send over it.
|
||||||
This channel is bi-directional and all messages sent over it are validated with a JSON schema (see [this guide][guide] for an introduction to writing JSON schema).
|
This channel is bi-directional and all messages sent over it are validated with a JSON schema (see [this guide][guide] for an introduction to writing JSON schema).
|
||||||
|
|
||||||
[guide]: https://json-schema.org/learn/getting-started-step-by-step.html
|
[guide]: https://json-schema.org/learn/getting-started-step-by-step.html
|
||||||
@@ -335,7 +335,7 @@ The Event constructor takes an object of properties that define the event, for e
|
|||||||
messages: {
|
messages: {
|
||||||
startFrobnication: new libLink.Event({
|
startFrobnication: new libLink.Event({
|
||||||
type: "foo_frobber:start_frobnication",
|
type: "foo_frobber:start_frobnication",
|
||||||
links: ["master-slave", "slave-instance"],
|
links: ["controller-host", "host-instance"],
|
||||||
forwardTo: "instance",
|
forwardTo: "instance",
|
||||||
eventRequired: ["frobnication_type"],
|
eventRequired: ["frobnication_type"],
|
||||||
eventProperties: {
|
eventProperties: {
|
||||||
@@ -346,9 +346,9 @@ messages: {
|
|||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
This specifies an event that can be sent from the master to a slave, and from a slave to an instance.
|
This specifies an event that can be sent from the controller to a host, and from a host to an instance.
|
||||||
It also specifies that the event must contain the property `frobnication_type`, with a string value in the data payload and that it may optionally contain a boolean `urgent` property.
|
It also specifies that the event must contain the property `frobnication_type`, with a string value in the data payload and that it may optionally contain a boolean `urgent` property.
|
||||||
It will also be forwarded by slaves to a specific instance.
|
It will also be forwarded by hosts to a specific instance.
|
||||||
|
|
||||||
The following properties are recognized by the Event constructor:
|
The following properties are recognized by the Event constructor:
|
||||||
|
|
||||||
@@ -361,17 +361,17 @@ The type of the message sent over the socket will have the suffix `_event` appen
|
|||||||
#### links
|
#### links
|
||||||
|
|
||||||
An array of strings describing which links this event can be sent over.
|
An array of strings describing which links this event can be sent over.
|
||||||
Direction matters, `"master-slave"` means the event can be sent from the master to the slave, but can't be sent back the other way, unless `"slave-master"` is also present in the links array.
|
Direction matters, `"controller-host"` means the event can be sent from the controller to the host, but can't be sent back the other way, unless `"host-controller"` is also present in the links array.
|
||||||
|
|
||||||
The available endpoints are `master`, `slave`, `instance`, and `control`.
|
The available endpoints are `controller`, `host`, `instance`, and `control`.
|
||||||
Master talks with slave and control, and slave talks to instance.
|
Controller talks with host and control, and host talks to instance.
|
||||||
The full chain must be specified as the individual links in order for a message to travers multiple hops, (i.e., for a message to go from master to instance it must have both `"master-slave"` and `"slave-instance"` in the links array).
|
The full chain must be specified as the individual links in order for a message to travers multiple hops, (i.e., for a message to go from controller to instance it must have both `"controller-host"` and `"host-instance"` in the links array).
|
||||||
See `forwardTo` and `broadcastTo` for ways to forward an event to the next link in a chain.
|
See `forwardTo` and `broadcastTo` for ways to forward an event to the next link in a chain.
|
||||||
|
|
||||||
#### forwardTo
|
#### forwardTo
|
||||||
|
|
||||||
Target to forward an event to.
|
Target to forward an event to.
|
||||||
Can either be `"master"`, to indicate a slave should forward it to the master server, or `"instance"`, to indicate it should be forwarded to the instances specified by the `instance_id` event property.
|
Can either be `"controller"`, to indicate a host should forward it to the controller, or `"instance"`, to indicate it should be forwarded to the instances specified by the `instance_id` event property.
|
||||||
This works by using a default handler for the event at the links that forward it.
|
This works by using a default handler for the event at the links that forward it.
|
||||||
|
|
||||||
#### broadcastTo
|
#### broadcastTo
|
||||||
@@ -379,7 +379,7 @@ This works by using a default handler for the event at the links that forward it
|
|||||||
Target to broadcast this message towards.
|
Target to broadcast this message towards.
|
||||||
A value of "instance" means the event will be broadcast to all instances downstream of the target it's sent to, but not back from where it came from.
|
A value of "instance" means the event will be broadcast to all instances downstream of the target it's sent to, but not back from where it came from.
|
||||||
Currently, only "instance" is supported.
|
Currently, only "instance" is supported.
|
||||||
This means that sending the event to a slave from an instance will cause it to be broadcast to all instances of that slave except for the instance it came from.
|
This means that sending the event to a host from an instance will cause it to be broadcast to all instances of that host except for the instance it came from.
|
||||||
|
|
||||||
#### eventRequired
|
#### eventRequired
|
||||||
|
|
||||||
@@ -393,8 +393,8 @@ Object with properties mapping to a JSON schema of that property that specifies
|
|||||||
This is equivalent to using the `properties` keyword in JSON schema, except that the properties specified are by default required and additional properties are not allowed.
|
This is equivalent to using the `properties` keyword in JSON schema, except that the properties specified are by default required and additional properties are not allowed.
|
||||||
See [this guide][guide] for an introduction to writing JSON schemas.
|
See [this guide][guide] for an introduction to writing JSON schemas.
|
||||||
|
|
||||||
The forwardTo and broadcastTo can be combined such that specifying `"master"` as the forwardTo value and `"instance"` as the broadcastTo value will cause the event to be broadcast to all instances in the cluster.
|
The forwardTo and broadcastTo can be combined such that specifying `"controller"` as the forwardTo value and `"instance"` as the broadcastTo value will cause the event to be broadcast to all instances in the cluster.
|
||||||
For this to work, you will need to specify `instance-slave`, `slave-master`, `master-slave`, and `slave-instance` as the links.
|
For this to work, you will need to specify `instance-host`, `host-controller`, `controller-host`, and `host-instance` as the links.
|
||||||
|
|
||||||
Keep in mind when forwarding events that if the target an event is being forwarded to is not online, the event will be dropped.
|
Keep in mind when forwarding events that if the target an event is being forwarded to is not online, the event will be dropped.
|
||||||
Use a request if you need a confirmation that the message was received.
|
Use a request if you need a confirmation that the message was received.
|
||||||
@@ -410,7 +410,7 @@ For example, the following could be defined in `info.js`:
|
|||||||
messages: {
|
messages: {
|
||||||
reportFrobnication: new libLink.Request({
|
reportFrobnication: new libLink.Request({
|
||||||
type: "foo_frobber:report_frobnication",
|
type: "foo_frobber:report_frobnication",
|
||||||
links: ["master-slave", "slave-instance"],
|
links: ["controller-host", "host-instance"],
|
||||||
forwardTo: "instance",
|
forwardTo: "instance",
|
||||||
requestRequired: ["verbosity"],
|
requestRequired: ["verbosity"],
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
@@ -427,10 +427,10 @@ messages: {
|
|||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
This specifies a request that can be sent from the master to a slave, and from a slave to an instance.
|
This specifies a request that can be sent from the controller to a host, and from a host to an instance.
|
||||||
The request data must contain the property `verbosity` with an integer number as the value, as well as the `instance_id` property (implied by `forwardTo: "instance"`) and it may also contain a boolean `special` property.
|
The request data must contain the property `verbosity` with an integer number as the value, as well as the `instance_id` property (implied by `forwardTo: "instance"`) and it may also contain a boolean `special` property.
|
||||||
It also defines that the response sent must contain a `report` property mapping to an array of strings.
|
It also defines that the response sent must contain a `report` property mapping to an array of strings.
|
||||||
When received by a slave, it will also be forwarded to the instance specified by `instance_id`.
|
When received by a host, it will also be forwarded to the instance specified by `instance_id`.
|
||||||
|
|
||||||
The following properties are recognized by the Request constructor:
|
The following properties are recognized by the Request constructor:
|
||||||
|
|
||||||
@@ -443,17 +443,17 @@ The type of the message sent over the socket will have the suffix `_request` app
|
|||||||
#### links
|
#### links
|
||||||
|
|
||||||
An array of strings describing which links this request can be sent over.
|
An array of strings describing which links this request can be sent over.
|
||||||
Direction matters; `"master-slave"` means the request can be sent from the master to the slave and the slave can reply to the master, but the slave can't send a request to the master unless `"slave-master"` is also present in the links array.
|
Direction matters; `"controller-host"` means the request can be sent from the controller to the host and the host can reply to the controller, but the host can't send a request to the controller unless `"host-controller"` is also present in the links array.
|
||||||
|
|
||||||
The available endpoints are `master`, `slave`, `instance`, and `control`.
|
The available endpoints are `controller`, `host`, `instance`, and `control`.
|
||||||
Master talks with slave and control, and slave talks to instance.
|
Controller talks with host and control, and host talks to instance.
|
||||||
The full chain must be specified as the individual links in order for a message to travers multiple hops, (i.e., for a message to go from master to instance it must have both `"master-slave"` and `"slave-instance"` in the links array).
|
The full chain must be specified as the individual links in order for a message to travers multiple hops, (i.e., for a message to go from controller to instance it must have both `"controller-host"` and `"host-instance"` in the links array).
|
||||||
See `forwardTo` for ways to forward a request to the next link in a chain.
|
See `forwardTo` for ways to forward a request to the next link in a chain.
|
||||||
|
|
||||||
#### forwardTo
|
#### forwardTo
|
||||||
|
|
||||||
Target to forward the request to.
|
Target to forward the request to.
|
||||||
Can either be `"master"` to indicate a slave should forward it to the master server when receiving it from an instance, or `"instance"` to indicate it should be forwarded to the instances specified by the `instance_id` request property.
|
Can either be `"controller"` to indicate a host should forward it to the controller when receiving it from an instance, or `"instance"` to indicate it should be forwarded to the instances specified by the `instance_id` request property.
|
||||||
This works by using a default handler for the request by the links that forward it.
|
This works by using a default handler for the request by the links that forward it.
|
||||||
|
|
||||||
#### requestRequired
|
#### requestRequired
|
||||||
@@ -480,7 +480,7 @@ Same as the requestProperties only for the response sent back by the target.
|
|||||||
## Sending Link Messages
|
## Sending Link Messages
|
||||||
|
|
||||||
Link messages are sent by calling the `.send()` method on the Event/Request instance with the link you want to send it over and the data to send.
|
Link messages are sent by calling the `.send()` method on the Event/Request instance with the link you want to send it over and the data to send.
|
||||||
For `InstancePlugin` code the link to the slave is the `instance` itself, which is accessible through the `.instance` property of the `InstancePlugin`.
|
For `InstancePlugin` code the link to the host is the `instance` itself, which is accessible through the `.instance` property of the `InstancePlugin`.
|
||||||
The `.info` property of the plugin class exposes the data exported from the plugin's `info.js` module.
|
The `.info` property of the plugin class exposes the data exported from the plugin's `info.js` module.
|
||||||
In other words:
|
In other words:
|
||||||
|
|
||||||
@@ -497,26 +497,26 @@ For the Request class the send method is async and returns the response data rec
|
|||||||
### Handling connection events
|
### Handling connection events
|
||||||
|
|
||||||
There are a few connection related events that plugins neeed to repsond to in order to avoid data loss and connection problems.
|
There are a few connection related events that plugins neeed to repsond to in order to avoid data loss and connection problems.
|
||||||
The most important is the prepare disconnect for the link between master and slave.
|
The most important is the prepare disconnect for the link between controller and host.
|
||||||
This is signaled to `MasterPlugin` classes via the `onPrepareSlaveDisconnect` hook and to `InstancePlugin` classes via the `onPrepareMasterDisconnect` hook.
|
This is signaled to `ControllerPlugin` classes via the `onPrepareHostDisconnect` hook and to `InstancePlugin` classes via the `onPrepareControllerDisconnect` hook.
|
||||||
|
|
||||||
After the prepare disconnect the connection will be closed, which will result in pending requests and events being dropped.
|
After the prepare disconnect the connection will be closed, which will result in pending requests and events being dropped.
|
||||||
Plugins must respond to the prepare disconnect by stopping any processess it does that send events or requests over the link in question.
|
Plugins must respond to the prepare disconnect by stopping any processess it does that send events or requests over the link in question.
|
||||||
This can be accomplished either through listening for the prepare disconnect hook, or by checking the `connected` property of the `SlaveConnection` class and `Slave` class on the master and slave respectively.
|
This can be accomplished either through listening for the prepare disconnect hook, or by checking the `connected` property of the `HostConnection` class and `Host` class on the controller and host respectively.
|
||||||
For example the sending of an event from an `InstancePlugin` class can be stopped while the connection is not connected, not in the dropped state, and not in the process of discunnecting by using the following code:
|
For example the sending of an event from an `InstancePlugin` class can be stopped while the connection is not connected, not in the dropped state, and not in the process of discunnecting by using the following code:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
if (this.slave.connected) {
|
if (this.host.connected) {
|
||||||
this.info.messages.frobnicate.send(this.instance, { foo: "bar" });
|
this.info.messages.frobnicate.send(this.instance, { foo: "bar" });
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
If the event or request needs to be sent to the master it can be put into a queue stored on the plugin instance and sent out when the connection is established again.
|
If the event or request needs to be sent to the controller it can be put into a queue stored on the plugin instance and sent out when the connection is established again.
|
||||||
The re-establishement of the connection is notified to plugins via the `connect` event to the `onMasterConnectionEvent` and `onSlaveConnectionEvent` hooks.
|
The re-establishement of the connection is notified to plugins via the `connect` event to the `onControllerConnectionEvent` and `onHostConnectionEvent` hooks.
|
||||||
|
|
||||||
The second connection event which is of lesser importance to respond to is the `drop` connection event served through `onMasterConnectionEvent` for `InstancePlugin` classes and through `onSlaveConnectionEvent` for `MasterPlugin` classes.
|
The second connection event which is of lesser importance to respond to is the `drop` connection event served through `onControllerConnectionEvent` for `InstancePlugin` classes and through `onHostConnectionEvent` for `ControllerPlugin` classes.
|
||||||
This is raised when the connection between the master and slave in question is lost, most likely due to networking issues.
|
This is raised when the connection between the controller and host in question is lost, most likely due to networking issues.
|
||||||
When in the dropped state the slave will keep trying to reconnect to the master server in order to re-establish it, and if successful no events or requests will be lost.
|
When in the dropped state the host will keep trying to reconnect to the controller in order to re-establish it, and if successful no events or requests will be lost.
|
||||||
However while in the dropped state any requests and events sent gets queued up in memory until the connection is either re-established or the session times out.
|
However while in the dropped state any requests and events sent gets queued up in memory until the connection is either re-established or the session times out.
|
||||||
This means that if your plugin sends a lot of events or requests, they can end up being queued up in a buffer and sent out all at once the connection is re-estabished.
|
This means that if your plugin sends a lot of events or requests, they can end up being queued up in a buffer and sent out all at once the connection is re-estabished.
|
||||||
To avoid this you should be throtteling and/or stopping your requests/events after `drop` has been raised, and continue back as normal when `resume` is raised.
|
To avoid this you should be throtteling and/or stopping your requests/events after `drop` has been raised, and continue back as normal when `resume` is raised.
|
||||||
@@ -536,11 +536,11 @@ const fooMetric = new Counter(
|
|||||||
"clusterio_foo_frobber_foo_metric", "Measures the level of foo",
|
"clusterio_foo_frobber_foo_metric", "Measures the level of foo",
|
||||||
);
|
);
|
||||||
|
|
||||||
// Somewhere in the master plugin code
|
// Somewhere in the controller plugin code
|
||||||
fooMetric.inc();
|
fooMetric.inc();
|
||||||
```
|
```
|
||||||
|
|
||||||
This works for master plugins, and the metric will be automatically available through the /metric HTTP endpoint.
|
This works for controller plugins, and the metric will be automatically available through the /metric HTTP endpoint.
|
||||||
It's recommended that plugin metrics follow `clusterio_<plugin_name>_<metric_name>` as the naming scheme.
|
It's recommended that plugin metrics follow `clusterio_<plugin_name>_<metric_name>` as the naming scheme.
|
||||||
|
|
||||||
For metrics that are per-instance, you must define an `instance_id` label and set it accordingly, for example:
|
For metrics that are per-instance, you must define an `instance_id` label and set it accordingly, for example:
|
||||||
@@ -557,11 +557,11 @@ const barMetric = new Gauge(
|
|||||||
barMetric.labels(String(this.instance.id)).set(someValue);
|
barMetric.labels(String(this.instance.id)).set(someValue);
|
||||||
```
|
```
|
||||||
|
|
||||||
Metrics are automatically registered to the default registry, and this default registry is automatically polled by the master server on slaves.
|
Metrics are automatically registered to the default registry, and this default registry is automatically polled by the controller on hosts.
|
||||||
This means that it's important that you place the definition of the metric at module level so that it's not created more than once over the lifetime of a slave.
|
This means that it's important that you place the definition of the metric at module level so that it's not created more than once over the lifetime of a host.
|
||||||
Since the metrics remember their values and would continue to be exported after an instance is shutdown, there's code at instance shutdown that removes all the values where the `instance_id` label matches the id of the instance shut down.
|
Since the metrics remember their values and would continue to be exported after an instance is shutdown, there's code at instance shutdown that removes all the values where the `instance_id` label matches the id of the instance shut down.
|
||||||
|
|
||||||
For statistics you need to update on collection there's an `onMetrics` hook on both master and instance plugins that is run before the metrics in the default registry are collected.
|
For statistics you need to update on collection there's an `onMetrics` hook on both controller and instance plugins that is run before the metrics in the default registry are collected.
|
||||||
|
|
||||||
|
|
||||||
## Adding Custom Commands to clusterioctl
|
## Adding Custom Commands to clusterioctl
|
||||||
@@ -600,7 +600,7 @@ For a command the `definition` is the arguments to pass to [yargs.command](http:
|
|||||||
The `handler` is an async function that's invoked when the command is executed and it's passed the parsed command line arguments and a reference to the `Control` class of clusterioctl.
|
The `handler` is an async function that's invoked when the command is executed and it's passed the parsed command line arguments and a reference to the `Control` class of clusterioctl.
|
||||||
It's possible to optain a reference to the plugin class with `control.plugins.get(info.name)`.
|
It's possible to optain a reference to the plugin class with `control.plugins.get(info.name)`.
|
||||||
|
|
||||||
Note that messages sent from clusterioctl needs to have `"control-master"` as a part of the links array for it to be accepted by the master server, see [Defining Link Messages](#defining-link-messages) for how to define the messages that can be sent to the master.
|
Note that messages sent from clusterioctl needs to have `"control-controller"` as a part of the links array for it to be accepted by the controller, see [Defining Link Messages](#defining-link-messages) for how to define the messages that can be sent to the controller.
|
||||||
|
|
||||||
To have the command tree become part of clusterioctl it needs to be added to the rootCommand tree in `addCommands` callback of the Control plugin:
|
To have the command tree become part of clusterioctl it needs to be added to the rootCommand tree in `addCommands` callback of the Control plugin:
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -23,8 +23,8 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@clusterio/ctl": "workspace:*",
|
"@clusterio/ctl": "workspace:*",
|
||||||
"@clusterio/lib": "workspace:*",
|
"@clusterio/lib": "workspace:*",
|
||||||
"@clusterio/master": "workspace:*",
|
"@clusterio/controller": "workspace:*",
|
||||||
"@clusterio/slave": "workspace:*",
|
"@clusterio/host": "workspace:*",
|
||||||
"eslint": "^8.18.0",
|
"eslint": "^8.18.0",
|
||||||
"eslint-plugin-node": "^11.1.0",
|
"eslint-plugin-node": "^11.1.0",
|
||||||
"express": "^4.16.2",
|
"express": "^4.16.2",
|
||||||
|
|||||||
File renamed without changes.
@@ -1,27 +1,27 @@
|
|||||||
# Clusterio Master Server
|
# Clusterio Controller
|
||||||
|
|
||||||
Communication hub for Clusterio clusters.
|
Communication hub for Clusterio clusters.
|
||||||
The master server forwards data between Clusterio slaves connected to it and allows the cluster to be remotely managed through WebSocket connections to it either by using the included web interface or the Clusterio ctl command line utility.
|
The controller forwards data between Clusterio hosts connected to it and allows the cluster to be remotely managed through WebSocket connections to it either by using the included web interface or the Clusterio ctl command line utility.
|
||||||
|
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
npx clusteriomaster <command>
|
npx clusteriocontroller <command>
|
||||||
|
|
||||||
Common options:
|
Common options:
|
||||||
|
|
||||||
* `--plugin-list <file>` JSON file to use for storing the list of plugins that are available to the master server.
|
* `--plugin-list <file>` JSON file to use for storing the list of plugins that are available to the controller.
|
||||||
Defaults to `plugin-list.json` and will be created if it does not exist.
|
Defaults to `plugin-list.json` and will be created if it does not exist.
|
||||||
See the `plugin` command for managing this list.
|
See the `plugin` command for managing this list.
|
||||||
|
|
||||||
* `--config <file>` JSON file to use for storing configuration for the master server.
|
* `--config <file>` JSON file to use for storing configuration for the controller.
|
||||||
Defaults to `config-master.json` and will be created if it does not exist.
|
Defaults to `config-controller.json` and will be created if it does not exist.
|
||||||
See the `config` command for inspecting and modifying the configuration.
|
See the `config` command for inspecting and modifying the configuration.
|
||||||
|
|
||||||
|
|
||||||
### `plugin <command>`
|
### `plugin <command>`
|
||||||
|
|
||||||
Configure plugins available to be loaded by the master server.
|
Configure plugins available to be loaded by the controller.
|
||||||
The available plugins will be loaded unless they have been disabled in the configuration, see the config command for disabling plugins.
|
The available plugins will be loaded unless they have been disabled in the configuration, see the config command for disabling plugins.
|
||||||
|
|
||||||
|
|
||||||
@@ -33,9 +33,9 @@ A relative path must start with ./ or ../ (or .\ and ..\ on Windows) otherwise i
|
|||||||
For example, installing the Subspace Storage plugin:
|
For example, installing the Subspace Storage plugin:
|
||||||
|
|
||||||
npm install @clusterio/plugin-subspace_storage
|
npm install @clusterio/plugin-subspace_storage
|
||||||
npx clusteriomaster plugin add @clusterio/plugin-subspace_storage
|
npx clusteriocontroller plugin add @clusterio/plugin-subspace_storage
|
||||||
|
|
||||||
Since the `plugin-list.json` is shared between master, slave and ctl you usually only need to do this once per machine.
|
Since the `plugin-list.json` is shared between controller, host and ctl you usually only need to do this once per machine.
|
||||||
|
|
||||||
|
|
||||||
#### `plugin remove <name>`
|
#### `plugin remove <name>`
|
||||||
@@ -46,10 +46,10 @@ Removing and unistalling a plugin is usually not neccessary as the functions pro
|
|||||||
|
|
||||||
For example, uninstalling the Subspace Storage plugin:
|
For example, uninstalling the Subspace Storage plugin:
|
||||||
|
|
||||||
npx clusteriomaster plugin remove subspace_storage
|
npx clusteriocontroller plugin remove subspace_storage
|
||||||
npm uninstall @clusterio/plugin-subspace_storage
|
npm uninstall @clusterio/plugin-subspace_storage
|
||||||
|
|
||||||
Since the `plugin-list.json` is shared between master, slave and ctl you usually only need to do this once per machine.
|
Since the `plugin-list.json` is shared between controller, host and ctl you usually only need to do this once per machine.
|
||||||
|
|
||||||
|
|
||||||
#### `plugin list`
|
#### `plugin list`
|
||||||
@@ -59,8 +59,8 @@ Lists the plugins set up to be available by name followed by path.
|
|||||||
|
|
||||||
### `config`
|
### `config`
|
||||||
|
|
||||||
Manage the master server configuration offline.
|
Manage the controller configuration offline.
|
||||||
This should only be used when the master server is stopped, otherwise the config read might be out of date and config changes will be overwritten when the master server shuts down.
|
This should only be used when the controller is stopped, otherwise the config read might be out of date and config changes will be overwritten when the controller shuts down.
|
||||||
|
|
||||||
|
|
||||||
#### `config set <config-entry> [value]`
|
#### `config set <config-entry> [value]`
|
||||||
@@ -96,7 +96,7 @@ You should be using your own Factorio multiplayer username here.
|
|||||||
#### `bootstrap generate-user-token <name>`
|
#### `bootstrap generate-user-token <name>`
|
||||||
|
|
||||||
Generate an access token for logging in and possibly managing the cluster from the given user account.
|
Generate an access token for logging in and possibly managing the cluster from the given user account.
|
||||||
This can be used both in the web interface and as the `master_token` to connect with clusterioctl.
|
This can be used both in the web interface and as the `controller_token` to connect with clusterioctl.
|
||||||
|
|
||||||
|
|
||||||
#### `bootstrap create-ctl-config <name>`
|
#### `bootstrap create-ctl-config <name>`
|
||||||
@@ -106,7 +106,7 @@ Creates a clusterioctl config for the given user with url and token set up for c
|
|||||||
|
|
||||||
### `run`
|
### `run`
|
||||||
|
|
||||||
Runs the master server.
|
Runs the controller.
|
||||||
|
|
||||||
|
|
||||||
## See Also
|
## See Also
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clusterio master server
|
* Clusterio controller
|
||||||
*
|
*
|
||||||
* Facilitates communication between slaves and control of the cluster
|
* Facilitates communication between hosts and control of the cluster
|
||||||
* through WebSocet connections, and hosts a webserver for browser
|
* through WebSocet connections, and hosts a webserver for browser
|
||||||
* interfaces and Prometheus statistics export. It is remotely controlled
|
* interfaces and Prometheus statistics export. It is remotely controlled
|
||||||
* by {@link module:ctl/ctl}.
|
* by {@link module:ctl/ctl}.
|
||||||
*
|
*
|
||||||
* @module master/master
|
* @module controller/controller
|
||||||
* @author Danielv123, Hornwitser
|
* @author Danielv123, Hornwitser
|
||||||
* @example
|
* @example
|
||||||
* npx clusteriomaster run
|
* npx clusteriocontroller run
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
@@ -36,28 +36,28 @@ const libSharedCommands = require("@clusterio/lib/shared_commands");
|
|||||||
const { ConsoleTransport, levels, logger } = require("@clusterio/lib/logging");
|
const { ConsoleTransport, levels, logger } = require("@clusterio/lib/logging");
|
||||||
const libLoggingUtils = require("@clusterio/lib/logging_utils");
|
const libLoggingUtils = require("@clusterio/lib/logging_utils");
|
||||||
|
|
||||||
const Master = require("./src/Master");
|
const Controller = require("./src/Controller");
|
||||||
const UserManager = require("./src/UserManager");
|
const UserManager = require("./src/UserManager");
|
||||||
const version = require("./package").version;
|
const version = require("./package").version;
|
||||||
|
|
||||||
// globals
|
// globals
|
||||||
let master;
|
let controller;
|
||||||
|
|
||||||
|
|
||||||
void new libPrometheus.Gauge(
|
void new libPrometheus.Gauge(
|
||||||
"clusterio_master_slave_mapping",
|
"clusterio_controller_host_mapping",
|
||||||
"Mapping of Slave ID to name",
|
"Mapping of Host ID to name",
|
||||||
{
|
{
|
||||||
labels: ["slave_id", "slave_name"],
|
labels: ["host_id", "host_name"],
|
||||||
callback: function(gauge) {
|
callback: function(gauge) {
|
||||||
gauge.clear();
|
gauge.clear();
|
||||||
if (!master || !master.slaves) {
|
if (!controller || !controller.hosts) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (let [id, slave] of master.slaves) {
|
for (let [id, host] of controller.hosts) {
|
||||||
gauge.labels({
|
gauge.labels({
|
||||||
slave_id: String(id),
|
host_id: String(id),
|
||||||
slave_name: slave.name,
|
host_name: host.name,
|
||||||
}).set(1);
|
}).set(1);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -65,20 +65,20 @@ void new libPrometheus.Gauge(
|
|||||||
);
|
);
|
||||||
|
|
||||||
void new libPrometheus.Gauge(
|
void new libPrometheus.Gauge(
|
||||||
"clusterio_master_instance_mapping",
|
"clusterio_controller_instance_mapping",
|
||||||
"Mapping of Instance ID to name and slave",
|
"Mapping of Instance ID to name and host",
|
||||||
{
|
{
|
||||||
labels: ["instance_id", "instance_name", "slave_id"],
|
labels: ["instance_id", "instance_name", "host_id"],
|
||||||
callback: function(gauge) {
|
callback: function(gauge) {
|
||||||
gauge.clear();
|
gauge.clear();
|
||||||
if (!master || !master.instances) {
|
if (!controller || !controller.instances) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (let [id, instance] of master.instances) {
|
for (let [id, instance] of controller.instances) {
|
||||||
gauge.labels({
|
gauge.labels({
|
||||||
instance_id: String(id),
|
instance_id: String(id),
|
||||||
instance_name: String(instance.config.get("instance.name")),
|
instance_name: String(instance.config.get("instance.name")),
|
||||||
slave_id: String(instance.config.get("instance.assigned_slave")),
|
host_id: String(instance.config.get("instance.assigned_host")),
|
||||||
}).set(1);
|
}).set(1);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -86,32 +86,32 @@ void new libPrometheus.Gauge(
|
|||||||
);
|
);
|
||||||
|
|
||||||
void new libPrometheus.Gauge(
|
void new libPrometheus.Gauge(
|
||||||
"clusterio_master_websocket_active_connections",
|
"clusterio_controller_websocket_active_connections",
|
||||||
"How many WebSocket connections are currently open to the master server",
|
"How many WebSocket connections are currently open to the controller",
|
||||||
{ callback: function(gauge) { gauge.set(master.wsServer.activeConnectors.size); }}
|
{ callback: function(gauge) { gauge.set(controller.wsServer.activeConnectors.size); }}
|
||||||
);
|
);
|
||||||
|
|
||||||
void new libPrometheus.Gauge(
|
void new libPrometheus.Gauge(
|
||||||
"clusterio_master_active_slaves",
|
"clusterio_controller_active_hosts",
|
||||||
"How many slaves are currently connected to the master",
|
"How many hosts are currently connected to the controller",
|
||||||
{ callback: function(gauge) { gauge.set(master.wsServer.slaveConnections.size); }}
|
{ callback: function(gauge) { gauge.set(controller.wsServer.hostConnections.size); }}
|
||||||
);
|
);
|
||||||
|
|
||||||
void new libPrometheus.Gauge(
|
void new libPrometheus.Gauge(
|
||||||
"clusterio_master_connected_clients_count", "How many clients are currently connected to this master server",
|
"clusterio_controller_connected_clients_count", "How many clients are currently connected to this controller",
|
||||||
{
|
{
|
||||||
labels: ["type"], callback: async function(gauge) {
|
labels: ["type"], callback: async function(gauge) {
|
||||||
gauge.labels("slave").set(master.wsServer.slaveConnections.size);
|
gauge.labels("host").set(controller.wsServer.hostConnections.size);
|
||||||
gauge.labels("control").set(master.wsServer.controlConnections.length);
|
gauge.labels("control").set(controller.wsServer.controlConnections.length);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
async function handleBootstrapCommand(args, masterConfig) {
|
async function handleBootstrapCommand(args, controllerConfig) {
|
||||||
let subCommand = args._[1];
|
let subCommand = args._[1];
|
||||||
let userManager = new UserManager(masterConfig);
|
let userManager = new UserManager(controllerConfig);
|
||||||
await userManager.load(path.join(masterConfig.get("master.database_directory"), "users.json"));
|
await userManager.load(path.join(controllerConfig.get("controller.database_directory"), "users.json"));
|
||||||
if (subCommand === "create-admin") {
|
if (subCommand === "create-admin") {
|
||||||
if (!args.name) {
|
if (!args.name) {
|
||||||
logger.error("name cannot be blank");
|
logger.error("name cannot be blank");
|
||||||
@@ -127,7 +127,7 @@ async function handleBootstrapCommand(args, masterConfig) {
|
|||||||
let adminRole = libUsers.ensureDefaultAdminRole(userManager.roles);
|
let adminRole = libUsers.ensureDefaultAdminRole(userManager.roles);
|
||||||
admin.roles.add(adminRole);
|
admin.roles.add(adminRole);
|
||||||
admin.isAdmin = true;
|
admin.isAdmin = true;
|
||||||
await userManager.save(path.join(masterConfig.get("master.database_directory"), "users.json"));
|
await userManager.save(path.join(controllerConfig.get("controller.database_directory"), "users.json"));
|
||||||
|
|
||||||
} else if (subCommand === "generate-user-token") {
|
} else if (subCommand === "generate-user-token") {
|
||||||
let user = userManager.users.get(args.name);
|
let user = userManager.users.get(args.name);
|
||||||
@@ -137,13 +137,13 @@ async function handleBootstrapCommand(args, masterConfig) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(user.createToken(masterConfig.get("master.auth_secret")));
|
console.log(user.createToken(controllerConfig.get("controller.auth_secret")));
|
||||||
|
|
||||||
} else if (subCommand === "generate-slave-token") {
|
} else if (subCommand === "generate-host-token") {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(jwt.sign(
|
console.log(jwt.sign(
|
||||||
{ aud: "slave", slave: args.id },
|
{ aud: "host", host: args.id },
|
||||||
Buffer.from(masterConfig.get("master.auth_secret"), "base64")
|
Buffer.from(controllerConfig.get("controller.auth_secret"), "base64")
|
||||||
));
|
));
|
||||||
|
|
||||||
} else if (subCommand === "create-ctl-config") {
|
} else if (subCommand === "create-ctl-config") {
|
||||||
@@ -156,8 +156,10 @@ async function handleBootstrapCommand(args, masterConfig) {
|
|||||||
let controlConfig = new libConfig.ControlConfig("control");
|
let controlConfig = new libConfig.ControlConfig("control");
|
||||||
await controlConfig.init();
|
await controlConfig.init();
|
||||||
|
|
||||||
controlConfig.set("control.master_url", Master.calculateMasterUrl(masterConfig));
|
controlConfig.set("control.controller_url", Controller.calculateControllerUrl(controllerConfig));
|
||||||
controlConfig.set("control.master_token", admin.createToken(masterConfig.get("master.auth_secret")));
|
controlConfig.set(
|
||||||
|
"control.controller_token", admin.createToken(controllerConfig.get("controller.auth_secret"))
|
||||||
|
);
|
||||||
|
|
||||||
let content = JSON.stringify(controlConfig.serialize(), null, 4);
|
let content = JSON.stringify(controlConfig.serialize(), null, 4);
|
||||||
if (args.output === "-") {
|
if (args.output === "-") {
|
||||||
@@ -176,13 +178,13 @@ async function initialize() {
|
|||||||
shouldRun: false,
|
shouldRun: false,
|
||||||
clusterLogger: null,
|
clusterLogger: null,
|
||||||
pluginInfos: null,
|
pluginInfos: null,
|
||||||
masterConfigPath: null,
|
controllerConfigPath: null,
|
||||||
masterConfig: null,
|
controllerConfig: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
// argument parsing
|
// argument parsing
|
||||||
parameters.args = yargs
|
parameters.args = yargs
|
||||||
.scriptName("master")
|
.scriptName("controller")
|
||||||
.usage("$0 <command> [options]")
|
.usage("$0 <command> [options]")
|
||||||
.option("log-level", {
|
.option("log-level", {
|
||||||
nargs: 1,
|
nargs: 1,
|
||||||
@@ -199,8 +201,8 @@ async function initialize() {
|
|||||||
})
|
})
|
||||||
.option("config", {
|
.option("config", {
|
||||||
nargs: 1,
|
nargs: 1,
|
||||||
describe: "master config file to use",
|
describe: "controller config file to use",
|
||||||
default: "config-master.json",
|
default: "config-controller.json",
|
||||||
type: "string",
|
type: "string",
|
||||||
})
|
})
|
||||||
.option("plugin-list", {
|
.option("plugin-list", {
|
||||||
@@ -210,13 +212,13 @@ async function initialize() {
|
|||||||
type: "string",
|
type: "string",
|
||||||
})
|
})
|
||||||
.command("plugin", "Manage available plugins", libSharedCommands.pluginCommand)
|
.command("plugin", "Manage available plugins", libSharedCommands.pluginCommand)
|
||||||
.command("config", "Manage Master config", libSharedCommands.configCommand)
|
.command("config", "Manage Controller config", libSharedCommands.configCommand)
|
||||||
.command("bootstrap", "Bootstrap access to cluster", yargs => {
|
.command("bootstrap", "Bootstrap access to cluster", yargs => {
|
||||||
yargs
|
yargs
|
||||||
.command("create-admin <name>", "Create a cluster admin")
|
.command("create-admin <name>", "Create a cluster admin")
|
||||||
.command("generate-user-token <name>", "Generate authentication token for the given user")
|
.command("generate-user-token <name>", "Generate authentication token for the given user")
|
||||||
.command("generate-slave-token <id>", "Generate authentication token for the given slave", yargs => {
|
.command("generate-host-token <id>", "Generate authentication token for the given host", yargs => {
|
||||||
yargs.positional("id", { describe: "ID of the slave", type: "number" });
|
yargs.positional("id", { describe: "ID of the host", type: "number" });
|
||||||
})
|
})
|
||||||
.command("create-ctl-config <name>", "Create clusterioctl config for the given user", yargs => {
|
.command("create-ctl-config <name>", "Create clusterioctl config for the given user", yargs => {
|
||||||
yargs.option("output", {
|
yargs.option("output", {
|
||||||
@@ -226,7 +228,7 @@ async function initialize() {
|
|||||||
})
|
})
|
||||||
.demandCommand(1, "You need to specify a command to run");
|
.demandCommand(1, "You need to specify a command to run");
|
||||||
})
|
})
|
||||||
.command("run", "Run master server", yargs => {
|
.command("run", "Run controller", yargs => {
|
||||||
yargs.option("dev", { hidden: true, type: "boolean", nargs: 0 });
|
yargs.option("dev", { hidden: true, type: "boolean", nargs: 0 });
|
||||||
yargs.option("dev-plugin", { hidden: true, type: "array" });
|
yargs.option("dev-plugin", { hidden: true, type: "array" });
|
||||||
})
|
})
|
||||||
@@ -235,28 +237,6 @@ async function initialize() {
|
|||||||
.argv
|
.argv
|
||||||
;
|
;
|
||||||
|
|
||||||
{
|
|
||||||
// Migration from alpha-10 single file logs, note that we can't use
|
|
||||||
// the logger here as it's not initalized yet.
|
|
||||||
/* eslint-disable no-console */
|
|
||||||
let clusterLogDirectory = path.join(parameters.args.logDirectory, "cluster");
|
|
||||||
if (!await fs.pathExists(clusterLogDirectory) && await fs.pathExists("cluster.log")) {
|
|
||||||
console.log("Migrating cluster log...");
|
|
||||||
await fs.ensureDir(clusterLogDirectory);
|
|
||||||
await libLoggingUtils.migrateLogs("cluster.log", clusterLogDirectory, "cluster-%DATE%.log");
|
|
||||||
console.log("Migration complete, you should delete cluster.log now");
|
|
||||||
}
|
|
||||||
|
|
||||||
let masterLogDirectory = path.join(parameters.args.logDirectory, "master");
|
|
||||||
if (!await fs.pathExists(masterLogDirectory) && await fs.pathExists("master.log")) {
|
|
||||||
console.log("Migrating master log...");
|
|
||||||
await fs.ensureDir(masterLogDirectory);
|
|
||||||
await libLoggingUtils.migrateLogs("master.log", masterLogDirectory, "master-%DATE%.log");
|
|
||||||
console.log("Migration complete, you should delete master.log now");
|
|
||||||
}
|
|
||||||
/* eslint-enable no-console */
|
|
||||||
}
|
|
||||||
|
|
||||||
// Combined log stream of the whole cluster.
|
// Combined log stream of the whole cluster.
|
||||||
parameters.clusterLogger = winston.createLogger({
|
parameters.clusterLogger = winston.createLogger({
|
||||||
format: winston.format.json(),
|
format: winston.format.json(),
|
||||||
@@ -269,11 +249,11 @@ async function initialize() {
|
|||||||
dirname: path.join(parameters.args.logDirectory, "cluster"),
|
dirname: path.join(parameters.args.logDirectory, "cluster"),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Log stream for the master server.
|
// Log stream for the controller.
|
||||||
logger.add(new winston.transports.DailyRotateFile({
|
logger.add(new winston.transports.DailyRotateFile({
|
||||||
format: winston.format.json(),
|
format: winston.format.json(),
|
||||||
filename: "master-%DATE%.log",
|
filename: "controller-%DATE%.log",
|
||||||
dirname: path.join(parameters.args.logDirectory, "master"),
|
dirname: path.join(parameters.args.logDirectory, "controller"),
|
||||||
}));
|
}));
|
||||||
logger.add(new winston.transports.Stream({
|
logger.add(new winston.transports.Stream({
|
||||||
stream: parameters.clusterLogger,
|
stream: parameters.clusterLogger,
|
||||||
@@ -288,7 +268,7 @@ async function initialize() {
|
|||||||
|
|
||||||
let command = parameters.args._[0];
|
let command = parameters.args._[0];
|
||||||
if (command === "run") {
|
if (command === "run") {
|
||||||
logger.info(`Starting Clusterio master ${version}`);
|
logger.info(`Starting Clusterio controller ${version}`);
|
||||||
parameters.shouldRun = true;
|
parameters.shouldRun = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,39 +293,39 @@ async function initialize() {
|
|||||||
libConfig.registerPluginConfigGroups(parameters.pluginInfos);
|
libConfig.registerPluginConfigGroups(parameters.pluginInfos);
|
||||||
libConfig.finalizeConfigs();
|
libConfig.finalizeConfigs();
|
||||||
|
|
||||||
parameters.masterConfigPath = parameters.args.config;
|
parameters.controllerConfigPath = parameters.args.config;
|
||||||
logger.info(`Loading config from ${parameters.masterConfigPath}`);
|
logger.info(`Loading config from ${parameters.controllerConfigPath}`);
|
||||||
parameters.masterConfig = new libConfig.MasterConfig("master");
|
parameters.controllerConfig = new libConfig.ControllerConfig("controller");
|
||||||
try {
|
try {
|
||||||
await parameters.masterConfig.load(JSON.parse(await fs.readFile(parameters.masterConfigPath)));
|
await parameters.controllerConfig.load(JSON.parse(await fs.readFile(parameters.controllerConfigPath)));
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.code === "ENOENT") {
|
if (err.code === "ENOENT") {
|
||||||
logger.info("Config not found, initializing new config");
|
logger.info("Config not found, initializing new config");
|
||||||
await parameters.masterConfig.init();
|
await parameters.controllerConfig.init();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new libErrors.StartupError(`Failed to load ${parameters.masterConfigPath}: ${err.message}`);
|
throw new libErrors.StartupError(`Failed to load ${parameters.controllerConfigPath}: ${err.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parameters.masterConfig.get("master.auth_secret")) {
|
if (!parameters.controllerConfig.get("controller.auth_secret")) {
|
||||||
logger.info("Generating new master authentication secret");
|
logger.info("Generating new controller authentication secret");
|
||||||
let asyncRandomBytes = util.promisify(crypto.randomBytes);
|
let asyncRandomBytes = util.promisify(crypto.randomBytes);
|
||||||
let bytes = await asyncRandomBytes(256);
|
let bytes = await asyncRandomBytes(256);
|
||||||
parameters.masterConfig.set("master.auth_secret", bytes.toString("base64"));
|
parameters.controllerConfig.set("controller.auth_secret", bytes.toString("base64"));
|
||||||
await libFileOps.safeOutputFile(
|
await libFileOps.safeOutputFile(
|
||||||
parameters.masterConfigPath, JSON.stringify(parameters.masterConfig.serialize(), null, 4)
|
parameters.controllerConfigPath, JSON.stringify(parameters.controllerConfig.serialize(), null, 4)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command === "config") {
|
if (command === "config") {
|
||||||
await libSharedCommands.handleConfigCommand(
|
await libSharedCommands.handleConfigCommand(
|
||||||
parameters.args, parameters.masterConfig, parameters.masterConfigPath
|
parameters.args, parameters.controllerConfig, parameters.controllerConfigPath
|
||||||
);
|
);
|
||||||
|
|
||||||
} else if (command === "bootstrap") {
|
} else if (command === "bootstrap") {
|
||||||
await handleBootstrapCommand(parameters.args, parameters.masterConfig);
|
await handleBootstrapCommand(parameters.args, parameters.controllerConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parameters;
|
return parameters;
|
||||||
@@ -354,14 +334,14 @@ async function initialize() {
|
|||||||
async function startup() {
|
async function startup() {
|
||||||
// Set the process title, shows up as the title of the CMD window on windows
|
// Set the process title, shows up as the title of the CMD window on windows
|
||||||
// and as the process name in ps/top on linux.
|
// and as the process name in ps/top on linux.
|
||||||
process.title = "clusterioMaster";
|
process.title = "clusteriocontroller";
|
||||||
|
|
||||||
let { args, shouldRun, clusterLogger, pluginInfos, masterConfigPath, masterConfig } = await initialize();
|
let { args, shouldRun, clusterLogger, pluginInfos, controllerConfigPath, controllerConfig } = await initialize();
|
||||||
if (!shouldRun) {
|
if (!shouldRun) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
master = new Master(clusterLogger, pluginInfos, masterConfigPath, masterConfig);
|
controller = new Controller(clusterLogger, pluginInfos, controllerConfigPath, controllerConfig);
|
||||||
|
|
||||||
let secondSigint = false;
|
let secondSigint = false;
|
||||||
process.on("SIGINT", () => {
|
process.on("SIGINT", () => {
|
||||||
@@ -374,7 +354,7 @@ async function startup() {
|
|||||||
|
|
||||||
secondSigint = true;
|
secondSigint = true;
|
||||||
logger.info("Caught interrupt signal, shutting down");
|
logger.info("Caught interrupt signal, shutting down");
|
||||||
master.stop();
|
controller.stop();
|
||||||
});
|
});
|
||||||
let secondSigterm = false;
|
let secondSigterm = false;
|
||||||
process.on("SIGTERM", () => {
|
process.on("SIGTERM", () => {
|
||||||
@@ -387,15 +367,15 @@ async function startup() {
|
|||||||
|
|
||||||
secondSigterm = true;
|
secondSigterm = true;
|
||||||
logger.info("Caught termination signal, shutting down");
|
logger.info("Caught termination signal, shutting down");
|
||||||
master.stop();
|
controller.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on("SIGHUP", () => {
|
process.on("SIGHUP", () => {
|
||||||
logger.info("Terminal closed, shutting down");
|
logger.info("Terminal closed, shutting down");
|
||||||
master.stop();
|
controller.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
await master.start(args);
|
await controller.start(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -413,9 +393,9 @@ I version of clusterio. Expect things to break. I
|
|||||||
startup().catch(err => {
|
startup().catch(err => {
|
||||||
if (err instanceof libErrors.StartupError) {
|
if (err instanceof libErrors.StartupError) {
|
||||||
logger.fatal(`
|
logger.fatal(`
|
||||||
+----------------------------------+
|
+-------------------------------+
|
||||||
| Unable to to start master server |
|
| Unable to to start controller |
|
||||||
+----------------------------------+
|
+-------------------------------+
|
||||||
${err.stack}`
|
${err.stack}`
|
||||||
);
|
);
|
||||||
} else if (err instanceof libErrors.PluginError) {
|
} else if (err instanceof libErrors.PluginError) {
|
||||||
@@ -428,7 +408,7 @@ ${err.original.stack}`
|
|||||||
} else {
|
} else {
|
||||||
logger.fatal(`
|
logger.fatal(`
|
||||||
+------------------------------------------------------------+
|
+------------------------------------------------------------+
|
||||||
| Unexpected error occured while starting master, please |
|
| Unexpected error occured while starting controller, please |
|
||||||
| report it to https://github.com/clusterio/clusterio/issues |
|
| report it to https://github.com/clusterio/clusterio/issues |
|
||||||
+------------------------------------------------------------+
|
+------------------------------------------------------------+
|
||||||
${err.stack}`
|
${err.stack}`
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
{
|
{
|
||||||
"name": "@clusterio/master",
|
"name": "@clusterio/controller",
|
||||||
"description": "Implementation of Clusterio master server",
|
"description": "Implementation of Clusterio controller",
|
||||||
"author": "Hornwitser",
|
"author": "Hornwitser",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "2.0.0-alpha.13",
|
"version": "2.0.0-alpha.13",
|
||||||
"main": "master.js",
|
"main": "controller.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepare": "webpack-cli --env production",
|
"prepare": "webpack-cli --env production",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"clusteriomaster": "./master.js"
|
"clusteriocontroller": "./controller.js"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"factorio"
|
"factorio"
|
||||||
@@ -6,58 +6,58 @@ const libPlugin = require("@clusterio/lib/plugin");
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for master server connections
|
* Base class for controller connections
|
||||||
*
|
*
|
||||||
* @extends module:lib/link.Link
|
* @extends module:lib/link.Link
|
||||||
* @alias module:master/src/BaseConnection
|
* @alias module:controller/src/BaseConnection
|
||||||
*/
|
*/
|
||||||
class BaseConnection extends libLink.Link {
|
class BaseConnection extends libLink.Link {
|
||||||
constructor(target, connector, master) {
|
constructor(target, connector, controller) {
|
||||||
/** @member {module:master/src/WsServerConnector} module:master/src/BaseConnection#connector */
|
/** @member {module:controller/src/WsServerConnector} module:controller/src/BaseConnection#connector */
|
||||||
super("master", target, connector);
|
super("controller", target, connector);
|
||||||
this._master = master;
|
this._controller = controller;
|
||||||
this._disconnecting = false;
|
this._disconnecting = false;
|
||||||
libLink.attachAllMessages(this);
|
libLink.attachAllMessages(this);
|
||||||
for (let masterPlugin of this._master.plugins.values()) {
|
for (let controllerPlugin of this._controller.plugins.values()) {
|
||||||
libPlugin.attachPluginMessages(this, masterPlugin);
|
libPlugin.attachPluginMessages(this, controllerPlugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async forwardRequestToInstance(message, request) {
|
async forwardRequestToInstance(message, request) {
|
||||||
return await this._master.forwardRequestToInstance(request, message.data);
|
return await this._controller.forwardRequestToInstance(request, message.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
async forwardEventToInstance(message, event) {
|
async forwardEventToInstance(message, event) {
|
||||||
let instance = this._master.instances.get(message.data.instance_id);
|
let instance = this._controller.instances.get(message.data.instance_id);
|
||||||
if (!instance) { return; }
|
if (!instance) { return; }
|
||||||
|
|
||||||
let slaveId = instance.config.get("instance.assigned_slave");
|
let hostId = instance.config.get("instance.assigned_host");
|
||||||
if (slaveId === null) { return; }
|
if (hostId === null) { return; }
|
||||||
|
|
||||||
let connection = this._master.wsServer.slaveConnections.get(slaveId);
|
let connection = this._controller.wsServer.hostConnections.get(hostId);
|
||||||
if (!connection || connection.closing) { return; }
|
if (!connection || connection.closing) { return; }
|
||||||
if (event.plugin && !connection.plugins.has(event.plugin)) { return; }
|
if (event.plugin && !connection.plugins.has(event.plugin)) { return; }
|
||||||
|
|
||||||
event.send(connection, message.data);
|
event.send(connection, message.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
async broadcastEventToSlaves(message, event) {
|
async broadcastEventToHosts(message, event) {
|
||||||
for (let slaveConnection of this._master.wsServer.slaveConnections.values()) {
|
for (let hostConnection of this._controller.wsServer.hostConnections.values()) {
|
||||||
// Do not broadcast back to the source
|
// Do not broadcast back to the source
|
||||||
if (slaveConnection === this) { continue; }
|
if (hostConnection === this) { continue; }
|
||||||
if (slaveConnection.connector.closing) { continue; }
|
if (hostConnection.connector.closing) { continue; }
|
||||||
if (event.plugin && !slaveConnection.plugins.has(event.plugin)) { continue; }
|
if (event.plugin && !hostConnection.plugins.has(event.plugin)) { continue; }
|
||||||
|
|
||||||
event.send(slaveConnection, message.data);
|
event.send(hostConnection, message.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async broadcastEventToInstance(message, event) {
|
async broadcastEventToInstance(message, event) {
|
||||||
await this.broadcastEventToSlaves(message, event);
|
await this.broadcastEventToHosts(message, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
async prepareDisconnectRequestHandler(message, request) {
|
async prepareDisconnectRequestHandler(message, request) {
|
||||||
await libPlugin.invokeHook(this._master.plugins, "onPrepareSlaveDisconnect", this);
|
await libPlugin.invokeHook(this._controller.plugins, "onPrepareHostDisconnect", this);
|
||||||
this._disconnecting = true;
|
this._disconnecting = true;
|
||||||
this.connector.setClosing();
|
this.connector.setClosing();
|
||||||
return await super.prepareDisconnectRequestHandler(message, request);
|
return await super.prepareDisconnectRequestHandler(message, request);
|
||||||
@@ -87,7 +87,7 @@ class BaseConnection extends libLink.Link {
|
|||||||
|
|
||||||
async getModPackRequestHandler(message) {
|
async getModPackRequestHandler(message) {
|
||||||
let { id } = message.data;
|
let { id } = message.data;
|
||||||
let modPack = this._master.modPacks.get(id);
|
let modPack = this._controller.modPacks.get(id);
|
||||||
if (!modPack) {
|
if (!modPack) {
|
||||||
throw new libErrors.RequestError(`Mod pack with ID ${id} does not exist`);
|
throw new libErrors.RequestError(`Mod pack with ID ${id} does not exist`);
|
||||||
}
|
}
|
||||||
@@ -95,11 +95,11 @@ class BaseConnection extends libLink.Link {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getDefaultModPackRequestHandler(message) {
|
async getDefaultModPackRequestHandler(message) {
|
||||||
let id = this._master.config.get("master.default_mod_pack_id");
|
let id = this._controller.config.get("controller.default_mod_pack_id");
|
||||||
if (id === null) {
|
if (id === null) {
|
||||||
throw new libErrors.RequestError("Default mod pack not set on master");
|
throw new libErrors.RequestError("Default mod pack not set on controller");
|
||||||
}
|
}
|
||||||
let modPack = this._master.modPacks.get(id);
|
let modPack = this._controller.modPacks.get(id);
|
||||||
if (!modPack) {
|
if (!modPack) {
|
||||||
throw new libErrors.RequestError(`Default mod pack configured (${id}) does not exist`);
|
throw new libErrors.RequestError(`Default mod pack configured (${id}) does not exist`);
|
||||||
}
|
}
|
||||||
+189
-189
@@ -21,19 +21,19 @@ const routes = require("./routes");
|
|||||||
const strcmp = new Intl.Collator(undefined, { numerice: "true", sensitivity: "base" }).compare;
|
const strcmp = new Intl.Collator(undefined, { numerice: "true", sensitivity: "base" }).compare;
|
||||||
|
|
||||||
const queryLogTime = new libPrometheus.Summary(
|
const queryLogTime = new libPrometheus.Summary(
|
||||||
"clusterio_master_query_log_duration_seconds",
|
"clusterio_controller_query_log_duration_seconds",
|
||||||
"Time in seconds log queries took to execute."
|
"Time in seconds log queries took to execute."
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the connection to a control link
|
* Represents the connection to a control link
|
||||||
*
|
*
|
||||||
* @extends module:master/src/BaseConnection
|
* @extends module:controller/src/BaseConnection
|
||||||
* @alias module:master/src/ControlConnection
|
* @alias module:controller/src/ControlConnection
|
||||||
*/
|
*/
|
||||||
class ControlConnection extends BaseConnection {
|
class ControlConnection extends BaseConnection {
|
||||||
constructor(registerData, connector, master, user) {
|
constructor(registerData, connector, controller, user) {
|
||||||
super("control", connector, master);
|
super("control", connector, controller);
|
||||||
|
|
||||||
this._agent = registerData.agent;
|
this._agent = registerData.agent;
|
||||||
this._version = registerData.version;
|
this._version = registerData.version;
|
||||||
@@ -44,9 +44,9 @@ class ControlConnection extends BaseConnection {
|
|||||||
*/
|
*/
|
||||||
this.user = user;
|
this.user = user;
|
||||||
|
|
||||||
this.slaveSubscriptions = {
|
this.hostSubscriptions = {
|
||||||
all: false,
|
all: false,
|
||||||
slave_ids: [],
|
host_ids: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
this.instanceSubscriptions = {
|
this.instanceSubscriptions = {
|
||||||
@@ -77,8 +77,8 @@ class ControlConnection extends BaseConnection {
|
|||||||
this.logTransport = null;
|
this.logTransport = null;
|
||||||
this.logSubscriptions = {
|
this.logSubscriptions = {
|
||||||
all: false,
|
all: false,
|
||||||
master: false,
|
controller: false,
|
||||||
slave_ids: [],
|
host_ids: [],
|
||||||
instance_ids: [],
|
instance_ids: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -92,101 +92,101 @@ class ControlConnection extends BaseConnection {
|
|||||||
logger.remove(this.logTransport);
|
logger.remove(this.logTransport);
|
||||||
}
|
}
|
||||||
if (this.ws_dumper) {
|
if (this.ws_dumper) {
|
||||||
this._master.debugEvents.off("message", this.ws_dumper);
|
this._controller.debugEvents.off("message", this.ws_dumper);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (let event of ["connect", "drop", "resume", "close"]) {
|
for (let event of ["connect", "drop", "resume", "close"]) {
|
||||||
this.connector.on(event, () => {
|
this.connector.on(event, () => {
|
||||||
for (let masterPlugin of this._master.plugins.values()) {
|
for (let controllerPlugin of this._controller.plugins.values()) {
|
||||||
masterPlugin.onControlConnectionEvent(this, event);
|
controllerPlugin.onControlConnectionEvent(this, event);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getMasterConfigRequestHandler() {
|
async getControllerConfigRequestHandler() {
|
||||||
return { serialized_config: this._master.config.serialize("control") };
|
return { serialized_config: this._controller.config.serialize("control") };
|
||||||
}
|
}
|
||||||
|
|
||||||
async setMasterConfigFieldRequestHandler(message) {
|
async setControllerConfigFieldRequestHandler(message) {
|
||||||
this._master.config.set(message.data.field, message.data.value, "control");
|
this._controller.config.set(message.data.field, message.data.value, "control");
|
||||||
}
|
}
|
||||||
|
|
||||||
async setMasterConfigPropRequestHandler(message) {
|
async setControllerConfigPropRequestHandler(message) {
|
||||||
let { field, prop, value } = message.data;
|
let { field, prop, value } = message.data;
|
||||||
this._master.config.setProp(field, prop, value, "control");
|
this._controller.config.setProp(field, prop, value, "control");
|
||||||
}
|
}
|
||||||
|
|
||||||
async listSlavesRequestHandler(message) {
|
async listHostsRequestHandler(message) {
|
||||||
let list = [];
|
let list = [];
|
||||||
for (let slave of this._master.slaves.values()) {
|
for (let host of this._controller.hosts.values()) {
|
||||||
list.push({
|
list.push({
|
||||||
agent: slave.agent,
|
agent: host.agent,
|
||||||
version: slave.version,
|
version: host.version,
|
||||||
id: slave.id,
|
id: host.id,
|
||||||
name: slave.name,
|
name: host.name,
|
||||||
public_address: slave.public_address || null,
|
public_address: host.public_address || null,
|
||||||
connected: this._master.wsServer.slaveConnections.has(slave.id),
|
connected: this._controller.wsServer.hostConnections.has(host.id),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return { list };
|
return { list };
|
||||||
}
|
}
|
||||||
|
|
||||||
async setSlaveSubscriptionsRequestHandler(message) {
|
async setHostSubscriptionsRequestHandler(message) {
|
||||||
this.slaveSubscriptions = message.data;
|
this.hostSubscriptions = message.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
slaveUpdated(slave, update) {
|
hostUpdated(host, update) {
|
||||||
if (
|
if (
|
||||||
this.slaveSubscriptions.all
|
this.hostSubscriptions.all
|
||||||
|| this.slaveSubscriptions.slave_ids.includes(slave.id)
|
|| this.hostSubscriptions.host_ids.includes(host.id)
|
||||||
) {
|
) {
|
||||||
libLink.messages.slaveUpdate.send(this, update);
|
libLink.messages.hostUpdate.send(this, update);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
generateSlaveToken(slaveId) {
|
generateHostToken(hostId) {
|
||||||
return jwt.sign(
|
return jwt.sign(
|
||||||
{ aud: "slave", slave: slaveId },
|
{ aud: "host", host: hostId },
|
||||||
Buffer.from(this._master.config.get("master.auth_secret"), "base64")
|
Buffer.from(this._controller.config.get("controller.auth_secret"), "base64")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async generateSlaveTokenRequestHandler(message) {
|
async generateHostTokenRequestHandler(message) {
|
||||||
let slaveId = message.data.slave_id;
|
let hostId = message.data.host_id;
|
||||||
if (slaveId === null) {
|
if (hostId === null) {
|
||||||
slaveId = Math.random() * 2**31 | 0;
|
hostId = Math.random() * 2**31 | 0;
|
||||||
}
|
}
|
||||||
return { token: this.generateSlaveToken(slaveId) };
|
return { token: this.generateHostToken(hostId) };
|
||||||
}
|
}
|
||||||
|
|
||||||
async createSlaveConfigRequestHandler(message) {
|
async createHostConfigRequestHandler(message) {
|
||||||
let slaveConfig = new libConfig.SlaveConfig("control");
|
let hostConfig = new libConfig.HostConfig("control");
|
||||||
await slaveConfig.init();
|
await hostConfig.init();
|
||||||
|
|
||||||
slaveConfig.set("slave.master_url", this._master.getMasterUrl());
|
hostConfig.set("host.controller_url", this._controller.getControllerUrl());
|
||||||
if (message.data.id !== null) {
|
if (message.data.id !== null) {
|
||||||
slaveConfig.set("slave.id", message.data.id);
|
hostConfig.set("host.id", message.data.id);
|
||||||
}
|
}
|
||||||
if (message.data.name !== null) {
|
if (message.data.name !== null) {
|
||||||
slaveConfig.set("slave.name", message.data.name);
|
hostConfig.set("host.name", message.data.name);
|
||||||
}
|
}
|
||||||
if (message.data.generate_token) {
|
if (message.data.generate_token) {
|
||||||
this.user.checkPermission("core.slave.generate_token");
|
this.user.checkPermission("core.host.generate_token");
|
||||||
slaveConfig.set("slave.master_token", this.generateSlaveToken(slaveConfig.get("slave.id")));
|
hostConfig.set("host.controller_token", this.generateHostToken(hostConfig.get("host.id")));
|
||||||
}
|
}
|
||||||
return { serialized_config: slaveConfig.serialize() };
|
return { serialized_config: hostConfig.serialize() };
|
||||||
}
|
}
|
||||||
|
|
||||||
async getInstanceRequestHandler(message) {
|
async getInstanceRequestHandler(message) {
|
||||||
let id = message.data.id;
|
let id = message.data.id;
|
||||||
let instance = this._master.getRequestInstance(id);
|
let instance = this._controller.getRequestInstance(id);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
name: instance.config.get("instance.name"),
|
name: instance.config.get("instance.name"),
|
||||||
assigned_slave: instance.config.get("instance.assigned_slave"),
|
assigned_host: instance.config.get("instance.assigned_host"),
|
||||||
game_port: instance.game_port || null,
|
game_port: instance.game_port || null,
|
||||||
status: instance.status,
|
status: instance.status,
|
||||||
};
|
};
|
||||||
@@ -194,11 +194,11 @@ class ControlConnection extends BaseConnection {
|
|||||||
|
|
||||||
async listInstancesRequestHandler(message) {
|
async listInstancesRequestHandler(message) {
|
||||||
let list = [];
|
let list = [];
|
||||||
for (let instance of this._master.instances.values()) {
|
for (let instance of this._controller.instances.values()) {
|
||||||
list.push({
|
list.push({
|
||||||
id: instance.config.get("instance.id"),
|
id: instance.config.get("instance.id"),
|
||||||
name: instance.config.get("instance.name"),
|
name: instance.config.get("instance.name"),
|
||||||
assigned_slave: instance.config.get("instance.assigned_slave"),
|
assigned_host: instance.config.get("instance.assigned_host"),
|
||||||
game_port: instance.game_port || null,
|
game_port: instance.game_port || null,
|
||||||
status: instance.status,
|
status: instance.status,
|
||||||
});
|
});
|
||||||
@@ -218,27 +218,27 @@ class ControlConnection extends BaseConnection {
|
|||||||
libLink.messages.instanceUpdate.send(this, {
|
libLink.messages.instanceUpdate.send(this, {
|
||||||
id: instance.config.get("instance.id"),
|
id: instance.config.get("instance.id"),
|
||||||
name: instance.config.get("instance.name"),
|
name: instance.config.get("instance.name"),
|
||||||
assigned_slave: instance.config.get("instance.assigned_slave"),
|
assigned_host: instance.config.get("instance.assigned_host"),
|
||||||
game_port: instance.game_port || null,
|
game_port: instance.game_port || null,
|
||||||
status: instance.status,
|
status: instance.status,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX should probably add a hook for slave reuqests?
|
// XXX should probably add a hook for host reuqests?
|
||||||
async createInstanceRequestHandler(message) {
|
async createInstanceRequestHandler(message) {
|
||||||
let instanceConfig = new libConfig.InstanceConfig("master");
|
let instanceConfig = new libConfig.InstanceConfig("controller");
|
||||||
await instanceConfig.load(message.data.serialized_config);
|
await instanceConfig.load(message.data.serialized_config);
|
||||||
|
|
||||||
let instanceId = instanceConfig.get("instance.id");
|
let instanceId = instanceConfig.get("instance.id");
|
||||||
if (this._master.instances.has(instanceId)) {
|
if (this._controller.instances.has(instanceId)) {
|
||||||
throw new libErrors.RequestError(`Instance with ID ${instanceId} already exists`);
|
throw new libErrors.RequestError(`Instance with ID ${instanceId} already exists`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add common settings for the Factorio server
|
// Add common settings for the Factorio server
|
||||||
let settings = {
|
let settings = {
|
||||||
"name": `${this._master.config.get("master.name")} - ${instanceConfig.get("instance.name")}`,
|
"name": `${this._controller.config.get("controller.name")} - ${instanceConfig.get("instance.name")}`,
|
||||||
"description": `Clusterio instance for ${this._master.config.get("master.name")}`,
|
"description": `Clusterio instance for ${this._controller.config.get("controller.name")}`,
|
||||||
"tags": ["clusterio"],
|
"tags": ["clusterio"],
|
||||||
"max_players": 0,
|
"max_players": 0,
|
||||||
"visibility": { "public": true, "lan": true },
|
"visibility": { "public": true, "lan": true },
|
||||||
@@ -262,48 +262,48 @@ class ControlConnection extends BaseConnection {
|
|||||||
instanceConfig.set("factorio.settings", settings);
|
instanceConfig.set("factorio.settings", settings);
|
||||||
|
|
||||||
let instance = { config: instanceConfig, status: "unassigned" };
|
let instance = { config: instanceConfig, status: "unassigned" };
|
||||||
this._master.instances.set(instanceId, instance);
|
this._controller.instances.set(instanceId, instance);
|
||||||
await libPlugin.invokeHook(this._master.plugins, "onInstanceStatusChanged", instance, null);
|
await libPlugin.invokeHook(this._controller.plugins, "onInstanceStatusChanged", instance, null);
|
||||||
this._master.addInstanceHooks(instance);
|
this._controller.addInstanceHooks(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteInstanceRequestHandler(message, request) {
|
async deleteInstanceRequestHandler(message, request) {
|
||||||
let instance = this._master.getRequestInstance(message.data.instance_id);
|
let instance = this._controller.getRequestInstance(message.data.instance_id);
|
||||||
if (instance.config.get("instance.assigned_slave") !== null) {
|
if (instance.config.get("instance.assigned_host") !== null) {
|
||||||
await this.forwardRequestToInstance(message, request);
|
await this.forwardRequestToInstance(message, request);
|
||||||
}
|
}
|
||||||
this._master.instances.delete(message.data.instance_id);
|
this._controller.instances.delete(message.data.instance_id);
|
||||||
|
|
||||||
let prev = instance.status;
|
let prev = instance.status;
|
||||||
instance.status = "deleted";
|
instance.status = "deleted";
|
||||||
this._master.instanceUpdated(instance);
|
this._controller.instanceUpdated(instance);
|
||||||
await libPlugin.invokeHook(this._master.plugins, "onInstanceStatusChanged", instance, prev);
|
await libPlugin.invokeHook(this._controller.plugins, "onInstanceStatusChanged", instance, prev);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getInstanceConfigRequestHandler(message) {
|
async getInstanceConfigRequestHandler(message) {
|
||||||
let instance = this._master.getRequestInstance(message.data.instance_id);
|
let instance = this._controller.getRequestInstance(message.data.instance_id);
|
||||||
return {
|
return {
|
||||||
serialized_config: instance.config.serialize("control"),
|
serialized_config: instance.config.serialize("control"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateInstanceConfig(instance) {
|
async updateInstanceConfig(instance) {
|
||||||
let slaveId = instance.config.get("instance.assigned_slave");
|
let hostId = instance.config.get("instance.assigned_host");
|
||||||
if (slaveId !== null) {
|
if (hostId !== null) {
|
||||||
let connection = this._master.wsServer.slaveConnections.get(slaveId);
|
let connection = this._controller.wsServer.hostConnections.get(hostId);
|
||||||
if (connection) {
|
if (connection) {
|
||||||
await libLink.messages.assignInstance.send(connection, {
|
await libLink.messages.assignInstance.send(connection, {
|
||||||
instance_id: instance.config.get("instance.id"),
|
instance_id: instance.config.get("instance.id"),
|
||||||
serialized_config: instance.config.serialize("slave"),
|
serialized_config: instance.config.serialize("host"),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async setInstanceConfigFieldRequestHandler(message) {
|
async setInstanceConfigFieldRequestHandler(message) {
|
||||||
let instance = this._master.getRequestInstance(message.data.instance_id);
|
let instance = this._controller.getRequestInstance(message.data.instance_id);
|
||||||
if (message.data.field === "instance.assigned_slave") {
|
if (message.data.field === "instance.assigned_host") {
|
||||||
throw new libErrors.RequestError("instance.assigned_slave must be set through the assign-slave interface");
|
throw new libErrors.RequestError("instance.assigned_host must be set through the assign-host interface");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.data.field === "instance.id") {
|
if (message.data.field === "instance.id") {
|
||||||
@@ -316,49 +316,49 @@ class ControlConnection extends BaseConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async setInstanceConfigPropRequestHandler(message) {
|
async setInstanceConfigPropRequestHandler(message) {
|
||||||
let instance = this._master.getRequestInstance(message.data.instance_id);
|
let instance = this._controller.getRequestInstance(message.data.instance_id);
|
||||||
let { field, prop, value } = message.data;
|
let { field, prop, value } = message.data;
|
||||||
instance.config.setProp(field, prop, value, "control");
|
instance.config.setProp(field, prop, value, "control");
|
||||||
await this.updateInstanceConfig(instance);
|
await this.updateInstanceConfig(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
async assignInstanceCommandRequestHandler(message, request) {
|
async assignInstanceCommandRequestHandler(message, request) {
|
||||||
let { slave_id, instance_id } = message.data;
|
let { host_id, instance_id } = message.data;
|
||||||
let instance = this._master.getRequestInstance(instance_id);
|
let instance = this._controller.getRequestInstance(instance_id);
|
||||||
|
|
||||||
// Check if target slave is connected
|
// Check if target host is connected
|
||||||
let newSlaveConnection;
|
let newHostConnection;
|
||||||
if (slave_id !== null) {
|
if (host_id !== null) {
|
||||||
newSlaveConnection = this._master.wsServer.slaveConnections.get(slave_id);
|
newHostConnection = this._controller.wsServer.hostConnections.get(host_id);
|
||||||
if (!newSlaveConnection) {
|
if (!newHostConnection) {
|
||||||
// The case of the slave not getting the assign instance message
|
// The case of the host not getting the assign instance message
|
||||||
// still have to be handled, so it's not a requirement that the
|
// still have to be handled, so it's not a requirement that the
|
||||||
// target slave be connected to the master while doing the
|
// target host be connected to the controller while doing the
|
||||||
// assignment, but it is IMHO a better user experience if this
|
// assignment, but it is IMHO a better user experience if this
|
||||||
// is the case.
|
// is the case.
|
||||||
throw new libErrors.RequestError("Target slave is not connected to the master server");
|
throw new libErrors.RequestError("Target host is not connected to the controller");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unassign from currently assigned slave if it is connected.
|
// Unassign from currently assigned host if it is connected.
|
||||||
let currentAssignedSlave = instance.config.get("instance.assigned_slave");
|
let currentAssignedHost = instance.config.get("instance.assigned_host");
|
||||||
if (currentAssignedSlave !== null && slave_id !== currentAssignedSlave) {
|
if (currentAssignedHost !== null && host_id !== currentAssignedHost) {
|
||||||
let oldSlaveConnection = this._master.wsServer.slaveConnections.get(currentAssignedSlave);
|
let oldHostConnection = this._controller.wsServer.hostConnections.get(currentAssignedHost);
|
||||||
if (oldSlaveConnection && !oldSlaveConnection.connector.closing) {
|
if (oldHostConnection && !oldHostConnection.connector.closing) {
|
||||||
await libLink.messages.unassignInstance.send(oldSlaveConnection, { instance_id });
|
await libLink.messages.unassignInstance.send(oldHostConnection, { instance_id });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign to target
|
// Assign to target
|
||||||
instance.config.set("instance.assigned_slave", slave_id);
|
instance.config.set("instance.assigned_host", host_id);
|
||||||
if (slave_id !== null) {
|
if (host_id !== null) {
|
||||||
await libLink.messages.assignInstance.send(newSlaveConnection, {
|
await libLink.messages.assignInstance.send(newHostConnection, {
|
||||||
instance_id,
|
instance_id,
|
||||||
serialized_config: instance.config.serialize("slave"),
|
serialized_config: instance.config.serialize("host"),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
instance.status = "unassigned";
|
instance.status = "unassigned";
|
||||||
this._master.instanceUpdated(instance);
|
this._controller.instanceUpdated(instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,18 +377,18 @@ class ControlConnection extends BaseConnection {
|
|||||||
|
|
||||||
async downloadSaveRequestHandler(message) {
|
async downloadSaveRequestHandler(message) {
|
||||||
let { instance_id, save } = message.data;
|
let { instance_id, save } = message.data;
|
||||||
let stream = await routes.createProxyStream(this._master.app);
|
let stream = await routes.createProxyStream(this._controller.app);
|
||||||
stream.filename = save;
|
stream.filename = save;
|
||||||
|
|
||||||
let ready = new Promise((resolve, reject) => {
|
let ready = new Promise((resolve, reject) => {
|
||||||
stream.events.on("source", resolve);
|
stream.events.on("source", resolve);
|
||||||
stream.events.on("timeout", () => reject(
|
stream.events.on("timeout", () => reject(
|
||||||
new libErrors.RequestError("Timed out establishing stream from slave")
|
new libErrors.RequestError("Timed out establishing stream from host")
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
ready.catch(() => {});
|
ready.catch(() => {});
|
||||||
|
|
||||||
await this._master.forwardRequestToInstance(libLink.messages.pushSave, {
|
await this._controller.forwardRequestToInstance(libLink.messages.pushSave, {
|
||||||
instance_id,
|
instance_id,
|
||||||
stream_id: stream.id,
|
stream_id: stream.id,
|
||||||
save,
|
save,
|
||||||
@@ -409,35 +409,35 @@ class ControlConnection extends BaseConnection {
|
|||||||
if (instance_id === target_instance_id) {
|
if (instance_id === target_instance_id) {
|
||||||
throw new libErrors.RequestError("Source and target instance may not be the same");
|
throw new libErrors.RequestError("Source and target instance may not be the same");
|
||||||
}
|
}
|
||||||
let sourceInstance = this._master.getRequestInstance(instance_id);
|
let sourceInstance = this._controller.getRequestInstance(instance_id);
|
||||||
let targetInstance = this._master.getRequestInstance(target_instance_id);
|
let targetInstance = this._controller.getRequestInstance(target_instance_id);
|
||||||
let sourceSlaveId = sourceInstance.config.get("instance.assigned_slave");
|
let sourceHostId = sourceInstance.config.get("instance.assigned_host");
|
||||||
let targetSlaveId = targetInstance.config.get("instance.assigned_slave");
|
let targetHostId = targetInstance.config.get("instance.assigned_host");
|
||||||
if (sourceSlaveId === null) {
|
if (sourceHostId === null) {
|
||||||
throw new libErrors.RequestError("Source instance is not assigned a slave");
|
throw new libErrors.RequestError("Source instance is not assigned a host");
|
||||||
}
|
}
|
||||||
if (targetSlaveId === null) {
|
if (targetHostId === null) {
|
||||||
throw new libErrors.RequestError("Target instance is not assigned a slave");
|
throw new libErrors.RequestError("Target instance is not assigned a host");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let slave handle request if source and target is on the same slave.
|
// Let host handle request if source and target is on the same host.
|
||||||
if (sourceSlaveId === targetSlaveId) {
|
if (sourceHostId === targetHostId) {
|
||||||
return await this.forwardRequestToInstance(message, request);
|
return await this.forwardRequestToInstance(message, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check connectivity
|
// Check connectivity
|
||||||
let sourceSlaveConnection = this._master.wsServer.slaveConnections.get(sourceSlaveId);
|
let sourceHostConnection = this._controller.wsServer.hostConnections.get(sourceHostId);
|
||||||
if (!sourceSlaveConnection || sourceSlaveConnection.closing) {
|
if (!sourceHostConnection || sourceHostConnection.closing) {
|
||||||
throw new libErrors.RequestError("Source slave is not connected to the master server");
|
throw new libErrors.RequestError("Source host is not connected to the controller");
|
||||||
}
|
}
|
||||||
|
|
||||||
let targetSlaveConnection = this._master.wsServer.slaveConnections.get(targetSlaveId);
|
let targetHostConnection = this._controller.wsServer.hostConnections.get(targetHostId);
|
||||||
if (!targetSlaveConnection || targetSlaveConnection.closing) {
|
if (!targetHostConnection || targetHostConnection.closing) {
|
||||||
throw new libErrors.RequestError("Target slave is not connected to the master server");
|
throw new libErrors.RequestError("Target host is not connected to the controller");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create stream to proxy from target to source
|
// Create stream to proxy from target to source
|
||||||
let stream = await routes.createProxyStream(this._master.app);
|
let stream = await routes.createProxyStream(this._controller.app);
|
||||||
stream.events.on("timeout", () => {
|
stream.events.on("timeout", () => {
|
||||||
if (stream.source) {
|
if (stream.source) {
|
||||||
stream.source.destroy();
|
stream.source.destroy();
|
||||||
@@ -448,10 +448,10 @@ class ControlConnection extends BaseConnection {
|
|||||||
// Ignore errors if not listening for them to avoid crash.
|
// Ignore errors if not listening for them to avoid crash.
|
||||||
stream.events.on("error", () => { /* ignore */ });
|
stream.events.on("error", () => { /* ignore */ });
|
||||||
|
|
||||||
// Establish push from source slave to stream, this is done first to
|
// Establish push from source host to stream, this is done first to
|
||||||
// ensure the file size is known prior to the target slave pull.
|
// ensure the file size is known prior to the target host pull.
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
this._master.forwardRequestToInstance(libLink.messages.pushSave, {
|
this._controller.forwardRequestToInstance(libLink.messages.pushSave, {
|
||||||
instance_id,
|
instance_id,
|
||||||
stream_id: stream.id,
|
stream_id: stream.id,
|
||||||
save: source_save,
|
save: source_save,
|
||||||
@@ -459,8 +459,8 @@ class ControlConnection extends BaseConnection {
|
|||||||
events.once(stream.events, "source"),
|
events.once(stream.events, "source"),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Establish pull from target slave to stream and wait for completion.
|
// Establish pull from target host to stream and wait for completion.
|
||||||
let result = await this._master.forwardRequestToInstance(libLink.messages.pullSave, {
|
let result = await this._controller.forwardRequestToInstance(libLink.messages.pullSave, {
|
||||||
instance_id: target_instance_id,
|
instance_id: target_instance_id,
|
||||||
stream_id: stream.id,
|
stream_id: stream.id,
|
||||||
filename: target_save,
|
filename: target_save,
|
||||||
@@ -468,7 +468,7 @@ class ControlConnection extends BaseConnection {
|
|||||||
|
|
||||||
// Delete source save if this is not a copy
|
// Delete source save if this is not a copy
|
||||||
if (!copy) {
|
if (!copy) {
|
||||||
await this._master.forwardRequestToInstance(libLink.messages.deleteSave, {
|
await this._controller.forwardRequestToInstance(libLink.messages.deleteSave, {
|
||||||
instance_id,
|
instance_id,
|
||||||
save: source_save,
|
save: source_save,
|
||||||
});
|
});
|
||||||
@@ -478,7 +478,7 @@ class ControlConnection extends BaseConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async listModPacksRequestHandler(message) {
|
async listModPacksRequestHandler(message) {
|
||||||
return { list: [...this._master.modPacks.values()].map(pack => pack.toJSON()) };
|
return { list: [...this._controller.modPacks.values()].map(pack => pack.toJSON()) };
|
||||||
}
|
}
|
||||||
|
|
||||||
async setModPackSubscriptionsRequestHandler(message) {
|
async setModPackSubscriptionsRequestHandler(message) {
|
||||||
@@ -487,31 +487,31 @@ class ControlConnection extends BaseConnection {
|
|||||||
|
|
||||||
async createModPackRequestHandler(message) {
|
async createModPackRequestHandler(message) {
|
||||||
let modPack = new libData.ModPack(message.data.mod_pack);
|
let modPack = new libData.ModPack(message.data.mod_pack);
|
||||||
if (this._master.modPacks.has(modPack.id)) {
|
if (this._controller.modPacks.has(modPack.id)) {
|
||||||
throw new libErrors.RequestError(`Mod pack with ID ${modPack.id} already exist`);
|
throw new libErrors.RequestError(`Mod pack with ID ${modPack.id} already exist`);
|
||||||
}
|
}
|
||||||
this._master.modPacks.set(modPack.id, modPack);
|
this._controller.modPacks.set(modPack.id, modPack);
|
||||||
this._master.modPackUpdated(modPack);
|
this._controller.modPackUpdated(modPack);
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateModPackRequestHandler(message) {
|
async updateModPackRequestHandler(message) {
|
||||||
let modPack = new libData.ModPack(message.data.mod_pack);
|
let modPack = new libData.ModPack(message.data.mod_pack);
|
||||||
if (!this._master.modPacks.has(modPack.id)) {
|
if (!this._controller.modPacks.has(modPack.id)) {
|
||||||
throw new libErrors.RequestError(`Mod pack with ID ${modPack.id} does not exist`);
|
throw new libErrors.RequestError(`Mod pack with ID ${modPack.id} does not exist`);
|
||||||
}
|
}
|
||||||
this._master.modPacks.set(modPack.id, modPack);
|
this._controller.modPacks.set(modPack.id, modPack);
|
||||||
this._master.modPackUpdated(modPack);
|
this._controller.modPackUpdated(modPack);
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteModPackRequestHandler(message) {
|
async deleteModPackRequestHandler(message) {
|
||||||
let { id } = message.data;
|
let { id } = message.data;
|
||||||
let modPack = this._master.modPacks.get(id);
|
let modPack = this._controller.modPacks.get(id);
|
||||||
if (!modPack) {
|
if (!modPack) {
|
||||||
throw new libErrors.RequestError(`Mod pack with ID ${id} does not exist`);
|
throw new libErrors.RequestError(`Mod pack with ID ${id} does not exist`);
|
||||||
}
|
}
|
||||||
modPack.isDeleted = true;
|
modPack.isDeleted = true;
|
||||||
this._master.modPacks.delete(id);
|
this._controller.modPacks.delete(id);
|
||||||
this._master.modPackUpdated(modPack);
|
this._controller.modPackUpdated(modPack);
|
||||||
}
|
}
|
||||||
|
|
||||||
modPackUpdated(modPack) {
|
modPackUpdated(modPack) {
|
||||||
@@ -526,7 +526,7 @@ class ControlConnection extends BaseConnection {
|
|||||||
async getModRequestHandler(message) {
|
async getModRequestHandler(message) {
|
||||||
let { name, version } = message.data;
|
let { name, version } = message.data;
|
||||||
let filename = `${name}_${version}.zip`;
|
let filename = `${name}_${version}.zip`;
|
||||||
let mod = this._master.mods.get(filename);
|
let mod = this._controller.mods.get(filename);
|
||||||
if (!mod) {
|
if (!mod) {
|
||||||
throw new libErrors.RequestError(`Mod ${filename} does not exist`);
|
throw new libErrors.RequestError(`Mod ${filename} does not exist`);
|
||||||
}
|
}
|
||||||
@@ -536,7 +536,7 @@ class ControlConnection extends BaseConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async listModsRequestHandler(message) {
|
async listModsRequestHandler(message) {
|
||||||
return { list: [...this._master.mods.values()].map(mod => mod.toJSON()) };
|
return { list: [...this._controller.mods.values()].map(mod => mod.toJSON()) };
|
||||||
}
|
}
|
||||||
|
|
||||||
static termsMatchesMod(terms, mod) {
|
static termsMatchesMod(terms, mod) {
|
||||||
@@ -575,7 +575,7 @@ class ControlConnection extends BaseConnection {
|
|||||||
let factorioVersion = message.data.factorio_version;
|
let factorioVersion = message.data.factorio_version;
|
||||||
|
|
||||||
let results = new Map();
|
let results = new Map();
|
||||||
for (let mod of this._master.mods.values()) {
|
for (let mod of this._controller.mods.values()) {
|
||||||
if (
|
if (
|
||||||
mod.factorioVersion !== factorioVersion
|
mod.factorioVersion !== factorioVersion
|
||||||
|| !ControlConnection.termsMatchesMod(query.terms, mod)
|
|| !ControlConnection.termsMatchesMod(query.terms, mod)
|
||||||
@@ -634,13 +634,13 @@ class ControlConnection extends BaseConnection {
|
|||||||
async downloadModRequestHandler(message) {
|
async downloadModRequestHandler(message) {
|
||||||
let { name, version } = message.data;
|
let { name, version } = message.data;
|
||||||
let filename = `${name}_${version}.zip`;
|
let filename = `${name}_${version}.zip`;
|
||||||
let mod = this._master.mods.get(filename);
|
let mod = this._controller.mods.get(filename);
|
||||||
if (!mod) {
|
if (!mod) {
|
||||||
throw new libErrors.RequestError(`Mod ${filename} does not exist`);
|
throw new libErrors.RequestError(`Mod ${filename} does not exist`);
|
||||||
}
|
}
|
||||||
let modPath = path.join(this._master.config.get("master.mods_directory"), mod.filename);
|
let modPath = path.join(this._controller.config.get("controller.mods_directory"), mod.filename);
|
||||||
|
|
||||||
let stream = await routes.createProxyStream(this._master.app);
|
let stream = await routes.createProxyStream(this._controller.app);
|
||||||
stream.filename = mod.filename;
|
stream.filename = mod.filename;
|
||||||
stream.source = fs.createReadStream(modPath);
|
stream.source = fs.createReadStream(modPath);
|
||||||
stream.mime = "application/zip";
|
stream.mime = "application/zip";
|
||||||
@@ -650,7 +650,7 @@ class ControlConnection extends BaseConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async deleteModRequestHandler(message) {
|
async deleteModRequestHandler(message) {
|
||||||
await this._master.deleteMod(message.data.name, message.data.version);
|
await this._controller.deleteMod(message.data.name, message.data.version);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setLogSubscriptionsRequestHandler(message) {
|
async setLogSubscriptionsRequestHandler(message) {
|
||||||
@@ -668,29 +668,29 @@ class ControlConnection extends BaseConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateLogSubscriptions() {
|
updateLogSubscriptions() {
|
||||||
let { all, master, slave_ids, instance_ids } = this.logSubscriptions;
|
let { all, controller, host_ids, instance_ids } = this.logSubscriptions;
|
||||||
if (all || master || slave_ids.length || instance_ids.length) {
|
if (all || controller || host_ids.length || instance_ids.length) {
|
||||||
if (!this.logTransport) {
|
if (!this.logTransport) {
|
||||||
this.logTransport = new libLoggingUtils.LinkTransport({ link: this });
|
this.logTransport = new libLoggingUtils.LinkTransport({ link: this });
|
||||||
this._master.clusterLogger.add(this.logTransport);
|
this._controller.clusterLogger.add(this.logTransport);
|
||||||
}
|
}
|
||||||
this.logTransport.filter = logFilter(this.logSubscriptions);
|
this.logTransport.filter = logFilter(this.logSubscriptions);
|
||||||
|
|
||||||
} else if (this.logTransport) {
|
} else if (this.logTransport) {
|
||||||
this._master.clusterLogger.remove(this.logTransport);
|
this._controller.clusterLogger.remove(this.logTransport);
|
||||||
this.logTransport = null;
|
this.logTransport = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async queryLogRequestHandler(message) {
|
async queryLogRequestHandler(message) {
|
||||||
let observeDuration = queryLogTime.startTimer();
|
let observeDuration = queryLogTime.startTimer();
|
||||||
let { all, master, slave_ids, instance_ids } = message.data;
|
let { all, controller, host_ids, instance_ids } = message.data;
|
||||||
|
|
||||||
let log;
|
let log;
|
||||||
if (!all && master && !slave_ids.length && !instance_ids.length) {
|
if (!all && controller && !host_ids.length && !instance_ids.length) {
|
||||||
log = await this._master.queryMasterLog(message.data);
|
log = await this._controller.queryControllerLog(message.data);
|
||||||
} else {
|
} else {
|
||||||
log = await this._master.queryClusterLog(message.data);
|
log = await this._controller.queryClusterLog(message.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
observeDuration();
|
observeDuration();
|
||||||
@@ -711,7 +711,7 @@ class ControlConnection extends BaseConnection {
|
|||||||
|
|
||||||
async listRolesRequestHandler(message) {
|
async listRolesRequestHandler(message) {
|
||||||
let list = [];
|
let list = [];
|
||||||
for (let role of this._master.userManager.roles.values()) {
|
for (let role of this._controller.userManager.roles.values()) {
|
||||||
list.push({
|
list.push({
|
||||||
id: role.id,
|
id: role.id,
|
||||||
name: role.name,
|
name: role.name,
|
||||||
@@ -723,17 +723,17 @@ class ControlConnection extends BaseConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createRoleRequestHandler(message) {
|
async createRoleRequestHandler(message) {
|
||||||
let lastId = Math.max.apply(null, [...this._master.userManager.roles.keys()]);
|
let lastId = Math.max.apply(null, [...this._controller.userManager.roles.keys()]);
|
||||||
|
|
||||||
// Start at 5 to leave space for future default roles
|
// Start at 5 to leave space for future default roles
|
||||||
let id = Math.max(5, lastId+1);
|
let id = Math.max(5, lastId+1);
|
||||||
this._master.userManager.roles.set(id, new libUsers.Role({ id, ...message.data }));
|
this._controller.userManager.roles.set(id, new libUsers.Role({ id, ...message.data }));
|
||||||
return { id };
|
return { id };
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateRoleRequestHandler(message) {
|
async updateRoleRequestHandler(message) {
|
||||||
let { id, name, description, permissions } = message.data;
|
let { id, name, description, permissions } = message.data;
|
||||||
let role = this._master.userManager.roles.get(id);
|
let role = this._controller.userManager.roles.get(id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
throw new libErrors.RequestError(`Role with ID ${id} does not exist`);
|
throw new libErrors.RequestError(`Role with ID ${id} does not exist`);
|
||||||
}
|
}
|
||||||
@@ -741,36 +741,36 @@ class ControlConnection extends BaseConnection {
|
|||||||
role.name = name;
|
role.name = name;
|
||||||
role.description = description;
|
role.description = description;
|
||||||
role.permissions = new Set(permissions);
|
role.permissions = new Set(permissions);
|
||||||
this._master.rolePermissionsUpdated(role);
|
this._controller.rolePermissionsUpdated(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
async grantDefaultRolePermissionsRequestHandler(message) {
|
async grantDefaultRolePermissionsRequestHandler(message) {
|
||||||
let role = this._master.userManager.roles.get(message.data.id);
|
let role = this._controller.userManager.roles.get(message.data.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
throw new libErrors.RequestError(`Role with ID ${message.data.id} does not exist`);
|
throw new libErrors.RequestError(`Role with ID ${message.data.id} does not exist`);
|
||||||
}
|
}
|
||||||
|
|
||||||
role.grantDefaultPermissions();
|
role.grantDefaultPermissions();
|
||||||
this._master.rolePermissionsUpdated(role);
|
this._controller.rolePermissionsUpdated(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteRoleRequestHandler(message) {
|
async deleteRoleRequestHandler(message) {
|
||||||
let id = message.data.id;
|
let id = message.data.id;
|
||||||
let role = this._master.userManager.roles.get(id);
|
let role = this._controller.userManager.roles.get(id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
throw new libErrors.RequestError(`Role with ID ${id} does not exist`);
|
throw new libErrors.RequestError(`Role with ID ${id} does not exist`);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._master.userManager.roles.delete(id);
|
this._controller.userManager.roles.delete(id);
|
||||||
for (let user of this._master.userManager.users.values()) {
|
for (let user of this._controller.userManager.users.values()) {
|
||||||
user.roles.delete(role);
|
user.roles.delete(role);
|
||||||
this._master.userPermissionsUpdated(user);
|
this._controller.userPermissionsUpdated(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUserRequestHandler(message) {
|
async getUserRequestHandler(message) {
|
||||||
let name = message.data.name;
|
let name = message.data.name;
|
||||||
let user = this._master.userManager.users.get(name);
|
let user = this._controller.userManager.users.get(name);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new libErrors.RequestError(`User ${name} does not exist`);
|
throw new libErrors.RequestError(`User ${name} does not exist`);
|
||||||
}
|
}
|
||||||
@@ -790,7 +790,7 @@ class ControlConnection extends BaseConnection {
|
|||||||
|
|
||||||
async listUsersRequestHandler(message) {
|
async listUsersRequestHandler(message) {
|
||||||
let list = [];
|
let list = [];
|
||||||
for (let user of this._master.userManager.users.values()) {
|
for (let user of this._controller.userManager.users.values()) {
|
||||||
list.push({
|
list.push({
|
||||||
name: user.name,
|
name: user.name,
|
||||||
roles: [...user.roles].map(role => role.id),
|
roles: [...user.roles].map(role => role.id),
|
||||||
@@ -829,12 +829,12 @@ class ControlConnection extends BaseConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createUserRequestHandler(message) {
|
async createUserRequestHandler(message) {
|
||||||
let user = this._master.userManager.createUser(message.data.name);
|
let user = this._controller.userManager.createUser(message.data.name);
|
||||||
this._master.userUpdated(user);
|
this._controller.userUpdated(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
async revokeUserTokenRequestHandler(message) {
|
async revokeUserTokenRequestHandler(message) {
|
||||||
let user = this._master.userManager.users.get(message.data.name);
|
let user = this._controller.userManager.users.get(message.data.name);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new libErrors.RequestError(`User '${message.data.name}' does not exist`);
|
throw new libErrors.RequestError(`User '${message.data.name}' does not exist`);
|
||||||
}
|
}
|
||||||
@@ -843,23 +843,23 @@ class ControlConnection extends BaseConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
user.invalidateToken();
|
user.invalidateToken();
|
||||||
for (let controlConnection of this._master.wsServer.controlConnections) {
|
for (let controlConnection of this._controller.wsServer.controlConnections) {
|
||||||
if (controlConnection.user.name === user.name) {
|
if (controlConnection.user.name === user.name) {
|
||||||
controlConnection.connector.terminate();
|
controlConnection.connector.terminate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._master.userUpdated(user);
|
this._controller.userUpdated(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateUserRolesRequestHandler(message) {
|
async updateUserRolesRequestHandler(message) {
|
||||||
let user = this._master.userManager.users.get(message.data.name);
|
let user = this._controller.userManager.users.get(message.data.name);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new libErrors.RequestError(`User '${message.data.name}' does not exist`);
|
throw new libErrors.RequestError(`User '${message.data.name}' does not exist`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let resolvedRoles = new Set();
|
let resolvedRoles = new Set();
|
||||||
for (let roleId of message.data.roles) {
|
for (let roleId of message.data.roles) {
|
||||||
let role = this._master.userManager.roles.get(roleId);
|
let role = this._controller.userManager.roles.get(roleId);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
throw new libErrors.RequestError(`Role with ID ${roleId} does not exist`);
|
throw new libErrors.RequestError(`Role with ID ${roleId} does not exist`);
|
||||||
}
|
}
|
||||||
@@ -868,34 +868,34 @@ class ControlConnection extends BaseConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
user.roles = resolvedRoles;
|
user.roles = resolvedRoles;
|
||||||
this._master.userPermissionsUpdated(user);
|
this._controller.userPermissionsUpdated(user);
|
||||||
this._master.userUpdated(user);
|
this._controller.userUpdated(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setUserAdminRequestHandler(message) {
|
async setUserAdminRequestHandler(message) {
|
||||||
let { name, create, admin } = message.data;
|
let { name, create, admin } = message.data;
|
||||||
let user = this._master.userManager.users.get(name);
|
let user = this._controller.userManager.users.get(name);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
if (create) {
|
if (create) {
|
||||||
this.user.checkPermission("core.user.create");
|
this.user.checkPermission("core.user.create");
|
||||||
user = this._master.userManager.createUser(name);
|
user = this._controller.userManager.createUser(name);
|
||||||
} else {
|
} else {
|
||||||
throw new libErrors.RequestError(`User '${name}' does not exist`);
|
throw new libErrors.RequestError(`User '${name}' does not exist`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
user.isAdmin = admin;
|
user.isAdmin = admin;
|
||||||
this._master.userUpdated(user);
|
this._controller.userUpdated(user);
|
||||||
this.broadcastEventToSlaves({ data: { name, admin }}, libLink.messages.adminlistUpdate);
|
this.broadcastEventToHosts({ data: { name, admin }}, libLink.messages.adminlistUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setUserBannedRequestHandler(message) {
|
async setUserBannedRequestHandler(message) {
|
||||||
let { name, create, banned, reason } = message.data;
|
let { name, create, banned, reason } = message.data;
|
||||||
let user = this._master.userManager.users.get(name);
|
let user = this._controller.userManager.users.get(name);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
if (create) {
|
if (create) {
|
||||||
this.user.checkPermission("core.user.create");
|
this.user.checkPermission("core.user.create");
|
||||||
user = this._master.userManager.createUser(name);
|
user = this._controller.userManager.createUser(name);
|
||||||
} else {
|
} else {
|
||||||
throw new libErrors.RequestError(`User '${name}' does not exist`);
|
throw new libErrors.RequestError(`User '${name}' does not exist`);
|
||||||
}
|
}
|
||||||
@@ -903,45 +903,45 @@ class ControlConnection extends BaseConnection {
|
|||||||
|
|
||||||
user.isBanned = banned;
|
user.isBanned = banned;
|
||||||
user.banReason = reason;
|
user.banReason = reason;
|
||||||
this._master.userUpdated(user);
|
this._controller.userUpdated(user);
|
||||||
this.broadcastEventToSlaves({ data: { name, banned, reason }}, libLink.messages.banlistUpdate);
|
this.broadcastEventToHosts({ data: { name, banned, reason }}, libLink.messages.banlistUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setUserWhitelistedRequestHandler(message) {
|
async setUserWhitelistedRequestHandler(message) {
|
||||||
let { name, create, whitelisted } = message.data;
|
let { name, create, whitelisted } = message.data;
|
||||||
let user = this._master.userManager.users.get(name);
|
let user = this._controller.userManager.users.get(name);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
if (create) {
|
if (create) {
|
||||||
this.user.checkPermission("core.user.create");
|
this.user.checkPermission("core.user.create");
|
||||||
user = this._master.userManager.createUser(name);
|
user = this._controller.userManager.createUser(name);
|
||||||
} else {
|
} else {
|
||||||
throw new libErrors.RequestError(`User '${name}' does not exist`);
|
throw new libErrors.RequestError(`User '${name}' does not exist`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
user.isWhitelisted = whitelisted;
|
user.isWhitelisted = whitelisted;
|
||||||
this._master.userUpdated(user);
|
this._controller.userUpdated(user);
|
||||||
this.broadcastEventToSlaves({ data: { name, whitelisted }}, libLink.messages.whitelistUpdate);
|
this.broadcastEventToHosts({ data: { name, whitelisted }}, libLink.messages.whitelistUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteUserRequestHandler(message) {
|
async deleteUserRequestHandler(message) {
|
||||||
let user = this._master.userManager.users.get(message.data.name);
|
let user = this._controller.userManager.users.get(message.data.name);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new libErrors.RequestError(`User '${message.data.name}' does not exist`);
|
throw new libErrors.RequestError(`User '${message.data.name}' does not exist`);
|
||||||
}
|
}
|
||||||
|
|
||||||
user.isDeleted = true;
|
user.isDeleted = true;
|
||||||
this._master.userManager.users.delete(message.data.name);
|
this._controller.userManager.users.delete(message.data.name);
|
||||||
this._master.userUpdated(user);
|
this._controller.userUpdated(user);
|
||||||
|
|
||||||
if (user.is_admin) {
|
if (user.is_admin) {
|
||||||
this.broadcastEventToSlaves({ data: { name, admin: false }}, libLink.messages.adminlistUpdate);
|
this.broadcastEventToHosts({ data: { name, admin: false }}, libLink.messages.adminlistUpdate);
|
||||||
}
|
}
|
||||||
if (user.is_whitelisted) {
|
if (user.is_whitelisted) {
|
||||||
this.broadcastEventToSlaves({ data: { name, whitelisted: false }}, libLink.messages.whitelistUpdate);
|
this.broadcastEventToHosts({ data: { name, whitelisted: false }}, libLink.messages.whitelistUpdate);
|
||||||
}
|
}
|
||||||
if (user.is_banned) {
|
if (user.is_banned) {
|
||||||
this.broadcastEventToSlaves({ data: { name, banned: false, reason: "" }}, libLink.messages.banlistUpdate);
|
this.broadcastEventToHosts({ data: { name, banned: false, reason: "" }}, libLink.messages.banlistUpdate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -952,7 +952,7 @@ class ControlConnection extends BaseConnection {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.connector._socket.clusterio_ignore_dump = true;
|
this.connector._socket.clusterio_ignore_dump = true;
|
||||||
this._master.debugEvents.on("message", this.ws_dumper);
|
this._controller.debugEvents.on("message", this.ws_dumper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,21 +27,21 @@ const WsServer = require("./WsServer");
|
|||||||
|
|
||||||
|
|
||||||
const endpointDurationSummary = new libPrometheus.Summary(
|
const endpointDurationSummary = new libPrometheus.Summary(
|
||||||
"clusterio_master_http_endpoint_duration_seconds",
|
"clusterio_controller_http_endpoint_duration_seconds",
|
||||||
"Time it took to respond to a an HTTP request",
|
"Time it took to respond to a an HTTP request",
|
||||||
{ labels: ["route"] }
|
{ labels: ["route"] }
|
||||||
);
|
);
|
||||||
|
|
||||||
const logSizeGauge = new libPrometheus.Gauge(
|
const logSizeGauge = new libPrometheus.Gauge(
|
||||||
"clusterio_master_log_bytes",
|
"clusterio_controller_log_bytes",
|
||||||
"Size of all log files currently stored on the master."
|
"Size of all log files currently stored on the controller."
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages all master related operations
|
* Manages all controller related operations
|
||||||
* @alias module:master/src/Master
|
* @alias module:controller/src/Controller
|
||||||
*/
|
*/
|
||||||
class Master {
|
class Controller {
|
||||||
constructor(clusterLogger, pluginInfos, configPath, config) {
|
constructor(clusterLogger, pluginInfos, configPath, config) {
|
||||||
this.clusterLogger = clusterLogger;
|
this.clusterLogger = clusterLogger;
|
||||||
/**
|
/**
|
||||||
@@ -51,20 +51,20 @@ class Master {
|
|||||||
this.pluginInfos = pluginInfos;
|
this.pluginInfos = pluginInfos;
|
||||||
this.configPath = configPath;
|
this.configPath = configPath;
|
||||||
/**
|
/**
|
||||||
* Master config.
|
* Controller config.
|
||||||
* @type {module:lib/config.MasterConfig}
|
* @type {module:lib/config.ControllerConfig}
|
||||||
*/
|
*/
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
this.app = express();
|
this.app = express();
|
||||||
this.app.locals.master = this;
|
this.app.locals.controller = this;
|
||||||
this.app.locals.streams = new Map();
|
this.app.locals.streams = new Map();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mapping of slave id to slave info
|
* Mapping of host id to host info
|
||||||
* @type {Map<number, Object>}
|
* @type {Map<number, Object>}
|
||||||
*/
|
*/
|
||||||
this.slaves = null;
|
this.hosts = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mapping of instance id to instance info
|
* Mapping of instance id to instance info
|
||||||
@@ -86,7 +86,7 @@ class Master {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* User and roles manager for the cluster
|
* User and roles manager for the cluster
|
||||||
* @type {module:master/src/UserManager}
|
* @type {module:controller/src/UserManager}
|
||||||
*/
|
*/
|
||||||
this.userManager = null;
|
this.userManager = null;
|
||||||
this.httpServer = null;
|
this.httpServer = null;
|
||||||
@@ -96,13 +96,13 @@ class Master {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Mapping of plugin name to loaded plugin
|
* Mapping of plugin name to loaded plugin
|
||||||
* @type {Map<string, module:lib/plugin.BaseMasterPlugin>}
|
* @type {Map<string, module:lib/plugin.BaseControllerPlugin>}
|
||||||
*/
|
*/
|
||||||
this.plugins = new Map();
|
this.plugins = new Map();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WebSocket server
|
* WebSocket server
|
||||||
* @type {module:master/src/WsServer}
|
* @type {module:controller/src/WsServer}
|
||||||
*/
|
*/
|
||||||
this.wsServer = new WsServer(this);
|
this.wsServer = new WsServer(this);
|
||||||
|
|
||||||
@@ -144,8 +144,8 @@ class Master {
|
|||||||
async logSize() {
|
async logSize() {
|
||||||
return (await Promise.all([
|
return (await Promise.all([
|
||||||
libFileOps.directorySize(path.join(this.logDirectory, "cluster")),
|
libFileOps.directorySize(path.join(this.logDirectory, "cluster")),
|
||||||
libFileOps.directorySize(path.join(this.logDirectory, "master")),
|
libFileOps.directorySize(path.join(this.logDirectory, "controller")),
|
||||||
libFileOps.directorySize(path.join(this.logDirectory, "slave")),
|
libFileOps.directorySize(path.join(this.logDirectory, "host")),
|
||||||
])).reduce((a, v) => a + v, 0);
|
])).reduce((a, v) => a + v, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,38 +189,38 @@ class Master {
|
|||||||
this.app.use(this.devMiddleware);
|
this.app.use(this.devMiddleware);
|
||||||
}
|
}
|
||||||
|
|
||||||
let databaseDirectory = this.config.get("master.database_directory");
|
let databaseDirectory = this.config.get("controller.database_directory");
|
||||||
await fs.ensureDir(databaseDirectory);
|
await fs.ensureDir(databaseDirectory);
|
||||||
|
|
||||||
this.slaves = await Master.loadSlaves(path.join(databaseDirectory, "slaves.json"));
|
this.hosts = await Controller.loadHosts(path.join(databaseDirectory, "hosts.json"));
|
||||||
this.instances = await Master.loadInstances(path.join(databaseDirectory, "instances.json"));
|
this.instances = await Controller.loadInstances(path.join(databaseDirectory, "instances.json"));
|
||||||
this.modPacks = await Master.loadModPacks(path.join(databaseDirectory, "mod-packs.json"));
|
this.modPacks = await Controller.loadModPacks(path.join(databaseDirectory, "mod-packs.json"));
|
||||||
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"));
|
||||||
|
|
||||||
let modsDirectory = this.config.get("master.mods_directory");
|
let modsDirectory = this.config.get("controller.mods_directory");
|
||||||
await fs.ensureDir(modsDirectory);
|
await fs.ensureDir(modsDirectory);
|
||||||
this.mods = await Master.loadModInfos(modsDirectory);
|
this.mods = await Controller.loadModInfos(modsDirectory);
|
||||||
|
|
||||||
this.config.on("fieldChanged", (group, field, prev) => {
|
this.config.on("fieldChanged", (group, field, prev) => {
|
||||||
libPlugin.invokeHook(this.plugins, "onMasterConfigFieldChanged", group, field, prev);
|
libPlugin.invokeHook(this.plugins, "onControllerConfigFieldChanged", group, field, prev);
|
||||||
});
|
});
|
||||||
for (let instance of this.instances.values()) {
|
for (let instance of this.instances.values()) {
|
||||||
this.addInstanceHooks(instance);
|
this.addInstanceHooks(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("controller.http_port");
|
||||||
let httpsPort = this.config.get("master.https_port");
|
let httpsPort = this.config.get("controller.https_port");
|
||||||
let bindAddress = this.config.get("master.bind_address") || "";
|
let bindAddress = this.config.get("controller.bind_address") || "";
|
||||||
if (!httpPort && !httpsPort) {
|
if (!httpPort && !httpsPort) {
|
||||||
logger.fatal("Error: at least one of http_port and https_port must be configured");
|
logger.fatal("Error: at least one of http_port and https_port must be configured");
|
||||||
process.exitCode = 1;
|
process.exitCode = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let tls_cert = this.config.get("master.tls_certificate");
|
let tls_cert = this.config.get("controller.tls_certificate");
|
||||||
let tls_key = this.config.get("master.tls_private_key");
|
let tls_key = this.config.get("controller.tls_private_key");
|
||||||
|
|
||||||
if (httpsPort && (!tls_cert || !tls_key)) {
|
if (httpsPort && (!tls_cert || !tls_key)) {
|
||||||
throw new libErrors.StartupError(
|
throw new libErrors.StartupError(
|
||||||
@@ -228,10 +228,10 @@ class Master {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Master.addAppRoutes(this.app, this.pluginInfos);
|
Controller.addAppRoutes(this.app, this.pluginInfos);
|
||||||
|
|
||||||
if (!args.dev) {
|
if (!args.dev) {
|
||||||
let manifest = await Master.loadJsonObject(path.join(__dirname, "..", "dist", "web", "manifest.json"));
|
let manifest = await Controller.loadJsonObject(path.join(__dirname, "..", "dist", "web", "manifest.json"));
|
||||||
if (!manifest["main.js"]) {
|
if (!manifest["main.js"]) {
|
||||||
logger.error("Missing main.js entry in dist/web/manifest.json");
|
logger.error("Missing main.js entry in dist/web/manifest.json");
|
||||||
}
|
}
|
||||||
@@ -272,12 +272,12 @@ class Master {
|
|||||||
logger.info(`Listening for HTTPS on port ${this.httpsServer.address().port}`);
|
logger.info(`Listening for HTTPS on port ${this.httpsServer.address().port}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Started master");
|
logger.info("Started controller");
|
||||||
this._state = "running";
|
this._state = "running";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops the master server.
|
* Stops the controller.
|
||||||
*
|
*
|
||||||
* Save data and bring down the active connections. This is the reverse
|
* Save data and bring down the active connections. This is the reverse
|
||||||
* of start and is valid at any point in time.
|
* of start and is valid at any point in time.
|
||||||
@@ -299,7 +299,7 @@ class Master {
|
|||||||
async _stopInternal() {
|
async _stopInternal() {
|
||||||
// This function should never throw.
|
// This function should never throw.
|
||||||
this._state = "stopping";
|
this._state = "stopping";
|
||||||
logger.info("Stopping master");
|
logger.info("Stopping controller");
|
||||||
clearInterval(this.clusterLogBuildInterval);
|
clearInterval(this.clusterLogBuildInterval);
|
||||||
if (this.clusterLogIndex) {
|
if (this.clusterLogIndex) {
|
||||||
await this.clusterLogIndex.save();
|
await this.clusterLogIndex.save();
|
||||||
@@ -312,17 +312,17 @@ class Master {
|
|||||||
await new Promise((resolve, reject) => { this.devMiddleware.close(resolve); });
|
await new Promise((resolve, reject) => { this.devMiddleware.close(resolve); });
|
||||||
}
|
}
|
||||||
|
|
||||||
let databaseDirectory = this.config.get("master.database_directory");
|
let databaseDirectory = this.config.get("controller.database_directory");
|
||||||
if (this.slaves) {
|
if (this.hosts) {
|
||||||
await Master.saveSlaves(path.join(databaseDirectory, "slaves.json"), this.slaves);
|
await Controller.saveHosts(path.join(databaseDirectory, "hosts.json"), this.hosts);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.instances) {
|
if (this.instances) {
|
||||||
await Master.saveInstances(path.join(databaseDirectory, "instances.json"), this.instances);
|
await Controller.saveInstances(path.join(databaseDirectory, "instances.json"), this.instances);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.modPacks) {
|
if (this.modPacks) {
|
||||||
await Master.saveModPacks(path.join(databaseDirectory, "mod-packs.json"), this.modPacks);
|
await Controller.saveModPacks(path.join(databaseDirectory, "mod-packs.json"), this.modPacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.userManager) {
|
if (this.userManager) {
|
||||||
@@ -344,7 +344,7 @@ class Master {
|
|||||||
logger.info("Goodbye");
|
logger.info("Goodbye");
|
||||||
}
|
}
|
||||||
|
|
||||||
static async loadSlaves(filePath) {
|
static async loadHosts(filePath) {
|
||||||
let serialized;
|
let serialized;
|
||||||
try {
|
try {
|
||||||
serialized = JSON.parse(await fs.readFile(filePath));
|
serialized = JSON.parse(await fs.readFile(filePath));
|
||||||
@@ -365,8 +365,8 @@ class Master {
|
|||||||
return new Map(serialized);
|
return new Map(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async saveSlaves(filePath, slaves) {
|
static async saveHosts(filePath, hosts) {
|
||||||
await libFileOps.safeOutputFile(filePath, JSON.stringify([...slaves.entries()], null, 4));
|
await libFileOps.safeOutputFile(filePath, JSON.stringify([...hosts.entries()], null, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
static async loadInstances(filePath) {
|
static async loadInstances(filePath) {
|
||||||
@@ -376,9 +376,9 @@ class Master {
|
|||||||
try {
|
try {
|
||||||
let serialized = JSON.parse(await fs.readFile(filePath));
|
let serialized = JSON.parse(await fs.readFile(filePath));
|
||||||
for (let serializedConfig of serialized) {
|
for (let serializedConfig of serialized) {
|
||||||
let instanceConfig = new libConfig.InstanceConfig("master");
|
let instanceConfig = new libConfig.InstanceConfig("controller");
|
||||||
await instanceConfig.load(serializedConfig);
|
await instanceConfig.load(serializedConfig);
|
||||||
let status = instanceConfig.get("instance.assigned_slave") === null ? "unassigned" : "unknown";
|
let status = instanceConfig.get("instance.assigned_host") === null ? "unassigned" : "unknown";
|
||||||
let instance = { config: instanceConfig, status };
|
let instance = { config: instanceConfig, status };
|
||||||
instances.set(instanceConfig.get("instance.id"), instance);
|
instances.set(instanceConfig.get("instance.id"), instance);
|
||||||
}
|
}
|
||||||
@@ -471,7 +471,7 @@ class Master {
|
|||||||
throw new Error(`Mod ${filename} does not exist`);
|
throw new Error(`Mod ${filename} does not exist`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let modsDirectory = this.config.get("master.mods_directory");
|
let modsDirectory = this.config.get("controller.mods_directory");
|
||||||
await fs.unlink(path.join(modsDirectory, filename));
|
await fs.unlink(path.join(modsDirectory, filename));
|
||||||
this.mods.delete(filename);
|
this.mods.delete(filename);
|
||||||
mod.isDeleted = true;
|
mod.isDeleted = true;
|
||||||
@@ -479,16 +479,16 @@ class Master {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query master log
|
* Query controller log
|
||||||
*
|
*
|
||||||
* @param {module:lib/logging_utils~QueryLogFilter} filter -
|
* @param {module:lib/logging_utils~QueryLogFilter} filter -
|
||||||
* Filter to limit entries with. Note that only the master log can
|
* Filter to limit entries with. Note that only the controller log can
|
||||||
* be queried from this function.
|
* be queried from this function.
|
||||||
* @returns {Promise<Array<Object>>} log entries matching the filter
|
* @returns {Promise<Array<Object>>} log entries matching the filter
|
||||||
*/
|
*/
|
||||||
async queryMasterLog(filter) {
|
async queryControllerLog(filter) {
|
||||||
return await libLoggingUtils.queryLog(
|
return await libLoggingUtils.queryLog(
|
||||||
path.join(this.logDirectory, "master"), filter,
|
path.join(this.logDirectory, "controller"), filter,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -530,11 +530,11 @@ class Master {
|
|||||||
|
|
||||||
// Add routes for the web interface
|
// Add routes for the web interface
|
||||||
for (let route of routes.webRoutes) {
|
for (let route of routes.webRoutes) {
|
||||||
app.get(route, Master.serveWeb(route));
|
app.get(route, Controller.serveWeb(route));
|
||||||
}
|
}
|
||||||
for (let pluginInfo of pluginInfos) {
|
for (let pluginInfo of pluginInfos) {
|
||||||
for (let route of pluginInfo.routes || []) {
|
for (let route of pluginInfo.routes || []) {
|
||||||
app.get(route, Master.serveWeb(route));
|
app.get(route, Controller.serveWeb(route));
|
||||||
}
|
}
|
||||||
|
|
||||||
let pluginPackagePath = require.resolve(path.posix.join(pluginInfo.requirePath, "package.json"));
|
let pluginPackagePath = require.resolve(path.posix.join(pluginInfo.requirePath, "package.json"));
|
||||||
@@ -543,14 +543,14 @@ class Master {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
slaveUpdated(slave) {
|
hostUpdated(host) {
|
||||||
let update = {
|
let update = {
|
||||||
agent: slave.agent,
|
agent: host.agent,
|
||||||
version: slave.version,
|
version: host.version,
|
||||||
id: slave.id,
|
id: host.id,
|
||||||
name: slave.name,
|
name: host.name,
|
||||||
public_address: slave.public_address || null,
|
public_address: host.public_address || null,
|
||||||
connected: this.wsServer.slaveConnections.has(slave.id),
|
connected: this.wsServer.hostConnections.has(host.id),
|
||||||
};
|
};
|
||||||
|
|
||||||
for (let controlConnection of this.wsServer.controlConnections) {
|
for (let controlConnection of this.wsServer.controlConnections) {
|
||||||
@@ -558,7 +558,7 @@ class Master {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
controlConnection.slaveUpdated(slave, update);
|
controlConnection.hostUpdated(host, update);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -684,7 +684,7 @@ class Master {
|
|||||||
for (let pluginInfo of this.pluginInfos) {
|
for (let pluginInfo of this.pluginInfos) {
|
||||||
try {
|
try {
|
||||||
let manifestPath = path.posix.join(pluginInfo.requirePath, "dist", "web", "manifest.json");
|
let manifestPath = path.posix.join(pluginInfo.requirePath, "dist", "web", "manifest.json");
|
||||||
pluginInfo.manifest = await Master.loadJsonObject(require.resolve(manifestPath), true);
|
pluginInfo.manifest = await Controller.loadJsonObject(require.resolve(manifestPath), true);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.warn(`Unable to load dist/web/manifest.json for plugin ${pluginInfo.name}`);
|
logger.warn(`Unable to load dist/web/manifest.json for plugin ${pluginInfo.name}`);
|
||||||
}
|
}
|
||||||
@@ -693,15 +693,15 @@ class Master {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let MasterPluginClass = libPlugin.BaseMasterPlugin;
|
let ControllerPluginClass = libPlugin.BaseControllerPlugin;
|
||||||
try {
|
try {
|
||||||
if (pluginInfo.masterEntrypoint) {
|
if (pluginInfo.controllerEntrypoint) {
|
||||||
MasterPluginClass = await libPluginLoader.loadMasterPluginClass(pluginInfo);
|
ControllerPluginClass = await libPluginLoader.loadControllerPluginClass(pluginInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
let masterPlugin = new MasterPluginClass(pluginInfo, this, metrics, logger);
|
let controllerPlugin = new ControllerPluginClass(pluginInfo, this, metrics, logger);
|
||||||
await masterPlugin.init();
|
await controllerPlugin.init();
|
||||||
this.plugins.set(pluginInfo.name, masterPlugin);
|
this.plugins.set(pluginInfo.name, controllerPlugin);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new libErrors.PluginError(pluginInfo.name, err);
|
throw new libErrors.PluginError(pluginInfo.name, err);
|
||||||
@@ -743,21 +743,21 @@ class Master {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the URL needed to connect to the master server.
|
* Returns the URL needed to connect to the controller.
|
||||||
*
|
*
|
||||||
* @returns {string} master URL.
|
* @returns {string} controller URL.
|
||||||
*/
|
*/
|
||||||
getMasterUrl() {
|
getControllerUrl() {
|
||||||
return Master.calculateMasterUrl(this.config);
|
return Controller.calculateControllerUrl(this.config);
|
||||||
}
|
}
|
||||||
|
|
||||||
static calculateMasterUrl(config) {
|
static calculateControllerUrl(config) {
|
||||||
let url = config.get("master.external_address");
|
let url = config.get("controller.external_address");
|
||||||
if (!url) {
|
if (!url) {
|
||||||
if (config.get("master.https_port")) {
|
if (config.get("controller.https_port")) {
|
||||||
url = `https://localhost:${config.get("master.https_port")}/`;
|
url = `https://localhost:${config.get("controller.https_port")}/`;
|
||||||
} else {
|
} else {
|
||||||
url = `http://localhost:${config.get("master.http_port")}/`;
|
url = `http://localhost:${config.get("controller.http_port")}/`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return url;
|
return url;
|
||||||
@@ -789,7 +789,7 @@ class Master {
|
|||||||
fs.readFile(path.join(__dirname, "..", "web", "index.html"), "utf8").then((content) => {
|
fs.readFile(path.join(__dirname, "..", "web", "index.html"), "utf8").then((content) => {
|
||||||
res.type("text/html");
|
res.type("text/html");
|
||||||
res.send(content
|
res.send(content
|
||||||
.replace(/__CLUSTER_NAME__/g, res.app.locals.master.config.get("master.name"))
|
.replace(/__CLUSTER_NAME__/g, res.app.locals.controller.config.get("controller.name"))
|
||||||
.replace(/__WEB_ROOT__/g, webRoot)
|
.replace(/__WEB_ROOT__/g, webRoot)
|
||||||
.replace(/__STATIC_ROOT__/g, staticRoot)
|
.replace(/__STATIC_ROOT__/g, staticRoot)
|
||||||
.replace(/__MAIN_BUNDLE__/g, mainBundle)
|
.replace(/__MAIN_BUNDLE__/g, mainBundle)
|
||||||
@@ -801,9 +801,9 @@ class Master {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forward the given request to the slave contaning the instance
|
* Forward the given request to the host contaning the instance
|
||||||
*
|
*
|
||||||
* Finds the slave which the instance with the given instance ID is
|
* Finds the host which the instance with the given instance ID is
|
||||||
* currently assigned to and forwards the request to that instance.
|
* currently assigned to and forwards the request to that instance.
|
||||||
* The request data must have an instance_id parameter.
|
* The request data must have an instance_id parameter.
|
||||||
*
|
*
|
||||||
@@ -815,21 +815,21 @@ class Master {
|
|||||||
*/
|
*/
|
||||||
async forwardRequestToInstance(request, data) {
|
async forwardRequestToInstance(request, data) {
|
||||||
let instance = this.getRequestInstance(data.instance_id);
|
let instance = this.getRequestInstance(data.instance_id);
|
||||||
let slaveId = instance.config.get("instance.assigned_slave");
|
let hostId = instance.config.get("instance.assigned_host");
|
||||||
if (slaveId === null) {
|
if (hostId === null) {
|
||||||
throw new libErrors.RequestError("Instance is not assigned to a slave");
|
throw new libErrors.RequestError("Instance is not assigned to a host");
|
||||||
}
|
}
|
||||||
|
|
||||||
let connection = this.wsServer.slaveConnections.get(slaveId);
|
let connection = this.wsServer.hostConnections.get(hostId);
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
throw new libErrors.RequestError("Slave containing instance is not connected");
|
throw new libErrors.RequestError("Host containing instance is not connected");
|
||||||
}
|
}
|
||||||
if (request.plugin && !connection.plugins.has(request.plugin)) {
|
if (request.plugin && !connection.plugins.has(request.plugin)) {
|
||||||
throw new libErrors.RequestError(`Slave containing instance does not have ${request.plugin} plugin`);
|
throw new libErrors.RequestError(`Host containing instance does not have ${request.plugin} plugin`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await request.send(connection, data);
|
return await request.send(connection, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Master;
|
module.exports = Controller;
|
||||||
+61
-59
@@ -9,14 +9,14 @@ const BaseConnection = require("./BaseConnection");
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the connection to a slave
|
* Represents the connection to a host
|
||||||
*
|
*
|
||||||
* @extends module:master/src/BaseConnection
|
* @extends module:controller/src/BaseConnection
|
||||||
* @alias module:master/src/SlaveConnection
|
* @alias module:controller/src/HostConnection
|
||||||
*/
|
*/
|
||||||
class SlaveConnection extends BaseConnection {
|
class HostConnection extends BaseConnection {
|
||||||
constructor(registerData, connector, master) {
|
constructor(registerData, connector, controller) {
|
||||||
super("slave", connector, master);
|
super("host", connector, controller);
|
||||||
|
|
||||||
this._agent = registerData.agent;
|
this._agent = registerData.agent;
|
||||||
this._id = registerData.id;
|
this._id = registerData.id;
|
||||||
@@ -25,7 +25,7 @@ class SlaveConnection extends BaseConnection {
|
|||||||
this.plugins = new Map(Object.entries(registerData.plugins));
|
this.plugins = new Map(Object.entries(registerData.plugins));
|
||||||
this._checkPluginVersions();
|
this._checkPluginVersions();
|
||||||
|
|
||||||
this._master.slaves.set(this._id, {
|
this._controller.hosts.set(this._id, {
|
||||||
agent: this._agent,
|
agent: this._agent,
|
||||||
id: this._id,
|
id: this._id,
|
||||||
name: this._name,
|
name: this._name,
|
||||||
@@ -37,75 +37,75 @@ class SlaveConnection extends BaseConnection {
|
|||||||
for (let event of ["connect", "drop", "resume", "close"]) {
|
for (let event of ["connect", "drop", "resume", "close"]) {
|
||||||
// eslint-disable-next-line no-loop-func
|
// eslint-disable-next-line no-loop-func
|
||||||
this.connector.on(event, () => {
|
this.connector.on(event, () => {
|
||||||
for (let plugin of this._master.plugins.values()) {
|
for (let plugin of this._controller.plugins.values()) {
|
||||||
plugin.onSlaveConnectionEvent(this, event);
|
plugin.onHostConnectionEvent(this, event);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.connector.on("close", () => {
|
this.connector.on("close", () => {
|
||||||
// Update status to unknown for instances on this slave.
|
// Update status to unknown for instances on this host.
|
||||||
for (let instance of this._master.instances.values()) {
|
for (let instance of this._controller.instances.values()) {
|
||||||
if (instance.config.get("instance.assigned_slave") !== this._id) {
|
if (instance.config.get("instance.assigned_host") !== this._id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let prev = instance.status;
|
let prev = instance.status;
|
||||||
instance.status = "unknown";
|
instance.status = "unknown";
|
||||||
this._master.instanceUpdated(instance);
|
this._controller.instanceUpdated(instance);
|
||||||
libPlugin.invokeHook(this._master.plugins, "onInstanceStatusChanged", instance, prev);
|
libPlugin.invokeHook(this._controller.plugins, "onInstanceStatusChanged", instance, prev);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_checkPluginVersions() {
|
_checkPluginVersions() {
|
||||||
let pluginInfos = new Map(this._master.pluginInfos.map(i => [i.name, i]));
|
let pluginInfos = new Map(this._controller.pluginInfos.map(i => [i.name, i]));
|
||||||
for (let [name, version] of this.plugins) {
|
for (let [name, version] of this.plugins) {
|
||||||
let info = pluginInfos.get(name);
|
let info = pluginInfos.get(name);
|
||||||
if (!info) {
|
if (!info) {
|
||||||
logger.warn(`Slave ${this._name} has plugin ${name} ${version} which the master does not have`);
|
logger.warn(`Host ${this._name} has plugin ${name} ${version} which the controller does not have`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.version !== version) {
|
if (info.version !== version) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
`Slave ${this._name} has plugin ${name} ${version} which does not match the version of this ` +
|
`Host ${this._name} has plugin ${name} ${version} which does not match the version of this ` +
|
||||||
`plugin on the master (${info.version})`
|
`plugin on the controller (${info.version})`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let [name, info] of pluginInfos) {
|
for (let [name, info] of pluginInfos) {
|
||||||
if (!this.plugins.has(name)) {
|
if (!this.plugins.has(name)) {
|
||||||
logger.warn(`Slave ${this._name} is missing plugin ${name} ${info.version}`);
|
logger.warn(`Host ${this._name} is missing plugin ${name} ${info.version}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ID of the slave this connection is connected to
|
* ID of the host this connection is connected to
|
||||||
*
|
*
|
||||||
* @returns {number} slave ID.
|
* @returns {number} host ID.
|
||||||
*/
|
*/
|
||||||
get id() {
|
get id() {
|
||||||
return this._id;
|
return this._id;
|
||||||
}
|
}
|
||||||
|
|
||||||
async instanceStatusChangedEventHandler(message, event) {
|
async instanceStatusChangedEventHandler(message, event) {
|
||||||
let instance = this._master.instances.get(message.data.instance_id);
|
let instance = this._controller.instances.get(message.data.instance_id);
|
||||||
|
|
||||||
// It's possible to get updates from an instance that does not exist
|
// It's possible to get updates from an instance that does not exist
|
||||||
// or is not assigned to the slave it originated from if it was
|
// or is not assigned to the host it originated from if it was
|
||||||
// reassigned or deleted while the connection to the slave it was
|
// reassigned or deleted while the connection to the host it was
|
||||||
// originally on was down at the time.
|
// originally on was down at the time.
|
||||||
if (!instance || instance.config.get("instance.assigned_slave") !== this._id) {
|
if (!instance || instance.config.get("instance.assigned_host") !== this._id) {
|
||||||
logger.warn(`Got bogus update for instance id ${message.data.instance_id}`);
|
logger.warn(`Got bogus update for instance id ${message.data.instance_id}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We may receive status changed where the status hasn't changed
|
// We may receive status changed where the status hasn't changed
|
||||||
// from our perspective if the connection was down at the time it
|
// from our perspective if the connection was down at the time it
|
||||||
// changed. Slaves also send status updates on assignInstance which
|
// changed. Hosts also send status updates on assignInstance which
|
||||||
// for hacky reason is also used to push config changes and
|
// for hacky reason is also used to push config changes and
|
||||||
// restablish status after a connection loss.
|
// restablish status after a connection loss.
|
||||||
if (instance.status === message.data.status) {
|
if (instance.status === message.data.status) {
|
||||||
@@ -116,56 +116,58 @@ class SlaveConnection extends BaseConnection {
|
|||||||
instance.status = message.data.status;
|
instance.status = message.data.status;
|
||||||
instance.game_port = message.data.game_port;
|
instance.game_port = message.data.game_port;
|
||||||
logger.verbose(`Instance ${instance.config.get("instance.name")} State: ${instance.status}`);
|
logger.verbose(`Instance ${instance.config.get("instance.name")} State: ${instance.status}`);
|
||||||
this._master.instanceUpdated(instance);
|
this._controller.instanceUpdated(instance);
|
||||||
await libPlugin.invokeHook(this._master.plugins, "onInstanceStatusChanged", instance, prev);
|
await libPlugin.invokeHook(this._controller.plugins, "onInstanceStatusChanged", instance, prev);
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateInstancesRequestHandler(message) {
|
async updateInstancesRequestHandler(message) {
|
||||||
// Push updated instance configs
|
// Push updated instance configs
|
||||||
for (let instance of this._master.instances.values()) {
|
for (let instance of this._controller.instances.values()) {
|
||||||
if (instance.config.get("instance.assigned_slave") === this._id) {
|
if (instance.config.get("instance.assigned_host") === this._id) {
|
||||||
await libLink.messages.assignInstance.send(this, {
|
await libLink.messages.assignInstance.send(this, {
|
||||||
instance_id: instance.config.get("instance.id"),
|
instance_id: instance.config.get("instance.id"),
|
||||||
serialized_config: instance.config.serialize("slave"),
|
serialized_config: instance.config.serialize("host"),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign instances the slave has but master does not
|
// Assign instances the host has but controller does not
|
||||||
for (let instanceData of message.data.instances) {
|
for (let instanceData of message.data.instances) {
|
||||||
let instanceConfig = new libConfig.InstanceConfig("master");
|
let instanceConfig = new libConfig.InstanceConfig("controller");
|
||||||
await instanceConfig.load(instanceData.serialized_config, "slave");
|
await instanceConfig.load(instanceData.serialized_config, "host");
|
||||||
|
|
||||||
let masterInstance = this._master.instances.get(instanceConfig.get("instance.id"));
|
let controllerInstance = this._controller.instances.get(instanceConfig.get("instance.id"));
|
||||||
if (masterInstance) {
|
if (controllerInstance) {
|
||||||
// Check if this instance is assigned somewhere else.
|
// Check if this instance is assigned somewhere else.
|
||||||
if (masterInstance.config.get("instance.assigned_slave") !== this._id) {
|
if (controllerInstance.config.get("instance.assigned_host") !== this._id) {
|
||||||
await libLink.messages.unassignInstance.send(this, {
|
await libLink.messages.unassignInstance.send(this, {
|
||||||
instance_id: masterInstance.config.get("instance.id"),
|
instance_id: controllerInstance.config.get("instance.id"),
|
||||||
});
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Already have this instance, update state instead
|
// Already have this instance, update state instead
|
||||||
if (masterInstance.status !== instanceData.status) {
|
if (controllerInstance.status !== instanceData.status) {
|
||||||
let prev = masterInstance.status;
|
let prev = controllerInstance.status;
|
||||||
masterInstance.status = instanceData.status;
|
controllerInstance.status = instanceData.status;
|
||||||
logger.verbose(`Instance ${instanceConfig.get("instance.name")} State: ${instanceData.status}`);
|
logger.verbose(`Instance ${instanceConfig.get("instance.name")} State: ${instanceData.status}`);
|
||||||
this._master.instanceUpdated(instance);
|
this._controller.instanceUpdated(instance);
|
||||||
await libPlugin.invokeHook(this._master.plugins, "onInstanceStatusChanged", masterInstance, prev);
|
await libPlugin.invokeHook(
|
||||||
|
this._controller.plugins, "onInstanceStatusChanged", controllerInstance, prev
|
||||||
|
);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
instanceConfig.set("instance.assigned_slave", this._id);
|
instanceConfig.set("instance.assigned_host", 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._controller.instances.set(instanceConfig.get("instance.id"), newInstance);
|
||||||
this._master.addInstanceHooks(newInstance);
|
this._controller.addInstanceHooks(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("host"),
|
||||||
});
|
});
|
||||||
await libPlugin.invokeHook(this._master.plugins, "onInstanceStatusChanged", newInstance, null);
|
await libPlugin.invokeHook(this._controller.plugins, "onInstanceStatusChanged", newInstance, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push lists to make sure they are in sync.
|
// Push lists to make sure they are in sync.
|
||||||
@@ -173,7 +175,7 @@ class SlaveConnection extends BaseConnection {
|
|||||||
let banlist = [];
|
let banlist = [];
|
||||||
let whitelist = [];
|
let whitelist = [];
|
||||||
|
|
||||||
for (let user of this._master.userManager.users.values()) {
|
for (let user of this._controller.userManager.users.values()) {
|
||||||
if (user.isAdmin) {
|
if (user.isAdmin) {
|
||||||
adminlist.push(user.name);
|
adminlist.push(user.name);
|
||||||
}
|
}
|
||||||
@@ -189,22 +191,22 @@ class SlaveConnection extends BaseConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async saveListUpdateEventHandler(message) {
|
async saveListUpdateEventHandler(message) {
|
||||||
this._master.saveListUpdate(message.data);
|
this._controller.saveListUpdate(message.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
async logMessageEventHandler(message) {
|
async logMessageEventHandler(message) {
|
||||||
this._master.clusterLogger.log({
|
this._controller.clusterLogger.log({
|
||||||
...message.data.info,
|
...message.data.info,
|
||||||
slave_id: this._id,
|
host_id: this._id,
|
||||||
slave_name: this._name,
|
host_name: this._name,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async playerEventEventHandler(message) {
|
async playerEventEventHandler(message) {
|
||||||
let { instance_id, name, type, stats } = message.data;
|
let { instance_id, name, type, stats } = message.data;
|
||||||
let user = this._master.userManager.users.get(name);
|
let user = this._controller.userManager.users.get(name);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
user = this._master.userManager.createUser(name);
|
user = this._controller.userManager.createUser(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === "join") {
|
if (type === "join") {
|
||||||
@@ -214,12 +216,12 @@ class SlaveConnection extends BaseConnection {
|
|||||||
}
|
}
|
||||||
user.instanceStats.set(instance_id, new PlayerStats(stats));
|
user.instanceStats.set(instance_id, new PlayerStats(stats));
|
||||||
user.recalculatePlayerStats();
|
user.recalculatePlayerStats();
|
||||||
this._master.userUpdated(user);
|
this._controller.userUpdated(user);
|
||||||
|
|
||||||
delete message.data.stats;
|
delete message.data.stats;
|
||||||
let instance = this._master.instances.get(instance_id);
|
let instance = this._controller.instances.get(instance_id);
|
||||||
await libPlugin.invokeHook(this._master.plugins, "onPlayerEvent", instance, message.data);
|
await libPlugin.invokeHook(this._controller.plugins, "onPlayerEvent", instance, message.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = SlaveConnection;
|
module.exports = HostConnection;
|
||||||
@@ -17,7 +17,7 @@ const https = require("https");
|
|||||||
* // in the shutdown logic
|
* // in the shutdown logic
|
||||||
* await serverCloser.close();
|
* await serverCloser.close();
|
||||||
*
|
*
|
||||||
* @alias module:master/src/HttpCloser
|
* @alias module:controller/src/HttpCloser
|
||||||
*/
|
*/
|
||||||
class HttpCloser {
|
class HttpCloser {
|
||||||
/**
|
/**
|
||||||
@@ -6,7 +6,7 @@ const libUsers = require("@clusterio/lib/users");
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages users and roles
|
* Manages users and roles
|
||||||
* @alias module:master/src/UserManager
|
* @alias module:controller/src/UserManager
|
||||||
*/
|
*/
|
||||||
class UserManager {
|
class UserManager {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
@@ -79,7 +79,7 @@ class UserManager {
|
|||||||
throw new Error(`User '${name}' already exists`);
|
throw new Error(`User '${name}' already exists`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let defaultRoleId = this._config.get("master.default_role_id");
|
let defaultRoleId = this._config.get("controller.default_role_id");
|
||||||
let user = new libUsers.User({ name, roles: [defaultRoleId] }, this.roles);
|
let user = new libUsers.User({ name, roles: [defaultRoleId] }, this.roles);
|
||||||
this.users.set(name, user);
|
this.users.set(name, user);
|
||||||
return user;
|
return user;
|
||||||
@@ -9,41 +9,41 @@ const libSchema = require("@clusterio/lib/schema");
|
|||||||
|
|
||||||
const ControlConnection = require("./ControlConnection");
|
const ControlConnection = require("./ControlConnection");
|
||||||
const packageVersion = require("../package").version;
|
const packageVersion = require("../package").version;
|
||||||
const SlaveConnection = require("./SlaveConnection");
|
const HostConnection = require("./HostConnection");
|
||||||
const WsServerConnector = require("./WsServerConnector");
|
const WsServerConnector = require("./WsServerConnector");
|
||||||
|
|
||||||
|
|
||||||
const wsMessageCounter = new libPrometheus.Counter(
|
const wsMessageCounter = new libPrometheus.Counter(
|
||||||
"clusterio_master_websocket_message_total",
|
"clusterio_controller_websocket_message_total",
|
||||||
"How many messages have been received over WebSocket on the master server",
|
"How many messages have been received over WebSocket on the controller",
|
||||||
{ labels: ["direction"] }
|
{ labels: ["direction"] }
|
||||||
);
|
);
|
||||||
|
|
||||||
const wsConnectionsCounter = new libPrometheus.Counter(
|
const wsConnectionsCounter = new libPrometheus.Counter(
|
||||||
"clusterio_master_websocket_connections_total",
|
"clusterio_controller_websocket_connections_total",
|
||||||
"How many WebSocket connections have been initiated on the master server"
|
"How many WebSocket connections have been initiated on the controller"
|
||||||
);
|
);
|
||||||
|
|
||||||
const wsRejectedConnectionsCounter = new libPrometheus.Counter(
|
const wsRejectedConnectionsCounter = new libPrometheus.Counter(
|
||||||
"clusterio_master_websocket_rejected_connections_total",
|
"clusterio_controller_websocket_rejected_connections_total",
|
||||||
"How many WebSocket connections have been rejected during the handshake on the master server"
|
"How many WebSocket connections have been rejected during the handshake on the controller"
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WebSocket server
|
* WebSocket server
|
||||||
* @alias module:master/src/WsServer
|
* @alias module:controller/src/WsServer
|
||||||
*/
|
*/
|
||||||
class WsServer {
|
class WsServer {
|
||||||
constructor(master) {
|
constructor(controller) {
|
||||||
this.master = master;
|
this.controller = controller;
|
||||||
|
|
||||||
this.stopAcceptingNewSessions = false;
|
this.stopAcceptingNewSessions = false;
|
||||||
|
|
||||||
/** @type {Array<module:master/src/ControlConnection>} */
|
/** @type {Array<module:controller/src/ControlConnection>} */
|
||||||
this.controlConnections = [];
|
this.controlConnections = [];
|
||||||
/** @type {Map<number, module:master/src/SlaveConnection>} */
|
/** @type {Map<number, module:controller/src/HostConnection>} */
|
||||||
this.slaveConnections = new Map();
|
this.hostConnections = new Map();
|
||||||
/** @type {Map<number, module:master/src/WsServerConnector>} */
|
/** @type {Map<number, module:controller/src/WsServerConnector>} */
|
||||||
this.activeConnectors = new Map();
|
this.activeConnectors = new Map();
|
||||||
/** @type {Set<module:ws>} */
|
/** @type {Set<module:ws>} */
|
||||||
this.pendingSockets = new Set();
|
this.pendingSockets = new Set();
|
||||||
@@ -68,8 +68,8 @@ class WsServer {
|
|||||||
disconnectTasks.push(controlConnection.disconnect(1001, "Server Quit"));
|
disconnectTasks.push(controlConnection.disconnect(1001, "Server Quit"));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let slaveConnection of this.slaveConnections.values()) {
|
for (let hostConnection of this.hostConnections.values()) {
|
||||||
disconnectTasks.push(slaveConnection.disconnect(1001, "Server Quit"));
|
disconnectTasks.push(hostConnection.disconnect(1001, "Server Quit"));
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(`WsServer | Waiting for ${disconnectTasks.length} connectors to close`);
|
logger.info(`WsServer | Waiting for ${disconnectTasks.length} connectors to close`);
|
||||||
@@ -104,21 +104,21 @@ class WsServer {
|
|||||||
socket.on("message", (message) => {
|
socket.on("message", (message) => {
|
||||||
wsMessageCounter.labels("in").inc();
|
wsMessageCounter.labels("in").inc();
|
||||||
if (!socket.clusterio_ignore_dump) {
|
if (!socket.clusterio_ignore_dump) {
|
||||||
this.master.debugEvents.emit("message", { direction: "in", content: message });
|
this.controller.debugEvents.emit("message", { direction: "in", content: message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let originalSend = socket.send;
|
let originalSend = socket.send;
|
||||||
socket.send = (...args) => {
|
socket.send = (...args) => {
|
||||||
wsMessageCounter.labels("out").inc();
|
wsMessageCounter.labels("out").inc();
|
||||||
if (typeof args[0] === "string" && !socket.clusterio_ignore_dump) {
|
if (typeof args[0] === "string" && !socket.clusterio_ignore_dump) {
|
||||||
this.master.debugEvents.emit("message", { direction: "out", content: args[0] });
|
this.controller.debugEvents.emit("message", { direction: "out", content: args[0] });
|
||||||
}
|
}
|
||||||
return originalSend.call(socket, ...args);
|
return originalSend.call(socket, ...args);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Start connection handshake.
|
// Start connection handshake.
|
||||||
let loadedPlugins = {};
|
let loadedPlugins = {};
|
||||||
for (let [name, plugin] of this.master.plugins) {
|
for (let [name, plugin] of this.controller.plugins) {
|
||||||
loadedPlugins[name] = plugin.info.version;
|
loadedPlugins[name] = plugin.info.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +183,7 @@ ${err.stack}`
|
|||||||
try {
|
try {
|
||||||
let payload = jwt.verify(
|
let payload = jwt.verify(
|
||||||
data.session_token,
|
data.session_token,
|
||||||
Buffer.from(this.master.config.get("master.auth_secret"), "base64"),
|
Buffer.from(this.controller.config.get("controller.auth_secret"), "base64"),
|
||||||
{ audience: this.sessionAud }
|
{ audience: this.sessionAud }
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -212,25 +212,27 @@ ${err.stack}`
|
|||||||
// Validate token
|
// Validate token
|
||||||
let user;
|
let user;
|
||||||
try {
|
try {
|
||||||
if (type === "register_slave") {
|
if (type === "register_host") {
|
||||||
let tokenPayload = jwt.verify(
|
let tokenPayload = jwt.verify(
|
||||||
data.token,
|
data.token,
|
||||||
Buffer.from(this.master.config.get("master.auth_secret"), "base64"),
|
Buffer.from(this.controller.config.get("controller.auth_secret"), "base64"),
|
||||||
{ audience: "slave" }
|
// migrate: allow pre-rename tokens issued to hosts before alpha-14
|
||||||
|
{ audience: ["host", "slave"] }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (tokenPayload.slave !== data.id) {
|
// migrate: allow pre-rename tokens issued to hosts before alpha-14
|
||||||
throw new Error("missmatched slave id");
|
if ((tokenPayload.host !== undefined ? tokenPayload.host : tokenPayload.slave) !== data.id) {
|
||||||
|
throw new Error("missmatched host id");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (type === "register_control") {
|
} else if (type === "register_control") {
|
||||||
let tokenPayload = jwt.verify(
|
let tokenPayload = jwt.verify(
|
||||||
data.token,
|
data.token,
|
||||||
Buffer.from(this.master.config.get("master.auth_secret"), "base64"),
|
Buffer.from(this.controller.config.get("controller.auth_secret"), "base64"),
|
||||||
{ audience: "user" }
|
{ audience: "user" }
|
||||||
);
|
);
|
||||||
|
|
||||||
user = this.master.userManager.users.get(tokenPayload.user);
|
user = this.controller.userManager.users.get(tokenPayload.user);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new Error("invalid user");
|
throw new Error("invalid user");
|
||||||
}
|
}
|
||||||
@@ -251,10 +253,10 @@ ${err.stack}`
|
|||||||
this.nextSessionId += 1;
|
this.nextSessionId += 1;
|
||||||
let sessionToken = jwt.sign(
|
let sessionToken = jwt.sign(
|
||||||
{ aud: this.sessionAud, sid: sessionId },
|
{ aud: this.sessionAud, sid: sessionId },
|
||||||
Buffer.from(this.master.config.get("master.auth_secret"), "base64"),
|
Buffer.from(this.controller.config.get("controller.auth_secret"), "base64"),
|
||||||
);
|
);
|
||||||
let sessionTimeout = this.master.config.get("master.session_timeout");
|
let sessionTimeout = this.controller.config.get("controller.session_timeout");
|
||||||
let heartbeatInterval = this.master.config.get("master.heartbeat_interval");
|
let heartbeatInterval = this.controller.config.get("controller.heartbeat_interval");
|
||||||
let connector = new WsServerConnector(sessionId, sessionTimeout, heartbeatInterval);
|
let connector = new WsServerConnector(sessionId, sessionTimeout, heartbeatInterval);
|
||||||
this.activeConnectors.set(sessionId, connector);
|
this.activeConnectors.set(sessionId, connector);
|
||||||
connector.on("close", () => {
|
connector.on("close", () => {
|
||||||
@@ -262,39 +264,39 @@ ${err.stack}`
|
|||||||
});
|
});
|
||||||
|
|
||||||
let additionalReadyData = {};
|
let additionalReadyData = {};
|
||||||
if (type === "register_slave") {
|
if (type === "register_host") {
|
||||||
let connection = this.slaveConnections.get(data.id);
|
let connection = this.hostConnections.get(data.id);
|
||||||
if (connection) {
|
if (connection) {
|
||||||
logger.verbose(`WsServer | disconnecting existing connection for slave ${data.id}`);
|
logger.verbose(`WsServer | disconnecting existing connection for host ${data.id}`);
|
||||||
await connection.disconnect(1008, "Registered from another connection");
|
await connection.disconnect(1008, "Registered from another connection");
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
`WsServer | registered slave ${data.name} (${data.id}) using agent ${data.agent} ${data.version}`
|
`WsServer | registered host ${data.name} (${data.id}) using agent ${data.agent} ${data.version}`
|
||||||
);
|
);
|
||||||
if (data.agent === "Clusterio Slave" && data.version !== packageVersion) {
|
if (data.agent === "Clusterio Host" && data.version !== packageVersion) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
`Slave ${data.name} (${data.id}) connected using version ${data.version} which does not match ` +
|
`Host ${data.name} (${data.id}) connected using version ${data.version} which does not match the ` +
|
||||||
`the version of the master is currently running (${packageVersion}). It may not work as expected.`
|
`version of the controller is currently running (${packageVersion}). It may not work as expected.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
connection = new SlaveConnection(data, connector, this.master);
|
connection = new HostConnection(data, connector, this.controller);
|
||||||
connector.on("close", () => {
|
connector.on("close", () => {
|
||||||
if (this.slaveConnections.get(data.id) === connection) {
|
if (this.hostConnections.get(data.id) === connection) {
|
||||||
this.slaveConnections.delete(data.id);
|
this.hostConnections.delete(data.id);
|
||||||
this.master.slaveUpdated(this.master.slaves.get(data.id));
|
this.controller.hostUpdated(this.controller.hosts.get(data.id));
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Unlisted SlaveConnection closed");
|
logger.warn("Unlisted HostConnection closed");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.slaveConnections.set(data.id, connection);
|
this.hostConnections.set(data.id, connection);
|
||||||
this.master.slaveUpdated(this.master.slaves.get(data.id));
|
this.controller.hostUpdated(this.controller.hosts.get(data.id));
|
||||||
|
|
||||||
|
|
||||||
} else if (type === "register_control") {
|
} else if (type === "register_control") {
|
||||||
logger.verbose(`WsServer | registered control from ${req.socket.remoteAddress}`);
|
logger.verbose(`WsServer | registered control from ${req.socket.remoteAddress}`);
|
||||||
let connection = new ControlConnection(data, connector, this.master, user);
|
let connection = new ControlConnection(data, connector, this.controller, user);
|
||||||
connector.on("close", () => {
|
connector.on("close", () => {
|
||||||
let index = this.controlConnections.indexOf(connection);
|
let index = this.controlConnections.indexOf(connection);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
+2
-2
@@ -6,10 +6,10 @@ const { logger } = require("@clusterio/lib/logging");
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connector for master server connections
|
* Connector for controller connections
|
||||||
*
|
*
|
||||||
* @extends module:lib/link.WebSocketBaseConnector
|
* @extends module:lib/link.WebSocketBaseConnector
|
||||||
* @alias module:master/src/WsServerConnector
|
* @alias module:controller/src/WsServerConnector
|
||||||
*/
|
*/
|
||||||
class WsServerConnector extends libLink.WebSocketBaseConnector {
|
class WsServerConnector extends libLink.WebSocketBaseConnector {
|
||||||
constructor(sessionId, sessionTimeout, heartbeatInterval) {
|
constructor(sessionId, sessionTimeout, heartbeatInterval) {
|
||||||
@@ -4,7 +4,7 @@ const libPrometheus = require("@clusterio/lib/prometheus");
|
|||||||
const util = require("util");
|
const util = require("util");
|
||||||
|
|
||||||
exports.endpointHitCounter = new libPrometheus.Counter(
|
exports.endpointHitCounter = new libPrometheus.Counter(
|
||||||
"clusterio_master_http_endpoint_hits_total",
|
"clusterio_controller_http_endpoint_hits_total",
|
||||||
"How many requests a particular HTTP endpoint has gotten",
|
"How many requests a particular HTTP endpoint has gotten",
|
||||||
{ labels: ["route"], register: false }
|
{ labels: ["route"], register: false }
|
||||||
);
|
);
|
||||||
@@ -40,7 +40,7 @@ function mergeSamples(destinationResult, sourceResult) {
|
|||||||
// Prometheus polling endpoint
|
// Prometheus polling endpoint
|
||||||
async function getMetrics(req, res, next) {
|
async function getMetrics(req, res, next) {
|
||||||
let results = [];
|
let results = [];
|
||||||
let pluginResults = await libPlugin.invokeHook(req.app.locals.master.plugins, "onMetrics");
|
let pluginResults = await libPlugin.invokeHook(req.app.locals.controller.plugins, "onMetrics");
|
||||||
for (let metricIterator of pluginResults) {
|
for (let metricIterator of pluginResults) {
|
||||||
for await (let metric of metricIterator) {
|
for await (let metric of metricIterator) {
|
||||||
results.push(metric);
|
results.push(metric);
|
||||||
@@ -48,15 +48,15 @@ async function getMetrics(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let requests = [];
|
let requests = [];
|
||||||
let timeout = req.app.locals.master.config.get("master.metrics_timeout") * 1000;
|
let timeout = req.app.locals.controller.config.get("controller.metrics_timeout") * 1000;
|
||||||
for (let slaveConnection of req.app.locals.master.wsServer.slaveConnections.values()) {
|
for (let hostConnection of req.app.locals.controller.wsServer.hostConnections.values()) {
|
||||||
if (!slaveConnection.connected) {
|
if (!hostConnection.connected) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
requests.push(libHelpers.timeout(
|
requests.push(libHelpers.timeout(
|
||||||
libLink.messages.getMetrics.send(slaveConnection).catch(err => {
|
libLink.messages.getMetrics.send(hostConnection).catch(err => {
|
||||||
if (!(err instanceof libErrors.SessionLost)) {
|
if (!(err instanceof libErrors.SessionLost)) {
|
||||||
logger.error(`Unexpected error gathering metrics from slave:\n${err.stack}`);
|
logger.error(`Unexpected error gathering metrics from host:\n${err.stack}`);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}),
|
}),
|
||||||
@@ -80,7 +80,7 @@ async function getMetrics(req, res, next) {
|
|||||||
resultMap.set(result.metric.name, result);
|
resultMap.set(result.metric.name, result);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Merge metrics received by multiple slaves
|
// Merge metrics received by multiple hosts
|
||||||
mergeSamples(resultMap.get(result.metric.name), result);
|
mergeSamples(resultMap.get(result.metric.name), result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,10 +98,10 @@ async function getMetrics(req, res, next) {
|
|||||||
|
|
||||||
function getPlugins(req, res) {
|
function getPlugins(req, res) {
|
||||||
let plugins = [];
|
let plugins = [];
|
||||||
for (let pluginInfo of req.app.locals.master.pluginInfos) {
|
for (let pluginInfo of req.app.locals.controller.pluginInfos) {
|
||||||
let name = pluginInfo.name;
|
let name = pluginInfo.name;
|
||||||
let loaded = req.app.locals.master.plugins.has(name);
|
let loaded = req.app.locals.controller.plugins.has(name);
|
||||||
let enabled = loaded && req.app.locals.master.config.group(pluginInfo.name).get("load_plugin");
|
let enabled = loaded && req.app.locals.controller.config.group(pluginInfo.name).get("load_plugin");
|
||||||
let web = {};
|
let web = {};
|
||||||
let devPlugins = req.app.locals.devPlugins;
|
let devPlugins = req.app.locals.devPlugins;
|
||||||
if (devPlugins && devPlugins.has(name)) {
|
if (devPlugins && devPlugins.has(name)) {
|
||||||
@@ -123,7 +123,7 @@ function getPlugins(req, res) {
|
|||||||
res.send(plugins);
|
res.send(plugins);
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateSlaveToken(req, res, next) {
|
function validateHostToken(req, res, next) {
|
||||||
let token = req.header("x-access-token");
|
let token = req.header("x-access-token");
|
||||||
if (!token) {
|
if (!token) {
|
||||||
res.sendStatus(401);
|
res.sendStatus(401);
|
||||||
@@ -133,8 +133,8 @@ function validateSlaveToken(req, res, next) {
|
|||||||
try {
|
try {
|
||||||
jwt.verify(
|
jwt.verify(
|
||||||
token,
|
token,
|
||||||
Buffer.from(req.app.locals.master.config.get("master.auth_secret"), "base64"),
|
Buffer.from(req.app.locals.controller.config.get("controller.auth_secret"), "base64"),
|
||||||
{ audience: "slave" }
|
{ audience: "host" }
|
||||||
);
|
);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -155,10 +155,10 @@ function validateUserToken(req, res, next) {
|
|||||||
try {
|
try {
|
||||||
let tokenPayload = jwt.verify(
|
let tokenPayload = jwt.verify(
|
||||||
token,
|
token,
|
||||||
Buffer.from(req.app.locals.master.config.get("master.auth_secret"), "base64"),
|
Buffer.from(req.app.locals.controller.config.get("controller.auth_secret"), "base64"),
|
||||||
{ audience: "user" }
|
{ audience: "user" }
|
||||||
);
|
);
|
||||||
let user = req.app.locals.master.userManager.users.get(tokenPayload.user);
|
let user = req.app.locals.controller.userManager.users.get(tokenPayload.user);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new Error("invalid user");
|
throw new Error("invalid user");
|
||||||
}
|
}
|
||||||
@@ -191,7 +191,7 @@ async function uploadExport(req, res) {
|
|||||||
res.sendStatus(400);
|
res.sendStatus(400);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let modPack = res.app.locals.master.modPacks.get(modPackId);
|
let modPack = res.app.locals.controller.modPacks.get(modPackId);
|
||||||
if (!modPack) {
|
if (!modPack) {
|
||||||
res.sendStatus(400);
|
res.sendStatus(400);
|
||||||
return;
|
return;
|
||||||
@@ -234,7 +234,7 @@ async function uploadExport(req, res) {
|
|||||||
|
|
||||||
modPack.exportManifest = new libData.ExportManifest({ assets });
|
modPack.exportManifest = new libData.ExportManifest({ assets });
|
||||||
modPack.fillDefaultSettings(settingPrototypes, logger);
|
modPack.fillDefaultSettings(settingPrototypes, logger);
|
||||||
res.app.locals.master.modPackUpdated(modPack);
|
res.app.locals.controller.modPackUpdated(modPack);
|
||||||
|
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
}
|
}
|
||||||
@@ -251,7 +251,7 @@ async function createProxyStream(app) {
|
|||||||
events: new events.EventEmitter(),
|
events: new events.EventEmitter(),
|
||||||
timeout: setTimeout(() => {
|
timeout: setTimeout(() => {
|
||||||
stream.events.emit("timeout");
|
stream.events.emit("timeout");
|
||||||
}, app.locals.master.config.get("master.proxy_stream_timeout") * 1000),
|
}, app.locals.controller.config.get("controller.proxy_stream_timeout") * 1000),
|
||||||
};
|
};
|
||||||
stream.events.on("close", () => {
|
stream.events.on("close", () => {
|
||||||
clearTimeout(stream.timeout);
|
clearTimeout(stream.timeout);
|
||||||
@@ -356,13 +356,13 @@ async function uploadSave(req, res) {
|
|||||||
let timeout = new Promise((_, reject) => {
|
let timeout = new Promise((_, reject) => {
|
||||||
proxyStream.events.on("timeout", () => {
|
proxyStream.events.on("timeout", () => {
|
||||||
stream.resume();
|
stream.resume();
|
||||||
reject(new Error("Timed out establishing stream to slave"));
|
reject(new Error("Timed out establishing stream to host"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let result = await Promise.race([
|
let result = await Promise.race([
|
||||||
req.app.locals.master.forwardRequestToInstance(libLink.messages.pullSave, {
|
req.app.locals.controller.forwardRequestToInstance(libLink.messages.pullSave, {
|
||||||
instance_id: instanceId,
|
instance_id: instanceId,
|
||||||
stream_id: proxyStream.id,
|
stream_id: proxyStream.id,
|
||||||
filename,
|
filename,
|
||||||
@@ -498,7 +498,7 @@ async function uploadMod(req, res) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const modsDirectory = req.app.locals.master.config.get("master.mods_directory");
|
const modsDirectory = req.app.locals.controller.config.get("controller.mods_directory");
|
||||||
let tempFilename = filename.replace(/(\.zip)?$/, ".tmp.zip");
|
let tempFilename = filename.replace(/(\.zip)?$/, ".tmp.zip");
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@@ -521,8 +521,8 @@ async function uploadMod(req, res) {
|
|||||||
|
|
||||||
const modInfo = await libData.ModInfo.fromModFile(path.join(modsDirectory, tempFilename));
|
const modInfo = await libData.ModInfo.fromModFile(path.join(modsDirectory, tempFilename));
|
||||||
await fs.rename(path.join(modsDirectory, tempFilename), path.join(modsDirectory, modInfo.filename));
|
await fs.rename(path.join(modsDirectory, tempFilename), path.join(modsDirectory, modInfo.filename));
|
||||||
req.app.locals.master.mods.set(modInfo.filename, modInfo);
|
req.app.locals.controller.mods.set(modInfo.filename, modInfo);
|
||||||
req.app.locals.master.modUpdated(modInfo);
|
req.app.locals.controller.modUpdated(modInfo);
|
||||||
mods.push(modInfo.toJSON());
|
mods.push(modInfo.toJSON());
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -609,7 +609,7 @@ function addRouteHandlers(app) {
|
|||||||
app.get("/metrics", (req, res, next) => getMetrics(req, res, next).catch(next));
|
app.get("/metrics", (req, res, next) => getMetrics(req, res, next).catch(next));
|
||||||
app.get("/api/plugins", getPlugins);
|
app.get("/api/plugins", getPlugins);
|
||||||
app.put("/api/upload-export",
|
app.put("/api/upload-export",
|
||||||
validateSlaveToken,
|
validateHostToken,
|
||||||
(req, res, next) => uploadExport(req, res).catch(next)
|
(req, res, next) => uploadExport(req, res).catch(next)
|
||||||
);
|
);
|
||||||
app.put("/api/stream/:id", (req, res, next) => putStream(req, res).catch(next));
|
app.put("/api/stream/:id", (req, res, next) => putStream(req, res).catch(next));
|
||||||
@@ -624,12 +624,12 @@ function addRouteHandlers(app) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Routes used in the web interface and served by the master server
|
// Routes used in the web interface and served by the controller
|
||||||
const webRoutes = [
|
const webRoutes = [
|
||||||
"/",
|
"/",
|
||||||
"/master",
|
"/controller",
|
||||||
"/slaves",
|
"/hosts",
|
||||||
"/slaves/:id/view",
|
"/hosts/:id/view",
|
||||||
"/instances",
|
"/instances",
|
||||||
"/instances/:id/view",
|
"/instances/:id/view",
|
||||||
"/mods",
|
"/mods",
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
@@ -16,7 +16,7 @@ module.exports = (env = {}) => merge(common(env), {
|
|||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.container.ModuleFederationPlugin({
|
new webpack.container.ModuleFederationPlugin({
|
||||||
name: "master",
|
name: "controller",
|
||||||
shared: {
|
shared: {
|
||||||
"@clusterio/lib": { singleton: true },
|
"@clusterio/lib": { singleton: true },
|
||||||
"@clusterio/web_ui": { singleton: true },
|
"@clusterio/web_ui": { singleton: true },
|
||||||
+210
-81
@@ -110,18 +110,18 @@ async function execFile(cmd, args) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function execMaster(args) {
|
async function execController(args) {
|
||||||
if (dev) {
|
if (dev) {
|
||||||
return await execFile("node", [path.join("packages", "master"), ...args]);
|
return await execFile("node", [path.join("packages", "controller"), ...args]);
|
||||||
}
|
}
|
||||||
return await execFile(path.join("node_modules", ".bin", `clusteriomaster${scriptExt}`), args);
|
return await execFile(path.join("node_modules", ".bin", `clusteriocontroller${scriptExt}`), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function execSlave(args) {
|
async function execHost(args) {
|
||||||
if (dev) {
|
if (dev) {
|
||||||
return await execFile("node", [path.join("packages", "slave"), ...args]);
|
return await execFile("node", [path.join("packages", "host"), ...args]);
|
||||||
}
|
}
|
||||||
return await execFile(path.join("node_modules", ".bin", `clusterioslave${scriptExt}`), args);
|
return await execFile(path.join("node_modules", ".bin", `clusteriohost${scriptExt}`), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function execCtl(args) {
|
async function execCtl(args) {
|
||||||
@@ -131,7 +131,7 @@ async function execCtl(args) {
|
|||||||
return await execFile(path.join("node_modules", ".bin", `clusterioctl${scriptExt}`), args);
|
return await execFile(path.join("node_modules", ".bin", `clusterioctl${scriptExt}`), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateSlaveToken(token) {
|
function validateHostToken(token) {
|
||||||
let parts = token.split(".");
|
let parts = token.split(".");
|
||||||
if (parts.length !== 3) {
|
if (parts.length !== 3) {
|
||||||
throw new InstallError("Invalid token");
|
throw new InstallError("Invalid token");
|
||||||
@@ -144,7 +144,7 @@ function validateSlaveToken(token) {
|
|||||||
throw new InstallError("Invalid token");
|
throw new InstallError("Invalid token");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parsed.aud !== "slave" || !Number.isInteger(parsed.slave)) {
|
if (parsed.aud !== "host" || !Number.isInteger(parsed.host)) {
|
||||||
throw new InstallError("Invalid token");
|
throw new InstallError("Invalid token");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,6 +181,127 @@ async function validateNotRoot(args) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function migrateRename(args) {
|
||||||
|
function rename(string) {
|
||||||
|
return string.replace(/master/g, "controller").replace(/slave/g, "host");
|
||||||
|
}
|
||||||
|
|
||||||
|
function renameConfig(config) {
|
||||||
|
for (let group of config["groups"]) {
|
||||||
|
group["name"] = rename(group["name"]);
|
||||||
|
group["fields"] = Object.fromEntries(
|
||||||
|
Object.entries(group["fields"]).map(([k, v]) => [rename(k), v])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function migrateConfig(source, destination) {
|
||||||
|
if (await fs.pathExists(source) && !await fs.pathExists(destination)) {
|
||||||
|
await safeOutputFile(destination, JSON.stringify(
|
||||||
|
renameConfig(JSON.parse(await fs.readFile(source))), null, 4
|
||||||
|
));
|
||||||
|
logger.info(`Migrated ${source} to ${destination}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await migrateConfig("config-master.json", "config-controller.json");
|
||||||
|
await migrateConfig("config-slave.json", "config-host.json");
|
||||||
|
|
||||||
|
let instancesFile = path.join("database", "instances.json");
|
||||||
|
if (await fs.pathExists(instancesFile)) {
|
||||||
|
await safeOutputFile(instancesFile, JSON.stringify(
|
||||||
|
JSON.parse(await fs.readFile(instancesFile)).map(renameConfig), null, 4
|
||||||
|
));
|
||||||
|
logger.info(`Migrated ${instancesFile}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
let usersFile = path.join("database", "users.json");
|
||||||
|
if (await fs.pathExists(usersFile)) {
|
||||||
|
let users = JSON.parse(await fs.readFile(usersFile));
|
||||||
|
for (let role of users["roles"]) {
|
||||||
|
role["permissions"] = role["permissions"].map(rename);
|
||||||
|
}
|
||||||
|
await safeOutputFile(usersFile, JSON.stringify(users, null, 4));
|
||||||
|
logger.info(`Migrated ${usersFile}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function renameLogLine(info) {
|
||||||
|
return Object.fromEntries(
|
||||||
|
Object.entries(info).map(([k, v]) => [rename(k), v])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function migrateLog(inputFile, outputFile) {
|
||||||
|
let lineStream = new LineSplitter({ readableObjectMode: true });
|
||||||
|
let fileStream = fs.createReadStream(inputFile);
|
||||||
|
fileStream.pipe(lineStream);
|
||||||
|
let lines = [];
|
||||||
|
|
||||||
|
for await (let inputLine of lineStream) {
|
||||||
|
try {
|
||||||
|
lines.push(Buffer.from(JSON.stringify(renameLogLine(JSON.parse(inputLine)))));
|
||||||
|
lines.push(Buffer.from("\n"));
|
||||||
|
} catch (err) {
|
||||||
|
if (!(err instanceof SyntaxError)) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
logger.warn(`Invalid log line: ${inputLine.toString()}`);
|
||||||
|
lines.push(inputLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
safeOutputFile(outputFile, Buffer.concat(lines));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function migrateLogsDir(inputLogs, outputLogs) {
|
||||||
|
if (await fs.pathExists(inputLogs)) {
|
||||||
|
logger.info(`Migrating ${inputLogs} to ${outputLogs}`);
|
||||||
|
for (let logFile of await fs.readdir(inputLogs)) {
|
||||||
|
if (!logFile.endsWith(".log")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let inputFile = path.join(inputLogs, logFile);
|
||||||
|
let outputFile = path.join(outputLogs, rename(logFile));
|
||||||
|
if (!await fs.pathExists(outputFile)) {
|
||||||
|
await migrateLog(inputFile, outputFile);
|
||||||
|
logger.verbose(`Migrated ${inputFile} to ${outputFile}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await migrateLogsDir(path.join("logs", "master"), path.join("logs", "controller"));
|
||||||
|
await migrateLogsDir(path.join("logs", "slave"), path.join("logs", "host"));
|
||||||
|
if (
|
||||||
|
await fs.pathExists(path.join("logs", "cluster"))
|
||||||
|
&& !await fs.pathExists(path.join("logs", "cluster-prerename"))
|
||||||
|
) {
|
||||||
|
await fs.rename(path.join("logs", "cluster"), path.join("logs", "cluster-prerename"));
|
||||||
|
await migrateLogsDir(path.join("logs", "cluster-prerename"), path.join("logs", "cluster"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!args.dev) {
|
||||||
|
let pkg = JSON.parse(await fs.readFile("package.json"));
|
||||||
|
if (pkg.dependencies) {
|
||||||
|
let convert = ["@clusterio/master", "@clusterio/slave"];
|
||||||
|
let uninstall = convert.filter(c => pkg.dependencies[c] !== undefined);
|
||||||
|
let install = uninstall.map(rename);
|
||||||
|
if (uninstall.length) {
|
||||||
|
logger.info(`Replacing ${uninstall.join(" and ")}`);
|
||||||
|
await execFile(`npm${scriptExt}`, ["install", ...install]);
|
||||||
|
await execFile(`npm${scriptExt}`, ["uninstall", ...uninstall]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logger.info("Updating packages");
|
||||||
|
await execFile(`npm${scriptExt}`, ["update"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
"Migration complete, you may now delete the following left over files and directories (if present):" +
|
||||||
|
"\n- config-master.json\n- config-slave.json\n- logs/master\n- logs/slave\n- logs/cluster-prerename"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async function installClusterio(mode, plugins) {
|
async function installClusterio(mode, plugins) {
|
||||||
try {
|
try {
|
||||||
await fs.outputFile("package.json", JSON.stringify({
|
await fs.outputFile("package.json", JSON.stringify({
|
||||||
@@ -194,11 +315,11 @@ async function installClusterio(mode, plugins) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let components = [];
|
let components = [];
|
||||||
if (["standalone", "master"].includes(mode)) {
|
if (["standalone", "controller"].includes(mode)) {
|
||||||
components.push("@clusterio/master");
|
components.push("@clusterio/controller");
|
||||||
}
|
}
|
||||||
if (["standalone", "slave"].includes(mode)) {
|
if (["standalone", "host"].includes(mode)) {
|
||||||
components.push("@clusterio/slave");
|
components.push("@clusterio/host");
|
||||||
}
|
}
|
||||||
if (mode === "ctl") {
|
if (mode === "ctl") {
|
||||||
components.push("@clusterio/ctl");
|
components.push("@clusterio/ctl");
|
||||||
@@ -250,22 +371,22 @@ async function groupIdToName(gid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function writeScripts(mode) {
|
async function writeScripts(mode) {
|
||||||
if (["standalone", "master"].includes(mode)) {
|
if (["standalone", "controller"].includes(mode)) {
|
||||||
if (process.platform === "win32") {
|
if (process.platform === "win32") {
|
||||||
await safeOutputFile(
|
await safeOutputFile(
|
||||||
"run-master.cmd",
|
"run-controller.cmd",
|
||||||
"@echo off\n.\\node_modules\\.bin\\clusteriomaster.cmd run\n"
|
"@echo off\n.\\node_modules\\.bin\\clusteriocontroller.cmd run\n"
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
await safeOutputFile(
|
await safeOutputFile(
|
||||||
"run-master.sh",
|
"run-controller.sh",
|
||||||
"#!/bin/sh\nexec ./node_modules/.bin/clusteriomaster run\n",
|
"#!/bin/sh\nexec ./node_modules/.bin/clusteriocontroller run\n",
|
||||||
{ mode: 0o755 },
|
{ mode: 0o755 },
|
||||||
);
|
);
|
||||||
await safeOutputFile(
|
await safeOutputFile(
|
||||||
"systemd/clusteriomaster.service",
|
"systemd/clusteriocontroller.service",
|
||||||
`[Unit]
|
`[Unit]
|
||||||
Description=Clusterio Master
|
Description=Clusterio Controller
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User=${os.userInfo().username}
|
User=${os.userInfo().username}
|
||||||
@@ -273,7 +394,7 @@ Group=${await groupIdToName(os.userInfo().gid)}
|
|||||||
WorkingDirectory=${process.cwd()}
|
WorkingDirectory=${process.cwd()}
|
||||||
KillMode=mixed
|
KillMode=mixed
|
||||||
KillSignal=SIGINT
|
KillSignal=SIGINT
|
||||||
ExecStart=${process.cwd()}/node_modules/.bin/clusteriomaster run --log-level=warn
|
ExecStart=${process.cwd()}/node_modules/.bin/clusteriocontroller run --log-level=warn
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
@@ -281,22 +402,22 @@ WantedBy=multi-user.target
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (["standalone", "slave"].includes(mode)) {
|
if (["standalone", "host"].includes(mode)) {
|
||||||
if (process.platform === "win32") {
|
if (process.platform === "win32") {
|
||||||
await safeOutputFile(
|
await safeOutputFile(
|
||||||
"run-slave.cmd",
|
"run-host.cmd",
|
||||||
"@echo off\n.\\node_modules\\.bin\\clusterioslave.cmd run\n"
|
"@echo off\n.\\node_modules\\.bin\\clusteriohost.cmd run\n"
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
await safeOutputFile(
|
await safeOutputFile(
|
||||||
"run-slave.sh",
|
"run-host.sh",
|
||||||
"#!/bin/sh\nexec ./node_modules/.bin/clusterioslave run\n",
|
"#!/bin/sh\nexec ./node_modules/.bin/clusteriohost run\n",
|
||||||
{ mode: 0o755 },
|
{ mode: 0o755 },
|
||||||
);
|
);
|
||||||
await safeOutputFile(
|
await safeOutputFile(
|
||||||
"systemd/clusterioslave.service",
|
"systemd/clusteriohost.service",
|
||||||
`[Unit]
|
`[Unit]
|
||||||
Description=Clusterio Slave
|
Description=Clusterio Host
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User=${os.userInfo().username}
|
User=${os.userInfo().username}
|
||||||
@@ -304,7 +425,7 @@ Group=${await groupIdToName(os.userInfo().gid)}
|
|||||||
WorkingDirectory=${process.cwd()}
|
WorkingDirectory=${process.cwd()}
|
||||||
KillMode=mixed
|
KillMode=mixed
|
||||||
KillSignal=SIGINT
|
KillSignal=SIGINT
|
||||||
ExecStart=${process.cwd()}/node_modules/.bin/clusterioslave run --log-level=warn
|
ExecStart=${process.cwd()}/node_modules/.bin/clusteriohost run --log-level=warn
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
@@ -324,16 +445,16 @@ async function inquirerMissingArgs(args) {
|
|||||||
message: "Operating mode to install",
|
message: "Operating mode to install",
|
||||||
default: "standalone",
|
default: "standalone",
|
||||||
choices: [
|
choices: [
|
||||||
{ name: "Standalone (install both master and slave on this computer)", value: "standalone" },
|
{ name: "Standalone (install both controller and host on this computer)", value: "standalone" },
|
||||||
{ name: "Master only", value: "master" },
|
{ name: "Controller only", value: "controller" },
|
||||||
{ name: "Slave only", value: "slave" },
|
{ name: "Host only", value: "host" },
|
||||||
{ name: "Ctl only", value: "ctl" },
|
{ name: "Ctl only", value: "ctl" },
|
||||||
{ name: "Plugins only", value: "plugins" },
|
{ name: "Plugins only", value: "plugins" },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
], answers);
|
], answers);
|
||||||
|
|
||||||
if (["standalone", "master"].includes(answers.mode)) {
|
if (["standalone", "controller"].includes(answers.mode)) {
|
||||||
if (args.admin) { answers.admin = args.admin; }
|
if (args.admin) { answers.admin = args.admin; }
|
||||||
answers = await inquirer.prompt([
|
answers = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
@@ -350,42 +471,42 @@ async function inquirerMissingArgs(args) {
|
|||||||
], answers);
|
], answers);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (answers.mode === "slave") {
|
if (answers.mode === "host") {
|
||||||
if (args.slaveName) { answers.slaveName = args.slaveName; }
|
if (args.hostName) { answers.hostName = args.hostName; }
|
||||||
answers = await inquirer.prompt([
|
answers = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
type: "input",
|
type: "input",
|
||||||
name: "slaveName",
|
name: "hostName",
|
||||||
message: "Name of slave",
|
message: "Name of host",
|
||||||
},
|
},
|
||||||
], answers);
|
], answers);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (["slave", "ctl"].includes(answers.mode)) {
|
if (["host", "ctl"].includes(answers.mode)) {
|
||||||
if (args.masterUrl) { answers.masterUrl = args.masterUrl; }
|
if (args.controllerUrl) { answers.controllerUrl = args.controllerUrl; }
|
||||||
answers = await inquirer.prompt([
|
answers = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
type: "input",
|
type: "input",
|
||||||
name: "masterUrl",
|
name: "controllerUrl",
|
||||||
message: "Master server URL",
|
message: "Controller URL",
|
||||||
},
|
},
|
||||||
], answers);
|
], answers);
|
||||||
|
|
||||||
if (args.masterToken) { answers.masterToken = args.masterToken; }
|
if (args.controllerToken) { answers.controllerToken = args.controllerToken; }
|
||||||
answers = await inquirer.prompt([
|
answers = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
type: "input",
|
type: "input",
|
||||||
name: "masterToken",
|
name: "controllerToken",
|
||||||
message: "Master authentication Token",
|
message: "Controller authentication Token",
|
||||||
},
|
},
|
||||||
], answers);
|
], answers);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (answers.mode === "slave") {
|
if (answers.mode === "host") {
|
||||||
validateSlaveToken(answers.masterToken);
|
validateHostToken(answers.controllerToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (["standalone", "slave"].includes(answers.mode)) {
|
if (["standalone", "host"].includes(answers.mode)) {
|
||||||
let myIp = "localhost";
|
let myIp = "localhost";
|
||||||
if (args.publicAddress) {
|
if (args.publicAddress) {
|
||||||
answers.publicAddress = args.publicAddress;
|
answers.publicAddress = args.publicAddress;
|
||||||
@@ -532,25 +653,28 @@ async function main() {
|
|||||||
})
|
})
|
||||||
.option("mode", {
|
.option("mode", {
|
||||||
nargs: 1, describe: "Operating mode to install",
|
nargs: 1, describe: "Operating mode to install",
|
||||||
choices: ["standalone", "master", "slave", "ctl", "plugins"],
|
choices: ["standalone", "controller", "host", "ctl", "plugins"],
|
||||||
|
})
|
||||||
|
.option("migrate-rename", {
|
||||||
|
nargs: 0, describe: "Migrate from before slave/master rename", default: false, type: "boolean",
|
||||||
})
|
})
|
||||||
.option("admin", {
|
.option("admin", {
|
||||||
nargs: 1, describe: "Admin account name [standalone/master]", type: "string",
|
nargs: 1, describe: "Admin account name [standalone/controller]", type: "string",
|
||||||
})
|
})
|
||||||
.option("slave-name", {
|
.option("host-name", {
|
||||||
nargs: 1, describe: "Slave name [slave]", type: "string",
|
nargs: 1, describe: "Host name [host]", type: "string",
|
||||||
})
|
})
|
||||||
.option("master-url", {
|
.option("controller-url", {
|
||||||
nargs: 1, describe: "Master URL [slave/ctl]", type: "string",
|
nargs: 1, describe: "Controller URL [host/ctl]", type: "string",
|
||||||
})
|
})
|
||||||
.option("master-token", {
|
.option("controller-token", {
|
||||||
nargs: 1, describe: "Master authentication token [slave/ctl]", type: "string",
|
nargs: 1, describe: "Controller authentication token [host/ctl]", type: "string",
|
||||||
})
|
})
|
||||||
.option("public-address", {
|
.option("public-address", {
|
||||||
nargs: 1, describe: "DNS/IP Address to connect to this server [standalone/slave]", type: "string",
|
nargs: 1, describe: "DNS/IP Address to connect to this server [standalone/host]", type: "string",
|
||||||
})
|
})
|
||||||
.option("factorio-dir", {
|
.option("factorio-dir", {
|
||||||
nargs: 1, describe: "Path to Factorio installation [standalone/slave]", type: "string",
|
nargs: 1, describe: "Path to Factorio installation [standalone/host]", type: "string",
|
||||||
})
|
})
|
||||||
.option("plugins", {
|
.option("plugins", {
|
||||||
array: true, describe: "Plugins to install", type: "string",
|
array: true, describe: "Plugins to install", type: "string",
|
||||||
@@ -582,6 +706,11 @@ async function main() {
|
|||||||
await validateNotRoot(args);
|
await validateNotRoot(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args.migrateRename) {
|
||||||
|
await migrateRename(args);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let answers = await inquirerMissingArgs(args);
|
let answers = await inquirerMissingArgs(args);
|
||||||
if (answers.downloadHeadless) {
|
if (answers.downloadHeadless) {
|
||||||
await downloadLinuxServer();
|
await downloadLinuxServer();
|
||||||
@@ -594,47 +723,47 @@ async function main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let adminToken = null;
|
let adminToken = null;
|
||||||
if (["standalone", "master"].includes(answers.mode)) {
|
if (["standalone", "controller"].includes(answers.mode)) {
|
||||||
logger.info("Setting up master");
|
logger.info("Setting up controller");
|
||||||
await execMaster(["bootstrap", "create-admin", answers.admin]);
|
await execController(["bootstrap", "create-admin", answers.admin]);
|
||||||
let result = await execMaster(["bootstrap", "generate-user-token", answers.admin]);
|
let result = await execController(["bootstrap", "generate-user-token", answers.admin]);
|
||||||
adminToken = result.stdout.split("\n").slice(-2)[0];
|
adminToken = result.stdout.split("\n").slice(-2)[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (answers.mode === "standalone") {
|
if (answers.mode === "standalone") {
|
||||||
logger.info("Setting up slave");
|
logger.info("Setting up host");
|
||||||
await execSlave(["config", "set", "slave.name", "local"]);
|
await execHost(["config", "set", "host.name", "local"]);
|
||||||
|
|
||||||
let result = await execSlave(["config", "show", "slave.id"]);
|
let result = await execHost(["config", "show", "host.id"]);
|
||||||
let slaveId = Number.parseInt(result.stdout.split("\n").slice(-2)[0], 10);
|
let hostId = Number.parseInt(result.stdout.split("\n").slice(-2)[0], 10);
|
||||||
|
|
||||||
result = await execMaster(["bootstrap", "generate-slave-token", slaveId]);
|
result = await execController(["bootstrap", "generate-host-token", hostId]);
|
||||||
let slaveToken = result.stdout.split("\n").slice(-2)[0];
|
let hostToken = result.stdout.split("\n").slice(-2)[0];
|
||||||
|
|
||||||
await execSlave(["config", "set", "slave.master_token", slaveToken]);
|
await execHost(["config", "set", "host.controller_token", hostToken]);
|
||||||
await execSlave(["config", "set", "slave.public_address", answers.publicAddress]);
|
await execHost(["config", "set", "host.public_address", answers.publicAddress]);
|
||||||
await execSlave(["config", "set", "slave.factorio_directory", answers.factorioDir]);
|
await execHost(["config", "set", "host.factorio_directory", answers.factorioDir]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (answers.mode === "slave") {
|
if (answers.mode === "host") {
|
||||||
logger.info("Setting up slave");
|
logger.info("Setting up host");
|
||||||
let slaveId = JSON.parse(Buffer.from(answers.masterToken.split(".")[1], "base64")).slave;
|
let hostId = JSON.parse(Buffer.from(answers.controllerToken.split(".")[1], "base64")).host;
|
||||||
await execSlave(["config", "set", "slave.id", slaveId]);
|
await execHost(["config", "set", "host.id", hostId]);
|
||||||
await execSlave(["config", "set", "slave.name", answers.slaveName]);
|
await execHost(["config", "set", "host.name", answers.hostName]);
|
||||||
await execSlave(["config", "set", "slave.master_url", answers.masterUrl]);
|
await execHost(["config", "set", "host.controller_url", answers.controllerUrl]);
|
||||||
await execSlave(["config", "set", "slave.master_token", answers.masterToken]);
|
await execHost(["config", "set", "host.controller_token", answers.controllerToken]);
|
||||||
await execSlave(["config", "set", "slave.public_address", answers.publicAddress]);
|
await execHost(["config", "set", "host.public_address", answers.publicAddress]);
|
||||||
await execSlave(["config", "set", "slave.factorio_directory", answers.factorioDir]);
|
await execHost(["config", "set", "host.factorio_directory", answers.factorioDir]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dev && ["standalone", "master", "slave"].includes(answers.mode)) {
|
if (!dev && ["standalone", "controller", "host"].includes(answers.mode)) {
|
||||||
logger.info("Writing run scripts");
|
logger.info("Writing run scripts");
|
||||||
await writeScripts(answers.mode);
|
await writeScripts(answers.mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (answers.mode === "ctl") {
|
if (answers.mode === "ctl") {
|
||||||
await execCtl(["control-config", "set", "control.master_url", answers.masterUrl]);
|
await execCtl(["control-config", "set", "control.controller_url", answers.controllerUrl]);
|
||||||
await execCtl(["control-config", "set", "control.master_token", answers.masterToken]);
|
await execCtl(["control-config", "set", "control.controller_token", answers.controllerToken]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ For example, installing the Subspace Storage plugin:
|
|||||||
npm install @clusterio/plugin-subspace_storage
|
npm install @clusterio/plugin-subspace_storage
|
||||||
npx clusterioctl plugin add @clusterio/plugin-subspace_storage
|
npx clusterioctl plugin add @clusterio/plugin-subspace_storage
|
||||||
|
|
||||||
Since the `plugin-list.json` is shared between master, slave and ctl you usually only need to do this once per machine.
|
Since the `plugin-list.json` is shared between controller, host and ctl you usually only need to do this once per machine.
|
||||||
|
|
||||||
|
|
||||||
#### `plugin remove <name>`
|
#### `plugin remove <name>`
|
||||||
@@ -51,7 +51,7 @@ For example, uninstalling the Subspace Storage plugin:
|
|||||||
npx clusterioctl plugin remove subspace_storage
|
npx clusterioctl plugin remove subspace_storage
|
||||||
npm uninstall @clusterio/plugin-subspace_storage
|
npm uninstall @clusterio/plugin-subspace_storage
|
||||||
|
|
||||||
Since the `plugin-list.json` is shared between master, slave and ctl you usually only need to do this once per machine.
|
Since the `plugin-list.json` is shared between controller, host and ctl you usually only need to do this once per machine.
|
||||||
|
|
||||||
|
|
||||||
#### `plugin list`
|
#### `plugin list`
|
||||||
@@ -62,7 +62,7 @@ Lists the plugins set up to be available by name followed by path.
|
|||||||
### `config-control`
|
### `config-control`
|
||||||
|
|
||||||
Manage the ctl configuration.
|
Manage the ctl configuration.
|
||||||
This allows setting the url and token to the master server to manage.
|
This allows setting the url and token to the controller to manage.
|
||||||
|
|
||||||
|
|
||||||
#### `config-control set <config-entry> [value]`
|
#### `config-control set <config-entry> [value]`
|
||||||
|
|||||||
+13
-13
@@ -24,7 +24,7 @@ const commands = require("./src/commands");
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connector for control connection to master server
|
* Connector for control connection to controller
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
class ControlConnector extends libLink.WebSocketClientConnector {
|
class ControlConnector extends libLink.WebSocketClientConnector {
|
||||||
@@ -46,22 +46,22 @@ class ControlConnector extends libLink.WebSocketClientConnector {
|
|||||||
/**
|
/**
|
||||||
* Handles running the control
|
* Handles running the control
|
||||||
*
|
*
|
||||||
* Connects to the master server over WebSocket and sends commands to it.
|
* Connects to the controller over WebSocket and sends commands to it.
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
class Control extends libLink.Link {
|
class Control extends libLink.Link {
|
||||||
|
|
||||||
constructor(connector, controlConfig, tlsCa, controlPlugins) {
|
constructor(connector, controlConfig, tlsCa, controlPlugins) {
|
||||||
super("control", "master", connector);
|
super("control", "controller", connector);
|
||||||
libLink.attachAllMessages(this);
|
libLink.attachAllMessages(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Control config used for connecting to the master.
|
* Control config used for connecting to the controller.
|
||||||
* @type {module:lib/config.ControlConfig}
|
* @type {module:lib/config.ControlConfig}
|
||||||
*/
|
*/
|
||||||
this.config = controlConfig;
|
this.config = controlConfig;
|
||||||
/**
|
/**
|
||||||
* Certificate authority used to validate TLS connections to the master.
|
* Certificate authority used to validate TLS connections to the controller.
|
||||||
* @type {?string}
|
* @type {?string}
|
||||||
*/
|
*/
|
||||||
this.tlsCa = tlsCa;
|
this.tlsCa = tlsCa;
|
||||||
@@ -83,7 +83,7 @@ class Control extends libLink.Link {
|
|||||||
|
|
||||||
async accountUpdateEventHandler() { }
|
async accountUpdateEventHandler() { }
|
||||||
|
|
||||||
async slaveUpdateEventHandler() { }
|
async hostUpdateEventHandler() { }
|
||||||
|
|
||||||
async instanceUpdateEventHandler() { }
|
async instanceUpdateEventHandler() { }
|
||||||
|
|
||||||
@@ -97,13 +97,13 @@ class Control extends libLink.Link {
|
|||||||
|
|
||||||
async setLogSubscriptions({
|
async setLogSubscriptions({
|
||||||
all = false,
|
all = false,
|
||||||
master = false,
|
controller = false,
|
||||||
slave_ids = [],
|
host_ids = [],
|
||||||
instance_ids = [],
|
instance_ids = [],
|
||||||
max_level = null,
|
max_level = null,
|
||||||
}) {
|
}) {
|
||||||
await libLink.messages.setLogSubscriptions.send(this, {
|
await libLink.messages.setLogSubscriptions.send(this, {
|
||||||
all, master, slave_ids, instance_ids, max_level,
|
all, controller, host_ids, instance_ids, max_level,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,8 +251,8 @@ async function startControl() {
|
|||||||
targetCommand = targetCommand.get(commandPath.shift());
|
targetCommand = targetCommand.get(commandPath.shift());
|
||||||
}
|
}
|
||||||
|
|
||||||
// The remaining commands require connecting to the master server.
|
// The remaining commands require connecting to the controller.
|
||||||
if (!controlConfig.get("control.master_url") || !controlConfig.get("control.master_token")) {
|
if (!controlConfig.get("control.controller_url") || !controlConfig.get("control.controller_token")) {
|
||||||
logger.error("Missing URL and/or token to connect with. See README.md for setting up access.");
|
logger.error("Missing URL and/or token to connect with. See README.md for setting up access.");
|
||||||
process.exitCode = 1;
|
process.exitCode = 1;
|
||||||
return;
|
return;
|
||||||
@@ -265,10 +265,10 @@ async function startControl() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let controlConnector = new ControlConnector(
|
let controlConnector = new ControlConnector(
|
||||||
controlConfig.get("control.master_url"),
|
controlConfig.get("control.controller_url"),
|
||||||
controlConfig.get("control.max_reconnect_delay"),
|
controlConfig.get("control.max_reconnect_delay"),
|
||||||
tlsCa,
|
tlsCa,
|
||||||
controlConfig.get("control.master_token")
|
controlConfig.get("control.controller_token")
|
||||||
);
|
);
|
||||||
let control = new Control(controlConnector, controlConfig, tlsCa, controlPlugins);
|
let control = new Control(controlConnector, controlConfig, tlsCa, controlPlugins);
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -84,14 +84,14 @@ async function serializedConfigToString(serializedConfig, configGroup, disallowe
|
|||||||
return allConfigElements;
|
return allConfigElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
const masterCommands = new libCommand.CommandTree({ name: "master", description: "Master management" });
|
const controllerCommands = new libCommand.CommandTree({ name: "controller", description: "Controller management" });
|
||||||
const masterConfigCommands = new libCommand.CommandTree({
|
const controllerConfigCommands = new libCommand.CommandTree({
|
||||||
name: "config", alias: ["c"], description: "master config management",
|
name: "config", alias: ["c"], description: "controller config management",
|
||||||
});
|
});
|
||||||
masterConfigCommands.add(new libCommand.Command({
|
controllerConfigCommands.add(new libCommand.Command({
|
||||||
definition: ["list", "List master configuration"],
|
definition: ["list", "List controller configuration"],
|
||||||
handler: async function(args, control) {
|
handler: async function(args, control) {
|
||||||
let response = await libLink.messages.getMasterConfig.send(control);
|
let response = await libLink.messages.getControllerConfig.send(control);
|
||||||
|
|
||||||
for (let group of response.serialized_config.groups) {
|
for (let group of response.serialized_config.groups) {
|
||||||
for (let [name, value] of Object.entries(group.fields)) {
|
for (let [name, value] of Object.entries(group.fields)) {
|
||||||
@@ -101,8 +101,8 @@ masterConfigCommands.add(new libCommand.Command({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
masterConfigCommands.add(new libCommand.Command({
|
controllerConfigCommands.add(new libCommand.Command({
|
||||||
definition: ["set <field> [value]", "Set field in master config", (yargs) => {
|
definition: ["set <field> [value]", "Set field in controller config", (yargs) => {
|
||||||
yargs.positional("field", { describe: "Field to set", type: "string" });
|
yargs.positional("field", { describe: "Field to set", type: "string" });
|
||||||
yargs.positional("value", { describe: "Value to set", type: "string" });
|
yargs.positional("value", { describe: "Value to set", type: "string" });
|
||||||
yargs.options({
|
yargs.options({
|
||||||
@@ -115,15 +115,15 @@ masterConfigCommands.add(new libCommand.Command({
|
|||||||
} else if (args.value === undefined) {
|
} else if (args.value === undefined) {
|
||||||
args.value = "";
|
args.value = "";
|
||||||
}
|
}
|
||||||
await libLink.messages.setMasterConfigField.send(control, {
|
await libLink.messages.setControllerConfigField.send(control, {
|
||||||
field: args.field,
|
field: args.field,
|
||||||
value: args.value,
|
value: args.value,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
masterConfigCommands.add(new libCommand.Command({
|
controllerConfigCommands.add(new libCommand.Command({
|
||||||
definition: ["set-prop <field> <prop> [value]", "Set property of field in master config", (yargs) => {
|
definition: ["set-prop <field> <prop> [value]", "Set property of field in controller config", (yargs) => {
|
||||||
yargs.positional("field", { describe: "Field to set", type: "string" });
|
yargs.positional("field", { describe: "Field to set", type: "string" });
|
||||||
yargs.positional("prop", { describe: "Property to set", type: "string" });
|
yargs.positional("prop", { describe: "Property to set", type: "string" });
|
||||||
yargs.positional("value", { describe: "JSON parsed value to set", type: "string" });
|
yargs.positional("value", { describe: "JSON parsed value to set", type: "string" });
|
||||||
@@ -150,11 +150,11 @@ masterConfigCommands.add(new libCommand.Command({
|
|||||||
}
|
}
|
||||||
request.value = args.value;
|
request.value = args.value;
|
||||||
}
|
}
|
||||||
await libLink.messages.setMasterConfigProp.send(control, request);
|
await libLink.messages.setControllerConfigProp.send(control, request);
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
masterConfigCommands.add(new libCommand.Command({
|
controllerConfigCommands.add(new libCommand.Command({
|
||||||
definition: ["edit [editor]", "Edit master configuration", (yargs) => {
|
definition: ["edit [editor]", "Edit controller configuration", (yargs) => {
|
||||||
yargs.positional("editor", {
|
yargs.positional("editor", {
|
||||||
describe: "Editor to use",
|
describe: "Editor to use",
|
||||||
type: "string",
|
type: "string",
|
||||||
@@ -162,14 +162,16 @@ masterConfigCommands.add(new libCommand.Command({
|
|||||||
});
|
});
|
||||||
}],
|
}],
|
||||||
handler: async function(args, control) {
|
handler: async function(args, control) {
|
||||||
let response = await libLink.messages.getMasterConfig.send(control);
|
let response = await libLink.messages.getControllerConfig.send(control);
|
||||||
let tmpFile = await libFileOps.getTempFile("ctl-", "-tmp", os.tmpdir());
|
let tmpFile = await libFileOps.getTempFile("ctl-", "-tmp", os.tmpdir());
|
||||||
let editor = await getEditor(args.editor);
|
let editor = await getEditor(args.editor);
|
||||||
if (editor === -1) {
|
if (editor === -1) {
|
||||||
throw new libErrors.CommandError(`No editor avalible. Checked CLI input, EDITOR and VISUAL env vars
|
throw new libErrors.CommandError(`No editor avalible. Checked CLI input, EDITOR and VISUAL env vars
|
||||||
Try "ctl master config edit <editor of choice>"`);
|
Try "ctl controller config edit <editor of choice>"`);
|
||||||
}
|
}
|
||||||
let allConfigElements = await serializedConfigToString(response.serialized_config, libConfig.MasterConfig, {});
|
let allConfigElements = await serializedConfigToString(
|
||||||
|
response.serialized_config, libConfig.ControllerConfig, {}
|
||||||
|
);
|
||||||
await fs.writeFile(tmpFile, allConfigElements, (err) => {
|
await fs.writeFile(tmpFile, allConfigElements, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@@ -189,7 +191,7 @@ masterConfigCommands.add(new libCommand.Command({
|
|||||||
for (let index in final) {
|
for (let index in final) {
|
||||||
if (index in final) {
|
if (index in final) {
|
||||||
try {
|
try {
|
||||||
await libLink.messages.setMasterConfigField.send(control, {
|
await libLink.messages.setControllerConfigField.send(control, {
|
||||||
field: index,
|
field: index,
|
||||||
value: final[index],
|
value: final[index],
|
||||||
});
|
});
|
||||||
@@ -213,16 +215,16 @@ masterConfigCommands.add(new libCommand.Command({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
masterCommands.add(masterConfigCommands);
|
controllerCommands.add(controllerConfigCommands);
|
||||||
|
|
||||||
|
|
||||||
const masterPluginCommands = new libCommand.CommandTree({
|
const controllerPluginCommands = new libCommand.CommandTree({
|
||||||
name: "plugin", alias: ["p"], description: "master plugin inspection",
|
name: "plugin", alias: ["p"], description: "controller plugin inspection",
|
||||||
});
|
});
|
||||||
masterPluginCommands.add(new libCommand.Command({
|
controllerPluginCommands.add(new libCommand.Command({
|
||||||
definition: ["list", "List plugins on master"],
|
definition: ["list", "List plugins on controller"],
|
||||||
handler: async function(args, control) {
|
handler: async function(args, control) {
|
||||||
let url = new URL(control.config.get("control.master_url"));
|
let url = new URL(control.config.get("control.controller_url"));
|
||||||
url.pathname += "api/plugins";
|
url.pathname += "api/plugins";
|
||||||
let response = await phin({
|
let response = await phin({
|
||||||
url,
|
url,
|
||||||
@@ -232,42 +234,42 @@ masterPluginCommands.add(new libCommand.Command({
|
|||||||
print(asTable(response.body));
|
print(asTable(response.body));
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
masterCommands.add(masterPluginCommands);
|
controllerCommands.add(controllerPluginCommands);
|
||||||
|
|
||||||
|
|
||||||
const slaveCommands = new libCommand.CommandTree({ name: "slave", description: "Slave management" });
|
const hostCommands = new libCommand.CommandTree({ name: "host", description: "Host management" });
|
||||||
slaveCommands.add(new libCommand.Command({
|
hostCommands.add(new libCommand.Command({
|
||||||
definition: [["list", "l"], "List slaves connected to the master"],
|
definition: [["list", "l"], "List hosts connected to the controller"],
|
||||||
handler: async function(args, control) {
|
handler: async function(args, control) {
|
||||||
let response = await libLink.messages.listSlaves.send(control);
|
let response = await libLink.messages.listHosts.send(control);
|
||||||
print(asTable(response.list));
|
print(asTable(response.list));
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
slaveCommands.add(new libCommand.Command({
|
hostCommands.add(new libCommand.Command({
|
||||||
definition: ["generate-token", "Generate token for a slave", (yargs) => {
|
definition: ["generate-token", "Generate token for a host", (yargs) => {
|
||||||
yargs.option("id", { type: "number", nargs: 1, describe: "Slave id" });
|
yargs.option("id", { type: "number", nargs: 1, describe: "Host id" });
|
||||||
}],
|
}],
|
||||||
handler: async function(args, control) {
|
handler: async function(args, control) {
|
||||||
let slaveId = typeof args.id === "number" ? args.id : null;
|
let hostId = typeof args.id === "number" ? args.id : null;
|
||||||
let response = await libLink.messages.generateSlaveToken.send(control, { slave_id: slaveId });
|
let response = await libLink.messages.generateHostToken.send(control, { host_id: hostId });
|
||||||
print(response.token);
|
print(response.token);
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
slaveCommands.add(new libCommand.Command({
|
hostCommands.add(new libCommand.Command({
|
||||||
definition: ["create-config", "Create slave config", (yargs) => {
|
definition: ["create-config", "Create host config", (yargs) => {
|
||||||
yargs.option("id", { type: "number", nargs: 1, describe: "Slave id", default: null });
|
yargs.option("id", { type: "number", nargs: 1, describe: "Host id", default: null });
|
||||||
yargs.option("name", { type: "string", nargs: 1, describe: "Slave name", default: null });
|
yargs.option("name", { type: "string", nargs: 1, describe: "Host name", default: null });
|
||||||
yargs.option("generate-token", {
|
yargs.option("generate-token", {
|
||||||
type: "boolean", nargs: 0, describe: "Generate authentication token", default: false,
|
type: "boolean", nargs: 0, describe: "Generate authentication token", default: false,
|
||||||
});
|
});
|
||||||
yargs.option("output", {
|
yargs.option("output", {
|
||||||
type: "string", nargs: 1, describe: "Path to output config (- for stdout)", default: "config-slave.json",
|
type: "string", nargs: 1, describe: "Path to output config (- for stdout)", default: "config-host.json",
|
||||||
});
|
});
|
||||||
}],
|
}],
|
||||||
handler: async function(args, control) {
|
handler: async function(args, control) {
|
||||||
let response = await libLink.messages.createSlaveConfig.send(control, {
|
let response = await libLink.messages.createHostConfig.send(control, {
|
||||||
id: args.id, name: args.name, generate_token: args.generateToken,
|
id: args.id, name: args.name, generate_token: args.generateToken,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -293,7 +295,7 @@ const instanceCommands = new libCommand.CommandTree({
|
|||||||
name: "instance", alias: ["i"], description: "Instance management",
|
name: "instance", alias: ["i"], description: "Instance management",
|
||||||
});
|
});
|
||||||
instanceCommands.add(new libCommand.Command({
|
instanceCommands.add(new libCommand.Command({
|
||||||
definition: [["list", "l"], "List instances known to the master"],
|
definition: [["list", "l"], "List instances known to the controller"],
|
||||||
handler: async function(args, control) {
|
handler: async function(args, control) {
|
||||||
let response = await libLink.messages.listInstances.send(control);
|
let response = await libLink.messages.listInstances.send(control);
|
||||||
print(asTable(response.list));
|
print(asTable(response.list));
|
||||||
@@ -315,7 +317,7 @@ instanceCommands.add(new libCommand.Command({
|
|||||||
instanceConfig.set("instance.id", args.id);
|
instanceConfig.set("instance.id", args.id);
|
||||||
}
|
}
|
||||||
instanceConfig.set("instance.name", args.name);
|
instanceConfig.set("instance.name", args.name);
|
||||||
let serialized_config = instanceConfig.serialize("master");
|
let serialized_config = instanceConfig.serialize("controller");
|
||||||
await libLink.messages.createInstance.send(control, { serialized_config });
|
await libLink.messages.createInstance.send(control, { serialized_config });
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
@@ -426,9 +428,9 @@ instanceConfigCommands.add(new libCommand.Command({
|
|||||||
let editor = await getEditor(args.editor);
|
let editor = await getEditor(args.editor);
|
||||||
if (editor === -1) {
|
if (editor === -1) {
|
||||||
throw new libErrors.CommandError(`No editor avalible. Checked CLI input, EDITOR and VISUAL env vars
|
throw new libErrors.CommandError(`No editor avalible. Checked CLI input, EDITOR and VISUAL env vars
|
||||||
Try "ctl master config edit <editor of choice>"`);
|
Try "ctl controller config edit <editor of choice>"`);
|
||||||
}
|
}
|
||||||
let disallowedList = {"instance.id": 0, "instance.assigned_slave": 0, "factorio.settings": 0};
|
let disallowedList = {"instance.id": 0, "instance.assigned_host": 0, "factorio.settings": 0};
|
||||||
let allConfigElements = await serializedConfigToString(
|
let allConfigElements = await serializedConfigToString(
|
||||||
response.serialized_config,
|
response.serialized_config,
|
||||||
libConfig.InstanceConfig,
|
libConfig.InstanceConfig,
|
||||||
@@ -485,16 +487,16 @@ instanceConfigCommands.add(new libCommand.Command({
|
|||||||
instanceCommands.add(instanceConfigCommands);
|
instanceCommands.add(instanceConfigCommands);
|
||||||
|
|
||||||
instanceCommands.add(new libCommand.Command({
|
instanceCommands.add(new libCommand.Command({
|
||||||
definition: ["assign <instance> [slave]", "Assign instance to a slave", (yargs) => {
|
definition: ["assign <instance> [host]", "Assign instance to a host", (yargs) => {
|
||||||
yargs.positional("instance", { describe: "Instance to assign", type: "string" });
|
yargs.positional("instance", { describe: "Instance to assign", type: "string" });
|
||||||
yargs.positional("slave", { describe: "Slave to assign to or unassign if none", type: "string" });
|
yargs.positional("host", { describe: "Host to assign to or unassign if none", type: "string" });
|
||||||
}],
|
}],
|
||||||
handler: async function(args, control) {
|
handler: async function(args, control) {
|
||||||
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
||||||
let slaveId = args.slave ? await libCommand.resolveSlave(control, args.slave) : null;
|
let hostId = args.host ? await libCommand.resolveHost(control, args.host) : null;
|
||||||
await libLink.messages.assignInstanceCommand.send(control, {
|
await libLink.messages.assignInstanceCommand.send(control, {
|
||||||
instance_id: instanceId,
|
instance_id: instanceId,
|
||||||
slave_id: slaveId,
|
host_id: hostId,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
@@ -614,7 +616,7 @@ instanceSaveCommands.add(new libCommand.Command({
|
|||||||
let content = await fs.readFile(args.filepath);
|
let content = await fs.readFile(args.filepath);
|
||||||
|
|
||||||
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
||||||
let url = new URL(control.config.get("control.master_url"));
|
let url = new URL(control.config.get("control.controller_url"));
|
||||||
url.pathname += "api/upload-save";
|
url.pathname += "api/upload-save";
|
||||||
url.searchParams.append("instance_id", instanceId);
|
url.searchParams.append("instance_id", instanceId);
|
||||||
url.searchParams.append("filename", filename);
|
url.searchParams.append("filename", filename);
|
||||||
@@ -622,7 +624,7 @@ instanceSaveCommands.add(new libCommand.Command({
|
|||||||
let result = await phin({
|
let result = await phin({
|
||||||
url, method: "POST",
|
url, method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"X-Access-Token": control.config.get("control.master_token"),
|
"X-Access-Token": control.config.get("control.controller_token"),
|
||||||
"Content-Type": "application/zip",
|
"Content-Type": "application/zip",
|
||||||
},
|
},
|
||||||
core: { ca: control.tlsCa },
|
core: { ca: control.tlsCa },
|
||||||
@@ -688,7 +690,7 @@ instanceSaveCommands.add(new libCommand.Command({
|
|||||||
save: args.save,
|
save: args.save,
|
||||||
});
|
});
|
||||||
|
|
||||||
let url = new URL(control.config.get("control.master_url"));
|
let url = new URL(control.config.get("control.controller_url"));
|
||||||
url.pathname += `api/stream/${result.stream_id}`;
|
url.pathname += `api/stream/${result.stream_id}`;
|
||||||
let response = await phin({
|
let response = await phin({
|
||||||
url, method: "GET",
|
url, method: "GET",
|
||||||
@@ -1233,14 +1235,14 @@ modCommands.add(new libCommand.Command({
|
|||||||
// phin doesn't support streaming requests :(
|
// phin doesn't support streaming requests :(
|
||||||
let content = await fs.readFile(args.file);
|
let content = await fs.readFile(args.file);
|
||||||
|
|
||||||
let url = new URL(control.config.get("control.master_url"));
|
let url = new URL(control.config.get("control.controller_url"));
|
||||||
url.pathname += "api/upload-mod";
|
url.pathname += "api/upload-mod";
|
||||||
url.searchParams.append("filename", filename);
|
url.searchParams.append("filename", filename);
|
||||||
|
|
||||||
let result = await phin({
|
let result = await phin({
|
||||||
url, method: "POST",
|
url, method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"X-Access-Token": control.config.get("control.master_token"),
|
"X-Access-Token": control.config.get("control.controller_token"),
|
||||||
"Content-Type": "application/zip",
|
"Content-Type": "application/zip",
|
||||||
},
|
},
|
||||||
core: { ca: control.tlsCa },
|
core: { ca: control.tlsCa },
|
||||||
@@ -1278,7 +1280,7 @@ modCommands.add(new libCommand.Command({
|
|||||||
version: args.modVersion,
|
version: args.modVersion,
|
||||||
});
|
});
|
||||||
|
|
||||||
let url = new URL(control.config.get("control.master_url"));
|
let url = new URL(control.config.get("control.controller_url"));
|
||||||
url.pathname += `api/stream/${result.stream_id}`;
|
url.pathname += `api/stream/${result.stream_id}`;
|
||||||
let response = await phin({
|
let response = await phin({
|
||||||
url, method: "GET",
|
url, method: "GET",
|
||||||
@@ -1583,20 +1585,20 @@ logCommands.add(new libCommand.Command({
|
|||||||
definition: ["follow", "follow cluster log", (yargs) => {
|
definition: ["follow", "follow cluster log", (yargs) => {
|
||||||
yargs.options({
|
yargs.options({
|
||||||
"all": { describe: "Follow the whole cluster log", nargs: 0, type: "boolean", default: false },
|
"all": { describe: "Follow the whole cluster log", nargs: 0, type: "boolean", default: false },
|
||||||
"master": { describe: "Follow log of the master server", nargs: 0, type: "boolean", default: false },
|
"controller": { describe: "Follow log of the controller", nargs: 0, type: "boolean", default: false },
|
||||||
"slave": { describe: "Follow log of given slave", nargs: 1, type: "string", default: null },
|
"host": { describe: "Follow log of given host", nargs: 1, type: "string", default: null },
|
||||||
"instance": { describe: "Follow log of given instance", nargs: 1, type: "string", default: null },
|
"instance": { describe: "Follow log of given instance", nargs: 1, type: "string", default: null },
|
||||||
});
|
});
|
||||||
}],
|
}],
|
||||||
handler: async function(args, control) {
|
handler: async function(args, control) {
|
||||||
if (!args.all && !args.master && !args.slave && !args.instance) {
|
if (!args.all && !args.controller && !args.host && !args.instance) {
|
||||||
logger.error("At least one of --all, --master, --slave and --instance must be passed");
|
logger.error("At least one of --all, --controller, --host and --instance must be passed");
|
||||||
process.exitCode = 1;
|
process.exitCode = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let instance_ids = args.instance ? [await libCommand.resolveInstance(control, args.instance)] : [];
|
let instance_ids = args.instance ? [await libCommand.resolveInstance(control, args.instance)] : [];
|
||||||
let slave_ids = args.slave ? [await libCommand.resolveSlave(control, args.slave)] : [];
|
let host_ids = args.host ? [await libCommand.resolveHost(control, args.host)] : [];
|
||||||
await control.setLogSubscriptions({ all: args.all, master: args.master, slave_ids, instance_ids });
|
await control.setLogSubscriptions({ all: args.all, controller: args.controller, host_ids, instance_ids });
|
||||||
control.keepOpen = true;
|
control.keepOpen = true;
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
@@ -1605,8 +1607,8 @@ logCommands.add(new libCommand.Command({
|
|||||||
definition: ["query", "Query cluster log", (yargs) => {
|
definition: ["query", "Query cluster log", (yargs) => {
|
||||||
yargs.options({
|
yargs.options({
|
||||||
"all": { describe: "Query the whole cluster log", nargs: 0, type: "boolean", default: false },
|
"all": { describe: "Query the whole cluster log", nargs: 0, type: "boolean", default: false },
|
||||||
"master": { describe: "Query log of the master server", nargs: 0, type: "boolean", default: false },
|
"controller": { describe: "Query log of the controller", nargs: 0, type: "boolean", default: false },
|
||||||
"slave": { describe: "Query log of given slave", nargs: 1, type: "string", default: null },
|
"host": { describe: "Query log of given host", nargs: 1, type: "string", default: null },
|
||||||
"instance": { describe: "Query log of given instance", nargs: 1, type: "string", default: null },
|
"instance": { describe: "Query log of given instance", nargs: 1, type: "string", default: null },
|
||||||
"max-level": { describe: "Maximum log level to return", nargs: 1, type: "string", default: null },
|
"max-level": { describe: "Maximum log level to return", nargs: 1, type: "string", default: null },
|
||||||
"limit": { describe: "Max number of entries to return", nargs: 1, type: "number", default: 1000 },
|
"limit": { describe: "Max number of entries to return", nargs: 1, type: "number", default: 1000 },
|
||||||
@@ -1614,17 +1616,17 @@ logCommands.add(new libCommand.Command({
|
|||||||
});
|
});
|
||||||
}],
|
}],
|
||||||
handler: async function(args, control) {
|
handler: async function(args, control) {
|
||||||
if (!args.all && !args.master && !args.slave && !args.instance) {
|
if (!args.all && !args.controller && !args.host && !args.instance) {
|
||||||
logger.error("At least one of --all, --master, --slave and --instance must be passed");
|
logger.error("At least one of --all, --controller, --host and --instance must be passed");
|
||||||
process.exitCode = 1;
|
process.exitCode = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let instance_ids = args.instance ? [await libCommand.resolveInstance(control, args.instance)] : [];
|
let instance_ids = args.instance ? [await libCommand.resolveInstance(control, args.instance)] : [];
|
||||||
let slave_ids = args.slave ? [await libCommand.resolveSlave(control, args.slave)] : [];
|
let host_ids = args.host ? [await libCommand.resolveHost(control, args.host)] : [];
|
||||||
let result = await libLink.messages.queryLog.send(control, {
|
let result = await libLink.messages.queryLog.send(control, {
|
||||||
all: args.all,
|
all: args.all,
|
||||||
master: args.master,
|
controller: args.controller,
|
||||||
slave_ids,
|
host_ids,
|
||||||
instance_ids,
|
instance_ids,
|
||||||
max_level: args.maxLevel,
|
max_level: args.maxLevel,
|
||||||
limit: args.limit,
|
limit: args.limit,
|
||||||
@@ -1651,7 +1653,7 @@ logCommands.add(new libCommand.Command({
|
|||||||
|
|
||||||
const debugCommands = new libCommand.CommandTree({ name: "debug", description: "Debugging utilities" });
|
const debugCommands = new libCommand.CommandTree({ name: "debug", description: "Debugging utilities" });
|
||||||
debugCommands.add(new libCommand.Command({
|
debugCommands.add(new libCommand.Command({
|
||||||
definition: ["dump-ws", "Dump WebSocket messages sent and received by master", (yargs) => { }],
|
definition: ["dump-ws", "Dump WebSocket messages sent and received by controller", (yargs) => { }],
|
||||||
handler: async function(args, control) {
|
handler: async function(args, control) {
|
||||||
await libLink.messages.debugDumpWs.send(control);
|
await libLink.messages.debugDumpWs.send(control);
|
||||||
control.keepOpen = true;
|
control.keepOpen = true;
|
||||||
@@ -1660,8 +1662,8 @@ debugCommands.add(new libCommand.Command({
|
|||||||
|
|
||||||
async function registerCommands(controlPlugins, yargs) {
|
async function registerCommands(controlPlugins, yargs) {
|
||||||
const rootCommands = new libCommand.CommandTree({ name: "clusterioctl", description: "Manage cluster" });
|
const rootCommands = new libCommand.CommandTree({ name: "clusterioctl", description: "Manage cluster" });
|
||||||
rootCommands.add(masterCommands);
|
rootCommands.add(controllerCommands);
|
||||||
rootCommands.add(slaveCommands);
|
rootCommands.add(hostCommands);
|
||||||
rootCommands.add(instanceCommands);
|
rootCommands.add(instanceCommands);
|
||||||
rootCommands.add(modPackCommands);
|
rootCommands.add(modPackCommands);
|
||||||
rootCommands.add(modCommands);
|
rootCommands.add(modCommands);
|
||||||
|
|||||||
@@ -1,28 +1,28 @@
|
|||||||
# Clusterio Slave
|
# Clusterio Host
|
||||||
|
|
||||||
Node hosting Factorio servers in a Clusterio cluster.
|
Node hosting Factorio servers in a Clusterio cluster.
|
||||||
Clusterio slaves connect to the master server and waits for commands from the master server to start up and stop instances.
|
Clusterio hosts connect to the controller and waits for commands from the controller to start up and stop instances.
|
||||||
A cluster can have any number of slaves in it located on different computers, and each slave can host any number of instances each of which is a Factorio server that talks with the rest of the cluster.
|
A cluster can have any number of hosts in it located on different computers, and each host can host any number of instances each of which is a Factorio server that talks with the rest of the cluster.
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
npx clusterioslave <command>
|
npx clusteriohost <command>
|
||||||
|
|
||||||
Common options:
|
Common options:
|
||||||
|
|
||||||
* `--plugin-list <file>` JSON file to use for storing the list of plugins that are available to the slave.
|
* `--plugin-list <file>` JSON file to use for storing the list of plugins that are available to the host.
|
||||||
Defaults to `plugin-list.json` and will be created if it does not exist.
|
Defaults to `plugin-list.json` and will be created if it does not exist.
|
||||||
See the `plugin` command for managing this list.
|
See the `plugin` command for managing this list.
|
||||||
|
|
||||||
* `--config <file>` JSON file to use for storing configuration for the slave.
|
* `--config <file>` JSON file to use for storing configuration for the host.
|
||||||
Defaults to `config-slave.json` and will be created if it does not exist.
|
Defaults to `config-host.json` and will be created if it does not exist.
|
||||||
See the `config` command for inspecting and modifying the configuration.
|
See the `config` command for inspecting and modifying the configuration.
|
||||||
|
|
||||||
|
|
||||||
### `plugin <command>`
|
### `plugin <command>`
|
||||||
|
|
||||||
Configure plugins available to be loaded by the slave.
|
Configure plugins available to be loaded by the host.
|
||||||
The available plugins will be loaded unless they have been disabled in the configuration, see the config command for disabling plugins.
|
The available plugins will be loaded unless they have been disabled in the configuration, see the config command for disabling plugins.
|
||||||
|
|
||||||
|
|
||||||
@@ -34,9 +34,9 @@ A relative path must start with ./ or ../ (or .\ and ..\ on Windows) otherwise i
|
|||||||
For example, installing the Subspace Storage plugin:
|
For example, installing the Subspace Storage plugin:
|
||||||
|
|
||||||
npm install @clusterio/plugin-subspace_storage
|
npm install @clusterio/plugin-subspace_storage
|
||||||
npx clusterioslave plugin add @clusterio/plugin-subspace_storage
|
npx clusteriohost plugin add @clusterio/plugin-subspace_storage
|
||||||
|
|
||||||
Since the `plugin-list.json` is shared between master, slave and ctl you usually only need to do this once per machine.
|
Since the `plugin-list.json` is shared between controller, host and ctl you usually only need to do this once per machine.
|
||||||
|
|
||||||
|
|
||||||
#### `plugin remove <name>`
|
#### `plugin remove <name>`
|
||||||
@@ -47,10 +47,10 @@ Removing and unistalling a plugin is usually not neccessary as the functions pro
|
|||||||
|
|
||||||
For example, uninstalling the Subspace Storage plugin:
|
For example, uninstalling the Subspace Storage plugin:
|
||||||
|
|
||||||
npx clusterioslave plugin remove subspace_storage
|
npx clusteriohost plugin remove subspace_storage
|
||||||
npm uninstall @clusterio/plugin-subspace_storage
|
npm uninstall @clusterio/plugin-subspace_storage
|
||||||
|
|
||||||
Since the `plugin-list.json` is shared between master, slave and ctl you usually only need to do this once per machine.
|
Since the `plugin-list.json` is shared between controller, host and ctl you usually only need to do this once per machine.
|
||||||
|
|
||||||
|
|
||||||
#### `plugin list`
|
#### `plugin list`
|
||||||
@@ -60,8 +60,8 @@ Lists the plugins set up to be available by name followed by path.
|
|||||||
|
|
||||||
### `config`
|
### `config`
|
||||||
|
|
||||||
Manage the slave configuration offline.
|
Manage the host configuration offline.
|
||||||
This should only be used when the slave is stopped, otherwise the config read might be out of date and config changes will be overwritten when the slave shuts down.
|
This should only be used when the host is stopped, otherwise the config read might be out of date and config changes will be overwritten when the host shuts down.
|
||||||
|
|
||||||
|
|
||||||
#### `config set <config-entry> [value]`
|
#### `config set <config-entry> [value]`
|
||||||
@@ -85,7 +85,7 @@ Lists up all configuration entries with their currently configured values.
|
|||||||
|
|
||||||
### `run`
|
### `run`
|
||||||
|
|
||||||
Runs the slave.
|
Runs the host.
|
||||||
|
|
||||||
|
|
||||||
## See Also
|
## See Also
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clusterio slave
|
* Clusterio host
|
||||||
*
|
*
|
||||||
* Connects to the master server and hosts Factorio servers that can
|
* Connects to the controller and hosts Factorio servers that can
|
||||||
* communicate with the cluster. It is remotely controlled by {@link
|
* communicate with the cluster. It is remotely controlled by {@link
|
||||||
* module:master/master}.
|
* module:controller/controller}.
|
||||||
*
|
*
|
||||||
* @module slave/slave
|
* @module host/host
|
||||||
* @author Danielv123, Hornwitser
|
* @author Danielv123, Hornwitser
|
||||||
* @example
|
* @example
|
||||||
* npx clusterioslave run
|
* npx clusteriohost run
|
||||||
*/
|
*/
|
||||||
"use strict";
|
"use strict";
|
||||||
const fs = require("fs-extra");
|
const fs = require("fs-extra");
|
||||||
@@ -30,44 +30,44 @@ const libSharedCommands = require("@clusterio/lib/shared_commands");
|
|||||||
const { ConsoleTransport, FilteredTransport, levels, logger } = require("@clusterio/lib/logging");
|
const { ConsoleTransport, FilteredTransport, levels, logger } = require("@clusterio/lib/logging");
|
||||||
const libLoggingUtils = require("@clusterio/lib/logging_utils");
|
const libLoggingUtils = require("@clusterio/lib/logging_utils");
|
||||||
|
|
||||||
const Slave = require("./src/Slave");
|
const Host = require("./src/Host");
|
||||||
|
|
||||||
|
|
||||||
class SlaveConnector extends libLink.WebSocketClientConnector {
|
class HostConnector extends libLink.WebSocketClientConnector {
|
||||||
constructor(slaveConfig, tlsCa, pluginInfos) {
|
constructor(hostConfig, tlsCa, pluginInfos) {
|
||||||
super(
|
super(
|
||||||
slaveConfig.get("slave.master_url"),
|
hostConfig.get("host.controller_url"),
|
||||||
slaveConfig.get("slave.max_reconnect_delay"),
|
hostConfig.get("host.max_reconnect_delay"),
|
||||||
tlsCa
|
tlsCa
|
||||||
);
|
);
|
||||||
this.slaveConfig = slaveConfig;
|
this.hostConfig = hostConfig;
|
||||||
this.pluginInfos = pluginInfos;
|
this.pluginInfos = pluginInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
register() {
|
register() {
|
||||||
logger.info("Connector | registering slave");
|
logger.info("Connector | registering host");
|
||||||
let plugins = {};
|
let plugins = {};
|
||||||
for (let pluginInfo of this.pluginInfos) {
|
for (let pluginInfo of this.pluginInfos) {
|
||||||
plugins[pluginInfo.name] = pluginInfo.version;
|
plugins[pluginInfo.name] = pluginInfo.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sendHandshake("register_slave", {
|
this.sendHandshake("register_host", {
|
||||||
token: this.slaveConfig.get("slave.master_token"),
|
token: this.hostConfig.get("host.controller_token"),
|
||||||
agent: "Clusterio Slave",
|
agent: "Clusterio Host",
|
||||||
version,
|
version,
|
||||||
id: this.slaveConfig.get("slave.id"),
|
id: this.hostConfig.get("host.id"),
|
||||||
name: this.slaveConfig.get("slave.name"),
|
name: this.hostConfig.get("host.name"),
|
||||||
public_address: this.slaveConfig.get("slave.public_address"),
|
public_address: this.hostConfig.get("host.public_address"),
|
||||||
plugins,
|
plugins,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function startSlave() {
|
async function startHost() {
|
||||||
// argument parsing
|
// argument parsing
|
||||||
const args = yargs
|
const args = yargs
|
||||||
.scriptName("slave")
|
.scriptName("host")
|
||||||
.usage("$0 <command> [options]")
|
.usage("$0 <command> [options]")
|
||||||
.option("log-level", {
|
.option("log-level", {
|
||||||
nargs: 1,
|
nargs: 1,
|
||||||
@@ -84,8 +84,8 @@ async function startSlave() {
|
|||||||
})
|
})
|
||||||
.option("config", {
|
.option("config", {
|
||||||
nargs: 1,
|
nargs: 1,
|
||||||
describe: "slave config file to use",
|
describe: "host config file to use",
|
||||||
default: "config-slave.json",
|
default: "config-host.json",
|
||||||
type: "string",
|
type: "string",
|
||||||
})
|
})
|
||||||
.option("plugin-list", {
|
.option("plugin-list", {
|
||||||
@@ -95,32 +95,18 @@ async function startSlave() {
|
|||||||
type: "string",
|
type: "string",
|
||||||
})
|
})
|
||||||
.command("plugin", "Manage available plugins", libSharedCommands.pluginCommand)
|
.command("plugin", "Manage available plugins", libSharedCommands.pluginCommand)
|
||||||
.command("config", "Manage Slave config", libSharedCommands.configCommand)
|
.command("config", "Manage Host config", libSharedCommands.configCommand)
|
||||||
.command("run", "Run slave")
|
.command("run", "Run host")
|
||||||
.demandCommand(1, "You need to specify a command to run")
|
.demandCommand(1, "You need to specify a command to run")
|
||||||
.strict()
|
.strict()
|
||||||
.argv
|
.argv
|
||||||
;
|
;
|
||||||
|
|
||||||
{
|
|
||||||
// Migration from alpha-10 single file logs, note that we can't use
|
|
||||||
// the logger here as it's not initalized yet.
|
|
||||||
/* eslint-disable no-console */
|
|
||||||
let slaveLogDirectory = path.join(args.logDirectory, "slave");
|
|
||||||
if (!await fs.pathExists(slaveLogDirectory) && await fs.pathExists("slave.log")) {
|
|
||||||
console.log("Migrating slave log...");
|
|
||||||
await fs.ensureDir(slaveLogDirectory);
|
|
||||||
await libLoggingUtils.migrateLogs("slave.log", slaveLogDirectory, "slave-%DATE%.log");
|
|
||||||
console.log("Migration complete, you should delete slave.log now");
|
|
||||||
}
|
|
||||||
/* eslint-enable no-console */
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.add(new winston.transports.DailyRotateFile({
|
logger.add(new winston.transports.DailyRotateFile({
|
||||||
format: winston.format.json(),
|
format: winston.format.json(),
|
||||||
filename: "slave-%DATE%.log",
|
filename: "host-%DATE%.log",
|
||||||
utc: true,
|
utc: true,
|
||||||
dirname: path.join(args.logDirectory, "slave"),
|
dirname: path.join(args.logDirectory, "host"),
|
||||||
}));
|
}));
|
||||||
if (args.logLevel !== "none") {
|
if (args.logLevel !== "none") {
|
||||||
logger.add(new ConsoleTransport({
|
logger.add(new ConsoleTransport({
|
||||||
@@ -133,7 +119,7 @@ async function startSlave() {
|
|||||||
|
|
||||||
let command = args._[0];
|
let command = args._[0];
|
||||||
if (command === "run") {
|
if (command === "run") {
|
||||||
logger.info(`Starting Clusterio slave ${version}`);
|
logger.info(`Starting Clusterio host ${version}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(`Loading available plugins from ${args.pluginList}`);
|
logger.info(`Loading available plugins from ${args.pluginList}`);
|
||||||
@@ -158,14 +144,14 @@ async function startSlave() {
|
|||||||
libConfig.finalizeConfigs();
|
libConfig.finalizeConfigs();
|
||||||
|
|
||||||
logger.info(`Loading config from ${args.config}`);
|
logger.info(`Loading config from ${args.config}`);
|
||||||
let slaveConfig = new libConfig.SlaveConfig("slave");
|
let hostConfig = new libConfig.HostConfig("host");
|
||||||
try {
|
try {
|
||||||
await slaveConfig.load(JSON.parse(await fs.readFile(args.config)));
|
await hostConfig.load(JSON.parse(await fs.readFile(args.config)));
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.code === "ENOENT") {
|
if (err.code === "ENOENT") {
|
||||||
logger.info("Config not found, initializing new config");
|
logger.info("Config not found, initializing new config");
|
||||||
await slaveConfig.init();
|
await hostConfig.init();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new libErrors.StartupError(`Failed to load ${args.config}: ${err.message}`);
|
throw new libErrors.StartupError(`Failed to load ${args.config}: ${err.message}`);
|
||||||
@@ -173,49 +159,49 @@ async function startSlave() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (command === "config") {
|
if (command === "config") {
|
||||||
await libSharedCommands.handleConfigCommand(args, slaveConfig, args.config);
|
await libSharedCommands.handleConfigCommand(args, hostConfig, args.config);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we get here the command was run
|
// If we get here the command was run
|
||||||
|
|
||||||
await fs.ensureDir(slaveConfig.get("slave.instances_directory"));
|
await fs.ensureDir(hostConfig.get("host.instances_directory"));
|
||||||
await fs.ensureDir(slaveConfig.get("slave.mods_directory"));
|
await fs.ensureDir(hostConfig.get("host.mods_directory"));
|
||||||
await fs.ensureDir("modules");
|
await fs.ensureDir("modules");
|
||||||
|
|
||||||
// Set the process title, shows up as the title of the CMD window on windows
|
// Set the process title, shows up as the title of the CMD window on windows
|
||||||
// and as the process name in ps/top on linux.
|
// and as the process name in ps/top on linux.
|
||||||
process.title = "clusterioSlave";
|
process.title = "clusteriohost";
|
||||||
|
|
||||||
// make sure we have the master access token
|
// make sure we have the controller access token
|
||||||
if (slaveConfig.get("slave.master_token") === "enter token here") {
|
if (hostConfig.get("host.controller_token") === "enter token here") {
|
||||||
logger.fatal("ERROR invalid config!");
|
logger.fatal("ERROR invalid config!");
|
||||||
logger.fatal(
|
logger.fatal(
|
||||||
"Master server requires an access token for socket operations. As clusterio\n"+
|
"Controller requires an access token for socket operations. As clusterio\n"+
|
||||||
"slaves depends upon this, please set your token using the command npx\n"+
|
"hosts depends upon this, please set your token using the command npx\n"+
|
||||||
"clusterioslave config set slave.master_token <token>. You can generate an\n"+
|
"clusteriohost config set host.controller_token <token>. You can generate an\n"+
|
||||||
"auth token using npx clusterioctl generate-slave-token."
|
"auth token using npx clusterioctl generate-host-token."
|
||||||
);
|
);
|
||||||
process.exitCode = 1;
|
process.exitCode = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure url ends with /
|
// make sure url ends with /
|
||||||
if (!slaveConfig.get("slave.master_url").endsWith("/")) {
|
if (!hostConfig.get("host.controller_url").endsWith("/")) {
|
||||||
logger.fatal("ERROR invalid config!");
|
logger.fatal("ERROR invalid config!");
|
||||||
logger.fatal("slave.master_url must end with '/'");
|
logger.fatal("host.controller_url must end with '/'");
|
||||||
process.exitCode = 1;
|
process.exitCode = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let tlsCa = null;
|
let tlsCa = null;
|
||||||
let tlsCaPath = slaveConfig.get("slave.tls_ca");
|
let tlsCaPath = hostConfig.get("host.tls_ca");
|
||||||
if (tlsCaPath) {
|
if (tlsCaPath) {
|
||||||
tlsCa = await fs.readFile(tlsCaPath);
|
tlsCa = await fs.readFile(tlsCaPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
let slaveConnector = new SlaveConnector(slaveConfig, tlsCa, pluginInfos);
|
let hostConnector = new HostConnector(hostConfig, tlsCa, pluginInfos);
|
||||||
let slave = new Slave(slaveConnector, slaveConfig, tlsCa, pluginInfos);
|
let host = new Host(hostConnector, hostConfig, tlsCa, pluginInfos);
|
||||||
|
|
||||||
// Handle interrupts
|
// Handle interrupts
|
||||||
let secondSigint = false;
|
let secondSigint = false;
|
||||||
@@ -229,7 +215,7 @@ async function startSlave() {
|
|||||||
|
|
||||||
secondSigint = true;
|
secondSigint = true;
|
||||||
logger.info("Caught interrupt signal, shutting down");
|
logger.info("Caught interrupt signal, shutting down");
|
||||||
slave.shutdown();
|
host.shutdown();
|
||||||
});
|
});
|
||||||
let secondSigterm = false;
|
let secondSigterm = false;
|
||||||
process.on("SIGTERM", () => {
|
process.on("SIGTERM", () => {
|
||||||
@@ -242,19 +228,19 @@ async function startSlave() {
|
|||||||
|
|
||||||
secondSigterm = true;
|
secondSigterm = true;
|
||||||
logger.info("Caught termination signal, shutting down");
|
logger.info("Caught termination signal, shutting down");
|
||||||
slave.shutdown();
|
host.shutdown();
|
||||||
});
|
});
|
||||||
process.on("SIGHUP", () => {
|
process.on("SIGHUP", () => {
|
||||||
logger.info("Terminal closed, shutting down");
|
logger.info("Terminal closed, shutting down");
|
||||||
slave.shutdown();
|
host.shutdown();
|
||||||
});
|
});
|
||||||
|
|
||||||
slaveConnector.once("connect", () => {
|
hostConnector.once("connect", () => {
|
||||||
logger.add(new libLoggingUtils.LinkTransport({ link: slave }));
|
logger.add(new libLoggingUtils.LinkTransport({ link: host }));
|
||||||
});
|
});
|
||||||
|
|
||||||
await slaveConnector.connect();
|
await hostConnector.connect();
|
||||||
logger.info("Started slave");
|
logger.info("Started host");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (module === require.main) {
|
if (module === require.main) {
|
||||||
@@ -266,15 +252,15 @@ I version of clusterio. Expect things to break. I
|
|||||||
+==========================================================+
|
+==========================================================+
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
startSlave().catch(err => {
|
startHost().catch(err => {
|
||||||
if (err instanceof libErrors.AuthenticationFailed) {
|
if (err instanceof libErrors.AuthenticationFailed) {
|
||||||
logger.fatal(err.message);
|
logger.fatal(err.message);
|
||||||
|
|
||||||
} else if (err instanceof libErrors.StartupError) {
|
} else if (err instanceof libErrors.StartupError) {
|
||||||
logger.fatal(`
|
logger.fatal(`
|
||||||
+-----------------------------------+
|
+----------------------------------+
|
||||||
| Unable to to start clusterioslave |
|
| Unable to to start clusteriohost |
|
||||||
+-----------------------------------+
|
+----------------------------------+
|
||||||
${err.stack}`
|
${err.stack}`
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -289,7 +275,7 @@ ${err.original.stack}`
|
|||||||
} else {
|
} else {
|
||||||
logger.fatal(`
|
logger.fatal(`
|
||||||
+------------------------------------------------------------+
|
+------------------------------------------------------------+
|
||||||
| Unexpected error occured while starting slave, please |
|
| Unexpected error occured while starting host, please |
|
||||||
| report it to https://github.com/clusterio/clusterio/issues |
|
| report it to https://github.com/clusterio/clusterio/issues |
|
||||||
+------------------------------------------------------------+
|
+------------------------------------------------------------+
|
||||||
${err.stack}`
|
${err.stack}`
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,15 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "@clusterio/slave",
|
"name": "@clusterio/host",
|
||||||
"description": "Implementation of Clusterio slave server",
|
"description": "Implementation of Clusterio host server",
|
||||||
"author": "Hornwitser",
|
"author": "Hornwitser",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "2.0.0-alpha.13",
|
"version": "2.0.0-alpha.13",
|
||||||
"main": "slave.js",
|
"main": "host.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"clusterioslave": "./slave.js"
|
"clusteriohost": "./host.js"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"factorio"
|
"factorio"
|
||||||
@@ -49,7 +49,7 @@ async function discoverInstances(instancesDir) {
|
|||||||
let instanceInfos = new Map();
|
let instanceInfos = new Map();
|
||||||
for (let entry of await fs.readdir(instancesDir, { withFileTypes: true })) {
|
for (let entry of await fs.readdir(instancesDir, { withFileTypes: true })) {
|
||||||
if (entry.isDirectory()) {
|
if (entry.isDirectory()) {
|
||||||
let instanceConfig = new libConfig.InstanceConfig("slave");
|
let instanceConfig = new libConfig.InstanceConfig("host");
|
||||||
let configPath = path.join(instancesDir, entry.name, "instance.json");
|
let configPath = path.join(instancesDir, entry.name, "instance.json");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -81,16 +81,16 @@ async function discoverInstances(instancesDir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles running the slave
|
* Handles running the host
|
||||||
*
|
*
|
||||||
* Connects to the master server over the WebSocket and manages intsances.
|
* Connects to the controller over the WebSocket and manages intsances.
|
||||||
* @alias module:slave/src/Slave
|
* @alias module:host/src/Host
|
||||||
*/
|
*/
|
||||||
class Slave extends libLink.Link {
|
class Host extends libLink.Link {
|
||||||
// I don't like God classes, but the alternative of putting all this state
|
// I don't like God classes, but the alternative of putting all this state
|
||||||
// into global variables is not much better.
|
// into global variables is not much better.
|
||||||
constructor(connector, slaveConfig, tlsCa, pluginInfos) {
|
constructor(connector, hostConfig, tlsCa, pluginInfos) {
|
||||||
super("slave", "master", connector);
|
super("host", "controller", connector);
|
||||||
libLink.attachAllMessages(this);
|
libLink.attachAllMessages(this);
|
||||||
|
|
||||||
this.pluginInfos = pluginInfos;
|
this.pluginInfos = pluginInfos;
|
||||||
@@ -98,10 +98,10 @@ class Slave extends libLink.Link {
|
|||||||
libPlugin.attachPluginMessages(this, { info: pluginInfo });
|
libPlugin.attachPluginMessages(this, { info: pluginInfo });
|
||||||
}
|
}
|
||||||
|
|
||||||
this.config = slaveConfig;
|
this.config = hostConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Certificate authority used to validate TLS connections to the master.
|
* Certificate authority used to validate TLS connections to the controller.
|
||||||
* @type {?string}
|
* @type {?string}
|
||||||
*/
|
*/
|
||||||
this.tlsCa = tlsCa;
|
this.tlsCa = tlsCa;
|
||||||
@@ -146,12 +146,12 @@ class Slave extends libLink.Link {
|
|||||||
if (this._disconnecting) {
|
if (this._disconnecting) {
|
||||||
this._disconnecting = false;
|
this._disconnecting = false;
|
||||||
this.connector.connect().catch((err) => {
|
this.connector.connect().catch((err) => {
|
||||||
logger.fatal(`Unexpected error reconnecting to master:\n${err.stack}`);
|
logger.fatal(`Unexpected error reconnecting to controller:\n${err.stack}`);
|
||||||
return this.shutdown();
|
return this.shutdown();
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
logger.fatal("Master connection was unexpectedly closed");
|
logger.fatal("Controller connection was unexpectedly closed");
|
||||||
this.shutdown();
|
this.shutdown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -159,7 +159,7 @@ class Slave extends libLink.Link {
|
|||||||
for (let event of ["connect", "drop", "resume", "close"]) {
|
for (let event of ["connect", "drop", "resume", "close"]) {
|
||||||
this.connector.on(event, () => {
|
this.connector.on(event, () => {
|
||||||
for (let instanceConnection of this.instanceConnections.values()) {
|
for (let instanceConnection of this.instanceConnections.values()) {
|
||||||
libLink.messages.masterConnectionEvent.send(instanceConnection, { event });
|
libLink.messages.controllerConnectionEvent.send(instanceConnection, { event });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -173,7 +173,7 @@ class Slave extends libLink.Link {
|
|||||||
throw new Error(`Instance folder was unepectedly invalid: name ${err.message}`);
|
throw new Error(`Instance folder was unepectedly invalid: name ${err.message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let instancesDir = this.config.get("slave.instances_directory");
|
let instancesDir = this.config.get("host.instances_directory");
|
||||||
for (let i = 0; i < 10; i++) { // Limit attempts in case this is somehow an infinite loop
|
for (let i = 0; i < 10; i++) { // Limit attempts in case this is somehow an infinite loop
|
||||||
let candidateDir = path.join(instancesDir, await libFileOps.findUnusedName(instancesDir, name));
|
let candidateDir = path.join(instancesDir, await libFileOps.findUnusedName(instancesDir, name));
|
||||||
try {
|
try {
|
||||||
@@ -306,22 +306,22 @@ class Slave extends libLink.Link {
|
|||||||
let { instance_id, serialized_config } = message.data;
|
let { instance_id, serialized_config } = message.data;
|
||||||
let instanceInfo = this.instanceInfos.get(instance_id);
|
let instanceInfo = this.instanceInfos.get(instance_id);
|
||||||
if (instanceInfo) {
|
if (instanceInfo) {
|
||||||
instanceInfo.config.update(serialized_config, true, "master");
|
instanceInfo.config.update(serialized_config, true, "controller");
|
||||||
logger.verbose(`Updated config for ${instanceInfo.path}`, this.instanceLogMeta(instance_id, instanceInfo));
|
logger.verbose(`Updated config for ${instanceInfo.path}`, this.instanceLogMeta(instance_id, instanceInfo));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
instanceInfo = this.discoveredInstanceInfos.get(instance_id);
|
instanceInfo = this.discoveredInstanceInfos.get(instance_id);
|
||||||
if (instanceInfo) {
|
if (instanceInfo) {
|
||||||
instanceInfo.config.update(serialized_config, true, "master");
|
instanceInfo.config.update(serialized_config, true, "controller");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
let instanceConfig = new libConfig.InstanceConfig("slave");
|
let instanceConfig = new libConfig.InstanceConfig("host");
|
||||||
await instanceConfig.load(serialized_config, "master");
|
await instanceConfig.load(serialized_config, "controller");
|
||||||
|
|
||||||
let instanceDir = await this._createNewInstanceDir(instanceConfig.get("instance.name"));
|
let instanceDir = await this._createNewInstanceDir(instanceConfig.get("instance.name"));
|
||||||
|
|
||||||
logger.info(`Creating ${instanceDir}`);
|
logger.info(`Creating ${instanceDir}`);
|
||||||
await Instance.create(instanceDir, this.config.get("slave.factorio_directory"));
|
await Instance.create(instanceDir, this.config.get("host.factorio_directory"));
|
||||||
instanceInfo = {
|
instanceInfo = {
|
||||||
path: instanceDir,
|
path: instanceDir,
|
||||||
config: instanceConfig,
|
config: instanceConfig,
|
||||||
@@ -335,8 +335,8 @@ class Slave extends libLink.Link {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Somewhat hacky, but in the event of a lost session the status is
|
// Somewhat hacky, but in the event of a lost session the status is
|
||||||
// resent on assigment since the master server sends an assigment
|
// resent on assigment since the controller sends an assigment
|
||||||
// request for all the instances it knows should be on this slave.
|
// request for all the instances it knows should be on this host.
|
||||||
let instanceConnection = this.instanceConnections.get(instance_id);
|
let instanceConnection = this.instanceConnections.get(instance_id);
|
||||||
libLink.messages.instanceStatusChanged.send(this, {
|
libLink.messages.instanceStatusChanged.send(this, {
|
||||||
instance_id,
|
instance_id,
|
||||||
@@ -345,7 +345,7 @@ class Slave extends libLink.Link {
|
|||||||
|
|
||||||
// save a copy of the instance config
|
// save a copy of the instance config
|
||||||
let warnedOutput = {
|
let warnedOutput = {
|
||||||
_warning: "Changes to this file will be overwritten by the master server's copy.",
|
_warning: "Changes to this file will be overwritten by the controller's copy.",
|
||||||
...instanceInfo.config.serialize(),
|
...instanceInfo.config.serialize(),
|
||||||
};
|
};
|
||||||
await libFileOps.safeOutputFile(
|
await libFileOps.safeOutputFile(
|
||||||
@@ -388,7 +388,7 @@ class Slave extends libLink.Link {
|
|||||||
* Initialize and connect an unloaded instance
|
* Initialize and connect an unloaded instance
|
||||||
*
|
*
|
||||||
* @param {number} instanceId - ID of instance to initialize.
|
* @param {number} instanceId - ID of instance to initialize.
|
||||||
* @returns {Promise<module:slave/slave~InstanceConnection>} connection to instance.
|
* @returns {Promise<module:host/host~InstanceConnection>} connection to instance.
|
||||||
*/
|
*/
|
||||||
async _connectInstance(instanceId) {
|
async _connectInstance(instanceId) {
|
||||||
let instanceInfo = this.getRequestInstanceInfo(instanceId);
|
let instanceInfo = this.getRequestInstanceInfo(instanceId);
|
||||||
@@ -399,7 +399,7 @@ class Slave extends libLink.Link {
|
|||||||
let [connectionClient, connectionServer] = libLink.VirtualConnector.makePair();
|
let [connectionClient, connectionServer] = libLink.VirtualConnector.makePair();
|
||||||
let instanceConnection = new InstanceConnection(connectionServer, this, instanceId);
|
let instanceConnection = new InstanceConnection(connectionServer, this, instanceId);
|
||||||
let instance = new Instance(
|
let instance = new Instance(
|
||||||
this, connectionClient, instanceInfo.path, this.config.get("slave.factorio_directory"), instanceInfo.config
|
this, connectionClient, instanceInfo.path, this.config.get("host.factorio_directory"), instanceInfo.config
|
||||||
);
|
);
|
||||||
|
|
||||||
this.instanceConnections.set(instanceId, instanceConnection);
|
this.instanceConnections.set(instanceId, instanceConnection);
|
||||||
@@ -422,8 +422,8 @@ class Slave extends libLink.Link {
|
|||||||
for await (let result of libPrometheus.defaultRegistry.collect()) {
|
for await (let result of libPrometheus.defaultRegistry.collect()) {
|
||||||
if (result.metric.name.startsWith("process_")) {
|
if (result.metric.name.startsWith("process_")) {
|
||||||
results.push(libPrometheus.serializeResult(result, {
|
results.push(libPrometheus.serializeResult(result, {
|
||||||
addLabels: { "slave_id": String(this.config.get("slave.id")) },
|
addLabels: { "host_id": String(this.config.get("host.id")) },
|
||||||
metricName: result.metric.name.replace("process_", "clusterio_slave_"),
|
metricName: result.metric.name.replace("process_", "clusterio_host_"),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -601,7 +601,7 @@ class Slave extends libLink.Link {
|
|||||||
checkRequestSaveName(filename);
|
checkRequestSaveName(filename);
|
||||||
let instanceInfo = this.getRequestInstanceInfo(instance_id);
|
let instanceInfo = this.getRequestInstanceInfo(instance_id);
|
||||||
|
|
||||||
let url = new URL(this.config.get("slave.master_url"));
|
let url = new URL(this.config.get("host.controller_url"));
|
||||||
url.pathname += `api/stream/${stream_id}`;
|
url.pathname += `api/stream/${stream_id}`;
|
||||||
let response = await phin({
|
let response = await phin({
|
||||||
url, method: "GET",
|
url, method: "GET",
|
||||||
@@ -656,13 +656,15 @@ class Slave extends libLink.Link {
|
|||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
let url = new URL(this.config.get("slave.master_url"));
|
let url = new URL(this.config.get("host.controller_url"));
|
||||||
url.pathname += `api/stream/${stream_id}`;
|
url.pathname += `api/stream/${stream_id}`;
|
||||||
phin({
|
phin({
|
||||||
url, method: "PUT",
|
url, method: "PUT",
|
||||||
core: { ca: this.tlsCa },
|
core: { ca: this.tlsCa },
|
||||||
data: content,
|
data: content,
|
||||||
}).catch(err => logger.error(`Error pushing save to master:\n${err.stack}`, this.instanceLogMeta(instance_id)));
|
}).catch(err => {
|
||||||
|
logger.error(`Error pushing save to controller:\n${err.stack}`, this.instanceLogMeta(instance_id));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async exportDataRequestHandler(message, request) {
|
async exportDataRequestHandler(message, request) {
|
||||||
@@ -704,15 +706,15 @@ class Slave extends libLink.Link {
|
|||||||
* Discover available instances
|
* Discover available instances
|
||||||
*
|
*
|
||||||
* Looks through the instances directory for instances and updates
|
* Looks through the instances directory for instances and updates
|
||||||
* the slave and master server with the new list of instances.
|
* the host and controller with the new list of instances.
|
||||||
*/
|
*/
|
||||||
async updateInstances() {
|
async updateInstances() {
|
||||||
this.discoveredInstanceInfos = await discoverInstances(this.config.get("slave.instances_directory"));
|
this.discoveredInstanceInfos = await discoverInstances(this.config.get("host.instances_directory"));
|
||||||
let list = [];
|
let list = [];
|
||||||
for (let [instanceId, instanceInfo] of this.discoveredInstanceInfos) {
|
for (let [instanceId, instanceInfo] of this.discoveredInstanceInfos) {
|
||||||
let instanceConnection = this.instanceConnections.get(instanceId);
|
let instanceConnection = this.instanceConnections.get(instanceId);
|
||||||
list.push({
|
list.push({
|
||||||
serialized_config: instanceInfo.config.serialize("master"),
|
serialized_config: instanceInfo.config.serialize("controller"),
|
||||||
status: instanceConnection ? instanceConnection.status : "stopped",
|
status: instanceConnection ? instanceConnection.status : "stopped",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -743,7 +745,7 @@ class Slave extends libLink.Link {
|
|||||||
|
|
||||||
async prepareDisconnectRequestHandler(message, request) {
|
async prepareDisconnectRequestHandler(message, request) {
|
||||||
for (let instanceConnection of this.instanceConnections.values()) {
|
for (let instanceConnection of this.instanceConnections.values()) {
|
||||||
await libLink.messages.prepareMasterDisconnect.send(instanceConnection);
|
await libLink.messages.prepareControllerDisconnect.send(instanceConnection);
|
||||||
}
|
}
|
||||||
this._disconnecting = true;
|
this._disconnecting = true;
|
||||||
this.connector.setClosing();
|
this.connector.setClosing();
|
||||||
@@ -771,7 +773,7 @@ class Slave extends libLink.Link {
|
|||||||
for (let instanceId of this.instanceConnections.keys()) {
|
for (let instanceId of this.instanceConnections.keys()) {
|
||||||
await this.stopInstance(instanceId);
|
await this.stopInstance(instanceId);
|
||||||
}
|
}
|
||||||
await this.connector.close(1000, "Slave Shutdown");
|
await this.connector.close(1000, "Host Shutdown");
|
||||||
|
|
||||||
// Clear silly interval in pidfile library.
|
// Clear silly interval in pidfile library.
|
||||||
pidusage.clear();
|
pidusage.clear();
|
||||||
@@ -779,7 +781,7 @@ class Slave extends libLink.Link {
|
|||||||
setBlocking(true);
|
setBlocking(true);
|
||||||
logger.error(`
|
logger.error(`
|
||||||
+------------------------------------------------------------+
|
+------------------------------------------------------------+
|
||||||
| Unexpected error occured while shutting down slave, please |
|
| Unexpected error occured while shutting down host, please |
|
||||||
| report it to https://github.com/clusterio/clusterio/issues |
|
| report it to https://github.com/clusterio/clusterio/issues |
|
||||||
+------------------------------------------------------------+
|
+------------------------------------------------------------+
|
||||||
${err.stack}`
|
${err.stack}`
|
||||||
@@ -790,7 +792,7 @@ ${err.stack}`
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True if the connection to the master is connected, not in the dropped
|
* True if the connection to the controller is connected, not in the dropped
|
||||||
* state,and not in the process of disconnecting.
|
* state,and not in the process of disconnecting.
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
*/
|
*/
|
||||||
@@ -799,7 +801,7 @@ ${err.stack}`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Slave;
|
module.exports = Host;
|
||||||
|
|
||||||
// For testing only
|
// For testing only
|
||||||
module.exports._discoverInstances = discoverInstances;
|
module.exports._discoverInstances = discoverInstances;
|
||||||
@@ -98,13 +98,13 @@ const serverSettingsActions = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Keeps track of the runtime parameters of an instance
|
* Keeps track of the runtime parameters of an instance
|
||||||
* @alias module:slave/src/Instance
|
* @alias module:host/src/Instance
|
||||||
*/
|
*/
|
||||||
class Instance extends libLink.Link {
|
class Instance extends libLink.Link {
|
||||||
constructor(slave, connector, dir, factorioDir, instanceConfig) {
|
constructor(host, connector, dir, factorioDir, instanceConfig) {
|
||||||
super("instance", "slave", connector);
|
super("instance", "host", connector);
|
||||||
libLink.attachAllMessages(this);
|
libLink.attachAllMessages(this);
|
||||||
this._slave = slave;
|
this._host = host;
|
||||||
this._dir = dir;
|
this._dir = dir;
|
||||||
|
|
||||||
this.plugins = new Map();
|
this.plugins = new Map();
|
||||||
@@ -461,10 +461,10 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
|||||||
this._saveStats().catch(err => this.logger.error(`Error saving stats:\n${err.stack}`));
|
this._saveStats().catch(err => this.logger.error(`Error saving stats:\n${err.stack}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
async _loadPlugin(pluginInfo, slave) {
|
async _loadPlugin(pluginInfo, host) {
|
||||||
let pluginLoadStarted = Date.now();
|
let pluginLoadStarted = Date.now();
|
||||||
let InstancePluginClass = await libPluginLoader.loadInstancePluginClass(pluginInfo);
|
let InstancePluginClass = await libPluginLoader.loadInstancePluginClass(pluginInfo);
|
||||||
let instancePlugin = new InstancePluginClass(pluginInfo, this, slave);
|
let instancePlugin = new InstancePluginClass(pluginInfo, this, host);
|
||||||
this.plugins.set(pluginInfo.name, instancePlugin);
|
this.plugins.set(pluginInfo.name, instancePlugin);
|
||||||
await instancePlugin.init();
|
await instancePlugin.init();
|
||||||
libPlugin.attachPluginMessages(this, instancePlugin);
|
libPlugin.attachPluginMessages(this, instancePlugin);
|
||||||
@@ -509,14 +509,14 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
|||||||
for (let pluginInfo of pluginInfos) {
|
for (let pluginInfo of pluginInfos) {
|
||||||
if (
|
if (
|
||||||
!pluginInfo.instanceEntrypoint
|
!pluginInfo.instanceEntrypoint
|
||||||
|| !this._slave.serverPlugins.has(pluginInfo.name)
|
|| !this._host.serverPlugins.has(pluginInfo.name)
|
||||||
|| !this.config.group(pluginInfo.name).get("load_plugin")
|
|| !this.config.group(pluginInfo.name).get("load_plugin")
|
||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this._loadPlugin(pluginInfo, this._slave);
|
await this._loadPlugin(pluginInfo, this._host);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.notifyExit();
|
this.notifyExit();
|
||||||
await this.sendSaveListUpdate();
|
await this.sendSaveListUpdate();
|
||||||
@@ -593,7 +593,7 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
|||||||
* a vanilla mods folder. If the instance mods directory does't exist
|
* a vanilla mods folder. If the instance mods directory does't exist
|
||||||
* then it will be created.
|
* then it will be created.
|
||||||
*
|
*
|
||||||
* On Linux this creates symlinks to mods in the slave's mods folder, on
|
* On Linux this creates symlinks to mods in the host's mods folder, on
|
||||||
* Windows hard links are used instead due to symlinks being privileged.
|
* Windows hard links are used instead due to symlinks being privileged.
|
||||||
*/
|
*/
|
||||||
async syncMods() {
|
async syncMods() {
|
||||||
@@ -608,7 +608,7 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
|||||||
|
|
||||||
// TODO validate factorioVersion
|
// TODO validate factorioVersion
|
||||||
|
|
||||||
if (!this._slave.config.get("slave.mods_directory_is_shared")) {
|
if (!this._host.config.get("host.mods_directory_is_shared")) {
|
||||||
throw new Error("Fetching mods is not implemented");
|
throw new Error("Fetching mods is not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -629,7 +629,7 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add mods from mod the pack
|
// Add mods from mod the pack
|
||||||
const modsDir = this._slave.config.get("slave.mods_directory");
|
const modsDir = this._host.config.get("host.mods_directory");
|
||||||
for (let mod of this.activeModPack.mods.values()) {
|
for (let mod of this.activeModPack.mods.values()) {
|
||||||
const modFile = `${mod.name}_${mod.version}.zip`;
|
const modFile = `${mod.name}_${mod.version}.zip`;
|
||||||
const target = path.join(modsDir, modFile);
|
const target = path.join(modsDir, modFile);
|
||||||
@@ -668,7 +668,7 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
|||||||
this.logger.verbose("Writing server-adminlist.json");
|
this.logger.verbose("Writing server-adminlist.json");
|
||||||
libFileOps.safeOutputFile(
|
libFileOps.safeOutputFile(
|
||||||
this.server.writePath("server-adminlist.json"),
|
this.server.writePath("server-adminlist.json"),
|
||||||
JSON.stringify([...this._slave.adminlist], null, 4)
|
JSON.stringify([...this._host.adminlist], null, 4)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -676,7 +676,7 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
|||||||
this.logger.verbose("Writing server-banlist.json");
|
this.logger.verbose("Writing server-banlist.json");
|
||||||
libFileOps.safeOutputFile(
|
libFileOps.safeOutputFile(
|
||||||
this.server.writePath("server-banlist.json"),
|
this.server.writePath("server-banlist.json"),
|
||||||
JSON.stringify([...this._slave.banlist].map(
|
JSON.stringify([...this._host.banlist].map(
|
||||||
([username, reason]) => ({ username, reason })
|
([username, reason]) => ({ username, reason })
|
||||||
), null, 4),
|
), null, 4),
|
||||||
);
|
);
|
||||||
@@ -686,7 +686,7 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
|||||||
this.logger.verbose("Writing server-whitelist.json");
|
this.logger.verbose("Writing server-whitelist.json");
|
||||||
libFileOps.safeOutputFile(
|
libFileOps.safeOutputFile(
|
||||||
this.server.writePath("server-whitelist.json"),
|
this.server.writePath("server-whitelist.json"),
|
||||||
JSON.stringify([...this._slave.whitelist], null, 4)
|
JSON.stringify([...this._host.whitelist], null, 4)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -897,7 +897,7 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
|||||||
|
|
||||||
if (this.config.get("factorio.sync_whitelist")) {
|
if (this.config.get("factorio.sync_whitelist")) {
|
||||||
await this.sendRcon("/whitelist clear");
|
await this.sendRcon("/whitelist clear");
|
||||||
for (let player of this._slave.whitelist) {
|
for (let player of this._host.whitelist) {
|
||||||
await this.sendRcon(`/whitelist ${player}`);
|
await this.sendRcon(`/whitelist ${player}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -962,12 +962,12 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
|||||||
await this.server.kill(true);
|
await this.server.kill(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async masterConnectionEventEventHandler(message) {
|
async controllerConnectionEventEventHandler(message) {
|
||||||
await libPlugin.invokeHook(this.plugins, "onMasterConnectionEvent", message.data.event);
|
await libPlugin.invokeHook(this.plugins, "onControllerConnectionEvent", message.data.event);
|
||||||
}
|
}
|
||||||
|
|
||||||
async prepareMasterDisconnectRequestHandler() {
|
async prepareControllerDisconnectRequestHandler() {
|
||||||
await libPlugin.invokeHook(this.plugins, "onPrepareMasterDisconnect");
|
await libPlugin.invokeHook(this.plugins, "onPrepareControllerDisconnect");
|
||||||
}
|
}
|
||||||
|
|
||||||
async getMetricsRequestHandler() {
|
async getMetricsRequestHandler() {
|
||||||
@@ -1072,16 +1072,16 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
|
|||||||
let zip = await libFactorio.exportData(this.server);
|
let zip = await libFactorio.exportData(this.server);
|
||||||
|
|
||||||
let content = await zip.generateAsync({ type: "nodebuffer" });
|
let content = await zip.generateAsync({ type: "nodebuffer" });
|
||||||
let url = new URL(this._slave.config.get("slave.master_url"));
|
let url = new URL(this._host.config.get("host.controller_url"));
|
||||||
url.pathname += "api/upload-export";
|
url.pathname += "api/upload-export";
|
||||||
url.searchParams.set("mod_pack_id", this.activeModPack.id);
|
url.searchParams.set("mod_pack_id", this.activeModPack.id);
|
||||||
let response = await phin({
|
let response = await phin({
|
||||||
url, method: "PUT",
|
url, method: "PUT",
|
||||||
data: content,
|
data: content,
|
||||||
core: { ca: this._slave.tlsCa },
|
core: { ca: this._host.tlsCa },
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/zip",
|
"Content-Type": "application/zip",
|
||||||
"x-access-token": this._slave.config.get("slave.master_token"),
|
"x-access-token": this._host.config.get("host.controller_token"),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (response.statusCode !== 200) {
|
if (response.statusCode !== 200) {
|
||||||
+18
-18
@@ -5,29 +5,29 @@ const libErrors = require("@clusterio/lib/errors");
|
|||||||
|
|
||||||
|
|
||||||
class InstanceConnection extends libLink.Link {
|
class InstanceConnection extends libLink.Link {
|
||||||
constructor(connector, slave, instanceId) {
|
constructor(connector, host, instanceId) {
|
||||||
super("slave", "instance", connector);
|
super("host", "instance", connector);
|
||||||
this.slave = slave;
|
this.host = host;
|
||||||
this.instanceId = instanceId;
|
this.instanceId = instanceId;
|
||||||
this.plugins = new Map();
|
this.plugins = new Map();
|
||||||
this.status = "stopped";
|
this.status = "stopped";
|
||||||
libLink.attachAllMessages(this);
|
libLink.attachAllMessages(this);
|
||||||
|
|
||||||
for (let pluginInfo of slave.pluginInfos) {
|
for (let pluginInfo of host.pluginInfos) {
|
||||||
libPlugin.attachPluginMessages(this, { info: pluginInfo });
|
libPlugin.attachPluginMessages(this, { info: pluginInfo });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async forwardRequestToMaster(message, request) {
|
async forwardRequestToController(message, request) {
|
||||||
return await request.send(this.slave, message.data);
|
return await request.send(this.host, message.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
async forwardRequestToInstance(message, request) {
|
async forwardRequestToInstance(message, request) {
|
||||||
let instanceId = message.data.instance_id;
|
let instanceId = message.data.instance_id;
|
||||||
let instanceConnection = this.slave.instanceConnections.get(instanceId);
|
let instanceConnection = this.host.instanceConnections.get(instanceId);
|
||||||
if (!instanceConnection) {
|
if (!instanceConnection) {
|
||||||
// Instance is probably on another slave
|
// Instance is probably on another host
|
||||||
return await this.forwardRequestToMaster(message, request);
|
return await this.forwardRequestToController(message, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.plugin && !instanceConnection.plugins.has(request.plugin)) {
|
if (request.plugin && !instanceConnection.plugins.has(request.plugin)) {
|
||||||
@@ -40,10 +40,10 @@ class InstanceConnection extends libLink.Link {
|
|||||||
|
|
||||||
async forwardEventToInstance(message, event) {
|
async forwardEventToInstance(message, event) {
|
||||||
let instanceId = message.data.instance_id;
|
let instanceId = message.data.instance_id;
|
||||||
let instanceConnection = this.slave.instanceConnections.get(instanceId);
|
let instanceConnection = this.host.instanceConnections.get(instanceId);
|
||||||
if (!instanceConnection) {
|
if (!instanceConnection) {
|
||||||
// Instance is probably on another slave
|
// Instance is probably on another host
|
||||||
await this.forwardEventToMaster(message, event);
|
await this.forwardEventToController(message, event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.plugin && !instanceConnection.plugins.has(event.plugin)) { return; }
|
if (event.plugin && !instanceConnection.plugins.has(event.plugin)) { return; }
|
||||||
@@ -51,16 +51,16 @@ class InstanceConnection extends libLink.Link {
|
|||||||
event.send(instanceConnection, message.data);
|
event.send(instanceConnection, message.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
async forwardEventToMaster(message, event) {
|
async forwardEventToController(message, event) {
|
||||||
if (!this.slave.connector.hasSession) {
|
if (!this.host.connector.hasSession) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.send(this.slave, message.data);
|
event.send(this.host, message.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
async broadcastEventToInstance(message, event) {
|
async broadcastEventToInstance(message, event) {
|
||||||
for (let instanceConnection of this.slave.instanceConnections.values()) {
|
for (let instanceConnection of this.host.instanceConnections.values()) {
|
||||||
// Do not broadcast back to the source
|
// Do not broadcast back to the source
|
||||||
if (instanceConnection === this) { continue; }
|
if (instanceConnection === this) { continue; }
|
||||||
if (event.plugin && !instanceConnection.plugins.has(event.plugin)) { continue; }
|
if (event.plugin && !instanceConnection.plugins.has(event.plugin)) { continue; }
|
||||||
@@ -76,9 +76,9 @@ class InstanceConnection extends libLink.Link {
|
|||||||
async instanceStatusChangedEventHandler(message, event) {
|
async instanceStatusChangedEventHandler(message, event) {
|
||||||
this.status = message.data.status;
|
this.status = message.data.status;
|
||||||
if (this.status === "stopped") {
|
if (this.status === "stopped") {
|
||||||
this.slave.instanceConnections.delete(this.instanceId);
|
this.host.instanceConnections.delete(this.instanceId);
|
||||||
}
|
}
|
||||||
this.forwardEventToMaster(message, event);
|
this.forwardEventToController(message, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# Common Library for Clusterio
|
# Common Library for Clusterio
|
||||||
|
|
||||||
This package contains functionality shared between master, 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.
|
See [the Clusterio repository](https://github.com/clusterio/clusterio) for more information on Clusterio.
|
||||||
+21
-21
@@ -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
|
* Resolves a string with either an host name or an id into an integer with
|
||||||
* the slave ID.
|
* the host ID.
|
||||||
*
|
*
|
||||||
* @param {module:lib/link.Link} client - link to master server to query slave on.
|
* @param {module:lib/link.Link} client - link to controller to query host on.
|
||||||
* @param {string} slaveName - string with name or id of slave.
|
* @param {string} hostName - string with name or id of host.
|
||||||
* @returns {Promise<number>} slave ID.
|
* @returns {Promise<number>} host ID.
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
async function resolveSlave(client, slaveName) {
|
async function resolveHost(client, hostName) {
|
||||||
let slaveId;
|
let hostId;
|
||||||
if (/^-?\d+$/.test(slaveName)) {
|
if (/^-?\d+$/.test(hostName)) {
|
||||||
slaveId = parseInt(slaveName, 10);
|
hostId = parseInt(hostName, 10);
|
||||||
} else {
|
} else {
|
||||||
let response = await libLink.messages.listSlaves.send(client);
|
let response = await libLink.messages.listHosts.send(client);
|
||||||
for (let slave of response.list) {
|
for (let host of response.list) {
|
||||||
if (slave.name === slaveName) {
|
if (host.name === hostName) {
|
||||||
slaveId = slave.id;
|
hostId = host.id;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slaveId === undefined) {
|
if (hostId === undefined) {
|
||||||
throw new libErrors.CommandError(`No slave named ${slaveName}`);
|
throw new libErrors.CommandError(`No host named ${hostName}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return slaveId;
|
return hostId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -172,7 +172,7 @@ async function resolveSlave(client, slaveName) {
|
|||||||
* Resolves a string with either an instance name or an id into an integer
|
* Resolves a string with either an instance name or an id into an integer
|
||||||
* with the instance ID.
|
* with the instance ID.
|
||||||
*
|
*
|
||||||
* @param {module:lib/link.Link} client - link to master server to query instance on.
|
* @param {module:lib/link.Link} client - link to controller to query instance on.
|
||||||
* @param {string} instanceName - string with name or id of instance.
|
* @param {string} instanceName - string with name or id of instance.
|
||||||
* @returns {Promise<number>} instance ID.
|
* @returns {Promise<number>} instance ID.
|
||||||
* @static
|
* @static
|
||||||
@@ -205,7 +205,7 @@ async function resolveInstance(client, instanceName) {
|
|||||||
* with the mod pack ID.
|
* with the mod pack ID.
|
||||||
*
|
*
|
||||||
* @param {module:lib/link.Link} client -
|
* @param {module:lib/link.Link} client -
|
||||||
* link to master server to query mod pack on.
|
* link to controller to query mod pack on.
|
||||||
* @param {string} modPackName - string with name or id of mod pack.
|
* @param {string} modPackName - string with name or id of mod pack.
|
||||||
* @returns {Promise<number>} mod pack ID.
|
* @returns {Promise<number>} mod pack ID.
|
||||||
* @static
|
* @static
|
||||||
@@ -237,7 +237,7 @@ async function resolveModPack(client, modPackName) {
|
|||||||
* Resolves a string with either a role name or an id into an object
|
* Resolves a string with either a role name or an id into an object
|
||||||
* representing the role.
|
* representing the role.
|
||||||
*
|
*
|
||||||
* @param {module:lib/link.Link} client - link to master server to query role on.
|
* @param {module:lib/link.Link} client - link to controller to query role on.
|
||||||
* @param {string} roleName - string with name or id of role.
|
* @param {string} roleName - string with name or id of role.
|
||||||
* @returns {Promise<object>} Role info.
|
* @returns {Promise<object>} Role info.
|
||||||
* @static
|
* @static
|
||||||
@@ -275,7 +275,7 @@ module.exports = {
|
|||||||
Command,
|
Command,
|
||||||
CommandTree,
|
CommandTree,
|
||||||
|
|
||||||
resolveSlave,
|
resolveHost,
|
||||||
resolveInstance,
|
resolveInstance,
|
||||||
resolveModPack,
|
resolveModPack,
|
||||||
retrieveRole,
|
retrieveRole,
|
||||||
|
|||||||
@@ -5,35 +5,35 @@ const classes = require("./classes");
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Master config group for {@link module:lib/config.MasterConfig}
|
* Controller config group for {@link module:lib/config.ControllerConfig}
|
||||||
* @extends module:lib/config.ConfigGroup
|
* @extends module:lib/config.ConfigGroup
|
||||||
* @memberof module:lib/config
|
* @memberof module:lib/config
|
||||||
*/
|
*/
|
||||||
class MasterGroup extends classes.ConfigGroup { }
|
class ControllerGroup extends classes.ConfigGroup { }
|
||||||
MasterGroup.defaultAccess = ["master", "slave", "control"];
|
ControllerGroup.defaultAccess = ["controller", "host", "control"];
|
||||||
MasterGroup.groupName = "master";
|
ControllerGroup.groupName = "controller";
|
||||||
MasterGroup.define({
|
ControllerGroup.define({
|
||||||
name: "name",
|
name: "name",
|
||||||
title: "Name",
|
title: "Name",
|
||||||
description: "Name of the cluster.",
|
description: "Name of the cluster.",
|
||||||
type: "string",
|
type: "string",
|
||||||
initial_value: "Your Cluster",
|
initial_value: "Your Cluster",
|
||||||
});
|
});
|
||||||
MasterGroup.define({
|
ControllerGroup.define({
|
||||||
name: "mods_directory",
|
name: "mods_directory",
|
||||||
title: "Mods Directory",
|
title: "Mods Directory",
|
||||||
description: "Path to directory where mods shared with the cluster are stored.",
|
description: "Path to directory where mods shared with the cluster are stored.",
|
||||||
type: "string",
|
type: "string",
|
||||||
initial_value: "mods",
|
initial_value: "mods",
|
||||||
});
|
});
|
||||||
MasterGroup.define({
|
ControllerGroup.define({
|
||||||
name: "database_directory",
|
name: "database_directory",
|
||||||
title: "Database directory",
|
title: "Database directory",
|
||||||
description: "Directory where item and configuration data is stored.",
|
description: "Directory where item and configuration data is stored.",
|
||||||
type: "string",
|
type: "string",
|
||||||
initial_value: "database",
|
initial_value: "database",
|
||||||
});
|
});
|
||||||
MasterGroup.define({
|
ControllerGroup.define({
|
||||||
name: "http_port",
|
name: "http_port",
|
||||||
title: "HTTP Port",
|
title: "HTTP Port",
|
||||||
description: "Port to listen for HTTP connections on, set to null to not listen for HTTP connections.",
|
description: "Port to listen for HTTP connections on, set to null to not listen for HTTP connections.",
|
||||||
@@ -42,7 +42,7 @@ MasterGroup.define({
|
|||||||
optional: true,
|
optional: true,
|
||||||
initial_value: 8080,
|
initial_value: 8080,
|
||||||
});
|
});
|
||||||
MasterGroup.define({
|
ControllerGroup.define({
|
||||||
name: "https_port",
|
name: "https_port",
|
||||||
title: "HTTPS Port",
|
title: "HTTPS Port",
|
||||||
description: "Port to listen for HTTPS connection on, set to null to not listen for HTTPS connections.",
|
description: "Port to listen for HTTPS connection on, set to null to not listen for HTTPS connections.",
|
||||||
@@ -50,7 +50,7 @@ MasterGroup.define({
|
|||||||
type: "number",
|
type: "number",
|
||||||
optional: true,
|
optional: true,
|
||||||
});
|
});
|
||||||
MasterGroup.define({
|
ControllerGroup.define({
|
||||||
name: "bind_address",
|
name: "bind_address",
|
||||||
title: "Bind Address",
|
title: "Bind Address",
|
||||||
description: "IP address to bind the HTTP and HTTPS ports on.",
|
description: "IP address to bind the HTTP and HTTPS ports on.",
|
||||||
@@ -58,14 +58,14 @@ MasterGroup.define({
|
|||||||
type: "string",
|
type: "string",
|
||||||
optional: true,
|
optional: true,
|
||||||
});
|
});
|
||||||
MasterGroup.define({
|
ControllerGroup.define({
|
||||||
name: "external_address",
|
name: "external_address",
|
||||||
title: "External Address",
|
title: "External Address",
|
||||||
description: "Public facing address the master server is hosted on.",
|
description: "Public facing address the controller is hosted on.",
|
||||||
type: "string",
|
type: "string",
|
||||||
optional: true,
|
optional: true,
|
||||||
});
|
});
|
||||||
MasterGroup.define({
|
ControllerGroup.define({
|
||||||
name: "tls_certificate",
|
name: "tls_certificate",
|
||||||
title: "TLS Certificate",
|
title: "TLS Certificate",
|
||||||
description: "Path to the certificate to use for HTTPS.",
|
description: "Path to the certificate to use for HTTPS.",
|
||||||
@@ -73,7 +73,7 @@ MasterGroup.define({
|
|||||||
type: "string",
|
type: "string",
|
||||||
optional: true,
|
optional: true,
|
||||||
});
|
});
|
||||||
MasterGroup.define({
|
ControllerGroup.define({
|
||||||
name: "tls_private_key",
|
name: "tls_private_key",
|
||||||
title: "TLS Private Key",
|
title: "TLS Private Key",
|
||||||
description: "Path to the private key to use for HTTPS.",
|
description: "Path to the private key to use for HTTPS.",
|
||||||
@@ -81,10 +81,10 @@ MasterGroup.define({
|
|||||||
type: "string",
|
type: "string",
|
||||||
optional: true,
|
optional: true,
|
||||||
});
|
});
|
||||||
MasterGroup.define({
|
ControllerGroup.define({
|
||||||
access: ["master"],
|
access: ["controller"],
|
||||||
name: "auth_secret",
|
name: "auth_secret",
|
||||||
title: "Master Authentication Secret",
|
title: "Controller Authentication Secret",
|
||||||
description:
|
description:
|
||||||
"Secret used to generate and verify authentication tokens. " +
|
"Secret used to generate and verify authentication tokens. " +
|
||||||
"Should be a long string of random letters and numbers. " +
|
"Should be a long string of random letters and numbers. " +
|
||||||
@@ -93,42 +93,42 @@ MasterGroup.define({
|
|||||||
type: "string",
|
type: "string",
|
||||||
optional: true,
|
optional: true,
|
||||||
});
|
});
|
||||||
MasterGroup.define({
|
ControllerGroup.define({
|
||||||
name: "heartbeat_interval",
|
name: "heartbeat_interval",
|
||||||
title: "Heartbeat Interval",
|
title: "Heartbeat Interval",
|
||||||
description: "Interval heartbeats are sent out on WebSocket connections.",
|
description: "Interval heartbeats are sent out on WebSocket connections.",
|
||||||
type: "number",
|
type: "number",
|
||||||
initial_value: 15,
|
initial_value: 15,
|
||||||
});
|
});
|
||||||
MasterGroup.define({
|
ControllerGroup.define({
|
||||||
name: "session_timeout",
|
name: "session_timeout",
|
||||||
title: "Session Timeout",
|
title: "Session Timeout",
|
||||||
description: "Time in seconds before giving up resuming a dropped WebSocket session.",
|
description: "Time in seconds before giving up resuming a dropped WebSocket session.",
|
||||||
type: "number",
|
type: "number",
|
||||||
initial_value: 60,
|
initial_value: 60,
|
||||||
});
|
});
|
||||||
MasterGroup.define({
|
ControllerGroup.define({
|
||||||
name: "metrics_timeout",
|
name: "metrics_timeout",
|
||||||
title: "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",
|
type: "number",
|
||||||
initial_value: 8,
|
initial_value: 8,
|
||||||
});
|
});
|
||||||
MasterGroup.define({
|
ControllerGroup.define({
|
||||||
name: "proxy_stream_timeout",
|
name: "proxy_stream_timeout",
|
||||||
title: "Proxy Stream Timeout",
|
title: "Proxy Stream Timeout",
|
||||||
description: "Timeout in seconds for proxy streams to start flowing.",
|
description: "Timeout in seconds for proxy streams to start flowing.",
|
||||||
type: "number",
|
type: "number",
|
||||||
initial_value: 15,
|
initial_value: 15,
|
||||||
});
|
});
|
||||||
MasterGroup.define({
|
ControllerGroup.define({
|
||||||
name: "default_mod_pack_id",
|
name: "default_mod_pack_id",
|
||||||
title: "Default Mod Pack",
|
title: "Default Mod Pack",
|
||||||
description: "Mod pack used by default for instances.",
|
description: "Mod pack used by default for instances.",
|
||||||
type: "number",
|
type: "number",
|
||||||
optional: true,
|
optional: true,
|
||||||
});
|
});
|
||||||
MasterGroup.define({
|
ControllerGroup.define({
|
||||||
name: "default_role_id",
|
name: "default_role_id",
|
||||||
title: "Default role",
|
title: "Default role",
|
||||||
description: "ID of role assigned by default to new users.",
|
description: "ID of role assigned by default to new users.",
|
||||||
@@ -136,107 +136,107 @@ MasterGroup.define({
|
|||||||
optional: true,
|
optional: true,
|
||||||
initial_value: 1,
|
initial_value: 1,
|
||||||
});
|
});
|
||||||
MasterGroup.finalize();
|
ControllerGroup.finalize();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Master Config class
|
* Controller Config class
|
||||||
* @extends module:lib/config.Config
|
* @extends module:lib/config.Config
|
||||||
* @memberof module:lib/config
|
* @memberof module:lib/config
|
||||||
*/
|
*/
|
||||||
class MasterConfig extends classes.Config { }
|
class ControllerConfig extends classes.Config { }
|
||||||
MasterConfig.registerGroup(MasterGroup);
|
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
|
* @extends module:lib/config.ConfigGroup
|
||||||
* @memberof module:lib/config
|
* @memberof module:lib/config
|
||||||
*/
|
*/
|
||||||
class SlaveGroup extends classes.ConfigGroup {}
|
class HostGroup extends classes.ConfigGroup {}
|
||||||
SlaveGroup.defaultAccess = ["master", "slave", "control"];
|
HostGroup.defaultAccess = ["controller", "host", "control"];
|
||||||
SlaveGroup.groupName = "slave";
|
HostGroup.groupName = "host";
|
||||||
SlaveGroup.define({
|
HostGroup.define({
|
||||||
name: "name",
|
name: "name",
|
||||||
description: "Name of the slave",
|
description: "Name of the host",
|
||||||
type: "string",
|
type: "string",
|
||||||
initial_value: "New Slave",
|
initial_value: "New Host",
|
||||||
});
|
});
|
||||||
SlaveGroup.define({
|
HostGroup.define({
|
||||||
name: "id",
|
name: "id",
|
||||||
description: "ID of the slave",
|
description: "ID of the host",
|
||||||
type: "number",
|
type: "number",
|
||||||
initial_value: () => Math.random() * 2**31 | 0,
|
initial_value: () => Math.random() * 2**31 | 0,
|
||||||
});
|
});
|
||||||
SlaveGroup.define({
|
HostGroup.define({
|
||||||
name: "factorio_directory",
|
name: "factorio_directory",
|
||||||
description: "Path to directory to look for factorio installs",
|
description: "Path to directory to look for factorio installs",
|
||||||
type: "string",
|
type: "string",
|
||||||
initial_value: "factorio",
|
initial_value: "factorio",
|
||||||
});
|
});
|
||||||
SlaveGroup.define({
|
HostGroup.define({
|
||||||
name: "mods_directory",
|
name: "mods_directory",
|
||||||
title: "Mods Directory",
|
title: "Mods Directory",
|
||||||
description: "Path to directory where mods for instances are cached.",
|
description: "Path to directory where mods for instances are cached.",
|
||||||
type: "string",
|
type: "string",
|
||||||
initial_value: "mods",
|
initial_value: "mods",
|
||||||
});
|
});
|
||||||
SlaveGroup.define({
|
HostGroup.define({
|
||||||
name: "mods_directory_is_shared",
|
name: "mods_directory_is_shared",
|
||||||
title: "Mods Directory is Shared",
|
title: "Mods Directory is Shared",
|
||||||
description: "True if the mods directory is shared with the master server.",
|
description: "True if the mods directory is shared with the controller.",
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
initial_value: true,
|
initial_value: true,
|
||||||
});
|
});
|
||||||
SlaveGroup.define({
|
HostGroup.define({
|
||||||
name: "instances_directory",
|
name: "instances_directory",
|
||||||
description: "Path to directory to store instances in.",
|
description: "Path to directory to store instances in.",
|
||||||
restartRequired: true,
|
restartRequired: true,
|
||||||
type: "string",
|
type: "string",
|
||||||
initial_value: "instances",
|
initial_value: "instances",
|
||||||
});
|
});
|
||||||
SlaveGroup.define({
|
HostGroup.define({
|
||||||
name: "master_url",
|
name: "controller_url",
|
||||||
description: "URL to connect to the master server at",
|
description: "URL to connect to the controller at",
|
||||||
restartRequired: true,
|
restartRequired: true,
|
||||||
type: "string",
|
type: "string",
|
||||||
initial_value: "http://localhost:8080/",
|
initial_value: "http://localhost:8080/",
|
||||||
});
|
});
|
||||||
SlaveGroup.define({
|
HostGroup.define({
|
||||||
name: "master_token",
|
name: "controller_token",
|
||||||
description: "Token to authenticate to master server with.",
|
description: "Token to authenticate to controller with.",
|
||||||
restartRequired: true,
|
restartRequired: true,
|
||||||
type: "string",
|
type: "string",
|
||||||
initial_value: "enter token here",
|
initial_value: "enter token here",
|
||||||
});
|
});
|
||||||
SlaveGroup.define({
|
HostGroup.define({
|
||||||
name: "tls_ca",
|
name: "tls_ca",
|
||||||
description: "Path to Certificate Authority to validate TLS connection to master against.",
|
description: "Path to Certificate Authority to validate TLS connection to controller against.",
|
||||||
restartRequired: true,
|
restartRequired: true,
|
||||||
type: "string",
|
type: "string",
|
||||||
optional: true,
|
optional: true,
|
||||||
});
|
});
|
||||||
SlaveGroup.define({
|
HostGroup.define({
|
||||||
name: "public_address",
|
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",
|
type: "string",
|
||||||
initial_value: "localhost",
|
initial_value: "localhost",
|
||||||
});
|
});
|
||||||
SlaveGroup.define({
|
HostGroup.define({
|
||||||
name: "max_reconnect_delay",
|
name: "max_reconnect_delay",
|
||||||
title: "Max Reconnect Delay",
|
title: "Max Reconnect Delay",
|
||||||
description: "Maximum delay to wait before attempting to reconnect WebSocket",
|
description: "Maximum delay to wait before attempting to reconnect WebSocket",
|
||||||
type: "number",
|
type: "number",
|
||||||
initial_value: 60,
|
initial_value: 60,
|
||||||
});
|
});
|
||||||
SlaveGroup.finalize();
|
HostGroup.finalize();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Slave Config class
|
* Host Config class
|
||||||
* @extends module:lib/config.Config
|
* @extends module:lib/config.Config
|
||||||
* @memberof module:lib/config
|
* @memberof module:lib/config
|
||||||
*/
|
*/
|
||||||
class SlaveConfig extends classes.Config { }
|
class HostConfig extends classes.Config { }
|
||||||
SlaveConfig.registerGroup(SlaveGroup);
|
HostConfig.registerGroup(HostGroup);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -245,7 +245,7 @@ SlaveConfig.registerGroup(SlaveGroup);
|
|||||||
* @memberof module:lib/config
|
* @memberof module:lib/config
|
||||||
*/
|
*/
|
||||||
class InstanceGroup extends classes.ConfigGroup { }
|
class InstanceGroup extends classes.ConfigGroup { }
|
||||||
InstanceGroup.defaultAccess = ["master", "slave", "control"];
|
InstanceGroup.defaultAccess = ["controller", "host", "control"];
|
||||||
InstanceGroup.groupName = "instance";
|
InstanceGroup.groupName = "instance";
|
||||||
InstanceGroup.define({
|
InstanceGroup.define({
|
||||||
name: "name",
|
name: "name",
|
||||||
@@ -259,13 +259,13 @@ InstanceGroup.define({
|
|||||||
initial_value: () => Math.random() * 2**31 | 0,
|
initial_value: () => Math.random() * 2**31 | 0,
|
||||||
});
|
});
|
||||||
InstanceGroup.define({
|
InstanceGroup.define({
|
||||||
name: "assigned_slave",
|
name: "assigned_host",
|
||||||
type: "number",
|
type: "number",
|
||||||
optional: true,
|
optional: true,
|
||||||
});
|
});
|
||||||
InstanceGroup.define({
|
InstanceGroup.define({
|
||||||
name: "auto_start",
|
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",
|
type: "boolean",
|
||||||
initial_value: false,
|
initial_value: false,
|
||||||
});
|
});
|
||||||
@@ -277,7 +277,7 @@ InstanceGroup.finalize();
|
|||||||
* @memberof module:lib/config
|
* @memberof module:lib/config
|
||||||
*/
|
*/
|
||||||
class FactorioGroup extends classes.ConfigGroup { }
|
class FactorioGroup extends classes.ConfigGroup { }
|
||||||
FactorioGroup.defaultAccess = ["master", "slave", "control"];
|
FactorioGroup.defaultAccess = ["controller", "host", "control"];
|
||||||
FactorioGroup.groupName = "factorio";
|
FactorioGroup.groupName = "factorio";
|
||||||
FactorioGroup.define({
|
FactorioGroup.define({
|
||||||
name: "version",
|
name: "version",
|
||||||
@@ -353,7 +353,7 @@ FactorioGroup.define({
|
|||||||
"require_user_verification", "tags", "visibility",
|
"require_user_verification", "tags", "visibility",
|
||||||
],
|
],
|
||||||
type: "object",
|
type: "object",
|
||||||
initial_value: {}, // See create instance handler in master.
|
initial_value: {}, // See create instance handler in controller.
|
||||||
});
|
});
|
||||||
FactorioGroup.define({
|
FactorioGroup.define({
|
||||||
name: "verbose_logging",
|
name: "verbose_logging",
|
||||||
@@ -371,19 +371,19 @@ FactorioGroup.define({
|
|||||||
});
|
});
|
||||||
FactorioGroup.define({
|
FactorioGroup.define({
|
||||||
name: "sync_adminlist",
|
name: "sync_adminlist",
|
||||||
description: "Synchronize adminlist with master server",
|
description: "Synchronize adminlist with controller",
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
initial_value: true,
|
initial_value: true,
|
||||||
});
|
});
|
||||||
FactorioGroup.define({
|
FactorioGroup.define({
|
||||||
name: "sync_whitelist",
|
name: "sync_whitelist",
|
||||||
description: "Synchronize whitelist with master server",
|
description: "Synchronize whitelist with controller",
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
initial_value: true,
|
initial_value: true,
|
||||||
});
|
});
|
||||||
FactorioGroup.define({
|
FactorioGroup.define({
|
||||||
name: "sync_banlist",
|
name: "sync_banlist",
|
||||||
description: "Synchronize banlist with master server",
|
description: "Synchronize banlist with controller",
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
initial_value: true,
|
initial_value: true,
|
||||||
});
|
});
|
||||||
@@ -415,20 +415,20 @@ class ControlGroup extends classes.ConfigGroup {}
|
|||||||
ControlGroup.defaultAccess = ["control"];
|
ControlGroup.defaultAccess = ["control"];
|
||||||
ControlGroup.groupName = "control";
|
ControlGroup.groupName = "control";
|
||||||
ControlGroup.define({
|
ControlGroup.define({
|
||||||
name: "master_url",
|
name: "controller_url",
|
||||||
description: "URL to connect to the master server at",
|
description: "URL to connect to the controller at",
|
||||||
type: "string",
|
type: "string",
|
||||||
optional: true,
|
optional: true,
|
||||||
});
|
});
|
||||||
ControlGroup.define({
|
ControlGroup.define({
|
||||||
name: "master_token",
|
name: "controller_token",
|
||||||
description: "Token to authenticate to master server with.",
|
description: "Token to authenticate to controller with.",
|
||||||
type: "string",
|
type: "string",
|
||||||
optional: true,
|
optional: true,
|
||||||
});
|
});
|
||||||
ControlGroup.define({
|
ControlGroup.define({
|
||||||
name: "tls_ca",
|
name: "tls_ca",
|
||||||
description: "Path to Certificate Authority to validate TLS connection to master against.",
|
description: "Path to Certificate Authority to validate TLS connection to controller against.",
|
||||||
type: "string",
|
type: "string",
|
||||||
optional: true,
|
optional: true,
|
||||||
});
|
});
|
||||||
@@ -472,16 +472,16 @@ function validateGroup(pluginInfo, groupName) {
|
|||||||
*/
|
*/
|
||||||
function registerPluginConfigGroups(pluginInfos) {
|
function registerPluginConfigGroups(pluginInfos) {
|
||||||
for (let pluginInfo of pluginInfos) {
|
for (let pluginInfo of pluginInfos) {
|
||||||
if (pluginInfo.MasterConfigGroup) {
|
if (pluginInfo.ControllerConfigGroup) {
|
||||||
validateGroup(pluginInfo, "MasterConfigGroup");
|
validateGroup(pluginInfo, "ControllerConfigGroup");
|
||||||
MasterConfig.registerGroup(pluginInfo.MasterConfigGroup);
|
ControllerConfig.registerGroup(pluginInfo.ControllerConfigGroup);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
class MasterConfigGroup extends classes.PluginConfigGroup { }
|
class ControllerConfigGroup extends classes.PluginConfigGroup { }
|
||||||
MasterConfigGroup.defaultAccess = ["master", "slave", "control"];
|
ControllerConfigGroup.defaultAccess = ["controller", "host", "control"];
|
||||||
MasterConfigGroup.groupName = pluginInfo.name;
|
ControllerConfigGroup.groupName = pluginInfo.name;
|
||||||
MasterConfigGroup.finalize();
|
ControllerConfigGroup.finalize();
|
||||||
MasterConfig.registerGroup(MasterConfigGroup);
|
ControllerConfig.registerGroup(ControllerConfigGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pluginInfo.instanceEntrypoint) {
|
if (pluginInfo.instanceEntrypoint) {
|
||||||
@@ -491,7 +491,7 @@ function registerPluginConfigGroups(pluginInfos) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
class InstanceConfigGroup extends classes.PluginConfigGroup { }
|
class InstanceConfigGroup extends classes.PluginConfigGroup { }
|
||||||
InstanceConfigGroup.defaultAccess = ["master", "slave", "control"];
|
InstanceConfigGroup.defaultAccess = ["controller", "host", "control"];
|
||||||
InstanceConfigGroup.groupName = pluginInfo.name;
|
InstanceConfigGroup.groupName = pluginInfo.name;
|
||||||
InstanceConfigGroup.finalize();
|
InstanceConfigGroup.finalize();
|
||||||
InstanceConfig.registerGroup(InstanceConfigGroup);
|
InstanceConfig.registerGroup(InstanceConfigGroup);
|
||||||
@@ -506,21 +506,21 @@ function registerPluginConfigGroups(pluginInfos) {
|
|||||||
* @memberof module:lib/config
|
* @memberof module:lib/config
|
||||||
*/
|
*/
|
||||||
function finalizeConfigs() {
|
function finalizeConfigs() {
|
||||||
MasterConfig.finalize();
|
ControllerConfig.finalize();
|
||||||
SlaveConfig.finalize();
|
HostConfig.finalize();
|
||||||
InstanceConfig.finalize();
|
InstanceConfig.finalize();
|
||||||
ControlConfig.finalize();
|
ControlConfig.finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
MasterGroup,
|
ControllerGroup,
|
||||||
SlaveGroup,
|
HostGroup,
|
||||||
InstanceGroup,
|
InstanceGroup,
|
||||||
FactorioGroup,
|
FactorioGroup,
|
||||||
ControlGroup,
|
ControlGroup,
|
||||||
|
|
||||||
MasterConfig,
|
ControllerConfig,
|
||||||
SlaveConfig,
|
HostConfig,
|
||||||
InstanceConfig,
|
InstanceConfig,
|
||||||
ControlConfig,
|
ControlConfig,
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ const { integerModVersion, integerFactorioVersion, modVersionRegExp } = require(
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Info about a mod available on the master server.
|
* Info about a mod available on the controller.
|
||||||
*
|
*
|
||||||
* See https://wiki.factorio.com/Tutorial:Mod_structure#info.json for
|
* See https://wiki.factorio.com/Tutorial:Mod_structure#info.json for
|
||||||
* details of the invidiual fields sourced from info.json.
|
* details of the invidiual fields sourced from info.json.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Implementation of master databases
|
* Implementation of controller databases
|
||||||
*
|
*
|
||||||
* @module lib/database
|
* @module lib/database
|
||||||
* @author Hornwitser
|
* @author Hornwitser
|
||||||
@@ -159,7 +159,7 @@ function checkCount(count) {
|
|||||||
/**
|
/**
|
||||||
* Item database
|
* Item database
|
||||||
*
|
*
|
||||||
* Stores counts of items for the master server. Items that have not been
|
* Stores counts of items for the controller. Items that have not been
|
||||||
* stored in the database are treated as having a stored count of zero. When
|
* stored in the database are treated as having a stored count of zero. When
|
||||||
* serialized the database discards entries with a zero counts, and when
|
* serialized the database discards entries with a zero counts, and when
|
||||||
* deserialized the content is verified.
|
* deserialized the content is verified.
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ async function generateExportMod(server) {
|
|||||||
clean: false,
|
clean: false,
|
||||||
build: true,
|
build: true,
|
||||||
pack: true,
|
pack: true,
|
||||||
// XXX fix path when moving lib/factorio to slave
|
// XXX fix path when moving lib/factorio to host
|
||||||
sourceDir: path.join(__dirname, "..", "..", "slave", "lua", "export"),
|
sourceDir: path.join(__dirname, "..", "..", "host", "lua", "export"),
|
||||||
outputDir: server.writePath("mods"),
|
outputDir: server.writePath("mods"),
|
||||||
bumpPatch: false,
|
bumpPatch: false,
|
||||||
factorioVersion: server.version.replace(/\.\d+$/, ""),
|
factorioVersion: server.version.replace(/\.\d+$/, ""),
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ class WebSocketBaseConnector extends events.EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connector for master server clients
|
* Connector for controller clients
|
||||||
*
|
*
|
||||||
* @extends module:lib/link.WebSocketBaseConnector
|
* @extends module:lib/link.WebSocketBaseConnector
|
||||||
* @memberof module:lib/link
|
* @memberof module:lib/link
|
||||||
@@ -278,7 +278,7 @@ class WebSocketClientConnector extends WebSocketBaseConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to the master server
|
* Connect to the controller
|
||||||
*/
|
*/
|
||||||
async connect() {
|
async connect() {
|
||||||
this._check("closed");
|
this._check("closed");
|
||||||
@@ -294,7 +294,7 @@ class WebSocketClientConnector extends WebSocketBaseConnector {
|
|||||||
let url = new URL(this._url);
|
let url = new URL(this._url);
|
||||||
url.pathname += "api/socket";
|
url.pathname += "api/socket";
|
||||||
|
|
||||||
// Open WebSocket to master
|
// Open WebSocket to controller
|
||||||
logger.verbose(`Connector | connecting to ${url}`);
|
logger.verbose(`Connector | connecting to ${url}`);
|
||||||
|
|
||||||
// eslint-disable-next-line node/no-process-env
|
// eslint-disable-next-line node/no-process-env
|
||||||
@@ -447,7 +447,7 @@ class WebSocketClientConnector extends WebSocketBaseConnector {
|
|||||||
|
|
||||||
let { type, data } = message;
|
let { type, data } = message;
|
||||||
if (type === "hello") {
|
if (type === "hello") {
|
||||||
logger.verbose(`Connector | received hello from master version ${data.version}`);
|
logger.verbose(`Connector | received hello from controller version ${data.version}`);
|
||||||
this.emit("hello", data);
|
this.emit("hello", data);
|
||||||
if (this._sessionToken) {
|
if (this._sessionToken) {
|
||||||
logger.verbose("Connector | Attempting resume");
|
logger.verbose("Connector | Attempting resume");
|
||||||
@@ -460,7 +460,7 @@ class WebSocketClientConnector extends WebSocketBaseConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (type === "ready") {
|
} else if (type === "ready") {
|
||||||
logger.verbose("Connector | received ready from master");
|
logger.verbose("Connector | received ready from controller");
|
||||||
this._state = "connected";
|
this._state = "connected";
|
||||||
this._sessionToken = data.session_token;
|
this._sessionToken = data.session_token;
|
||||||
this._sessionTimeout = data.session_timeout;
|
this._sessionTimeout = data.session_timeout;
|
||||||
@@ -485,7 +485,7 @@ class WebSocketClientConnector extends WebSocketBaseConnector {
|
|||||||
this.emit("resume");
|
this.emit("resume");
|
||||||
|
|
||||||
} else if (type === "invalidate") {
|
} else if (type === "invalidate") {
|
||||||
logger.warn("Connector | session invalidated by master");
|
logger.warn("Connector | session invalidated by controller");
|
||||||
this._state = "connecting";
|
this._state = "connecting";
|
||||||
this._seq = 1;
|
this._seq = 1;
|
||||||
this._lastReceivedSeq = null;
|
this._lastReceivedSeq = null;
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ const libErrors = require("../errors");
|
|||||||
const { logger } = require("../logging");
|
const { logger } = require("../logging");
|
||||||
|
|
||||||
// Some definitions for the terminology used here:
|
// Some definitions for the terminology used here:
|
||||||
// link: Either side of a master - client connection
|
// link: Either side of a controller - client connection
|
||||||
// connector: Adapter between a link and a socket connection
|
// connector: Adapter between a link and a socket connection
|
||||||
// connection: the master server side of a link
|
// connection: the controller side of a link
|
||||||
// client: the side that is not the master server of a link
|
// client: the side that is not the controller of a link
|
||||||
// message: the complete object sent using the 'message' event
|
// message: the complete object sent using the 'message' event
|
||||||
// data: the data property of a message, essentially the payload.
|
// data: the data property of a message, essentially the payload.
|
||||||
// type: the type property of a message, identifies what to expect in data.
|
// type: the type property of a message, identifies what to expect in data.
|
||||||
|
|||||||
+153
-151
@@ -67,11 +67,11 @@ class Request extends Message {
|
|||||||
* containing "<source>-<target>" specifications.
|
* containing "<source>-<target>" specifications.
|
||||||
* @param {?string} permission -
|
* @param {?string} permission -
|
||||||
* Permission required to send this request. Only applies to
|
* Permission required to send this request. Only applies to
|
||||||
* requests sent from control to master.
|
* requests sent from control to controller.
|
||||||
* @param {?string} forwardTo -
|
* @param {?string} forwardTo -
|
||||||
* Optional target to forward this request to. 'instance' add
|
* Optional target to forward this request to. 'instance' add
|
||||||
* instance_id into the requestProperties and forward to the given
|
* instance_id into the requestProperties and forward to the given
|
||||||
* instance. 'master' forwards it to the master server.
|
* instance. 'controller' forwards it to the controller.
|
||||||
* @param {?Array<string>} requestRequired -
|
* @param {?Array<string>} requestRequired -
|
||||||
* List of properties that are required to be present in the data
|
* List of properties that are required to be present in the data
|
||||||
* payload of this request. Defaults to all.
|
* payload of this request. Defaults to all.
|
||||||
@@ -101,11 +101,13 @@ class Request extends Message {
|
|||||||
this.requestType = `${type}_request`;
|
this.requestType = `${type}_request`;
|
||||||
this.responseType = `${type}_response`;
|
this.responseType = `${type}_response`;
|
||||||
|
|
||||||
if (permission === undefined && links.includes("control-master")) {
|
if (permission === undefined && links.includes("control-controller")) {
|
||||||
throw new Error(`permission is required for ${this.type} request over control-master links`);
|
throw new Error(`permission is required for ${this.type} request over control-controller links`);
|
||||||
}
|
}
|
||||||
if (permission && !links.includes("control-master")) {
|
if (permission && !links.includes("control-controller")) {
|
||||||
throw new Error(`permission is not allowed on ${this.type} request as it is not over control-master link`);
|
throw new Error(
|
||||||
|
`permission is not allowed on ${this.type} request as it is not over control-controller link`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!requestRequired) {
|
if (!requestRequired) {
|
||||||
@@ -119,7 +121,7 @@ class Request extends Message {
|
|||||||
...requestProperties,
|
...requestProperties,
|
||||||
};
|
};
|
||||||
|
|
||||||
} else if (forwardTo !== "master" && forwardTo !== null) {
|
} else if (forwardTo !== "controller" && forwardTo !== null) {
|
||||||
throw new Error(`Invalid forwardTo value ${forwardTo}`);
|
throw new Error(`Invalid forwardTo value ${forwardTo}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +178,7 @@ class Request extends Message {
|
|||||||
* If forwardTo was set to 'instance' the `forwardRequestToInstance`
|
* If forwardTo was set to 'instance' the `forwardRequestToInstance`
|
||||||
* method on the link is used as the default handler.
|
* method on the link is used as the default handler.
|
||||||
*
|
*
|
||||||
* If forwardTo was set to 'master' the `forwardRequesToMaster` method
|
* If forwardTo was set to 'controller' the `forwardRequesToController` method
|
||||||
* on the link is used as the default handler.
|
* on the link is used as the default handler.
|
||||||
*
|
*
|
||||||
* Does nothing if the link is neither a source nor a target for this
|
* Does nothing if the link is neither a source nor a target for this
|
||||||
@@ -201,8 +203,8 @@ class Request extends Message {
|
|||||||
if (!handler) {
|
if (!handler) {
|
||||||
if (this.forwardTo === "instance") {
|
if (this.forwardTo === "instance") {
|
||||||
handler = link.forwardRequestToInstance;
|
handler = link.forwardRequestToInstance;
|
||||||
} else if (this.forwardTo === "master") {
|
} else if (this.forwardTo === "controller") {
|
||||||
handler = link.forwardRequestToMaster;
|
handler = link.forwardRequestToController;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,8 +212,8 @@ class Request extends Message {
|
|||||||
throw new MissingLinkHandlerError(this.requestType, link.source, link.target);
|
throw new MissingLinkHandlerError(this.requestType, link.source, link.target);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check permission if this is a handler for a control connection on the master
|
// Check permission if this is a handler for a control connection on the controller
|
||||||
if (this.permission !== null && `${link.source}-${link.target}` === "master-control") {
|
if (this.permission !== null && `${link.source}-${link.target}` === "controller-control") {
|
||||||
let origHandler = handler;
|
let origHandler = handler;
|
||||||
handler = async function(message, request) {
|
handler = async function(message, request) {
|
||||||
// Abuse this binding to get a hold of the ControlConnection instance
|
// Abuse this binding to get a hold of the ControlConnection instance
|
||||||
@@ -276,16 +278,16 @@ class Request extends Message {
|
|||||||
let messages = {};
|
let messages = {};
|
||||||
|
|
||||||
// Connection requests
|
// Connection requests
|
||||||
let wsLinks = ["master-control", "control-master", "master-slave", "slave-master"];
|
let wsLinks = ["controller-control", "control-controller", "controller-host", "host-controller"];
|
||||||
messages.prepareDisconnect = new Request({
|
messages.prepareDisconnect = new Request({
|
||||||
type: "prepare_disconnect",
|
type: "prepare_disconnect",
|
||||||
links: wsLinks,
|
links: wsLinks,
|
||||||
permission: null,
|
permission: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
messages.prepareMasterDisconnect = new Request({
|
messages.prepareControllerDisconnect = new Request({
|
||||||
type: "prepare_master_disconnect",
|
type: "prepare_controller_disconnect",
|
||||||
links: ["slave-instance"],
|
links: ["host-instance"],
|
||||||
});
|
});
|
||||||
|
|
||||||
messages.ping = new Request({
|
messages.ping = new Request({
|
||||||
@@ -296,35 +298,35 @@ messages.ping = new Request({
|
|||||||
|
|
||||||
messages.debugDumpWs = new Request({
|
messages.debugDumpWs = new Request({
|
||||||
type: "debug_dump_ws",
|
type: "debug_dump_ws",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.debug.dump_ws",
|
permission: "core.debug.dump_ws",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Management requests
|
// Management requests
|
||||||
messages.getMasterConfig = new Request({
|
messages.getControllerConfig = new Request({
|
||||||
type: "get_master_config",
|
type: "get_controller_config",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.master.get_config",
|
permission: "core.controller.get_config",
|
||||||
responseProperties: {
|
responseProperties: {
|
||||||
"serialized_config": { type: "object" },
|
"serialized_config": { type: "object" },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
messages.setMasterConfigField = new Request({
|
messages.setControllerConfigField = new Request({
|
||||||
type: "set_master_config_field",
|
type: "set_controller_config_field",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.master.update_config",
|
permission: "core.controller.update_config",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"field": { type: "string" },
|
"field": { type: "string" },
|
||||||
"value": { type: "string" },
|
"value": { type: "string" },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
messages.setMasterConfigProp = new Request({
|
messages.setControllerConfigProp = new Request({
|
||||||
type: "set_master_config_prop",
|
type: "set_controller_config_prop",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.master.update_config",
|
permission: "core.controller.update_config",
|
||||||
requestRequired: ["field", "prop"],
|
requestRequired: ["field", "prop"],
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"field": { type: "string" },
|
"field": { type: "string" },
|
||||||
@@ -333,7 +335,7 @@ messages.setMasterConfigProp = new Request({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let slaveProperties = {
|
let hostProperties = {
|
||||||
"agent": { type: "string" },
|
"agent": { type: "string" },
|
||||||
"version": { type: "string" },
|
"version": { type: "string" },
|
||||||
"name": { type: "string" },
|
"name": { type: "string" },
|
||||||
@@ -342,29 +344,29 @@ let slaveProperties = {
|
|||||||
"public_address": { type: ["null", "string"] },
|
"public_address": { type: ["null", "string"] },
|
||||||
};
|
};
|
||||||
|
|
||||||
messages.listSlaves = new Request({
|
messages.listHosts = new Request({
|
||||||
type: "list_slaves",
|
type: "list_hosts",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.slave.list",
|
permission: "core.host.list",
|
||||||
responseProperties: {
|
responseProperties: {
|
||||||
"list": {
|
"list": {
|
||||||
type: "array",
|
type: "array",
|
||||||
items: {
|
items: {
|
||||||
additionalProperties: false,
|
additionalProperties: false,
|
||||||
required: ["agent", "version", "name", "id", "connected"],
|
required: ["agent", "version", "name", "id", "connected"],
|
||||||
properties: slaveProperties,
|
properties: hostProperties,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
messages.setSlaveSubscriptions = new Request({
|
messages.setHostSubscriptions = new Request({
|
||||||
type: "set_slave_subscriptions",
|
type: "set_host_subscriptions",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.slave.subscribe",
|
permission: "core.host.subscribe",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"all": { type: "boolean" },
|
"all": { type: "boolean" },
|
||||||
"slave_ids": {
|
"host_ids": {
|
||||||
type: "array",
|
type: "array",
|
||||||
items: { type: "integer" },
|
items: { type: "integer" },
|
||||||
},
|
},
|
||||||
@@ -374,7 +376,7 @@ messages.setSlaveSubscriptions = new Request({
|
|||||||
let instanceProperties = {
|
let instanceProperties = {
|
||||||
"name": { type: "string" },
|
"name": { type: "string" },
|
||||||
"id": { type: "integer" },
|
"id": { type: "integer" },
|
||||||
"assigned_slave": { type: ["null", "integer"] },
|
"assigned_host": { type: ["null", "integer"] },
|
||||||
"game_port": { type: ["null", "integer"] },
|
"game_port": { type: ["null", "integer"] },
|
||||||
"status": { enum: [
|
"status": { enum: [
|
||||||
"unknown", "unassigned", "stopped", "starting", "running", "stopping",
|
"unknown", "unassigned", "stopped", "starting", "running", "stopping",
|
||||||
@@ -384,7 +386,7 @@ let instanceProperties = {
|
|||||||
|
|
||||||
messages.getInstance = new Request({
|
messages.getInstance = new Request({
|
||||||
type: "get_instance",
|
type: "get_instance",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.instance.get",
|
permission: "core.instance.get",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"id": { type: "integer" },
|
"id": { type: "integer" },
|
||||||
@@ -394,14 +396,14 @@ messages.getInstance = new Request({
|
|||||||
|
|
||||||
messages.listInstances = new Request({
|
messages.listInstances = new Request({
|
||||||
type: "list_instances",
|
type: "list_instances",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.instance.list",
|
permission: "core.instance.list",
|
||||||
responseProperties: {
|
responseProperties: {
|
||||||
"list": {
|
"list": {
|
||||||
type: "array",
|
type: "array",
|
||||||
items: {
|
items: {
|
||||||
additionalProperties: false,
|
additionalProperties: false,
|
||||||
required: ["name", "id", "assigned_slave", "status"],
|
required: ["name", "id", "assigned_host", "status"],
|
||||||
properties: instanceProperties,
|
properties: instanceProperties,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -410,7 +412,7 @@ messages.listInstances = new Request({
|
|||||||
|
|
||||||
messages.setInstanceSubscriptions = new Request({
|
messages.setInstanceSubscriptions = new Request({
|
||||||
type: "set_instance_subscriptions",
|
type: "set_instance_subscriptions",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.instance.subscribe",
|
permission: "core.instance.subscribe",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"all": { type: "boolean" },
|
"all": { type: "boolean" },
|
||||||
@@ -421,22 +423,22 @@ messages.setInstanceSubscriptions = new Request({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
messages.generateSlaveToken = new Request({
|
messages.generateHostToken = new Request({
|
||||||
type: "generate_slave_token",
|
type: "generate_host_token",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.slave.generate_token",
|
permission: "core.host.generate_token",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"slave_id": { type: ["integer", "null"] },
|
"host_id": { type: ["integer", "null"] },
|
||||||
},
|
},
|
||||||
responseProperties: {
|
responseProperties: {
|
||||||
"token": { type: "string" },
|
"token": { type: "string" },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
messages.createSlaveConfig = new Request({
|
messages.createHostConfig = new Request({
|
||||||
type: "create_slave_config",
|
type: "create_host_config",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.slave.create_config",
|
permission: "core.host.create_config",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"id": { type: ["integer", "null"] },
|
"id": { type: ["integer", "null"] },
|
||||||
"name": { type: ["string", "null"] },
|
"name": { type: ["string", "null"] },
|
||||||
@@ -449,7 +451,7 @@ messages.createSlaveConfig = new Request({
|
|||||||
|
|
||||||
messages.createInstance = new Request({
|
messages.createInstance = new Request({
|
||||||
type: "create_instance",
|
type: "create_instance",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.instance.create",
|
permission: "core.instance.create",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"serialized_config": { type: "object" },
|
"serialized_config": { type: "object" },
|
||||||
@@ -458,7 +460,7 @@ messages.createInstance = new Request({
|
|||||||
|
|
||||||
messages.getInstanceConfig = new Request({
|
messages.getInstanceConfig = new Request({
|
||||||
type: "get_instance_config",
|
type: "get_instance_config",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.instance.get_config",
|
permission: "core.instance.get_config",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"instance_id": { type: "integer" },
|
"instance_id": { type: "integer" },
|
||||||
@@ -470,7 +472,7 @@ messages.getInstanceConfig = new Request({
|
|||||||
|
|
||||||
messages.setInstanceConfigField = new Request({
|
messages.setInstanceConfigField = new Request({
|
||||||
type: "set_instance_config_field",
|
type: "set_instance_config_field",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.instance.update_config",
|
permission: "core.instance.update_config",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"instance_id": { type: "integer" },
|
"instance_id": { type: "integer" },
|
||||||
@@ -481,7 +483,7 @@ messages.setInstanceConfigField = new Request({
|
|||||||
|
|
||||||
messages.setInstanceConfigProp = new Request({
|
messages.setInstanceConfigProp = new Request({
|
||||||
type: "set_instance_config_prop",
|
type: "set_instance_config_prop",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.instance.update_config",
|
permission: "core.instance.update_config",
|
||||||
requestRequired: ["instance_id", "field", "prop"],
|
requestRequired: ["instance_id", "field", "prop"],
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
@@ -494,17 +496,17 @@ messages.setInstanceConfigProp = new Request({
|
|||||||
|
|
||||||
messages.assignInstanceCommand = new Request({
|
messages.assignInstanceCommand = new Request({
|
||||||
type: "assign_instance_command",
|
type: "assign_instance_command",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.instance.assign",
|
permission: "core.instance.assign",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"instance_id": { type: "integer" },
|
"instance_id": { type: "integer" },
|
||||||
"slave_id": { type: ["integer", "null"] },
|
"host_id": { type: ["integer", "null"] },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
messages.startInstance = new Request({
|
messages.startInstance = new Request({
|
||||||
type: "start_instance",
|
type: "start_instance",
|
||||||
links: ["control-master", "master-slave", "slave-instance"],
|
links: ["control-controller", "controller-host", "host-instance"],
|
||||||
permission: "core.instance.start",
|
permission: "core.instance.start",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"save": { type: ["string", "null"] },
|
"save": { type: ["string", "null"] },
|
||||||
@@ -531,7 +533,7 @@ let saveList = {
|
|||||||
|
|
||||||
messages.listSaves = new Request({
|
messages.listSaves = new Request({
|
||||||
type: "list_saves",
|
type: "list_saves",
|
||||||
links: ["control-master", "master-slave", "slave-instance"],
|
links: ["control-controller", "controller-host", "host-instance"],
|
||||||
permission: "core.instance.save.list",
|
permission: "core.instance.save.list",
|
||||||
forwardTo: "instance",
|
forwardTo: "instance",
|
||||||
responseProperties: {
|
responseProperties: {
|
||||||
@@ -541,7 +543,7 @@ messages.listSaves = new Request({
|
|||||||
|
|
||||||
messages.createSave = new Request({
|
messages.createSave = new Request({
|
||||||
type: "create_save",
|
type: "create_save",
|
||||||
links: ["control-master", "master-slave", "slave-instance"],
|
links: ["control-controller", "controller-host", "host-instance"],
|
||||||
permission: "core.instance.save.create",
|
permission: "core.instance.save.create",
|
||||||
forwardTo: "instance",
|
forwardTo: "instance",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
@@ -554,7 +556,7 @@ messages.createSave = new Request({
|
|||||||
|
|
||||||
messages.renameSave = new Request({
|
messages.renameSave = new Request({
|
||||||
type: "rename_save",
|
type: "rename_save",
|
||||||
links: ["control-master", "master-slave"],
|
links: ["control-controller", "controller-host"],
|
||||||
permission: "core.instance.save.rename",
|
permission: "core.instance.save.rename",
|
||||||
forwardTo: "instance",
|
forwardTo: "instance",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
@@ -565,7 +567,7 @@ messages.renameSave = new Request({
|
|||||||
|
|
||||||
messages.copySave = new Request({
|
messages.copySave = new Request({
|
||||||
type: "copy_save",
|
type: "copy_save",
|
||||||
links: ["control-master", "master-slave"],
|
links: ["control-controller", "controller-host"],
|
||||||
permission: "core.instance.save.copy",
|
permission: "core.instance.save.copy",
|
||||||
forwardTo: "instance",
|
forwardTo: "instance",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
@@ -576,7 +578,7 @@ messages.copySave = new Request({
|
|||||||
|
|
||||||
messages.deleteSave = new Request({
|
messages.deleteSave = new Request({
|
||||||
type: "delete_save",
|
type: "delete_save",
|
||||||
links: ["control-master", "master-slave"],
|
links: ["control-controller", "controller-host"],
|
||||||
permission: "core.instance.save.delete",
|
permission: "core.instance.save.delete",
|
||||||
forwardTo: "instance",
|
forwardTo: "instance",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
@@ -586,7 +588,7 @@ messages.deleteSave = new Request({
|
|||||||
|
|
||||||
messages.downloadSave = new Request({
|
messages.downloadSave = new Request({
|
||||||
type: "download_save",
|
type: "download_save",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.instance.save.download",
|
permission: "core.instance.save.download",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"instance_id": { type: "integer" },
|
"instance_id": { type: "integer" },
|
||||||
@@ -599,7 +601,7 @@ messages.downloadSave = new Request({
|
|||||||
|
|
||||||
messages.transferSave = new Request({
|
messages.transferSave = new Request({
|
||||||
type: "transfer_save",
|
type: "transfer_save",
|
||||||
links: ["control-master", "master-slave"],
|
links: ["control-controller", "controller-host"],
|
||||||
permission: "core.instance.save.transfer",
|
permission: "core.instance.save.transfer",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"instance_id": { type: "integer" },
|
"instance_id": { type: "integer" },
|
||||||
@@ -615,7 +617,7 @@ messages.transferSave = new Request({
|
|||||||
|
|
||||||
messages.pullSave = new Request({
|
messages.pullSave = new Request({
|
||||||
type: "pull_save",
|
type: "pull_save",
|
||||||
links: ["master-slave"],
|
links: ["controller-host"],
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"instance_id": { type: "integer" },
|
"instance_id": { type: "integer" },
|
||||||
"stream_id": { type: "string" },
|
"stream_id": { type: "string" },
|
||||||
@@ -628,7 +630,7 @@ messages.pullSave = new Request({
|
|||||||
|
|
||||||
messages.pushSave = new Request({
|
messages.pushSave = new Request({
|
||||||
type: "push_save",
|
type: "push_save",
|
||||||
links: ["master-slave"],
|
links: ["controller-host"],
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"instance_id": { type: "integer" },
|
"instance_id": { type: "integer" },
|
||||||
"stream_id": { type: "string" },
|
"stream_id": { type: "string" },
|
||||||
@@ -638,7 +640,7 @@ messages.pushSave = new Request({
|
|||||||
|
|
||||||
messages.setSaveListSubscriptions = new Request({
|
messages.setSaveListSubscriptions = new Request({
|
||||||
type: "set_save_list_subscriptions",
|
type: "set_save_list_subscriptions",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.instance.save.list_subscribe",
|
permission: "core.instance.save.list_subscribe",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"all": { type: "boolean" },
|
"all": { type: "boolean" },
|
||||||
@@ -651,7 +653,7 @@ messages.setSaveListSubscriptions = new Request({
|
|||||||
|
|
||||||
messages.loadScenario = new Request({
|
messages.loadScenario = new Request({
|
||||||
type: "load_scenario",
|
type: "load_scenario",
|
||||||
links: ["control-master", "master-slave", "slave-instance"],
|
links: ["control-controller", "controller-host", "host-instance"],
|
||||||
permission: "core.instance.load_scenario",
|
permission: "core.instance.load_scenario",
|
||||||
forwardTo: "instance",
|
forwardTo: "instance",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
@@ -664,42 +666,42 @@ messages.loadScenario = new Request({
|
|||||||
|
|
||||||
messages.exportData = new Request({
|
messages.exportData = new Request({
|
||||||
type: "export_data",
|
type: "export_data",
|
||||||
links: ["control-master", "master-slave", "slave-instance"],
|
links: ["control-controller", "controller-host", "host-instance"],
|
||||||
permission: "core.instance.export_data",
|
permission: "core.instance.export_data",
|
||||||
forwardTo: "instance",
|
forwardTo: "instance",
|
||||||
});
|
});
|
||||||
|
|
||||||
messages.extractPlayers = new Request({
|
messages.extractPlayers = new Request({
|
||||||
type: "extract_players",
|
type: "extract_players",
|
||||||
links: ["control-master", "master-slave", "slave-instance"],
|
links: ["control-controller", "controller-host", "host-instance"],
|
||||||
permission: "core.instance.extract_players",
|
permission: "core.instance.extract_players",
|
||||||
forwardTo: "instance",
|
forwardTo: "instance",
|
||||||
});
|
});
|
||||||
|
|
||||||
messages.stopInstance = new Request({
|
messages.stopInstance = new Request({
|
||||||
type: "stop_instance",
|
type: "stop_instance",
|
||||||
links: ["control-master", "master-slave", "slave-instance"],
|
links: ["control-controller", "controller-host", "host-instance"],
|
||||||
permission: "core.instance.stop",
|
permission: "core.instance.stop",
|
||||||
forwardTo: "instance",
|
forwardTo: "instance",
|
||||||
});
|
});
|
||||||
|
|
||||||
messages.killInstance = new Request({
|
messages.killInstance = new Request({
|
||||||
type: "kill_instance",
|
type: "kill_instance",
|
||||||
links: ["control-master", "master-slave", "slave-instance"],
|
links: ["control-controller", "controller-host", "host-instance"],
|
||||||
permission: "core.instance.kill",
|
permission: "core.instance.kill",
|
||||||
forwardTo: "instance",
|
forwardTo: "instance",
|
||||||
});
|
});
|
||||||
|
|
||||||
messages.deleteInstance = new Request({
|
messages.deleteInstance = new Request({
|
||||||
type: "delete_instance",
|
type: "delete_instance",
|
||||||
links: ["control-master", "master-slave"],
|
links: ["control-controller", "controller-host"],
|
||||||
permission: "core.instance.delete",
|
permission: "core.instance.delete",
|
||||||
forwardTo: "instance",
|
forwardTo: "instance",
|
||||||
});
|
});
|
||||||
|
|
||||||
messages.sendRcon = new Request({
|
messages.sendRcon = new Request({
|
||||||
type: "send_rcon",
|
type: "send_rcon",
|
||||||
links: ["control-master", "master-slave", "slave-instance"],
|
links: ["control-controller", "controller-host", "host-instance"],
|
||||||
permission: "core.instance.send_rcon",
|
permission: "core.instance.send_rcon",
|
||||||
forwardTo: "instance",
|
forwardTo: "instance",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
@@ -712,9 +714,9 @@ messages.sendRcon = new Request({
|
|||||||
|
|
||||||
messages.getModPack = new Request({
|
messages.getModPack = new Request({
|
||||||
type: "get_mod_pack",
|
type: "get_mod_pack",
|
||||||
links: ["control-master", "instance-slave", "slave-master"],
|
links: ["control-controller", "instance-host", "host-controller"],
|
||||||
permission: "core.mod_pack.get",
|
permission: "core.mod_pack.get",
|
||||||
forwardTo: "master",
|
forwardTo: "controller",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"id": { type: "integer" },
|
"id": { type: "integer" },
|
||||||
},
|
},
|
||||||
@@ -725,9 +727,9 @@ messages.getModPack = new Request({
|
|||||||
|
|
||||||
messages.getDefaultModPack = new Request({
|
messages.getDefaultModPack = new Request({
|
||||||
type: "get_default_mod_pack",
|
type: "get_default_mod_pack",
|
||||||
links: ["control-master", "instance-slave", "slave-master"],
|
links: ["control-controller", "instance-host", "host-controller"],
|
||||||
permission: "core.mod_pack.get",
|
permission: "core.mod_pack.get",
|
||||||
forwardTo: "master",
|
forwardTo: "controller",
|
||||||
responseProperties: {
|
responseProperties: {
|
||||||
"mod_pack": libData.ModPack.jsonSchema,
|
"mod_pack": libData.ModPack.jsonSchema,
|
||||||
},
|
},
|
||||||
@@ -735,7 +737,7 @@ messages.getDefaultModPack = new Request({
|
|||||||
|
|
||||||
messages.listModPacks = new Request({
|
messages.listModPacks = new Request({
|
||||||
type: "list_mod_packs",
|
type: "list_mod_packs",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.mod_pack.list",
|
permission: "core.mod_pack.list",
|
||||||
responseProperties: {
|
responseProperties: {
|
||||||
"list": {
|
"list": {
|
||||||
@@ -747,7 +749,7 @@ messages.listModPacks = new Request({
|
|||||||
|
|
||||||
messages.createModPack = new Request({
|
messages.createModPack = new Request({
|
||||||
type: "create_mod_pack",
|
type: "create_mod_pack",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.mod_pack.create",
|
permission: "core.mod_pack.create",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"mod_pack": libData.ModPack.jsonSchema,
|
"mod_pack": libData.ModPack.jsonSchema,
|
||||||
@@ -756,7 +758,7 @@ messages.createModPack = new Request({
|
|||||||
|
|
||||||
messages.updateModPack = new Request({
|
messages.updateModPack = new Request({
|
||||||
type: "update_mod_pack",
|
type: "update_mod_pack",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.mod_pack.update",
|
permission: "core.mod_pack.update",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"mod_pack": libData.ModPack.jsonSchema,
|
"mod_pack": libData.ModPack.jsonSchema,
|
||||||
@@ -765,7 +767,7 @@ messages.updateModPack = new Request({
|
|||||||
|
|
||||||
messages.deleteModPack = new Request({
|
messages.deleteModPack = new Request({
|
||||||
type: "delete_mod_pack",
|
type: "delete_mod_pack",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.mod_pack.delete",
|
permission: "core.mod_pack.delete",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"id": { type: "integer" },
|
"id": { type: "integer" },
|
||||||
@@ -774,7 +776,7 @@ messages.deleteModPack = new Request({
|
|||||||
|
|
||||||
messages.setModPackSubscriptions = new Request({
|
messages.setModPackSubscriptions = new Request({
|
||||||
type: "set_mod_pack_subscriptions",
|
type: "set_mod_pack_subscriptions",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.mod_pack.subscribe",
|
permission: "core.mod_pack.subscribe",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"all": { type: "boolean" },
|
"all": { type: "boolean" },
|
||||||
@@ -787,7 +789,7 @@ messages.setModPackSubscriptions = new Request({
|
|||||||
|
|
||||||
messages.getMod = new Request({
|
messages.getMod = new Request({
|
||||||
type: "get_mod",
|
type: "get_mod",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.mod.get",
|
permission: "core.mod.get",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"name": { type: "string" },
|
"name": { type: "string" },
|
||||||
@@ -800,7 +802,7 @@ messages.getMod = new Request({
|
|||||||
|
|
||||||
messages.listMods = new Request({
|
messages.listMods = new Request({
|
||||||
type: "list_mods",
|
type: "list_mods",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.mod.list",
|
permission: "core.mod.list",
|
||||||
responseProperties: {
|
responseProperties: {
|
||||||
"list": {
|
"list": {
|
||||||
@@ -812,7 +814,7 @@ messages.listMods = new Request({
|
|||||||
|
|
||||||
messages.searchMods = new Request({
|
messages.searchMods = new Request({
|
||||||
type: "search_mods",
|
type: "search_mods",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.mod.search",
|
permission: "core.mod.search",
|
||||||
requestRequired: ["query", "factorio_version", "page"],
|
requestRequired: ["query", "factorio_version", "page"],
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
@@ -848,7 +850,7 @@ messages.searchMods = new Request({
|
|||||||
|
|
||||||
messages.setModSubscriptions = new Request({
|
messages.setModSubscriptions = new Request({
|
||||||
type: "set_mod_subscriptions",
|
type: "set_mod_subscriptions",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.mod.subscribe",
|
permission: "core.mod.subscribe",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"all": { type: "boolean" },
|
"all": { type: "boolean" },
|
||||||
@@ -861,7 +863,7 @@ messages.setModSubscriptions = new Request({
|
|||||||
|
|
||||||
messages.downloadMod = new Request({
|
messages.downloadMod = new Request({
|
||||||
type: "download_mod",
|
type: "download_mod",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.mod.download",
|
permission: "core.mod.download",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"name": { type: "string" },
|
"name": { type: "string" },
|
||||||
@@ -874,7 +876,7 @@ messages.downloadMod = new Request({
|
|||||||
|
|
||||||
messages.deleteMod = new Request({
|
messages.deleteMod = new Request({
|
||||||
type: "delete_mod",
|
type: "delete_mod",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.mod.delete",
|
permission: "core.mod.delete",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"name": { type: "string" },
|
"name": { type: "string" },
|
||||||
@@ -884,7 +886,7 @@ messages.deleteMod = new Request({
|
|||||||
|
|
||||||
messages.listPermissions = new Request({
|
messages.listPermissions = new Request({
|
||||||
type: "list_permissions",
|
type: "list_permissions",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.permission.list",
|
permission: "core.permission.list",
|
||||||
responseProperties: {
|
responseProperties: {
|
||||||
"list": {
|
"list": {
|
||||||
@@ -904,7 +906,7 @@ messages.listPermissions = new Request({
|
|||||||
|
|
||||||
messages.listRoles = new Request({
|
messages.listRoles = new Request({
|
||||||
type: "list_roles",
|
type: "list_roles",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.role.list",
|
permission: "core.role.list",
|
||||||
responseProperties: {
|
responseProperties: {
|
||||||
"list": {
|
"list": {
|
||||||
@@ -925,7 +927,7 @@ messages.listRoles = new Request({
|
|||||||
|
|
||||||
messages.createRole = new Request({
|
messages.createRole = new Request({
|
||||||
type: "create_role",
|
type: "create_role",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.role.create",
|
permission: "core.role.create",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"name": { type: "string" },
|
"name": { type: "string" },
|
||||||
@@ -939,7 +941,7 @@ messages.createRole = new Request({
|
|||||||
|
|
||||||
messages.updateRole = new Request({
|
messages.updateRole = new Request({
|
||||||
type: "update_role",
|
type: "update_role",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.role.update",
|
permission: "core.role.update",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"id": { type: "integer" },
|
"id": { type: "integer" },
|
||||||
@@ -951,7 +953,7 @@ messages.updateRole = new Request({
|
|||||||
|
|
||||||
messages.grantDefaultRolePermissions = new Request({
|
messages.grantDefaultRolePermissions = new Request({
|
||||||
type: "grant_default_role_permissions",
|
type: "grant_default_role_permissions",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.role.update",
|
permission: "core.role.update",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"id": { type: "integer" },
|
"id": { type: "integer" },
|
||||||
@@ -960,7 +962,7 @@ messages.grantDefaultRolePermissions = new Request({
|
|||||||
|
|
||||||
messages.deleteRole = new Request({
|
messages.deleteRole = new Request({
|
||||||
type: "delete_role",
|
type: "delete_role",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.role.delete",
|
permission: "core.role.delete",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"id": { type: "integer" },
|
"id": { type: "integer" },
|
||||||
@@ -989,7 +991,7 @@ const userProperties = {
|
|||||||
|
|
||||||
messages.getUser = new Request({
|
messages.getUser = new Request({
|
||||||
type: "get_user",
|
type: "get_user",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.user.get",
|
permission: "core.user.get",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"name": { type: "string" },
|
"name": { type: "string" },
|
||||||
@@ -1000,7 +1002,7 @@ messages.getUser = new Request({
|
|||||||
|
|
||||||
messages.listUsers = new Request({
|
messages.listUsers = new Request({
|
||||||
type: "list_users",
|
type: "list_users",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.user.list",
|
permission: "core.user.list",
|
||||||
responseProperties: {
|
responseProperties: {
|
||||||
"list": {
|
"list": {
|
||||||
@@ -1016,7 +1018,7 @@ messages.listUsers = new Request({
|
|||||||
|
|
||||||
messages.setUserSubscriptions = new Request({
|
messages.setUserSubscriptions = new Request({
|
||||||
type: "set_user_subscriptions",
|
type: "set_user_subscriptions",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.user.subscribe",
|
permission: "core.user.subscribe",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"all": { type: "boolean" },
|
"all": { type: "boolean" },
|
||||||
@@ -1029,7 +1031,7 @@ messages.setUserSubscriptions = new Request({
|
|||||||
|
|
||||||
messages.createUser = new Request({
|
messages.createUser = new Request({
|
||||||
type: "create_user",
|
type: "create_user",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.user.create",
|
permission: "core.user.create",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"name": { type: "string" },
|
"name": { type: "string" },
|
||||||
@@ -1038,7 +1040,7 @@ messages.createUser = new Request({
|
|||||||
|
|
||||||
messages.revokeUserToken = new Request({
|
messages.revokeUserToken = new Request({
|
||||||
type: "revoke_user_token",
|
type: "revoke_user_token",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.user.revoke_token",
|
permission: "core.user.revoke_token",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"name": { type: "string" },
|
"name": { type: "string" },
|
||||||
@@ -1047,7 +1049,7 @@ messages.revokeUserToken = new Request({
|
|||||||
|
|
||||||
messages.updateUserRoles = new Request({
|
messages.updateUserRoles = new Request({
|
||||||
type: "update_user_roles",
|
type: "update_user_roles",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.user.update_roles",
|
permission: "core.user.update_roles",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"name": { type: "string" },
|
"name": { type: "string" },
|
||||||
@@ -1057,7 +1059,7 @@ messages.updateUserRoles = new Request({
|
|||||||
|
|
||||||
messages.setUserAdmin = new Request({
|
messages.setUserAdmin = new Request({
|
||||||
type: "set_user_admin",
|
type: "set_user_admin",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.user.set_admin",
|
permission: "core.user.set_admin",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"name": { type: "string" },
|
"name": { type: "string" },
|
||||||
@@ -1068,7 +1070,7 @@ messages.setUserAdmin = new Request({
|
|||||||
|
|
||||||
messages.setUserWhitelisted = new Request({
|
messages.setUserWhitelisted = new Request({
|
||||||
type: "set_user_whitelisted",
|
type: "set_user_whitelisted",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.user.set_whitelisted",
|
permission: "core.user.set_whitelisted",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"name": { type: "string" },
|
"name": { type: "string" },
|
||||||
@@ -1079,7 +1081,7 @@ messages.setUserWhitelisted = new Request({
|
|||||||
|
|
||||||
messages.setUserBanned = new Request({
|
messages.setUserBanned = new Request({
|
||||||
type: "set_user_banned",
|
type: "set_user_banned",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.user.set_banned",
|
permission: "core.user.set_banned",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"name": { type: "string" },
|
"name": { type: "string" },
|
||||||
@@ -1091,7 +1093,7 @@ messages.setUserBanned = new Request({
|
|||||||
|
|
||||||
messages.deleteUser = new Request({
|
messages.deleteUser = new Request({
|
||||||
type: "delete_user",
|
type: "delete_user",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.user.delete",
|
permission: "core.user.delete",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"name": { type: "string" },
|
"name": { type: "string" },
|
||||||
@@ -1100,12 +1102,12 @@ messages.deleteUser = new Request({
|
|||||||
|
|
||||||
messages.setLogSubscriptions = new Request({
|
messages.setLogSubscriptions = new Request({
|
||||||
type: "set_log_subscriptions",
|
type: "set_log_subscriptions",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.log.follow",
|
permission: "core.log.follow",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"all": { type: "boolean" },
|
"all": { type: "boolean" },
|
||||||
"master": { type: "boolean" },
|
"controller": { type: "boolean" },
|
||||||
"slave_ids": {
|
"host_ids": {
|
||||||
type: "array",
|
type: "array",
|
||||||
items: { type: "integer" },
|
items: { type: "integer" },
|
||||||
},
|
},
|
||||||
@@ -1119,12 +1121,12 @@ messages.setLogSubscriptions = new Request({
|
|||||||
|
|
||||||
messages.queryLog = new Request({
|
messages.queryLog = new Request({
|
||||||
type: "query_log",
|
type: "query_log",
|
||||||
links: ["control-master"],
|
links: ["control-controller"],
|
||||||
permission: "core.log.query",
|
permission: "core.log.query",
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"all": { type: "boolean" },
|
"all": { type: "boolean" },
|
||||||
"master": { type: "boolean" },
|
"controller": { type: "boolean" },
|
||||||
"slave_ids": {
|
"host_ids": {
|
||||||
type: "array",
|
type: "array",
|
||||||
items: { type: "integer" },
|
items: { type: "integer" },
|
||||||
},
|
},
|
||||||
@@ -1148,7 +1150,7 @@ messages.queryLog = new Request({
|
|||||||
// Internal requests
|
// Internal requests
|
||||||
messages.updateInstances = new Request({
|
messages.updateInstances = new Request({
|
||||||
type: "update_instances",
|
type: "update_instances",
|
||||||
links: ["slave-master"],
|
links: ["host-controller"],
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"instances": {
|
"instances": {
|
||||||
type: "array",
|
type: "array",
|
||||||
@@ -1169,7 +1171,7 @@ messages.updateInstances = new Request({
|
|||||||
|
|
||||||
messages.assignInstance = new Request({
|
messages.assignInstance = new Request({
|
||||||
type: "assign_instance",
|
type: "assign_instance",
|
||||||
links: ["master-slave"],
|
links: ["controller-host"],
|
||||||
requestProperties: {
|
requestProperties: {
|
||||||
"serialized_config": { type: "object" },
|
"serialized_config": { type: "object" },
|
||||||
},
|
},
|
||||||
@@ -1178,13 +1180,13 @@ messages.assignInstance = new Request({
|
|||||||
|
|
||||||
messages.unassignInstance = new Request({
|
messages.unassignInstance = new Request({
|
||||||
type: "unassigne_instance",
|
type: "unassigne_instance",
|
||||||
links: ["master-slave"],
|
links: ["controller-host"],
|
||||||
forwardTo: "instance",
|
forwardTo: "instance",
|
||||||
});
|
});
|
||||||
|
|
||||||
messages.getMetrics = new Request({
|
messages.getMetrics = new Request({
|
||||||
type: "get_metrics",
|
type: "get_metrics",
|
||||||
links: ["master-slave", "slave-instance"],
|
links: ["controller-host", "host-instance"],
|
||||||
responseProperties: {
|
responseProperties: {
|
||||||
"results": { type: "array" },
|
"results": { type: "array" },
|
||||||
},
|
},
|
||||||
@@ -1213,14 +1215,14 @@ class Event extends Message {
|
|||||||
* containing "<source>-<target>" specifications.
|
* containing "<source>-<target>" specifications.
|
||||||
* @param {?string} forwardTo -
|
* @param {?string} forwardTo -
|
||||||
* Optional target to forward this request to. Supported values are
|
* Optional target to forward this request to. Supported values are
|
||||||
* 'master' and 'instance'. If set to 'instance' an instance_id
|
* 'controller' and 'instance'. If set to 'instance' an instance_id
|
||||||
* property is implicity added to eventProperties.
|
* property is implicity added to eventProperties.
|
||||||
* @param {?string} broadcastTo -
|
* @param {?string} broadcastTo -
|
||||||
* Optional target to broadcast this event to. Only 'instance' is
|
* Optional target to broadcast this event to. Only 'instance' is
|
||||||
* currently supported. An event will only be broadcast towards
|
* currently supported. An event will only be broadcast towards
|
||||||
* links that are downstream, so sending an event set to instance
|
* links that are downstream, so sending an event set to instance
|
||||||
* broadcast that's sent to a slave will only be broadcast to that
|
* broadcast that's sent to a host will only be broadcast to that
|
||||||
* slave's instances.
|
* host's instances.
|
||||||
* @param {?Array<string>} eventRequired -
|
* @param {?Array<string>} eventRequired -
|
||||||
* List of properties required to be present in the event payload.
|
* List of properties required to be present in the event payload.
|
||||||
* Defaults to all.
|
* Defaults to all.
|
||||||
@@ -1247,7 +1249,7 @@ class Event extends Message {
|
|||||||
...eventProperties,
|
...eventProperties,
|
||||||
};
|
};
|
||||||
|
|
||||||
} else if (forwardTo !== "master" && forwardTo !== null) {
|
} else if (forwardTo !== "controller" && forwardTo !== null) {
|
||||||
throw new Error(`Invalid forwardTo value ${forwardTo}`);
|
throw new Error(`Invalid forwardTo value ${forwardTo}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1275,7 +1277,7 @@ class Event extends Message {
|
|||||||
* Set a the handler for the event on the given link if it's a target
|
* Set a the handler for the event on the given link if it's a target
|
||||||
* for the event.
|
* for the event.
|
||||||
*
|
*
|
||||||
* If forwardTo was set to 'master' the `forwardEventToMaster` method on
|
* If forwardTo was set to 'controller' the `forwardEventToController` method on
|
||||||
* the link is used as the default handler. If it was set to 'instance'
|
* the link is used as the default handler. If it was set to 'instance'
|
||||||
* the `forwardEventToInstance` method on the link is used by default.
|
* the `forwardEventToInstance` method on the link is used by default.
|
||||||
*
|
*
|
||||||
@@ -1297,15 +1299,15 @@ class Event extends Message {
|
|||||||
if (!handler) {
|
if (!handler) {
|
||||||
if (this.forwardTo === "instance") {
|
if (this.forwardTo === "instance") {
|
||||||
handler = link.forwardEventToInstance;
|
handler = link.forwardEventToInstance;
|
||||||
} else if (this.forwardTo === "master") {
|
} else if (this.forwardTo === "controller") {
|
||||||
handler = link.forwardEventToMaster;
|
handler = link.forwardEventToController;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.broadcastTo === "instance"
|
this.broadcastTo === "instance"
|
||||||
&& [
|
&& [
|
||||||
"instance-slave", "slave-master", "control-master", "master-slave",
|
"instance-host", "host-controller", "control-controller", "controller-host",
|
||||||
].includes(`${link.target}-${link.source}`)
|
].includes(`${link.target}-${link.source}`)
|
||||||
) {
|
) {
|
||||||
if (!handler) {
|
if (!handler) {
|
||||||
@@ -1352,7 +1354,7 @@ class Event extends Message {
|
|||||||
|
|
||||||
messages.debugWsMessage = new Event({
|
messages.debugWsMessage = new Event({
|
||||||
type: "debug_ws_message",
|
type: "debug_ws_message",
|
||||||
links: ["master-control"],
|
links: ["controller-control"],
|
||||||
eventProperties: {
|
eventProperties: {
|
||||||
"direction": { type: "string" },
|
"direction": { type: "string" },
|
||||||
"content": { type: "string" },
|
"content": { type: "string" },
|
||||||
@@ -1361,7 +1363,7 @@ messages.debugWsMessage = new Event({
|
|||||||
|
|
||||||
messages.accountUpdate = new Event({
|
messages.accountUpdate = new Event({
|
||||||
type: "account_update",
|
type: "account_update",
|
||||||
links: ["master-control"],
|
links: ["controller-control"],
|
||||||
eventRequired: [],
|
eventRequired: [],
|
||||||
eventProperties: {
|
eventProperties: {
|
||||||
"roles": {
|
"roles": {
|
||||||
@@ -1385,7 +1387,7 @@ messages.accountUpdate = new Event({
|
|||||||
|
|
||||||
messages.logMessage = new Event({
|
messages.logMessage = new Event({
|
||||||
type: "log_message",
|
type: "log_message",
|
||||||
links: ["slave-master", "master-control"],
|
links: ["host-controller", "controller-control"],
|
||||||
eventProperties: {
|
eventProperties: {
|
||||||
"info": {
|
"info": {
|
||||||
type: "object",
|
type: "object",
|
||||||
@@ -1398,16 +1400,16 @@ messages.logMessage = new Event({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
messages.slaveUpdate = new Event({
|
messages.hostUpdate = new Event({
|
||||||
type: "slave_update",
|
type: "host_update",
|
||||||
links: ["master-control"],
|
links: ["controller-control"],
|
||||||
eventProperties: slaveProperties,
|
eventProperties: hostProperties,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
messages.instanceInitialized = new Event({
|
messages.instanceInitialized = new Event({
|
||||||
type: "instance_initialized",
|
type: "instance_initialized",
|
||||||
links: ["instance-slave"],
|
links: ["instance-host"],
|
||||||
eventProperties: {
|
eventProperties: {
|
||||||
"instance_id": { type: "integer" },
|
"instance_id": { type: "integer" },
|
||||||
"plugins": {
|
"plugins": {
|
||||||
@@ -1418,7 +1420,7 @@ messages.instanceInitialized = new Event({
|
|||||||
});
|
});
|
||||||
messages.instanceStatusChanged = new Event({
|
messages.instanceStatusChanged = new Event({
|
||||||
type: "instance_status_changed",
|
type: "instance_status_changed",
|
||||||
links: ["instance-slave", "slave-master"],
|
links: ["instance-host", "host-controller"],
|
||||||
eventRequired: ["instance_id", "status"],
|
eventRequired: ["instance_id", "status"],
|
||||||
eventProperties: {
|
eventProperties: {
|
||||||
"instance_id": { type: "integer" },
|
"instance_id": { type: "integer" },
|
||||||
@@ -1431,14 +1433,14 @@ messages.instanceStatusChanged = new Event({
|
|||||||
|
|
||||||
messages.instanceUpdate = new Event({
|
messages.instanceUpdate = new Event({
|
||||||
type: "instance_update",
|
type: "instance_update",
|
||||||
links: ["master-control"],
|
links: ["controller-control"],
|
||||||
eventProperties: instanceProperties,
|
eventProperties: instanceProperties,
|
||||||
});
|
});
|
||||||
|
|
||||||
messages.saveListUpdate = new Event({
|
messages.saveListUpdate = new Event({
|
||||||
type: "save_list_update",
|
type: "save_list_update",
|
||||||
links: ["instance-slave", "slave-master", "master-control"],
|
links: ["instance-host", "host-controller", "controller-control"],
|
||||||
forwardTo: "master",
|
forwardTo: "controller",
|
||||||
eventProperties: {
|
eventProperties: {
|
||||||
"instance_id": { type: "integer" },
|
"instance_id": { type: "integer" },
|
||||||
"list": saveList,
|
"list": saveList,
|
||||||
@@ -1447,7 +1449,7 @@ messages.saveListUpdate = new Event({
|
|||||||
|
|
||||||
messages.modPackUpdate = new Event({
|
messages.modPackUpdate = new Event({
|
||||||
type: "mod_pack_update",
|
type: "mod_pack_update",
|
||||||
links: ["master-control"],
|
links: ["controller-control"],
|
||||||
eventProperties: {
|
eventProperties: {
|
||||||
"mod_pack": libData.ModPack.jsonSchema,
|
"mod_pack": libData.ModPack.jsonSchema,
|
||||||
},
|
},
|
||||||
@@ -1455,7 +1457,7 @@ messages.modPackUpdate = new Event({
|
|||||||
|
|
||||||
messages.modUpdate = new Event({
|
messages.modUpdate = new Event({
|
||||||
type: "mod_update",
|
type: "mod_update",
|
||||||
links: ["master-control"],
|
links: ["controller-control"],
|
||||||
eventProperties: {
|
eventProperties: {
|
||||||
"mod": libData.ModInfo.jsonSchema,
|
"mod": libData.ModInfo.jsonSchema,
|
||||||
},
|
},
|
||||||
@@ -1463,14 +1465,14 @@ messages.modUpdate = new Event({
|
|||||||
|
|
||||||
messages.userUpdate = new Event({
|
messages.userUpdate = new Event({
|
||||||
type: "user_update",
|
type: "user_update",
|
||||||
links: ["master-control"],
|
links: ["controller-control"],
|
||||||
eventRequired: userRequired,
|
eventRequired: userRequired,
|
||||||
eventProperties: userProperties,
|
eventProperties: userProperties,
|
||||||
});
|
});
|
||||||
|
|
||||||
messages.masterConnectionEvent = new Event({
|
messages.controllerConnectionEvent = new Event({
|
||||||
type: "master_connection_event",
|
type: "controller_connection_event",
|
||||||
links: ["slave-instance"],
|
links: ["host-instance"],
|
||||||
eventProperties: {
|
eventProperties: {
|
||||||
"event": { type: "string" },
|
"event": { type: "string" },
|
||||||
},
|
},
|
||||||
@@ -1478,7 +1480,7 @@ messages.masterConnectionEvent = new Event({
|
|||||||
|
|
||||||
messages.syncUserLists = new Event({
|
messages.syncUserLists = new Event({
|
||||||
type: "sync_user_lists",
|
type: "sync_user_lists",
|
||||||
links: ["master-slave"],
|
links: ["controller-host"],
|
||||||
eventProperties: {
|
eventProperties: {
|
||||||
"adminlist": {
|
"adminlist": {
|
||||||
type: "array",
|
type: "array",
|
||||||
@@ -1501,7 +1503,7 @@ messages.syncUserLists = new Event({
|
|||||||
|
|
||||||
messages.banlistUpdate = new Event({
|
messages.banlistUpdate = new Event({
|
||||||
type: "banlist_update",
|
type: "banlist_update",
|
||||||
links: ["master-slave", "slave-instance"],
|
links: ["controller-host", "host-instance"],
|
||||||
broadcastTo: "instance",
|
broadcastTo: "instance",
|
||||||
eventProperties: {
|
eventProperties: {
|
||||||
"name": { type: "string" },
|
"name": { type: "string" },
|
||||||
@@ -1512,7 +1514,7 @@ messages.banlistUpdate = new Event({
|
|||||||
|
|
||||||
messages.adminlistUpdate = new Event({
|
messages.adminlistUpdate = new Event({
|
||||||
type: "adminlist_update",
|
type: "adminlist_update",
|
||||||
links: ["master-slave", "slave-instance"],
|
links: ["controller-host", "host-instance"],
|
||||||
eventProperties: {
|
eventProperties: {
|
||||||
"name": { type: "string" },
|
"name": { type: "string" },
|
||||||
"admin": { type: "boolean" },
|
"admin": { type: "boolean" },
|
||||||
@@ -1522,7 +1524,7 @@ messages.adminlistUpdate = new Event({
|
|||||||
|
|
||||||
messages.whitelistUpdate = new Event({
|
messages.whitelistUpdate = new Event({
|
||||||
type: "whitelist_update",
|
type: "whitelist_update",
|
||||||
links: ["master-slave", "slave-instance"],
|
links: ["controller-host", "host-instance"],
|
||||||
eventProperties: {
|
eventProperties: {
|
||||||
"name": { type: "string" },
|
"name": { type: "string" },
|
||||||
"whitelisted": { type: "boolean" },
|
"whitelisted": { type: "boolean" },
|
||||||
@@ -1532,8 +1534,8 @@ messages.whitelistUpdate = new Event({
|
|||||||
|
|
||||||
messages.playerEvent = new Event({
|
messages.playerEvent = new Event({
|
||||||
type: "player_event",
|
type: "player_event",
|
||||||
links: ["instance-slave", "slave-master"],
|
links: ["instance-host", "host-controller"],
|
||||||
forwardTo: "master",
|
forwardTo: "controller",
|
||||||
eventRequired: ["instance_id", "type", "name"],
|
eventRequired: ["instance_id", "type", "name"],
|
||||||
eventProperties: {
|
eventProperties: {
|
||||||
"instance_id": { type: "integer" },
|
"instance_id": { type: "integer" },
|
||||||
|
|||||||
+13
-13
@@ -63,8 +63,8 @@ class WebConsoleFormat {
|
|||||||
|
|
||||||
transform(info, options) {
|
transform(info, options) {
|
||||||
let src = " ";
|
let src = " ";
|
||||||
if (info.slave_id !== undefined) {
|
if (info.host_id !== undefined) {
|
||||||
src += `s:${info.slave_name} - `;
|
src += `s:${info.host_name} - `;
|
||||||
}
|
}
|
||||||
if (info.instance_id !== undefined) {
|
if (info.instance_id !== undefined) {
|
||||||
src += `i:${info.instance_name}`;
|
src += `i:${info.instance_name}`;
|
||||||
@@ -88,12 +88,12 @@ class WebConsoleFormat {
|
|||||||
* @property {string} [max_level] -
|
* @property {string} [max_level] -
|
||||||
* Maximum log level to include. Higher levels are more verbose.
|
* Maximum log level to include. Higher levels are more verbose.
|
||||||
* @property {boolean} [all] -
|
* @property {boolean} [all] -
|
||||||
* Include log entries from master, all slaves and all instances.
|
* Include log entries from controller, all hosts and all instances.
|
||||||
* @property {boolean} [master] -
|
* @property {boolean} [controller] -
|
||||||
* Include log entries from the master server.
|
* Include log entries from the controller.
|
||||||
* @property {Array<number>} [slave_ids] -
|
* @property {Array<number>} [host_ids] -
|
||||||
* Include log entries for the given slaves and instances of those
|
* Include log entries for the given hosts and instances of those
|
||||||
* slaves by id.
|
* hosts by id.
|
||||||
* @property {Array<number>} [instance_ids] -
|
* @property {Array<number>} [instance_ids] -
|
||||||
* Include log entries for the given instances by id.
|
* Include log entries for the given instances by id.
|
||||||
*/
|
*/
|
||||||
@@ -107,7 +107,7 @@ class WebConsoleFormat {
|
|||||||
* filter returning true for log entries that match it.
|
* filter returning true for log entries that match it.
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
function logFilter({ all, master, slave_ids, instance_ids, max_level }) {
|
function logFilter({ all, controller, host_ids, instance_ids, max_level }) {
|
||||||
return info => {
|
return info => {
|
||||||
// Note: reversed to filter out undefined levels
|
// Note: reversed to filter out undefined levels
|
||||||
if (max_level && !(levels[info.level] <= levels[max_level])) {
|
if (max_level && !(levels[info.level] <= levels[max_level])) {
|
||||||
@@ -117,14 +117,14 @@ function logFilter({ all, master, slave_ids, instance_ids, max_level }) {
|
|||||||
if (all) {
|
if (all) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (master && info.slave_id === undefined) {
|
if (controller && info.host_id === undefined) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
slave_ids
|
host_ids
|
||||||
&& info.slave_id !== undefined
|
&& info.host_id !== undefined
|
||||||
&& info.instance_id === undefined
|
&& info.instance_id === undefined
|
||||||
&& slave_ids.includes(info.slave_id)
|
&& host_ids.includes(info.host_id)
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,8 +90,8 @@ class TerminalFormat {
|
|||||||
if (info.instance_name) {
|
if (info.instance_name) {
|
||||||
src += `i:${info.instance_name} `;
|
src += `i:${info.instance_name} `;
|
||||||
|
|
||||||
} else if (info.slave_name) {
|
} else if (info.host_name) {
|
||||||
src += `s:${info.slave_name} `;
|
src += `s:${info.host_name} `;
|
||||||
}
|
}
|
||||||
if (info.plugin) {
|
if (info.plugin) {
|
||||||
src += `${info.plugin}: `;
|
src += `${info.plugin}: `;
|
||||||
@@ -140,6 +140,7 @@ class LinkTransport extends Transport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const logFileGlob = /^[a-z]+-(\d{4}-\d{2}-\d{2})\.log$/;
|
const logFileGlob = /^[a-z]+-(\d{4}-\d{2}-\d{2})\.log$/;
|
||||||
|
const logIndexVersion = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keeps an index over a log directory to speed up queries to it
|
* Keeps an index over a log directory to speed up queries to it
|
||||||
@@ -150,15 +151,15 @@ class LogIndex {
|
|||||||
this.logDirectory = logDirectory;
|
this.logDirectory = logDirectory;
|
||||||
this.index = new Map();
|
this.index = new Map();
|
||||||
|
|
||||||
if (serialized.version !== 0) {
|
if (serialized.version !== logIndexVersion) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let [file, serializedEntry] of Object.entries(serialized.files)) {
|
for (let [file, serializedEntry] of Object.entries(serialized.files)) {
|
||||||
this.index.set(file, {
|
this.index.set(file, {
|
||||||
levels: new Set(serializedEntry.levels),
|
levels: new Set(serializedEntry.levels),
|
||||||
master: serializedEntry.master,
|
controller: serializedEntry.controller,
|
||||||
slave_ids: new Set(serializedEntry.slave_ids),
|
host_ids: new Set(serializedEntry.host_ids),
|
||||||
instance_ids: new Set(serializedEntry.instance_ids),
|
instance_ids: new Set(serializedEntry.instance_ids),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -166,15 +167,15 @@ class LogIndex {
|
|||||||
|
|
||||||
serialize() {
|
serialize() {
|
||||||
let serialized = {
|
let serialized = {
|
||||||
version: 0,
|
version: logIndexVersion,
|
||||||
files: {},
|
files: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
for (let [file, entry] of this.index) {
|
for (let [file, entry] of this.index) {
|
||||||
serialized.files[file] = {
|
serialized.files[file] = {
|
||||||
levels: [...entry.levels],
|
levels: [...entry.levels],
|
||||||
master: entry.master,
|
controller: entry.controller,
|
||||||
slave_ids: [...entry.slave_ids],
|
host_ids: [...entry.host_ids],
|
||||||
instance_ids: [...entry.instance_ids],
|
instance_ids: [...entry.instance_ids],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -224,8 +225,8 @@ class LogIndex {
|
|||||||
fileStream.pipe(lineStream);
|
fileStream.pipe(lineStream);
|
||||||
let entry = {
|
let entry = {
|
||||||
levels: new Set(),
|
levels: new Set(),
|
||||||
master: false,
|
controller: false,
|
||||||
slave_ids: new Set(),
|
host_ids: new Set(),
|
||||||
instance_ids: new Set(),
|
instance_ids: new Set(),
|
||||||
};
|
};
|
||||||
for await (let line of lineStream) {
|
for await (let line of lineStream) {
|
||||||
@@ -234,16 +235,16 @@ class LogIndex {
|
|||||||
info = JSON.parse(line);
|
info = JSON.parse(line);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
entry.levels.add("info");
|
entry.levels.add("info");
|
||||||
entry.master = true;
|
entry.controller = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (info.level) {
|
if (info.level) {
|
||||||
entry.levels.add(info.level);
|
entry.levels.add(info.level);
|
||||||
}
|
}
|
||||||
if (info.slave_id === undefined) {
|
if (info.host_id === undefined) {
|
||||||
entry.master = true;
|
entry.controller = true;
|
||||||
} else if (info.instance_id === undefined) {
|
} 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) {
|
if (info.instance_id !== undefined) {
|
||||||
entry.instance_ids.add(info.instance_id);
|
entry.instance_ids.add(info.instance_id);
|
||||||
@@ -279,7 +280,7 @@ class LogIndex {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
* true if the file may contain entries included by the filter.
|
* true if the file may contain entries included by the filter.
|
||||||
*/
|
*/
|
||||||
filterIncludesFile(file, { max_level, all, master, instance_ids, slave_ids }) {
|
filterIncludesFile(file, { max_level, all, controller, instance_ids, host_ids }) {
|
||||||
let entry = this.index.get(file);
|
let entry = this.index.get(file);
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
return true;
|
return true;
|
||||||
@@ -298,10 +299,10 @@ class LogIndex {
|
|||||||
if (all) {
|
if (all) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (master && entry.master) {
|
if (controller && entry.controller) {
|
||||||
return true;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
if (instance_ids && instance_ids.some(id => entry.instance_ids.has(id))) {
|
if (instance_ids && instance_ids.some(id => entry.instance_ids.has(id))) {
|
||||||
@@ -321,12 +322,12 @@ class LogIndex {
|
|||||||
* @property {string} [max_level] -
|
* @property {string} [max_level] -
|
||||||
* Maximum log level to include. Higher levels are more verbose.
|
* Maximum log level to include. Higher levels are more verbose.
|
||||||
* @property {boolean} [all] -
|
* @property {boolean} [all] -
|
||||||
* Include log entries from master, all slaves and all instances.
|
* Include log entries from controller, all hosts and all instances.
|
||||||
* @property {boolean} [master] -
|
* @property {boolean} [controller] -
|
||||||
* Include log entries from the master server.
|
* Include log entries from the controller.
|
||||||
* @property {Array<number>} [slave_ids] -
|
* @property {Array<number>} [host_ids] -
|
||||||
* Include log entries for the given slaves and instances of those
|
* Include log entries for the given hosts and instances of those
|
||||||
* slaves by id.
|
* hosts by id.
|
||||||
* @property {Array<number>} [instance_ids] -
|
* @property {Array<number>} [instance_ids] -
|
||||||
* Include log entries for the given instances by id.
|
* Include log entries for the given instances by id.
|
||||||
*/
|
*/
|
||||||
@@ -402,62 +403,6 @@ async function queryLog(logDirectory, filter, index) {
|
|||||||
return log;
|
return log;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function migrateLogs(log, directory, pattern) {
|
|
||||||
const dateRegExp = /^\d{4}-\d{2}-\d{2}/;
|
|
||||||
let lineStream = new libStream.LineSplitter({ readableObjectMode: true });
|
|
||||||
let fileStream = fs.createReadStream(log);
|
|
||||||
fileStream.pipe(lineStream);
|
|
||||||
|
|
||||||
let currentDate = null;
|
|
||||||
let output = null;
|
|
||||||
|
|
||||||
async function switchOutput(newOutputPath) {
|
|
||||||
if (output) {
|
|
||||||
output.end();
|
|
||||||
await finished(output);
|
|
||||||
}
|
|
||||||
|
|
||||||
output = fs.createWriteStream(newOutputPath, { flags: "ax" });
|
|
||||||
try {
|
|
||||||
await events.once(output, "open");
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log(`writing ${newOutputPath}`);
|
|
||||||
} catch (err) {
|
|
||||||
if (err.code === "EEXIST") {
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.warn(`Discarding logs for ${newDate} due to target logfile already existing`);
|
|
||||||
output = null;
|
|
||||||
} else {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for await (let line of lineStream) {
|
|
||||||
let info = {};
|
|
||||||
try {
|
|
||||||
info = JSON.parse(line);
|
|
||||||
} catch (err) {
|
|
||||||
// Ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof info.timestamp === "string" && dateRegExp.test(info.timestamp)) {
|
|
||||||
let newDate = info.timestamp.slice(0, 10);
|
|
||||||
// Only update date forward in time.
|
|
||||||
if (newDate !== currentDate && (!currentDate || newDate > currentDate)) {
|
|
||||||
await switchOutput(path.join(directory, pattern.replace("%DATE%", newDate)));
|
|
||||||
currentDate = newDate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (output) {
|
|
||||||
if (!output.write(Buffer.concat([line, Buffer.from("\n")]))) {
|
|
||||||
await events.once(output, "drain");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleUnhandledErrors() {
|
function handleUnhandledErrors() {
|
||||||
/* eslint-disable node/no-process-exit */
|
/* eslint-disable node/no-process-exit */
|
||||||
process.on("uncaughtException", err => {
|
process.on("uncaughtException", err => {
|
||||||
@@ -478,7 +423,6 @@ module.exports = {
|
|||||||
LogIndex,
|
LogIndex,
|
||||||
handleUnhandledErrors,
|
handleUnhandledErrors,
|
||||||
queryLog,
|
queryLog,
|
||||||
migrateLogs,
|
|
||||||
|
|
||||||
// for testing only
|
// for testing only
|
||||||
_formatServerOutput: formatServerOutput,
|
_formatServerOutput: formatServerOutput,
|
||||||
|
|||||||
+102
-102
@@ -7,9 +7,9 @@
|
|||||||
const helpers = require("./helpers");
|
const helpers = require("./helpers");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Conceptual base for master and instance plugins.
|
* Conceptual base for controller and instance plugins.
|
||||||
* @typedef {
|
* @typedef {
|
||||||
* module:lib/plugin.BaseMasterPlugin
|
* module:lib/plugin.BaseControllerPlugin
|
||||||
* |module:lib/plugin.BaseInstancePlugin
|
* |module:lib/plugin.BaseInstancePlugin
|
||||||
* |module:lib/plugin.BaseControlPlugin
|
* |module:lib/plugin.BaseControlPlugin
|
||||||
* } module:lib/plugin.BasePlugin
|
* } module:lib/plugin.BasePlugin
|
||||||
@@ -19,7 +19,7 @@ const helpers = require("./helpers");
|
|||||||
* Base class for instance plugins
|
* Base class for instance plugins
|
||||||
*
|
*
|
||||||
* Instance plugins are subclasses of this class which get instantiated by
|
* 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
|
* config. To be discovered the class must be exported under the name
|
||||||
* `InstancePlugin` in the module specified by the `instanceEntrypoint` in
|
* `InstancePlugin` in the module specified by the `instanceEntrypoint` in
|
||||||
* the plugin's info.js file.
|
* the plugin's info.js file.
|
||||||
@@ -31,7 +31,7 @@ const helpers = require("./helpers");
|
|||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
class BaseInstancePlugin {
|
class BaseInstancePlugin {
|
||||||
constructor(info, instance, slave) {
|
constructor(info, instance, host) {
|
||||||
/**
|
/**
|
||||||
* The plugin's own info module
|
* The plugin's own info module
|
||||||
*/
|
*/
|
||||||
@@ -39,19 +39,19 @@ class BaseInstancePlugin {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Instance the plugin started for
|
* Instance the plugin started for
|
||||||
* @type {module:slave/src/Instance}
|
* @type {module:host/src/Instance}
|
||||||
*/
|
*/
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Slave running the instance
|
* Host running the instance
|
||||||
*
|
*
|
||||||
* With the exepction of accessing the slave's config you should
|
* With the exepction of accessing the host's config you should
|
||||||
* avoid ineracting with the slave object directly.
|
* 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
|
* Logger for this plugin
|
||||||
@@ -150,23 +150,23 @@ class BaseInstancePlugin {
|
|||||||
async onOutput(parsed, line) { }
|
async onOutput(parsed, line) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when an event on the master connection happens
|
* Called when an event on the controller connection happens
|
||||||
*
|
*
|
||||||
* The event param may be one of connect, drop, resume and close and has
|
* The event param may be one of connect, drop, resume and close and has
|
||||||
* the following meaning:
|
* the following meaning:
|
||||||
*
|
*
|
||||||
* ##### connect
|
* ##### connect
|
||||||
*
|
*
|
||||||
* Invoked when a new connection to the master has been established.
|
* Invoked when a new connection to the controller has been established.
|
||||||
*
|
*
|
||||||
* ##### drop
|
* ##### 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
|
||||||
* master. Plugins should respond to this event by throtteling messages
|
* controller. Plugins should respond to this event by throtteling messages
|
||||||
* it is sending to the master to an absolute minimum.
|
* it is sending to the controller to an absolute minimum.
|
||||||
*
|
*
|
||||||
* Messages sent over a dropped master connection will get queued up in
|
* 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.
|
* re-established again.
|
||||||
*
|
*
|
||||||
* ##### resume
|
* ##### resume
|
||||||
@@ -176,29 +176,29 @@ class BaseInstancePlugin {
|
|||||||
*
|
*
|
||||||
* ##### close
|
* ##### close
|
||||||
*
|
*
|
||||||
* Invoked when the connection to the master has been closed. This
|
* Invoked when the connection to the controller has been closed. This
|
||||||
* typically means the master server has shut down. Plugins should not
|
* typically means the controller has shut down. Plugins should not
|
||||||
* send any messages that goes to or via the master server after the
|
* send any messages that goes to or via the controller after the
|
||||||
* connection has been closed and before a new one is established.
|
* connection has been closed and before a new one is established.
|
||||||
*
|
*
|
||||||
* @param {string} event - one of connect, drop, resume and close
|
* @param {string} event - one of connect, drop, resume and close
|
||||||
*/
|
*/
|
||||||
onMasterConnectionEvent(event) { }
|
onControllerConnectionEvent(event) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the master is preparing to disconnect from the slave
|
* Called when the controller is preparing to disconnect from the host
|
||||||
*
|
*
|
||||||
* Invoked when the master server has requested the disconnection from
|
* 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.
|
* shutting down.
|
||||||
*
|
*
|
||||||
* Plugins must stop sending messages to the master, or are forwarded
|
* Plugins must stop sending messages to the controller, or are forwarded
|
||||||
* via the master server after the prepare disconnect has been handled.
|
* via the controller after the prepare disconnect has been handled.
|
||||||
*
|
*
|
||||||
* @param {module:master/src/SlaveConnection} connection -
|
* @param {module:controller/src/HostConnection} connection -
|
||||||
* The connection to the slave preparing to disconnect.
|
* The connection to the host preparing to disconnect.
|
||||||
*/
|
*/
|
||||||
async onPrepareMasterDisconnect(connection) { }
|
async onPrepareControllerDisconnect(connection) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player joins or leaves the game
|
* Called when a player joins or leaves the game
|
||||||
@@ -284,25 +284,25 @@ class BaseInstancePlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for master plugins
|
* Base class for controller plugins
|
||||||
*
|
*
|
||||||
* Master plugins are subclasses of this class which get instantiated by
|
* Controller plugins are subclasses of this class which get instantiated by
|
||||||
* the master server on startup when the plugin is enabled in the config.
|
* the controller on startup when the plugin is enabled in the config.
|
||||||
* To be discovered the class must be exported under the name `MasterPlugin`
|
* To be discovered the class must be exported under the name `ControllerPlugin`
|
||||||
* in the module specified by the `masterEntrypoint` in the plugin's info.js
|
* in the module specified by the `controllerEntrypoint` in the plugin's info.js
|
||||||
* file.
|
* file.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
class BaseMasterPlugin {
|
class BaseControllerPlugin {
|
||||||
constructor(info, master, metrics, logger) {
|
constructor(info, controller, metrics, logger) {
|
||||||
this.info = info;
|
this.info = info;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Master server
|
* Controller
|
||||||
* @type {module:master/src/Master}
|
* @type {module:controller/src/Controller}
|
||||||
*/
|
*/
|
||||||
this.master = master;
|
this.controller = controller;
|
||||||
this.metrics = metrics;
|
this.metrics = metrics;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -323,13 +323,13 @@ class BaseMasterPlugin {
|
|||||||
/**
|
/**
|
||||||
* Called when the status of an instance changes
|
* Called when the status of an instance changes
|
||||||
*
|
*
|
||||||
* Invoked when the master server has changed the status of an instance
|
* 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:
|
* changed. The possible statuses that can be notified about are:
|
||||||
* - `unassigned:`: Instance is no longer asssigned to a slave.
|
* - `unassigned:`: Instance is no longer asssigned to a host.
|
||||||
* - `unknown`: Slave assigned to instance is offline.
|
* - `unknown`: Host assigned to instance is offline.
|
||||||
* - `stopped`: Instance is no longer running or was just assigned to a
|
* - `stopped`: Instance is no longer running or was just assigned to a
|
||||||
* slave.
|
* host.
|
||||||
* - `starting`: Instance is in the process of starting up.
|
* - `starting`: Instance is in the process of starting up.
|
||||||
* - `running`: Instance startup completed and is now running.
|
* - `running`: Instance startup completed and is now running.
|
||||||
* - `stopping`: Instance is in the processing stopping.
|
* - `stopping`: Instance is in the processing stopping.
|
||||||
@@ -338,21 +338,21 @@ class BaseMasterPlugin {
|
|||||||
* icons and locale data.
|
* icons and locale data.
|
||||||
* - `deleted`: Instance was deleted.
|
* - `deleted`: Instance was deleted.
|
||||||
*
|
*
|
||||||
* On master startup all known instances gets the status `unknown` if
|
* 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
|
||||||
* master and informs of the current status of its instances this hook
|
* controller and informs of the current status of its instances this hook
|
||||||
* is invoked for all those instances. You can detect this situation by
|
* 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.
|
* instances will again get the `unknown` status.
|
||||||
*
|
*
|
||||||
* When instances are created on the master they will notify of a 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
|
* 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
|
* 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
|
* 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
|
* the case of network outages if reconnect fails to re-establish the
|
||||||
* session between the master server and the slave.
|
* session between the controller and the host.
|
||||||
*
|
*
|
||||||
* @param {Object} instance - the instance that changed.
|
* @param {Object} instance - the instance that changed.
|
||||||
* @param {?string} prev - the previous status of the instance.
|
* @param {?string} prev - the previous status of the instance.
|
||||||
@@ -360,17 +360,17 @@ class BaseMasterPlugin {
|
|||||||
async onInstanceStatusChanged(instance, prev) { }
|
async onInstanceStatusChanged(instance, prev) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the value of a master config field changed.
|
* Called when the value of a controller config field changed.
|
||||||
*
|
*
|
||||||
* Invoked after the value of the config field given by `field` has
|
* Invoked after the value of the config field given by `field` has
|
||||||
* changed on the master.
|
* changed on the controller.
|
||||||
*
|
*
|
||||||
* @param {module:lib/config.ConfigGroup} group -
|
* @param {module:lib/config.ConfigGroup} group -
|
||||||
* The group who's field got changed.
|
* The group who's field got changed.
|
||||||
* @param {string} field - Name of the field that changed.
|
* @param {string} field - Name of the field that changed.
|
||||||
* @param {*} prev - The previous value of the field.
|
* @param {*} prev - The previous value of the field.
|
||||||
*/
|
*/
|
||||||
async onMasterConfigFieldChanged(group, field, prev) { }
|
async onControllerConfigFieldChanged(group, field, prev) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the value of an instance config field changed.
|
* Called when the value of an instance config field changed.
|
||||||
@@ -404,28 +404,28 @@ class BaseMasterPlugin {
|
|||||||
async onMetrics() { }
|
async onMetrics() { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the master server is shutting down
|
* Called when the controller is shutting down
|
||||||
*/
|
*/
|
||||||
async onShutdown() { }
|
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 event param may be one of connect, drop, resume and close and has
|
||||||
* the following meaning:
|
* the following meaning:
|
||||||
*
|
*
|
||||||
* ##### connect
|
* ##### connect
|
||||||
*
|
*
|
||||||
* Invoked when a new connection to the slave has been established.
|
* Invoked when a new connection to the host has been established.
|
||||||
*
|
*
|
||||||
* ##### drop
|
* ##### drop
|
||||||
*
|
*
|
||||||
* Invoked when a connection loss is detected between the master and a
|
* Invoked when a connection loss is detected between the controller and a
|
||||||
* slave. Plugins should respond to this event by throtteling messages
|
* host. Plugins should respond to this event by throtteling messages
|
||||||
* it is sending to the given slave connection to an absolute minimum.
|
* 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 master and sent all in one go when the connection is
|
* memory on the controller and sent all in one go when the connection is
|
||||||
* re-established again.
|
* re-established again.
|
||||||
*
|
*
|
||||||
* ##### resume
|
* ##### resume
|
||||||
@@ -435,13 +435,13 @@ class BaseMasterPlugin {
|
|||||||
*
|
*
|
||||||
* ##### close
|
* ##### close
|
||||||
*
|
*
|
||||||
* Invoked when the connection to the slave has been closed.
|
* Invoked when the connection to the host has been closed.
|
||||||
*
|
*
|
||||||
* @param {module:master/src/SlaveConnection} connection -
|
* @param {module:controller/src/HostConnection} connection -
|
||||||
* The connection the event occured on.
|
* The connection the event occured on.
|
||||||
* @param {string} event - one of connect, drop, resume and close
|
* @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
|
* Called when an avent on a control connection happens
|
||||||
@@ -455,13 +455,13 @@ class BaseMasterPlugin {
|
|||||||
*
|
*
|
||||||
* ##### drop
|
* ##### drop
|
||||||
*
|
*
|
||||||
* Invoked when a connection loss is detected between the master and a
|
* Invoked when a connection loss is detected between the controller and a
|
||||||
* control. Plugins should respond to this event by throtteling
|
* control. Plugins should respond to this event by throtteling
|
||||||
* messages it is sending to the given control connection to an absolute
|
* messages it is sending to the given control connection to an absolute
|
||||||
* minimum.
|
* minimum.
|
||||||
*
|
*
|
||||||
* Messages sent over a dropped control connection will get queued up in
|
* Messages sent over a dropped control connection will get queued up in
|
||||||
* memory on the master and sent all in one go when the connection is
|
* memory on the controller and sent all in one go when the connection is
|
||||||
* re-established again.
|
* re-established again.
|
||||||
*
|
*
|
||||||
* ##### resume
|
* ##### resume
|
||||||
@@ -473,25 +473,25 @@ class BaseMasterPlugin {
|
|||||||
*
|
*
|
||||||
* Invoked when the connection to the control has been closed.
|
* Invoked when the connection to the control has been closed.
|
||||||
*
|
*
|
||||||
* @param {module:master/src/ControlConnection} connection -
|
* @param {module:controller/src/ControlConnection} connection -
|
||||||
* The connection the event occured on.
|
* The connection the event occured on.
|
||||||
* @param {string} event - one of connect, drop, resume, and close.
|
* @param {string} event - one of connect, drop, resume, and close.
|
||||||
*/
|
*/
|
||||||
onControlConnectionEvent(connection, event) { }
|
onControlConnectionEvent(connection, event) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a slave is preparing to disconnect from the master
|
* Called when a host is preparing to disconnect from the controller
|
||||||
*
|
*
|
||||||
* Invoked when a slave has requested the disconnection from the master.
|
* Invoked when a host has requested the disconnection from the controller.
|
||||||
* This typically happens when it is in the process of shutting down.
|
* 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.
|
* prepare disconnect has been handled.
|
||||||
*
|
*
|
||||||
* @param {module:master/src/SlaveConnection} connection -
|
* @param {module:controller/src/HostConnection} connection -
|
||||||
* The connection to the slave preparing to disconnect.
|
* The connection to the host preparing to disconnect.
|
||||||
*/
|
*/
|
||||||
async onPrepareSlaveDisconnect(connection) { }
|
async onPrepareHostDisconnect(connection) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a mod pack is updated
|
* Called when a mod pack is updated
|
||||||
@@ -507,7 +507,7 @@ class BaseMasterPlugin {
|
|||||||
async onModPackUpdated(modPack) { }
|
async onModPackUpdated(modPack) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a mod stored on the master server is updated
|
* Called when a mod stored on the controller is updated
|
||||||
*
|
*
|
||||||
* Invoked when a mod has been added, updated or deleted from the pool
|
* Invoked when a mod has been added, updated or deleted from the pool
|
||||||
* of shared mods stored on the cluster.
|
* of shared mods stored on the cluster.
|
||||||
@@ -536,22 +536,22 @@ class BaseMasterPlugin {
|
|||||||
async onPlayerEvent(instance, event) { }
|
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 master server.
|
* Sends the given event to all hosts connected to the controller.
|
||||||
* This does not include slaves that are in the process of closing the
|
* This does not include hosts that are in the process of closing the
|
||||||
* connection, which typically happens when they are shutting down.
|
* connection, which typically happens when they are shutting down.
|
||||||
*
|
*
|
||||||
* @param {module:lib/link.Event} event - Event to send
|
* @param {module:lib/link.Event} event - Event to send
|
||||||
* @param {Object} data - Data ta pass with the event.
|
* @param {Object} data - Data ta pass with the event.
|
||||||
*/
|
*/
|
||||||
broadcastEventToSlaves(event, data={}) {
|
broadcastEventToHosts(event, data={}) {
|
||||||
for (let slaveConnection of this.master.wsServer.slaveConnections.values()) {
|
for (let hostConnection of this.controller.wsServer.hostConnections.values()) {
|
||||||
if (
|
if (
|
||||||
!slaveConnection.connector.closing
|
!hostConnection.connector.closing
|
||||||
&& (!event.plugin || slaveConnection.plugins.has(event.plugin))
|
&& (!event.plugin || hostConnection.plugins.has(event.plugin))
|
||||||
) {
|
) {
|
||||||
event.send(slaveConnection, data);
|
event.send(hostConnection, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -660,8 +660,8 @@ class BaseWebPlugin {
|
|||||||
this.info = info;
|
this.info = info;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Control link to the master server, not available until the
|
* Control link to the controller, not available until the
|
||||||
* connect event in onMasterConnectionEvent is signaled.
|
* connect event in onControllerConnectionEvent is signaled.
|
||||||
* @type {?module:lib/link.Link}
|
* @type {?module:lib/link.Link}
|
||||||
*/
|
*/
|
||||||
this.control = null;
|
this.control = null;
|
||||||
@@ -700,13 +700,13 @@ class BaseWebPlugin {
|
|||||||
* component extra.
|
* component extra.
|
||||||
*
|
*
|
||||||
* @type {object}
|
* @type {object}
|
||||||
* @property {React.ComponentType} MasterPage -
|
* @property {React.ComponentType} ControllerPage -
|
||||||
* Placed at the end of the master page.
|
* Placed at the end of the controller page.
|
||||||
* @property {React.ComponentType} SlavesPage -
|
* @property {React.ComponentType} HostsPage -
|
||||||
* Placed at the end of the slaves list page.
|
* Placed at the end of the hosts list page.
|
||||||
* @property {React.ComponentType} SlaveViewPage -
|
* @property {React.ComponentType} HostViewPage -
|
||||||
* Placed at the end of each slave page. Takes a `slave` param
|
* Placed at the end of each host page. Takes a `host` param
|
||||||
* which is the slave the page is displayed for.
|
* which is the host the page is displayed for.
|
||||||
* @property {React.ComponentType} InstancesPage -
|
* @property {React.ComponentType} InstancesPage -
|
||||||
* Placed at the end of the instance list page.
|
* Placed at the end of the instance list page.
|
||||||
* @property {React.ComponentType} InstanceViewPage -
|
* @property {React.ComponentType} InstanceViewPage -
|
||||||
@@ -732,22 +732,22 @@ class BaseWebPlugin {
|
|||||||
async init() { }
|
async init() { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when an event on the master connection happens
|
* Called when an event on the controller connection happens
|
||||||
*
|
*
|
||||||
* The event param may be one of connect, drop, resume and close and has
|
* The event param may be one of connect, drop, resume and close and has
|
||||||
* the following meaning:
|
* the following meaning:
|
||||||
*
|
*
|
||||||
* ##### connect
|
* ##### connect
|
||||||
*
|
*
|
||||||
* Invoked when a new connection to the master has been established.
|
* Invoked when a new connection to the controller has been established.
|
||||||
*
|
*
|
||||||
* ##### drop
|
* ##### drop
|
||||||
*
|
*
|
||||||
* Invoked when a connection loss is detected between the control link
|
* Invoked when a connection loss is detected between the control link
|
||||||
* and the master. Plugins should respond to this event by throtteling
|
* and the controller. Plugins should respond to this event by throtteling
|
||||||
* messages it is sending to the master to an absolute minimum.
|
* messages it is sending to the controller to an absolute minimum.
|
||||||
*
|
*
|
||||||
* Messages sent over a dropped master connection will get queued up in
|
* Messages sent over a dropped controller connection will get queued up in
|
||||||
* memory in the browser and sent all in one go when the connection is
|
* memory in the browser and sent all in one go when the connection is
|
||||||
* re-established again.
|
* re-established again.
|
||||||
*
|
*
|
||||||
@@ -758,14 +758,14 @@ class BaseWebPlugin {
|
|||||||
*
|
*
|
||||||
* ##### close
|
* ##### close
|
||||||
*
|
*
|
||||||
* Invoked when the connection to the master has been closed. This
|
* Invoked when the connection to the controller has been closed. This
|
||||||
* typically means the master server has shut down. Plugins should not
|
* typically means the controller has shut down. Plugins should not
|
||||||
* send any messages that goes to or via the master server after the
|
* send any messages that goes to or via the controller after the
|
||||||
* connection has been closed and before a new one is established.
|
* connection has been closed and before a new one is established.
|
||||||
*
|
*
|
||||||
* @param {string} event - one of connect, drop, resume and close
|
* @param {string} event - one of connect, drop, resume and close
|
||||||
*/
|
*/
|
||||||
onMasterConnectionEvent(event) { }
|
onControllerConnectionEvent(event) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -840,7 +840,7 @@ async function invokeHook(plugins, hook, ...args) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
BaseInstancePlugin,
|
BaseInstancePlugin,
|
||||||
BaseMasterPlugin,
|
BaseControllerPlugin,
|
||||||
BaseControlPlugin,
|
BaseControlPlugin,
|
||||||
BaseWebPlugin,
|
BaseWebPlugin,
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ function loadPluginClass(entrypointName, className, pluginClass, pluginInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load master plugin class of a plugin
|
* Load controller plugin class of a plugin
|
||||||
*
|
*
|
||||||
* @param {Object} pluginInfo -
|
* @param {Object} pluginInfo -
|
||||||
* Plugin info object returned from {@link
|
* Plugin info object returned from {@link
|
||||||
@@ -74,8 +74,8 @@ function loadPluginClass(entrypointName, className, pluginClass, pluginInfo) {
|
|||||||
* @returns {Promise<function>} plugin class
|
* @returns {Promise<function>} plugin class
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
async function loadMasterPluginClass(pluginInfo) {
|
async function loadControllerPluginClass(pluginInfo) {
|
||||||
return loadPluginClass("masterEntrypoint", "MasterPlugin", libPlugin.BaseMasterPlugin, pluginInfo);
|
return loadPluginClass("controllerEntrypoint", "ControllerPlugin", libPlugin.BaseControllerPlugin, pluginInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,7 +106,7 @@ async function loadControlPluginClass(pluginInfo) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
loadPluginInfos,
|
loadPluginInfos,
|
||||||
loadMasterPluginClass,
|
loadControllerPluginClass,
|
||||||
loadInstancePluginClass,
|
loadInstancePluginClass,
|
||||||
loadControlPluginClass,
|
loadControlPluginClass,
|
||||||
};
|
};
|
||||||
@@ -168,7 +168,7 @@ const clientHandshake = ajv.compile({
|
|||||||
anyOf: [
|
anyOf: [
|
||||||
{
|
{
|
||||||
properties: {
|
properties: {
|
||||||
"type": { const: "register_slave" },
|
"type": { const: "register_host" },
|
||||||
"data": {
|
"data": {
|
||||||
additionalProperties: false,
|
additionalProperties: false,
|
||||||
required: ["token", "agent", "version", "name", "id", "plugins"],
|
required: ["token", "agent", "version", "name", "id", "plugins"],
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Implementation of commands shared between master/slave/ctl.
|
* Implementation of commands shared between controller/host/ctl.
|
||||||
* @module lib/shared_commands
|
* @module lib/shared_commands
|
||||||
*/
|
*/
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|||||||
+28
-28
@@ -350,41 +350,41 @@ definePermission({
|
|||||||
definePermission({
|
definePermission({
|
||||||
name: "core.control.connect",
|
name: "core.control.connect",
|
||||||
title: "Connect to WebSocket",
|
title: "Connect to WebSocket",
|
||||||
description: "Connect to the master's WebSocket control interface.",
|
description: "Connect to the controller's WebSocket control interface.",
|
||||||
grantByDefault: true,
|
grantByDefault: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
definePermission({
|
definePermission({
|
||||||
name: "core.master.get_config",
|
name: "core.controller.get_config",
|
||||||
title: "Get master config",
|
title: "Get controller config",
|
||||||
description: "Get the config of master.",
|
description: "Get the config of controller.",
|
||||||
});
|
});
|
||||||
definePermission({
|
definePermission({
|
||||||
name: "core.master.update_config",
|
name: "core.controller.update_config",
|
||||||
title: "Modify master config",
|
title: "Modify controller config",
|
||||||
description: "Modify the master config or entries of the master config.",
|
description: "Modify the controller config or entries of the controller config.",
|
||||||
});
|
});
|
||||||
definePermission({
|
definePermission({
|
||||||
name: "core.slave.list",
|
name: "core.host.list",
|
||||||
title: "List slaves",
|
title: "List hosts",
|
||||||
description: "Get the full list of slaves in the cluster.",
|
description: "Get the full list of hosts in the cluster.",
|
||||||
grantByDefault: true,
|
grantByDefault: true,
|
||||||
});
|
});
|
||||||
definePermission({
|
definePermission({
|
||||||
name: "core.slave.subscribe",
|
name: "core.host.subscribe",
|
||||||
title: "Subscribe to slave updates",
|
title: "Subscribe to host updates",
|
||||||
description: "Subscribe to be notified on updates on the details of slaves.",
|
description: "Subscribe to be notified on updates on the details of hosts.",
|
||||||
grantByDefault: true,
|
grantByDefault: true,
|
||||||
});
|
});
|
||||||
definePermission({
|
definePermission({
|
||||||
name: "core.slave.generate_token",
|
name: "core.host.generate_token",
|
||||||
title: "Generate slave token",
|
title: "Generate host token",
|
||||||
description: "Generate tokens for slaves to connect to the cluster with.",
|
description: "Generate tokens for hosts to connect to the cluster with.",
|
||||||
});
|
});
|
||||||
definePermission({
|
definePermission({
|
||||||
name: "core.slave.create_config",
|
name: "core.host.create_config",
|
||||||
title: "Create slave config",
|
title: "Create host config",
|
||||||
description: "Create slave configs via the master server.",
|
description: "Create host configs via the controller.",
|
||||||
});
|
});
|
||||||
|
|
||||||
definePermission({
|
definePermission({
|
||||||
@@ -408,7 +408,7 @@ definePermission({
|
|||||||
definePermission({
|
definePermission({
|
||||||
name: "core.instance.create",
|
name: "core.instance.create",
|
||||||
title: "Create instance",
|
title: "Create instance",
|
||||||
description: "Create new instances on the master server.",
|
description: "Create new instances on the controller.",
|
||||||
});
|
});
|
||||||
definePermission({
|
definePermission({
|
||||||
name: "core.instance.get_config",
|
name: "core.instance.get_config",
|
||||||
@@ -423,7 +423,7 @@ definePermission({
|
|||||||
definePermission({
|
definePermission({
|
||||||
name: "core.instance.assign",
|
name: "core.instance.assign",
|
||||||
title: "Assign instance",
|
title: "Assign instance",
|
||||||
description: "Assign or reassign instances to a slave.",
|
description: "Assign or reassign instances to a host.",
|
||||||
});
|
});
|
||||||
definePermission({
|
definePermission({
|
||||||
name: "core.instance.save.list",
|
name: "core.instance.save.list",
|
||||||
@@ -473,7 +473,7 @@ definePermission({
|
|||||||
definePermission({
|
definePermission({
|
||||||
name: "core.instance.export_data",
|
name: "core.instance.export_data",
|
||||||
title: "Export locale and icons",
|
title: "Export locale and icons",
|
||||||
description: "Export the the locale and icons from an instance and upload it to the master.",
|
description: "Export the the locale and icons from an instance and upload it to the controller.",
|
||||||
});
|
});
|
||||||
definePermission({
|
definePermission({
|
||||||
name: "core.instance.extract_players",
|
name: "core.instance.extract_players",
|
||||||
@@ -553,13 +553,13 @@ definePermission({
|
|||||||
definePermission({
|
definePermission({
|
||||||
name: "core.mod.list",
|
name: "core.mod.list",
|
||||||
title: "List mods",
|
title: "List mods",
|
||||||
description: "Get the full list of mods stored on the master.",
|
description: "Get the full list of mods stored on the controller.",
|
||||||
grantByDefault: true,
|
grantByDefault: true,
|
||||||
});
|
});
|
||||||
definePermission({
|
definePermission({
|
||||||
name: "core.mod.search",
|
name: "core.mod.search",
|
||||||
title: "Search mods",
|
title: "Search mods",
|
||||||
description: "Search through the list of mods stored on the master.",
|
description: "Search through the list of mods stored on the controller.",
|
||||||
grantByDefault: true,
|
grantByDefault: true,
|
||||||
});
|
});
|
||||||
definePermission({
|
definePermission({
|
||||||
@@ -571,18 +571,18 @@ definePermission({
|
|||||||
definePermission({
|
definePermission({
|
||||||
name: "core.mod.upload",
|
name: "core.mod.upload",
|
||||||
title: "Upload mod",
|
title: "Upload mod",
|
||||||
description: "Upload mods to the master.",
|
description: "Upload mods to the controller.",
|
||||||
});
|
});
|
||||||
definePermission({
|
definePermission({
|
||||||
name: "core.mod.download",
|
name: "core.mod.download",
|
||||||
title: "Download mod",
|
title: "Download mod",
|
||||||
description: "Download mods stored on the master.",
|
description: "Download mods stored on the controller.",
|
||||||
grantByDefault: true,
|
grantByDefault: true,
|
||||||
});
|
});
|
||||||
definePermission({
|
definePermission({
|
||||||
name: "core.mod.delete",
|
name: "core.mod.delete",
|
||||||
title: "Delete mod",
|
title: "Delete mod",
|
||||||
description: "Delete mods stored on the master.",
|
description: "Delete mods stored on the controller.",
|
||||||
});
|
});
|
||||||
|
|
||||||
definePermission({
|
definePermission({
|
||||||
@@ -687,7 +687,7 @@ definePermission({
|
|||||||
definePermission({
|
definePermission({
|
||||||
name: "core.debug.dump_ws",
|
name: "core.debug.dump_ws",
|
||||||
title: "Dump WebSocket",
|
title: "Dump WebSocket",
|
||||||
description: "Dump all WebSocket communicatation from the master.",
|
description: "Dump all WebSocket communicatation from the controller.",
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@@ -25,18 +25,18 @@ function ErrorCard(props) {
|
|||||||
|
|
||||||
export default function App(props) {
|
export default function App(props) {
|
||||||
let [connected, setConnected] = useState(false);
|
let [connected, setConnected] = useState(false);
|
||||||
let [token, setToken] = useState(localStorage.getItem("master_token") || null);
|
let [token, setToken] = useState(localStorage.getItem("controller_token") || null);
|
||||||
let connector = props.control.connector;
|
let connector = props.control.connector;
|
||||||
|
|
||||||
function clearToken() {
|
function clearToken() {
|
||||||
setToken(null);
|
setToken(null);
|
||||||
connector.token = null;
|
connector.token = null;
|
||||||
localStorage.removeItem("master_token");
|
localStorage.removeItem("controller_token");
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function onConnect() {
|
function onConnect() {
|
||||||
localStorage.setItem("master_token", token);
|
localStorage.setItem("controller_token", token);
|
||||||
setConnected(true);
|
setConnected(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ import { libLink } from "@clusterio/lib";
|
|||||||
|
|
||||||
import ControlContext from "./ControlContext";
|
import ControlContext from "./ControlContext";
|
||||||
import { notifyErrorHandler } from "../util/notify";
|
import { notifyErrorHandler } from "../util/notify";
|
||||||
import { useSlaveList } from "../model/slave";
|
import { useHostList } from "../model/host";
|
||||||
|
|
||||||
const { Paragraph } = Typography;
|
const { Paragraph } = Typography;
|
||||||
|
|
||||||
|
|
||||||
export default function AssignInstanceModal(props) {
|
export default function AssignInstanceModal(props) {
|
||||||
let [visible, setVisible] = useState(false);
|
let [visible, setVisible] = useState(false);
|
||||||
let [slaveList] = useSlaveList();
|
let [hostList] = useHostList();
|
||||||
let [applying, setApplying] = useState(false);
|
let [applying, setApplying] = useState(false);
|
||||||
let [form] = Form.useForm();
|
let [form] = Form.useForm();
|
||||||
let control = useContext(ControlContext);
|
let control = useContext(ControlContext);
|
||||||
@@ -22,20 +22,20 @@ export default function AssignInstanceModal(props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleAssign() {
|
function handleAssign() {
|
||||||
let slaveId = form.getFieldValue("slave");
|
let hostId = form.getFieldValue("host");
|
||||||
if (slaveId === undefined) {
|
if (hostId === undefined) {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slaveId === "null") {
|
if (hostId === "null") {
|
||||||
slaveId = null;
|
hostId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
setApplying(true);
|
setApplying(true);
|
||||||
libLink.messages.assignInstanceCommand.send(control, {
|
libLink.messages.assignInstanceCommand.send(control, {
|
||||||
instance_id: props.id,
|
instance_id: props.id,
|
||||||
slave_id: slaveId,
|
host_id: hostId,
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
if (props.onFinish) {
|
if (props.onFinish) {
|
||||||
@@ -66,24 +66,24 @@ export default function AssignInstanceModal(props) {
|
|||||||
destroyOnClose
|
destroyOnClose
|
||||||
>
|
>
|
||||||
<Paragraph style={{ maxWidth: "30em" }}>
|
<Paragraph style={{ maxWidth: "30em" }}>
|
||||||
Select a Slave to assign this instance to. Assignment
|
Select a Host to assign this instance to. Assignment
|
||||||
creates the necessary files on the slave to start up
|
creates the necessary files on the host to start up
|
||||||
the instance. Note that reassigning an instance from
|
the instance. Note that reassigning an instance from
|
||||||
one slave to another will not move the server save over.
|
one host to another will not move the server save over.
|
||||||
</Paragraph>
|
</Paragraph>
|
||||||
<Form form={form} initialValues={{ slave: props.slaveId === null ? "null" : props.slaveId }}>
|
<Form form={form} initialValues={{ host: props.hostId === null ? "null" : props.hostId }}>
|
||||||
<Form.Item name="slave" label="Slave">
|
<Form.Item name="host" label="Host">
|
||||||
<Select>
|
<Select>
|
||||||
<Select.Option value={"null"}>
|
<Select.Option value={"null"}>
|
||||||
<Typography.Text italic>Unassigned</Typography.Text>
|
<Typography.Text italic>Unassigned</Typography.Text>
|
||||||
</Select.Option>
|
</Select.Option>
|
||||||
{slaveList.map((slave) => <Select.Option
|
{hostList.map((host) => <Select.Option
|
||||||
key={slave["id"]}
|
key={host["id"]}
|
||||||
value={slave["id"]}
|
value={host["id"]}
|
||||||
disabled={!slave["connected"]}
|
disabled={!host["connected"]}
|
||||||
>
|
>
|
||||||
{slave["name"]}
|
{host["name"]}
|
||||||
{!slave["connected"] && " (offline)"}
|
{!host["connected"] && " (offline)"}
|
||||||
</Select.Option>)}
|
</Select.Option>)}
|
||||||
</Select>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|||||||
+5
-5
@@ -6,16 +6,16 @@ import BaseConfigTree from "./BaseConfigTree";
|
|||||||
import ControlContext from "./ControlContext";
|
import ControlContext from "./ControlContext";
|
||||||
|
|
||||||
|
|
||||||
export default function MasterConfigTree(props) {
|
export default function ControllerConfigTree(props) {
|
||||||
let control = useContext(ControlContext);
|
let control = useContext(ControlContext);
|
||||||
|
|
||||||
async function retrieveConfig() {
|
async function retrieveConfig() {
|
||||||
let result = await libLink.messages.getMasterConfig.send(control);
|
let result = await libLink.messages.getControllerConfig.send(control);
|
||||||
return result.serialized_config;
|
return result.serialized_config;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setField(field, value) {
|
async function setField(field, value) {
|
||||||
await libLink.messages.setMasterConfigField.send(control, {
|
await libLink.messages.setControllerConfigField.send(control, {
|
||||||
field,
|
field,
|
||||||
value: String(value),
|
value: String(value),
|
||||||
});
|
});
|
||||||
@@ -30,11 +30,11 @@ export default function MasterConfigTree(props) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await libLink.messages.setMasterConfigProp.send(control, data);
|
await libLink.messages.setControllerConfigProp.send(control, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return <BaseConfigTree
|
return <BaseConfigTree
|
||||||
ConfigClass={libConfig.MasterConfig}
|
ConfigClass={libConfig.ControllerConfig}
|
||||||
retrieveConfig={retrieveConfig}
|
retrieveConfig={retrieveConfig}
|
||||||
setField={setField}
|
setField={setField}
|
||||||
setProp={setProp}
|
setProp={setProp}
|
||||||
+7
-7
@@ -4,22 +4,22 @@ import { Typography } from "antd";
|
|||||||
import PluginExtra from "./PluginExtra";
|
import PluginExtra from "./PluginExtra";
|
||||||
import LogConsole from "./LogConsole";
|
import LogConsole from "./LogConsole";
|
||||||
import { useAccount } from "../model/account";
|
import { useAccount } from "../model/account";
|
||||||
import MasterConfigTree from "./MasterConfigTree";
|
import ControllerConfigTree from "./ControllerConfigTree";
|
||||||
import PageLayout from "./PageLayout";
|
import PageLayout from "./PageLayout";
|
||||||
|
|
||||||
const { Title } = Typography;
|
const { Title } = Typography;
|
||||||
|
|
||||||
|
|
||||||
export default function MasterPage() {
|
export default function ControllerPage() {
|
||||||
let account = useAccount();
|
let account = useAccount();
|
||||||
|
|
||||||
return <PageLayout nav={[{ name: "Master" }]}>
|
return <PageLayout nav={[{ name: "Controller" }]}>
|
||||||
<h2>Master</h2>
|
<h2>Controller</h2>
|
||||||
{account.hasPermission("core.log.follow") && <>
|
{account.hasPermission("core.log.follow") && <>
|
||||||
<Title level={5} style={{ marginTop: 16 }}>Console</Title>
|
<Title level={5} style={{ marginTop: 16 }}>Console</Title>
|
||||||
<LogConsole master={true} />
|
<LogConsole controller={true} />
|
||||||
</>}
|
</>}
|
||||||
{account.hasPermission("core.master.get_config") && <MasterConfigTree />}
|
{account.hasPermission("core.controller.get_config") && <ControllerConfigTree />}
|
||||||
<PluginExtra component="MasterPage" />
|
<PluginExtra component="ControllerPage" />
|
||||||
</PageLayout>;
|
</PageLayout>;
|
||||||
};
|
};
|
||||||
+19
-19
@@ -6,61 +6,61 @@ import InstanceList from "./InstanceList";
|
|||||||
import LogConsole from "./LogConsole";
|
import LogConsole from "./LogConsole";
|
||||||
import { useAccount } from "../model/account";
|
import { useAccount } from "../model/account";
|
||||||
import { useInstanceList } from "../model/instance";
|
import { useInstanceList } from "../model/instance";
|
||||||
import { useSlave } from "../model/slave";
|
import { useHost } from "../model/host";
|
||||||
import PageLayout from "./PageLayout";
|
import PageLayout from "./PageLayout";
|
||||||
import PluginExtra from "./PluginExtra";
|
import PluginExtra from "./PluginExtra";
|
||||||
|
|
||||||
const { Title } = Typography;
|
const { Title } = Typography;
|
||||||
|
|
||||||
|
|
||||||
export default function SlaveViewPage(props) {
|
export default function HostViewPage(props) {
|
||||||
let params = useParams();
|
let params = useParams();
|
||||||
let slaveId = Number(params.id);
|
let hostId = Number(params.id);
|
||||||
let account = useAccount();
|
let account = useAccount();
|
||||||
let [instanceList] = useInstanceList();
|
let [instanceList] = useInstanceList();
|
||||||
let [slave] = useSlave(slaveId);
|
let [host] = useHost(hostId);
|
||||||
|
|
||||||
instanceList = instanceList.filter(instance => instance["assigned_slave"] === slaveId);
|
instanceList = instanceList.filter(instance => instance["assigned_host"] === hostId);
|
||||||
|
|
||||||
let nav = [{ name: "Slaves", path: "/slaves" }, { name: slave.name || slaveId }];
|
let nav = [{ name: "Hosts", path: "/hosts" }, { name: host.name || hostId }];
|
||||||
if (slave.loading) {
|
if (host.loading) {
|
||||||
return <PageLayout nav={nav}><Spin size="large" /></PageLayout>;
|
return <PageLayout nav={nav}><Spin size="large" /></PageLayout>;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slave.missing) {
|
if (host.missing) {
|
||||||
return <PageLayout nav={nav}>
|
return <PageLayout nav={nav}>
|
||||||
<PageHeader
|
<PageHeader
|
||||||
className="site-page-header"
|
className="site-page-header"
|
||||||
title={slaveId}
|
title={hostId}
|
||||||
/>
|
/>
|
||||||
<p>Slave with id {slaveId} was not found on the master server.</p>
|
<p>Host with id {hostId} was not found on the controller.</p>
|
||||||
</PageLayout>;
|
</PageLayout>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <PageLayout nav={nav}>
|
return <PageLayout nav={nav}>
|
||||||
<PageHeader
|
<PageHeader
|
||||||
className="site-page-header"
|
className="site-page-header"
|
||||||
title={slave.name || slaveId}
|
title={host.name || hostId}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Descriptions bordered size="small" column={{ xs: 1, sm: 2, xl: 4 }}>
|
<Descriptions bordered size="small" column={{ xs: 1, sm: 2, xl: 4 }}>
|
||||||
<Descriptions.Item label="Name">{slave["name"]}</Descriptions.Item>
|
<Descriptions.Item label="Name">{host["name"]}</Descriptions.Item>
|
||||||
<Descriptions.Item label="Connected">
|
<Descriptions.Item label="Connected">
|
||||||
<Tag color={slave["connected"] ? "#389e0d" : "#cf1322"}>
|
<Tag color={host["connected"] ? "#389e0d" : "#cf1322"}>
|
||||||
{slave["connected"] ? "Connected" : "Disconnected"}
|
{host["connected"] ? "Connected" : "Disconnected"}
|
||||||
</Tag>
|
</Tag>
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="Agent">{slave["agent"]}</Descriptions.Item>
|
<Descriptions.Item label="Agent">{host["agent"]}</Descriptions.Item>
|
||||||
<Descriptions.Item label="Version">{slave["version"]}</Descriptions.Item>
|
<Descriptions.Item label="Version">{host["version"]}</Descriptions.Item>
|
||||||
</Descriptions>
|
</Descriptions>
|
||||||
{account.hasPermission("core.instance.list") && <>
|
{account.hasPermission("core.instance.list") && <>
|
||||||
<Title level={5} style={{ marginTop: 16 }}>Instances</Title>
|
<Title level={5} style={{ marginTop: 16 }}>Instances</Title>
|
||||||
<InstanceList instances={instanceList} size="small" hideAssignedSlave />
|
<InstanceList instances={instanceList} size="small" hideAssignedHost />
|
||||||
</>}
|
</>}
|
||||||
{account.hasPermission("core.log.follow") && <>
|
{account.hasPermission("core.log.follow") && <>
|
||||||
<Title level={5} style={{ marginTop: 16 }}>Console</Title>
|
<Title level={5} style={{ marginTop: 16 }}>Console</Title>
|
||||||
<LogConsole slaves={[slaveId]} />
|
<LogConsole hosts={[hostId]} />
|
||||||
</>}
|
</>}
|
||||||
<PluginExtra component="SlaveViewPage" slave={slave} />
|
<PluginExtra component="HostViewPage" host={host} />
|
||||||
</PageLayout>;
|
</PageLayout>;
|
||||||
}
|
}
|
||||||
+37
-37
@@ -9,17 +9,17 @@ import { useAccount } from "../model/account";
|
|||||||
import ControlContext from "./ControlContext";
|
import ControlContext from "./ControlContext";
|
||||||
import PageLayout from "./PageLayout";
|
import PageLayout from "./PageLayout";
|
||||||
import PluginExtra from "./PluginExtra";
|
import PluginExtra from "./PluginExtra";
|
||||||
import { useSlaveList } from "../model/slave";
|
import { useHostList } from "../model/host";
|
||||||
import notify, { notifyErrorHandler } from "../util/notify";
|
import notify, { notifyErrorHandler } from "../util/notify";
|
||||||
|
|
||||||
const strcmp = new Intl.Collator(undefined, { numerice: "true", sensitivity: "base" }).compare;
|
const strcmp = new Intl.Collator(undefined, { numerice: "true", sensitivity: "base" }).compare;
|
||||||
|
|
||||||
|
|
||||||
function GenerateSlaveTokenButton(props) {
|
function GenerateHostTokenButton(props) {
|
||||||
let control = useContext(ControlContext);
|
let control = useContext(ControlContext);
|
||||||
let [visible, setVisible] = useState(false);
|
let [visible, setVisible] = useState(false);
|
||||||
let [token, setToken] = useState(null);
|
let [token, setToken] = useState(null);
|
||||||
let [slaveId, setSlaveId] = useState(null);
|
let [hostId, setHostId] = useState(null);
|
||||||
let [form] = Form.useForm();
|
let [form] = Form.useForm();
|
||||||
let [pluginList, setPluginList] = useState([]);
|
let [pluginList, setPluginList] = useState([]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -37,18 +37,18 @@ function GenerateSlaveTokenButton(props) {
|
|||||||
async function generateToken() {
|
async function generateToken() {
|
||||||
let id;
|
let id;
|
||||||
let values = form.getFieldsValue();
|
let values = form.getFieldsValue();
|
||||||
if (values.slaveId) {
|
if (values.hostId) {
|
||||||
id = Number.parseInt(values.slaveId, 10);
|
id = Number.parseInt(values.hostId, 10);
|
||||||
if (Number.isNaN(id)) {
|
if (Number.isNaN(id)) {
|
||||||
form.setFields([{ name: "slaveId", errors: ["Must be an integer"] }]);
|
form.setFields([{ name: "hostId", errors: ["Must be an integer"] }]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
form.setFields([{ name: "slaveId", errors: [] }]);
|
form.setFields([{ name: "hostId", errors: [] }]);
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = await libLink.messages.generateSlaveToken.send(control, { slave_id: id || null });
|
let result = await libLink.messages.generateHostToken.send(control, { host_id: id || null });
|
||||||
setToken(result.token);
|
setToken(result.token);
|
||||||
setSlaveId(id);
|
setHostId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate a new random
|
// Generate a new random
|
||||||
@@ -65,7 +65,7 @@ function GenerateSlaveTokenButton(props) {
|
|||||||
onClick={() => { setVisible(true); }}
|
onClick={() => { setVisible(true); }}
|
||||||
>Generate Token</Button>
|
>Generate Token</Button>
|
||||||
<Modal
|
<Modal
|
||||||
title="Generate Slave Token"
|
title="Generate Host Token"
|
||||||
visible={visible}
|
visible={visible}
|
||||||
footer={null}
|
footer={null}
|
||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
@@ -76,7 +76,7 @@ function GenerateSlaveTokenButton(props) {
|
|||||||
width="700px"
|
width="700px"
|
||||||
>
|
>
|
||||||
<Form form={form} layout="vertical" requiredMark="optional">
|
<Form form={form} layout="vertical" requiredMark="optional">
|
||||||
<Form.Item name="slaveId" label="Slave ID">
|
<Form.Item name="hostId" label="Host ID">
|
||||||
<InputNumber onChange={() => {
|
<InputNumber onChange={() => {
|
||||||
generateToken().catch(notifyErrorHandler("Error generating token"));
|
generateToken().catch(notifyErrorHandler("Error generating token"));
|
||||||
}} />
|
}} />
|
||||||
@@ -84,7 +84,7 @@ function GenerateSlaveTokenButton(props) {
|
|||||||
</Form>
|
</Form>
|
||||||
{token !== null && <>
|
{token !== null && <>
|
||||||
<Typography.Paragraph>
|
<Typography.Paragraph>
|
||||||
Slave auth token:
|
Host auth token:
|
||||||
</Typography.Paragraph>
|
</Typography.Paragraph>
|
||||||
<div className="codeblock">
|
<div className="codeblock">
|
||||||
<CopyButton
|
<CopyButton
|
||||||
@@ -94,43 +94,43 @@ function GenerateSlaveTokenButton(props) {
|
|||||||
{token}
|
{token}
|
||||||
</div>
|
</div>
|
||||||
<Typography.Paragraph>
|
<Typography.Paragraph>
|
||||||
You can set the token on an existing slave with the following command:
|
You can set the token on an existing host with the following command:
|
||||||
</Typography.Paragraph>
|
</Typography.Paragraph>
|
||||||
<div className="codeblock">
|
<div className="codeblock">
|
||||||
<CopyButton
|
<CopyButton
|
||||||
message={"Copied configuration commands to clipboard"}
|
message={"Copied configuration commands to clipboard"}
|
||||||
text={`npx clusterioslave config set slave.master_token ${token}
|
text={`npx clusteriohost config set host.controller_token ${token}
|
||||||
npx clusterioslave config set slave.id ${slaveId}`}
|
npx clusteriohost config set host.id ${hostId}`}
|
||||||
/>
|
/>
|
||||||
<p>npx clusterioslave config set slave.master_token <token></p>
|
<p>npx clusteriohost config set host.controller_token <token></p>
|
||||||
<p>npx clusterioslave config set slave.id <slaveId></p>
|
<p>npx clusteriohost config set host.id <hostId></p>
|
||||||
</div>
|
</div>
|
||||||
<Typography.Paragraph>
|
<Typography.Paragraph>
|
||||||
Example slave setup commands:
|
Example host setup commands:
|
||||||
</Typography.Paragraph>
|
</Typography.Paragraph>
|
||||||
<div className="codeblock">
|
<div className="codeblock">
|
||||||
<CopyButton
|
<CopyButton
|
||||||
message={"Copied slave setup commands to clipboard"}
|
message={"Copied host setup commands to clipboard"}
|
||||||
text={`
|
text={`
|
||||||
mkdir clusterio
|
mkdir clusterio
|
||||||
cd clusterio
|
cd clusterio
|
||||||
`+
|
`+
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
`npm init "@clusterio" -- --master-token ${token} --mode "slave" --download-headless --master-url ${document.location.origin}/ --slave-name "Slave ${slaveId || "?"}" --public-address localhost ${pluginString.length ? "--plugins" : ""} ${pluginString}`
|
`npm init "@clusterio" -- --controller-token ${token} --mode "host" --download-headless --controller-url ${document.location.origin}/ --host-name "Host ${hostId || "?"}" --public-address localhost ${pluginString.length ? "--plugins" : ""} ${pluginString}`
|
||||||
}/>
|
}/>
|
||||||
<p>> mkdir clusterio</p>
|
<p>> mkdir clusterio</p>
|
||||||
<p>> cd clusterio</p>
|
<p>> cd clusterio</p>
|
||||||
<p>
|
<p>
|
||||||
> npm init "@clusterio" --
|
> npm init "@clusterio" --
|
||||||
--master-token <span className="highlight">{token} </span>
|
--controller-token <span className="highlight">{token} </span>
|
||||||
--mode "slave"
|
--mode "host"
|
||||||
--download-headless
|
--download-headless
|
||||||
--master-url <span className="highlight">{document.location.origin}/ </span>
|
--controller-url <span className="highlight">{document.location.origin}/ </span>
|
||||||
--slave-name <span className="highlight">"Slave {slaveId || "?"}" </span>
|
--host-name <span className="highlight">"Host {hostId || "?"}" </span>
|
||||||
--public-address <span className="highlight">localhost </span>
|
--public-address <span className="highlight">localhost </span>
|
||||||
{pluginString.length ? "--plugins" : ""} <span className="highlight">{pluginString}</span>
|
{pluginString.length ? "--plugins" : ""} <span className="highlight">{pluginString}</span>
|
||||||
</p>
|
</p>
|
||||||
<p>> ./run-slave</p>
|
<p>> ./run-host</p>
|
||||||
</div>
|
</div>
|
||||||
</>}
|
</>}
|
||||||
</Modal>
|
</Modal>
|
||||||
@@ -175,16 +175,16 @@ function CopyButton({ text, message }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default function SlavesPage() {
|
export default function HostsPage() {
|
||||||
let account = useAccount();
|
let account = useAccount();
|
||||||
let history = useHistory();
|
let history = useHistory();
|
||||||
let [slaveList] = useSlaveList();
|
let [hostList] = useHostList();
|
||||||
|
|
||||||
return <PageLayout nav={[{ name: "Slaves" }]}>
|
return <PageLayout nav={[{ name: "Hosts" }]}>
|
||||||
<PageHeader
|
<PageHeader
|
||||||
className="site-page-header"
|
className="site-page-header"
|
||||||
title="Slaves"
|
title="Hosts"
|
||||||
extra={account.hasPermission("core.slave.generate_token") && <GenerateSlaveTokenButton />}
|
extra={account.hasPermission("core.host.generate_token") && <GenerateHostTokenButton />}
|
||||||
/>
|
/>
|
||||||
<Table
|
<Table
|
||||||
columns={[
|
columns={[
|
||||||
@@ -213,23 +213,23 @@ export default function SlavesPage() {
|
|||||||
{
|
{
|
||||||
title: "Connected",
|
title: "Connected",
|
||||||
key: "connected",
|
key: "connected",
|
||||||
render: slave => <Tag
|
render: host => <Tag
|
||||||
color={slave["connected"] ? "#389e0d" : "#cf1322"}
|
color={host["connected"] ? "#389e0d" : "#cf1322"}
|
||||||
>
|
>
|
||||||
{slave["connected"] ? "Connected" : "Disconnected"}
|
{host["connected"] ? "Connected" : "Disconnected"}
|
||||||
</Tag>,
|
</Tag>,
|
||||||
sorter: (a, b) => a["connected"] - b["connected"],
|
sorter: (a, b) => a["connected"] - b["connected"],
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
dataSource={slaveList}
|
dataSource={hostList}
|
||||||
rowKey={slave => slave["id"]}
|
rowKey={host => host["id"]}
|
||||||
pagination={false}
|
pagination={false}
|
||||||
onRow={(record, rowIndex) => ({
|
onRow={(record, rowIndex) => ({
|
||||||
onClick: event => {
|
onClick: event => {
|
||||||
history.push(`/slaves/${record.id}/view`);
|
history.push(`/hosts/${record.id}/view`);
|
||||||
},
|
},
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
<PluginExtra component="SlavesPage" />
|
<PluginExtra component="HostsPage" />
|
||||||
</PageLayout>;
|
</PageLayout>;
|
||||||
};
|
};
|
||||||
@@ -4,7 +4,7 @@ import { message, Button, Space, Table } from "antd";
|
|||||||
import CopyOutlined from "@ant-design/icons/CopyOutlined";
|
import CopyOutlined from "@ant-design/icons/CopyOutlined";
|
||||||
|
|
||||||
import { useAccount } from "../model/account";
|
import { useAccount } from "../model/account";
|
||||||
import { useSlaveList } from "../model/slave";
|
import { useHostList } from "../model/host";
|
||||||
import InstanceStatusTag from "./InstanceStatusTag";
|
import InstanceStatusTag from "./InstanceStatusTag";
|
||||||
import StartStopInstanceButton from "./StartStopInstanceButton";
|
import StartStopInstanceButton from "./StartStopInstanceButton";
|
||||||
|
|
||||||
@@ -13,26 +13,26 @@ const strcmp = new Intl.Collator(undefined, { numerice: "true", sensitivity: "ba
|
|||||||
export default function InstanceList(props) {
|
export default function InstanceList(props) {
|
||||||
let account = useAccount();
|
let account = useAccount();
|
||||||
let history = useHistory();
|
let history = useHistory();
|
||||||
let [slaveList] = useSlaveList();
|
let [hostList] = useHostList();
|
||||||
|
|
||||||
function slaveName(slaveId) {
|
function hostName(hostId) {
|
||||||
if (slaveId === null) {
|
if (hostId === null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
let slave = slaveList.find(s => s.id === slaveId);
|
let host = hostList.find(s => s.id === hostId);
|
||||||
if (slave) {
|
if (host) {
|
||||||
return slave.name;
|
return host.name;
|
||||||
}
|
}
|
||||||
return String(slaveId);
|
return String(hostId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function instancePublicAddress(instance) {
|
function instancePublicAddress(instance) {
|
||||||
let slave = slaveList.find(s => s.id === instance.assigned_slave);
|
let host = hostList.find(s => s.id === instance.assigned_host);
|
||||||
if (slave && slave.public_address) {
|
if (host && host.public_address) {
|
||||||
if (instance.game_port) {
|
if (instance.game_port) {
|
||||||
return `${slave.public_address}:${instance.game_port}`;
|
return `${host.public_address}:${instance.game_port}`;
|
||||||
}
|
}
|
||||||
return slave.public_address;
|
return host.public_address;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -45,10 +45,10 @@ export default function InstanceList(props) {
|
|||||||
sorter: (a, b) => strcmp(a["name"], b["name"]),
|
sorter: (a, b) => strcmp(a["name"], b["name"]),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Assigned Slave",
|
title: "Assigned Host",
|
||||||
key: "assigned_slave",
|
key: "assigned_host",
|
||||||
render: instance => slaveName(instance["assigned_slave"]),
|
render: instance => hostName(instance["assigned_host"]),
|
||||||
sorter: (a, b) => strcmp(slaveName(a["assigned_slave"]), slaveName(b["assigned_slave"])),
|
sorter: (a, b) => strcmp(hostName(a["assigned_host"]), hostName(b["assigned_host"])),
|
||||||
responsive: ["sm"],
|
responsive: ["sm"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -69,7 +69,7 @@ export default function InstanceList(props) {
|
|||||||
/>
|
/>
|
||||||
</> : "";
|
</> : "";
|
||||||
},
|
},
|
||||||
sorter: (a, b) => strcmp(slavePublicAddress(a["assigned_slave"]), slavePublicAddress(b["assigned_slave"])),
|
sorter: (a, b) => strcmp(hostPublicAddress(a["assigned_host"]), hostPublicAddress(b["assigned_host"])),
|
||||||
responsive: ["lg"],
|
responsive: ["lg"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -90,7 +90,7 @@ export default function InstanceList(props) {
|
|||||||
}] : []),
|
}] : []),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (props.hideAssignedSlave) {
|
if (props.hideAssignedHost) {
|
||||||
columns.splice(1, 1);
|
columns.splice(1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import LoadScenarioModal from "./LoadScenarioModal";
|
|||||||
import SavesList from "./SavesList";
|
import SavesList from "./SavesList";
|
||||||
import { notifyErrorHandler } from "../util/notify";
|
import { notifyErrorHandler } from "../util/notify";
|
||||||
import { useInstance } from "../model/instance";
|
import { useInstance } from "../model/instance";
|
||||||
import { useSlave } from "../model/slave";
|
import { useHost } from "../model/host";
|
||||||
import InstanceStatusTag from "./InstanceStatusTag";
|
import InstanceStatusTag from "./InstanceStatusTag";
|
||||||
|
|
||||||
const { Title } = Typography;
|
const { Title } = Typography;
|
||||||
@@ -28,20 +28,20 @@ const { Title } = Typography;
|
|||||||
function InstanceDescription(props) {
|
function InstanceDescription(props) {
|
||||||
let account = useAccount();
|
let account = useAccount();
|
||||||
|
|
||||||
const { slave, instance } = props;
|
const { host, instance } = props;
|
||||||
let assigned = instance["assigned_slave"] !== null;
|
let assigned = instance["assigned_host"] !== null;
|
||||||
return <Descriptions
|
return <Descriptions
|
||||||
bordered
|
bordered
|
||||||
size="small"
|
size="small"
|
||||||
>
|
>
|
||||||
<Descriptions.Item label="Slave">
|
<Descriptions.Item label="Host">
|
||||||
{!assigned
|
{!assigned
|
||||||
? <em>Unassigned</em>
|
? <em>Unassigned</em>
|
||||||
: slave["name"] || instance["assigned_slave"]
|
: host["name"] || instance["assigned_host"]
|
||||||
}
|
}
|
||||||
{account.hasPermission("core.instance.assign") && <AssignInstanceModal
|
{account.hasPermission("core.instance.assign") && <AssignInstanceModal
|
||||||
id={instance["id"]}
|
id={instance["id"]}
|
||||||
slaveId={instance["assigned_slave"]}
|
hostId={instance["assigned_host"]}
|
||||||
buttonProps={{
|
buttonProps={{
|
||||||
size: "small",
|
size: "small",
|
||||||
style: { float: "Right" },
|
style: { float: "Right" },
|
||||||
@@ -64,7 +64,7 @@ export default function InstanceViewPage(props) {
|
|||||||
let account = useAccount();
|
let account = useAccount();
|
||||||
let control = useContext(ControlContext);
|
let control = useContext(ControlContext);
|
||||||
let [instance] = useInstance(instanceId);
|
let [instance] = useInstance(instanceId);
|
||||||
let [slave] = useSlave(Number(instance["assigned_slave"]));
|
let [host] = useHost(Number(instance["assigned_host"]));
|
||||||
|
|
||||||
let [exportingData, setExportingData] = useState(false);
|
let [exportingData, setExportingData] = useState(false);
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ export default function InstanceViewPage(props) {
|
|||||||
<Alert
|
<Alert
|
||||||
message={instance["status"] === "deleted" ? "Instance has been deleted" : "Instance not found" }
|
message={instance["status"] === "deleted" ? "Instance has been deleted" : "Instance not found" }
|
||||||
showIcon
|
showIcon
|
||||||
description={<>Instance with id {instanceId} was not found on the master server.</>}
|
description={<>Instance with id {instanceId} was not found on the controller.</>}
|
||||||
type="warning"
|
type="warning"
|
||||||
action={
|
action={
|
||||||
<Button
|
<Button
|
||||||
@@ -188,7 +188,7 @@ export default function InstanceViewPage(props) {
|
|||||||
title={instance["name"]}
|
title={instance["name"]}
|
||||||
extra={instanceButtons}
|
extra={instanceButtons}
|
||||||
/>
|
/>
|
||||||
<InstanceDescription slave={slave} instance={instance} />
|
<InstanceDescription host={host} instance={instance} />
|
||||||
|
|
||||||
{
|
{
|
||||||
account.hasAllPermission("core.instance.save.list", "core.instance.save.list_subscribe")
|
account.hasAllPermission("core.instance.save.list", "core.instance.save.list_subscribe")
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ function CreateInstanceButton(props) {
|
|||||||
let instanceConfig = new libConfig.InstanceConfig("control");
|
let instanceConfig = new libConfig.InstanceConfig("control");
|
||||||
await instanceConfig.init();
|
await instanceConfig.init();
|
||||||
instanceConfig.set("instance.name", values.instanceName);
|
instanceConfig.set("instance.name", values.instanceName);
|
||||||
let serialized_config = instanceConfig.serialize("master");
|
let serialized_config = instanceConfig.serialize("controller");
|
||||||
await libLink.messages.createInstance.send(control, { serialized_config });
|
await libLink.messages.createInstance.send(control, { serialized_config });
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
history.push(`/instances/${instanceConfig.get("instance.id")}/view`);
|
history.push(`/instances/${instanceConfig.get("instance.id")}/view`);
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ export default function LogConsole(props) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let logFilter = {
|
let logFilter = {
|
||||||
all: props.all || false,
|
all: props.all || false,
|
||||||
master: props.master || false,
|
controller: props.controller || false,
|
||||||
slave_ids: props.slaves || [],
|
host_ids: props.hosts || [],
|
||||||
instance_ids: props.instances || [],
|
instance_ids: props.instances || [],
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ export default function LogConsole(props) {
|
|||||||
return () => {
|
return () => {
|
||||||
control.offLog(logFilter, logHandler);
|
control.offLog(logFilter, logHandler);
|
||||||
};
|
};
|
||||||
}, [props.all, props.master, (props.slaves || []).join(), (props.instances || []).join()]);
|
}, [props.all, props.controller, (props.hosts || []).join(), (props.instances || []).join()]);
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
<Paragraph code className="instance-console">
|
<Paragraph code className="instance-console">
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ const { Paragraph } = Typography;
|
|||||||
|
|
||||||
function TokenAuth(props) {
|
function TokenAuth(props) {
|
||||||
return <>
|
return <>
|
||||||
<Paragraph>If you have generated an authentication token from the master server, use that here.</Paragraph>
|
<Paragraph>If you have generated an authentication token from the controller, use that here.</Paragraph>
|
||||||
<Form
|
<Form
|
||||||
name="login"
|
name="login"
|
||||||
onFinish={(values) => { props.setToken(values.token.trim()); }}
|
onFinish={(values) => { props.setToken(values.token.trim()); }}
|
||||||
|
|||||||
@@ -13,9 +13,10 @@ export default function ModDetails(props) {
|
|||||||
|
|
||||||
return <Descriptions className="borderless" bordered size="small" column={{ xs: 1, sm: 1, md: 1, lg: 2 }}>
|
return <Descriptions className="borderless" bordered size="small" column={{ xs: 1, sm: 1, md: 1, lg: 2 }}>
|
||||||
{mod.error && <Descriptions.Item label={<><ExclamationCircleOutlined/> Error</>} span={2}>
|
{mod.error && <Descriptions.Item label={<><ExclamationCircleOutlined/> Error</>} span={2}>
|
||||||
{mod.error === "missing" && "The given version of this mod is missing from the master storage."}
|
{mod.error === "missing" && "The given version of this mod is missing from the controller storage."}
|
||||||
{mod.error === "bad_checksum"
|
{mod.error === "bad_checksum"
|
||||||
&& "Checksum of the mod in the master storage does not match the checksum provided by this mod pack."
|
&& "Checksum of the mod in the controller storage does not match the checksum provided " +
|
||||||
|
"by this mod pack."
|
||||||
}
|
}
|
||||||
</Descriptions.Item>}
|
</Descriptions.Item>}
|
||||||
{props.actions && !screens.lg
|
{props.actions && !screens.lg
|
||||||
|
|||||||
@@ -670,7 +670,7 @@ export default function ModPackViewPage() {
|
|||||||
className="site-page-header"
|
className="site-page-header"
|
||||||
title="Mod Pack Not Found"
|
title="Mod Pack Not Found"
|
||||||
/>
|
/>
|
||||||
<p>Mod pack with id {modPackId} was not found on the master server.</p>
|
<p>Mod pack with id {modPackId} was not found on the controller.</p>
|
||||||
</PageLayout>;
|
</PageLayout>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export default function PluginViewPage() {
|
|||||||
if (!pluginMeta) {
|
if (!pluginMeta) {
|
||||||
return <PageLayout nav={nav}>
|
return <PageLayout nav={nav}>
|
||||||
<h2>Plugin not found</h2>
|
<h2>Plugin not found</h2>
|
||||||
<p>Plugin with name {pluginName} was not found on the master server.</p>
|
<p>Plugin with name {pluginName} was not found on the controller.</p>
|
||||||
</PageLayout>;
|
</PageLayout>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,9 +84,9 @@ export default function PluginViewPage() {
|
|||||||
message="Version missmatch detected"
|
message="Version missmatch detected"
|
||||||
description={
|
description={
|
||||||
`The version of the web interface module for this plugin (${plugin.package.version}) `+
|
`The version of the web interface module for this plugin (${plugin.package.version}) `+
|
||||||
`does not match the version running on the master server (${pluginMeta.version}), `+
|
`does not match the version running on the controller (${pluginMeta.version}), `+
|
||||||
"spurious errors may occur. This usually happens when the plugin is updated but the "+
|
"spurious errors may occur. This usually happens when the plugin is updated but the "+
|
||||||
"master server has not been restarted yet, but may also be due to an outdated build."
|
"controller has not been restarted yet, but may also be due to an outdated build."
|
||||||
}
|
}
|
||||||
type="warning"
|
type="warning"
|
||||||
showIcon
|
showIcon
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export default function RoleViewPage() {
|
|||||||
className="site-page-header"
|
className="site-page-header"
|
||||||
title="Role not found"
|
title="Role not found"
|
||||||
/>
|
/>
|
||||||
<p>Role with id {roleId} was not found on the master server.</p>
|
<p>Role with id {roleId} was not found on the controller.</p>
|
||||||
</PageLayout>;
|
</PageLayout>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ export default function SavesList(props) {
|
|||||||
let [starting, setStarting] = useState(false);
|
let [starting, setStarting] = useState(false);
|
||||||
let [uploadingFiles, setUploadingFiles] = useState([]);
|
let [uploadingFiles, setUploadingFiles] = useState([]);
|
||||||
|
|
||||||
let slaveOffline = ["unassigned", "unknown"].includes(props.instance.status);
|
let hostOffline = ["unassigned", "unknown"].includes(props.instance.status);
|
||||||
const saveTable = <Table
|
const saveTable = <Table
|
||||||
size="small"
|
size="small"
|
||||||
columns={[
|
columns={[
|
||||||
@@ -237,13 +237,13 @@ export default function SavesList(props) {
|
|||||||
}}
|
}}
|
||||||
>Load save</Button>}
|
>Load save</Button>}
|
||||||
{account.hasPermission("core.instance.save.rename") && <RenameModal
|
{account.hasPermission("core.instance.save.rename") && <RenameModal
|
||||||
disabled={slaveOffline} instanceId={props.instance.id} save={save}
|
disabled={hostOffline} instanceId={props.instance.id} save={save}
|
||||||
/>}
|
/>}
|
||||||
{account.hasPermission("core.instance.save.copy") && <CopyModal
|
{account.hasPermission("core.instance.save.copy") && <CopyModal
|
||||||
disabled={slaveOffline} instanceId={props.instance.id} save={save}
|
disabled={hostOffline} instanceId={props.instance.id} save={save}
|
||||||
/>}
|
/>}
|
||||||
{account.hasPermission("core.instance.save.download") && <Button
|
{account.hasPermission("core.instance.save.download") && <Button
|
||||||
disabled={slaveOffline}
|
disabled={hostOffline}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
libLink.messages.downloadSave.send(
|
libLink.messages.downloadSave.send(
|
||||||
control, { instance_id: props.instance.id, save: save.name }
|
control, { instance_id: props.instance.id, save: save.name }
|
||||||
@@ -257,7 +257,7 @@ export default function SavesList(props) {
|
|||||||
}}
|
}}
|
||||||
>Download</Button>}
|
>Download</Button>}
|
||||||
{account.hasPermission("core.instance.save.transfer") && <TransferModal
|
{account.hasPermission("core.instance.save.transfer") && <TransferModal
|
||||||
disabled={slaveOffline} instanceId={props.instance.id} save={save}
|
disabled={hostOffline} instanceId={props.instance.id} save={save}
|
||||||
/>}
|
/>}
|
||||||
{account.hasPermission("core.instance.save.delete") && <Popconfirm
|
{account.hasPermission("core.instance.save.delete") && <Popconfirm
|
||||||
title="Permanently delete save?"
|
title="Permanently delete save?"
|
||||||
@@ -270,7 +270,7 @@ export default function SavesList(props) {
|
|||||||
).catch(notifyErrorHandler("Error deleting save"));
|
).catch(notifyErrorHandler("Error deleting save"));
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Button danger disabled={slaveOffline}>Delete</Button>
|
<Button danger disabled={hostOffline}>Delete</Button>
|
||||||
</Popconfirm>}
|
</Popconfirm>}
|
||||||
</Space>,
|
</Space>,
|
||||||
}}
|
}}
|
||||||
@@ -309,7 +309,7 @@ export default function SavesList(props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let uploadProps = {
|
let uploadProps = {
|
||||||
disabled: slaveOffline,
|
disabled: hostOffline,
|
||||||
name: "file",
|
name: "file",
|
||||||
accept: ".zip",
|
accept: ".zip",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -326,7 +326,7 @@ export default function SavesList(props) {
|
|||||||
return <div>
|
return <div>
|
||||||
<SectionHeader title="Saves" extra={<Space>
|
<SectionHeader title="Saves" extra={<Space>
|
||||||
{account.hasPermission("core.instance.save.upload") && <Upload {...uploadProps} >
|
{account.hasPermission("core.instance.save.upload") && <Upload {...uploadProps} >
|
||||||
<Button disabled={slaveOffline}>Upload save</Button>
|
<Button disabled={hostOffline}>Upload save</Button>
|
||||||
</Upload>}
|
</Upload>}
|
||||||
{account.hasPermission("core.instance.save.create") && <CreateSaveModal instance={props.instance} />}
|
{account.hasPermission("core.instance.save.create") && <CreateSaveModal instance={props.instance} />}
|
||||||
</Space>} />
|
</Space>} />
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ export default function UserViewPage() {
|
|||||||
className="site-page-header"
|
className="site-page-header"
|
||||||
title="User not found"
|
title="User not found"
|
||||||
/>
|
/>
|
||||||
<p>User with name {userName} was not found on the master server.</p>
|
<p>User with name {userName} was not found on the controller.</p>
|
||||||
</PageLayout>;
|
</PageLayout>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ export { default as bootstrap } from "./bootstrap.jsx";
|
|||||||
export { default as notify, notifyErrorHandler } from "./util/notify.jsx";
|
export { default as notify, notifyErrorHandler } from "./util/notify.jsx";
|
||||||
|
|
||||||
export * from "./model/instance.jsx";
|
export * from "./model/instance.jsx";
|
||||||
export * from "./model/slave.jsx";
|
export * from "./model/host.jsx";
|
||||||
export * from "./model/locale.jsx";
|
export * from "./model/locale.jsx";
|
||||||
export * from "./model/item_metadata.jsx";
|
export * from "./model/item_metadata.jsx";
|
||||||
export * from "./model/account.jsx";
|
export * from "./model/account.jsx";
|
||||||
@@ -12,7 +12,7 @@ export { default as ControlContext } from "./components/ControlContext";
|
|||||||
|
|
||||||
export { default as BaseConfigTree } from "./components/BaseConfigTree";
|
export { default as BaseConfigTree } from "./components/BaseConfigTree";
|
||||||
export { default as InstanceConfigTree } from "./components/InstanceConfigTree";
|
export { default as InstanceConfigTree } from "./components/InstanceConfigTree";
|
||||||
export { default as MasterConfigTree } from "./components/MasterConfigTree";
|
export { default as ControllerConfigTree } from "./components/ControllerConfigTree";
|
||||||
|
|
||||||
export { default as LogConsole } from "./components/LogConsole";
|
export { default as LogConsole } from "./components/LogConsole";
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
import { useEffect, useContext, useState } from "react";
|
||||||
|
import ControlContext from "../components/ControlContext";
|
||||||
|
|
||||||
|
import { libLink } from "@clusterio/lib";
|
||||||
|
|
||||||
|
|
||||||
|
export function useHost(id) {
|
||||||
|
let control = useContext(ControlContext);
|
||||||
|
let [host, setHost] = useState({ loading: true });
|
||||||
|
|
||||||
|
function updateHost() {
|
||||||
|
// XXX optimize by requesting only the host in question
|
||||||
|
libLink.messages.listHosts.send(control).then(result => {
|
||||||
|
let match = result.list.find(i => i.id === id);
|
||||||
|
if (!match) {
|
||||||
|
setHost({ missing: true });
|
||||||
|
} else {
|
||||||
|
setHost({ ...match, present: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!Number.isInteger(id)) {
|
||||||
|
setHost({ missing: true });
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
updateHost();
|
||||||
|
|
||||||
|
function updateHandler(newHost) {
|
||||||
|
setHost({ ...newHost, present: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
control.onHostUpdate(id, updateHandler);
|
||||||
|
return () => {
|
||||||
|
control.offHostUpdate(id, updateHandler);
|
||||||
|
};
|
||||||
|
}, [id]);
|
||||||
|
|
||||||
|
return [host, updateHost];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useHostList() {
|
||||||
|
let control = useContext(ControlContext);
|
||||||
|
let [hostList, setHostList] = useState([]);
|
||||||
|
|
||||||
|
function updateHostList() {
|
||||||
|
libLink.messages.listHosts.send(control).then(result => {
|
||||||
|
setHostList(result.list);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
updateHostList();
|
||||||
|
|
||||||
|
function updateHandler(newHost) {
|
||||||
|
setHostList(oldList => {
|
||||||
|
let newList = oldList.concat();
|
||||||
|
let index = newList.findIndex(s => s.id === newHost.id);
|
||||||
|
if (index !== -1) {
|
||||||
|
newList[index] = newHost;
|
||||||
|
} else {
|
||||||
|
newList.push(newHost);
|
||||||
|
}
|
||||||
|
return newList;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
control.onHostUpdate(null, updateHandler);
|
||||||
|
return () => {
|
||||||
|
control.offHostUpdate(null, updateHandler);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
|
return [hostList];
|
||||||
|
}
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
import { useEffect, useContext, useState } from "react";
|
|
||||||
import ControlContext from "../components/ControlContext";
|
|
||||||
|
|
||||||
import { libLink } from "@clusterio/lib";
|
|
||||||
|
|
||||||
|
|
||||||
export function useSlave(id) {
|
|
||||||
let control = useContext(ControlContext);
|
|
||||||
let [slave, setSlave] = useState({ loading: true });
|
|
||||||
|
|
||||||
function updateSlave() {
|
|
||||||
// XXX optimize by requesting only the slave in question
|
|
||||||
libLink.messages.listSlaves.send(control).then(result => {
|
|
||||||
let match = result.list.find(i => i.id === id);
|
|
||||||
if (!match) {
|
|
||||||
setSlave({ missing: true });
|
|
||||||
} else {
|
|
||||||
setSlave({ ...match, present: true });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!Number.isInteger(id)) {
|
|
||||||
setSlave({ missing: true });
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
updateSlave();
|
|
||||||
|
|
||||||
function updateHandler(newSlave) {
|
|
||||||
setSlave({ ...newSlave, present: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
control.onSlaveUpdate(id, updateHandler);
|
|
||||||
return () => {
|
|
||||||
control.offSlaveUpdate(id, updateHandler);
|
|
||||||
};
|
|
||||||
}, [id]);
|
|
||||||
|
|
||||||
return [slave, updateSlave];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useSlaveList() {
|
|
||||||
let control = useContext(ControlContext);
|
|
||||||
let [slaveList, setSlaveList] = useState([]);
|
|
||||||
|
|
||||||
function updateSlaveList() {
|
|
||||||
libLink.messages.listSlaves.send(control).then(result => {
|
|
||||||
setSlaveList(result.list);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
updateSlaveList();
|
|
||||||
|
|
||||||
function updateHandler(newSlave) {
|
|
||||||
setSlaveList(oldList => {
|
|
||||||
let newList = oldList.concat();
|
|
||||||
let index = newList.findIndex(s => s.id === newSlave.id);
|
|
||||||
if (index !== -1) {
|
|
||||||
newList[index] = newSlave;
|
|
||||||
} else {
|
|
||||||
newList.push(newSlave);
|
|
||||||
}
|
|
||||||
return newList;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
control.onSlaveUpdate(null, updateHandler);
|
|
||||||
return () => {
|
|
||||||
control.offSlaveUpdate(null, updateHandler);
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
|
|
||||||
return [slaveList];
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import MasterPage from "./components/MasterPage";
|
import ControllerPage from "./components/ControllerPage";
|
||||||
import SlavesPage from "./components/SlavesPage";
|
import HostsPage from "./components/HostsPage";
|
||||||
import SlaveViewPage from "./components/SlaveViewPage";
|
import HostViewPage from "./components/HostViewPage";
|
||||||
import InstancesPage from "./components/InstancesPage";
|
import InstancesPage from "./components/InstancesPage";
|
||||||
import InstanceViewPage from "./components/InstanceViewPage";
|
import InstanceViewPage from "./components/InstanceViewPage";
|
||||||
import ModPackViewPage from "./components/ModPackViewPage";
|
import ModPackViewPage from "./components/ModPackViewPage";
|
||||||
@@ -17,20 +17,20 @@ import PluginViewPage from "./components/PluginViewPage";
|
|||||||
|
|
||||||
export const pages = [
|
export const pages = [
|
||||||
{
|
{
|
||||||
path: "/master",
|
path: "/controller",
|
||||||
sidebarName: "Master",
|
sidebarName: "Controller",
|
||||||
content: <MasterPage />,
|
content: <ControllerPage />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/slaves",
|
path: "/hosts",
|
||||||
sidebarName: "Slaves",
|
sidebarName: "Hosts",
|
||||||
permission: "core.slave.list",
|
permission: "core.host.list",
|
||||||
content: <SlavesPage />,
|
content: <HostsPage />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/slaves/:id/view",
|
path: "/hosts/:id/view",
|
||||||
sidebarPath: "/slaves",
|
sidebarPath: "/hosts",
|
||||||
content: <SlaveViewPage />,
|
content: <HostViewPage />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/instances",
|
path: "/instances",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import packageJson from "../../package.json";
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connector for control connection to master server
|
* Connector for control connection to controller
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
export class ControlConnector extends libLink.WebSocketClientConnector {
|
export class ControlConnector extends libLink.WebSocketClientConnector {
|
||||||
@@ -30,12 +30,12 @@ export class ControlConnector extends libLink.WebSocketClientConnector {
|
|||||||
/**
|
/**
|
||||||
* Handles running the control
|
* Handles running the control
|
||||||
*
|
*
|
||||||
* Connects to the master server over WebSocket and sends commands to it.
|
* Connects to the controller over WebSocket and sends commands to it.
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
export class Control extends libLink.Link {
|
export class Control extends libLink.Link {
|
||||||
constructor(connector, plugins) {
|
constructor(connector, plugins) {
|
||||||
super("control", "master", connector);
|
super("control", "controller", connector);
|
||||||
libLink.attachAllMessages(this);
|
libLink.attachAllMessages(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,7 +67,7 @@ export class Control extends libLink.Link {
|
|||||||
this.accountRoles = null;
|
this.accountRoles = null;
|
||||||
|
|
||||||
this.accountUpdateHandlers = [];
|
this.accountUpdateHandlers = [];
|
||||||
this.slaveUpdateHandlers = new Map();
|
this.hostUpdateHandlers = new Map();
|
||||||
this.instanceUpdateHandlers = new Map();
|
this.instanceUpdateHandlers = new Map();
|
||||||
this.saveListUpdateHandlers = new Map();
|
this.saveListUpdateHandlers = new Map();
|
||||||
this.modPackUpdateHandlers = new Map();
|
this.modPackUpdateHandlers = new Map();
|
||||||
@@ -79,8 +79,8 @@ export class Control extends libLink.Link {
|
|||||||
this.accountName = data.account.name;
|
this.accountName = data.account.name;
|
||||||
this.accountRoles = data.account.roles;
|
this.accountRoles = data.account.roles;
|
||||||
this.emitAccountUpdate();
|
this.emitAccountUpdate();
|
||||||
this.updateSlaveSubscriptions().catch(err => logger.error(
|
this.updateHostSubscriptions().catch(err => logger.error(
|
||||||
`Unexpected error updating slave subscriptions:\n${err.stack}`
|
`Unexpected error updating host subscriptions:\n${err.stack}`
|
||||||
));
|
));
|
||||||
this.updateInstanceSubscriptions().catch(err => logger.error(
|
this.updateInstanceSubscriptions().catch(err => logger.error(
|
||||||
`Unexpected error updating instance subscriptions:\n${err.stack}`
|
`Unexpected error updating instance subscriptions:\n${err.stack}`
|
||||||
@@ -111,7 +111,7 @@ export class Control extends libLink.Link {
|
|||||||
for (let event of ["connect", "drop", "resume", "close"]) {
|
for (let event of ["connect", "drop", "resume", "close"]) {
|
||||||
this.connector.on(event, () => {
|
this.connector.on(event, () => {
|
||||||
for (let plugin of this.plugins.values()) {
|
for (let plugin of this.plugins.values()) {
|
||||||
plugin.onMasterConnectionEvent(event);
|
plugin.onControllerConnectionEvent(event);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -143,60 +143,60 @@ export class Control extends libLink.Link {
|
|||||||
this.accountUpdateHandlers.splice(index, 1);
|
this.accountUpdateHandlers.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
async slaveUpdateEventHandler(message) {
|
async hostUpdateEventHandler(message) {
|
||||||
let handlers = [].concat(
|
let handlers = [].concat(
|
||||||
this.slaveUpdateHandlers.get(null) || [],
|
this.hostUpdateHandlers.get(null) || [],
|
||||||
this.slaveUpdateHandlers.get(message.data.id) || [],
|
this.hostUpdateHandlers.get(message.data.id) || [],
|
||||||
);
|
);
|
||||||
for (let handler of handlers) {
|
for (let handler of handlers) {
|
||||||
handler(message.data);
|
handler(message.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async onSlaveUpdate(id, handler) {
|
async onHostUpdate(id, handler) {
|
||||||
if (id !== null && !Number.isInteger(id)) {
|
if (id !== null && !Number.isInteger(id)) {
|
||||||
throw new Error("Invalid slave id");
|
throw new Error("Invalid host id");
|
||||||
}
|
}
|
||||||
|
|
||||||
let handlers = this.slaveUpdateHandlers.get(id);
|
let handlers = this.hostUpdateHandlers.get(id);
|
||||||
if (!handlers) {
|
if (!handlers) {
|
||||||
handlers = [];
|
handlers = [];
|
||||||
this.slaveUpdateHandlers.set(id, handlers);
|
this.hostUpdateHandlers.set(id, handlers);
|
||||||
}
|
}
|
||||||
|
|
||||||
handlers.push(handler);
|
handlers.push(handler);
|
||||||
|
|
||||||
if (handlers.length === 1) {
|
if (handlers.length === 1) {
|
||||||
await this.updateSlaveSubscriptions();
|
await this.updateHostSubscriptions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async offSlaveUpdate(id, handler) {
|
async offHostUpdate(id, handler) {
|
||||||
let handlers = this.slaveUpdateHandlers.get(id);
|
let handlers = this.hostUpdateHandlers.get(id);
|
||||||
if (!handlers || !handlers.length) {
|
if (!handlers || !handlers.length) {
|
||||||
throw new Error(`No handlers for slave ${id} exists`);
|
throw new Error(`No handlers for host ${id} exists`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let index = handlers.lastIndexOf(handler);
|
let index = handlers.lastIndexOf(handler);
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
throw new Error(`Given handler is not registered for slave ${id}`);
|
throw new Error(`Given handler is not registered for host ${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
handlers.splice(index, 1);
|
handlers.splice(index, 1);
|
||||||
if (!handlers.length) {
|
if (!handlers.length) {
|
||||||
this.slaveUpdateHandlers.delete(id);
|
this.hostUpdateHandlers.delete(id);
|
||||||
await this.updateSlaveSubscriptions();
|
await this.updateHostSubscriptions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateSlaveSubscriptions() {
|
async updateHostSubscriptions() {
|
||||||
if (!this.connector.connected) {
|
if (!this.connector.connected) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await libLink.messages.setSlaveSubscriptions.send(this, {
|
await libLink.messages.setHostSubscriptions.send(this, {
|
||||||
all: this.slaveUpdateHandlers.has(null),
|
all: this.hostUpdateHandlers.has(null),
|
||||||
slave_ids: [...this.slaveUpdateHandlers.keys()].filter(e => e !== null),
|
host_ids: [...this.hostUpdateHandlers.keys()].filter(e => e !== null),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -535,17 +535,17 @@ export class Control extends libLink.Link {
|
|||||||
|
|
||||||
let combinedFilter = {
|
let combinedFilter = {
|
||||||
all: false,
|
all: false,
|
||||||
master: false,
|
controller: false,
|
||||||
slave_ids: [],
|
host_ids: [],
|
||||||
instance_ids: [],
|
instance_ids: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
for (let filter of this.logHandlers.keys()) {
|
for (let filter of this.logHandlers.keys()) {
|
||||||
if (filter.all) { combinedFilter.all = true; }
|
if (filter.all) { combinedFilter.all = true; }
|
||||||
if (filter.master) { combinedFilter.master = true; }
|
if (filter.controller) { combinedFilter.controller = true; }
|
||||||
for (let slaveId of filter.slave_ids || []) {
|
for (let hostId of filter.host_ids || []) {
|
||||||
if (!combinedFilter.slave_ids.includes(slaveId)) {
|
if (!combinedFilter.host_ids.includes(hostId)) {
|
||||||
combinedFilter.slave_ids.push(slaveId);
|
combinedFilter.host_ids.push(hostId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let instanceId of filter.instance_ids || []) {
|
for (let instanceId of filter.instance_ids || []) {
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ Plugin sharing the in-game chat between instances.
|
|||||||
Run the following commands in the folder Clusterio is installed to:
|
Run the following commands in the folder Clusterio is installed to:
|
||||||
|
|
||||||
npm install @clusterio/plugin-global_chat
|
npm install @clusterio/plugin-global_chat
|
||||||
npx clusteriomaster plugin add @clusterio/plugin-global_chat
|
npx clusteriocontroller plugin add @clusterio/plugin-global_chat
|
||||||
|
|
||||||
Substitute clusteriomaster with clusterioslave or clusterioctl if this a dedicate slave or ctl installation respectively.
|
Substitute clusteriocontroller with clusteriohost or clusterioctl if this a dedicate host or ctl installation respectively.
|
||||||
@@ -11,8 +11,8 @@ module.exports = {
|
|||||||
messages: {
|
messages: {
|
||||||
chat: new libLink.Event({
|
chat: new libLink.Event({
|
||||||
type: "global_chat:chat",
|
type: "global_chat:chat",
|
||||||
links: ["instance-slave", "slave-master", "master-slave", "slave-instance", "control-master"],
|
links: ["instance-host", "host-controller", "controller-host", "host-instance", "control-controller"],
|
||||||
forwardTo: "master",
|
forwardTo: "controller",
|
||||||
broadcastTo: "instance",
|
broadcastTo: "instance",
|
||||||
eventProperties: {
|
eventProperties: {
|
||||||
"instance_name": { type: "string" },
|
"instance_name": { type: "string" },
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
|||||||
this.messageQueue = [];
|
this.messageQueue = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
onMasterConnectionEvent(event) {
|
onControllerConnectionEvent(event) {
|
||||||
if (event === "connect") {
|
if (event === "connect") {
|
||||||
for (let message of this.messageQueue) {
|
for (let message of this.messageQueue) {
|
||||||
this.sendChat(message);
|
this.sendChat(message);
|
||||||
@@ -45,7 +45,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
|||||||
|
|
||||||
async onOutput(output) {
|
async onOutput(output) {
|
||||||
if (output.type === "action" && output.action === "CHAT") {
|
if (output.type === "action" && output.action === "CHAT") {
|
||||||
if (this.slave.connector.connected) {
|
if (this.host.connector.connected) {
|
||||||
this.sendChat(output.message);
|
this.sendChat(output.message);
|
||||||
} else {
|
} else {
|
||||||
this.messageQueue.push(output.message);
|
this.messageQueue.push(output.message);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ describe("global_chat plugin", function() {
|
|||||||
let instancePlugin;
|
let instancePlugin;
|
||||||
|
|
||||||
before(async function() {
|
before(async function() {
|
||||||
instancePlugin = new instance.InstancePlugin(info, new mock.MockInstance(), new mock.MockSlave());
|
instancePlugin = new instance.InstancePlugin(info, new mock.MockInstance(), new mock.MockHost());
|
||||||
await instancePlugin.init();
|
await instancePlugin.init();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ When a server crashes while you are online there won't be time to immediately up
|
|||||||
Run the following commands in the folder Clusterio is installed to:
|
Run the following commands in the folder Clusterio is installed to:
|
||||||
|
|
||||||
npm install @clusterio/plugin-inventory_sync
|
npm install @clusterio/plugin-inventory_sync
|
||||||
npx clusteriomaster plugin add @clusterio/plugin-inventory_sync
|
npx clusteriocontroller plugin add @clusterio/plugin-inventory_sync
|
||||||
|
|
||||||
Substitute clusteriomaster with clusterioslave or clusterioctl if this a dedicated slave or ctl installation respectively.
|
Substitute clusteriocontroller with clusteriohost or clusterioctl if this a dedicated host or ctl installation respectively.
|
||||||
|
|
||||||
## Method of operation
|
## Method of operation
|
||||||
|
|
||||||
@@ -23,17 +23,17 @@ This plugin does event based synchronization of inventories.
|
|||||||
The greatly simplified data flow is as follows:
|
The greatly simplified data flow is as follows:
|
||||||
|
|
||||||
1. Player joins server.
|
1. Player joins server.
|
||||||
2. Scenario script asks master for exclusive access to the player.
|
2. Scenario script asks controller for exclusive access to the player.
|
||||||
3. Master grants exclusive access for the player to the instance.
|
3. Controller grants exclusive access for the player to the instance.
|
||||||
4. Scenario script checks the access response and then acts according to the situation:
|
4. Scenario script checks the access response and then acts according to the situation:
|
||||||
|
|
||||||
1. If the player has no inventory on the master then the current inventory becomes the synced inventory and the process is done.
|
1. If the player has no inventory on the controller then the current inventory becomes the synced inventory and the process is done.
|
||||||
2. If the player inventory was previously uploaded and is the same as the one stored on the master then the current inventory becomes the synced inventory and the process is done.
|
2. If the player inventory was previously uploaded and is the same as the one stored on the controller then the current inventory becomes the synced inventory and the process is done.
|
||||||
3. If the player inventory was previously uploaded but is not the same then the player inventory is deleted and the player is turned into a spectator.
|
3. If the player inventory was previously uploaded but is not the same then the player inventory is deleted and the player is turned into a spectator.
|
||||||
4. Otherwise the player inventory is kept.
|
4. Otherwise the player inventory is kept.
|
||||||
|
|
||||||
5. Scenario script asks for the player inventory from the master.
|
5. Scenario script asks for the player inventory from the controller.
|
||||||
6. Master sends it to the scenario in a stream of chunks.
|
6. Controller sends it to the scenario in a stream of chunks.
|
||||||
7. Scenario displays and updates a progress bar as each chunk is received.
|
7. Scenario displays and updates a progress bar as each chunk is received.
|
||||||
8. Once all chunks have loaded the player's synced inventory is recreated from the data and the player can start playing.
|
8. Once all chunks have loaded the player's synced inventory is recreated from the data and the player can start playing.
|
||||||
|
|
||||||
@@ -41,5 +41,5 @@ When the player leaves the inventory is uploaded if it's a synced inventory and
|
|||||||
Should an error occur during this process the player is given the option to use a temporary inventory instead, which will be merged back into the synced inventory the next time the sync succeeds on that instance.
|
Should an error occur during this process the player is given the option to use a temporary inventory instead, which will be merged back into the synced inventory the next time the sync succeeds on that instance.
|
||||||
|
|
||||||
Communication between the server and instance goes over stdout or rcon, depending on the size of the data.
|
Communication between the server and instance goes over stdout or rcon, depending on the size of the data.
|
||||||
Communication between the instance and the master server goes over websockets.
|
Communication between the instance and the controller goes over websockets.
|
||||||
Overall, we are able to achieve a latency between 3 and infinite ticks from server join, depending on the size of the inventory. The major limiter is rcon transfer speeds with larger inventories, especially if they contain blueprints.
|
Overall, we are able to achieve a latency between 3 and infinite ticks from server join, depending on the size of the inventory. The major limiter is rcon transfer speeds with larger inventories, especially if they contain blueprints.
|
||||||
Loaded 100 of 144 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user