You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@reef.apache.org by we...@apache.org on 2015/07/22 06:53:46 UTC
[3/3] incubator-reef git commit: [REEF-486] Refactor
Org.Apache.REEF.Examples.AllHandlers
[REEF-486] Refactor Org.Apache.REEF.Examples.AllHandlers
This PR is to move handlers in
`Org.Apache.REEF.Examples.HelloCLRBridge.Handlers`
to corresponding example and test folders and rename, update the
coresponding test code to use ClientAPI.
* Renamed Org.Apache.REEF.Examples.HelloCLRBridge project to
Org.Apache.REEF.Examples.AllHandlers
* Renamed the class
Org.Apache.REEF.Examples.HelloCLRBridge.ClrBridgeClient.cs to
Org.Apache.REEF.Examples.AllHandlers.AllHandler.cs
* And moved handlers in
Org.Apache.REEF.Examples.HelloCLRBridge.Handlers to
Org.Apache.REEF.Examples.HelloCLRBridge project so that they all stay
in the same project as a complete example.
* Removed TestHelloBridgeHandlers.cs as the test has been covered by
TestBridgeClient.cs
* Moved Org.Apache.REEF.Examples/HelloCLRBridge/Handlers/HelloSimpleEventHandlers.cs
to test folder and updated it
* Updated test case Org.Apache.REEF.Tests/Functional/Bridge/TestSimpleEventHandlers.cs
to use ClientAPI
* Removed the code in Org.Apache.REEF.Client/CLRBridgeClient.cs,
preparing for REEF-473
JIRA:
[REEF-486](https://issues.apache.org/jira/browse/REEF-486)
Pull Request:
This closes #306
Project: http://git-wip-us.apache.org/repos/asf/incubator-reef/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-reef/commit/7824be83
Tree: http://git-wip-us.apache.org/repos/asf/incubator-reef/tree/7824be83
Diff: http://git-wip-us.apache.org/repos/asf/incubator-reef/diff/7824be83
Branch: refs/heads/master
Commit: 7824be835cdacf21512df355d6d79a8dc5a6d11b
Parents: d077974
Author: Julia Wang <jw...@yahoo.com>
Authored: Mon Jul 20 19:35:10 2015 -0700
Committer: Markus Weimer <we...@apache.org>
Committed: Tue Jul 21 21:50:12 2015 -0700
----------------------------------------------------------------------
.../Org.Apache.REEF.Client/CLRBridgeClient.cs | 119 +-----
.../AllHandlers.cs | 132 ++++++
.../AnotherHelloAllocatedEvaluatorHandler.cs | 52 +++
.../HelloActiveContextHandler.cs | 90 ++++
.../HelloAllocatedEvaluatorHandler.cs | 139 ++++++
.../HelloCompletedEvaluatorHandler.cs | 60 +++
.../HelloDriverRestartActiveContextHandler.cs | 76 ++++
.../HelloDriverRestartRunningTaskHandler.cs | 71 ++++
.../HelloDriverStartHandler.cs | 79 ++++
.../HelloFailedEvaluatorHandler.cs | 74 ++++
.../HelloFailedTaskHandler.cs | 74 ++++
.../HelloHttpHandler.cs | 59 +++
.../HelloRestartHandler.cs | 55 +++
.../HelloRunningTaskHandler.cs | 69 +++
.../HelloTaskMessageHandler.cs | 61 +++
.../HelloTraceListener.cs | 48 +++
.../Org.Apache.REEF.Examples.AllHandlers.csproj | 122 ++++++
.../Properties/AssemblyInfo.cs | 54 +++
.../Readme.md | 17 +
.../ClrBridgeClient.cs | 122 ------
...g.Apache.REEF.Examples.HelloCLRBridge.csproj | 105 -----
.../Properties/AssemblyInfo.cs | 54 ---
.../AnotherHelloAllocatedEvaluatorHandler.cs | 48 ---
.../Handlers/HelloActiveContextHandler.cs | 82 ----
.../Handlers/HelloAllocatedEvaluatorHandler.cs | 132 ------
.../Handlers/HelloCompletedEvaluatorHandler.cs | 56 ---
.../HelloDriverRestartActiveContextHandler.cs | 69 ---
.../HelloDriverRestartRunningTaskHandler.cs | 67 ---
.../Handlers/HelloDriverStartHandler.cs | 75 ----
.../Handlers/HelloEvaluatorRequestorHandler.cs | 63 ---
.../Handlers/HelloFailedEvaluatorHandler.cs | 67 ---
.../Handlers/HelloFailedTaskHandler.cs | 67 ---
.../HelloCLRBridge/Handlers/HelloHttpHandler.cs | 51 ---
.../Handlers/HelloRestartHandler.cs | 48 ---
.../Handlers/HelloRunningTaskHandler.cs | 65 ---
.../Handlers/HelloSimpleEventHandlers.cs | 421 -------------------
.../Handlers/HelloStartHandler.cs | 64 ---
.../Handlers/HelloTaskMessageHandler.cs | 54 ---
.../HelloCLRBridge/HelloTraceListener.cs | 48 ---
.../Org.Apache.REEF.Examples.csproj | 20 +-
.../Bridge/HelloSimpleEventHandlers.cs | 421 +++++++++++++++++++
.../Functional/Bridge/TestBridgeClient.cs | 4 +-
.../Bridge/TestHelloBridgeHandlers.cs | 100 -----
.../Bridge/TestSimpleEventHandlers.cs | 80 ++--
.../Functional/ReefFunctionalTest.cs | 39 ++
.../Org.Apache.REEF.Tests.csproj | 6 +-
lang/cs/Org.Apache.REEF.sln | Bin 29022 -> 29004 bytes
47 files changed, 1834 insertions(+), 2045 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/7824be83/lang/cs/Org.Apache.REEF.Client/CLRBridgeClient.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Client/CLRBridgeClient.cs b/lang/cs/Org.Apache.REEF.Client/CLRBridgeClient.cs
index f6d8f82..0c2cc80 100644
--- a/lang/cs/Org.Apache.REEF.Client/CLRBridgeClient.cs
+++ b/lang/cs/Org.Apache.REEF.Client/CLRBridgeClient.cs
@@ -18,129 +18,14 @@
*/
using System;
-using System.Collections.Generic;
-using System.IO;
-using Org.Apache.REEF.Common.Evaluator;
-using Org.Apache.REEF.Driver;
-using Org.Apache.REEF.Driver.Bridge;
-using Org.Apache.REEF.Driver.Defaults;
-using Org.Apache.REEF.Examples.HelloCLRBridge.Handlers;
-using Org.Apache.REEF.Examples.Tasks.HelloTask;
-using Org.Apache.REEF.Network.Naming;
-using Org.Apache.REEF.Tang.Interface;
-using Org.Apache.REEF.Tang.Util;
-using Org.Apache.REEF.Utilities.Logging;
namespace Org.Apache.REEF.Client
{
public class CLRBridgeClient
- {
- public const string ReefHome = "REEF_HOME";
- public const string DefaultClrFolder = ".";
- public const string DefaultReefJar = Constants.JavaBridgeJarFileName;
- public const string DefaultRunCommand = "run.cmd";
-
- private static string _clrFolder = null;
- private static string _reefJar = null;
- private static string _className = Constants.BridgeLaunchClass;
- private static string _runCommand = DefaultRunCommand;
- private static readonly string _submitControlForAllocatedEvaluator = "submitContextAndTask"; // submitContext, submitContextAndTask, submitContextAndServiceAndTask
-
- public static HashSet<string> AppDll
- {
- get
- {
- HashSet<string> appDlls = new HashSet<string>();
- appDlls.Add(typeof(HelloStartHandler).Assembly.GetName().Name);
- appDlls.Add(typeof(HelloTask).Assembly.GetName().Name);
- appDlls.Add(typeof(INameServer).Assembly.GetName().Name);
- return appDlls;
- }
- }
-
- public static IConfiguration ClrConfigurations
- {
- get
- {
- return DriverBridgeConfiguration.ConfigurationModule
- .Set(DriverBridgeConfiguration.OnDriverStarted, GenericType<HelloStartHandler>.Class)
- .Set(DriverBridgeConfiguration.OnEvaluatorAllocated, GenericType<HelloAllocatedEvaluatorHandler>.Class)
- .Set(DriverBridgeConfiguration.OnEvaluatorAllocated, GenericType<AnotherHelloAllocatedEvaluatorHandler>.Class)
- .Set(DriverBridgeConfiguration.OnContextActive, GenericType<HelloActiveContextHandler>.Class)
- .Set(DriverBridgeConfiguration.OnTaskMessage, GenericType<HelloTaskMessageHandler>.Class)
- .Set(DriverBridgeConfiguration.OnEvaluatorFailed, GenericType<HelloFailedEvaluatorHandler>.Class)
- .Set(DriverBridgeConfiguration.OnTaskFailed, GenericType<HelloFailedTaskHandler>.Class)
- .Set(DriverBridgeConfiguration.OnTaskRunning, GenericType<HelloRunningTaskHandler>.Class)
- .Set(DriverBridgeConfiguration.OnEvaluatorRequested, GenericType<HelloEvaluatorRequestorHandler>.Class)
- .Set(DriverBridgeConfiguration.OnHttpEvent, GenericType<HelloHttpHandler>.Class)
- .Set(DriverBridgeConfiguration.OnEvaluatorCompleted, GenericType<HelloCompletedEvaluatorHandler>.Class)
- .Set(DriverBridgeConfiguration.CustomTraceListeners, GenericType<DefaultCustomTraceListener>.Class)
- .Set(DriverBridgeConfiguration.CustomTraceLevel, Level.Info.ToString())
- .Set(DriverBridgeConfiguration.CommandLineArguments, _submitControlForAllocatedEvaluator) // this is for testing purpose only
- .Set(DriverBridgeConfiguration.OnDriverRestarted, GenericType<HelloRestartHandler>.Class)
- .Set(DriverBridgeConfiguration.OnDriverReconnect, GenericType<DefaultLocalHttpDriverConnection>.Class)
- .Set(DriverBridgeConfiguration.OnDirverRestartContextActive, GenericType<HelloDriverRestartActiveContextHandler>.Class)
- .Set(DriverBridgeConfiguration.OnDriverRestartTaskRunning, GenericType<HelloDriverRestartRunningTaskHandler>.Class)
- .Build();
- }
- }
-
+ {
public static void Main(string[] args)
{
- Console.WriteLine("start running client: " + DateTime.Now);
- bool runOnYarn = false;
- if (args != null)
- {
- if (args.Length > 0)
- {
- runOnYarn = bool.Parse(args[0]);
- }
-
- if (args.Length > 1)
- {
- _className = args[1];
- }
- if (args.Length > 2)
- {
- _clrFolder = args[2];
- }
- if (args.Length > 3)
- {
- _reefJar = args[3];
- }
- if (args.Length > 4)
- {
- _runCommand = args[4];
- }
- }
-
- if (string.IsNullOrWhiteSpace(_reefJar))
- {
- _reefJar = DefaultReefJar;
- }
-
- if (string.IsNullOrWhiteSpace(_clrFolder))
- {
- _clrFolder = DefaultClrFolder;
- }
-
- // Configurable driver submission settings:
- // DriverMemory, default to 512
- // DriverIdentifer, default to "ReefClrBridge"
- // Submit, default to True. Setting it to false and Java client will construct the driver.config and write to to FS without submitting the job
- // ClientWaitTime, default to -1 which means client will wait till Driver is done
- // SubmissionDirectory, default to a tmp folder on (H)DFS according to the YARN assigned application id, if user sets it, it must be guaranteed to be unique across multiple jobs
- // RunOnYarn, default to false to run on local runtime.
- // UpdateJarBeforeSubmission, default to true. Setting it to false can reduce startup time, but only if the jar file already contains all application dlls.
- // JavaLogLevel, default to INFO.
- DriverSubmissionSettings driverSubmissionSettings = new DriverSubmissionSettings()
- {
- RunOnYarn = runOnYarn,
- SubmissionDirectory = "reefClrBridgeTmp/job_" + Guid.NewGuid().ToString("N").Substring(0, 8)
- };
-
- Console.WriteLine("start calling Run: " + DateTime.Now);
- ClrClientHelper.Run(AppDll, ClrConfigurations, driverSubmissionSettings, _reefJar, _runCommand, _clrFolder, _className);
+ Console.WriteLine("This is a skeleton for the console application. It will be removed after the project is converted to assembly.");
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/7824be83/lang/cs/Org.Apache.REEF.Examples.AllHandlers/AllHandlers.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/AllHandlers.cs b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/AllHandlers.cs
new file mode 100644
index 0000000..dd99e98
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/AllHandlers.cs
@@ -0,0 +1,132 @@
+/**
+ * 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.Bridge;
+using Org.Apache.REEF.Driver.Defaults;
+using Org.Apache.REEF.Examples.Tasks.HelloTask;
+using Org.Apache.REEF.Network.Naming;
+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.AllHandlers
+{
+ public sealed class AllHandlers
+ {
+ private const string Local = "local";
+ private const string YARN = "yarn";
+ private readonly IREEFClient _reefClient;
+ private readonly JobSubmissionBuilderFactory _jobSubmissionBuilderFactory;
+
+ [Inject]
+ private AllHandlers(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 driverCondig = TangFactory.GetTang().NewConfigurationBuilder(helloDriverConfiguration)
+ .BindSetEntry<DriverBridgeConfigurationOptions.SetOfAssemblies, string>(typeof(HelloTask).Assembly.GetName().Name)
+ .BindSetEntry<DriverBridgeConfigurationOptions.SetOfAssemblies, string>(typeof(NameClient).Assembly.GetName().Name)
+ .Build();
+
+ var helloJobSubmission = _jobSubmissionBuilderFactory.GetJobSubmissionBuilder()
+ .AddDriverConfiguration(driverCondig)
+ .AddGlobalAssemblyForType(typeof(HelloDriverStartHandler))
+ .SetJobIdentifier("HelloDriver")
+ .Build();
+
+ _reefClient.Submit(helloJobSubmission);
+ }
+
+ /// <summary></summary>
+ /// <param name="runOnYarn"></param>
+ /// <param name="runtimeFolder"></param>
+ /// <returns></returns>
+ private static IConfiguration GetRuntimeConfiguration(string runOnYarn, string runtimeFolder)
+ {
+ switch (runOnYarn)
+ {
+ case Local:
+ var dir = Path.Combine(".", runtimeFolder);
+ return LocalRuntimeClientConfiguration.ConfigurationModule
+ .Set(LocalRuntimeClientConfiguration.NumberOfEvaluators, "2")
+ .Set(LocalRuntimeClientConfiguration.RuntimeFolder, dir)
+ .Build();
+ case YARN:
+ return YARNClientConfiguration.ConfigurationModule.Build();
+ default:
+ throw new Exception("Unknown runtime: " + runOnYarn);
+ }
+ }
+
+ /// <summary>
+ /// console application for driver with most of sample handlers
+ /// </summary>
+ /// <param name="args"></param>
+ public static void Main(string[] args)
+ {
+ Run(args);
+ }
+
+ /// <summary>
+ /// </summary>
+ /// <param name="args"></param>
+ /// <remarks>
+ /// args[0] specify either running local or YARN. Default is local
+ /// args[1] specify running folder. Default is REEF_LOCAL_RUNTIME
+ /// </remarks>
+ public static void Run(string[] args)
+ {
+ string runOnYarn = args.Length > 0 ? args[0] : Local;
+ string runtimeFolder = args.Length > 1 ? args[1] : "REEF_LOCAL_RUNTIME";
+ TangFactory.GetTang().NewInjector(GetRuntimeConfiguration(runOnYarn, runtimeFolder)).GetInstance<AllHandlers>().Run();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/7824be83/lang/cs/Org.Apache.REEF.Examples.AllHandlers/AnotherHelloAllocatedEvaluatorHandler.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/AnotherHelloAllocatedEvaluatorHandler.cs b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/AnotherHelloAllocatedEvaluatorHandler.cs
new file mode 100644
index 0000000..2fab61d
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/AnotherHelloAllocatedEvaluatorHandler.cs
@@ -0,0 +1,52 @@
+/**
+ * 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.Evaluator;
+using Org.Apache.REEF.Tang.Annotations;
+
+namespace Org.Apache.REEF.Examples.AllHandlers
+{
+ /// <summary>
+ /// A sample implementation of Another AllocatedEvaluator Handler
+ /// User can register multiple handlers
+ /// </summary>
+ public class AnotherHelloAllocatedEvaluatorHandler : IObserver<IAllocatedEvaluator>
+ {
+ [Inject]
+ private AnotherHelloAllocatedEvaluatorHandler()
+ {
+ }
+
+ public void OnNext(IAllocatedEvaluator allocatedEvaluator)
+ {
+ Console.WriteLine("I am just here for the ride.");
+ }
+
+ public void OnCompleted()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void OnError(Exception error)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/7824be83/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloActiveContextHandler.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloActiveContextHandler.cs b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloActiveContextHandler.cs
new file mode 100644
index 0000000..7bfa55a
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloActiveContextHandler.cs
@@ -0,0 +1,90 @@
+/**
+ * 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.Globalization;
+using Org.Apache.REEF.Common.Tasks;
+using Org.Apache.REEF.Driver.Context;
+using Org.Apache.REEF.Driver.Evaluator;
+using Org.Apache.REEF.Examples.Tasks.HelloTask;
+using Org.Apache.REEF.Tang.Annotations;
+using Org.Apache.REEF.Tang.Interface;
+using Org.Apache.REEF.Tang.Util;
+
+namespace Org.Apache.REEF.Examples.AllHandlers
+{
+ /// <summary>
+ /// A sample implementation of ActiveContext handler
+ /// </summary>
+ public class HelloActiveContextHandler : IObserver<IActiveContext>
+ {
+ [Inject]
+ private HelloActiveContextHandler()
+ {
+ }
+
+ /// <summary>
+ /// This method prepare a Task Configuration and submit the task to the active context
+ ///
+ /// </summary>
+ /// <param name="activeContext"></param>
+ public void OnNext(IActiveContext activeContext)
+ {
+ Console.WriteLine(
+ string.Format(
+ CultureInfo.InvariantCulture,
+ "Active context {0} received from evaluator {1}",
+ activeContext.Id,
+ activeContext.EvaluatorId));
+
+ IEvaluatorDescriptor evaluatorDescriptor = activeContext.EvaluatorDescriptor;
+ string ipAddress = evaluatorDescriptor.NodeDescriptor.InetSocketAddress.Address.ToString();
+ int port = evaluatorDescriptor.NodeDescriptor.InetSocketAddress.Port;
+ string hostName = evaluatorDescriptor.NodeDescriptor.HostName;
+
+ Console.WriteLine(
+ string.Format(
+ CultureInfo.InvariantCulture,
+ "The running evaluator is assigned with {0} MB of memory and is running at ip: {1} and port {2}, with hostname {3}",
+ evaluatorDescriptor.Memory,
+ ipAddress,
+ port,
+ hostName));
+
+ IConfiguration taskConfiguration = TaskConfiguration.ConfigurationModule
+ .Set(TaskConfiguration.Identifier, "bridgeCLRHelloTask_" + DateTime.Now.Ticks)
+ .Set(TaskConfiguration.Task, GenericType<HelloTask>.Class)
+ .Set(TaskConfiguration.OnMessage, GenericType<HelloTask.HelloDriverMessageHandler>.Class)
+ .Set(TaskConfiguration.OnSendMessage, GenericType<HelloTaskMessage>.Class)
+ .Build();
+
+ activeContext.SubmitTask(taskConfiguration);
+ }
+
+ public void OnError(Exception error)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void OnCompleted()
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/7824be83/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloAllocatedEvaluatorHandler.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloAllocatedEvaluatorHandler.cs b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloAllocatedEvaluatorHandler.cs
new file mode 100644
index 0000000..b65a4b3
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloAllocatedEvaluatorHandler.cs
@@ -0,0 +1,139 @@
+/**
+ * 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.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Net;
+using Org.Apache.REEF.Common.Io;
+using Org.Apache.REEF.Common.Services;
+using Org.Apache.REEF.Common.Tasks;
+using Org.Apache.REEF.Driver.Bridge;
+using Org.Apache.REEF.Driver.Context;
+using Org.Apache.REEF.Driver.Evaluator;
+using Org.Apache.REEF.Examples.Tasks.HelloTask;
+using Org.Apache.REEF.Network.Naming;
+using Org.Apache.REEF.Tang.Annotations;
+using Org.Apache.REEF.Tang.Implementations.Configuration;
+using Org.Apache.REEF.Tang.Implementations.Tang;
+using Org.Apache.REEF.Tang.Interface;
+using Org.Apache.REEF.Tang.Util;
+using Org.Apache.REEF.Utilities;
+
+namespace Org.Apache.REEF.Examples.AllHandlers
+{
+ /// <summary>
+ /// A sample implementation of allocatedEvaluator handler
+ /// </summary>
+ public class HelloAllocatedEvaluatorHandler : IObserver<IAllocatedEvaluator>
+ {
+ [Inject]
+ private HelloAllocatedEvaluatorHandler()
+ {
+ }
+
+ /// <summary>
+ /// This method create Service/context/task configuration and submit them to the allocatedEvaluator
+ /// </summary>
+ /// <param name="allocatedEvaluator"></param>
+ public void OnNext(IAllocatedEvaluator allocatedEvaluator)
+ {
+ string control = string.Empty;
+
+ ISet<string> arguments = ClrHandlerHelper.GetCommandLineArguments();
+
+ if (arguments != null && arguments.Any())
+ {
+ foreach (string argument in arguments)
+ {
+ Console.WriteLine("testing argument: " + argument);
+ }
+
+ control = arguments.Last();
+ }
+
+ IEvaluatorDescriptor descriptor = allocatedEvaluator.GetEvaluatorDescriptor();
+
+ IConfiguration serviceConfiguration = ServiceConfiguration.ConfigurationModule
+ .Set(ServiceConfiguration.Services, GenericType<HelloService>.Class)
+ .Build();
+
+ IConfiguration contextConfiguration = ContextConfiguration.ConfigurationModule
+ .Set(ContextConfiguration.Identifier, "bridgeHelloCLRContextId_" + Guid.NewGuid().ToString("N"))
+ .Build();
+
+ IConfiguration taskConfiguration = TaskConfiguration.ConfigurationModule
+ .Set(TaskConfiguration.Identifier, "bridgeHelloCLRTaskId_" + Guid.NewGuid().ToString("N"))
+ .Set(TaskConfiguration.Task, GenericType<HelloTask>.Class)
+ .Set(TaskConfiguration.OnMessage, GenericType<HelloTask.HelloDriverMessageHandler>.Class)
+ .Set(TaskConfiguration.OnSendMessage, GenericType<HelloTaskMessage>.Class)
+ .Build();
+
+ IConfiguration mergedTaskConfiguration = taskConfiguration;
+
+ if (allocatedEvaluator.NameServerInfo != null)
+ {
+ IPEndPoint nameServerEndpoint = NetUtilities.ParseIpEndpoint(allocatedEvaluator.NameServerInfo);
+
+ IConfiguration nameClientConfiguration = TangFactory.GetTang().NewConfigurationBuilder(
+ NamingConfiguration.ConfigurationModule
+ .Set(NamingConfiguration.NameServerAddress, nameServerEndpoint.Address.ToString())
+ .Set(NamingConfiguration.NameServerPort,
+ nameServerEndpoint.Port.ToString(CultureInfo.InvariantCulture))
+ .Build())
+ .BindImplementation(GenericType<INameClient>.Class,
+ GenericType<NameClient>.Class)
+ .Build();
+
+ mergedTaskConfiguration = Configurations.Merge(taskConfiguration, nameClientConfiguration);
+ }
+
+ string ipAddress = descriptor.NodeDescriptor.InetSocketAddress.Address.ToString();
+ int port = descriptor.NodeDescriptor.InetSocketAddress.Port;
+ string hostName = descriptor.NodeDescriptor.HostName;
+ Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Alloated evaluator {0} with ip {1}:{2}. Hostname is {3}", allocatedEvaluator.Id, ipAddress, port, hostName));
+ Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Evaluator is assigned with {0} MB of memory and {1} cores.", descriptor.Memory, descriptor.VirtualCore));
+
+ if (control.Equals("submitContext", StringComparison.OrdinalIgnoreCase))
+ {
+ allocatedEvaluator.SubmitContext(contextConfiguration);
+ }
+ else if (control.Equals("submitContextAndServiceAndTask", StringComparison.OrdinalIgnoreCase))
+ {
+ allocatedEvaluator.SubmitContextAndServiceAndTask(contextConfiguration, serviceConfiguration, mergedTaskConfiguration);
+ }
+ else
+ {
+ // default behavior
+ allocatedEvaluator.SubmitContextAndTask(contextConfiguration, mergedTaskConfiguration);
+ }
+ }
+
+ public void OnCompleted()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void OnError(Exception error)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/7824be83/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloCompletedEvaluatorHandler.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloCompletedEvaluatorHandler.cs b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloCompletedEvaluatorHandler.cs
new file mode 100644
index 0000000..3b9e2fc
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloCompletedEvaluatorHandler.cs
@@ -0,0 +1,60 @@
+/**
+ * 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.Globalization;
+using Org.Apache.REEF.Driver.Evaluator;
+using Org.Apache.REEF.Tang.Annotations;
+
+namespace Org.Apache.REEF.Examples.AllHandlers
+{
+ /// <summary>
+ /// Sample implementation of RunningTaskHandler
+ /// </summary>
+ public class HelloCompletedEvaluatorHandler : IObserver<ICompletedEvaluator>
+ {
+ [Inject]
+ private HelloCompletedEvaluatorHandler()
+ {
+ }
+
+ /// <summary>
+ /// It is called when evaluator is completed.
+ /// </summary>
+ /// <param name="completedEvaluator"></param>
+ public void OnNext(ICompletedEvaluator completedEvaluator)
+ {
+ string messageStr = string.Format(
+ CultureInfo.InvariantCulture,
+ "HelloCompletedEvaluatorHandler: Evaluator [{0}] is done.",
+ completedEvaluator.Id);
+ Console.WriteLine(messageStr);
+ }
+
+ public void OnError(Exception error)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void OnCompleted()
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/7824be83/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloDriverRestartActiveContextHandler.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloDriverRestartActiveContextHandler.cs b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloDriverRestartActiveContextHandler.cs
new file mode 100644
index 0000000..69385c7
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloDriverRestartActiveContextHandler.cs
@@ -0,0 +1,76 @@
+/**
+ * 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.Globalization;
+using Org.Apache.REEF.Driver.Context;
+using Org.Apache.REEF.Driver.Evaluator;
+using Org.Apache.REEF.Tang.Annotations;
+
+namespace Org.Apache.REEF.Examples.AllHandlers
+{
+ /// <summary>
+ /// A sample implementation of DriverRestartActiveContextHandler
+ /// </summary>
+ public class HelloDriverRestartActiveContextHandler : IObserver<IActiveContext>
+ {
+ [Inject]
+ private HelloDriverRestartActiveContextHandler()
+ {
+ }
+
+ /// <summary>
+ /// It is called when receiving an active context
+ /// </summary>
+ /// <param name="activeContext"></param>
+ public void OnNext(IActiveContext activeContext)
+ {
+ Console.WriteLine(
+ string.Format(
+ CultureInfo.InvariantCulture,
+ "Active context {0} received after driver restart, from evaluator {1}",
+ activeContext.Id,
+ activeContext.EvaluatorId));
+
+ IEvaluatorDescriptor evaluatorDescriptor = activeContext.EvaluatorDescriptor;
+ string ipAddress = evaluatorDescriptor.NodeDescriptor.InetSocketAddress.Address.ToString();
+ int port = evaluatorDescriptor.NodeDescriptor.InetSocketAddress.Port;
+ string hostName = evaluatorDescriptor.NodeDescriptor.HostName;
+
+ Console.WriteLine(
+ string.Format(
+ CultureInfo.InvariantCulture,
+ "The running evaluator allocated by previous driver is assigned with {0} MB of memory and is running at ip: {1} and port {2}, with hostname {3}",
+ evaluatorDescriptor.Memory,
+ ipAddress,
+ port,
+ hostName));
+ }
+
+ public void OnError(Exception error)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void OnCompleted()
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/7824be83/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloDriverRestartRunningTaskHandler.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloDriverRestartRunningTaskHandler.cs b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloDriverRestartRunningTaskHandler.cs
new file mode 100644
index 0000000..8fb7871
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloDriverRestartRunningTaskHandler.cs
@@ -0,0 +1,71 @@
+/**
+ * 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.Globalization;
+using Org.Apache.REEF.Driver.Context;
+using Org.Apache.REEF.Driver.Task;
+using Org.Apache.REEF.Tang.Annotations;
+using Org.Apache.REEF.Utilities;
+
+namespace Org.Apache.REEF.Examples.AllHandlers
+{
+ /// <summary>
+ /// Sample implementation of RunningTaskHandler when driver is restarted
+ /// </summary>
+ public class HelloDriverRestartRunningTaskHandler : IObserver<IRunningTask>
+ {
+ [Inject]
+ private HelloDriverRestartRunningTaskHandler()
+ {
+ }
+
+ /// <summary>
+ /// Sending message to running task
+ /// </summary>
+ /// <param name="runningTask"></param>
+ public void OnNext(IRunningTask runningTask)
+ {
+ IActiveContext context = runningTask.ActiveContext;
+
+ Console.WriteLine(string.Format(
+ CultureInfo.InvariantCulture,
+ "HelloDriverRestartRunningTaskHandler: Task [{0}] is running after driver restart. Evaluator id: [{1}].",
+ runningTask.Id,
+ context.EvaluatorId));
+
+ runningTask.Send(ByteUtilities.StringToByteArrays(
+ string.Format(
+ CultureInfo.InvariantCulture,
+ "Hello, task {0}! Glad to know that you are still running in Evaluator {1} after driver restart!",
+ runningTask.Id,
+ context.EvaluatorId)));
+ }
+
+ public void OnError(Exception error)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void OnCompleted()
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/7824be83/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloDriverStartHandler.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloDriverStartHandler.cs b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloDriverStartHandler.cs
new file mode 100644
index 0000000..fd29e9d
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloDriverStartHandler.cs
@@ -0,0 +1,79 @@
+/**
+ * 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.AllHandlers
+{
+ /// <summary>
+ /// A sample implementation of driver start handler
+ /// </summary>
+ 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
+ /// Sample code to create EvaluatorRequest and submit it
+ /// </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/7824be83/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloFailedEvaluatorHandler.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloFailedEvaluatorHandler.cs b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloFailedEvaluatorHandler.cs
new file mode 100644
index 0000000..542fd3e
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloFailedEvaluatorHandler.cs
@@ -0,0 +1,74 @@
+/**
+ * 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.Evaluator;
+using Org.Apache.REEF.Tang.Annotations;
+
+namespace Org.Apache.REEF.Examples.AllHandlers
+{
+ /// <summary>
+ /// A sample implementation of FailedEvaluatorHandler
+ /// </summary>
+ public class HelloFailedEvaluatorHandler : IObserver<IFailedEvaluator>
+ {
+ private static int _failureCount = 0;
+
+ private static readonly int _maxTrial = 2;
+
+ [Inject]
+ private HelloFailedEvaluatorHandler()
+ {
+ }
+
+ /// <summary>
+ /// Sample code to resubmit a request
+ /// </summary>
+ /// <param name="failedEvaluator"></param>
+ public void OnNext(IFailedEvaluator failedEvaluator)
+ {
+ Console.WriteLine("Receive a failed evaluator: " + failedEvaluator.Id);
+ if (++_failureCount < _maxTrial)
+ {
+ Console.WriteLine("Requesting another evaluator");
+ EvaluatorRequest newRequest = new EvaluatorRequest(1, 512, "somerack");
+ IEvaluatorRequestor requestor = failedEvaluator.GetEvaluatorRequetor();
+ if (failedEvaluator.GetEvaluatorRequetor() != null)
+ {
+ requestor.Submit(newRequest);
+ }
+ }
+ else
+ {
+ Console.WriteLine("Exceed max retries number");
+ throw new Exception("Unrecoverable evaluator failure.");
+ }
+ }
+
+ public void OnError(Exception error)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void OnCompleted()
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/7824be83/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloFailedTaskHandler.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloFailedTaskHandler.cs b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloFailedTaskHandler.cs
new file mode 100644
index 0000000..4b19bea
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloFailedTaskHandler.cs
@@ -0,0 +1,74 @@
+/**
+ * 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.Globalization;
+using Org.Apache.REEF.Driver.Task;
+using Org.Apache.REEF.Tang.Annotations;
+using Org.Apache.REEF.Utilities;
+
+namespace Org.Apache.REEF.Examples.AllHandlers
+{
+ /// <summary>
+ /// A sample implementation of FailedTask Handler
+ /// </summary>
+ public class HelloFailedTaskHandler : IObserver<IFailedTask>
+ {
+ [Inject]
+ private HelloFailedTaskHandler()
+ {
+ }
+
+ /// <summary>
+ /// Sample code close the active context when task is failed
+ /// </summary>
+ /// <param name="failedTask"></param>
+ public void OnNext(IFailedTask failedTask)
+ {
+ string errorMessage = string.Format(
+ CultureInfo.InvariantCulture,
+ "Task [{0}] has failed caused by [{1}], with message [{2}] and description [{3}]. The raw data for failure is [{4}].",
+ failedTask.Id,
+ failedTask.Reason.IsPresent() ? failedTask.Reason.Value : string.Empty,
+ failedTask.Message,
+ failedTask.Description.IsPresent() ? failedTask.Description.Value : string.Empty,
+ failedTask.Data.IsPresent() ? ByteUtilities.ByteArrarysToString(failedTask.Data.Value) : string.Empty);
+
+ Console.WriteLine(errorMessage);
+
+ if (failedTask.GetActiveContext().IsPresent())
+ {
+ Console.WriteLine("Disposing the active context the failed task ran in.");
+
+ // we must do something here: either close the context or resubmit a task to the active context
+ failedTask.GetActiveContext().Value.Dispose();
+ }
+ }
+
+ public void OnCompleted()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void OnError(Exception error)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/7824be83/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloHttpHandler.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloHttpHandler.cs b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloHttpHandler.cs
new file mode 100644
index 0000000..3c4899c
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloHttpHandler.cs
@@ -0,0 +1,59 @@
+/**
+ * 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.Globalization;
+using System.Net;
+using Org.Apache.REEF.Driver.Bridge;
+using Org.Apache.REEF.Tang.Annotations;
+using Org.Apache.REEF.Utilities;
+using Org.Apache.REEF.Utilities.Logging;
+
+namespace Org.Apache.REEF.Examples.AllHandlers
+{
+ /// <summary>
+ /// A sample implementation of HttpHandler
+ /// </summary>
+ public class HelloHttpHandler : IHttpHandler
+ {
+ private static readonly Logger Logger = Logger.GetLogger(typeof(HttpServerHandler));
+
+ [Inject]
+ private HelloHttpHandler()
+ {
+ }
+
+ public string GetSpecification()
+ {
+ return "NRT"; //Client Example
+ }
+
+ /// <summary>
+ /// Sample code after receiving http request and send back the http response
+ /// </summary>
+ /// <param name="requet"></param>
+ /// <param name="response"></param>
+ public void OnHttpRequest(ReefHttpRequest requet, ReefHttpResponse response)
+ {
+ Logger.Log(Level.Info, string.Format(CultureInfo.CurrentCulture, "HelloHttpHandler OnHttpRequest: URL: {0}, QueryString: {1}, inputStream: {2}.", requet.Url, requet.Querystring, ByteUtilities.ByteArrarysToString(requet.InputStream)));
+ response.Status = HttpStatusCode.OK;
+ response.OutputStream =
+ ByteUtilities.StringToByteArrays("Byte array returned from HelloHttpHandler in CLR!!!");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/7824be83/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloRestartHandler.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloRestartHandler.cs b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloRestartHandler.cs
new file mode 100644
index 0000000..547aa08
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloRestartHandler.cs
@@ -0,0 +1,55 @@
+/**
+ * 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.Tang.Annotations;
+using Org.Apache.REEF.Wake.Time.Event;
+
+namespace Org.Apache.REEF.Examples.AllHandlers
+{
+ /// <summary>
+ /// A sample implementation of driver restart handler
+ /// </summary>
+ public class HelloRestartHandler : IObserver<StartTime>
+ {
+ [Inject]
+ private HelloRestartHandler()
+ {
+ }
+
+ /// <summary>
+ /// It is called when the driver is restarted
+ /// </summary>
+ /// <param name="value"></param>
+ public void OnNext(StartTime value)
+ {
+ Console.WriteLine("Hello from CLR: we are informed that Driver has restarted at " + new DateTime(value.TimeStamp));
+ }
+
+ public void OnError(Exception error)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void OnCompleted()
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/7824be83/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloRunningTaskHandler.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloRunningTaskHandler.cs b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloRunningTaskHandler.cs
new file mode 100644
index 0000000..cc0c725
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloRunningTaskHandler.cs
@@ -0,0 +1,69 @@
+/**
+ * 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.Globalization;
+using Org.Apache.REEF.Driver.Context;
+using Org.Apache.REEF.Driver.Task;
+using Org.Apache.REEF.Tang.Annotations;
+using Org.Apache.REEF.Utilities;
+
+namespace Org.Apache.REEF.Examples.AllHandlers
+{
+ /// <summary>
+ /// Sample implementation of RunningTaskHandler
+ /// </summary>
+ public class HelloRunningTaskHandler : IObserver<IRunningTask>
+ {
+ [Inject]
+ private HelloRunningTaskHandler()
+ {
+ }
+
+ /// <summary>
+ /// Sample code to send message to running task
+ /// </summary>
+ /// <param name="runningTask"></param>
+ public void OnNext(IRunningTask runningTask)
+ {
+ IActiveContext context = runningTask.ActiveContext;
+
+ string messageStr = string.Format(
+ CultureInfo.InvariantCulture,
+ "HelloRunningTaskHandler: Task [{0}] is running. Evaluator id: [{1}].",
+ runningTask.Id,
+ context.EvaluatorId);
+ Console.WriteLine(messageStr);
+
+ byte[] message = ByteUtilities.StringToByteArrays(messageStr);
+
+ runningTask.Send(message);
+ }
+
+ public void OnError(Exception error)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void OnCompleted()
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/7824be83/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloTaskMessageHandler.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloTaskMessageHandler.cs b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloTaskMessageHandler.cs
new file mode 100644
index 0000000..18b798e
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloTaskMessageHandler.cs
@@ -0,0 +1,61 @@
+/**
+ * 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.Globalization;
+using System.Text;
+using Org.Apache.REEF.Driver.Task;
+using Org.Apache.REEF.Tang.Annotations;
+
+namespace Org.Apache.REEF.Examples.AllHandlers
+{
+ /// <summary>
+ /// A sample implementation of TaskMessage Handler
+ /// </summary>
+ public class HelloTaskMessageHandler : IObserver<ITaskMessage>
+ {
+ [Inject]
+ private HelloTaskMessageHandler()
+ {
+ }
+
+ /// <summary>
+ /// It is called when receiving a task message
+ /// </summary>
+ /// <param name="taskMessage"></param>
+ public void OnNext(ITaskMessage taskMessage)
+ {
+ Console.WriteLine(string.Format(
+ CultureInfo.InvariantCulture,
+ "CLR HelloTaskMessageHandler received following message from Task: {0}, Message: {1}.",
+ taskMessage.TaskId,
+ Encoding.UTF8.GetString(taskMessage.Message)));
+ }
+
+ public void OnCompleted()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void OnError(Exception error)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/7824be83/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloTraceListener.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloTraceListener.cs b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloTraceListener.cs
new file mode 100644
index 0000000..bd97549
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloTraceListener.cs
@@ -0,0 +1,48 @@
+/**
+ * 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.Diagnostics;
+using Org.Apache.REEF.Tang.Annotations;
+
+namespace Org.Apache.REEF.Examples.AllHandlers
+{
+ /// <summary>
+ /// This is a sample implementation on how custom trace listener can be implemented
+ /// </summary>
+ public class HelloTraceListener : TraceListener
+ {
+ private readonly TraceListener _listener;
+
+ [Inject]
+ private HelloTraceListener()
+ {
+ _listener = new ConsoleTraceListener();
+ }
+
+ public override void Write(string message)
+ {
+ _listener.Write("[helloTrace]" + message );
+ }
+
+ public override void WriteLine(string message)
+ {
+ _listener.WriteLine("[helloTrace]" + message);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/7824be83/lang/cs/Org.Apache.REEF.Examples.AllHandlers/Org.Apache.REEF.Examples.AllHandlers.csproj
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/Org.Apache.REEF.Examples.AllHandlers.csproj b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/Org.Apache.REEF.Examples.AllHandlers.csproj
new file mode 100644
index 0000000..3a69437
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/Org.Apache.REEF.Examples.AllHandlers.csproj
@@ -0,0 +1,122 @@
+<?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.AllHandlers</RootNamespace>
+ <AssemblyName>Org.Apache.REEF.Examples.AllHandlers</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="AllHandlers.cs" />
+ <Compile Include="AnotherHelloAllocatedEvaluatorHandler.cs" />
+ <Compile Include="HelloActiveContextHandler.cs" />
+ <Compile Include="HelloAllocatedEvaluatorHandler.cs" />
+ <Compile Include="HelloCompletedEvaluatorHandler.cs" />
+ <Compile Include="HelloDriverRestartActiveContextHandler.cs" />
+ <Compile Include="HelloDriverRestartRunningTaskHandler.cs" />
+ <Compile Include="HelloDriverStartHandler.cs" />
+ <Compile Include="HelloFailedEvaluatorHandler.cs" />
+ <Compile Include="HelloFailedTaskHandler.cs" />
+ <Compile Include="HelloHttpHandler.cs" />
+ <Compile Include="HelloRestartHandler.cs" />
+ <Compile Include="HelloRunningTaskHandler.cs" />
+ <Compile Include="HelloTaskMessageHandler.cs" />
+ <Compile Include="HelloTraceListener.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.Examples\Org.Apache.REEF.Examples.csproj">
+ <Project>{75503f90-7b82-4762-9997-94b5c68f15db}</Project>
+ <Name>Org.Apache.REEF.Examples</Name>
+ </ProjectReference>
+ <ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.Network\Org.Apache.REEF.Network.csproj">
+ <Project>{883ce800-6a6a-4e0a-b7fe-c054f4f2c1dc}</Project>
+ <Name>Org.Apache.REEF.Network</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>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Readme.md" />
+ </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/7824be83/lang/cs/Org.Apache.REEF.Examples.AllHandlers/Properties/AssemblyInfo.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/Properties/AssemblyInfo.cs b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..185f822
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/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.AllHandlers")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Org.Apache.REEF.Examples.AllHandlers")]
+[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("0.12.0.0")]
+[assembly: AssemblyFileVersion("0.12.0.0")]
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/7824be83/lang/cs/Org.Apache.REEF.Examples.AllHandlers/Readme.md
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/Readme.md b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/Readme.md
new file mode 100644
index 0000000..671c991
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/Readme.md
@@ -0,0 +1,17 @@
+# AllHandlers
+This project contains an example of a REEF Program. It contains the following classes:
+
+ * `AllHandlers`: This is the program that submits the driver to the local runtime.
+ * `HelloDriverStartHandler`: The Driver requests 2 Evaluators.
+ * `HelloAllocatedEvaluatorHandler` : The handler that submit Context and Tasks
+ * `HelloActiveContextHandler` : The handler that submit Tasks to Context
+ * `HelloHttpHandler` : The handler that handles http requests
+ * `HelloRunningTaskHandler` : The handler that send messages to Running Task
+ * `HelloTaskMessageHandler` : The handler that receives task messages
+ * Other handler samples
+ * `HelloTask`: This Task prints a greeting to STDOUT of the Evaluator.
+
+## Running it
+Just run the main class, `AllHandlers`, followed by the runtime you want, e.g. `local` and the run time folder e.g. 'REEF_LOCAL_RUNTIME'. If you don't specify the run time parameters, default will be used.
+e.g. AllHandlers.exe local REEF_LOCAL_RUNTIME
+or AllHandler.exe
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/7824be83/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
deleted file mode 100644
index d05503d..0000000
--- a/lang/cs/Org.Apache.REEF.Examples.HelloCLRBridge/ClrBridgeClient.cs
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * 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.Bridge;
-using Org.Apache.REEF.Driver.Defaults;
-using Org.Apache.REEF.Examples.HelloCLRBridge.Handlers;
-using Org.Apache.REEF.Examples.Tasks.HelloTask;
-using Org.Apache.REEF.Network.Naming;
-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 driverCondig = TangFactory.GetTang().NewConfigurationBuilder(helloDriverConfiguration)
- .BindSetEntry<DriverBridgeConfigurationOptions.SetOfAssemblies, string>(typeof(HelloTask).Assembly.GetName().Name)
- .BindSetEntry<DriverBridgeConfigurationOptions.SetOfAssemblies, string>(typeof(NameClient).Assembly.GetName().Name)
- .Build();
-
- var helloJobSubmission = _jobSubmissionBuilderFactory.GetJobSubmissionBuilder()
- .AddDriverConfiguration(driverCondig)
- .AddGlobalAssemblyForType(typeof(HelloDriverStartHandler))
- .SetJobIdentifier("HelloDriver")
- .Build();
-
- _reefClient.Submit(helloJobSubmission);
- }
-
- /// <summary>
- /// <param name="runOnYarn"></param>
- /// <param name="runtimeFolder"></param>
- /// <returns></returns>
- private static IConfiguration GetRuntimeConfiguration(string runOnYarn, string runtimeFolder)
- {
- switch (runOnYarn)
- {
- case Local:
- var dir = Path.Combine(".", runtimeFolder);
- return LocalRuntimeClientConfiguration.ConfigurationModule
- .Set(LocalRuntimeClientConfiguration.NumberOfEvaluators, "2")
- .Set(LocalRuntimeClientConfiguration.RuntimeFolder, dir)
- .Build();
- case YARN:
- return YARNClientConfiguration.ConfigurationModule.Build();
- default:
- throw new Exception("Unknown runtime: " + runOnYarn);
- }
- }
-
- public static void Main(string[] args)
- {
- Run(args);
- }
-
- public static void Run(string[] args)
- {
- string runOnYarn = args.Length > 0 ? args[0] : Local;
- string runtimeFolder = args.Length > 1 ? args[1] : "REEF_LOCAL_RUNTIME";
- TangFactory.GetTang().NewInjector(GetRuntimeConfiguration(runOnYarn, runtimeFolder)).GetInstance<ClrBridgeClient>().Run();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/7824be83/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
deleted file mode 100644
index 08702d7..0000000
--- a/lang/cs/Org.Apache.REEF.Examples.HelloCLRBridge/Org.Apache.REEF.Examples.HelloCLRBridge.csproj
+++ /dev/null
@@ -1,105 +0,0 @@
-<?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.Examples\Org.Apache.REEF.Examples.csproj">
- <Project>{75503f90-7b82-4762-9997-94b5c68f15db}</Project>
- <Name>Org.Apache.REEF.Examples</Name>
- </ProjectReference>
- <ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.Network\Org.Apache.REEF.Network.csproj">
- <Project>{883ce800-6a6a-4e0a-b7fe-c054f4f2c1dc}</Project>
- <Name>Org.Apache.REEF.Network</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>
- </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