Repository: reef Updated Branches: refs/heads/master 48ade1b82 -> db685c756
[REEF-1240] Fix CanRunClrBridgeExampleOnLocalRuntime failure * Fix the behavior of LocalClient.SubmitAndGetJobStatus to start Java in * background * Add logging helper to async utils to log on failure of fire-and-forget * tasks JIRA: [REEF-1240](https://issues.apache.org/jira/browse/REEF-1240) Pull Request: This closes #879 Project: http://git-wip-us.apache.org/repos/asf/reef/repo Commit: http://git-wip-us.apache.org/repos/asf/reef/commit/db685c75 Tree: http://git-wip-us.apache.org/repos/asf/reef/tree/db685c75 Diff: http://git-wip-us.apache.org/repos/asf/reef/diff/db685c75 Branch: refs/heads/master Commit: db685c756e30fd7123a89423f269edf46dc1795e Parents: 48ade1b Author: Anupam <[email protected]> Authored: Mon Mar 7 19:48:06 2016 -0800 Committer: Markus Weimer <[email protected]> Committed: Tue Mar 8 14:09:42 2016 -0800 ---------------------------------------------------------------------- .../Org.Apache.REEF.Client/Local/LocalClient.cs | 3 +- .../AsyncUtils/LoggingHelper.cs | 45 ++++++++++++++++++++ .../Org.Apache.Reef.Utilities.csproj | 1 + 3 files changed, 48 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/reef/blob/db685c75/lang/cs/Org.Apache.REEF.Client/Local/LocalClient.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Client/Local/LocalClient.cs b/lang/cs/Org.Apache.REEF.Client/Local/LocalClient.cs index 782b664..c2d3db6 100644 --- a/lang/cs/Org.Apache.REEF.Client/Local/LocalClient.cs +++ b/lang/cs/Org.Apache.REEF.Client/Local/LocalClient.cs @@ -30,6 +30,7 @@ using Org.Apache.REEF.Common.Avro; using Org.Apache.REEF.Common.Files; using Org.Apache.REEF.Tang.Annotations; using Org.Apache.REEF.Tang.Implementations.Tang; +using Org.Apache.REEF.Utilities.AsyncUtils; using Org.Apache.REEF.Utilities.Attributes; using Org.Apache.REEF.Utilities.Logging; using Org.Apache.REEF.Wake.Remote.Parameters; @@ -169,7 +170,7 @@ namespace Org.Apache.REEF.Client.Local var submissionAppArgsFilePath = CreateBootstrapAvroAppConfig(jobRequest.AppParameters, driverFolder); _javaClientLauncher.LaunchAsync(JavaClassName, submissionJobArgsFilePath, submissionAppArgsFilePath) - .GetAwaiter().GetResult(); + .LogAndIgnoreExceptionIfAny(Logger, "Java launcher failed"); var fileName = Path.Combine(driverFolder, _fileNames.DriverHttpEndpoint); JobSubmissionResult result = new LocalJobSubmissionResult(this, fileName); http://git-wip-us.apache.org/repos/asf/reef/blob/db685c75/lang/cs/Org.Apache.REEF.Utilities/AsyncUtils/LoggingHelper.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Utilities/AsyncUtils/LoggingHelper.cs b/lang/cs/Org.Apache.REEF.Utilities/AsyncUtils/LoggingHelper.cs new file mode 100644 index 0000000..b17de6b --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Utilities/AsyncUtils/LoggingHelper.cs @@ -0,0 +1,45 @@ +// 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.Threading.Tasks; +using Org.Apache.REEF.Utilities.Logging; + +namespace Org.Apache.REEF.Utilities.AsyncUtils +{ + /// <summary> + /// Logging helpers for TPL + /// </summary> + public static class LoggingHelper + { + /// <summary> + /// Logs the and then ignores the exceptions thrown from the task if any. + /// </summary> + /// <param name="self">The task itself</param> + /// <param name="logger">Logger to log against</param> + /// <param name="msg">Optional message to be included</param> + /// <param name="logLevel">Optional parameter to set log level</param> + public static void LogAndIgnoreExceptionIfAny(this Task self, Logger logger, string msg = "", Level logLevel = Level.Error) + { + self.ContinueWith(t => + { + // ReSharper disable once PossibleNullReferenceException ; We know the task is Faulted + logger.Log(logLevel, "{0} Exception:{1}", t.Exception.GetBaseException()); + }, + TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/reef/blob/db685c75/lang/cs/Org.Apache.REEF.Utilities/Org.Apache.Reef.Utilities.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Utilities/Org.Apache.Reef.Utilities.csproj b/lang/cs/Org.Apache.REEF.Utilities/Org.Apache.Reef.Utilities.csproj index 910e10c..50d5851 100644 --- a/lang/cs/Org.Apache.REEF.Utilities/Org.Apache.Reef.Utilities.csproj +++ b/lang/cs/Org.Apache.REEF.Utilities/Org.Apache.Reef.Utilities.csproj @@ -37,6 +37,7 @@ under the License. <Reference Include="System.Core" /> </ItemGroup> <ItemGroup> + <Compile Include="AsyncUtils\LoggingHelper.cs" /> <Compile Include="AsyncUtils\RemoveSynchronizationContextAwaiter.cs" /> <Compile Include="AsyncUtils\VoidResult.cs" /> <Compile Include="Attributes\ClientSideAttribute.cs" />
