Граф коммитов

430 Коммитов

Автор SHA1 Сообщение Дата
Dongbo Wang 8fd5060735
Embed resource strings to the PS worker and move all error strings to the resource file (#135) 2019-01-23 13:23:05 -08:00
SatishRanjan 2cf1ff922c Adding latest AzPSModulesPath to PSModulePath for private preview (#133) 2019-01-23 11:47:38 -08:00
Dongbo Wang 9b8c27fd72
Make the hashtable returned from ConvertFromJson case-insensitive as long as possible (#138)
Cast the Hashtable returned from JsonObject.CovnertFromJson to a case-insensitive Hashtable as long as it's doable.
If the cast fails, because of keys differ only in case, then we use the original case-sensitive Hashtable.
2019-01-22 15:01:00 -08:00
Dongbo Wang a7718a4926
Make the worker able to do additional data transformation as needed (#134)
Major changes are as follows:
- Add `Utils.TransformInBindingValueAsNeeded` and `Utils.TransformOutBindingValueAsNeeded` for additional data transformation before passing input data in as argument and after retrieving output data back.
- Update `AzFunctionInfo` to capture the static types of script parameters. The parameter types can be used as hints for the additional data transformation.
- Update `PowerShellManager` to call `Utils.TransformInBindingValueAsNeeded` before passing argument in; update `RequestProcessor` to call `Utils.TransformOutBindingValueAsNeeded` before sending out the output data.
- Update `PowerShellWorker.psm1` to remove `Convert-OutputBindingValue`. That logic is moved to `Utils.TransformOutBindingValueAsNeeded`. The reason to move the transformation to C# code is:
   - A script transform function will always unroll the collection value passed to the function when returning the value, which will result in losing the actual type of the collection value. For example, if a byte array is passed to `Convert-OutputBindingValue`, after `return $Value`, the caller will get back an object array instead. `Write-Output -NoEnumerate` doesn't work either -- it returns an array of `PSObject` even though `-NoEnumerate` is specified. In order to preserve the original type of a collection value, I have to implement the transformation function either as a PowerShell class method, or in C# directly. I think the latter is more desirable.
   - Keep consistent with `Utils.TransformInBindingValueAsNeeded`
- Remove `FunctionMetadata.cs`. The `FunctionMetadata` type was added to support doing data transformation on output value within the script. Now that we move that operation in C#, this type is no longer needed. It could be useful in future, but I don't intend to keep an unused data structure around. If we need it in future, we can always add it back since there is no much code about it.
2019-01-22 15:00:28 -08:00
Francisco Gamino 729710d259 Adding supportedManagedDependencies.json with a list of supported modules. (#129) 2019-01-17 19:05:42 -08:00
Dongbo Wang 42b1ac6597 Build against dotnet SDK 2.2 (#125)
* Build again dotnet SDK 2.2

* Fix test
2019-01-09 07:18:45 -08:00
Dongbo Wang 5de474c8d1
Add in-process concurrency support to the PS worker (#123)
The major changes are:
- Use `PSThreadOptions.ReuseThread` for the `InitialSessionState` when creating `Runspace`, so that every `PowerShellManager` only creates one thread and then reuse it afterwards. The default behavior is to create a new thread every time `PowerShell.Invoke` is called.
- Update `RequestProcessor` to process `InvocationRequest` in asynchronously via tasks.
- Implement `PowerShellManagerPool` using `BlockingCollection`
   - make upper bound of the pool configurable via an environment variable `PSWorkerInProcConcurrencyUpperBound`
   - make the pool able to expand in a lazy way
   - checkout `PowerShellManager` via `CheckoutIdleWorker` on the main thread. Once getting an idle instance back, the main thread will queue a task to process an invocation request on a thread-pool thread and forget about it -- the main thread then can go ahead to process the next message.
- Update the `RpcLogger` and make every `PowerShellManager` have its own logger instance.
   - also update the way to set the `RequestId` and `InvocationId` for logger. The original way to setup the context only works for single-thread design.
- Update `MessagingStream` to use a `BlockingCollection` to hold all messages that are about to be written out, then use a single thread-pool thread to take out items and write them to the gRPC channel.
   - currently, the way we write out response/log messages is completely task-based/async, using a semaphore for synchronization. However, this approach doesn't guarantee the order of the message.
   - this is because there could be multiple tasks blocked on the semaphore, and releasing the semaphore allows a blocked task to enter the semaphore, but there is no guaranteed order, such as first-in-first-out, for blocked threads to enter the semaphore.
   - so, the unblocked task could be a random one, and thus change the arrival order of the message when writing the message to the gRPC channel.
- Remove the two system logging we have in our worker, because they drastically worsen the processing time per an invocation request when there are a lot in-coming invocation requests.
   - the logging for "TriggerMetadata" parameter is not that useful, and should be removed
   - the execution time logging is good to have, but not necessary, especially when it impact the throughput.
2019-01-07 11:56:22 -08:00
Tyler James Leonhardt 64060403f9
Enter-PSHostProcess workaround (#121)
* bundle Management + Utility modules and misc config updates

* Test-Path fix
2019-01-05 19:51:41 -08:00
Tyler James Leonhardt 04c0af38ba Fix a test by making it more reliable (#122)
Formatting tables is different in pwsh 6.2-preview.3. We can no longer be sure that the last 2 items in a format-table string are new lines.
Now we walk backwards until we hit the last not white-space line.
2019-01-05 13:31:38 -08:00
Dongbo Wang bf4ba5a7c1
Refactor the code base to make it easy to support concurrency within a worker in future (#117)
Refactor the code base to make it easy to support concurrency within a worker in future.
- Add `PowerShellManagerPool` , but it's just the skeleton. Today the pool only has one PowerShellManager instance. We can add the real pool implementation if we decide to support concurrency within a worker process.
- Setup the `PSModule` environment variable as part of `Runspace.Open` by using `InitialSessionState.EnvironmentVariables`. This fixes the mysterious `ModulePathShouldBeSetCorrectly` test failure by making sure the env variable is set to the expected one as part of the `Runspace.Open` of every `PowerShellManager`. It failed before because:
   1. `dotnet test` runs tests in parallel by default
   2. when creating a new `PowerShellManager`, the `PSModulePath` environment variable will be set again within `Runspace.Open` (by `SetModulePath` called from `ModuleIntrisic` constructor). That makes value unexpected.
- Update tests to make them more reliable.
2018-12-17 00:58:29 -08:00
Tyler James Leonhardt 8964b0d62d
add better what's available 2018-12-14 15:18:58 -08:00
Dongbo Wang 5393e1469c
Refactor the code to pre-validate at 'FunctionLoadRequest' and officially support entrypoint (#116)
- Refactor the code to do initialization in a more organized way.
- Pre-validate the script against the function metadata when loading a 'FunctionLoadRequest'.
- Support `EntryPoint` only when `ScriptFile` points to a `.psm1`; support `.psm1` script file only when `EntryPoint` is specified.
- Add unit tests and e2e tests
2018-12-14 13:49:51 -08:00
Tyler James Leonhardt eca0b1e353 Support `profile.ps1` and remove auto-auth to azure (#114) 2018-12-12 21:17:58 -08:00
Dongbo Wang 357c3c0662
Trace pipeline output in a streaming way (#111)
In order to trace the pipeline output in a streaming way, the `DataAdding` event won't work, because even though you can get the pipeline object right after it's inserted into the pipeline, you will have to call `Out-String` to get the formatted output. You cannot call `Out-String` within the same Runspace as it's busying running the user's function script, so you will have to create a separate Runspace just for this purpose. This won't work given the concurrency support PS worker needs to have.

The approach I choose is to have a special cmdlet `Trace-PipelineObject` behaves like `Tee-Object`. For each object from the pipeline, `Trace-PipelineObject` pushes the object through a `SteppablePipeline` that consists of `Out-String -Stream | Write-Information -Tags "__PipelineObject__"`, and then writes the object back to pipeline. By using this `SteppablePipeline`, every pipeline object is properly formatted and the resulted strings are written to the information stream.
2018-12-12 12:08:59 -08:00
Dongbo Wang 4593c4366e
Make 'HttpResponseContext' not needed in PS function script (#113)
To properly convert a value for a specific output binding name implicitly, we need to know the metadata of the binding referred by that name, such as the type of the output binding.
The changes in this PR register the output binding metadata to a concurrent dictionary with the Runspace's InstanceId as the key before start running a function script, and then unregister after the function script finishes running. When a function script that calls `Push-OutputBinding` is running, we can figure out the current Runspace by `Runspace.DefaultRunspace`, and then we can query for the output binding metadata by using the InstanceId.

This approach take into the concurrency support that we will have in future. `Push-OutputBinding` is able to get the metadata about the function script that is running even with multiple Runspaces/PowerShellManagers processing requests at the same time.
2018-12-11 12:34:24 -08:00
Dongbo Wang 6e5335738b
Remove Service Principal support (#112) 2018-12-10 23:52:27 -08:00
Tyler James Leonhardt 982251eb2d
add thread jobs (#109) 2018-12-07 15:39:55 -08:00
Tyler James Leonhardt 73cef3bb95 Remove Az modules from the worker and add MSI support (#108) 2018-12-05 16:34:14 -08:00
Dongbo Wang 5fd9170ff1
Update worker to build against 6.2.0-preview.2 SDK (#106) 2018-11-30 17:55:39 -08:00
Tyler James Leonhardt 2138cba2f1
changes the environment variables used since we can't set these (#98) 2018-11-16 15:55:22 -08:00
Dongbo Wang b8f323b536 Make 'StatusCode' accept status code in the form of integer, string, and enum (#97)
* Make 'StatusCode' accept status code in the form of integer, string, and enum

* Update the property to type 'HttpStatusCode'

* Update the E2E test to cover different forms of status code

* Use status code 202 for success case to make sure status code is set

* Minor fix in test
2018-11-16 15:41:07 -08:00
Tyler James Leonhardt 293f6086a7
Log items added to the pipeline (#95)
* Log items added to the pipeline

* CRLF and LF

* add comment about Write-Output
2018-11-12 15:00:08 -08:00
Tyler James Leonhardt 2109dacf84
remove powershellget from worker (#94) 2018-11-08 08:10:29 -08:00
Tyler James Leonhardt ead3710125
E2e tests (#85)
* first e2e test

* conditionally chmod +x

* actually run the tests :)

* get job differently

* don't fail if we cant get the job

* honor configuration

* handle env:CONFIGURATION not set

* address Pragna's feedback

* add TestFunctionApp change

* elaborate test name

* add additional test cases

* typo

* add trigger metadata tests and Error test

* new lines

* address Steve's feedback

* address Steve's feedback

* nit extra line
2018-10-31 07:53:47 -07:00
Tyler James Leonhardt 489b3dacca
remove $returns support for now (#84) 2018-10-29 13:38:12 -07:00
Dongbo Wang 8a0c316b20
Use 'JsonObject.ConvertFromJson' to serialize JSON binding input (#83)
There are 2 changes:
1. Use `JsonObject.ConvertFromJson` to serialize JSON binding input. We have to use reflection because the reference assemblies are missing in our SDK NuGet packages.
2. Check for `PSObject` in our `ToTypedData` method, so that it handles wrapped objects properly.
2018-10-25 18:04:34 -07:00
Dongbo Wang 954dad550d
Fix the logging to make logs more readable (#80) 2018-10-24 10:35:46 -07:00
Tyler James Leonhardt 7e084284aa Prepend the module folder under the Function App root to PSModulePath (#78) 2018-10-22 21:45:16 -07:00
Dongbo Wang 1b5d5e7a41
Update JSON conversion depth to 3 to get better responsiveness given a complex return object (#79)
When the return/output object is a complex one, the powershell worker will freeze when converting it to JSON due to `-Depth 10` in the call to `ConvertTo-Json`. Talked to @eamonoreilly and decided to change to 3, which should be deep enough for most real scenarios.
2018-10-22 17:55:13 -07:00
Dongbo Wang 45b6099d7e
Update the module tests to not depend on internal data structure (#74) 2018-10-08 15:08:12 -07:00
Dongbo Wang ee8229b0bc
Bug fixes and code refactoring to get it ready for durable function support (#72)
- Use `ConvertTo-Json` for converting the results returned from the function to JSON. So objects that are wrapped in `PSObject` won't be a problem anymore.
- Refactor the code to make it ready for durable function implementation. The implementation of invoking an orchestration function is made a placeholder in this PR, where it throws `NotImplementedException` when an orchestration function is triggered.
See `RequestProcessor.InvokeOrchestrationFunction`.
2018-10-05 15:59:52 -07:00
Tyler James Leonhardt 55a218d3bd
switch to the Az module for Azure (#67)
* switch to the Az module for Azure

* throw on lastexitcode

* remove unneeded line and update example
2018-10-02 09:51:16 -07:00
Tyler James Leonhardt 372324b556
correct the build steps (#66) 2018-09-30 17:02:07 -04:00
Dongbo Wang 854ff1912f
Added subtree from 'azure-functions-language-worker-protobuf' repo. Branch: dev. Commit: 58b3dc0 (#61) 2018-09-20 22:12:12 -07:00
Dongbo Wang 6dd91369ef
Remove `powershell-core` and `dotnet-core` feeds from NuGet.config (#60) 2018-09-19 23:34:05 -07:00
Tyler James Leonhardt 449f69ccb7
Refactor Logger and add PowerShellManager tests (#54)
* initial refactor of logger

* misc

* add PowerShellManagerTests

* newline

* use test data and move RpcLogger to logger folder with ILogger

* add copyright
2018-09-19 21:33:51 +00:00
Dongbo Wang 94aab53e05
Refactor the build script and update appveyor.yml (#58) 2018-09-19 14:12:55 -07:00
Tyler James Leonhardt 8d68c925d9
add other package sources to nuget.config (#59) 2018-09-19 20:37:36 +00:00
Dongbo Wang eb1765c646 Change to the 'Release' configuration in appveyor.yml (#57) 2018-09-18 23:22:47 +00:00
Tyler James Leonhardt 996cee9aa8
set build number in CI (#56) 2018-09-18 23:01:17 +00:00
Tyler James Leonhardt 576d01b5fe
Update sdk to release (#55)
* Update sdk to release

* update test reference too
2018-09-18 21:40:57 +00:00
Tyler James Leonhardt ea67a3e3d1
add dev to CI branches 2018-09-17 14:52:23 -07:00
Pragna Gopa a70d473dfb Update Readme (#53)
Add build status
2018-09-17 21:49:23 +00:00
Tyler James Leonhardt 646dae0a82
add appveyor (#52)
* add appveyor

* add PSDepend and hard code configuration for now

* Scope CurrentUser

* no .

* upload Pester tests

* configuration

* CONFIGURATION

* $(configuration)

* * instead of env var and ErrorActionPref

* more spaces

* explictly say paths and remove bogus failing test
2018-09-17 21:13:01 +00:00
Tyler James Leonhardt 50659a9a34
bundle and handle Azure PowerShell (#47)
* add logic to grab dependencies

* move psdepends logic

* PSDepends is not a required dependency

* move comment

* actually include install deps script

* fix path

* commit handle Azure authentication

* move WriteAsync out of using

* authenticate to azure per-request and address feedback

* moved Auth to Azure in Worker Init for now
2018-09-12 14:58:47 -07:00
Tyler James Leonhardt 7f1779f766
added build scripts and pester tests (#43)
* added build scripts and pester tests

* header and newlines

* bug in PowerShellGet logic

* to null

* address Dongbo's feedback

* remove InvokeBuild

* add Pester as a dependency
2018-09-10 17:42:11 -07:00
Tyler James Leonhardt 0ee58b5e52
Update README to talk about logging (#42)
* Update README.md

* semantics
2018-09-07 16:48:22 -07:00
Tyler James Leonhardt dc73d8130c
separate out logs for user vs system (#41)
* separate out logs for user vs system

* pulled out the prefix to a const
2018-09-07 16:27:52 -07:00
Tyler James Leonhardt 7f81344d47 Move to packaging everything in contentFiles with added nuspec (#36) 2018-09-07 16:09:35 -07:00
Tyler James Leonhardt 3a1b0bfa56 Rename the module to be 'Microsoft.Azure.Functions.PowerShellWorker' (#40) 2018-09-07 16:07:32 -07:00