Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
994 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.25123.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elasticsearch.Powershell", "src\Elasticsearch.Powershell\Elasticsearch.Powershell.csproj", "{366D21C7-F569-4D6E-AC7A-8C27E61B54EF}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elasticsearch.Powershell.Tests", "src\Elasticsearch.Powershell.Tests\Elasticsearch.Powershell.Tests.csproj", "{34B3DFEE-6900-4310-8534-BFABAAA77FB8}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{366D21C7-F569-4D6E-AC7A-8C27E61B54EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{366D21C7-F569-4D6E-AC7A-8C27E61B54EF}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{366D21C7-F569-4D6E-AC7A-8C27E61B54EF}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{366D21C7-F569-4D6E-AC7A-8C27E61B54EF}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{34B3DFEE-6900-4310-8534-BFABAAA77FB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{34B3DFEE-6900-4310-8534-BFABAAA77FB8}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{34B3DFEE-6900-4310-8534-BFABAAA77FB8}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{34B3DFEE-6900-4310-8534-BFABAAA77FB8}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
30 changes: 30 additions & 0 deletions
30
src/Elasticsearch.Powershell.Tests/ElasticIndicesHealthTests.cs
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,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Nest; | ||
using Xunit; | ||
|
||
namespace Elasticsearch.Powershell.Tests | ||
{ | ||
public class ElasticIndicesHealthTests | ||
{ | ||
[Fact] | ||
public void Test() | ||
{ | ||
var cmdlet = new HealtCmdLet.ElasticClusterHealth(); | ||
var enumerator = cmdlet.Invoke().GetEnumerator(); | ||
|
||
Assert.True(enumerator.MoveNext()); | ||
} | ||
|
||
[Fact] | ||
public void Test2() | ||
{ | ||
var cmdlet = new HealtCmdLet.ElasticIndicesHealth(); | ||
var enumerator = cmdlet.Invoke().GetEnumerator(); | ||
|
||
Assert.True(enumerator.MoveNext()); | ||
} | ||
} | ||
} |
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,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Elasticsearch.Powershell.Tests | ||
{ | ||
public class ElasticSearchTests | ||
{ | ||
[Fact] | ||
public void Test() | ||
{ | ||
var cmdlet = new ElastichSearch(); | ||
cmdlet.Fields = new[] { "EventID" }; | ||
var enumerator = cmdlet.Invoke().GetEnumerator(); | ||
|
||
Assert.True(enumerator.MoveNext()); | ||
} | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
src/Elasticsearch.Powershell.Tests/Elasticsearch.Powershell.Tests.csproj
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,104 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="..\..\packages\xunit.runner.visualstudio.2.2.0-beta1-build1144\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\packages\xunit.runner.visualstudio.2.2.0-beta1-build1144\build\net20\xunit.runner.visualstudio.props')" /> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{34B3DFEE-6900-4310-8534-BFABAAA77FB8}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Elasticsearch.Powershell.Tests</RootNamespace> | ||
<AssemblyName>Elasticsearch.Powershell.Tests</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<TargetFrameworkProfile /> | ||
<NuGetPackageImportStamp> | ||
</NuGetPackageImportStamp> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<Prefer32Bit>false</Prefer32Bit> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<Prefer32Bit>false</Prefer32Bit> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Elasticsearch.Net, Version=5.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\Elasticsearch.Net.5.0.0-alpha2\lib\net45\Elasticsearch.Net.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Nest, Version=5.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\NEST.5.0.0-alpha2\lib\net45\Nest.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\Newtonsoft.Json.8.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="xunit.assert, Version=2.2.0.3239, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\xunit.assert.2.2.0-beta1-build3239\lib\dotnet\xunit.assert.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="xunit.core, Version=2.2.0.3239, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\xunit.extensibility.core.2.2.0-beta1-build3239\lib\dotnet\xunit.core.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="xunit.execution.desktop, Version=2.2.0.3239, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\xunit.extensibility.execution.2.2.0-beta1-build3239\lib\net45\xunit.execution.desktop.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="ElasticIndicesHealthTests.cs" /> | ||
<Compile Include="ElasticSearchTests.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Elasticsearch.Powershell\Elasticsearch.Powershell.csproj"> | ||
<Project>{366d21c7-f569-4d6e-ac7a-8c27e61b54ef}</Project> | ||
<Name>Elasticsearch.Powershell</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | ||
<PropertyGroup> | ||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> | ||
</PropertyGroup> | ||
<Error Condition="!Exists('..\..\packages\xunit.runner.visualstudio.2.2.0-beta1-build1144\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.runner.visualstudio.2.2.0-beta1-build1144\build\net20\xunit.runner.visualstudio.props'))" /> | ||
</Target> | ||
<!-- 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> | ||
--> | ||
</Project> |
36 changes: 36 additions & 0 deletions
36
src/Elasticsearch.Powershell.Tests/Properties/AssemblyInfo.cs
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,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
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("Elasticsearch.Powershell.Tests")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("Elasticsearch.Powershell.Tests")] | ||
[assembly: AssemblyCopyright("Copyright © 2016")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// 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("34b3dfee-6900-4310-8534-bfabaaa77fb8")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
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,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Elasticsearch.Net" version="5.0.0-alpha2" targetFramework="net45" /> | ||
<package id="NEST" version="5.0.0-alpha2" targetFramework="net45" /> | ||
<package id="Newtonsoft.Json" version="8.0.1" targetFramework="net45" /> | ||
<package id="xunit" version="2.2.0-beta1-build3239" targetFramework="net45" /> | ||
<package id="xunit.abstractions" version="2.0.0" targetFramework="net45" /> | ||
<package id="xunit.assert" version="2.2.0-beta1-build3239" targetFramework="net45" /> | ||
<package id="xunit.core" version="2.2.0-beta1-build3239" targetFramework="net45" /> | ||
<package id="xunit.extensibility.core" version="2.2.0-beta1-build3239" targetFramework="net45" /> | ||
<package id="xunit.extensibility.execution" version="2.2.0-beta1-build3239" targetFramework="net45" /> | ||
<package id="xunit.runner.visualstudio" version="2.2.0-beta1-build1144" targetFramework="net45" developmentDependency="true" /> | ||
</packages> |
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,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Management.Automation; | ||
using Nest; | ||
|
||
namespace Elasticsearch.Powershell | ||
{ | ||
[Cmdlet(VerbsCommon.Get, "ElasticCluster")] | ||
public class ElasticCluster : ElasticCmdlet | ||
{ | ||
protected override void ProcessRecord() | ||
{ | ||
var health = this.Client.ClusterHealth(); | ||
this.CheckResponse(health); | ||
|
||
WriteObject(new Types.Cluster | ||
{ | ||
ConnectionSettings = this.Client.ConnectionSettings, | ||
ActivePrimaryShards = health.ActivePrimaryShards, | ||
ActiveShards = health.ActiveShards, | ||
Name = health.ClusterName, | ||
InitializingShards = health.InitializingShards, | ||
NumberOfDataNodes = health.NumberOfDataNodes, | ||
NumberOfNodes = health.NumberOfNodes, | ||
NumberOfPendingTasks = health.NumberOfPendingTasks, | ||
RelocatingShards = health.RelocatingShards, | ||
Status = health.Status, | ||
UnassignedShards = health.UnassignedShards | ||
}); | ||
} | ||
} | ||
} |
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 System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Management.Automation; | ||
using Elasticsearch.Net; | ||
using Nest; | ||
|
||
namespace Elasticsearch.Powershell | ||
{ | ||
public class ElasticCmdlet : Cmdlet | ||
{ | ||
private ElasticClient _client; | ||
private IConnectionSettingsValues _connectionSettings; | ||
|
||
public ElasticCmdlet() | ||
{ | ||
this.Nodes = new[] { "http://localhost:9200" }; | ||
} | ||
|
||
[Parameter(Position = 0, Mandatory = false, HelpMessage = "The cluster node(s) urls (ex. http://localhost:9200)")] | ||
public string[] Nodes { get; set; } | ||
|
||
protected IElasticClient Client | ||
{ | ||
get | ||
{ | ||
if (_client != null) | ||
return _client; | ||
|
||
return _client = new ElasticClient(this.ConnectionSettings); | ||
} | ||
} | ||
|
||
protected IConnectionSettingsValues ConnectionSettings | ||
{ | ||
get | ||
{ | ||
if (_connectionSettings != null) | ||
return _connectionSettings; | ||
|
||
var pool = new StaticConnectionPool(this.Nodes.Select(GetNodeUri)); | ||
return _connectionSettings = new ConnectionSettings(pool); | ||
} | ||
set | ||
{ | ||
_connectionSettings = value; | ||
} | ||
} | ||
|
||
protected override void EndProcessing() | ||
{ | ||
_client = null; | ||
} | ||
|
||
protected void CheckResponse(IResponse response) | ||
{ | ||
WriteVerbose(response.DebugInformation); | ||
|
||
if (response.OriginalException != null) | ||
{ | ||
var exception = response.OriginalException; | ||
var first = exception; | ||
|
||
while(exception != null) | ||
{ | ||
first = exception; | ||
WriteVerbose("Error: " + exception.Message); | ||
exception = exception.InnerException; | ||
} | ||
|
||
throw first; | ||
} | ||
} | ||
|
||
private static Uri GetNodeUri(string node) | ||
{ | ||
return new Uri(GetNodeAddress(node)); | ||
} | ||
|
||
private static string GetNodeAddress(string node) | ||
{ | ||
if (node.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase)) | ||
return node; | ||
|
||
if (node.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase)) | ||
return node; | ||
|
||
return "http://" + node; | ||
} | ||
} | ||
} |
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 @@ | ||
using System; | ||
using System.Management.Automation; | ||
|
||
namespace Elasticsearch.Powershell | ||
{ | ||
[Cmdlet(VerbsCommon.Get, "ElasticNode")] | ||
public class ElasticNode : ElasticCmdlet | ||
{ | ||
[Parameter(ValueFromPipeline = true)] | ||
public Types.Cluster InputObject { get; set; } | ||
|
||
protected override void ProcessRecord() | ||
{ | ||
if (this.InputObject != null) | ||
this.ConnectionSettings = this.InputObject.ConnectionSettings; | ||
|
||
var nodes = this.Client.NodesInfo(); | ||
this.CheckResponse(nodes); | ||
|
||
foreach (var node in nodes.Nodes.Values) | ||
WriteObject(node); | ||
} | ||
} | ||
} |
Oops, something went wrong.