Repository: reef
Updated Branches:
  refs/heads/master 082186a2d -> cf8275e39


[REEF-1335] Create State Machine for Fault tolerant

This adds:
  * SystemStates, SystemStateEvents
  * StateTransition as a generic, it will be shared with Task state
  * SystemState to define state transitions
  * Tests

None of these classes are threadsafe, we assume proper locking in the users
of them.

JIRA:
  [REEF-1335](https://issues.apache.org/jira/browse/REEF-1335)

Pull Request:
  This closes #948


Project: http://git-wip-us.apache.org/repos/asf/reef/repo
Commit: http://git-wip-us.apache.org/repos/asf/reef/commit/cf8275e3
Tree: http://git-wip-us.apache.org/repos/asf/reef/tree/cf8275e3
Diff: http://git-wip-us.apache.org/repos/asf/reef/diff/cf8275e3

Branch: refs/heads/master
Commit: cf8275e39331537a16946dd71fafe195a81db769
Parents: 082186a
Author: Julia Wang <[email protected]>
Authored: Thu Apr 21 17:38:55 2016 -0700
Committer: Markus Weimer <[email protected]>
Committed: Thu Apr 21 18:08:50 2016 -0700

----------------------------------------------------------------------
 .../Org.Apache.REEF.IMRU.Tests.csproj           |   3 +-
 .../TestSystemStates.cs                         | 116 +++++++++++++++++++
 .../Driver/StateMachine/StateTransition.cs      |  52 +++++++++
 .../OnREEF/Driver/StateMachine/SystemState.cs   |  58 ++++++++++
 .../Driver/StateMachine/SystemStateEvent.cs     |  55 +++++++++
 .../Driver/StateMachine/SystemStateMachine.cs   |  91 +++++++++++++++
 .../SystemStateTransitionException.cs           |  49 ++++++++
 .../Org.Apache.REEF.IMRU.csproj                 |   7 +-
 8 files changed, 429 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/reef/blob/cf8275e3/lang/cs/Org.Apache.REEF.IMRU.Tests/Org.Apache.REEF.IMRU.Tests.csproj
----------------------------------------------------------------------
diff --git 
a/lang/cs/Org.Apache.REEF.IMRU.Tests/Org.Apache.REEF.IMRU.Tests.csproj 
b/lang/cs/Org.Apache.REEF.IMRU.Tests/Org.Apache.REEF.IMRU.Tests.csproj
index 6267be0..c5120f2 100644
--- a/lang/cs/Org.Apache.REEF.IMRU.Tests/Org.Apache.REEF.IMRU.Tests.csproj
+++ b/lang/cs/Org.Apache.REEF.IMRU.Tests/Org.Apache.REEF.IMRU.Tests.csproj
@@ -47,6 +47,7 @@ under the License.
     <Compile Include="MapInputWithControlMessageTests.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="MapperCountTest.cs" />
+    <Compile Include="TestSystemStates.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference 
Include="$(SolutionDir)\Org.Apache.REEF.IMRU\Org.Apache.REEF.IMRU.csproj">
@@ -82,4 +83,4 @@ under the License.
   <Target Name="EnsureNuGetPackageBuildImports" 
BeforeTargets="PrepareForBuild">
     <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" 
Text="$([System.String]::Format('$(NuGetError)', 
'$(SolutionDir)\.nuget\NuGet.targets'))" />
   </Target>
-</Project>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/reef/blob/cf8275e3/lang/cs/Org.Apache.REEF.IMRU.Tests/TestSystemStates.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.IMRU.Tests/TestSystemStates.cs 
b/lang/cs/Org.Apache.REEF.IMRU.Tests/TestSystemStates.cs
new file mode 100644
index 0000000..95cfc7f
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.IMRU.Tests/TestSystemStates.cs
@@ -0,0 +1,116 @@
+// 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.IMRU.OnREEF.Driver.StateMachine;
+using Xunit;
+
+namespace Org.Apache.REEF.IMRU.Tests
+{
+    /// <summary>
+    /// This is to test system state transition for all the possible scenarios
+    /// </summary>
+    public class TestSystemStates
+    {
+        /// <summary>
+        /// Test Equal method for StateTransition
+        /// </summary>
+        [Fact]
+        public void TestStateTransitionEquals()
+        {
+            var s1 = new StateTransition<SystemState, 
SystemStateEvent>(SystemState.WaitingForEvaluator,
+                SystemStateEvent.AllContextsAreReady);
+            var s2 = new StateTransition<SystemState, 
SystemStateEvent>(SystemState.WaitingForEvaluator,
+                SystemStateEvent.AllContextsAreReady);
+            Assert.True(s1.Equals(s2), "The two transitions should be equal");
+        }
+
+        /// <summary>
+        /// Successful transitions from WaitingForEvaluator to TasksCompleted
+        /// </summary>
+        [Fact]
+        public void TestFromRequestEvaluatorToTasksComplete()
+        {
+            var systemState = new SystemStateMachine();
+            
Assert.True(systemState.CurrentState.Equals(SystemState.WaitingForEvaluator), 
"The initial state should be WaitingForEvaluator.");
+            
Assert.True(systemState.MoveNext(SystemStateEvent.FailedNode).Equals(SystemState.WaitingForEvaluator),
 "Fail to stay at WaitingForEvaluator state.");
+            
Assert.True(systemState.MoveNext(SystemStateEvent.AllContextsAreReady).Equals(SystemState.SubmittingTasks),
 "Fail to move from WaitingForEvaluator state to SubmittingTasks state.");
+            
Assert.True(systemState.MoveNext(SystemStateEvent.AllTasksAreRunning).Equals(SystemState.TasksRunning),
 "Fail to move from SubmittingTasks state to TasksRunning state.");
+            
Assert.True(systemState.MoveNext(SystemStateEvent.AllTasksAreCompleted).Equals(SystemState.TasksCompleted),
 "Fail to move from TasksRunning state to TasksCompleted state.");
+        }
+
+        /// <summary>
+        /// Fail scenario, from WaitingForEvaluator->Fail
+        /// </summary>
+        [Fact]
+        public void TestNoRecoverableFailedEvaluatorDuringWaitingForEvaluator()
+        {
+            var systemState = new SystemStateMachine();
+            
Assert.True(systemState.MoveNext(SystemStateEvent.NotRecoverable).Equals(SystemState.Fail),
 "Fail to move from WaitingForEvaluator state to Fail state.");
+        }
+
+        /// <summary>
+        /// Recovery scenario, from 
WaitingForEvaluator->SubmittingTasks->TasksRunning->ShuttingDown->WaitingForEvaluator
+        /// </summary>
+        [Fact]
+        public void TestFailedNodeAfterTasksAreRunningThenRecovery()
+        {
+            var systemState = new SystemStateMachine();
+            systemState.MoveNext(SystemStateEvent.AllContextsAreReady);
+            systemState.MoveNext(SystemStateEvent.AllTasksAreRunning);
+            
Assert.True(systemState.MoveNext(SystemStateEvent.FailedNode).Equals(SystemState.ShuttingDown),
 "Fail to move from TasksRunning state to ShuttingDown state.");
+            
Assert.True(systemState.MoveNext(SystemStateEvent.FailedNode).Equals(SystemState.ShuttingDown),
 "Fail to stay at ShuttingDown state.");
+            
Assert.True(systemState.MoveNext(SystemStateEvent.Recover).Equals(SystemState.WaitingForEvaluator),
 "Fail to move from ShuttingDown state to WaitingForEvaluator state.");
+        }
+
+        /// <summary>
+        /// Fail scenario, from 
WaitingForEvaluator->SubmittingTasks->TasksRunning->ShuttingDown->Fail
+        /// </summary>
+        [Fact]
+        public void TestFailedNodeAfterTasksAreRunningThenFail()
+        {
+            var systemState = new SystemStateMachine();
+            systemState.MoveNext(SystemStateEvent.AllContextsAreReady);
+            systemState.MoveNext(SystemStateEvent.AllTasksAreRunning);
+            
Assert.True(systemState.MoveNext(SystemStateEvent.FailedNode).Equals(SystemState.ShuttingDown),
 "Fail to move from TasksRunning state to ShuttingDown state.");
+            
Assert.True(systemState.MoveNext(SystemStateEvent.NotRecoverable).Equals(SystemState.Fail),
 "Fail to move from ShuttingDown state to Fail state.");
+        }
+
+        /// <summary>
+        /// Fail scenario, from 
WaitingForEvaluator->SubmittingTasks->ShuttingDown->Fail
+        /// </summary>
+        [Fact]
+        public void TestFailedNodeDuringTaskSubmittingThenFail()
+        {
+            var systemState = new SystemStateMachine();
+            systemState.MoveNext(SystemStateEvent.AllContextsAreReady);
+            
Assert.True(systemState.MoveNext(SystemStateEvent.FailedNode).Equals(SystemState.ShuttingDown),
 "Fail to move from SubmittingTasks state to ShuttingDown state.");
+            
Assert.True(systemState.MoveNext(SystemStateEvent.NotRecoverable).Equals(SystemState.Fail),
 "Fail to move from ShuttingDown state to Fail state.");
+        }
+
+        /// <summary>
+        /// Recovery scenario, from 
WaitingForEvaluator->SubmittingTasks->ShuttingDown->WaitingForEvaluator
+        /// </summary>
+        [Fact]
+        public void TestFailedNodeDuringTaskSubmittingThenRecovery()
+        {
+            var systemState = new SystemStateMachine();
+            systemState.MoveNext(SystemStateEvent.AllContextsAreReady);
+            
Assert.True(systemState.MoveNext(SystemStateEvent.FailedNode).Equals(SystemState.ShuttingDown),
 "Fail to move from SubmittingTasks state to ShuttingDown state.");
+            
Assert.True(systemState.MoveNext(SystemStateEvent.Recover).Equals(SystemState.WaitingForEvaluator),
 "Fail to move from ShuttingDown state to WaitingForEvaluator state.");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/reef/blob/cf8275e3/lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/StateMachine/StateTransition.cs
----------------------------------------------------------------------
diff --git 
a/lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/StateMachine/StateTransition.cs 
b/lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/StateMachine/StateTransition.cs
new file mode 100644
index 0000000..bf09288
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/StateMachine/StateTransition.cs
@@ -0,0 +1,52 @@
+// 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.
+
+namespace Org.Apache.REEF.IMRU.OnREEF.Driver.StateMachine
+{
+    /// <summary>
+    /// State transition that represents the current state and event
+    /// </summary>
+    /// <typeparam name="TState"></typeparam>
+    /// <typeparam name="TEvent"></typeparam>
+    internal sealed class StateTransition<TState, TEvent> 
+    {
+        private readonly TState _currentState;
+        private readonly TEvent _event;
+
+        /// <summary>
+        /// Create a state transition with current state and event
+        /// </summary>
+        /// <param name="currentState"></param>
+        /// <param name="anEvent"></param>
+        internal StateTransition(TState currentState, TEvent anEvent)
+        {
+            _currentState = currentState;
+            _event = anEvent;
+        }
+
+        public override int GetHashCode()
+        {
+            return 17 + (31 * _currentState.GetHashCode()) + (31 * 
_event.GetHashCode());
+        }
+
+        public override bool Equals(object obj)
+        {
+            StateTransition<TState, TEvent> other = obj as 
StateTransition<TState, TEvent>;
+            return other != null && _currentState.Equals(other._currentState) 
&& _event.Equals(other._event);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/reef/blob/cf8275e3/lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/StateMachine/SystemState.cs
----------------------------------------------------------------------
diff --git 
a/lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/StateMachine/SystemState.cs 
b/lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/StateMachine/SystemState.cs
new file mode 100644
index 0000000..bd8af6f
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/StateMachine/SystemState.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.
+
+namespace Org.Apache.REEF.IMRU.OnREEF.Driver.StateMachine
+{
+    /// <summary>
+    /// System states during a complete life cycle 
+    /// </summary>
+    internal enum SystemState
+    {
+        /// <summary>
+        /// In this state, the driver is waiting for Evaluators to be 
allocated and for data to be loaded into them. 
+        /// This is the state the Driver starts in. It is also the state the 
Driver is in recovery after suffering a failure. 
+        /// </summary>
+        WaitingForEvaluator,
+        
+        /// <summary>
+        /// In this state, the driver submits all the tasks to the contexts. 
At this state, driver creates a communication group 
+        /// and its topology. Once it has all the expected tasks, it enters 
the TasksRunning state. During this stage, if there 
+        /// is any failed task or failed evaluator, it goes to ShuttingDown 
state.
+        /// </summary>
+        SubmittingTasks,
+
+        /// <summary>
+        /// This is the sate after all tasks are running. If we receive a task 
failure or evaluator failure in this state, it goes to ShuttingDown state. 
+        /// </summary>
+        TasksRunning,
+
+        /// <summary>
+        /// After all tasks are completed, the state will be set to this 
state. And then all the active contexts will be closed. 
+        /// </summary>
+        TasksCompleted,
+
+        /// <summary>
+        /// If an evaluator failed or Task failed, it enters this state.
+        /// </summary>
+        ShuttingDown,
+
+        /// <summary>
+        /// Error happens and the system is not recoverable, it enters Fail 
state. 
+        /// </summary>
+        Fail
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/reef/blob/cf8275e3/lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/StateMachine/SystemStateEvent.cs
----------------------------------------------------------------------
diff --git 
a/lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/StateMachine/SystemStateEvent.cs 
b/lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/StateMachine/SystemStateEvent.cs
new file mode 100644
index 0000000..4da4be6
--- /dev/null
+++ 
b/lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/StateMachine/SystemStateEvent.cs
@@ -0,0 +1,55 @@
+// 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.
+
+namespace Org.Apache.REEF.IMRU.OnREEF.Driver.StateMachine
+{
+    /// <summary>
+    /// Events that trigger the states to transit from one to another
+    /// </summary>
+    internal enum SystemStateEvent
+    {
+        /// <summary>
+        /// All active contexts are received
+        /// </summary>
+        AllContextsAreReady,
+
+        /// <summary>
+        /// All tasks are running
+        /// </summary>
+        AllTasksAreRunning,
+
+        /// <summary>
+        /// All tasks are completed
+        /// </summary>
+        AllTasksAreCompleted,
+        
+        /// <summary>
+        /// A Task or Evaluator is failed
+        /// </summary>
+        FailedNode,
+
+        /// <summary>
+        /// System is not recoverable
+        /// </summary>
+        NotRecoverable,
+
+        /// <summary>
+        /// Ready to recover
+        /// </summary>
+        Recover
+    }
+}

http://git-wip-us.apache.org/repos/asf/reef/blob/cf8275e3/lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/StateMachine/SystemStateMachine.cs
----------------------------------------------------------------------
diff --git 
a/lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/StateMachine/SystemStateMachine.cs 
b/lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/StateMachine/SystemStateMachine.cs
new file mode 100644
index 0000000..00963cd
--- /dev/null
+++ 
b/lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/StateMachine/SystemStateMachine.cs
@@ -0,0 +1,91 @@
+// 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.Collections.Generic;
+using System.Collections.ObjectModel;
+
+namespace Org.Apache.REEF.IMRU.OnREEF.Driver.StateMachine
+{
+    /// <summary>
+    /// This is a state transition machine which wraps current state, defines 
valid state transitions and API to move to next state. 
+    /// All the system states are defined in <see cref="SystemState"></see>
+    /// For the system state transition diagram <see 
href="https://issues.apache.org/jira/browse/REEF-1335";></see>
+    /// </summary>
+    internal sealed class SystemStateMachine
+    {
+        internal readonly static IDictionary<StateTransition<SystemState, 
SystemStateEvent>, SystemState> Transitions = 
+            new ReadOnlyDictionary<StateTransition<SystemState, 
SystemStateEvent>, SystemState>(
+                new Dictionary<StateTransition<SystemState, SystemStateEvent>, 
SystemState>()
+        {
+            { new StateTransition<SystemState, 
SystemStateEvent>(SystemState.WaitingForEvaluator, 
SystemStateEvent.AllContextsAreReady), SystemState.SubmittingTasks },
+            { new StateTransition<SystemState, 
SystemStateEvent>(SystemState.WaitingForEvaluator, 
SystemStateEvent.NotRecoverable), SystemState.Fail },
+            { new StateTransition<SystemState, 
SystemStateEvent>(SystemState.WaitingForEvaluator, 
SystemStateEvent.FailedNode), SystemState.WaitingForEvaluator },
+            { new StateTransition<SystemState, 
SystemStateEvent>(SystemState.SubmittingTasks, 
SystemStateEvent.AllTasksAreRunning), SystemState.TasksRunning },
+            { new StateTransition<SystemState, 
SystemStateEvent>(SystemState.SubmittingTasks, SystemStateEvent.FailedNode), 
SystemState.ShuttingDown },
+            { new StateTransition<SystemState, 
SystemStateEvent>(SystemState.TasksRunning, SystemStateEvent.FailedNode), 
SystemState.ShuttingDown },
+            { new StateTransition<SystemState, 
SystemStateEvent>(SystemState.TasksRunning, 
SystemStateEvent.AllTasksAreCompleted), SystemState.TasksCompleted },
+            { new StateTransition<SystemState, 
SystemStateEvent>(SystemState.ShuttingDown, SystemStateEvent.FailedNode), 
SystemState.ShuttingDown },
+            { new StateTransition<SystemState, 
SystemStateEvent>(SystemState.ShuttingDown, SystemStateEvent.Recover), 
SystemState.WaitingForEvaluator },
+            { new StateTransition<SystemState, 
SystemStateEvent>(SystemState.ShuttingDown, SystemStateEvent.NotRecoverable), 
SystemState.Fail }
+        });
+
+        private SystemState _currentState;
+
+        /// <summary>
+        /// create a new SysteState starting from WaitingForEvaluator
+        /// </summary>
+        internal SystemStateMachine()
+        {
+            _currentState = SystemState.WaitingForEvaluator;
+        }
+
+        /// <summary>
+        /// Returns current state
+        /// </summary>
+        internal SystemState CurrentState
+        {
+            get { return _currentState; }
+        }
+
+        /// <summary>
+        /// Based on the event and current state to determine the next state
+        /// </summary>
+        /// <param name="systemEvent"></param>
+        /// <returns></returns>
+        internal SystemState GetNext(SystemStateEvent systemEvent)
+        {
+            var transition = new StateTransition<SystemState, 
SystemStateEvent>(_currentState, systemEvent);
+            SystemState nextState;
+            if (!Transitions.TryGetValue(transition, out nextState))
+            {
+                throw new SystemStateTransitionException(_currentState, 
systemEvent);
+            }
+            return nextState;
+        }
+
+        /// <summary>
+        /// Move to next state based on the event given
+        /// </summary>
+        /// <param name="stateEvent"></param>
+        /// <returns></returns>
+        internal SystemState MoveNext(SystemStateEvent stateEvent)
+        {
+            _currentState = GetNext(stateEvent);
+            return _currentState;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/reef/blob/cf8275e3/lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/StateMachine/SystemStateTransitionException.cs
----------------------------------------------------------------------
diff --git 
a/lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/StateMachine/SystemStateTransitionException.cs
 
b/lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/StateMachine/SystemStateTransitionException.cs
new file mode 100644
index 0000000..741cfa0
--- /dev/null
+++ 
b/lang/cs/Org.Apache.REEF.IMRU/OnREEF/Driver/StateMachine/SystemStateTransitionException.cs
@@ -0,0 +1,49 @@
+// 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.Globalization;
+
+namespace Org.Apache.REEF.IMRU.OnREEF.Driver.StateMachine
+{
+    /// <summary>
+    /// Exception for SystemState Transition
+    /// </summary>
+    internal sealed class SystemStateTransitionException : Exception
+    {
+        /// <summary>
+        /// Exception when error happens in system state transition
+        /// </summary>
+        /// <param name="systemState"></param>
+        /// <param name="stateEvent"></param>
+        internal SystemStateTransitionException(SystemState systemState, 
SystemStateEvent stateEvent)
+            : base(ExceptionMessage(systemState, stateEvent))
+        {            
+        }
+
+        /// <summary>
+        /// Format a message
+        /// </summary>
+        /// <param name="systemState"></param>
+        /// <param name="stateEvent"></param>
+        /// <returns></returns>
+        private static string ExceptionMessage(SystemState systemState, 
SystemStateEvent stateEvent)
+        {
+            return string.Format(CultureInfo.InvariantCulture, "Unexpected 
event {0} in state {1}.", stateEvent, systemState);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/reef/blob/cf8275e3/lang/cs/Org.Apache.REEF.IMRU/Org.Apache.REEF.IMRU.csproj
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.IMRU/Org.Apache.REEF.IMRU.csproj 
b/lang/cs/Org.Apache.REEF.IMRU/Org.Apache.REEF.IMRU.csproj
index bae979f..7d6e8c3 100644
--- a/lang/cs/Org.Apache.REEF.IMRU/Org.Apache.REEF.IMRU.csproj
+++ b/lang/cs/Org.Apache.REEF.IMRU/Org.Apache.REEF.IMRU.csproj
@@ -73,6 +73,11 @@ under the License.
     <Compile Include="OnREEF\Driver\IMRUConstants.cs" />
     <Compile Include="OnREEF\Driver\IMRUDriver.cs" />
     <Compile Include="OnREEF\Driver\ServiceAndContextConfigurationProvider.cs" 
/>
+    <Compile Include="OnREEF\Driver\StateMachine\StateTransition.cs" />
+    <Compile Include="OnREEF\Driver\StateMachine\SystemState.cs" />
+    <Compile Include="OnREEF\Driver\StateMachine\SystemStateEvent.cs" />
+    <Compile Include="OnREEF\Driver\StateMachine\SystemStateMachine.cs" />
+    <Compile 
Include="OnREEF\Driver\StateMachine\SystemStateTransitionException.cs" />
     <Compile Include="OnREEF\IMRUTasks\MapTaskHost.cs" />
     <Compile Include="OnREEF\IMRUTasks\UpdateTaskHost.cs" />
     <Compile Include="OnREEF\MapInputWithControlMessage\MapControlMessage.cs" 
/>
@@ -141,4 +146,4 @@ under the License.
     <None Include="packages.config" />
   </ItemGroup>
   <ItemGroup />
-</Project>
+</Project>
\ No newline at end of file

Reply via email to