mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 16:13:12 +09:00
Implemented forwarding of requests to the master
Implement the forwardTo function for requests to the master server.
This commit is contained in:
1 parent
5681ef9733
commit
6a8346186f
3 files changed
+15
-6
No files matched your search
@@ -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) {
|
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.slave.instanceConnections.get(instanceId);
|
||||||
|
|||||||
@@ -408,8 +408,8 @@ The following properties are recognized by the Request constructor:
|
|||||||
Target to forward request to. Can be either `'master'` to indicate
|
Target to forward request to. Can be either `'master'` to indicate
|
||||||
a slave should forward it to the master server when receiving it
|
a slave should forward it to the master server when receiving it
|
||||||
from an instance or `'instance'` to indicate it should be forwarded
|
from an instance or `'instance'` to indicate it should be forwarded
|
||||||
to the instances specified by the `instance_id` event property.
|
to the instances specified by the `instance_id` request property.
|
||||||
This works by using a default handler for the event at the links
|
This works by using a default handler for the request at the links
|
||||||
that forward it.
|
that forward it.
|
||||||
|
|
||||||
**requestProperties**:
|
**requestProperties**:
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ class Request {
|
|||||||
* Links this request is valid on. Takes an array of strings
|
* Links this request is valid on. Takes an array of strings
|
||||||
* containing "<source>-<target>" specifications.
|
* containing "<source>-<target>" specifications.
|
||||||
* @param {?string} forwardTo -
|
* @param {?string} forwardTo -
|
||||||
* Optional target to forward this request to. Only 'instance' is
|
* Optional target to forward this request to. 'instance' add
|
||||||
* currently supported and adds instance_id into the
|
* instance_id into the requestProperties and forward to the given
|
||||||
* requestProperties.
|
* instance. 'master' forwards it to the master server.
|
||||||
* @param {Object<string, Object>} requestProperties -
|
* @param {Object<string, Object>} requestProperties -
|
||||||
* Mapping of property values to JSON schema specifications for the
|
* Mapping of property values to JSON schema specifications for the
|
||||||
* properties that are valid in the data payload of this requst.
|
* properties that are valid in the data payload of this requst.
|
||||||
@@ -46,7 +46,7 @@ class Request {
|
|||||||
{"instance_id": { type: "integer" }}, requestProperties
|
{"instance_id": { type: "integer" }}, requestProperties
|
||||||
);
|
);
|
||||||
|
|
||||||
} else if (forwardTo !== null) {
|
} else if (forwardTo !== "master" && forwardTo !== null) {
|
||||||
throw new Error(`Invalid forwardTo value ${forwardTo}`);
|
throw new Error(`Invalid forwardTo value ${forwardTo}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,6 +99,9 @@ class Request {
|
|||||||
* 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
|
||||||
|
* 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
|
||||||
* request.
|
* request.
|
||||||
*
|
*
|
||||||
@@ -121,6 +124,8 @@ class Request {
|
|||||||
if (!handler) {
|
if (!handler) {
|
||||||
if (this.forwardTo === 'instance') {
|
if (this.forwardTo === 'instance') {
|
||||||
handler = link.forwardRequestToInstance;
|
handler = link.forwardRequestToInstance;
|
||||||
|
} else if (this.forwardTo === "master") {
|
||||||
|
handler = link.forwardRequestToMaster;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user