Skip to content

Commit 6c6aae2

Browse files
committed
first cut of the project
1 parent f3d8a44 commit 6c6aae2

22 files changed

Lines changed: 843 additions & 0 deletions
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Management.Automation;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Elastacloud.LivyApi.AppList;
8+
9+
namespace Elastacloud.LivyApi.PS
10+
{
11+
[Cmdlet("Execute", "SparkApplication")]
12+
public class ExecuteSparkApplicationCmdLet : Cmdlet
13+
{
14+
private LivyApi _api;
15+
private appList _appList;
16+
17+
[Parameter(Mandatory = true)]
18+
public string ClusterName { get; set; }
19+
20+
[Parameter(Mandatory = true)]
21+
public string Username { get; set; }
22+
23+
[Parameter(Mandatory = true)]
24+
public string Password { get; set; }
25+
26+
public string Args { get; set; }
27+
public string ClassName { get; set; }
28+
public string SparkJar { get; set; }
29+
30+
protected override void BeginProcessing()
31+
{
32+
WriteObject($"Connecting to HDInsight cluster {ClusterName}");
33+
_api = new LivyApi(new LivySettings(Username, Password, ClusterName));
34+
}
35+
36+
protected override void ProcessRecord()
37+
{
38+
var colour = Console.ForegroundColor;
39+
var executeResponse =_api.Execute(new SparkSettings()
40+
{
41+
args = Args,
42+
className = ClassName,
43+
file = SparkJar
44+
}).Result;
45+
var state = executeResponse.JobState;
46+
while (state == SparkJobState.Running || state == SparkJobState.Starting)
47+
{
48+
state = _api.GetJobState(executeResponse.id).Result;
49+
WriteObject($"Processing record with state {state}");
50+
}
51+
}
52+
53+
protected override void EndProcessing()
54+
{
55+
WriteObject($"{_appList.total} apps running on the Spark cluster");
56+
}
57+
}
58+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Management.Automation;
7+
using Elastacloud.LivyApi.AppList;
8+
9+
namespace Elastacloud.LivyApi.PS
10+
{
11+
[Cmdlet(VerbsCommunications.Read, "SparkApplications")]
12+
public class ListSparkApplicationsCmdLet : Cmdlet
13+
{
14+
private LivyApi _api;
15+
private appList _appList;
16+
17+
[Parameter(Mandatory = true)]
18+
public string ClusterName { get; set; }
19+
20+
[Parameter(Mandatory = true)]
21+
public string Username { get; set; }
22+
23+
[Parameter(Mandatory = true)]
24+
public string Password { get; set; }
25+
26+
protected override void BeginProcessing()
27+
{
28+
WriteObject($"Connecting to HDInsight cluster {ClusterName}");
29+
_api = new LivyApi(new LivySettings(Username, Password, ClusterName));
30+
}
31+
32+
protected override void ProcessRecord()
33+
{
34+
var colour = Console.ForegroundColor;
35+
_appList = _api.List().Result;
36+
var sessions = _appList.sessions;
37+
foreach (var session in sessions)
38+
{
39+
if (session.state != "running" && session.state != "started") continue;
40+
Console.ForegroundColor = ConsoleColor.Cyan;
41+
WriteObject($"{session.appId} is in a {session.state} state");
42+
Console.ForegroundColor = colour;
43+
}
44+
}
45+
46+
protected override void EndProcessing()
47+
{
48+
WriteObject($"{_appList.total} apps running on the Spark cluster");
49+
}
50+
}
51+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{D33FF887-0753-4923-8CD6-974130115BB0}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>ProductFactory.LivyApi.PS</RootNamespace>
11+
<AssemblyName>ProductFactory.LivyApi.PS</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="System" />
34+
<Reference Include="System.Core" />
35+
<Reference Include="System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
36+
<HintPath>..\packages\System.Management.Automation.6.1.7601.17515\lib\net45\System.Management.Automation.dll</HintPath>
37+
<Private>True</Private>
38+
</Reference>
39+
<Reference Include="System.Management.Instrumentation" />
40+
<Reference Include="System.Xml.Linq" />
41+
<Reference Include="System.Data.DataSetExtensions" />
42+
<Reference Include="Microsoft.CSharp" />
43+
<Reference Include="System.Data" />
44+
<Reference Include="System.Net.Http" />
45+
<Reference Include="System.Xml" />
46+
</ItemGroup>
47+
<ItemGroup>
48+
<Compile Include="ExecuteSparkApplicationCmdLet.cs" />
49+
<Compile Include="ListSparkApplicationsCmdLet.cs" />
50+
<Compile Include="Properties\AssemblyInfo.cs" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<None Include="packages.config" />
54+
</ItemGroup>
55+
<ItemGroup>
56+
<ProjectReference Include="..\LivyApi\ProductFactory.LivyApi.csproj">
57+
<Project>{9a374db7-355c-42ae-840e-720eb4a52c2f}</Project>
58+
<Name>ProductFactory.LivyApi</Name>
59+
</ProjectReference>
60+
</ItemGroup>
61+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
62+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
63+
Other similar extension points exist, see Microsoft.Common.targets.
64+
<Target Name="BeforeBuild">
65+
</Target>
66+
<Target Name="AfterBuild">
67+
</Target>
68+
-->
69+
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Elastacloud.LivyApi.PS")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Elastacloud.LivyApi.PS")]
13+
[assembly: AssemblyCopyright("Copyright © 2016")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("d33ff887-0753-4923-8cd6-974130115bb0")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

LivyApi.PS/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="System.Management.Automation" version="6.1.7601.17515" targetFramework="net452" />
4+
</packages>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{34985E6D-6765-4561-97B5-6B475EDE8954}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>ProductFactory.LivyApi.Test</RootNamespace>
11+
<AssemblyName>ProductFactory.LivyApi.Test</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
34+
<HintPath>..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll</HintPath>
35+
<Private>True</Private>
36+
</Reference>
37+
<Reference Include="Moq, Version=4.5.21.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
38+
<HintPath>..\packages\Moq.4.5.21\lib\net45\Moq.dll</HintPath>
39+
<Private>True</Private>
40+
</Reference>
41+
<Reference Include="System" />
42+
<Reference Include="System.Core" />
43+
<Reference Include="System.Xml.Linq" />
44+
<Reference Include="System.Data.DataSetExtensions" />
45+
<Reference Include="Microsoft.CSharp" />
46+
<Reference Include="System.Data" />
47+
<Reference Include="System.Net.Http" />
48+
<Reference Include="System.Xml" />
49+
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
50+
<HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
51+
<Private>True</Private>
52+
</Reference>
53+
<Reference Include="xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
54+
<HintPath>..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll</HintPath>
55+
<Private>True</Private>
56+
</Reference>
57+
<Reference Include="xunit.core, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
58+
<HintPath>..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll</HintPath>
59+
<Private>True</Private>
60+
</Reference>
61+
<Reference Include="xunit.execution.desktop, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
62+
<HintPath>..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath>
63+
<Private>True</Private>
64+
</Reference>
65+
</ItemGroup>
66+
<ItemGroup>
67+
<Compile Include="TestApi.cs" />
68+
<Compile Include="Properties\AssemblyInfo.cs" />
69+
</ItemGroup>
70+
<ItemGroup>
71+
<None Include="packages.config" />
72+
</ItemGroup>
73+
<ItemGroup>
74+
<ProjectReference Include="..\LivyApi\ProductFactory.LivyApi.csproj">
75+
<Project>{9a374db7-355c-42ae-840e-720eb4a52c2f}</Project>
76+
<Name>ProductFactory.LivyApi</Name>
77+
</ProjectReference>
78+
</ItemGroup>
79+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
80+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
81+
Other similar extension points exist, see Microsoft.Common.targets.
82+
<Target Name="BeforeBuild">
83+
</Target>
84+
<Target Name="AfterBuild">
85+
</Target>
86+
-->
87+
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Elastacloud.LivyApi.Test")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Elastacloud.LivyApi.Test")]
13+
[assembly: AssemblyCopyright("Copyright © 2016")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("34985e6d-6765-4561-97b5-6b475ede8954")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)