Repository: reef Updated Branches: refs/heads/master 003e3e20e -> 12decb734
[REEF-1160] Deprecate O.A.R.Driver.ContextConfiguration and add O.A.R.Common.Context.ContextConfiguration This addressed the issue by * Deprecated O.A.R.Driver.ContextConfiguration (and options) and add O.A.R.Common.Context.ContextConfiguration (and options). * Added tests for currently the only functionality of ContextConfigurations -- allowing submission of Context IDs. * Deprecated default context handlers and created new classes for them in O.A.R.Common. JIRA: [REEF-1160](https://issues.apache.org/jira/browse/REEF-1160) Thia closes #799 Project: http://git-wip-us.apache.org/repos/asf/reef/repo Commit: http://git-wip-us.apache.org/repos/asf/reef/commit/12decb73 Tree: http://git-wip-us.apache.org/repos/asf/reef/tree/12decb73 Diff: http://git-wip-us.apache.org/repos/asf/reef/diff/12decb73 Branch: refs/heads/master Commit: 12decb7344edadb2972521f02cb20adcd3dba135 Parents: 003e3e2 Author: Andrew Chung <[email protected]> Authored: Tue Jan 26 15:35:51 2016 -0800 Committer: Julia Wang <[email protected]> Committed: Fri Jan 29 12:46:22 2016 -0800 ---------------------------------------------------------------------- .../Context/ContextConfiguration.cs | 92 ++++++++ .../Context/ContextConfigurationOptions.cs | 58 +++++ .../Defaults/DefaultContextMessageSource.cs | 35 +++ .../Defaults/DefaultContextStartHandler.cs | 46 ++++ .../Defaults/DefaultContextStopHandler.cs | 46 ++++ .../Org.Apache.REEF.Common.csproj | 5 + .../Evaluator/Context/ContextConfiguration.cs | 4 +- .../Evaluator/Context/ContextLifeCycle.cs | 18 +- .../Runtime/Evaluator/Context/ContextManager.cs | 30 ++- .../Runtime/Evaluator/Context/ContextRuntime.cs | 71 +++++-- .../Evaluator/Context/RootContextLauncher.cs | 50 +---- .../Runtime/Evaluator/EvaluatorSettings.cs | 1 + .../Bridge/Events/AllocatedEvaluator.cs | 5 +- .../Context/ContextConfiguration.cs | 2 + .../Context/ContextConfigurationOptions.cs | 5 +- .../Defaults/DefaultContextMessageSource.cs | 7 +- .../Defaults/DefaultContextStartHandler.cs | 8 +- .../Defaults/DefaultContextStopHandler.cs | 2 + .../HelloAllocatedEvaluatorHandler.cs | 2 +- .../Group/Driver/Impl/GroupCommDriver.cs | 1 + .../Bridge/HelloSimpleEventHandlers.cs | 2 +- .../Functional/Bridge/TestSimpleContext.cs | 211 +++++++++++++++++++ .../Functional/Messaging/MessageDriver.cs | 4 +- .../RuntimeName/EvaluatorRequestingDriver.cs | 3 +- .../Org.Apache.REEF.Tests.csproj | 1 + 25 files changed, 613 insertions(+), 96 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/lang/cs/Org.Apache.REEF.Common/Context/ContextConfiguration.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Context/ContextConfiguration.cs b/lang/cs/Org.Apache.REEF.Common/Context/ContextConfiguration.cs new file mode 100644 index 0000000..115dc4a --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/Context/ContextConfiguration.cs @@ -0,0 +1,92 @@ +// 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.CodeAnalysis; +using Org.Apache.REEF.Common.Events; +using Org.Apache.REEF.Common.Tasks; +using Org.Apache.REEF.Common.Tasks.Events; +using Org.Apache.REEF.Tang.Formats; +using Org.Apache.REEF.Tang.Util; +using Org.Apache.REEF.Utilities.Attributes; + +[module: SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "static field, typical usage in configurations")] + +namespace Org.Apache.REEF.Common.Context +{ + [ClientSide] + public sealed class ContextConfiguration : ConfigurationModuleBuilder + { + /// <summary> + /// The identifier of the context. + /// </summary> + [SuppressMessage("Microsoft.Security", "CA2104:Do not declare read only mutable reference types", Justification = "not applicable")] + public static readonly RequiredParameter<string> Identifier = new RequiredParameter<string>(); + + /// <summary> + /// for context start. Defaults to logging if not bound. + /// </summary> + [SuppressMessage("Microsoft.Security", "CA2104:Do not declare read only mutable reference types", Justification = "not applicable")] + public static readonly OptionalImpl<IObserver<IContextStart>> OnContextStart = new OptionalImpl<IObserver<IContextStart>>(); + + /// <summary> + /// for context stop. Defaults to logging if not bound. + /// </summary> + [SuppressMessage("Microsoft.Security", "CA2104:Do not declare read only mutable reference types", Justification = "not applicable")] + public static readonly OptionalImpl<IObserver<IContextStop>> OnContextStop = new OptionalImpl<IObserver<IContextStop>>(); + + /// <summary> + /// to be informed right before a Task enters its call() method. + /// </summary> + [SuppressMessage("Microsoft.Security", "CA2104:Do not declare read only mutable reference types", Justification = "not applicable")] + public static readonly OptionalImpl<IObserver<ITaskStart>> OnTaskStart = new OptionalImpl<IObserver<ITaskStart>>(); + + /// <summary> + /// to be informed right after a Task exits its call() method. + /// </summary> + [SuppressMessage("Microsoft.Security", "CA2104:Do not declare read only mutable reference types", Justification = "not applicable")] + public static readonly OptionalImpl<IObserver<ITaskStop>> OnTaskStop = new OptionalImpl<IObserver<ITaskStop>>(); + + /// <summary> + /// Source of messages to be called whenever the evaluator is about to make a heartbeat. + /// </summary> + [SuppressMessage("Microsoft.Security", "CA2104:Do not declare read only mutable reference types", Justification = "not applicable")] + public static readonly OptionalImpl<IContextMessageSource> OnSendMessage = new OptionalImpl<IContextMessageSource>(); + + /// <summary> + /// Driver has sent the context a message, and this parameter is used to register a handler on the context for processing that message. + /// </summary> + [SuppressMessage("Microsoft.Security", "CA2104:Do not declare read only mutable reference types", Justification = "not applicable")] + public static readonly OptionalImpl<IContextMessageHandler> OnMessage = new OptionalImpl<IContextMessageHandler>(); + + public static ConfigurationModule ConfigurationModule + { + get + { + return new ContextConfiguration() + .BindNamedParameter(GenericType<ContextConfigurationOptions.ContextIdentifier>.Class, Identifier) + .BindSetEntry(GenericType<ContextConfigurationOptions.StartHandlers>.Class, OnContextStart) + .BindSetEntry(GenericType<ContextConfigurationOptions.StopHandlers>.Class, OnContextStop) + .BindSetEntry(GenericType<ContextConfigurationOptions.ContextMessageSources>.Class, OnSendMessage) + .BindSetEntry(GenericType<ContextConfigurationOptions.ContextMessageHandlers>.Class, OnMessage) + .BindSetEntry(GenericType<TaskConfigurationOptions.StartHandlers>.Class, OnTaskStart) + .BindSetEntry(GenericType<TaskConfigurationOptions.StopHandlers>.Class, OnTaskStop) + .Build(); + } + } + } +} http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/lang/cs/Org.Apache.REEF.Common/Context/ContextConfigurationOptions.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Context/ContextConfigurationOptions.cs b/lang/cs/Org.Apache.REEF.Common/Context/ContextConfigurationOptions.cs new file mode 100644 index 0000000..39f0baa --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/Context/ContextConfigurationOptions.cs @@ -0,0 +1,58 @@ +// 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.Collections.Generic; +using Org.Apache.REEF.Common.Context.Defaults; +using Org.Apache.REEF.Common.Events; +using Org.Apache.REEF.Tang.Annotations; +using Org.Apache.REEF.Utilities.Attributes; + +namespace Org.Apache.REEF.Common.Context +{ + /// <summary> + /// Configuration parameters for ContextConfiguration module. + /// </summary> + [ClientSide] + public static class ContextConfigurationOptions + { + [NamedParameter(documentation: "The identifier for the context.")] + public class ContextIdentifier : Name<string> + { + } + + [NamedParameter(documentation: "The set of event handlers for the ContextStart event", defaultClasses: new[] { typeof(DefaultContextStartHandler) })] + public class StartHandlers : Name<ISet<IObserver<IContextStart>>> + { + } + + [NamedParameter(documentation: "The set of event handlers for the ContextStop event", defaultClasses: new[] { typeof(DefaultContextStopHandler) })] + public class StopHandlers : Name<ISet<IObserver<IContextStop>>> + { + } + + [NamedParameter(documentation: "The set of ContextMessageSource implementations called during heartbeats.", defaultClasses: new[] { typeof(DefaultContextMessageSource) })] + public class ContextMessageSources : Name<ISet<IContextMessageSource>> + { + } + + [NamedParameter(documentation: "The set of Context message handlers.")] + public class ContextMessageHandlers : Name<ISet<IContextMessageHandler>> + { + } + } +} http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/lang/cs/Org.Apache.REEF.Common/Context/Defaults/DefaultContextMessageSource.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Context/Defaults/DefaultContextMessageSource.cs b/lang/cs/Org.Apache.REEF.Common/Context/Defaults/DefaultContextMessageSource.cs new file mode 100644 index 0000000..67c5ed0 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/Context/Defaults/DefaultContextMessageSource.cs @@ -0,0 +1,35 @@ +// 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 Org.Apache.REEF.Utilities; + +namespace Org.Apache.REEF.Common.Context.Defaults +{ + /// <summary> + /// Default ContextMessageSource: return nothing. + /// </summary> + public class DefaultContextMessageSource : IContextMessageSource + { + public Optional<ContextMessage> Message + { + get + { + return Optional<ContextMessage>.Empty(); + } + } + } +} http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/lang/cs/Org.Apache.REEF.Common/Context/Defaults/DefaultContextStartHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Context/Defaults/DefaultContextStartHandler.cs b/lang/cs/Org.Apache.REEF.Common/Context/Defaults/DefaultContextStartHandler.cs new file mode 100644 index 0000000..01422d1 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/Context/Defaults/DefaultContextStartHandler.cs @@ -0,0 +1,46 @@ +// 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.Common.Events; +using Org.Apache.REEF.Utilities.Logging; + +namespace Org.Apache.REEF.Common.Context.Defaults +{ + /// <summary> + /// Default handler for ContextStart + /// </summary> + public class DefaultContextStartHandler : IObserver<IContextStart> + { + private static readonly Logger Logger = Logger.GetLogger(typeof(DefaultContextStartHandler)); + + public void OnNext(IContextStart contextStart) + { + Logger.Log(Level.Info, "DefaultContextStartHandler received for context: " + contextStart.Id); + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + } +} http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/lang/cs/Org.Apache.REEF.Common/Context/Defaults/DefaultContextStopHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Context/Defaults/DefaultContextStopHandler.cs b/lang/cs/Org.Apache.REEF.Common/Context/Defaults/DefaultContextStopHandler.cs new file mode 100644 index 0000000..8688314 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Common/Context/Defaults/DefaultContextStopHandler.cs @@ -0,0 +1,46 @@ +// 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.Common.Events; +using Org.Apache.REEF.Utilities.Logging; + +namespace Org.Apache.REEF.Common.Context.Defaults +{ + /// <summary> + /// Default event handler for ContextStop + /// </summary> + public class DefaultContextStopHandler : IObserver<IContextStop> + { + private static readonly Logger Logger = Logger.GetLogger(typeof(DefaultContextStopHandler)); + + public void OnNext(IContextStop contextStop) + { + Logger.Log(Level.Info, "DefaultContextStopHandler received for context: " + contextStop.Id); + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + } +} http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/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 30af205..ebaa513 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 @@ -78,7 +78,12 @@ under the License. <Compile Include="Catalog\RackDescriptorImpl.cs" /> <Compile Include="Catalog\ResourceCatalogImpl.cs" /> <Compile Include="Constants.cs" /> + <Compile Include="Context\ContextConfiguration.cs" /> + <Compile Include="Context\ContextConfigurationOptions.cs" /> <Compile Include="Context\ContextMessage.cs" /> + <Compile Include="Context\Defaults\DefaultContextMessageSource.cs" /> + <Compile Include="Context\Defaults\DefaultContextStartHandler.cs" /> + <Compile Include="Context\Defaults\DefaultContextStopHandler.cs" /> <Compile Include="Context\IContextMessage.cs" /> <Compile Include="Context\IContextMessageHandler.cs" /> <Compile Include="Context\IContextMessageSource.cs" /> http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/ContextConfiguration.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/ContextConfiguration.cs b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/ContextConfiguration.cs index 10df33d..e2c7f88 100644 --- a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/ContextConfiguration.cs +++ b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/ContextConfiguration.cs @@ -26,6 +26,8 @@ using Org.Apache.REEF.Utilities.Logging; namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context { + // TODO[JIRA REEF-1167]: Remove class. + [Obsolete("Deprecated in 0.14. Will be removed.")] internal sealed class ContextConfiguration : IConfiguration { private static readonly Logger LOGGER = Logger.GetLogger(typeof(ContextConfiguration)); @@ -53,7 +55,7 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context { string msg = "Required parameter ContextIdentifier not provided."; LOGGER.Log(Level.Error, msg); - Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new ArgumentException(msg), LOGGER); + Utilities.Diagnostics.Exceptions.Throw(new ArgumentException(msg), LOGGER); } } } http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/ContextLifeCycle.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/ContextLifeCycle.cs b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/ContextLifeCycle.cs index b79f285..a987d28 100644 --- a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/ContextLifeCycle.cs +++ b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Context/ContextLifeCycle.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; using Org.Apache.REEF.Common.Context; using Org.Apache.REEF.Common.Events; +using Org.Apache.REEF.Tang.Annotations; namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context { @@ -33,20 +34,9 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context private readonly HashSet<IContextMessageSource> _contextMessageSources; - // @Inject - public ContextLifeCycle( - string id, - HashSet<IObserver<IContextStart>> contextStartHandlers, - HashSet<IObserver<IContextStop>> contextStopHandlers, - HashSet<IContextMessageSource> contextMessageSources) - { - Id = id; - _contextStartHandlers = contextStartHandlers; - _contextStopHandlers = contextStopHandlers; - _contextMessageSources = contextMessageSources; - } - - public ContextLifeCycle(string contextId) + // TODO[JIRA REEF-1167]: Make method private. + [Inject] + public ContextLifeCycle([Parameter(typeof(ContextConfigurationOptions.ContextIdentifier))] string contextId) { Id = contextId; _contextStartHandlers = new HashSet<IObserver<IContextStart>>(); http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/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 720ae00..70316a7 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 @@ -25,6 +25,8 @@ using Org.Apache.REEF.Common.Runtime.Evaluator.Task; using Org.Apache.REEF.Common.Services; using Org.Apache.REEF.Common.Tasks; using Org.Apache.REEF.Tang.Annotations; +using Org.Apache.REEF.Tang.Formats; +using Org.Apache.REEF.Tang.Interface; using Org.Apache.REEF.Utilities; using Org.Apache.REEF.Utilities.Logging; @@ -36,20 +38,24 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context private readonly HeartBeatManager _heartBeatManager; private readonly RootContextLauncher _rootContextLauncher; private readonly object _contextLock = new object(); + private readonly AvroConfigurationSerializer _serializer; private ContextRuntime _topContext = null; [Inject] private ContextManager( HeartBeatManager heartBeatManager, - EvaluatorSettings evaluatorSetting) + EvaluatorSettings evaluatorSettings, + AvroConfigurationSerializer serializer) { using (LOGGER.LogFunction("ContextManager::ContextManager")) { _heartBeatManager = heartBeatManager; + _serializer = serializer; _rootContextLauncher = new RootContextLauncher( - evaluatorSetting.RootContextConfig, - evaluatorSetting.RootServiceConfiguration, - evaluatorSetting.RootTaskConfiguration); + evaluatorSettings.RootContextConfig.Id, + evaluatorSettings.RootContextConfig, + evaluatorSettings.RootServiceConfiguration, + evaluatorSettings.RootTaskConfiguration); } } @@ -68,7 +74,7 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context LOGGER.Log(Level.Info, "Launching the initial Task"); try { - _topContext.StartTask(_rootContextLauncher.RootTaskConfig.Value, _rootContextLauncher.RootContextConfig.Id, _heartBeatManager); + _topContext.StartTask(_rootContextLauncher.RootTaskConfig.Value, _rootContextLauncher.Id, _heartBeatManager); } catch (TaskClientCodeException e) { @@ -276,8 +282,18 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context currentTopContext.Id)); Utilities.Diagnostics.Exceptions.Throw(e, LOGGER); } - string contextConfigString = addContextProto.context_configuration; - var contextConfiguration = new ContextConfiguration(contextConfigString); + + IConfiguration contextConfiguration; + try + { + contextConfiguration = _serializer.FromString(addContextProto.context_configuration); + } + catch (Exception) + { + // TODO[JIRA REEF-1167]: Remove the catch. + contextConfiguration = new ContextConfiguration(addContextProto.context_configuration); + } + ContextRuntime newTopContext; if (addContextProto.service_configuration != null) { http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/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 e9f242a..5ec7564 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,21 +55,19 @@ 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) { - var config = contextConfiguration as ContextConfiguration; - if (config == null) - { - Utilities.Diagnostics.Exceptions.Throw( - new ArgumentException("contextConfiguration is not of type ContextConfiguration"), LOGGER); - } - _contextLifeCycle = new ContextLifeCycle(config.Id); + _contextLifeCycle = new ContextLifeCycle(id); _serviceInjector = serviceInjector; _parentContext = parentContext; try @@ -84,7 +82,7 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context 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); } @@ -93,14 +91,36 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context } /// <summary> + /// Create a new ContextRuntime. + /// </summary> + /// <param name="serviceInjector"></param> + /// <param name="contextConfiguration">the Configuration for this context.</param> + /// <param name="parentContext"></param> + public ContextRuntime( + IInjector serviceInjector, + IConfiguration contextConfiguration, + Optional<ContextRuntime> parentContext) + { + _serviceInjector = serviceInjector; + _contextInjector = serviceInjector.ForkInjector(contextConfiguration); + _contextLifeCycle = _contextInjector.GetInstance<ContextLifeCycle>(); + _parentContext = parentContext; + _contextLifeCycle.Start(); + } + + /// <summary> /// Create a new ContextRuntime for the root context. /// </summary> - /// <param name="serviceInjector"> </param> the serviceInjector to be used. + /// <param name="id">the ID of the context.</param> + /// <param name="serviceInjector">the serviceInjector to be used.</param> /// <param name="contextConfiguration"> the Configuration for this context.</param> + /// TODO[JIRA REEF-1167]: Remove constructor. + [Obsolete("Deprecated in 0.14, will be removed.")] public ContextRuntime( + string id, IInjector serviceInjector, IConfiguration contextConfiguration) - : this(serviceInjector, contextConfiguration, Optional<ContextRuntime>.Empty()) + : this(id, serviceInjector, contextConfiguration, Optional<ContextRuntime>.Empty()) { LOGGER.Log(Level.Info, "Instantiating root context"); } @@ -115,15 +135,27 @@ 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 /// serviceConfiguration. The contextConfiguration is used to fork the contextInjector from that new serviceInjector. /// </summary> - /// <param name="contextConfiguration">the new context's context (local) Configuration.</param> - /// <param name="serviceConfiguration">the new context's service Configuration.</param> + /// <param name="childContextConfiguration">the new context's context (local) Configuration.</param> + /// <param name="childServiceConfiguration">the new context's service Configuration.</param> /// <returns>a child context.</returns> - public ContextRuntime SpawnChildContext(IConfiguration contextConfiguration, IConfiguration serviceConfiguration) + public ContextRuntime SpawnChildContext(IConfiguration childContextConfiguration, IConfiguration childServiceConfiguration) { lock (_contextLifeCycle) { @@ -141,8 +173,9 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context } try { - IInjector childServiceInjector = _serviceInjector.ForkInjector(serviceConfiguration); - var childContext = new ContextRuntime(childServiceInjector, contextConfiguration, Optional<ContextRuntime>.Of(this)); + var childServiceInjector = _serviceInjector.ForkInjector(childServiceConfiguration); + var childContext = GetChildContextRuntime(childServiceInjector, childContextConfiguration, this); + _childContext = Optional<ContextRuntime>.Of(childContext); return childContext; } @@ -153,7 +186,7 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context 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); + ContextClientCodeException ex = new ContextClientCodeException(ContextClientCodeException.GetId(childContextConfiguration), parentId, "Unable to spawn context", e); Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER); } @@ -166,9 +199,9 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context /// The new context will have a serviceInjector that is created by forking the one in this object. The /// contextConfiguration is used to fork the contextInjector from that new serviceInjector. /// </summary> - /// <param name="contextConfiguration">the new context's context (local) Configuration.</param> + /// <param name="childContextConfiguration">the new context's context (local) Configuration.</param> /// <returns> a child context.</returns> - public ContextRuntime SpawnChildContext(IConfiguration contextConfiguration) + public ContextRuntime SpawnChildContext(IConfiguration childContextConfiguration) { lock (_contextLifeCycle) { @@ -184,7 +217,7 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context Utilities.Diagnostics.Exceptions.Throw(e, LOGGER); } IInjector childServiceInjector = _serviceInjector.ForkInjector(); - ContextRuntime childContext = new ContextRuntime(childServiceInjector, contextConfiguration, Optional<ContextRuntime>.Of(this)); + ContextRuntime childContext = new ContextRuntime(childServiceInjector, childContextConfiguration, Optional<ContextRuntime>.Of(this)); _childContext = Optional<ContextRuntime>.Of(childContext); return childContext; } http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/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 d9b2c6e..c7dfece 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 @@ -35,35 +35,34 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context private readonly IInjector _rootServiceInjector = null; - private ContextRuntime _rootContext = null; + private readonly IConfiguration _rootContextConfiguration; - private ContextConfiguration _rootContextConfiguration = null; + private ContextRuntime _rootContext = null; - public RootContextLauncher(ContextConfiguration rootContextConfig, Optional<ServiceConfiguration> rootServiceConfig, Optional<TaskConfiguration> rootTaskConfig) + public RootContextLauncher(string id, IConfiguration contextConfiguration, + Optional<ServiceConfiguration> rootServiceConfig, Optional<TaskConfiguration> rootTaskConfig) { - _rootContextConfiguration = rootContextConfig; + Id = id; + _rootContextConfiguration = contextConfiguration; _rootServiceInjector = InjectServices(rootServiceConfig); RootTaskConfig = rootTaskConfig; } public Optional<TaskConfiguration> RootTaskConfig { get; set; } - public ContextConfiguration RootContextConfig - { - get { return _rootContextConfiguration; } - set { _rootContextConfiguration = value; } - } + public string Id { get; private set; } internal ContextRuntime GetRootContext() { if (_rootContext == null) { - _rootContext = GetRootContext(_rootServiceInjector, _rootContextConfiguration); + // TODO[JIRA REEF-1167]: Remove use of this constructor. + _rootContext = new ContextRuntime(Id, _rootServiceInjector, _rootContextConfiguration); } return _rootContext; } - private IInjector InjectServices(Optional<ServiceConfiguration> serviceConfig) + private static IInjector InjectServices(Optional<ServiceConfiguration> serviceConfig) { IInjector rootServiceInjector; @@ -91,32 +90,5 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Context return rootServiceInjector; } - - private ContextRuntime GetRootContext( - IInjector rootServiceInjector, - IConfiguration rootContextConfiguration) - { - ContextRuntime result; - result = new ContextRuntime(rootServiceInjector, rootContextConfiguration); - return result; - } } -} -////if (rootServiceInjector != null) -////{ -//// try -//// { -//// rootServiceInjector = rootServiceInjector.ForkInjector(serviceConfigs); -//// } -//// catch (Exception e) -//// { -//// throw new ContextClientCodeException(ContextClientCodeException.GetId(rootContextConfiguration), -//// Optional<String>.Empty(), -//// "Unable to instatiate the root context", e); -//// } -//// result = new ContextRuntime(rootServiceInjector, rootContextConfiguration); -////} -////else -////{ -//// result = new ContextRuntime(rootServiceInjector.ForkInjector(), rootContextConfiguration); -////} \ No newline at end of file +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/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 613bcf6..d639dd2 100644 --- a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/EvaluatorSettings.cs +++ b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/EvaluatorSettings.cs @@ -160,6 +160,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 { get { return _rootContextConfig; } http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/lang/cs/Org.Apache.REEF.Driver/Bridge/Events/AllocatedEvaluator.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/Bridge/Events/AllocatedEvaluator.cs b/lang/cs/Org.Apache.REEF.Driver/Bridge/Events/AllocatedEvaluator.cs index 4d19728..9b5d402 100644 --- a/lang/cs/Org.Apache.REEF.Driver/Bridge/Events/AllocatedEvaluator.cs +++ b/lang/cs/Org.Apache.REEF.Driver/Bridge/Events/AllocatedEvaluator.cs @@ -74,8 +74,9 @@ namespace Org.Apache.REEF.Driver.Bridge.Events public void SubmitTask(IConfiguration taskConfiguration) { var contextConfiguration = - ContextConfiguration.ConfigurationModule.Set(ContextConfiguration.Identifier, "RootContext_" + this.Id) - .Build(); + Common.Context.ContextConfiguration.ConfigurationModule.Set( + Common.Context.ContextConfiguration.Identifier, "RootContext_" + this.Id).Build(); + SubmitContextAndTask(contextConfiguration, taskConfiguration); } public void SubmitContext(IConfiguration contextConfiguration) http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/lang/cs/Org.Apache.REEF.Driver/Context/ContextConfiguration.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/Context/ContextConfiguration.cs b/lang/cs/Org.Apache.REEF.Driver/Context/ContextConfiguration.cs index 19d596c..290a840 100644 --- a/lang/cs/Org.Apache.REEF.Driver/Context/ContextConfiguration.cs +++ b/lang/cs/Org.Apache.REEF.Driver/Context/ContextConfiguration.cs @@ -29,7 +29,9 @@ using Org.Apache.REEF.Utilities.Attributes; namespace Org.Apache.REEF.Driver.Context { + // TODO[JIRA REEF-1167]: Delete class. [ClientSide] + [Obsolete("Obsoleted in 0.14, please use Org.Apache.REEF.Common.ContextConfiguration instead.")] public sealed class ContextConfiguration : ConfigurationModuleBuilder { /// <summary> http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/lang/cs/Org.Apache.REEF.Driver/Context/ContextConfigurationOptions.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/Context/ContextConfigurationOptions.cs b/lang/cs/Org.Apache.REEF.Driver/Context/ContextConfigurationOptions.cs index 9c8e945..df002ab 100644 --- a/lang/cs/Org.Apache.REEF.Driver/Context/ContextConfigurationOptions.cs +++ b/lang/cs/Org.Apache.REEF.Driver/Context/ContextConfigurationOptions.cs @@ -21,7 +21,6 @@ using Org.Apache.REEF.Common.Context; using Org.Apache.REEF.Common.Events; using Org.Apache.REEF.Driver.Context.Defaults; using Org.Apache.REEF.Tang.Annotations; -using Org.Apache.REEF.Tang.Formats; using Org.Apache.REEF.Utilities.Attributes; namespace Org.Apache.REEF.Driver.Context @@ -29,8 +28,10 @@ namespace Org.Apache.REEF.Driver.Context /// <summary> /// Configuration parameters for ContextConfiguration module. /// </summary> + /// TODO[JIRA REEF-1167]: Remove this class. [ClientSide] - public sealed class ContextConfigurationOptions : ConfigurationModuleBuilder + [Obsolete("Obsoleted in 0.14, please use Org.Apache.REEF.Common.ContextConfiguration instead.")] + public static class ContextConfigurationOptions { [NamedParameter(documentation: "The identifier for the context.")] public class ContextIdentifier : Name<string> http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/lang/cs/Org.Apache.REEF.Driver/Context/Defaults/DefaultContextMessageSource.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/Context/Defaults/DefaultContextMessageSource.cs b/lang/cs/Org.Apache.REEF.Driver/Context/Defaults/DefaultContextMessageSource.cs index 57761ed..5b83c29 100644 --- a/lang/cs/Org.Apache.REEF.Driver/Context/Defaults/DefaultContextMessageSource.cs +++ b/lang/cs/Org.Apache.REEF.Driver/Context/Defaults/DefaultContextMessageSource.cs @@ -15,6 +15,7 @@ // specific language governing permissions and limitations // under the License. +using System; using Org.Apache.REEF.Common.Context; using Org.Apache.REEF.Utilities; @@ -23,13 +24,15 @@ namespace Org.Apache.REEF.Driver.Context.Defaults /// <summary> /// Default ContextMessageSource: return nothing. /// </summary> + /// TODO[JIRA REEF-1167]: Remove this class. + [Obsolete("Deprecated in 0.14, please use Org.Apache.REEF.Common.Evaluator.Defaults.DefaultContextMessageSource instead.")] public class DefaultContextMessageSource : IContextMessageSource { - public Optional<Common.Context.ContextMessage> Message + public Optional<ContextMessage> Message { get { - return Optional<Common.Context.ContextMessage>.Empty(); + return Optional<ContextMessage>.Empty(); } } } http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/lang/cs/Org.Apache.REEF.Driver/Context/Defaults/DefaultContextStartHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/Context/Defaults/DefaultContextStartHandler.cs b/lang/cs/Org.Apache.REEF.Driver/Context/Defaults/DefaultContextStartHandler.cs index 6001c8e..0483320 100644 --- a/lang/cs/Org.Apache.REEF.Driver/Context/Defaults/DefaultContextStartHandler.cs +++ b/lang/cs/Org.Apache.REEF.Driver/Context/Defaults/DefaultContextStartHandler.cs @@ -20,10 +20,12 @@ using Org.Apache.REEF.Common.Events; using Org.Apache.REEF.Utilities.Logging; namespace Org.Apache.REEF.Driver.Context.Defaults -{ - /// <summary> +{ + /// <summary> /// Default handler for ContextStart - /// </summary> + /// </summary> + /// TODO[JIRA REEF-1167]: Remove this class. + [Obsolete("Deprecated in 0.14, please use Org.Apache.REEF.Common.Evaluator.Defaults.DefaultContextStartHandler instead.")] public class DefaultContextStartHandler : IObserver<IContextStart> { private static readonly Logger LOGGER = Logger.GetLogger(typeof(DefaultContextStartHandler)); http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/lang/cs/Org.Apache.REEF.Driver/Context/Defaults/DefaultContextStopHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/Context/Defaults/DefaultContextStopHandler.cs b/lang/cs/Org.Apache.REEF.Driver/Context/Defaults/DefaultContextStopHandler.cs index 1118cc1..3f2807a 100644 --- a/lang/cs/Org.Apache.REEF.Driver/Context/Defaults/DefaultContextStopHandler.cs +++ b/lang/cs/Org.Apache.REEF.Driver/Context/Defaults/DefaultContextStopHandler.cs @@ -24,6 +24,8 @@ namespace Org.Apache.REEF.Driver.Context.Defaults /// <summary> /// Default event handler for ContextStop /// </summary> + /// TODO[JIRA REEF-1167]: Remove this class. + [Obsolete("Deprecated in 0.14, please use Org.Apache.REEF.Common.Evaluator.Defaults.DefaultContextStopHandler instead.")] public class DefaultContextStopHandler : IObserver<IContextStop> { private static readonly Logger LOGGER = Logger.GetLogger(typeof(DefaultContextStopHandler)); http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloAllocatedEvaluatorHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloAllocatedEvaluatorHandler.cs b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloAllocatedEvaluatorHandler.cs index f0cd434..944fa57 100644 --- a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloAllocatedEvaluatorHandler.cs +++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloAllocatedEvaluatorHandler.cs @@ -24,7 +24,6 @@ using Org.Apache.REEF.Common.Io; using Org.Apache.REEF.Common.Services; using Org.Apache.REEF.Common.Tasks; using Org.Apache.REEF.Driver.Bridge; -using Org.Apache.REEF.Driver.Context; using Org.Apache.REEF.Driver.Evaluator; using Org.Apache.REEF.Examples.Tasks.HelloTask; using Org.Apache.REEF.Network.Naming; @@ -34,6 +33,7 @@ using Org.Apache.REEF.Tang.Implementations.Tang; using Org.Apache.REEF.Tang.Interface; using Org.Apache.REEF.Tang.Util; using Org.Apache.REEF.Utilities; +using Org.Apache.REEF.Common.Context; namespace Org.Apache.REEF.Examples.AllHandlers { http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/lang/cs/Org.Apache.REEF.Network/Group/Driver/Impl/GroupCommDriver.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Network/Group/Driver/Impl/GroupCommDriver.cs b/lang/cs/Org.Apache.REEF.Network/Group/Driver/Impl/GroupCommDriver.cs index 76e34f6..3f7a47a 100644 --- a/lang/cs/Org.Apache.REEF.Network/Group/Driver/Impl/GroupCommDriver.cs +++ b/lang/cs/Org.Apache.REEF.Network/Group/Driver/Impl/GroupCommDriver.cs @@ -33,6 +33,7 @@ using Org.Apache.REEF.Tang.Implementations.Tang; using Org.Apache.REEF.Tang.Interface; using Org.Apache.REEF.Tang.Util; using Org.Apache.REEF.Utilities.Logging; +using ContextConfiguration = Org.Apache.REEF.Common.Context.ContextConfiguration; namespace Org.Apache.REEF.Network.Group.Driver.Impl { http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/HelloSimpleEventHandlers.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/HelloSimpleEventHandlers.cs b/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/HelloSimpleEventHandlers.cs index 47eef30..0944680 100644 --- a/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/HelloSimpleEventHandlers.cs +++ b/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/HelloSimpleEventHandlers.cs @@ -18,7 +18,6 @@ using System; using System.Collections.Generic; using System.Globalization; -using System.Linq; using System.Net; using System.Text; using Org.Apache.REEF.Common.Tasks; @@ -33,6 +32,7 @@ using Org.Apache.REEF.Tang.Interface; using Org.Apache.REEF.Tang.Util; using Org.Apache.REEF.Utilities; using Org.Apache.REEF.Utilities.Logging; +using ContextConfiguration = Org.Apache.REEF.Common.Context.ContextConfiguration; using IRunningTask = Org.Apache.REEF.Driver.Task.IRunningTask; namespace Org.Apache.REEF.Tests.Functional.Bridge http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/TestSimpleContext.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/TestSimpleContext.cs b/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/TestSimpleContext.cs new file mode 100644 index 0000000..6935ffd --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/TestSimpleContext.cs @@ -0,0 +1,211 @@ +// 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 Microsoft.VisualStudio.TestTools.UnitTesting; +using Org.Apache.REEF.Common.Tasks; +using Org.Apache.REEF.Driver; +using Org.Apache.REEF.Driver.Bridge; +using Org.Apache.REEF.Driver.Context; +using Org.Apache.REEF.Driver.Evaluator; +using Org.Apache.REEF.Driver.Task; +using Org.Apache.REEF.Examples.AllHandlers; +using Org.Apache.REEF.Examples.Tasks.HelloTask; +using Org.Apache.REEF.Tang.Annotations; +using Org.Apache.REEF.Tang.Implementations.Tang; +using Org.Apache.REEF.Tang.Interface; +using Org.Apache.REEF.Tang.Util; +using Org.Apache.REEF.Utilities.Logging; +using ContextConfiguration = Org.Apache.REEF.Common.Context.ContextConfiguration; + +namespace Org.Apache.REEF.Tests.Functional.Bridge +{ + [TestClass] + public sealed class TestSimpleContext : ReefFunctionalTest + { + private const string ContextId = "ContextId"; + private const string ValidationMessage = "ValidationMessage"; + + private static readonly Logger Logger = Logger.GetLogger(typeof(TestSimpleContext)); + + [TestInitialize] + public void TestSetup() + { + Init(); + } + + /// <summary> + /// Does a simple test of context submission. + /// </summary> + [TestMethod, Priority(1), TestCategory("FunctionalGated")] + [Description("Test Context ID submission on local runtime")] + [DeploymentItem(@".")] + [Timeout(180 * 1000)] + public void TestSimpleContextOnLocalRuntime() + { + TestContextOnLocalRuntime(ContextDriverConfiguration()); + } + + /// <summary> + /// Does a simple test of context submission with deprecated configurations. + /// </summary> + [TestMethod, Priority(1), TestCategory("FunctionalGated")] + [Description("Test deprecated Context ID submission on local runtime")] + [DeploymentItem(@".")] + [Timeout(180 * 1000)] + public void TestDeprecatedContextOnLocalRuntime() + { + TestContextOnLocalRuntime(DeprecatedContextDriverConfiguration()); + } + + private void TestContextOnLocalRuntime(IConfiguration configuration) + { + string testFolder = DefaultRuntimeFolder + Guid.NewGuid().ToString("N").Substring(0, 4); + CleanUp(testFolder); + TestRun(configuration, typeof(TestContextHandlers), 1, "testSimpleContext", "local", testFolder); + ValidateSuccessForLocalRuntime(1, testFolder: testFolder); + ValidateMessageSuccessfullyLogged(ValidationMessage, testFolder); + CleanUp(testFolder); + } + + private static IConfiguration ContextDriverConfiguration() + { + return DriverConfiguration.ConfigurationModule + .Set(DriverConfiguration.OnDriverStarted, GenericType<TestContextHandlers>.Class) + .Set(DriverConfiguration.OnEvaluatorAllocated, GenericType<AllocatedEvaluatorHandler>.Class) + .Set(DriverConfiguration.OnContextActive, GenericType<TestContextHandlers>.Class) + .Set(DriverConfiguration.OnTaskMessage, GenericType<HelloTaskMessageHandler>.Class) + .Set(DriverConfiguration.OnTaskCompleted, GenericType<TestContextHandlers>.Class) + .Set(DriverConfiguration.OnTaskRunning, GenericType<TestContextHandlers>.Class) + .Build(); + } + + private static IConfiguration DeprecatedContextDriverConfiguration() + { + return DriverConfiguration.ConfigurationModule + .Set(DriverConfiguration.OnDriverStarted, GenericType<TestContextHandlers>.Class) + .Set(DriverConfiguration.OnEvaluatorAllocated, GenericType<DeprecatedAllocatedEvaluatorHandler>.Class) + .Set(DriverConfiguration.OnContextActive, GenericType<TestContextHandlers>.Class) + .Set(DriverConfiguration.OnTaskMessage, GenericType<HelloTaskMessageHandler>.Class) + .Set(DriverConfiguration.OnTaskCompleted, GenericType<TestContextHandlers>.Class) + .Set(DriverConfiguration.OnTaskRunning, GenericType<TestContextHandlers>.Class) + .Build(); + } + + private sealed class AllocatedEvaluatorHandler : IObserver<IAllocatedEvaluator> + { + [Inject] + private AllocatedEvaluatorHandler() + { + } + + public void OnNext(IAllocatedEvaluator value) + { + value.SubmitContext(ContextConfiguration.ConfigurationModule + .Set(ContextConfiguration.Identifier, ContextId) + .Build()); + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + } + + private sealed class DeprecatedAllocatedEvaluatorHandler : IObserver<IAllocatedEvaluator> + { + [Inject] + private DeprecatedAllocatedEvaluatorHandler() + { + } + + public void OnNext(IAllocatedEvaluator value) + { + value.SubmitContext(REEF.Driver.Context.ContextConfiguration.ConfigurationModule + .Set(REEF.Driver.Context.ContextConfiguration.Identifier, ContextId) + .Build()); + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + } + + private sealed class TestContextHandlers : IObserver<IDriverStarted>, IObserver<IActiveContext>, IObserver<IRunningTask>, IObserver<ICompletedTask> + { + private readonly IEvaluatorRequestor _requestor; + + [Inject] + private TestContextHandlers(IEvaluatorRequestor evaluatorRequestor) + { + _requestor = evaluatorRequestor; + } + + public void OnNext(IDriverStarted value) + { + _requestor.Submit(_requestor.NewBuilder().Build()); + } + + public void OnNext(IActiveContext value) + { + Logger.Log(Level.Info, "ContextId: " + value.Id); + if (value.Id != ContextId) + { + throw new Exception("Unexpected ContextId: " + value.Id); + } + + value.SubmitTask( + TaskConfiguration.ConfigurationModule.Set(TaskConfiguration.Identifier, "helloTaskId") + .Set(TaskConfiguration.Task, GenericType<HelloTask>.Class) + .Build()); + } + + public void OnNext(IRunningTask value) + { + Logger.Log(Level.Info, "Running Task" + value.Id); + } + + public void OnNext(ICompletedTask value) + { + Logger.Log(Level.Info, "Completed Task" + value.Id); + Logger.Log(Level.Info, ValidationMessage); + value.ActiveContext.Dispose(); + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/lang/cs/Org.Apache.REEF.Tests/Functional/Messaging/MessageDriver.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tests/Functional/Messaging/MessageDriver.cs b/lang/cs/Org.Apache.REEF.Tests/Functional/Messaging/MessageDriver.cs index bc0a4b9..d6558f3 100644 --- a/lang/cs/Org.Apache.REEF.Tests/Functional/Messaging/MessageDriver.cs +++ b/lang/cs/Org.Apache.REEF.Tests/Functional/Messaging/MessageDriver.cs @@ -16,12 +16,10 @@ // under the License. using System; -using System.Collections.Generic; using System.Globalization; +using Org.Apache.REEF.Common.Context; using Org.Apache.REEF.Common.Tasks; using Org.Apache.REEF.Driver; -using Org.Apache.REEF.Driver.Bridge; -using Org.Apache.REEF.Driver.Context; using Org.Apache.REEF.Driver.Evaluator; using Org.Apache.REEF.Driver.Task; using Org.Apache.REEF.Tang.Annotations; http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/lang/cs/Org.Apache.REEF.Tests/Functional/RuntimeName/EvaluatorRequestingDriver.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tests/Functional/RuntimeName/EvaluatorRequestingDriver.cs b/lang/cs/Org.Apache.REEF.Tests/Functional/RuntimeName/EvaluatorRequestingDriver.cs index 729a163..c5cee8e 100644 --- a/lang/cs/Org.Apache.REEF.Tests/Functional/RuntimeName/EvaluatorRequestingDriver.cs +++ b/lang/cs/Org.Apache.REEF.Tests/Functional/RuntimeName/EvaluatorRequestingDriver.cs @@ -17,10 +17,9 @@ using System; using System.Globalization; - +using Org.Apache.REEF.Common.Context; using Org.Apache.REEF.Common.Tasks; using Org.Apache.REEF.Driver; -using Org.Apache.REEF.Driver.Context; using Org.Apache.REEF.Driver.Evaluator; using Org.Apache.REEF.Driver.Task; using Org.Apache.REEF.Tang.Annotations; http://git-wip-us.apache.org/repos/asf/reef/blob/12decb73/lang/cs/Org.Apache.REEF.Tests/Org.Apache.REEF.Tests.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tests/Org.Apache.REEF.Tests.csproj b/lang/cs/Org.Apache.REEF.Tests/Org.Apache.REEF.Tests.csproj index 4e6f93b..7ed135f 100644 --- a/lang/cs/Org.Apache.REEF.Tests/Org.Apache.REEF.Tests.csproj +++ b/lang/cs/Org.Apache.REEF.Tests/Org.Apache.REEF.Tests.csproj @@ -95,6 +95,7 @@ under the License. <Compile Include="Functional\Bridge\TestBridgeClient.cs" /> <Compile Include="Functional\Bridge\TestFailedEvaluatorEventHandler.cs" /> <Compile Include="Functional\Bridge\TestFailedTaskEventHandler.cs" /> + <Compile Include="Functional\Bridge\TestSimpleContext.cs" /> <Compile Include="Functional\Bridge\TestSimpleEventHandlers.cs" /> <Compile Include="Functional\Driver\DriverTestStartHandler.cs" /> <Compile Include="Functional\RuntimeName\EvaluatorRequestingDriver.cs" />
