Skip to content

Commit

Permalink
Update functions binding to 2.0 model (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
ancaantochi authored Sep 5, 2018
1 parent 1ab956a commit 1bc69d1
Show file tree
Hide file tree
Showing 43 changed files with 1,574 additions and 262 deletions.
49 changes: 27 additions & 22 deletions Microsoft.Azure.Devices.Edge.sln
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{1ABF19EE-768
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "binding", "binding", "{B8B03013-8D6E-4D4E-9914-33D55074DEC8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Devices.Edge.Functions.Binding", "edge-modules\functions\binding\src\Microsoft.Azure.Devices.Edge.Functions.Binding\Microsoft.Azure.Devices.Edge.Functions.Binding.csproj", "{63120FDB-92DD-4E02-B77A-E4B51999A0BB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{33B7755E-D6F9-4F9B-86A8-5DFE9FEE674E}"
ProjectSection(SolutionItems) = preProject
edge-modules\functions\samples\host.json = edge-modules\functions\samples\host.json
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "EdgeHubTrigger-CSharp", "EdgeHubTrigger-CSharp", "{AFA4A92F-62AA-4EA9-9AE2-70E7EC5FCB12}"
ProjectSection(SolutionItems) = preProject
edge-modules\functions\samples\EdgeHubTrigger-CSharp\function.json = edge-modules\functions\samples\EdgeHubTrigger-CSharp\function.json
edge-modules\functions\samples\EdgeHubTrigger-CSharp\run.csx = edge-modules\functions\samples\EdgeHubTrigger-CSharp\run.csx
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Devices.Edge.Storage", "edge-util\src\Microsoft.Azure.Devices.Edge.Storage\Microsoft.Azure.Devices.Edge.Storage.csproj", "{DB92F6C3-A611-40C5-B464-8F11A3EE1AC3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Devices.Edge.Storage.RocksDb", "edge-util\src\Microsoft.Azure.Devices.Edge.Storage.RocksDb\Microsoft.Azure.Devices.Edge.Storage.RocksDb.csproj", "{D6BFCE1F-0F53-43F1-8D2B-FC0FF8EEFA9C}"
Expand All @@ -120,11 +112,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docker", "docker", "{64E95D7B-8541-4A88-A291-8BE3445FB8FF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "bin", "bin", "{80688705-AEFD-4297-907E-2B20DAFBB5D5}"
ProjectSection(SolutionItems) = preProject
edge-modules\functions\samples\bin\extensions.json = edge-modules\functions\samples\bin\extensions.json
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "linux", "linux", "{BCAA863C-8BC2-4FB1-9D9E-7BCADBCFC3A5}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "amd64", "amd64", "{B5BB5CDE-E6C7-4896-A66E-17D81BDB9A31}"
Expand Down Expand Up @@ -168,6 +155,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MessagesAnalyzer", "edge-mo
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LeafDevice", "smoke\LeafDevice\LeafDevice.csproj", "{C5CBC493-96A4-4628-A952-8C7B9EEF1441}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.WebJobs.Extensions.EdgeHub", "edge-modules\functions\binding\src\Microsoft.Azure.WebJobs.Extensions.EdgeHub\Microsoft.Azure.WebJobs.Extensions.EdgeHub.csproj", "{0D5C5996-7414-47D2-AF0F-C68E0E3F3AA4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "EdgeHubTrigger-CSharp", "EdgeHubTrigger-CSharp", "{C3BDC9FA-B7D8-44F3-970F-D24281335F46}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EdgeHubTriggerCSharp", "edge-modules\functions\samples\EdgeHubTrigger-Csharp\EdgeHubTriggerCSharp.csproj", "{B8D5312A-B37B-4FA3-8B80-2D1A93077DDF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "bin", "bin", "{3A879277-5A61-4A6A-BB27-5281FA83B1D3}"
ProjectSection(SolutionItems) = preProject
edge-modules\functions\samples\bin\extensions.json = edge-modules\functions\samples\bin\extensions.json
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
CodeCoverage|Any CPU = CodeCoverage|Any CPU
Expand Down Expand Up @@ -325,12 +323,6 @@ Global
{D67D382A-5F16-4AB2-8082-DBE62C33E5B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D67D382A-5F16-4AB2-8082-DBE62C33E5B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D67D382A-5F16-4AB2-8082-DBE62C33E5B1}.Release|Any CPU.Build.0 = Release|Any CPU
{63120FDB-92DD-4E02-B77A-E4B51999A0BB}.CodeCoverage|Any CPU.ActiveCfg = CodeCoverage|Any CPU
{63120FDB-92DD-4E02-B77A-E4B51999A0BB}.CodeCoverage|Any CPU.Build.0 = CodeCoverage|Any CPU
{63120FDB-92DD-4E02-B77A-E4B51999A0BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{63120FDB-92DD-4E02-B77A-E4B51999A0BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63120FDB-92DD-4E02-B77A-E4B51999A0BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63120FDB-92DD-4E02-B77A-E4B51999A0BB}.Release|Any CPU.Build.0 = Release|Any CPU
{DB92F6C3-A611-40C5-B464-8F11A3EE1AC3}.CodeCoverage|Any CPU.ActiveCfg = CodeCoverage|Any CPU
{DB92F6C3-A611-40C5-B464-8F11A3EE1AC3}.CodeCoverage|Any CPU.Build.0 = CodeCoverage|Any CPU
{DB92F6C3-A611-40C5-B464-8F11A3EE1AC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -415,6 +407,18 @@ Global
{C5CBC493-96A4-4628-A952-8C7B9EEF1441}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C5CBC493-96A4-4628-A952-8C7B9EEF1441}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C5CBC493-96A4-4628-A952-8C7B9EEF1441}.Release|Any CPU.Build.0 = Release|Any CPU
{0D5C5996-7414-47D2-AF0F-C68E0E3F3AA4}.CodeCoverage|Any CPU.ActiveCfg = CodeCoverage|Any CPU
{0D5C5996-7414-47D2-AF0F-C68E0E3F3AA4}.CodeCoverage|Any CPU.Build.0 = CodeCoverage|Any CPU
{0D5C5996-7414-47D2-AF0F-C68E0E3F3AA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0D5C5996-7414-47D2-AF0F-C68E0E3F3AA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0D5C5996-7414-47D2-AF0F-C68E0E3F3AA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0D5C5996-7414-47D2-AF0F-C68E0E3F3AA4}.Release|Any CPU.Build.0 = Release|Any CPU
{B8D5312A-B37B-4FA3-8B80-2D1A93077DDF}.CodeCoverage|Any CPU.ActiveCfg = Debug|Any CPU
{B8D5312A-B37B-4FA3-8B80-2D1A93077DDF}.CodeCoverage|Any CPU.Build.0 = Debug|Any CPU
{B8D5312A-B37B-4FA3-8B80-2D1A93077DDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B8D5312A-B37B-4FA3-8B80-2D1A93077DDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B8D5312A-B37B-4FA3-8B80-2D1A93077DDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B8D5312A-B37B-4FA3-8B80-2D1A93077DDF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -454,14 +458,11 @@ Global
{C4502187-81D7-4299-85C3-64AE241503E0} = {578D5330-2F72-44C6-9DB5-C93B3F42C473}
{1ABF19EE-7689-4EE3-A099-16111A8F16F4} = {B8B03013-8D6E-4D4E-9914-33D55074DEC8}
{B8B03013-8D6E-4D4E-9914-33D55074DEC8} = {C4502187-81D7-4299-85C3-64AE241503E0}
{63120FDB-92DD-4E02-B77A-E4B51999A0BB} = {1ABF19EE-7689-4EE3-A099-16111A8F16F4}
{33B7755E-D6F9-4F9B-86A8-5DFE9FEE674E} = {C4502187-81D7-4299-85C3-64AE241503E0}
{AFA4A92F-62AA-4EA9-9AE2-70E7EC5FCB12} = {33B7755E-D6F9-4F9B-86A8-5DFE9FEE674E}
{DB92F6C3-A611-40C5-B464-8F11A3EE1AC3} = {66964A75-04AC-4FDE-8505-E6CB2EF90BE8}
{D6BFCE1F-0F53-43F1-8D2B-FC0FF8EEFA9C} = {66964A75-04AC-4FDE-8505-E6CB2EF90BE8}
{3EB5B58A-5820-44E7-9558-917C105B940D} = {373FFF5E-E84C-4789-B768-676FFF51E7A6}
{64E95D7B-8541-4A88-A291-8BE3445FB8FF} = {33B7755E-D6F9-4F9B-86A8-5DFE9FEE674E}
{80688705-AEFD-4297-907E-2B20DAFBB5D5} = {33B7755E-D6F9-4F9B-86A8-5DFE9FEE674E}
{BCAA863C-8BC2-4FB1-9D9E-7BCADBCFC3A5} = {64E95D7B-8541-4A88-A291-8BE3445FB8FF}
{B5BB5CDE-E6C7-4896-A66E-17D81BDB9A31} = {BCAA863C-8BC2-4FB1-9D9E-7BCADBCFC3A5}
{31B0F93F-3E58-4C66-9DCC-24236EA81F16} = {BCAA863C-8BC2-4FB1-9D9E-7BCADBCFC3A5}
Expand All @@ -478,6 +479,10 @@ Global
{54771470-860C-4853-9318-6DB4EA76B595} = {578D5330-2F72-44C6-9DB5-C93B3F42C473}
{047DC795-A159-4BFF-AC0F-4DCE51A79C2C} = {578D5330-2F72-44C6-9DB5-C93B3F42C473}
{C5CBC493-96A4-4628-A952-8C7B9EEF1441} = {871A0862-7480-49C3-ACEB-9A60E9CE5B61}
{0D5C5996-7414-47D2-AF0F-C68E0E3F3AA4} = {1ABF19EE-7689-4EE3-A099-16111A8F16F4}
{C3BDC9FA-B7D8-44F3-970F-D24281335F46} = {33B7755E-D6F9-4F9B-86A8-5DFE9FEE674E}
{B8D5312A-B37B-4FA3-8B80-2D1A93077DDF} = {C3BDC9FA-B7D8-44F3-970F-D24281335F46}
{3A879277-5A61-4A6A-BB27-5281FA83B1D3} = {33B7755E-D6F9-4F9B-86A8-5DFE9FEE674E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D71830F5-3AF5-46B4-8A9E-1DCE4F2253AC}
Expand Down
7 changes: 0 additions & 7 deletions edge-modules/functions/binding/docker/linux/amd64/Dockerfile

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) Microsoft. All rights reserved.

namespace Microsoft.Azure.WebJobs.Extensions.EdgeHub
{
//
// Code ported from http://blogs.msdn.com/b/pfxteam/archive/2012/02/12/10266988.aspx
//
using System;
using System.Threading;
using System.Threading.Tasks;

sealed class AsyncLock : IDisposable
{
readonly Task<Releaser> releaser;
readonly SemaphoreSlim semaphore;

public AsyncLock()
: this(1)
{
}

public AsyncLock(int maximumConcurrency)
{
this.releaser = Task.FromResult(new Releaser(this));
this.semaphore = new SemaphoreSlim(maximumConcurrency, maximumConcurrency);
}

public Task<Releaser> LockAsync() => this.LockAsync(CancellationToken.None);

public Task<Releaser> LockAsync(CancellationToken token)
{
Task wait = this.semaphore.WaitAsync(token);
return wait.Status == TaskStatus.RanToCompletion ? this.releaser :
wait.ContinueWith((_, state) => new Releaser((AsyncLock)state),
this, CancellationToken.None,
TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Default);
}

/// <inheritdoc />
public void Dispose() => this.semaphore.Dispose();

public struct Releaser : IDisposable
{
readonly AsyncLock toRelease;
int disposed;

public Releaser(AsyncLock toRelease)
{
this.toRelease = toRelease ?? throw new ArgumentNullException(nameof(toRelease));
this.disposed = 0;
}

public void Dispose()
{
if (0 == Interlocked.Exchange(ref this.disposed, 1))
{
this.toRelease.semaphore.Release();
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

namespace Microsoft.Azure.Devices.Edge.Functions.Binding
namespace Microsoft.Azure.WebJobs.Extensions.EdgeHub
{
using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.

namespace Microsoft.Azure.Devices.Edge.Functions.Binding
namespace Microsoft.Azure.WebJobs.Extensions.EdgeHub
{
using System;
using Microsoft.Azure.WebJobs.Description;

[Binding]
[AttributeUsage(AttributeTargets.Parameter)]
public class EdgeHubAttribute : Attribute
{
public string OutputName { get; set; }

public int BatchSize { get; set; }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

namespace Microsoft.Azure.Devices.Edge.Functions.Binding
namespace Microsoft.Azure.WebJobs.Extensions.EdgeHub
{
using System;
using Microsoft.Azure.WebJobs.Description;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright (c) Microsoft. All rights reserved.

namespace Microsoft.Azure.Devices.Edge.Functions.Binding
namespace Microsoft.Azure.WebJobs.Extensions.EdgeHub
{
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.Azure.Devices.Client;
using Microsoft.Azure.Devices.Edge.Functions.Binding.Bindings;
using Microsoft.Azure.WebJobs.Host.Triggers;

/// <summary>
Expand All @@ -35,11 +34,6 @@ public async Task<ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext
return null;
}

if (parameter.ParameterType != typeof(Message) && parameter.ParameterType != typeof(string))
{
throw new InvalidOperationException($"Can't bind EdgeHubTriggerAttribute to type '{parameter.ParameterType}'.");
}

await this.TrySetEventDefaultHandlerAsync().ConfigureAwait(false);

var messageProcessor = new EdgeHubMessageProcessor();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.Azure.WebJobs.Extensions.EdgeHub;
using Microsoft.Azure.WebJobs.Hosting;

[assembly: WebJobsStartup(typeof(EdgeHubWebJobsStartup))]

namespace Microsoft.Azure.WebJobs.Extensions.EdgeHub
{
using Microsoft.Azure.WebJobs.Extensions.EdgeHub.Config;
using Microsoft.Azure.WebJobs.Hosting;

public class EdgeHubWebJobsStartup : IWebJobsStartup
{
public void Configure(IWebJobsBuilder builder) => builder.AddEdge();
}
}
Loading

0 comments on commit 1bc69d1

Please sign in to comment.