Repository: reef Updated Branches: refs/heads/master 677d86337 -> eb9be360f
[REEF-1415] Deprecate JavaTaskException and set AsError to null on FailedTask for FailedEvaluators This addressed the issue by * Deprecating JavaTaskException in favor of TaskExceptionMissingException. * Documenting the FailedTask class. * Adding a helper function in ByteUtilities to check byte array IsNullOrEmpty. JIRA: [REEF-1415](https://issues.apache.org/jira/browse/REEF-1415) Pull Request: This closes #1024 Project: http://git-wip-us.apache.org/repos/asf/reef/repo Commit: http://git-wip-us.apache.org/repos/asf/reef/commit/eb9be360 Tree: http://git-wip-us.apache.org/repos/asf/reef/tree/eb9be360 Diff: http://git-wip-us.apache.org/repos/asf/reef/diff/eb9be360 Branch: refs/heads/master Commit: eb9be360f2dcc6b7069456e587d5f3cca4ec591e Parents: 677d863 Author: Andrew Chung <[email protected]> Authored: Fri Jun 3 11:18:08 2016 -0700 Committer: Markus Weimer <[email protected]> Committed: Fri Jun 10 09:11:44 2016 -0700 ---------------------------------------------------------------------- .../Bridge/Events/FailedTask.cs | 38 +++++++++++++------ .../Org.Apache.REEF.Driver.csproj | 1 + .../Task/JavaTaskException.cs | 10 ++++- .../Task/TaskExceptionMissingException.cs | 40 ++++++++++++++++++++ .../Org.Apache.REEF.Utilities/ByteUtilities.cs | 8 ++++ 5 files changed, 85 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/reef/blob/eb9be360/lang/cs/Org.Apache.REEF.Driver/Bridge/Events/FailedTask.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/Bridge/Events/FailedTask.cs b/lang/cs/Org.Apache.REEF.Driver/Bridge/Events/FailedTask.cs index 8e51123..0e495bb 100644 --- a/lang/cs/Org.Apache.REEF.Driver/Bridge/Events/FailedTask.cs +++ b/lang/cs/Org.Apache.REEF.Driver/Bridge/Events/FailedTask.cs @@ -16,11 +16,10 @@ // under the License. using System; -using System.IO; using System.Runtime.Serialization; -using System.Runtime.Serialization.Formatters.Binary; using Org.Apache.REEF.Common.Avro; using Org.Apache.REEF.Common.Exceptions; +using Org.Apache.REEF.Common.Runtime.Evaluator.Task; using Org.Apache.REEF.Driver.Bridge.Clr2java; using Org.Apache.REEF.Driver.Context; using Org.Apache.REEF.Driver.Task; @@ -42,13 +41,19 @@ namespace Org.Apache.REEF.Driver.Bridge.Events var avroFailedTask = AvroJsonSerializer<AvroFailedTask>.FromBytes(serializedInfo); Id = avroFailedTask.identifier; + + // Data is simply the serialized Exception.ToString. Data = Optional<byte[]>.OfNullable(avroFailedTask.data); - Message = avroFailedTask.message ?? "No message in Failed Task."; + + // Message can be overwritten in Java, if the C# Message is null and the Task failure is caused by an Evaluator failure. + Message = string.IsNullOrWhiteSpace(avroFailedTask.message) ? "No message in Failed Task." : avroFailedTask.message; + + // Gets the Exception. _cause = GetCause(avroFailedTask.cause, ByteUtilities.ByteArraysToString(avroFailedTask.data)); // This is always empty, even in Java. Description = Optional<string>.Empty(); - FailedTaskClr2Java = failedTaskClr2Java; + ActiveContextClr2Java = failedTaskClr2Java.GetActiveContext(); } @@ -63,9 +68,6 @@ namespace Org.Apache.REEF.Driver.Bridge.Events public Optional<byte[]> Data { get; set; } [DataMember] - private IFailedTaskClr2Java FailedTaskClr2Java { get; set; } - - [DataMember] private IActiveContextClr2Java ActiveContextClr2Java { get; set; } /// <summary> @@ -87,16 +89,30 @@ namespace Org.Apache.REEF.Driver.Bridge.Events return Optional<IActiveContext>.Of(new ActiveContext(ActiveContextClr2Java)); } + /// <summary> + /// Returns the Exception causing the Failed Task. + /// </summary> + /// <returns>the Exception causing the Failed Task.</returns> + /// <remarks> + /// If the Exception was caused by a control flow error (start, stop, suspend), + /// a <see cref="TaskClientCodeException"/> is expected. + /// If the original Exception was not serializable, a <see cref="NonSerializableTaskException"/> is expected. + /// If the Exception was missing, presumably caused by a failed Evaluator, a + /// <see cref="TaskExceptionMissingException"/> is expected. + /// </remarks> public Exception AsError() { return _cause; } - private static Exception GetCause(byte[] serializedCause, string taskExceptionString) + private static Exception GetCause( + byte[] serializedCause, string originalTaskExceptionToString) { - if (serializedCause == null) + // TODO[JIRA REEF-1422]: Distinguish between Java Task Exception and missing Exception. + if (ByteUtilities.IsNullOrEmpty(serializedCause)) { - return new JavaTaskException("Task failed with Exception generated by the Java Driver, please inspect the message."); + return new TaskExceptionMissingException( + "Task failed without an Exception, presumably caused by an Exception failure. Please inspect the FailedTask message."); } try @@ -108,7 +124,7 @@ namespace Org.Apache.REEF.Driver.Bridge.Events Exceptions.Caught(se, Level.Info, "Exception from Task was not able to be deserialized, returning a NonSerializableTaskException.", Logger); - return NonSerializableTaskException.UnableToDeserialize(taskExceptionString, se); + return NonSerializableTaskException.UnableToDeserialize(originalTaskExceptionToString, se); } } } http://git-wip-us.apache.org/repos/asf/reef/blob/eb9be360/lang/cs/Org.Apache.REEF.Driver/Org.Apache.REEF.Driver.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/Org.Apache.REEF.Driver.csproj b/lang/cs/Org.Apache.REEF.Driver/Org.Apache.REEF.Driver.csproj index a9a91a1..c7e55b2 100644 --- a/lang/cs/Org.Apache.REEF.Driver/Org.Apache.REEF.Driver.csproj +++ b/lang/cs/Org.Apache.REEF.Driver/Org.Apache.REEF.Driver.csproj @@ -149,6 +149,7 @@ under the License. <Compile Include="Task\IRunningTask.cs" /> <Compile Include="Task\ISuspendedTask.cs" /> <Compile Include="Task\ITaskMessage.cs" /> + <Compile Include="Task\TaskExceptionMissingException.cs" /> </ItemGroup> <ItemGroup> <None Include="Bridge\Avro\README.md" /> http://git-wip-us.apache.org/repos/asf/reef/blob/eb9be360/lang/cs/Org.Apache.REEF.Driver/Task/JavaTaskException.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/Task/JavaTaskException.cs b/lang/cs/Org.Apache.REEF.Driver/Task/JavaTaskException.cs index 2e44413..9b12bdd 100644 --- a/lang/cs/Org.Apache.REEF.Driver/Task/JavaTaskException.cs +++ b/lang/cs/Org.Apache.REEF.Driver/Task/JavaTaskException.cs @@ -16,17 +16,25 @@ // under the License. using System; +using System.Runtime.Serialization; namespace Org.Apache.REEF.Driver.Task { /// <summary> - /// A Task Exception from the Java side. Generally not expected. + /// A Task Exception from the Java side. + /// TODO[JIRA REEF-1422]: Throw on the right occasion, when C# Driver orchestrates Java Tasks. /// </summary> + [Serializable] public sealed class JavaTaskException : Exception { internal JavaTaskException(string message) : base(message) { } + + private JavaTaskException(SerializationInfo serializationInfo, StreamingContext streamingContext) + : base(serializationInfo, streamingContext) + { + } } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/reef/blob/eb9be360/lang/cs/Org.Apache.REEF.Driver/Task/TaskExceptionMissingException.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/Task/TaskExceptionMissingException.cs b/lang/cs/Org.Apache.REEF.Driver/Task/TaskExceptionMissingException.cs new file mode 100644 index 0000000..95ccaf8 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Driver/Task/TaskExceptionMissingException.cs @@ -0,0 +1,40 @@ +// 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.Runtime.Serialization; + +namespace Org.Apache.REEF.Driver.Task +{ + /// <summary> + /// An Exception that is used to indicate that there are no Task Exceptions + /// in a Context. Could occur when an Evaluator fails or when a Context fails + /// before a Task is reported to be initialized. + /// </summary> + [Serializable] + public sealed class TaskExceptionMissingException : Exception + { + internal TaskExceptionMissingException(string message) : base(message) + { + } + + private TaskExceptionMissingException(SerializationInfo serializationInfo, StreamingContext streamingContext) + : base(serializationInfo, streamingContext) + { + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/reef/blob/eb9be360/lang/cs/Org.Apache.REEF.Utilities/ByteUtilities.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Utilities/ByteUtilities.cs b/lang/cs/Org.Apache.REEF.Utilities/ByteUtilities.cs index 4c79c4e..0e21453 100644 --- a/lang/cs/Org.Apache.REEF.Utilities/ByteUtilities.cs +++ b/lang/cs/Org.Apache.REEF.Utilities/ByteUtilities.cs @@ -34,6 +34,14 @@ namespace Org.Apache.REEF.Utilities } /// <summary> + /// Returns true if the byte array is null or empty. + /// </summary> + public static bool IsNullOrEmpty(byte[] bytes) + { + return bytes == null || bytes.Length == 0; + } + + /// <summary> /// Converts from a UTF-8 encoded byte array to a string. /// </summary> public static string ByteArraysToString(byte[] b)
