Skip to content

Commit e267888

Browse files
committed
Initial check-in for the PowerShell language worker
1 parent b01a685 commit e267888

File tree

8 files changed

+5573
-0
lines changed

8 files changed

+5573
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "src/protocol/protobuf"]
2+
path = src/protocol/protobuf
3+
url = https://github.com/Azure/azure-functions-language-worker-protobuf.git

NuGet.config

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
5+
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
6+
<add key="powershell-core" value="https://powershell.myget.org/F/powershell-core/api/v3/index.json" />
7+
</packageSources>
8+
</configuration>

src/PSWorker.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
6+
using CommandLine;
7+
using Grpc.Core;
8+
using Microsoft.Azure.WebJobs.Script.Grpc.Messages;
9+
10+
namespace Microsoft.Azure.PowerShell.Worker
11+
{
12+
public class WorkerEntry
13+
{
14+
public static void Main(string[] args)
15+
{
16+
LanguageWorker worker;
17+
Parser.Default.ParseArguments<ArgumentOptions>(args)
18+
.WithParsed(ops => worker = new LanguageWorker(ops))
19+
.WithNotParsed(err => Environment.Exit(1));
20+
}
21+
}
22+
23+
public class ArgumentOptions
24+
{
25+
[Option("host", Required = true, HelpText = "IP Address used to connect to the Host via gRPC.")]
26+
public string Host { get; set; }
27+
28+
[Option("port", Required = true, HelpText = "Port used to connect to the Host via gRPC.")]
29+
public int Port { get; set; }
30+
31+
[Option("workerId", Required = true, HelpText = "Worker ID assigned to this language worker.")]
32+
public string WorkerId { get; set; }
33+
34+
[Option("requestId", Required = true, HelpText = "Request ID used for gRPC communication with the Host.")]
35+
public string RequestId { get; set; }
36+
37+
[Option("grpcMaxMessageLength", Required = true, HelpText = "gRPC Maximum message size.")]
38+
public int MaxMessageLength { get; set; }
39+
}
40+
41+
internal class LanguageWorker
42+
{
43+
private ArgumentOptions _options;
44+
private FunctionRpc.FunctionRpcClient _client;
45+
private AsyncDuplexStreamingCall<StreamingMessage, StreamingMessage> _streamingCall;
46+
47+
internal LanguageWorker(ArgumentOptions options)
48+
{
49+
var channel = new Channel(options.Host, options.Port, ChannelCredentials.Insecure);
50+
_client = new FunctionRpc.FunctionRpcClient(channel);
51+
_streamingCall = _client.EventStream();
52+
_options = options;
53+
}
54+
}
55+
}

src/protocol/FunctionRpc.cs

Lines changed: 5384 additions & 0 deletions
Large diffs are not rendered by default.

src/protocol/FunctionRpcGrpc.cs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// <auto-generated>
2+
// Generated by the protocol buffer compiler. DO NOT EDIT!
3+
// source: FunctionRpc.proto
4+
// </auto-generated>
5+
#pragma warning disable 0414, 1591
6+
#region Designer generated code
7+
8+
using grpc = global::Grpc.Core;
9+
10+
namespace Microsoft.Azure.WebJobs.Script.Grpc.Messages {
11+
/// <summary>
12+
/// Interface exported by the server.
13+
/// </summary>
14+
public static partial class FunctionRpc
15+
{
16+
static readonly string __ServiceName = "AzureFunctionsRpcMessages.FunctionRpc";
17+
18+
static readonly grpc::Marshaller<global::Microsoft.Azure.WebJobs.Script.Grpc.Messages.StreamingMessage> __Marshaller_StreamingMessage = grpc::Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Microsoft.Azure.WebJobs.Script.Grpc.Messages.StreamingMessage.Parser.ParseFrom);
19+
20+
static readonly grpc::Method<global::Microsoft.Azure.WebJobs.Script.Grpc.Messages.StreamingMessage, global::Microsoft.Azure.WebJobs.Script.Grpc.Messages.StreamingMessage> __Method_EventStream = new grpc::Method<global::Microsoft.Azure.WebJobs.Script.Grpc.Messages.StreamingMessage, global::Microsoft.Azure.WebJobs.Script.Grpc.Messages.StreamingMessage>(
21+
grpc::MethodType.DuplexStreaming,
22+
__ServiceName,
23+
"EventStream",
24+
__Marshaller_StreamingMessage,
25+
__Marshaller_StreamingMessage);
26+
27+
/// <summary>Service descriptor</summary>
28+
public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor
29+
{
30+
get { return global::Microsoft.Azure.WebJobs.Script.Grpc.Messages.FunctionRpcReflection.Descriptor.Services[0]; }
31+
}
32+
33+
/// <summary>Base class for server-side implementations of FunctionRpc</summary>
34+
public abstract partial class FunctionRpcBase
35+
{
36+
public virtual global::System.Threading.Tasks.Task EventStream(grpc::IAsyncStreamReader<global::Microsoft.Azure.WebJobs.Script.Grpc.Messages.StreamingMessage> requestStream, grpc::IServerStreamWriter<global::Microsoft.Azure.WebJobs.Script.Grpc.Messages.StreamingMessage> responseStream, grpc::ServerCallContext context)
37+
{
38+
throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, ""));
39+
}
40+
41+
}
42+
43+
/// <summary>Client for FunctionRpc</summary>
44+
public partial class FunctionRpcClient : grpc::ClientBase<FunctionRpcClient>
45+
{
46+
/// <summary>Creates a new client for FunctionRpc</summary>
47+
/// <param name="channel">The channel to use to make remote calls.</param>
48+
public FunctionRpcClient(grpc::Channel channel) : base(channel)
49+
{
50+
}
51+
/// <summary>Creates a new client for FunctionRpc that uses a custom <c>CallInvoker</c>.</summary>
52+
/// <param name="callInvoker">The callInvoker to use to make remote calls.</param>
53+
public FunctionRpcClient(grpc::CallInvoker callInvoker) : base(callInvoker)
54+
{
55+
}
56+
/// <summary>Protected parameterless constructor to allow creation of test doubles.</summary>
57+
protected FunctionRpcClient() : base()
58+
{
59+
}
60+
/// <summary>Protected constructor to allow creation of configured clients.</summary>
61+
/// <param name="configuration">The client configuration.</param>
62+
protected FunctionRpcClient(ClientBaseConfiguration configuration) : base(configuration)
63+
{
64+
}
65+
66+
public virtual grpc::AsyncDuplexStreamingCall<global::Microsoft.Azure.WebJobs.Script.Grpc.Messages.StreamingMessage, global::Microsoft.Azure.WebJobs.Script.Grpc.Messages.StreamingMessage> EventStream(grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken))
67+
{
68+
return EventStream(new grpc::CallOptions(headers, deadline, cancellationToken));
69+
}
70+
public virtual grpc::AsyncDuplexStreamingCall<global::Microsoft.Azure.WebJobs.Script.Grpc.Messages.StreamingMessage, global::Microsoft.Azure.WebJobs.Script.Grpc.Messages.StreamingMessage> EventStream(grpc::CallOptions options)
71+
{
72+
return CallInvoker.AsyncDuplexStreamingCall(__Method_EventStream, null, options);
73+
}
74+
/// <summary>Creates a new instance of client from given <c>ClientBaseConfiguration</c>.</summary>
75+
protected override FunctionRpcClient NewInstance(ClientBaseConfiguration configuration)
76+
{
77+
return new FunctionRpcClient(configuration);
78+
}
79+
}
80+
81+
/// <summary>Creates service definition that can be registered with a server</summary>
82+
/// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
83+
public static grpc::ServerServiceDefinition BindService(FunctionRpcBase serviceImpl)
84+
{
85+
return grpc::ServerServiceDefinition.CreateBuilder()
86+
.AddMethod(__Method_EventStream, serviceImpl.EventStream).Build();
87+
}
88+
89+
}
90+
}
91+
#endregion

src/protocol/protobuf

Submodule protobuf added at 58b3dc0

src/psworker.csproj

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
<RootNamespace>Microsoft.Azure.PowerShell.Worker</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Grpc" Version="1.13.1" />
11+
<PackageReference Include="Google.Protobuf" Version="3.6.0" />
12+
<PackageReference Include="CommandLineParser" Version="2.2.1" />
13+
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.0-beta5" />
14+
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.1.0-preview.4" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<None Include="..\worker.config.json">
19+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
20+
</None>
21+
</ItemGroup>
22+
23+
</Project>

worker.config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Description":{
3+
"Language":"powershell",
4+
"Extension":".ps1",
5+
"DefaultExecutablePath":"C:\\Users\\dongbow\\AppData\\Local\\Microsoft\\dotnet\\dotnet.exe",
6+
"DefaultWorkerPath":"psworker.dll"
7+
}
8+
}

0 commit comments

Comments
 (0)