Implemented forwarding of requests to the master

Implement the forwardTo function for requests to the master server.
This commit is contained in:
Hornwitser committed 2020-03-13 22:46:17 +01:00
1 parent 5681ef9733
commit 6a8346186f
3 files changed
+15 -6

No files matched your search

+4
View File
@@ -358,6 +358,10 @@ class InstanceConnection extends link.Link {
}
}
async forwardRequestToMaster(message, request) {
return await request.send(this.slave, message.data);
}
async forwardEventToInstance(message, event) {
let instanceId = message.data.instance_id;
let instanceConnection = this.slave.instanceConnections.get(instanceId);
+2 -2
View File
@@ -408,8 +408,8 @@ The following properties are recognized by the Request constructor:
Target to forward request to. Can be either `'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` event property.
This works by using a default handler for the event at the links
to the instances specified by the `instance_id` request property.
This works by using a default handler for the request at the links
that forward it.
**requestProperties**:
+9 -4
View File
@@ -20,9 +20,9 @@ class Request {
* Links this request is valid on. Takes an array of strings
* containing "<source>-<target>" specifications.
* @param {?string} forwardTo -
* Optional target to forward this request to. Only 'instance' is
* currently supported and adds instance_id into the
* requestProperties.
* Optional target to forward this request to. 'instance' add
* instance_id into the requestProperties and forward to the given
* instance. 'master' forwards it to the master server.
* @param {Object<string, Object>} requestProperties -
* Mapping of property values to JSON schema specifications for the
* properties that are valid in the data payload of this requst.
@@ -46,7 +46,7 @@ class Request {
{"instance_id": { type: "integer" }}, requestProperties
);
} else if (forwardTo !== null) {
} else if (forwardTo !== "master" && forwardTo !== null) {
throw new Error(`Invalid forwardTo value ${forwardTo}`);
}
@@ -99,6 +99,9 @@ class Request {
* If forwardTo was set to 'instance' the `forwardRequestToInstance`
* method on the link is used as the default handler.
*
* If forwardTo was set to 'master' the `forwardRequesToMaster` method
* on the link is used as the default handler.
*
* Does nothing if the link is neither a source nor a target for this
* request.
*
@@ -121,6 +124,8 @@ class Request {
if (!handler) {
if (this.forwardTo === 'instance') {
handler = link.forwardRequestToInstance;
} else if (this.forwardTo === "master") {
handler = link.forwardRequestToMaster;
}
}