Skip to content

Commit

Permalink
Allow specifying a publisher for discovery (#2309)
Browse files Browse the repository at this point in the history
Fixes #2302 - support specifying a publisher to use for discovery via query string.
  • Loading branch information
marcschier authored Jul 31, 2024
1 parent f4f0245 commit cfb550e
Show file tree
Hide file tree
Showing 73 changed files with 301 additions and 162 deletions.
8 changes: 8 additions & 0 deletions docs/web-api/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Registers a server solely using a discovery url. Requires that the onboarding ag

|Type|Name|Description|Schema|
|---|---|---|---|
|**Query**|**discovererId** <br>*optional*|Scope the registration to a specific OPC Publisher using the publisher id|string|
|**Body**|**body** <br>*required*|Server registration request|[ServerRegistrationRequestModel](definitions.md#serverregistrationrequestmodel)|


Expand All @@ -31,6 +32,7 @@ Registers a server solely using a discovery url. Requires that the onboarding ag
|---|---|---|
|**200**|The operation was successful.|No Content|
|**400**|The passed in information is invalid|[ProblemDetails](definitions.md#problemdetails)|
|**404**|The publisher specified was not found.|[ProblemDetails](definitions.md#problemdetails)|
|**500**|An internal error ocurred.|[ProblemDetails](definitions.md#problemdetails)|


Expand Down Expand Up @@ -167,6 +169,7 @@ Registers servers by running a discovery scan in a supervisor's network. Require

|Type|Name|Description|Schema|
|---|---|---|---|
|**Query**|**discovererId** <br>*optional*|Scope the discovery to a specific OPC Publisher using the publisher id|string|
|**Body**|**body** <br>*required*|Discovery request|[DiscoveryRequestModel](definitions.md#discoveryrequestmodel)|


Expand All @@ -176,6 +179,7 @@ Registers servers by running a discovery scan in a supervisor's network. Require
|---|---|---|
|**200**|The operation was successful.|No Content|
|**400**|The passed in information is invalid|[ProblemDetails](definitions.md#problemdetails)|
|**404**|The publisher specified was not found.|[ProblemDetails](definitions.md#problemdetails)|
|**500**|An internal error ocurred.|[ProblemDetails](definitions.md#problemdetails)|


Expand Down Expand Up @@ -207,6 +211,7 @@ Cancels a discovery request using the request identifier.
|Type|Name|Description|Schema|
|---|---|---|---|
|**Path**|**requestId** <br>*required*|Discovery request|string|
|**Query**|**discovererId** <br>*optional*|Scope the cancellation to a specific OPC Publisher using the publisher id|string|


##### Responses
Expand All @@ -215,6 +220,7 @@ Cancels a discovery request using the request identifier.
|---|---|---|
|**200**|The operation was successful.|No Content|
|**400**|The passed in information is invalid|[ProblemDetails](definitions.md#problemdetails)|
|**404**|The publisher specified was not found.|[ProblemDetails](definitions.md#problemdetails)|
|**500**|An internal error ocurred.|[ProblemDetails](definitions.md#problemdetails)|


Expand Down Expand Up @@ -749,6 +755,7 @@ Adds an endpoint. This will onboard the endpoint and the associated application

|Type|Name|Description|Schema|
|---|---|---|---|
|**Query**|**discovererId** <br>*optional*|Scope the registration to a specific OPC Publisher using the publisher id|string|
|**Body**|**body** <br>*optional*|Query for the endpoint to register. This must have at least the discovery url. If more information is specified it is used to validate that the application has such endpoint and if not the call will fail.|[ServerEndpointQueryModel](definitions.md#serverendpointquerymodel)|


Expand All @@ -758,6 +765,7 @@ Adds an endpoint. This will onboard the endpoint and the associated application
|---|---|---|
|**200**|The operation was successful.|string|
|**400**|The passed in information is invalid|[ProblemDetails](definitions.md#problemdetails)|
|**404**|The publisher specified was not found.|[ProblemDetails](definitions.md#problemdetails)|
|**500**|An internal error ocurred.|[ProblemDetails](definitions.md#problemdetails)|


Expand Down
1 change: 1 addition & 0 deletions docs/web-api/definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,7 @@ Contains the nodes which should be published
|**DataSetWriterId** <br>*optional*|Name of the data set writer.|string|
|**DataSetWriterWatchdogBehavior** <br>*optional*||[SubscriptionWatchdogBehavior](definitions.md#subscriptionwatchdogbehavior)|
|**DisableSubscriptionTransfer** <br>*optional*|Disable subscription transfer on reconnect|boolean|
|**DumpConnectionDiagnostics** <br>*optional*|Dump server diagnostics for the connection to enable<br>advanced troubleshooting scenarios.|boolean|
|**EncryptedAuthPassword** <br>*optional*|encrypted password|string|
|**EncryptedAuthUsername** <br>*optional*|encrypted username|string|
|**EndpointSecurityMode** <br>*optional*||[SecurityMode](definitions.md#securitymode)|
Expand Down
52 changes: 52 additions & 0 deletions docs/web-api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
"application/x-msgpack"
],
"parameters": [
{
"in": "query",
"name": "discovererId",
"description": "Scope the registration to a specific OPC Publisher using the publisher id",
"type": "string"
},
{
"in": "body",
"name": "body",
Expand All @@ -55,6 +61,12 @@
"$ref": "#/definitions/ProblemDetails"
}
},
"404": {
"description": "The publisher specified was not found.",
"schema": {
"$ref": "#/definitions/ProblemDetails"
}
},
"500": {
"description": "An internal error ocurred.",
"schema": {
Expand Down Expand Up @@ -296,6 +308,12 @@
"application/x-msgpack"
],
"parameters": [
{
"in": "query",
"name": "discovererId",
"description": "Scope the discovery to a specific OPC Publisher using the publisher id",
"type": "string"
},
{
"in": "body",
"name": "body",
Expand All @@ -316,6 +334,12 @@
"$ref": "#/definitions/ProblemDetails"
}
},
"404": {
"description": "The publisher specified was not found.",
"schema": {
"$ref": "#/definitions/ProblemDetails"
}
},
"500": {
"description": "An internal error ocurred.",
"schema": {
Expand Down Expand Up @@ -344,6 +368,12 @@
"description": "Discovery request",
"required": true,
"type": "string"
},
{
"in": "query",
"name": "discovererId",
"description": "Scope the cancellation to a specific OPC Publisher using the publisher id",
"type": "string"
}
],
"responses": {
Expand All @@ -356,6 +386,12 @@
"$ref": "#/definitions/ProblemDetails"
}
},
"404": {
"description": "The publisher specified was not found.",
"schema": {
"$ref": "#/definitions/ProblemDetails"
}
},
"500": {
"description": "An internal error ocurred.",
"schema": {
Expand Down Expand Up @@ -947,6 +983,12 @@
"application/x-msgpack"
],
"parameters": [
{
"in": "query",
"name": "discovererId",
"description": "Scope the registration to a specific OPC Publisher using the publisher id",
"type": "string"
},
{
"in": "body",
"name": "body",
Expand All @@ -969,6 +1011,12 @@
"$ref": "#/definitions/ProblemDetails"
}
},
"404": {
"description": "The publisher specified was not found.",
"schema": {
"$ref": "#/definitions/ProblemDetails"
}
},
"500": {
"description": "An internal error ocurred.",
"schema": {
Expand Down Expand Up @@ -8261,6 +8309,10 @@
"description": "Message retention setting for messages sent by\r\nthe writer if the transport supports it.",
"type": "boolean"
},
"DumpConnectionDiagnostics": {
"description": "Dump server diagnostics for the connection to enable\r\nadvanced troubleshooting scenarios.",
"type": "boolean"
},
"NodeId": {
"$ref": "#/definitions/NodeIdModel"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public class DiscoveryController : ControllerBase, IMethodController
/// </summary>
/// <param name="discover"></param>
/// <param name="servers"></param>
public DiscoveryController(INetworkDiscovery discover,
IServerDiscovery servers)
public DiscoveryController(INetworkDiscovery<object> discover,
IServerDiscovery<object> servers)
{
_discover = discover ?? throw new ArgumentNullException(nameof(discover));
_servers = servers ?? throw new ArgumentNullException(nameof(servers));
Expand Down Expand Up @@ -83,7 +83,7 @@ public async Task<ApplicationRegistrationModel> FindServerAsync(
[FromBody][Required] ServerEndpointQueryModel endpoint, CancellationToken ct = default)
{
ArgumentNullException.ThrowIfNull(endpoint);
return await _servers.FindServerAsync(endpoint, ct).ConfigureAwait(false);
return await _servers.FindServerAsync(endpoint, ct: ct).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -115,7 +115,7 @@ public async Task<bool> RegisterAsync(
CancellationToken ct = default)
{
ArgumentNullException.ThrowIfNull(request);
await _discover.RegisterAsync(request, ct).ConfigureAwait(false);
await _discover.RegisterAsync(request, ct: ct).ConfigureAwait(false);
return true;
}

Expand Down Expand Up @@ -149,7 +149,7 @@ public async Task<bool> DiscoverAsync(
CancellationToken ct = default)
{
ArgumentNullException.ThrowIfNull(request);
await _discover.DiscoverAsync(request, ct).ConfigureAwait(false);
await _discover.DiscoverAsync(request, ct: ct).ConfigureAwait(false);
return true;
}

Expand Down Expand Up @@ -182,11 +182,11 @@ public async Task<bool> CancelAsync(
CancellationToken ct = default)
{
ArgumentNullException.ThrowIfNull(request);
await _discover.CancelAsync(request, ct).ConfigureAwait(false);
await _discover.CancelAsync(request, ct: ct).ConfigureAwait(false);
return true;
}

private readonly INetworkDiscovery _discover;
private readonly IServerDiscovery _servers;
private readonly INetworkDiscovery<object> _discover;
private readonly IServerDiscovery<object> _servers;
}
}
12 changes: 9 additions & 3 deletions src/Azure.IIoT.OpcUa.Publisher.Service.Sdk/cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,7 @@ await _client.Registry.DiscoverAsync(
Discovery = options.GetValueOrDefault(DiscoveryMode.Fast,
"-d", "--discovery"),
Configuration = BuildDiscoveryConfig(options)
}).ConfigureAwait(false);
}, options.GetValueOrNull<string>("-D", "--discovererId")).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -1676,7 +1676,7 @@ await _client.Registry.CancelAsync(
new DiscoveryCancelRequestModel
{
Id = options.GetValueOrThrow<string>("-i", "--id")
}).ConfigureAwait(false);
}, options.GetValueOrNull<string>("-D", "--discovererId")).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -2065,7 +2065,7 @@ private async Task RegisterEndpointAsync(CliOptions options)
SecurityMode = options.GetValueOrNull<SecurityMode?>("-m", "--mode"),
SecurityPolicy = options.GetValueOrNull<string>("-l", "--policy"),
Certificate = options.GetValueOrNull<string>("-c", "--certificate")
}).ConfigureAwait(false);
}, options.GetValueOrNull<string>("-D", "--discovererId")).ConfigureAwait(false);

PrintResult(options, result);
}
Expand Down Expand Up @@ -2423,6 +2423,8 @@ discover Discover applications and endpoints.
with ...
-i, --id Request id for the discovery request.
-d, --discovery Set discovery mode to use
-D --discovererId
Discover using specified discoverer.
-I, --idle-time Idle time between scans in seconds
-p, --port-ranges
Port ranges to scan.
Expand All @@ -2441,6 +2443,8 @@ Port probe timeout in milliseconds
cancel Cancel application discovery.
with ...
-i, --id Request id of the discovery request (mandatory).
-D --discovererId
Discovery was started using this discoverer.
register Manually register Application
with ...
Expand Down Expand Up @@ -2535,6 +2539,8 @@ with ...
-e, --endpoint The endpoint url to match against
-c, --certificate
The certificate thumbprint to match
-D --discovererId
Onboard using specified discoverer.
-m, --mode The security mode to match
-l, --policy The security policy to match
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,38 +229,53 @@ public async Task<SupervisorModel> GetSupervisorAsync(

/// <inheritdoc/>
public async Task RegisterAsync(ServerRegistrationRequestModel request,
CancellationToken ct)
string? discovererId, CancellationToken ct)
{
ArgumentNullException.ThrowIfNull(request);
if (request.DiscoveryUrl == null)
{
throw new ArgumentException("Discovery Url missing.", nameof(request));
}
var uri = new Uri($"{_serviceUri}/v2/applications");
await _httpClient.PostAsync(uri, request, _serializer,
var uri = new UriBuilder($"{_serviceUri}/v2/applications");
if (discovererId != null)
{
uri.Query = "discovererId=" + discovererId;
}
await _httpClient.PostAsync(uri.Uri, request, _serializer,
request => request.SetTimeout(TimeSpan.FromMinutes(3)),
authorization: _authorization, ct: ct).ConfigureAwait(false);
}

/// <inheritdoc/>
public async Task DiscoverAsync(DiscoveryRequestModel request, CancellationToken ct)
public async Task DiscoverAsync(DiscoveryRequestModel request,
string? discovererId, CancellationToken ct)
{
ArgumentNullException.ThrowIfNull(request);
var uri = new Uri($"{_serviceUri}/v2/applications/discover");
await _httpClient.PostAsync(uri, request, _serializer,
var uri = new UriBuilder($"{_serviceUri}/v2/applications/discover");
if (discovererId != null)
{
uri.Query = "discovererId=" + discovererId;
}
await _httpClient.PostAsync(uri.Uri, request, _serializer,
request => request.SetTimeout(TimeSpan.FromMinutes(3)),
authorization: _authorization, ct: ct).ConfigureAwait(false);
}

/// <inheritdoc/>
public async Task CancelAsync(DiscoveryCancelRequestModel request, CancellationToken ct)
public async Task CancelAsync(DiscoveryCancelRequestModel request,
string? discovererId, CancellationToken ct)
{
if (request?.Id == null)
{
throw new ArgumentNullException(nameof(request));
}
var uri = new Uri($"{_serviceUri}/v2/applications/discover/${Uri.EscapeDataString(request.Id)}");
await _httpClient.DeleteAsync(uri,
var uri = new UriBuilder(
$"{_serviceUri}/v2/applications/discover/${Uri.EscapeDataString(request.Id)}");
if (discovererId != null)
{
uri.Query = "discovererId=" + discovererId;
}
await _httpClient.DeleteAsync(uri.Uri,
authorization: _authorization, ct: ct).ConfigureAwait(false);
}

Expand Down Expand Up @@ -408,10 +423,14 @@ await _httpClient.DeleteAsync(uri, authorization: _authorization,

/// <inheritdoc/>
public async Task<string> RegisterEndpointAsync(ServerEndpointQueryModel query,
CancellationToken ct)
string? discovererId, CancellationToken ct)
{
var uri = new Uri($"{_serviceUri}/v2/endpoints");
return await _httpClient.PutAsync<string>(uri, query,
var uri = new UriBuilder($"{_serviceUri}/v2/endpoints");
if (discovererId != null)
{
uri.Query = "discovererId=" + discovererId;
}
return await _httpClient.PutAsync<string>(uri.Uri, query,
_serializer, authorization: _authorization, ct: ct).ConfigureAwait(false);
}

Expand Down
Loading

0 comments on commit cfb550e

Please sign in to comment.