Repository: incubator-reef Updated Branches: refs/heads/master 0f632ca86 -> 0549aca0b
[REEF-336] Change StartHandler This addressed the issue deprecating IStartHandler and adding IObserver<DateTime> for StartHandler JIRA: [REEF-336](https://issues.apache.org/jira/browse/REEF-336) Pull Request: This closes #200 Project: http://git-wip-us.apache.org/repos/asf/incubator-reef/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-reef/commit/0549aca0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-reef/tree/0549aca0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-reef/diff/0549aca0 Branch: refs/heads/master Commit: 0549aca0b05ff730262d04c1ba2fbaf984f177ee Parents: 0f632ca Author: Beysim Sezgin <[email protected]> Authored: Tue Jun 2 16:36:49 2015 -0700 Committer: Markus Weimer <[email protected]> Committed: Wed Jun 3 14:54:34 2015 +1000 ---------------------------------------------------------------------- .../Bridge/ClrSystemHandlerWrapper.cs | 14 ++--- .../Bridge/DriverBridge.cs | 18 ++++++- .../Bridge/DriverBridgeConfiguration.cs | 10 +++- .../Bridge/DriverBridgeConfigurationOptions.cs | 8 ++- .../Defaults/DefaultDriverStartHandler.cs | 54 ++++++++++++++++++++ .../DefaultObsoleteDriverStartHandler.cs | 41 +++++++++++++++ lang/cs/Org.Apache.REEF.Driver/IStartHandler.cs | 8 +++ .../Org.Apache.REEF.Driver.csproj | 2 + .../HelloDriver.cs | 21 ++++++-- .../HelloREEF.cs | 2 +- 10 files changed, 163 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/0549aca0/lang/cs/Org.Apache.REEF.Driver/Bridge/ClrSystemHandlerWrapper.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/Bridge/ClrSystemHandlerWrapper.cs b/lang/cs/Org.Apache.REEF.Driver/Bridge/ClrSystemHandlerWrapper.cs index 66b44b7..c6e07c6 100644 --- a/lang/cs/Org.Apache.REEF.Driver/Bridge/ClrSystemHandlerWrapper.cs +++ b/lang/cs/Org.Apache.REEF.Driver/Bridge/ClrSystemHandlerWrapper.cs @@ -30,9 +30,6 @@ using Org.Apache.REEF.Driver.Bridge.Events; using Org.Apache.REEF.Driver.Context; using Org.Apache.REEF.Driver.Evaluator; using Org.Apache.REEF.Driver.Task; -using Org.Apache.REEF.Tang.Formats; -using Org.Apache.REEF.Tang.Implementations.Tang; -using Org.Apache.REEF.Tang.Interface; using Org.Apache.REEF.Utilities.Diagnostics; using Org.Apache.REEF.Utilities.Logging; using Org.Apache.REEF.Wake.Time.Event; @@ -251,7 +248,11 @@ namespace Org.Apache.REEF.Driver.Bridge { LOGGER.Log(Level.Info, "*** Start time is " + startTime); LOGGER.Log(Level.Info, "*** httpServerPort: " + httpServerPort); - return GetHandlers(httpServerPort, evaluatorRequestor); + var handlers = GetHandlers(httpServerPort, evaluatorRequestor); + _driverBridge.StartHandlersOnNext(startTime); + _driverBridge.ObsoleteEvaluatorRequestorOnNext(evaluatorRequestor); + + return handlers; } } @@ -266,6 +267,7 @@ namespace Org.Apache.REEF.Driver.Bridge ? 0 : int.Parse(httpServerPortNumber, CultureInfo.InvariantCulture); + //TODO: Remove next 2 lines after Obsolete period var startHandler = injector.GetInstance<IStartHandler>(); LOGGER.Log(Level.Info, "Start handler set to be " + startHandler.Identifier); _driverBridge = injector.GetInstance<DriverBridge>(); @@ -275,9 +277,7 @@ namespace Org.Apache.REEF.Driver.Bridge Exceptions.CaughtAndThrow(e, Level.Error, "Cannot get instance.", LOGGER); } - var handles = _driverBridge.Subscribe(); - _driverBridge.ObsoleteEvaluatorRequestorOnNext(evaluatorRequestor); - return handles; + return _driverBridge.Subscribe(); } } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/0549aca0/lang/cs/Org.Apache.REEF.Driver/Bridge/DriverBridge.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/Bridge/DriverBridge.cs b/lang/cs/Org.Apache.REEF.Driver/Bridge/DriverBridge.cs index c8c4d59..dd6b443 100644 --- a/lang/cs/Org.Apache.REEF.Driver/Bridge/DriverBridge.cs +++ b/lang/cs/Org.Apache.REEF.Driver/Bridge/DriverBridge.cs @@ -70,6 +70,8 @@ namespace Org.Apache.REEF.Driver.Bridge private static ClrSystemHandler<StartTime> _driverRestartSubscriber; + private readonly ISet<IObserver<DateTime>> _driverStartHandlers; + private readonly IObserver<StartTime> _driverRestartHandler; private readonly ISet<IObserver<IEvaluatorRequestor>> _evaluatorRequestHandlers; @@ -108,6 +110,7 @@ namespace Org.Apache.REEF.Driver.Bridge [Inject] public DriverBridge( + [Parameter(Value = typeof(DriverBridgeConfigurationOptions.DriverStartHandlers))] ISet<IObserver<DateTime>> driverStartHandlers, [Parameter(Value = typeof(DriverBridgeConfigurationOptions.DriverRestartHandler))] IObserver<StartTime> driverRestartHandler, [Parameter(Value = typeof(DriverBridgeConfigurationOptions.EvaluatorRequestHandlers))] ISet<IObserver<IEvaluatorRequestor>> evaluatorRequestHandlers, [Parameter(Value = typeof(DriverBridgeConfigurationOptions.AllocatedEvaluatorHandlers))] ISet<IObserver<IAllocatedEvaluator>> allocatedEvaluatorHandlers, @@ -145,7 +148,8 @@ namespace Org.Apache.REEF.Driver.Bridge { Logger.SetCustomLevel(level); } - + + _driverStartHandlers = driverStartHandlers; _evaluatorRequestHandlers = evaluatorRequestHandlers; _allocatedEvaluatorHandlers = allocatedEvaluatorHandlers; _activeContextHandlers = activeContextHandlers; @@ -322,6 +326,18 @@ namespace Org.Apache.REEF.Driver.Bridge } } + /// <summary> + /// Call start handlers + /// </summary> + internal void StartHandlersOnNext(DateTime startTime) + { + foreach (var handler in _driverStartHandlers) + { + handler.OnNext(startTime); + _logger.Log(Level.Info, "called OnDriverStart handler: " + handler); + } + } + internal ISet<IConfigurationProvider> ConfigurationProviders { get { return _configurationProviders; } } } } http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/0549aca0/lang/cs/Org.Apache.REEF.Driver/Bridge/DriverBridgeConfiguration.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/Bridge/DriverBridgeConfiguration.cs b/lang/cs/Org.Apache.REEF.Driver/Bridge/DriverBridgeConfiguration.cs index 249466a..f1029d4 100644 --- a/lang/cs/Org.Apache.REEF.Driver/Bridge/DriverBridgeConfiguration.cs +++ b/lang/cs/Org.Apache.REEF.Driver/Bridge/DriverBridgeConfiguration.cs @@ -43,7 +43,14 @@ namespace Org.Apache.REEF.Driver.Bridge /// The event handler invoked right after the driver boots up. /// </summary> [SuppressMessage("Microsoft.Security", "CA2104:Do not declare read only mutable reference types", Justification = "not applicable")] - public static readonly RequiredImpl<IStartHandler> OnDriverStarted = new RequiredImpl<IStartHandler>(); + [Obsolete("Use OnDriverStart instead. Please see Jira REEF-336. Obsoleted v0.12 and will be removed v0.13", false)] + public static readonly OptionalImpl<IStartHandler> OnDriverStarted = new OptionalImpl<IStartHandler>(); + + /// <summary> + /// The event handler called on driver start + /// </summary> + [SuppressMessage("Microsoft.Security", "CA2104:Do not declare read only mutable reference types", Justification = "not applicable")] + public static readonly OptionalImpl<IObserver<DateTime>> OnDriverStart = new OptionalImpl<IObserver<DateTime>>(); /// <summary> /// The event handler invoked when driver restarts @@ -206,6 +213,7 @@ namespace Org.Apache.REEF.Driver.Bridge .BindImplementation(GenericType<IStartHandler>.Class, OnDriverStarted) .BindNamedParameter(GenericType<DriverBridgeConfigurationOptions.DriverRestartHandler>.Class, OnDriverRestarted) .BindImplementation(GenericType<IDriverConnection>.Class, OnDriverReconnect) + .BindSetEntry(GenericType<DriverBridgeConfigurationOptions.DriverStartHandlers>.Class, OnDriverStart) .BindSetEntry(GenericType<DriverBridgeConfigurationOptions.EvaluatorRequestHandlers>.Class, OnEvaluatorRequested) .BindSetEntry(GenericType<DriverBridgeConfigurationOptions.AllocatedEvaluatorHandlers>.Class, OnEvaluatorAllocated) .BindSetEntry(GenericType<DriverBridgeConfigurationOptions.ActiveContextHandlers>.Class, OnContextActive) http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/0549aca0/lang/cs/Org.Apache.REEF.Driver/Bridge/DriverBridgeConfigurationOptions.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/Bridge/DriverBridgeConfigurationOptions.cs b/lang/cs/Org.Apache.REEF.Driver/Bridge/DriverBridgeConfigurationOptions.cs index 14aed94..bbf7172 100644 --- a/lang/cs/Org.Apache.REEF.Driver/Bridge/DriverBridgeConfigurationOptions.cs +++ b/lang/cs/Org.Apache.REEF.Driver/Bridge/DriverBridgeConfigurationOptions.cs @@ -41,12 +41,18 @@ namespace Org.Apache.REEF.Driver.Bridge // Level.Verbose (since enum is not suppoted for TANG, we use a string here) private const string _verboseLevel = "Verbose"; + // There is not supposed to be a default for Start handler but we need to provide one because all the existing apps would break; + [NamedParameter(documentation: "Called when driver is started, after CLR bridge is set up.", defaultClasses: new[] { typeof(DefaultDriverStartHandler) })] + public class DriverStartHandlers : Name<ISet<IObserver<DateTime>>> + { + } + [NamedParameter(documentation: "Called when driver is restarted, after CLR bridge is set up.", defaultClasses: new[] { typeof(DefaultDriverRestartHandler) })] public class DriverRestartHandler : Name<IObserver<StartTime>> { } - [NamedParameter(documentation: "Called when evaluator is requested.", defaultClasses: new[] { typeof(DefaultEvaluatorRequestorHandler) })] + [NamedParameter(documentation: "Called when evaluator is requested.")] public class EvaluatorRequestHandlers : Name<ISet<IObserver<IEvaluatorRequestor>>> { } http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/0549aca0/lang/cs/Org.Apache.REEF.Driver/Defaults/DefaultDriverStartHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/Defaults/DefaultDriverStartHandler.cs b/lang/cs/Org.Apache.REEF.Driver/Defaults/DefaultDriverStartHandler.cs new file mode 100644 index 0000000..8d94941 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Driver/Defaults/DefaultDriverStartHandler.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; +using Org.Apache.REEF.Tang.Annotations; +using Org.Apache.REEF.Utilities.Logging; +using Org.Apache.REEF.Wake.Time.Event; + +namespace Org.Apache.REEF.Driver.Defaults +{ + /// <summary> + /// Default event handler for driver start: Logging it. + /// </summary> + public class DefaultDriverStartHandler : IObserver<DateTime> + { + private static readonly Logger LOGGER = Logger.GetLogger(typeof(DefaultDriverStartHandler)); + + [Inject] + public DefaultDriverStartHandler() + { + } + + public void OnNext(DateTime startTime) + { + LOGGER.Log(Level.Info, "Driver started at" + startTime); + } + + 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/0549aca0/lang/cs/Org.Apache.REEF.Driver/Defaults/DefaultObsoleteDriverStartHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/Defaults/DefaultObsoleteDriverStartHandler.cs b/lang/cs/Org.Apache.REEF.Driver/Defaults/DefaultObsoleteDriverStartHandler.cs new file mode 100644 index 0000000..1f1d49c --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Driver/Defaults/DefaultObsoleteDriverStartHandler.cs @@ -0,0 +1,41 @@ +/** + * 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; + +namespace Org.Apache.REEF.Driver.Defaults +{ + /// <summary> + /// Default event handler for driver start: Logging it. + /// </summary> + [Obsolete( + "Implement IObserver<DateTime> instead. Please see Jira REEF-336. Obsoleted v0.12 and will be removed v0.13", + false)] + public class DefaultObsoleteDriverStartHandler : IStartHandler + { + [Inject] + public DefaultObsoleteDriverStartHandler() + { + Identifier = "DefaultObsoleteDriverStartHandler"; + } + + public string Identifier { get; set; } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/0549aca0/lang/cs/Org.Apache.REEF.Driver/IStartHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/IStartHandler.cs b/lang/cs/Org.Apache.REEF.Driver/IStartHandler.cs index 0f03295..5dd7bea 100644 --- a/lang/cs/Org.Apache.REEF.Driver/IStartHandler.cs +++ b/lang/cs/Org.Apache.REEF.Driver/IStartHandler.cs @@ -17,8 +17,16 @@ * under the License. */ +using System; +using Org.Apache.REEF.Driver.Defaults; +using Org.Apache.REEF.Tang.Annotations; + namespace Org.Apache.REEF.Driver { + [DefaultImplementation(typeof(DefaultObsoleteDriverStartHandler))] + [Obsolete( + "Implement IObserver<DateTime> instead. Please see Jira REEF-336. Obsoleted v0.12 and will be removed v0.13", + false)] public interface IStartHandler { string Identifier { get; set; } http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/0549aca0/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 692f39d..b334930 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 @@ -106,11 +106,13 @@ under the License. <Compile Include="Defaults\DefaultDriverRestartContextActiveHandler.cs" /> <Compile Include="Defaults\DefaultDriverRestartHandler.cs" /> <Compile Include="Defaults\DefaultDriverRestartTaskRunningHandler.cs" /> + <Compile Include="Defaults\DefaultDriverStartHandler.cs" /> <Compile Include="Defaults\DefaultEvaluatorAllocationHandler.cs" /> <Compile Include="Defaults\DefaultEvaluatorCompletionHandler.cs" /> <Compile Include="Defaults\DefaultEvaluatorFailureHandler.cs" /> <Compile Include="Defaults\DefaultEvaluatorRequestorHandler.cs" /> <Compile Include="Defaults\DefaultHttpHandler.cs" /> + <Compile Include="Defaults\DefaultObsoleteDriverStartHandler.cs" /> <Compile Include="Defaults\DefaultTaskCompletionHandler.cs" /> <Compile Include="Defaults\DefaultTaskFailureHandler.cs" /> <Compile Include="Defaults\DefaultTaskMessageHandler.cs" /> http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/0549aca0/lang/cs/Org.Apache.REEF.Examples.HelloREEF/HelloDriver.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Examples.HelloREEF/HelloDriver.cs b/lang/cs/Org.Apache.REEF.Examples.HelloREEF/HelloDriver.cs index 3bd1ba8..34a25a8 100644 --- a/lang/cs/Org.Apache.REEF.Examples.HelloREEF/HelloDriver.cs +++ b/lang/cs/Org.Apache.REEF.Examples.HelloREEF/HelloDriver.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using Org.Apache.REEF.Common.Files; @@ -28,14 +29,17 @@ using Org.Apache.REEF.Driver.Evaluator; using Org.Apache.REEF.Tang.Annotations; using Org.Apache.REEF.Tang.Interface; using Org.Apache.REEF.Tang.Util; +using Org.Apache.REEF.Utilities.Logging; namespace Org.Apache.REEF.Examples.HelloREEF { /// <summary> /// The Driver for HelloREEF: It requests a single Evaluator and then submits the HelloTask to it. /// </summary> - public sealed class HelloDriver : IObserver<IAllocatedEvaluator>, IStartHandler + public sealed class HelloDriver : IObserver<IAllocatedEvaluator>, IObserver<DateTime> { + private static readonly Logger _Logger = Logger.GetLogger(typeof(HelloDriver)); + /// <summary> /// Contexts contain configuration data used beyond a single task. /// </summary> @@ -53,13 +57,24 @@ namespace Org.Apache.REEF.Examples.HelloREEF .Build(); private readonly REEFFileNames _fileNames; + private readonly IEvaluatorRequestor _evaluatorRequestor; [Inject] private HelloDriver(REEFFileNames fileNames, IEvaluatorRequestor evaluatorRequestor) { _fileNames = fileNames; ClrHandlerHelper.GenerateClassHierarchy(GetGlobalAssemblies()); - evaluatorRequestor.Submit(new EvaluatorRequest(number: 1, megaBytes: 64)); + _evaluatorRequestor = evaluatorRequestor; + } + + /// <summary> + /// Called to start the user mode driver + /// </summary> + /// <param name="startTime"></param> + public void OnNext(DateTime startTime) + { + _Logger.Log(Level.Info, string.Format("HelloDriver started at {0}", startTime)); + _evaluatorRequestor.Submit(new EvaluatorRequest(number: 1, megaBytes: 64)); } /// <summary> @@ -80,8 +95,6 @@ namespace Org.Apache.REEF.Examples.HelloREEF { } - public string Identifier { get; set; } - /// <summary> /// </summary> /// <returns>All DLLs in the global folder</returns> http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/0549aca0/lang/cs/Org.Apache.REEF.Examples.HelloREEF/HelloREEF.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Examples.HelloREEF/HelloREEF.cs b/lang/cs/Org.Apache.REEF.Examples.HelloREEF/HelloREEF.cs index 41b0d35..dbc3379 100644 --- a/lang/cs/Org.Apache.REEF.Examples.HelloREEF/HelloREEF.cs +++ b/lang/cs/Org.Apache.REEF.Examples.HelloREEF/HelloREEF.cs @@ -55,7 +55,7 @@ namespace Org.Apache.REEF.Examples.HelloREEF // The driver configuration contains all the needed bindings. var helloDriverConfiguration = DriverBridgeConfiguration.ConfigurationModule .Set(DriverBridgeConfiguration.OnEvaluatorAllocated, GenericType<HelloDriver>.Class) - .Set(DriverBridgeConfiguration.OnDriverStarted, GenericType<HelloDriver>.Class) + .Set(DriverBridgeConfiguration.OnDriverStart, GenericType<HelloDriver>.Class) .Build(); // The JobSubmission contains the Driver configuration as well as the files needed on the Driver. var helloJobSubmission = _jobSubmissionBuilderFactory.GetJobSubmissionBuilder()
