Skip to content

Commit a585842

Browse files
Ticket #114 : Get and update plugin configuration
1 parent 96a70fb commit a585842

51 files changed

Lines changed: 832 additions & 209 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,29 @@
1-
# AMQP1.0 protocol plugin
1+
# AMQP 1.0 protocol plugin
22

3+
**Name**
4+
5+
ProtocolAmqp
6+
7+
**Description**
8+
9+
AMQP 1.0 protocol.
10+
11+
**Link**
12+
13+
The ZIP file can be downloaded [here]().
14+
15+
**Options**
16+
17+
| Name | Description | Default value |
18+
| ----------------- | ------------------------------------------------------------------------------------------- | ------------- |
19+
| port | AMQP Port | 5672 |
20+
| maxFrameSize | Largest frame size that the sending peer is able to accept on this connection. | 1000 |
21+
| maxChannel | The channel-max value is the highest channel number that can be used on the connection | 1000 |
22+
| sessionLinkCredit | Current maximum number of messages that can be handled at the receiver endpoint of the link | 255 |
23+
| eventMeshVpn | EventMesh server VPN | default |
24+
| eventMeshUrl | EventMesh server URL | localhost |
25+
| eventMeshPort | EventMesh server Port | 4000 |
26+
27+
## Quick start
28+
29+
TODO

docs/documentation/eventmesh/plugins.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,33 @@ A plugin can manually be installed :
1515

1616
## Enable a plugin
1717

18-
Once the plugin is installed, open a command prompt and execute the command `FaasNet.EventMeshCTL.CLI.exe enable_plugin -n=<PLUGIN_NAME>` to enable the plugin.
18+
Once the plugin is installed, open a command prompt and execute the command `FaasNet.EventMeshCTL.CLI.exe enable_plugin --name=<PLUGIN_NAME>` to enable the plugin.
1919

2020
If the plugin is successfully enabled then a success message is displayed.
2121

22-
The EventMesh server must be restarted to take into consideration the new activated plugins.
22+
## Configure a plugin
23+
24+
There are two methods to configure a plugin. Either by editing the `appsettings.json` configuration file present inside the plugin directory or by using the CLI.
25+
26+
All the available configuration records can be displayed by executing the command line
27+
28+
```
29+
FaasNet.EventMeshCTL.CLI.exe get_plugin_configuration --name=<PLUGIN_NAME>
30+
```
31+
32+
For each configuration record, the CLI displays :
33+
* Unique property name.
34+
* Short description.
35+
* Configured value (coming from the configuration file).
36+
37+
Any configuration record can be updated like this
38+
39+
```
40+
FaasNet.EventMeshCTL.CLI.exe update_plugin_configuration --name=<PLUGIN_NAME> --key=<PROPERTY_KEY> --value=<PROPERTY_VALUE>
41+
```
42+
43+
> [!IMPORTANT]
44+
> Once the plugin is properly configured. The EventMesh server must be restarted in order to take into consideration your modifications.
2345
2446
## Supported plugins
2547

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,25 @@
11
# Websocket protocol plugin
22

3+
**Name**
4+
5+
ProtocolWebsocket
6+
7+
**Description**
8+
9+
Support Websocket protocol.
10+
11+
**Link**
12+
13+
The ZIP file can be downloaded [here]().
14+
15+
**Options**
16+
17+
| Name | Description | Default value |
18+
| ----------------- | ------------------------------------------------------------------------------------------- | ------------- |
19+
| port | Websocket port | 2803 |
20+
| eventMeshUrl | EventMesh server URL | localhost |
21+
| eventMeshPort | EventMesh server Port | 4000 |
22+
23+
## Quick start
24+
25+
TODO

src/EventMesh/FaasNet.EventMesh.Client/Constants.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ public class Constants
2424
{ Commands.ADD_CLIENT_REQUEST, Commands.ADD_CLIENT_RESPONSE },
2525
{ Commands.GET_ALL_PLUGINS_REQUEST, Commands.GET_ALL_PLUGINS_RESPONSE },
2626
{ Commands.ENABLE_PLUGIN_REQUEST, Commands.ENABLE_PLUGIN_RESPONSE },
27-
{ Commands.DISABLE_PLUGIN_REQUEST, Commands.DISABLE_PLUGIN_RESPONSE }
27+
{ Commands.DISABLE_PLUGIN_REQUEST, Commands.DISABLE_PLUGIN_RESPONSE },
28+
{ Commands.GET_PLUGIN_CONFIGURATION_REQUEST, Commands.GET_PLUGIN_CONFIGURATION_RESPONSE },
29+
{ Commands.UPDATE_PLUGIN_CONFIGURATION_REQUEST, Commands.UPDATE_PLUGIN_CONFIGURATION_RESPONSE }
2830
};
2931
}
3032
}

src/EventMesh/FaasNet.EventMesh.Client/EventMeshClient.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,39 @@ public EventMeshClient(string url = Constants.DefaultUrl, int port = Constants.D
208208
}
209209
}
210210

211+
public async Task<ICollection<PluginConfigurationRecordResponse>> GetPluginConfiguration(string pluginName, CancellationToken cancellationToken = default(CancellationToken))
212+
{
213+
using (var udpClient = new UdpClient())
214+
{
215+
var writeCtx = new WriteBufferContext();
216+
var package = PackageRequestBuilder.GetPluginConfiguration(pluginName);
217+
package.Serialize(writeCtx);
218+
var payload = writeCtx.Buffer.ToArray();
219+
await udpClient.SendAsync(payload, payload.Count(), new IPEndPoint(_ipAddr, _port)).WithCancellation(cancellationToken);
220+
var resultPayload = await udpClient.ReceiveAsync().WithCancellation(cancellationToken);
221+
var readCtx = new ReadBufferContext(resultPayload.Buffer);
222+
var packageResult = Package.Deserialize(readCtx);
223+
EnsureSuccessStatus(package, packageResult);
224+
return (packageResult as GetPluginConfigurationResponse).Records;
225+
}
226+
}
227+
228+
public async Task UpdatePluginConfiguration(string pluginName, string propertyKey, string propertyValue, CancellationToken cancellationToken = default(CancellationToken))
229+
{
230+
using (var udpClient = new UdpClient())
231+
{
232+
var writeCtx = new WriteBufferContext();
233+
var package = PackageRequestBuilder.UpdatePluginConfiguration(pluginName, propertyKey, propertyValue);
234+
package.Serialize(writeCtx);
235+
var payload = writeCtx.Buffer.ToArray();
236+
await udpClient.SendAsync(payload, payload.Count(), new IPEndPoint(_ipAddr, _port)).WithCancellation(cancellationToken);
237+
var resultPayload = await udpClient.ReceiveAsync().WithCancellation(cancellationToken);
238+
var readCtx = new ReadBufferContext(resultPayload.Buffer);
239+
var packageResult = Package.Deserialize(readCtx);
240+
EnsureSuccessStatus(package, packageResult);
241+
}
242+
}
243+
211244
internal static void EnsureSuccessStatus(Package packageRequest, Package packageResponse)
212245
{
213246
if (packageResponse.Header.Status != HeaderStatus.SUCCESS) throw new RuntimeClientResponseException(packageResponse.Header.Status, packageResponse.Header.Error);

src/EventMesh/FaasNet.EventMesh.Client/Messages/Commands.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,22 @@ public class Commands : IEquatable<Commands>
126126
/// Result returned when a plugin is disabled.
127127
/// </summary>
128128
public static Commands DISABLE_PLUGIN_RESPONSE = new Commands(29, "DISABLE_PLUGIN_RESPONSE");
129+
/// <summary>
130+
/// Request sent to get the plugin configuration.
131+
/// </summary>
132+
public static Commands GET_PLUGIN_CONFIGURATION_REQUEST = new Commands(30, "GET_PLUGIN_CONFIGURATION_REQUEST");
133+
/// <summary>
134+
/// Result returned to get the plugin configuration
135+
/// </summary>
136+
public static Commands GET_PLUGIN_CONFIGURATION_RESPONSE = new Commands(31, "GET_PLUGIN_CONFIGURATION_RESPONSE");
137+
/// <summary>
138+
/// Request sent to update the plugin configuration.
139+
/// </summary>
140+
public static Commands UPDATE_PLUGIN_CONFIGURATION_REQUEST = new Commands(32, "UPDATE_PLUGIN_CONFIGURATION_REQUEST");
141+
/// <summary>
142+
/// Result returned when the plugin configuration is updated.
143+
/// </summary>
144+
public static Commands UPDATE_PLUGIN_CONFIGURATION_RESPONSE = new Commands(33, "UPDATE_PLUGIN_CONFIGURATION_RESPONSE");
129145

130146

131147
private Commands(int code)

src/EventMesh/FaasNet.EventMesh.Client/Messages/Errors.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class Errors : IEquatable<Errors>
2121
public static Errors UNKNOWN_SOURCE_VPN = new Errors("UNKNOWN_SOURCE_VPN");
2222
public static Errors UNKNOWN_TARGET_VPN = new Errors("UNKNOWN_TARGET_VPN");
2323
public static Errors UNKNOWN_PLUGIN = new Errors("UNKNOWN_PLUGIN");
24+
public static Errors UNKNOWN_PLUGIN_PROPERTY = new Errors("UNKNOWN_PLUGIN_PROPERTY");
2425
public static Errors UNAUTHORIZED_PUBLISH = new Errors("UNAUTHORIZED_PUBLISH");
2526
public static Errors UNAUTHORIZED_SUBSCRIBE = new Errors("UNAUTHORIZED_SUBSCRIBE");
2627
public static Errors SESSION_LIFETIME_TOOLONG = new Errors("SESSION_LIFETIME_TOOLONG");
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using FaasNet.RaftConsensus.Client.Messages;
2+
3+
namespace FaasNet.EventMesh.Client.Messages
4+
{
5+
public class GetPluginConfigurationRequest : Package
6+
{
7+
public string Name { get; set; }
8+
9+
public override void Serialize(WriteBufferContext context)
10+
{
11+
base.Serialize(context);
12+
context.WriteString(Name);
13+
}
14+
15+
public void Extract(ReadBufferContext context)
16+
{
17+
Name = context.NextString();
18+
}
19+
}
20+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using FaasNet.RaftConsensus.Client.Messages;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace FaasNet.EventMesh.Client.Messages
6+
{
7+
public class GetPluginConfigurationResponse : Package
8+
{
9+
public GetPluginConfigurationResponse()
10+
{
11+
Records = new List<PluginConfigurationRecordResponse>();
12+
}
13+
14+
public ICollection<PluginConfigurationRecordResponse> Records { get; set; }
15+
16+
public override void Serialize(WriteBufferContext context)
17+
{
18+
base.Serialize(context);
19+
context.WriteInteger(Records.Count());
20+
foreach (var record in Records) record.Serialize(context);
21+
}
22+
23+
public void Extract(ReadBufferContext context)
24+
{
25+
var result = new List<PluginConfigurationRecordResponse>();
26+
int length = context.NextInt();
27+
for (var i = 0; i < length; i++) result.Add(PluginConfigurationRecordResponse.Extract(context));
28+
Records = result;
29+
}
30+
}
31+
32+
public class PluginConfigurationRecordResponse
33+
{
34+
public PluginConfigurationRecordResponse(string name, string description, string defaultValue, string configuredValue)
35+
{
36+
Name = name;
37+
Description = description;
38+
DefaultValue = defaultValue;
39+
ConfiguredValue = configuredValue;
40+
}
41+
42+
public string Name { get; private set; }
43+
public string Description { get; private set; }
44+
public string DefaultValue { get; private set; }
45+
public string ConfiguredValue { get; private set; }
46+
47+
public void Serialize(WriteBufferContext context)
48+
{
49+
context.WriteString(Name);
50+
context.WriteString(Description);
51+
context.WriteString(DefaultValue);
52+
context.WriteString(ConfiguredValue);
53+
}
54+
55+
public static PluginConfigurationRecordResponse Extract(ReadBufferContext context)
56+
{
57+
return new PluginConfigurationRecordResponse(context.NextString(), context.NextString(), context.NextString(), context.NextString());
58+
}
59+
}
60+
}

src/EventMesh/FaasNet.EventMesh.Client/Messages/Package.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,27 @@ public static Package Deserialize(ReadBufferContext context)
176176
return result;
177177
}
178178

179+
if(Commands.GET_PLUGIN_CONFIGURATION_REQUEST == header.Command)
180+
{
181+
var result = new GetPluginConfigurationRequest { Header = header };
182+
result.Extract(context);
183+
return result;
184+
}
185+
186+
if(Commands.GET_PLUGIN_CONFIGURATION_RESPONSE == header.Command)
187+
{
188+
var result = new GetPluginConfigurationResponse { Header = header };
189+
if (header.Status == HeaderStatus.SUCCESS) result.Extract(context);
190+
return result;
191+
}
192+
193+
if (Commands.UPDATE_PLUGIN_CONFIGURATION_REQUEST == header.Command)
194+
{
195+
var result = new UpdatePluginConfigurationRequest { Header = header };
196+
if (header.Status == HeaderStatus.SUCCESS) result.Extract(context);
197+
return result;
198+
}
199+
179200
return new Package
180201
{
181202
Header = header

0 commit comments

Comments
 (0)