Repository: incubator-reef Updated Branches: refs/heads/master 33812fb01 -> 5cdd655e4
[REEF-472] Move CLRBridgeClient from REEF.Client project into a separate example project This PR *Created a new project for CLRBridgeClient *Rewrite CLRBridgeClient with the new Client API JIRA: REEF-472(https://issues.apache.org/jira/browse/REEF-472) This closes #292 Author: Julia Wang Email: [email protected] Project: http://git-wip-us.apache.org/repos/asf/incubator-reef/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-reef/commit/5cdd655e Tree: http://git-wip-us.apache.org/repos/asf/incubator-reef/tree/5cdd655e Diff: http://git-wip-us.apache.org/repos/asf/incubator-reef/diff/5cdd655e Branch: refs/heads/master Commit: 5cdd655e43b567c544054f37104aedb8a2303863 Parents: 33812fb Author: Julia Wang <[email protected]> Authored: Sat Jul 11 16:03:57 2015 -0700 Committer: Beysim Sezgin <[email protected]> Committed: Wed Jul 15 09:57:03 2015 -0700 ---------------------------------------------------------------------- .../ClrBridgeClient.cs | 107 +++++++++++++++++++ ...g.Apache.REEF.Examples.HelloCLRBridge.csproj | 101 +++++++++++++++++ .../Properties/AssemblyInfo.cs | 54 ++++++++++ .../Handlers/HelloDriverStartHandler.cs | 75 +++++++++++++ .../Org.Apache.REEF.Examples.csproj | 3 +- lang/cs/Org.Apache.REEF.sln | Bin 27944 -> 29022 bytes 6 files changed, 339 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/5cdd655e/lang/cs/Org.Apache.REEF.Examples.HelloCLRBridge/ClrBridgeClient.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Examples.HelloCLRBridge/ClrBridgeClient.cs b/lang/cs/Org.Apache.REEF.Examples.HelloCLRBridge/ClrBridgeClient.cs new file mode 100644 index 0000000..a6cc87d --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Examples.HelloCLRBridge/ClrBridgeClient.cs @@ -0,0 +1,107 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +using System; +using System.IO; +using Org.Apache.REEF.Client.API; +using Org.Apache.REEF.Client.Local; +using Org.Apache.REEF.Client.YARN; +using Org.Apache.REEF.Common.Evaluator; +using Org.Apache.REEF.Driver; +using Org.Apache.REEF.Driver.Defaults; +using Org.Apache.REEF.Examples.HelloCLRBridge.Handlers; +using Org.Apache.REEF.Tang.Annotations; +using Org.Apache.REEF.Tang.Implementations.Tang; +using Org.Apache.REEF.Tang.Interface; +using Org.Apache.REEF.Tang.Util; +using Org.Apache.REEF.Utilities.Logging; + +namespace Org.Apache.REEF.Examples.HelloCLRBridge +{ + public sealed class ClrBridgeClient + { + private const string Local = "local"; + private const string YARN = "yarn"; + private readonly IREEFClient _reefClient; + private readonly JobSubmissionBuilderFactory _jobSubmissionBuilderFactory; + + [Inject] + private ClrBridgeClient(IREEFClient reefClient, JobSubmissionBuilderFactory jobSubmissionBuilderFactory) + { + _reefClient = reefClient; + _jobSubmissionBuilderFactory = jobSubmissionBuilderFactory; + } + + private void Run() + { + var helloDriverConfiguration = DriverConfiguration.ConfigurationModule + .Set(DriverConfiguration.OnEvaluatorAllocated, GenericType<HelloAllocatedEvaluatorHandler>.Class) + .Set(DriverConfiguration.OnEvaluatorAllocated, GenericType<AnotherHelloAllocatedEvaluatorHandler>.Class) + .Set(DriverConfiguration.OnContextActive, GenericType<HelloActiveContextHandler>.Class) + .Set(DriverConfiguration.OnTaskMessage, GenericType<HelloTaskMessageHandler>.Class) + .Set(DriverConfiguration.OnEvaluatorFailed, GenericType<HelloFailedEvaluatorHandler>.Class) + .Set(DriverConfiguration.OnTaskFailed, GenericType<HelloFailedTaskHandler>.Class) + .Set(DriverConfiguration.OnTaskRunning, GenericType<HelloRunningTaskHandler>.Class) + .Set(DriverConfiguration.OnDriverStarted, GenericType<HelloDriverStartHandler>.Class) + .Set(DriverConfiguration.OnHttpEvent, GenericType<HelloHttpHandler>.Class) + .Set(DriverConfiguration.OnEvaluatorCompleted, GenericType<HelloCompletedEvaluatorHandler>.Class) + .Set(DriverConfiguration.CustomTraceListeners, GenericType<DefaultCustomTraceListener>.Class) + .Set(DriverConfiguration.CustomTraceLevel, Level.Info.ToString()) + .Set(DriverConfiguration.OnDriverRestarted, GenericType<HelloRestartHandler>.Class) + .Set(DriverConfiguration.OnDriverReconnect, GenericType<DefaultLocalHttpDriverConnection>.Class) + .Set(DriverConfiguration.OnDirverRestartContextActive, GenericType<HelloDriverRestartActiveContextHandler>.Class) + .Set(DriverConfiguration.OnDriverRestartTaskRunning, GenericType<HelloDriverRestartRunningTaskHandler>.Class) + .Build(); + + var helloJobSubmission = _jobSubmissionBuilderFactory.GetJobSubmissionBuilder() + .AddDriverConfiguration(helloDriverConfiguration) + .AddGlobalAssemblyForType(typeof(HelloDriverStartHandler)) + .SetJobIdentifier("HelloDriverStartHandler") + .Build(); + + _reefClient.Submit(helloJobSubmission); + } + + /// <summary> + /// </summary> + /// <param name="name"></param> + /// <returns></returns> + private static IConfiguration GetRuntimeConfiguration(string name) + { + switch (name) + { + case Local: + var dir = Path.Combine(Directory.GetCurrentDirectory(), "REEF_LOCAL_RUNTIME"); + return LocalRuntimeClientConfiguration.ConfigurationModule + .Set(LocalRuntimeClientConfiguration.NumberOfEvaluators, "2") + .Set(LocalRuntimeClientConfiguration.RuntimeFolder, dir) + .Build(); + case YARN: + return YARNClientConfiguration.ConfigurationModule.Build(); + default: + throw new Exception("Unknown runtime: " + name); + } + } + + public static void Main(string[] args) + { + TangFactory.GetTang().NewInjector(GetRuntimeConfiguration(args.Length > 0 ? args[0] : Local)).GetInstance<ClrBridgeClient>().Run(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/5cdd655e/lang/cs/Org.Apache.REEF.Examples.HelloCLRBridge/Org.Apache.REEF.Examples.HelloCLRBridge.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Examples.HelloCLRBridge/Org.Apache.REEF.Examples.HelloCLRBridge.csproj b/lang/cs/Org.Apache.REEF.Examples.HelloCLRBridge/Org.Apache.REEF.Examples.HelloCLRBridge.csproj new file mode 100644 index 0000000..87e0537 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Examples.HelloCLRBridge/Org.Apache.REEF.Examples.HelloCLRBridge.csproj @@ -0,0 +1,101 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at +http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<Project ToolsVersion="12.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')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{159F7D70-8ACC-4D97-9F6D-2FC4CA0D8682}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Org.Apache.REEF.Examples.HelloCLRBridge</RootNamespace> + <AssemblyName>Org.Apache.REEF.Examples.HelloCLRBridge</AssemblyName> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <RestorePackages>true</RestorePackages> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..</SolutionDir> + </PropertyGroup> + <PropertyGroup> + <StartupObject /> + </PropertyGroup> + <Import Project="$(SolutionDir)\build.props" /> + <PropertyGroup> + <UseVSHostingProcess>false</UseVSHostingProcess> + </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.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="ClrBridgeClient.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.Bridge\Org.Apache.REEF.Bridge.vcxproj"> + <Project>{4e69d40a-26d6-4d4a-b96d-729946c07fe1}</Project> + <Name>Org.Apache.REEF.Bridge</Name> + </ProjectReference> + <ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.Client\Org.Apache.REEF.Client.csproj"> + <Project>{5094c35b-4fdb-4322-ac05-45d684501cbf}</Project> + <Name>Org.Apache.REEF.Client</Name> + </ProjectReference> + <ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.Common\Org.Apache.REEF.Common.csproj"> + <Project>{545a0582-4105-44ce-b99c-b1379514a630}</Project> + <Name>Org.Apache.REEF.Common</Name> + </ProjectReference> + <ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.Driver\Org.Apache.REEF.Driver.csproj"> + <Project>{a6baa2a7-f52f-4329-884e-1bcf711d6805}</Project> + <Name>Org.Apache.REEF.Driver</Name> + </ProjectReference> + <ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.Evaluator\Org.Apache.REEF.Evaluator.csproj"> + <Project>{1b983182-9c30-464c-948d-f87eb93a8240}</Project> + <Name>Org.Apache.REEF.Evaluator</Name> + </ProjectReference> + <ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.Tang\Org.Apache.REEF.Tang.csproj"> + <Project>{97dbb573-3994-417a-9f69-ffa25f00d2a6}</Project> + <Name>Org.Apache.REEF.Tang</Name> + </ProjectReference> + <ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.Utilities\Org.Apache.REEF.Utilities.csproj"> + <Project>{79e7f89a-1dfb-45e1-8d43-d71a954aeb98}</Project> + <Name>Org.Apache.REEF.Utilities</Name> + </ProjectReference> + <ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.Wake\Org.Apache.REEF.Wake.csproj"> + <Project>{cdfb3464-4041-42b1-9271-83af24cd5008}</Project> + <Name>Org.Apache.REEF.Wake</Name> + </ProjectReference> + <ProjectReference Include="..\Org.Apache.REEF.Examples\Org.Apache.REEF.Examples.csproj"> + <Project>{75503f90-7b82-4762-9997-94b5c68f15db}</Project> + <Name>Org.Apache.REEF.Examples</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <!--begin jar reference--> + <PropertyGroup> + <AfterBuildDependsOn> + $(AfterBuildDependsOn); + CopyJarFiles; + </AfterBuildDependsOn> + </PropertyGroup> + <Target Name="AfterBuild" DependsOnTargets="$(AfterBuildDependsOn);" /> + <!--end jar reference--> +</Project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/5cdd655e/lang/cs/Org.Apache.REEF.Examples.HelloCLRBridge/Properties/AssemblyInfo.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Examples.HelloCLRBridge/Properties/AssemblyInfo.cs b/lang/cs/Org.Apache.REEF.Examples.HelloCLRBridge/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..60540a2 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Examples.HelloCLRBridge/Properties/AssemblyInfo.cs @@ -0,0 +1,54 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +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("Org.Apache.REEF.Examples.HelloCLRBridge")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Org.Apache.REEF.Examples.HelloCLRBridge")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[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("2c286656-9b3f-42f9-a29f-3307ebfc8022")] + +// 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")] http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/5cdd655e/lang/cs/Org.Apache.REEF.Examples/HelloCLRBridge/Handlers/HelloDriverStartHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Examples/HelloCLRBridge/Handlers/HelloDriverStartHandler.cs b/lang/cs/Org.Apache.REEF.Examples/HelloCLRBridge/Handlers/HelloDriverStartHandler.cs new file mode 100644 index 0000000..f1eef50 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Examples/HelloCLRBridge/Handlers/HelloDriverStartHandler.cs @@ -0,0 +1,75 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +using System; + +using Org.Apache.REEF.Driver; +using Org.Apache.REEF.Driver.Evaluator; +using Org.Apache.REEF.Tang.Annotations; +using Org.Apache.REEF.Utilities.Logging; + +namespace Org.Apache.REEF.Examples.HelloCLRBridge.Handlers +{ + public sealed class HelloDriverStartHandler : IObserver<IDriverStarted> + { + private static readonly Logger _Logger = Logger.GetLogger(typeof(HelloDriverStartHandler)); + private readonly IEvaluatorRequestor _evaluatorRequestor; + + [Inject] + private HelloDriverStartHandler(IEvaluatorRequestor evaluatorRequestor) + { + _evaluatorRequestor = evaluatorRequestor; + } + + public void OnError(Exception error) + { + throw error; + } + + public void OnCompleted() + { + } + + /// <summary> + /// Called to start the user mode driver + /// </summary> + /// <param name="driverStarted"></param> + public void OnNext(IDriverStarted driverStarted) + { + _Logger.Log(Level.Info, string.Format("HelloDriver started at {0}", driverStarted.StartTime)); + + int evaluatorsNumber = 1; + int memory = 512; + int core = 2; + string rack = "WonderlandRack"; + string evaluatorBatchId = "evaluatorThatRequires512MBofMemory"; + EvaluatorRequest request = new EvaluatorRequest(evaluatorsNumber, memory, core, rack, evaluatorBatchId); + + _evaluatorRequestor.Submit(request); + + evaluatorsNumber = 1; + memory = 1999; + core = 2; + rack = "WonderlandRack"; + evaluatorBatchId = "evaluatorThatRequires1999MBofMemory"; + request = new EvaluatorRequest(evaluatorsNumber, memory, core, rack, evaluatorBatchId); + _evaluatorRequestor.Submit(request); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/5cdd655e/lang/cs/Org.Apache.REEF.Examples/Org.Apache.REEF.Examples.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Examples/Org.Apache.REEF.Examples.csproj b/lang/cs/Org.Apache.REEF.Examples/Org.Apache.REEF.Examples.csproj index 1e342ed..1557198 100644 --- a/lang/cs/Org.Apache.REEF.Examples/Org.Apache.REEF.Examples.csproj +++ b/lang/cs/Org.Apache.REEF.Examples/Org.Apache.REEF.Examples.csproj @@ -41,6 +41,7 @@ under the License. <Compile Include="HelloCLRBridge\Handlers\HelloCompletedEvaluatorHandler.cs" /> <Compile Include="HelloCLRBridge\Handlers\HelloDriverRestartActiveContextHandler.cs" /> <Compile Include="HelloCLRBridge\Handlers\HelloDriverRestartRunningTaskHandler.cs" /> + <Compile Include="HelloCLRBridge\Handlers\HelloDriverStartHandler.cs" /> <Compile Include="HelloCLRBridge\Handlers\HelloEvaluatorRequestorHandler.cs" /> <Compile Include="HelloCLRBridge\Handlers\HelloFailedEvaluatorHandler.cs" /> <Compile Include="HelloCLRBridge\Handlers\HelloFailedTaskHandler.cs" /> @@ -113,4 +114,4 @@ under the License. <Target Name="AfterBuild"> </Target> --> -</Project> +</Project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/5cdd655e/lang/cs/Org.Apache.REEF.sln ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.sln b/lang/cs/Org.Apache.REEF.sln index 2626a8e..63afdb0 100644 Binary files a/lang/cs/Org.Apache.REEF.sln and b/lang/cs/Org.Apache.REEF.sln differ
