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/11/06 17:07:08 UTC
incubator-reef git commit: [REEF-357] Document and refactor
ClrHandlerHelper
Repository: incubator-reef
Updated Branches:
refs/heads/master 8f1e78f6a -> 3a297b691
[REEF-357] Document and refactor ClrHandlerHelper
JIRA:
[REEF-357](https://issues.apache.org/jira/browse/REEF-357)
Pull Request:
Closes #580
Project: http://git-wip-us.apache.org/repos/asf/incubator-reef/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-reef/commit/3a297b69
Tree: http://git-wip-us.apache.org/repos/asf/incubator-reef/tree/3a297b69
Diff: http://git-wip-us.apache.org/repos/asf/incubator-reef/diff/3a297b69
Branch: refs/heads/master
Commit: 3a297b691648c75d6bfdba36ba8933b0ce63ed73
Parents: 8f1e78f
Author: Andrew Chung <af...@gmail.com>
Authored: Tue Oct 20 11:11:13 2015 -0700
Committer: Markus Weimer <we...@apache.org>
Committed: Fri Nov 6 08:05:42 2015 -0800
----------------------------------------------------------------------
.../Bridge/ClrHandlerHelper.cs | 103 +++++++++++++++----
1 file changed, 83 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3a297b69/lang/cs/Org.Apache.REEF.Driver/Bridge/ClrHandlerHelper.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Driver/Bridge/ClrHandlerHelper.cs b/lang/cs/Org.Apache.REEF.Driver/Bridge/ClrHandlerHelper.cs
index 7b07ce0..0c66158 100644
--- a/lang/cs/Org.Apache.REEF.Driver/Bridge/ClrHandlerHelper.cs
+++ b/lang/cs/Org.Apache.REEF.Driver/Bridge/ClrHandlerHelper.cs
@@ -23,7 +23,6 @@ using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
-using Org.Apache.REEF.Driver.Evaluator;
using Org.Apache.REEF.Tang.Exceptions;
using Org.Apache.REEF.Tang.Implementations.Tang;
using Org.Apache.REEF.Tang.Interface;
@@ -35,18 +34,43 @@ namespace Org.Apache.REEF.Driver.Bridge
{
public class ClrHandlerHelper
{
+ private const string DllExtension = ".dll";
private static readonly Logger LOGGER = Logger.GetLogger(typeof(ClrHandlerHelper));
+ /// <summary>
+ /// The set of REEF assemblies required for the Driver.
+ /// </summary>
+ [Obsolete("Deprecated in 0.14. Will be removed in 0.15.")]
public static string[] ReefAssemblies
{
get
{
- return new[] { "Microsoft.Hadoop.Avro.dll", "Org.Apache.REEF.Driver.dll", "Org.Apache.REEF.Common.dll", "Org.Apache.REEF.Utilities.dll", "Org.Apache.REEF.Network.dll", "Org.Apache.REEF.Tang.dll", "Org.Apache.REEF.Wake.dll", "Newtonsoft.Json.dll", "protobuf-net.dll" };
+ return new[]
+ {
+ "Microsoft.Hadoop.Avro.dll",
+ "Org.Apache.REEF.Driver.dll",
+ "Org.Apache.REEF.Common.dll",
+ "Org.Apache.REEF.Utilities.dll",
+ "Org.Apache.REEF.Network.dll",
+ "Org.Apache.REEF.Tang.dll",
+ "Org.Apache.REEF.Wake.dll",
+ "Newtonsoft.Json.dll",
+ "protobuf-net.dll"
+ };
}
}
+ /// <summary>
+ /// The memory granularity in megabytes for the Evaluator Descriptors.
+ /// </summary>
internal static int MemoryGranularity { get; set; }
+ /// <summary>
+ /// Creates an InterOp handle for .NET EventHandlers.
+ /// </summary>
+ /// <param name="handler">The EventHandler</param>
+ /// <returns>The InterOp handle</returns>
+ [Obsolete("Deprecated in 0.14. Will be removed in 0.15.")]
public static ulong CreateHandler(object handler)
{
GCHandle gc = GCHandle.Alloc(handler);
@@ -55,27 +79,47 @@ namespace Org.Apache.REEF.Driver.Bridge
return ul;
}
+ /// <summary>
+ /// Frees a .NET handle.
+ /// </summary>
+ /// <param name="handle">The handle to free</param>
+ [Obsolete("Deprecated in 0.14. Will be removed in 0.15.")]
public static void FreeHandle(ulong handle)
{
GCHandle gc = GCHandle.FromIntPtr((IntPtr)handle);
gc.Free();
}
+ /// <summary>
+ /// Sets the memory granularity in megabytes for the Evaluator Descriptors.
+ /// </summary>
+ /// <param name="granularity">The memory granularity in megabytes</param>
+ [Obsolete("Deprecated in 0.14. Will be removed in 0.15.")]
public static void SetMemoryGranuality(int granularity)
{
if (granularity <= 0)
{
- var e = new ArgumentException("granularity must be a positive value, provided: " + granularity);
+ var e = new ArgumentException("Granularity must be a positive value, provided: " + granularity);
Exceptions.Throw(e, LOGGER);
}
MemoryGranularity = granularity;
}
+ /// <summary>
+ /// Returns the null handle not used on the Java side (i.e. 0).
+ /// </summary>
+ /// <returns>The null handle</returns>
+ [Obsolete("Deprecated in 0.14. Will be removed in 0.15.")]
public static ulong CreateNullHandler()
{
return Constants.NullHandler;
}
+ /// <summary>
+ /// Gets the command line arguments as specified in <see cref="DriverBridgeConfigurationOptions.ArgumentSets"/>.
+ /// </summary>
+ /// <returns>The set of command line arguments</returns>
+ [Obsolete("Deprecated in 0.14. Will be removed in 0.15. Inject the CommandLineArguments in your Handler instead.")]
public static ISet<string> GetCommandLineArguments()
{
using (LOGGER.LogFunction("ClrHandlerHelper::GetCommandLineArguments"))
@@ -87,21 +131,33 @@ namespace Org.Apache.REEF.Driver.Bridge
}
catch (InjectionException e)
{
- string error = "Cannot inject command line arguments from driver bridge configuration. ";
+ const string error = "Cannot inject command line arguments from driver bridge configuration.";
Exceptions.CaughtAndThrow(e, Level.Error, error, LOGGER);
- throw e;
+ throw;
}
return arguments.Arguments;
}
}
+ /// <summary>
+ /// Allows additional Java classes to be included into the classpath by the user.
+ /// Generates a file named <see cref="Constants.GlobalUserSuppliedJavaLibraries"/> in the
+ /// executing directory containing classpath information.
+ /// </summary>
+ /// <param name="classPaths">classpaths to the Java classes</param>
+ [Obsolete("Deprecated in 0.14. Will be removed in 0.15.")]
public static void SupplyAdditionalClassPath(params string[] classPaths)
{
- string path = Path.Combine(Directory.GetCurrentDirectory(), Constants.GlobalUserSuppliedJavaLibraries);
- File.Delete(path);
+ var path = Path.Combine(Directory.GetCurrentDirectory(), Constants.GlobalUserSuppliedJavaLibraries);
File.WriteAllText(path, string.Join(",", classPaths));
}
+ /// <summary>
+ /// Generates the class hierarchy binary to the current directory into a file named
+ /// <see cref="Constants.ClassHierarchyBin"/>.
+ /// </summary>
+ /// <param name="clrDlls">The set of DLLs generating the class hierarchy</param>
+ [Obsolete("Deprecated in 0.14. Will be removed in 0.15.")]
public static void GenerateClassHierarchy(ISet<string> clrDlls)
{
using (LOGGER.LogFunction("ClrHandlerHelper::GenerateClassHierarchy"))
@@ -109,20 +165,24 @@ namespace Org.Apache.REEF.Driver.Bridge
IClassHierarchy ns = TangFactory.GetTang().GetClassHierarchy(clrDlls.ToArray());
ProtocolBufferClassHierarchy.Serialize(Constants.ClassHierarchyBin, ns);
- LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "Class hierarchy written to [{0}].", Path.Combine(Directory.GetCurrentDirectory(), Constants.ClassHierarchyBin)));
+ LOGGER.Log(Level.Info, "Class hierarchy written to [{0}].", Path.Combine(Directory.GetCurrentDirectory(), Constants.ClassHierarchyBin));
}
}
+ /// <summary>
+ /// Gets the list of assemblies needed for the REEF driver.
+ /// </summary>
+ /// <returns>A whitespace separated string consisting of all the required driver assemblies</returns>
public static string GetAssembliesListForReefDriverApp()
{
using (LOGGER.LogFunction("ClrHandlerHelper::GetAssembliesListForReefDriverApp"))
{
- string executionDirectory = Directory.GetCurrentDirectory();
- IList<string> assemblies =
+ var executionDirectory = Directory.GetCurrentDirectory();
+ var assemblies = new List<string>(
Directory.GetFiles(Path.Combine(executionDirectory, Constants.DriverAppDirectory), "*.dll")
- .Select(f => string.Format(CultureInfo.InvariantCulture, "\"{0}\"", Constants.DriverAppDirectory + @"\" + Path.GetFileName(f))).ToList();
+ .Select(f => string.Format(CultureInfo.InvariantCulture, "\"{0}\"", Constants.DriverAppDirectory + @"\" + Path.GetFileName(f))));
- foreach (string reefAssembly in ReefAssemblies)
+ foreach (var reefAssembly in ReefAssemblies)
{
if (!File.Exists(reefAssembly))
{
@@ -136,19 +196,22 @@ namespace Org.Apache.REEF.Driver.Bridge
}
}
- public static void CopyDllsToAppDirectory(HashSet<string> dlls)
+ /// <summary>
+ /// Creates a new local directory <see cref="Constants.DriverAppDirectory"/>
+ /// at the current directory and copies all .dll files as specified by
+ /// the input parameter <see cref="dlls"/> from the current directrory into
+ /// the new directory.
+ /// </summary>
+ /// <param name="dlls">The set of DLLs to copy from the current directory</param>
+ public static void CopyDllsToAppDirectory(ISet<string> dlls)
{
using (LOGGER.LogFunction("ClrHandlerHelper::CopyDllsToAppDirectory"))
{
- string executionDirectory = Directory.GetCurrentDirectory();
+ var executionDirectory = Directory.GetCurrentDirectory();
Directory.CreateDirectory(Path.Combine(executionDirectory, Constants.DriverAppDirectory));
- foreach (string dll in dlls)
+ foreach (var dll in dlls)
{
- string dllFile = dll;
- if (!dll.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
- {
- dllFile += ".dll";
- }
+ var dllFile = dll.EndsWith(DllExtension, StringComparison.OrdinalIgnoreCase) ? dll : dll + DllExtension;
if (!File.Exists(dllFile))
{
var e = new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Assembly [{0}] for REEF application not found in {1}", dllFile, executionDirectory));