Repository: reef Updated Branches: refs/heads/master 12daaba3b -> 407041dcd
[REEF-1172] Correct deprecation of ContextConfiguration for RootContext This addressed the issue by * Support RootContext backward compatibility. * Remove backward compatibility support for context stacking. JIRA: [REEF-1172](https://issues.apache.org/jira/browse/REEF-1172) This closes #809 Project: http://git-wip-us.apache.org/repos/asf/reef/repo Commit: http://git-wip-us.apache.org/repos/asf/reef/commit/407041dc Tree: http://git-wip-us.apache.org/repos/asf/reef/tree/407041dc Diff: http://git-wip-us.apache.org/repos/asf/reef/diff/407041dc Branch: refs/heads/master Commit: 407041dcdfda5de1f260297452b306df4420c037 Parents: 12daaba Author: Andrew Chung <[email protected]> Authored: Fri Jan 29 13:18:06 2016 -0800 Committer: Julia Wang <[email protected]> Committed: Sat Jan 30 19:52:09 2016 -0800 ---------------------------------------------------------------------- .../Runtime/Evaluator/Context/ContextManager.cs | 14 +--- .../Runtime/Evaluator/Context/ContextRuntime.cs | 80 ++++++-------------- .../Evaluator/Context/RootContextLauncher.cs | 17 ++++- .../Runtime/Evaluator/EvaluatorSettings.cs | 37 ++++++++- 4 files changed, 74 insertions(+), 74 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/reef/blob/407041dc/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/ContextManager.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/ContextManager.cs b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/ContextManager.cs index 70316a7..520dce9 100644 --- a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/ContextManager.cs +++ b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/ContextManager.cs @@ -51,8 +51,9 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context { _heartBeatManager = heartBeatManager; _serializer = serializer; + _rootContextLauncher = new RootContextLauncher( - evaluatorSettings.RootContextConfig.Id, + evaluatorSettings.RootContextId, evaluatorSettings.RootContextConfig, evaluatorSettings.RootServiceConfiguration, evaluatorSettings.RootTaskConfiguration); @@ -283,16 +284,7 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context Utilities.Diagnostics.Exceptions.Throw(e, LOGGER); } - IConfiguration contextConfiguration; - try - { - contextConfiguration = _serializer.FromString(addContextProto.context_configuration); - } - catch (Exception) - { - // TODO[JIRA REEF-1167]: Remove the catch. - contextConfiguration = new ContextConfiguration(addContextProto.context_configuration); - } + var contextConfiguration = _serializer.FromString(addContextProto.context_configuration); ContextRuntime newTopContext; if (addContextProto.service_configuration != null) http://git-wip-us.apache.org/repos/asf/reef/blob/407041dc/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/ContextRuntime.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/ContextRuntime.cs b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/ContextRuntime.cs index 5ec7564..953e1cd 100644 --- a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/ContextRuntime.cs +++ b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/ContextRuntime.cs @@ -55,44 +55,6 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context /// <summary> /// Create a new ContextRuntime. /// </summary> - /// <param name="id">ID of the context</param> - /// <param name="serviceInjector"></param> - /// <param name="contextConfiguration">the Configuration for this context.</param> - /// <param name="parentContext"></param> - /// TODO[JIRA REEF-1167]: Remove constructor. - [Obsolete("Deprecated in 0.14, will be removed.")] - public ContextRuntime( - string id, - IInjector serviceInjector, - IConfiguration contextConfiguration, - Optional<ContextRuntime> parentContext) - { - _contextLifeCycle = new ContextLifeCycle(id); - _serviceInjector = serviceInjector; - _parentContext = parentContext; - try - { - _contextInjector = serviceInjector.ForkInjector(); - } - catch (Exception e) - { - Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER); - - Optional<string> parentId = ParentContext.IsPresent() ? - Optional<string>.Of(ParentContext.Value.Id) : - Optional<string>.Empty(); - ContextClientCodeException ex = new ContextClientCodeException(ContextClientCodeException.GetId(contextConfiguration), parentId, "Unable to spawn context", e); - - Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER); - } - - // Trigger the context start events on contextInjector. - _contextLifeCycle.Start(); - } - - /// <summary> - /// Create a new ContextRuntime. - /// </summary> /// <param name="serviceInjector"></param> /// <param name="contextConfiguration">the Configuration for this context.</param> /// <param name="parentContext"></param> @@ -120,9 +82,30 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context string id, IInjector serviceInjector, IConfiguration contextConfiguration) - : this(id, serviceInjector, contextConfiguration, Optional<ContextRuntime>.Empty()) { + // This should only be used at the root context to support backward compatibility. LOGGER.Log(Level.Info, "Instantiating root context"); + _contextLifeCycle = new ContextLifeCycle(id); + _serviceInjector = serviceInjector; + _parentContext = Optional<ContextRuntime>.Empty(); + try + { + _contextInjector = serviceInjector.ForkInjector(); + } + catch (Exception e) + { + Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER); + + Optional<string> parentId = ParentContext.IsPresent() ? + Optional<string>.Of(ParentContext.Value.Id) : + Optional<string>.Empty(); + ContextClientCodeException ex = new ContextClientCodeException(ContextClientCodeException.GetId(contextConfiguration), parentId, "Unable to spawn context", e); + + Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER); + } + + // Trigger the context start events on contextInjector. + _contextLifeCycle.Start(); } public string Id @@ -135,18 +118,6 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context get { return _parentContext; } } - private static ContextRuntime GetChildContextRuntime(IInjector childServiceInjector, IConfiguration childContextConfiguration, ContextRuntime parentRuntime) - { - // TODO[JIRA REEF-1167]: Remove the cast and branch. - var actualContextConfiguration = childContextConfiguration as ContextConfiguration; - if (actualContextConfiguration == null) - { - return new ContextRuntime(childServiceInjector, childContextConfiguration, Optional<ContextRuntime>.Of(parentRuntime)); - } - - return new ContextRuntime(actualContextConfiguration.Id, childServiceInjector, childContextConfiguration, Optional<ContextRuntime>.Of(parentRuntime)); - } - /// <summary> /// Spawns a new context. /// The new context will have a serviceInjector that is created by forking the one in this object with the given @@ -174,7 +145,7 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context try { var childServiceInjector = _serviceInjector.ForkInjector(childServiceConfiguration); - var childContext = GetChildContextRuntime(childServiceInjector, childContextConfiguration, this); + var childContext = new ContextRuntime(childServiceInjector, childContextConfiguration, Optional<ContextRuntime>.Of(this)); _childContext = Optional<ContextRuntime>.Of(childContext); return childContext; @@ -217,9 +188,8 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context Utilities.Diagnostics.Exceptions.Throw(e, LOGGER); } IInjector childServiceInjector = _serviceInjector.ForkInjector(); - ContextRuntime childContext = new ContextRuntime(childServiceInjector, childContextConfiguration, Optional<ContextRuntime>.Of(this)); - _childContext = Optional<ContextRuntime>.Of(childContext); - return childContext; + _childContext = Optional<ContextRuntime>.Of(new ContextRuntime(childServiceInjector, childContextConfiguration, Optional<ContextRuntime>.Of(this))); + return _childContext.Value; } } http://git-wip-us.apache.org/repos/asf/reef/blob/407041dc/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/RootContextLauncher.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/RootContextLauncher.cs b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/RootContextLauncher.cs index c7dfece..775da51 100644 --- a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/RootContextLauncher.cs +++ b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/RootContextLauncher.cs @@ -56,8 +56,17 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context { if (_rootContext == null) { - // TODO[JIRA REEF-1167]: Remove use of this constructor. - _rootContext = new ContextRuntime(Id, _rootServiceInjector, _rootContextConfiguration); + // TODO[JIRA REEF-1167]: Remove use of deprecated ContextRuntime constructor and deprecatedContextConfiguration + var deprecatedContextConfiguration = _rootContextConfiguration as ContextConfiguration; + if (deprecatedContextConfiguration != null) + { + LOGGER.Log(Level.Info, "Using deprecated ContextConfiguration."); + _rootContext = new ContextRuntime(Id, _rootServiceInjector, _rootContextConfiguration); + } + else + { + _rootContext = new ContextRuntime(_rootServiceInjector, _rootContextConfiguration, Optional<ContextRuntime>.Empty()); + } } return _rootContext; } @@ -76,9 +85,9 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context } catch (Exception e) { - Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, "Failed to instantiate service.", LOGGER); + Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, "Failed to instantiate service.", LOGGER); InvalidOperationException ex = new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Failed to inject service: encoutned error {1} with message [{0}] and stack trace:[{1}]", e, e.Message, e.StackTrace)); - Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER); + Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER); } LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "injected {0} service(s)", services.Services.Count)); } http://git-wip-us.apache.org/repos/asf/reef/blob/407041dc/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/EvaluatorSettings.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/EvaluatorSettings.cs b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/EvaluatorSettings.cs index d639dd2..fe331da 100644 --- a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/EvaluatorSettings.cs +++ b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/EvaluatorSettings.cs @@ -16,6 +16,7 @@ // under the License. using System; +using Org.Apache.REEF.Common.Context; using Org.Apache.REEF.Common.Evaluator; using Org.Apache.REEF.Common.Io; using Org.Apache.REEF.Common.Protobuf.ReefProtocol; @@ -26,6 +27,7 @@ using Org.Apache.REEF.Common.Services; using Org.Apache.REEF.Common.Tasks; using Org.Apache.REEF.Tang.Annotations; using Org.Apache.REEF.Tang.Exceptions; +using Org.Apache.REEF.Tang.Formats; using Org.Apache.REEF.Tang.Interface; using Org.Apache.REEF.Utilities; using Org.Apache.REEF.Utilities.Logging; @@ -41,12 +43,14 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator private readonly string _applicationId; private readonly string _evaluatorId; + private readonly string _rootContextId; private readonly int _heartBeatPeriodInMs; private readonly int _maxHeartbeatRetries; private readonly IClock _clock; private readonly IRemoteManager<REEFMessage> _remoteManager; private readonly IInjector _injector; - private readonly ContextConfiguration _rootContextConfig; + private readonly IConfiguration _rootContextConfig; + private readonly AvroConfigurationSerializer _serializer; private readonly Optional<TaskConfiguration> _rootTaskConfiguration; private readonly Optional<ServiceConfiguration> _rootServiceConfiguration; @@ -61,6 +65,7 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator /// <param name="heartbeatPeriodInMs"></param> /// <param name="maxHeartbeatRetries"></param> /// <param name="rootContextConfigString"></param> + /// <param name="serializer"></param> /// <param name="clock"></param> /// <param name="remoteManagerFactory"></param> /// <param name="reefMessageCodec"></param> @@ -72,11 +77,13 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator [Parameter(typeof(EvaluatorHeartbeatPeriodInMs))] int heartbeatPeriodInMs, [Parameter(typeof(HeartbeatMaxRetry))] int maxHeartbeatRetries, [Parameter(typeof(RootContextConfiguration))] string rootContextConfigString, + AvroConfigurationSerializer serializer, RuntimeClock clock, IRemoteManagerFactory remoteManagerFactory, REEFMessageCodec reefMessageCodec, IInjector injector) { + _serializer = serializer; _injector = injector; _applicationId = applicationId; _evaluatorId = evaluatorId; @@ -89,7 +96,22 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator Utilities.Diagnostics.Exceptions.Throw( new ArgumentException("empty or null rootContextConfigString"), Logger); } - _rootContextConfig = new ContextConfiguration(rootContextConfigString); + _rootContextConfig = _serializer.FromString(rootContextConfigString); + + try + { + _rootContextId = injector.ForkInjector(_rootContextConfig).GetNamedInstance<ContextConfigurationOptions.ContextIdentifier, string>(); + } + catch (InjectionException) + { + Logger.Log(Level.Info, "Using deprecated ContextConfiguration."); + + // TODO[JIRA REEF-1167]: Remove this catch. + var deprecatedContextConfig = new Context.ContextConfiguration(rootContextConfigString); + _rootContextConfig = deprecatedContextConfig; + _rootContextId = deprecatedContextConfig.Id; + } + _rootTaskConfiguration = CreateTaskConfiguration(); _rootServiceConfiguration = CreateRootServiceConfiguration(); @@ -125,6 +147,14 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator } /// <summary> + /// Returns the root context ID. + /// </summary> + public string RootContextId + { + get { return _rootContextId; } + } + + /// <summary> /// Return HeartBeatPeriodInMs from NamedParameter /// </summary> public int HeartBeatPeriodInMs @@ -160,8 +190,7 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator /// <summary> /// return Root Context Configuration passed from Evaluator configuration /// </summary> - /// TODO[JIRA REEF-1167]: Change this to use IConfiguration. - public ContextConfiguration RootContextConfig + public IConfiguration RootContextConfig { get { return _rootContextConfig; } }
