* no-ops for other messages

* NewStreamingMessageTemplate additions

* dongbo's comments
This commit is contained in:
Tyler James Leonhardt 2019-03-08 11:26:44 -08:00 коммит произвёл GitHub
Родитель c0c9f47006
Коммит 2bb6ab4388
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 82 добавлений и 14 удалений

Просмотреть файл

@ -12,6 +12,7 @@ using Microsoft.Azure.Functions.PowerShellWorker.Messaging;
using Microsoft.Azure.Functions.PowerShellWorker.PowerShell;
using Microsoft.Azure.Functions.PowerShellWorker.Utility;
using Microsoft.Azure.WebJobs.Script.Grpc.Messages;
using LogLevel = Microsoft.Azure.WebJobs.Script.Grpc.Messages.RpcLog.Types.Level;
namespace Microsoft.Azure.Functions.PowerShellWorker
{
@ -24,33 +25,58 @@ namespace Microsoft.Azure.Functions.PowerShellWorker
// Indicate whether the FunctionApp has been initialized.
private bool _isFunctionAppInitialized;
private Dictionary<StreamingMessage.ContentOneofCase, Func<StreamingMessage, StreamingMessage>> _requestHandlers =
new Dictionary<StreamingMessage.ContentOneofCase, Func<StreamingMessage, StreamingMessage>>();
internal RequestProcessor(MessagingStream msgStream)
{
_msgStream = msgStream;
_powershellPool = new PowerShellManagerPool(msgStream);
_functionLoader = new FunctionLoader();
// Host sends capabilities/init data to worker
_requestHandlers.Add(StreamingMessage.ContentOneofCase.WorkerInitRequest, ProcessWorkerInitRequest);
// Host sends terminate message to worker.
// Worker terminates if it can, otherwise host terminates after a grace period
_requestHandlers.Add(StreamingMessage.ContentOneofCase.WorkerTerminate, ProcessWorkerTerminateRequest);
// Add any worker relevant status to response
_requestHandlers.Add(StreamingMessage.ContentOneofCase.WorkerStatusRequest, ProcessWorkerStatusRequest);
// On file change event, host sends notification to worker
_requestHandlers.Add(StreamingMessage.ContentOneofCase.FileChangeEventRequest, ProcessFileChangeEventRequest);
// Host sends required metadata to worker to load function
_requestHandlers.Add(StreamingMessage.ContentOneofCase.FunctionLoadRequest, ProcessFunctionLoadRequest);
// Host requests a given invocation
_requestHandlers.Add(StreamingMessage.ContentOneofCase.InvocationRequest, ProcessInvocationRequest);
// Host sends cancel message to attempt to cancel an invocation.
// If an invocation is cancelled, host will receive an invocation response with status cancelled.
_requestHandlers.Add(StreamingMessage.ContentOneofCase.InvocationCancel, ProcessInvocationCancelRequest);
_requestHandlers.Add(StreamingMessage.ContentOneofCase.FunctionEnvironmentReloadRequest, ProcessFunctionEnvironmentReloadRequest);
}
internal async Task ProcessRequestLoop()
{
var logger = new RpcLogger(_msgStream);
StreamingMessage request, response;
while (await _msgStream.MoveNext())
{
request = _msgStream.GetCurrentMessage();
switch (request.ContentCase)
if (_requestHandlers.TryGetValue(request.ContentCase, out Func<StreamingMessage, StreamingMessage> requestFunc))
{
case StreamingMessage.ContentOneofCase.WorkerInitRequest:
response = ProcessWorkerInitRequest(request);
break;
case StreamingMessage.ContentOneofCase.FunctionLoadRequest:
response = ProcessFunctionLoadRequest(request);
break;
case StreamingMessage.ContentOneofCase.InvocationRequest:
response = ProcessInvocationRequest(request);
break;
default:
string errorMsg = string.Format(PowerShellWorkerStrings.UnsupportedMessage, request.ContentCase);
throw new InvalidOperationException(errorMsg);
response = requestFunc(request);
}
else
{
logger.Log(LogLevel.Error, string.Format(PowerShellWorkerStrings.UnsupportedMessage, request.ContentCase));
continue;
}
if (response != null)
@ -70,6 +96,27 @@ namespace Microsoft.Azure.Functions.PowerShellWorker
return response;
}
internal StreamingMessage ProcessWorkerTerminateRequest(StreamingMessage request)
{
return null;
}
internal StreamingMessage ProcessWorkerStatusRequest(StreamingMessage request)
{
// WorkerStatusResponse type says that it is not used but this will create an empty one anyway to return to the host
StreamingMessage response = NewStreamingMessageTemplate(
request.RequestId,
StreamingMessage.ContentOneofCase.WorkerStatusResponse,
out StatusResult status);
return response;
}
internal StreamingMessage ProcessFileChangeEventRequest(StreamingMessage request)
{
return null;
}
/// <summary>
/// Method to process a FunctionLoadRequest.
/// FunctionLoadRequest should be processed sequentially. There is no point to process FunctionLoadRequest
@ -179,6 +226,21 @@ namespace Microsoft.Azure.Functions.PowerShellWorker
_msgStream.Write(response);
}
internal StreamingMessage ProcessInvocationCancelRequest(StreamingMessage request)
{
return null;
}
internal StreamingMessage ProcessFunctionEnvironmentReloadRequest(StreamingMessage request)
{
StreamingMessage response = NewStreamingMessageTemplate(
request.RequestId,
StreamingMessage.ContentOneofCase.FunctionEnvironmentReloadResponse,
out StatusResult status);
return response;
}
#region Helper_Methods
/// <summary>
@ -195,12 +257,18 @@ namespace Microsoft.Azure.Functions.PowerShellWorker
case StreamingMessage.ContentOneofCase.WorkerInitResponse:
response.WorkerInitResponse = new WorkerInitResponse() { Result = status };
break;
case StreamingMessage.ContentOneofCase.WorkerStatusResponse:
response.WorkerStatusResponse = new WorkerStatusResponse();
break;
case StreamingMessage.ContentOneofCase.FunctionLoadResponse:
response.FunctionLoadResponse = new FunctionLoadResponse() { Result = status };
break;
case StreamingMessage.ContentOneofCase.InvocationResponse:
response.InvocationResponse = new InvocationResponse() { Result = status };
break;
case StreamingMessage.ContentOneofCase.FunctionEnvironmentReloadResponse:
response.FunctionEnvironmentReloadResponse = new FunctionEnvironmentReloadResponse() { Result = status };
break;
default:
throw new InvalidOperationException("Unreachable code.");
}

Просмотреть файл

@ -7,7 +7,7 @@ using namespace System.Runtime.InteropServices
$IsWindowsEnv = [RuntimeInformation]::IsOSPlatform([OSPlatform]::Windows)
$RepoRoot = (Resolve-Path "$PSScriptRoot/..").Path
$MinimalSDKVersion = '2.1.300'
$MinimalSDKVersion = '2.2.0'
$LocalDotnetDirPath = if ($IsWindowsEnv) { "$env:LocalAppData\Microsoft\dotnet" } else { "$env:HOME/.dotnet" }
function Find-Dotnet