Administration of distributed workers and topologies
Administration of coordination storage that controls distributed processing can be done via command-line or web-based interface.
Both these interfaces are available out-of-the-box, but need specific storage implementation to run on.
CLI
QTopology CLI usage:
node myscript.js help
- displays a list of available commandsnode myscript.js register <uuid> <file_name>
- registers new topologynode myscript.js enable <topology_uuid>
- enables topologynode myscript.js disable <topology_uuid>
- disables topologynode myscript.js stop-topology <topology_uuid>
- stops and disables topologynode myscript.js clear-topology-error <topology_uuid>
- clears error flag for topologynode myscript.js set-topology-error <topology_uuid> <error_text>
- sets error flag for topology with given errornode myscript.js shut-down-worker <worker_name>
- sends shutdown signal to specified workernode myscript.js workers
- display a list of all workersnode myscript.js list
- display a list of all registered topologiesnode myscript.js details <topology_uuid>
- display details about given topologynode myscript.js export <topology_uuid> <output_file>
- export topology definition to destination file
CLI tool has to be attached to specific implementation, like in the following example:
"use strict";
const qtopology = require("qtopology");
const coor = require("my-custom-storage-implementation");
// instantiate custom storage implementation
let storage = new coor.MyCustomStorage();
// run CLI tool on it
let cmd = new qtopology.CommandLineHandler(storage);
cmd.run(() => {
storage.close(() => {
qtopology.logger().log("Done.");
})
});
REPL
It is also possible to start REPL mode of CLI tool - it accepts exactly the same commands as the CLI-mode above (without the node myscript.js
prefix):
"use strict";
const qtopology = require("qtopology");
const coor = require("my-custom-storage-implementation");
// instantiate custom storage implementation
let storage = new coor.MyCustomStorage();
// run CLI tool on it in REPL mode
qtopology.runRepl(storage);
An example that is provided in the demo directory:
$ node demo-repl.js
Welcome to QTopology REPL.
Type 'help' to display the list of commands
repl > list
topology.test.1 (enabled: enabled) (status: waiting) (worker: worker1)
topology.test.2 (enabled: enabled) (status: running) (worker: worker2)
topology.test.x (enabled: disabled) (status: unassigned) (worker: null)
topology.test.y (enabled: disabled) (status: error) (worker: null)
topology.test.z (enabled: enabled) (status: running) (worker: worker1)
repl >
GUI
A web application that displays all current information about workers and topologies. It also provides means to perform some actions like enabling/disabling topologies and shutting down workers.
Stand-alone web server
Web GUI tool has to be attached to specific implementation, like in the following example:
"use strict";
const qtopology = require("qtopology");
const coor = require("my-custom-storage-implementation");
// instantiate custom storage implementation
let storage = new coor.MyCustomStorage();
// start web server
let server = new qtopology.DashboardServer();
server.init(3000, storage, () => {
server.run();
});
Attaching to an Express server
The same web pages can be served inside existing Express web application,
under some predefined sub-path, e.g. /qtopology/
.
"use strict";
const qtopology = require("qtopology");
const express = require("express");
const coor = require("my-custom-storage-implementation");
// instantiate custom storage implementation
let storage = new coor.MyCustomStorage();
// start Express web server
let app = express();
app.use(bodyParser.json());
// start dashboard server with express server
let server = new qtopology.DashboardServer();
server.initForExpress(app, "qtopology", storage, () => {
if (err) {
console.log(err);
process.exit(1);
}
// ok, paths injected into Express application
// start serving requests
app.listen(3000, () => {
console.log("Express server running...");
})
});
Open web address http://localhost:3000/qtopology/
in your browser.
Express application needs to use JSON body-parser. See code above.