Skip to content

Commit

Permalink
[PnP] Port pnp to 1.0.10 (#3376)
Browse files Browse the repository at this point in the history
Cherry picking all the PnP changes from master to 1.0.10:

4425533
739954d
3aa7766
c8a78ee
0ee6978
777f2a5
481c2d9
4ddd047
f385a59
  • Loading branch information
dylanbronson authored Aug 10, 2020
1 parent 246c9ae commit f8da2f6
Show file tree
Hide file tree
Showing 86 changed files with 1,238 additions and 473 deletions.
4 changes: 3 additions & 1 deletion builds/e2e/templates/e2e-run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ steps:
env:
E2E_DPS_GROUP_KEY: $(TestDpsGroupKeySymmetric)
E2E_EVENT_HUB_ENDPOINT: $(TestEventHubCompatibleEndpoint)
E2E_PREVIEW_EVENT_HUB_ENDPOINT: $(TestPreviewEventHubCompatibleEndpoint)
E2E_IOT_HUB_CONNECTION_STRING: $(TestIotHubConnectionString)
E2E_PREVIEW_IOT_HUB_CONNECTION_STRING: $(TestPreviewIotHubConnectionString)
E2E_REGISTRIES__0__PASSWORD: $(TestContainerRegistryPassword)
E2E_ROOT_CA_PASSWORD: $(TestRootCaPassword)

Expand Down Expand Up @@ -60,5 +62,5 @@ steps:
displayName: Publish logs
inputs:
PathtoPublish: $(Build.ArtifactStagingDirectory)/logs
ArtifactName: logs-end-to-end-$(Build.BuildNumber)-$(os)-$(arch)
ArtifactName: logs-end-to-end-$(Build.BuildNumber)-$(os)-$(arch)-$(artifactName)
condition: succeededOrFailed()
2 changes: 2 additions & 0 deletions builds/e2e/templates/e2e-setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ steps:
TestContainerRegistryPassword,
TestDpsGroupKeySymmetric,
TestEventHubCompatibleEndpoint,
TestPreviewEventHubCompatibleEndpoint,
TestIotedgedPackageRootSigningCert,
TestIotHubConnectionString,
TestPreviewIotHubConnectionString,
TestRootCaCertificate,
TestRootCaKey,
TestRootCaPassword
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public Task<IDeviceListener> GetDeviceListener()
.GetOrElse(
async () =>
{
IDeviceListener dl = await this.connectionProvider.GetDeviceListenerAsync(this.identity);
// TODO: Implement plug and play for AMQP
IDeviceListener dl = await this.connectionProvider.GetDeviceListenerAsync(this.identity, Option.None<string>());
var deviceProxy = new DeviceProxy(this, this.identity);
dl.BindDeviceProxy(deviceProxy);
this.deviceListener = Option.Some(dl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ static class IotHubAmqpProperty
public static readonly AmqpSymbol QueuePartitionKey = "x-opt-partition-key";
public static readonly AmqpSymbol ChannelCorrelationId = AmqpConstants.Vendor + ":channel-correlation-id";
public static readonly AmqpSymbol GatewayReconnect = AmqpConstants.Vendor + ":gateway-reconnect";
public static readonly AmqpSymbol ModelId = AmqpConstants.Vendor + ":model-id";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public DeviceBoundLinkHandler(
IDictionary<string, string> boundVariables,
IConnectionHandler connectionHandler,
IMessageConverter<AmqpMessage> messageConverter,
IProductInfoStore productInfoStore)
: base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, productInfoStore)
IMetadataStore metadataStore)
: base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, metadataStore)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace Microsoft.Azure.Devices.Edge.Hub.Amqp.LinkHandlers
using Microsoft.Azure.Devices.Edge.Hub.Core.Device;
using Microsoft.Azure.Devices.Edge.Hub.Core.Identity;
using Microsoft.Azure.Devices.Edge.Util;
using Microsoft.Azure.Devices.Edge.Util.Metrics;
using Microsoft.Extensions.Logging;

/// <summary>
Expand All @@ -29,8 +28,8 @@ public EventsLinkHandler(
IDictionary<string, string> boundVariables,
IConnectionHandler connectionHandler,
IMessageConverter<AmqpMessage> messageConverter,
IProductInfoStore productInfoStore)
: base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, productInfoStore)
IMetadataStore metadataStore)
: base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, metadataStore)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.Azure.Devices.Edge.Hub.Amqp.LinkHandlers
public abstract class LinkHandler : ILinkHandler
{
readonly IConnectionHandler connectionHandler;
readonly IProductInfoStore productInfoStore;
readonly IMetadataStore metadataStore;

protected LinkHandler(
IIdentity identity,
Expand All @@ -23,7 +23,7 @@ protected LinkHandler(
IDictionary<string, string> boundVariables,
IConnectionHandler connectionHandler,
IMessageConverter<AmqpMessage> messageConverter,
IProductInfoStore productInfoStore)
IMetadataStore metadataStore)
{
this.Identity = Preconditions.CheckNotNull(identity, nameof(identity));
this.MessageConverter = Preconditions.CheckNotNull(messageConverter, nameof(messageConverter));
Expand All @@ -32,13 +32,19 @@ protected LinkHandler(
this.LinkUri = Preconditions.CheckNotNull(requestUri, nameof(requestUri));
this.Link.SafeAddClosed(this.OnLinkClosed);
this.connectionHandler = Preconditions.CheckNotNull(connectionHandler, nameof(connectionHandler));
this.productInfoStore = Preconditions.CheckNotNull(productInfoStore, nameof(productInfoStore));
this.metadataStore = Preconditions.CheckNotNull(metadataStore, nameof(metadataStore));

string clientVersion = null;
if (this.Link.Settings?.Properties?.TryGetValue(IotHubAmqpProperty.ClientVersion, out clientVersion) ?? false)
{
this.ClientVersion = Option.Maybe(clientVersion);
}

string modelId = null;
if (this.Link.Settings?.Properties?.TryGetValue(IotHubAmqpProperty.ModelId, out modelId) ?? false)
{
this.ModelId = Option.Maybe(modelId);
}
}

public IAmqpLink Link { get; }
Expand All @@ -61,6 +67,8 @@ protected LinkHandler(

protected Option<string> ClientVersion { get; }

public Option<string> ModelId { get; }

public async Task OpenAsync(TimeSpan timeout)
{
if (!await this.Authenticate())
Expand Down Expand Up @@ -105,9 +113,11 @@ protected async Task<bool> Authenticate()
bool authenticated = await amqpAuth.AuthenticateAsync(this.Identity.Id);
if (authenticated)
{
await this.ClientVersion
string productInfo = string.Empty;
this.ClientVersion
.Filter(c => !string.IsNullOrWhiteSpace(c))
.ForEachAsync(c => this.productInfoStore.SetProductInfo(this.Identity.Id, c));
.ForEach(c => productInfo = c);
await this.metadataStore.SetMetadata(this.Identity.Id, productInfo, this.ModelId);
}

return authenticated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ public class LinkHandlerProvider : ILinkHandlerProvider
readonly IMessageConverter<AmqpMessage> twinMessageConverter;
readonly IMessageConverter<AmqpMessage> methodMessageConverter;
readonly IIdentityProvider identityProvider;
readonly IProductInfoStore productInfoStore;
readonly IMetadataStore metadataStore;
readonly IDictionary<(UriPathTemplate Template, bool IsReceiver), LinkType> templatesList;

public LinkHandlerProvider(
IMessageConverter<AmqpMessage> messageConverter,
IMessageConverter<AmqpMessage> twinMessageConverter,
IMessageConverter<AmqpMessage> methodMessageConverter,
IIdentityProvider identityProvider,
IProductInfoStore productInfoStore)
: this(messageConverter, twinMessageConverter, methodMessageConverter, identityProvider, productInfoStore, DefaultTemplatesList)
IMetadataStore metadataStore)
: this(messageConverter, twinMessageConverter, methodMessageConverter, identityProvider, metadataStore, DefaultTemplatesList)
{
}

Expand All @@ -52,14 +52,14 @@ public LinkHandlerProvider(
IMessageConverter<AmqpMessage> twinMessageConverter,
IMessageConverter<AmqpMessage> methodMessageConverter,
IIdentityProvider identityProvider,
IProductInfoStore productInfoStore,
IMetadataStore metadataStore,
IDictionary<(UriPathTemplate Template, bool IsReceiver), LinkType> templatesList)
{
this.messageConverter = Preconditions.CheckNotNull(messageConverter, nameof(messageConverter));
this.twinMessageConverter = Preconditions.CheckNotNull(twinMessageConverter, nameof(twinMessageConverter));
this.methodMessageConverter = Preconditions.CheckNotNull(methodMessageConverter, nameof(methodMessageConverter));
this.identityProvider = Preconditions.CheckNotNull(identityProvider, nameof(identityProvider));
this.productInfoStore = Preconditions.CheckNotNull(productInfoStore, nameof(productInfoStore));
this.metadataStore = Preconditions.CheckNotNull(metadataStore, nameof(metadataStore));
this.templatesList = Preconditions.CheckNotNull(templatesList, nameof(templatesList));
}

Expand All @@ -86,25 +86,25 @@ internal ILinkHandler GetLinkHandler(LinkType linkType, IAmqpLink link, Uri uri,
switch (linkType)
{
case LinkType.C2D:
return new DeviceBoundLinkHandler(identity, link as ISendingAmqpLink, uri, boundVariables, connectionHandler, this.messageConverter, this.productInfoStore);
return new DeviceBoundLinkHandler(identity, link as ISendingAmqpLink, uri, boundVariables, connectionHandler, this.messageConverter, this.metadataStore);

case LinkType.Events:
return new EventsLinkHandler(identity, link as IReceivingAmqpLink, uri, boundVariables, connectionHandler, this.messageConverter, this.productInfoStore);
return new EventsLinkHandler(identity, link as IReceivingAmqpLink, uri, boundVariables, connectionHandler, this.messageConverter, this.metadataStore);

case LinkType.ModuleMessages:
return new ModuleMessageLinkHandler(identity, link as ISendingAmqpLink, uri, boundVariables, connectionHandler, this.messageConverter, this.productInfoStore);
return new ModuleMessageLinkHandler(identity, link as ISendingAmqpLink, uri, boundVariables, connectionHandler, this.messageConverter, this.metadataStore);

case LinkType.MethodSending:
return new MethodSendingLinkHandler(identity, link as ISendingAmqpLink, uri, boundVariables, connectionHandler, this.methodMessageConverter, this.productInfoStore);
return new MethodSendingLinkHandler(identity, link as ISendingAmqpLink, uri, boundVariables, connectionHandler, this.methodMessageConverter, this.metadataStore);

case LinkType.MethodReceiving:
return new MethodReceivingLinkHandler(identity, link as IReceivingAmqpLink, uri, boundVariables, connectionHandler, this.methodMessageConverter, this.productInfoStore);
return new MethodReceivingLinkHandler(identity, link as IReceivingAmqpLink, uri, boundVariables, connectionHandler, this.methodMessageConverter, this.metadataStore);

case LinkType.TwinReceiving:
return new TwinReceivingLinkHandler(identity, link as IReceivingAmqpLink, uri, boundVariables, connectionHandler, this.twinMessageConverter, this.productInfoStore);
return new TwinReceivingLinkHandler(identity, link as IReceivingAmqpLink, uri, boundVariables, connectionHandler, this.twinMessageConverter, this.metadataStore);

case LinkType.TwinSending:
return new TwinSendingLinkHandler(identity, link as ISendingAmqpLink, uri, boundVariables, connectionHandler, this.twinMessageConverter, this.productInfoStore);
return new TwinSendingLinkHandler(identity, link as ISendingAmqpLink, uri, boundVariables, connectionHandler, this.twinMessageConverter, this.metadataStore);

default:
throw new InvalidOperationException($"Invalid link type {linkType}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public MethodReceivingLinkHandler(
IDictionary<string, string> boundVariables,
IConnectionHandler connectionHandler,
IMessageConverter<AmqpMessage> messageConverter,
IProductInfoStore productInfoStore)
: base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, productInfoStore)
IMetadataStore metadataStore)
: base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, metadataStore)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public MethodSendingLinkHandler(
IDictionary<string, string> boundVariables,
IConnectionHandler connectionHandler,
IMessageConverter<AmqpMessage> messageConverter,
IProductInfoStore productInfoStore)
: base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, productInfoStore)
IMetadataStore metadataStore)
: base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, metadataStore)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public ModuleMessageLinkHandler(
IDictionary<string, string> boundVariables,
IConnectionHandler connectionHandler,
IMessageConverter<AmqpMessage> messageConverter,
IProductInfoStore productInfoStore)
: base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, productInfoStore)
IMetadataStore metadataStore)
: base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, metadataStore)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ protected ReceivingLinkHandler(
IDictionary<string, string> boundVariables,
IConnectionHandler connectionHandler,
IMessageConverter<AmqpMessage> messageConverter,
IProductInfoStore productInfoStore)
: base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, productInfoStore)
IMetadataStore metadataStore)
: base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, metadataStore)
{
Preconditions.CheckArgument(link.IsReceiver, $"Link {requestUri} cannot receive");
this.ReceivingLink = link;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ protected SendingLinkHandler(
IDictionary<string, string> boundVariables,
IConnectionHandler connectionHandler,
IMessageConverter<AmqpMessage> messageConverter,
IProductInfoStore productInfoStore)
: base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, productInfoStore)
IMetadataStore metadataStore)
: base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, metadataStore)
{
Preconditions.CheckArgument(!link.IsReceiver, $"Link {requestUri} cannot send");
this.SendingAmqpLink = link;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public TwinReceivingLinkHandler(
IDictionary<string, string> boundVariables,
IConnectionHandler connectionHandler,
IMessageConverter<AmqpMessage> messageConverter,
IProductInfoStore productInfoStore)
: base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, productInfoStore)
IMetadataStore metadataStore)
: base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, metadataStore)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public TwinSendingLinkHandler(
IDictionary<string, string> boundVariables,
IConnectionHandler connectionHandler,
IMessageConverter<AmqpMessage> messageConverter,
IProductInfoStore productInfoStore)
: base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, productInfoStore)
IMetadataStore metadataStore)
: base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, metadataStore)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,29 @@ namespace Microsoft.Azure.Devices.Edge.Hub.CloudProxy

public class ClientProvider : IClientProvider
{
public IClient Create(IIdentity identity, IAuthenticationMethod authenticationMethod, ITransportSettings[] transportSettings)
public IClient Create(IIdentity identity, IAuthenticationMethod authenticationMethod, ITransportSettings[] transportSettings, Option<string> modelId)
{
Preconditions.CheckNotNull(identity, nameof(identity));
Preconditions.CheckNotNull(transportSettings, nameof(transportSettings));
Preconditions.CheckNotNull(authenticationMethod, nameof(authenticationMethod));
modelId.ForEach(m => Preconditions.CheckNonWhiteSpace(m, nameof(m)));

Option<ClientOptions> options = modelId.Match(
m => Option.Some(new ClientOptions { ModelId = m }),
() => Option.None<ClientOptions>());

if (identity is IModuleIdentity)
{
ModuleClient moduleClient = ModuleClient.Create(identity.IotHubHostName, authenticationMethod, transportSettings);
ModuleClient moduleClient = options.Match(
o => ModuleClient.Create(identity.IotHubHostName, authenticationMethod, transportSettings, o),
() => ModuleClient.Create(identity.IotHubHostName, authenticationMethod, transportSettings));
return new ModuleClientWrapper(moduleClient);
}
else if (identity is IDeviceIdentity)
{
DeviceClient deviceClient = DeviceClient.Create(identity.IotHubHostName, authenticationMethod, transportSettings);
DeviceClient deviceClient = options.Match(
o => DeviceClient.Create(identity.IotHubHostName, authenticationMethod, transportSettings, o),
() => DeviceClient.Create(identity.IotHubHostName, authenticationMethod, transportSettings));
return new DeviceClientWrapper(deviceClient);
}

Expand Down Expand Up @@ -64,7 +73,7 @@ public async Task<IClient> CreateAsync(IIdentity identity, ITransportSettings[]
return new ModuleClientWrapper(moduleClient);
}

public IClient Create(IIdentity identity, ITokenProvider tokenProvider, ITransportSettings[] transportSettings)
public IClient Create(IIdentity identity, ITokenProvider tokenProvider, ITransportSettings[] transportSettings, Option<string> modelId)
{
Preconditions.CheckNotNull(identity, nameof(identity));
Preconditions.CheckNotNull(transportSettings, nameof(transportSettings));
Expand All @@ -73,10 +82,10 @@ public IClient Create(IIdentity identity, ITokenProvider tokenProvider, ITranspo
switch (identity)
{
case IModuleIdentity moduleIdentity:
return this.Create(identity, new ModuleAuthentication(tokenProvider, moduleIdentity.DeviceId, moduleIdentity.ModuleId), transportSettings);
return this.Create(identity, new ModuleAuthentication(tokenProvider, moduleIdentity.DeviceId, moduleIdentity.ModuleId), transportSettings, modelId);

case IDeviceIdentity deviceIdentity:
return this.Create(identity, new DeviceAuthentication(tokenProvider, deviceIdentity.DeviceId), transportSettings);
return this.Create(identity, new DeviceAuthentication(tokenProvider, deviceIdentity.DeviceId), transportSettings, modelId);

default:
throw new InvalidOperationException($"Invalid client identity type {identity.GetType()}");
Expand Down
Loading

0 comments on commit f8da2f6

Please sign in to comment.