Repository: reef Updated Branches: refs/heads/master 02bfc2f4f -> 771b34bd2
[REEF-1367] Write a PID file in the REEF.NET Evaluator This adds `PIDStoreHandler` and calls it from `EvaluatorRuntime`. JIRA: [REEF-1367](https://issues.apache.org/jira/browse/REEF-1367) Pull Request: This closes #976 Project: http://git-wip-us.apache.org/repos/asf/reef/repo Commit: http://git-wip-us.apache.org/repos/asf/reef/commit/771b34bd Tree: http://git-wip-us.apache.org/repos/asf/reef/tree/771b34bd Diff: http://git-wip-us.apache.org/repos/asf/reef/diff/771b34bd Branch: refs/heads/master Commit: 771b34bd24a358784ec4d24a907fecae39701220 Parents: 02bfc2f Author: Boris Shulman <[email protected]> Authored: Thu Apr 28 09:29:10 2016 -0700 Committer: Markus Weimer <[email protected]> Committed: Thu Apr 28 14:04:33 2016 -0700 ---------------------------------------------------------------------- .../Files/REEFFileNames.cs | 10 +++ .../Org.Apache.REEF.Common.csproj | 1 + .../Runtime/Evaluator/EvaluatorRuntime.cs | 7 +- .../Runtime/Evaluator/PIDStoreHandler.cs | 79 ++++++++++++++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/reef/blob/771b34bd/lang/cs/Org.Apache.REEF.Common/Files/REEFFileNames.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Files/REEFFileNames.cs b/lang/cs/Org.Apache.REEF.Common/Files/REEFFileNames.cs index 872ff59..3b625ac 100644 --- a/lang/cs/Org.Apache.REEF.Common/Files/REEFFileNames.cs +++ b/lang/cs/Org.Apache.REEF.Common/Files/REEFFileNames.cs @@ -60,6 +60,7 @@ namespace Org.Apache.REEF.Common.Files private const string YARN_DRIVER_STDOUT_PATH = YARN_DEFAULT_DRIVER_OUT_VAR + "/driver.stdout"; private const string YARN_DRIVER_STDERR_PATH = YARN_DEFAULT_DRIVER_OUT_VAR + "/driver.stderr"; private const string DRIVER_COMMAND_LOGGING_CONFIG = "1> <LOG_DIR>/driver.stdout 2> <LOG_DIR>/driver.stderr"; + private const string PID_FILE_NAME = "PID.txt"; [Inject] public REEFFileNames() @@ -326,6 +327,15 @@ namespace Org.Apache.REEF.Common.Files } /// <summary> + /// The file name of the PID file created in the current working directory of the process. + /// This is similar to the file name in the PIDStoreHandler.java + /// </summary> + public string GetPidFileName() + { + return PID_FILE_NAME; + } + + /// <summary> /// </summary> /// <returns>File name that contains the dfs path for the DriverHttpEndpoint</returns> [Unstable("0.13", "Working in progress for what to return after submit")] http://git-wip-us.apache.org/repos/asf/reef/blob/771b34bd/lang/cs/Org.Apache.REEF.Common/Org.Apache.REEF.Common.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Org.Apache.REEF.Common.csproj b/lang/cs/Org.Apache.REEF.Common/Org.Apache.REEF.Common.csproj index b754583..3807a7f 100644 --- a/lang/cs/Org.Apache.REEF.Common/Org.Apache.REEF.Common.csproj +++ b/lang/cs/Org.Apache.REEF.Common/Org.Apache.REEF.Common.csproj @@ -154,6 +154,7 @@ under the License. <Compile Include="Runtime\Evaluator\IHeartBeatManager.cs" /> <Compile Include="Runtime\Evaluator\Parameters\EvaluatorHeartbeatPeriodInMs.cs" /> <Compile Include="Runtime\Evaluator\Parameters\HeartbeatMaxRetry.cs" /> + <Compile Include="Runtime\Evaluator\PIDStoreHandler.cs" /> <Compile Include="Runtime\Evaluator\ReefMessageProtoObserver.cs" /> <Compile Include="Runtime\Evaluator\Task\CloseEventImpl.cs" /> <Compile Include="Runtime\Evaluator\Task\DriverMessageImpl.cs" /> http://git-wip-us.apache.org/repos/asf/reef/blob/771b34bd/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/EvaluatorRuntime.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/EvaluatorRuntime.cs b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/EvaluatorRuntime.cs index 495b2c2..5c0b25a 100644 --- a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/EvaluatorRuntime.cs +++ b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/EvaluatorRuntime.cs @@ -39,10 +39,13 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator private State _state = State.INIT; + private PIDStoreHandler _pidStoreHelper; + [Inject] public EvaluatorRuntime( ContextManager contextManager, - IHeartBeatManager heartBeatManager) + IHeartBeatManager heartBeatManager, + PIDStoreHandler pidStoreHelper) { using (Logger.LogFunction("EvaluatorRuntime::EvaluatorRuntime")) { @@ -50,6 +53,7 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator _clock = _heartBeatManager.EvaluatorSettings.RuntimeClock; _contextManager = contextManager; _evaluatorId = _heartBeatManager.EvaluatorSettings.EvalutorId; + _pidStoreHelper = pidStoreHelper; var remoteManager = _heartBeatManager.EvaluatorSettings.RemoteManager; ReefMessageProtoObserver driverObserver = new ReefMessageProtoObserver(); @@ -152,6 +156,7 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator try { Logger.Log(Level.Info, "Runtime start"); + _pidStoreHelper.WritePID(); if (_state != State.INIT) { var e = new InvalidOperationException("State should be init."); http://git-wip-us.apache.org/repos/asf/reef/blob/771b34bd/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/PIDStoreHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/PIDStoreHandler.cs b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/PIDStoreHandler.cs new file mode 100644 index 0000000..51282c4 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/PIDStoreHandler.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 System.Diagnostics; +using System.IO; + +using Org.Apache.REEF.Common.Files; +using Org.Apache.REEF.Tang.Annotations; +using Org.Apache.REEF.Utilities.Logging; + +namespace Org.Apache.REEF.Common.Runtime.Evaluator +{ + /// <summary> + /// A PID store handler for c# evaluator + /// </summary> + internal sealed class PIDStoreHandler + { + private static readonly Logger Logger = Logger.GetLogger(typeof(PIDStoreHandler)); + + private readonly object _lockObject = new object(); + + private readonly REEFFileNames _reefFileNames; + + private bool _pidIsWritten = false; + + [Inject] + private PIDStoreHandler(REEFFileNames reefFileNames) + { + _reefFileNames = reefFileNames; + } + + /// <summary> + /// Writes PID to the runtime folder + /// </summary> + internal void WritePID() + { + lock (_lockObject) + { + if (!_pidIsWritten) + { + string currentDirectory = Directory.GetCurrentDirectory(); + string path = Path.Combine(currentDirectory, _reefFileNames.GetPidFileName()); + + try + { + var pid = Process.GetCurrentProcess().Id; + using (StreamWriter sw = File.CreateText(path)) + { + sw.WriteLine(pid); + sw.Flush(); + } + + Logger.Log(Level.Verbose, "Writing PID {0} to file {1}", pid, path); + _pidIsWritten = true; + } + catch (IOException e) + { + Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, Logger); + } + } + } + } + } +}
