You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@reef.apache.org by do...@apache.org on 2016/02/24 02:05:52 UTC

reef git commit: [REEF-762] Implement ClosedContext.ParentContext

Repository: reef
Updated Branches:
  refs/heads/master c2cca4945 -> 23f7386b3


[REEF-762] Implement ClosedContext.ParentContext

JIRA:
  [REEF-762] https://issues.apache.org/jira/browse/REEF-762

Pull Request:
  Closes #853


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

Branch: refs/heads/master
Commit: 23f7386b333a137fda278416f4b04c08a89d8963
Parents: c2cca49
Author: Andrew Chung <af...@gmail.com>
Authored: Tue Feb 23 14:40:55 2016 -0800
Committer: Dongjoon Hyun <do...@apache.org>
Committed: Tue Feb 23 16:41:46 2016 -0800

----------------------------------------------------------------------
 .../ClosedContextClr2Java.cpp                   | 22 +++++++-------------
 lang/cs/Org.Apache.REEF.Bridge/Clr2JavaImpl.h   |  1 +
 .../Runtime/Evaluator/Task/CloseEventImpl.cs    |  6 +-----
 .../Tasks/Events/ICloseEvent.cs                 |  2 +-
 .../Bridge/Events/ClosedContext.cs              | 16 +++++++-------
 .../Functional/Bridge/TestContextStack.cs       | 22 ++++++++++++++++----
 .../Bridge/TestFailedTaskEventHandler.cs        |  2 +-
 .../Functional/ReefFunctionalTest.cs            |  4 ++--
 .../reef/javabridge/ClosedContextBridge.java    | 11 +++++++++-
 9 files changed, 50 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/reef/blob/23f7386b/lang/cs/Org.Apache.REEF.Bridge/ClosedContextClr2Java.cpp
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Bridge/ClosedContextClr2Java.cpp b/lang/cs/Org.Apache.REEF.Bridge/ClosedContextClr2Java.cpp
index 9292789..358e5e6 100644
--- a/lang/cs/Org.Apache.REEF.Bridge/ClosedContextClr2Java.cpp
+++ b/lang/cs/Org.Apache.REEF.Bridge/ClosedContextClr2Java.cpp
@@ -43,6 +43,13 @@ namespace Org {
                             _jstringContextId = CommonUtilities::GetJObjectId(env, _jobjectClosedContext, jclassClosedContext);
                             _jstringEvaluatorId = CommonUtilities::GetJObjectEvaluatorId(env, _jobjectClosedContext, jclassClosedContext);
 
+                            jmethodID jmidGetParentContextMid = env->GetMethodID(
+                                jclassClosedContext, "getParentContextBridge", "()Lorg/apache/reef/javabridge/ActiveContextBridge;");
+
+                            jobject parentContext = env->CallObjectMethod(_jobjectClosedContext, jmidGetParentContextMid);
+
+                            _parentContext = gcnew ActiveContextClr2Java(env, parentContext);
+
                             ManagedLog::LOGGER->LogStop("ClosedContextClr2Java::ClosedContextClr2Java");
                         }
 
@@ -69,20 +76,7 @@ namespace Org {
                          * Gets the Parent context of the closed context through a JNI call to Java.
                          */
                         IActiveContextClr2Java^ ClosedContextClr2Java::GetParentContext() {
-                            ManagedLog::LOGGER->LogStart("ClosedContextClr2Java::GetParentContext");
-
-                            JNIEnv *env = RetrieveEnv(_jvm);
-                            jclass jclassClosedContext = env->GetObjectClass(_jobjectClosedContext);
-                            jmethodID jmidGetParentContext = env->GetMethodID(jclassClosedContext, "getParentContext", "()Lorg/apache/reef/javabridge/ActiveContextBridge;");
-                            if (jmidGetParentContext == NULL) {
-                                ManagedLog::LOGGER->Log("jmidGetParentContext is NULL");
-                                return nullptr;
-                            }
-
-                            jobject jobjectParentContext = CommonUtilities::CallGetMethodNewGlobalRef<jobject>(env, _jobjectClosedContext, jmidGetParentContext);
-                            ManagedLog::LOGGER->LogStop("ClosedContextClr2Java::GetParentContext");
-
-                            return gcnew ActiveContextClr2Java(env, jobjectParentContext);
+                            return _parentContext;
                         }
 
                         /**

http://git-wip-us.apache.org/repos/asf/reef/blob/23f7386b/lang/cs/Org.Apache.REEF.Bridge/Clr2JavaImpl.h
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Bridge/Clr2JavaImpl.h b/lang/cs/Org.Apache.REEF.Bridge/Clr2JavaImpl.h
index bfb04ab..6cd897d 100644
--- a/lang/cs/Org.Apache.REEF.Bridge/Clr2JavaImpl.h
+++ b/lang/cs/Org.Apache.REEF.Bridge/Clr2JavaImpl.h
@@ -216,6 +216,7 @@ namespace Org {
                             JavaVM* _jvm;
                             jstring _jstringContextId = NULL;
                             jstring _jstringEvaluatorId = NULL;
+                            ActiveContextClr2Java^ _parentContext = nullptr;
                         public:
                             ClosedContextClr2Java(JNIEnv *env, jobject jobjectClosedContext);
                             ~ClosedContextClr2Java();

http://git-wip-us.apache.org/repos/asf/reef/blob/23f7386b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Task/CloseEventImpl.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Task/CloseEventImpl.cs b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Task/CloseEventImpl.cs
index ae722a9..940d381 100644
--- a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Task/CloseEventImpl.cs
+++ b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Task/CloseEventImpl.cs
@@ -32,11 +32,7 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Task
             Value = Optional<byte[]>.OfNullable(bytes);
         }
 
-        public Optional<byte[]> Value
-        {
-            get { return Value; }
-            set { value = Value; } 
-        }
+        public Optional<byte[]> Value { get; private set; }
 
         public override string ToString()
         {

http://git-wip-us.apache.org/repos/asf/reef/blob/23f7386b/lang/cs/Org.Apache.REEF.Common/Tasks/Events/ICloseEvent.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Common/Tasks/Events/ICloseEvent.cs b/lang/cs/Org.Apache.REEF.Common/Tasks/Events/ICloseEvent.cs
index 4a5c493..6f008fd 100644
--- a/lang/cs/Org.Apache.REEF.Common/Tasks/Events/ICloseEvent.cs
+++ b/lang/cs/Org.Apache.REEF.Common/Tasks/Events/ICloseEvent.cs
@@ -21,6 +21,6 @@ namespace Org.Apache.REEF.Common.Tasks.Events
 {
     public interface ICloseEvent
     {
-        Optional<byte[]> Value { get; set; }
+        Optional<byte[]> Value { get; }
     }
 }

http://git-wip-us.apache.org/repos/asf/reef/blob/23f7386b/lang/cs/Org.Apache.REEF.Driver/Bridge/Events/ClosedContext.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Driver/Bridge/Events/ClosedContext.cs b/lang/cs/Org.Apache.REEF.Driver/Bridge/Events/ClosedContext.cs
index abe8cc2..f5bc007 100644
--- a/lang/cs/Org.Apache.REEF.Driver/Bridge/Events/ClosedContext.cs
+++ b/lang/cs/Org.Apache.REEF.Driver/Bridge/Events/ClosedContext.cs
@@ -29,7 +29,7 @@ namespace Org.Apache.REEF.Driver.Bridge.Events
     /// </summary>
     internal sealed class ClosedContext : IClosedContext
     {
-        private readonly IActiveContextClr2Java _parentContextClr2Java;
+        private readonly ActiveContext _parentContext;
 
         internal ClosedContext(IClosedContextClr2Java clr2java)
         {
@@ -37,9 +37,7 @@ namespace Org.Apache.REEF.Driver.Bridge.Events
             Id = clr2java.GetId();
             EvaluatorId = clr2java.GetEvaluatorId();
             EvaluatorDescriptor = clr2java.GetEvaluatorDescriptor();
-
-            // TODO[JIRA REEF-762]: populate this
-            _parentContextClr2Java = null;
+            _parentContext = clr2java.GetParentContext() == null ? null : new ActiveContext(clr2java.GetParentContext());
         }
 
         /// <summary>
@@ -63,8 +61,11 @@ namespace Org.Apache.REEF.Driver.Bridge.Events
         /// </summary>
         public Optional<string> ParentId
         {
-            // TODO[REEF-762]: Implement
-            get { return Optional<string>.Empty(); }
+            get
+            {
+                return ParentContext == null ? 
+                    Optional<string>.Empty() : Optional<string>.Of(ParentContext.Id);
+            }
         }
 
         /// <summary>
@@ -79,8 +80,7 @@ namespace Org.Apache.REEF.Driver.Bridge.Events
         /// </summary>
         public IActiveContext ParentContext
         {
-            // TODO[JIRA REEF-762]: make sure this doesn't fail.
-            get { return new ActiveContext(_parentContextClr2Java); }
+            get { return _parentContext; }
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/reef/blob/23f7386b/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/TestContextStack.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/TestContextStack.cs b/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/TestContextStack.cs
index 273718c..2c2daa6 100644
--- a/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/TestContextStack.cs
+++ b/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/TestContextStack.cs
@@ -56,7 +56,7 @@ namespace Org.Apache.REEF.Tests.Functional.Bridge
             string testFolder = DefaultRuntimeFolder + Guid.NewGuid().ToString("N").Substring(0, 4);
             CleanUp(testFolder);
             TestRun(DriverConfigurations(), typeof(ContextStackHandlers), 1, "testContextStack", "local", testFolder);
-            ValidateSuccessForLocalRuntime(1, testFolder: testFolder);
+            ValidateSuccessForLocalRuntime(2, testFolder: testFolder);
             ValidateMessageSuccessfullyLogged(TaskValidationMessage, testFolder);
             ValidateMessageSuccessfullyLogged(ClosedContextValidationMessage, testFolder);
             CleanUp(testFolder);
@@ -85,6 +85,7 @@ namespace Org.Apache.REEF.Tests.Functional.Bridge
         {
             private readonly IEvaluatorRequestor _requestor;
             private IAllocatedEvaluator _evaluator;
+            private bool _contextTwoClosed = false;
 
             [Inject]
             private ContextStackHandlers(IEvaluatorRequestor evaluatorRequestor)
@@ -148,11 +149,24 @@ namespace Org.Apache.REEF.Tests.Functional.Bridge
 
             public void OnNext(IClosedContext value)
             {
-                // TODO[JIRA REEF-762]: Inspect closing order of contexts.
                 Logger.Log(Level.Info, ClosedContextValidationMessage);
 
-                // TODO[JIRA REEF-762]: Remove disposal of Evaluator, since it should naturally be closed if no contexts.
-                _evaluator.Dispose();
+                if (_contextTwoClosed == false)
+                {
+                    Assert.Equal(value.Id, ContextTwoId);
+                    Assert.True(value.ParentId.IsPresent());
+                    Assert.Equal(value.ParentId.Value, ContextOneId);
+                    Assert.Equal(value.ParentContext.Id, ContextOneId);
+                    _contextTwoClosed = true;
+                }
+                else
+                {
+                    Assert.Equal(value.Id, ContextOneId);
+                    Assert.False(value.ParentId.IsPresent());
+                    Assert.Equal(value.ParentContext, null);
+                }
+
+                value.ParentContext.Dispose();
             }
 
             public void OnError(Exception error)

http://git-wip-us.apache.org/repos/asf/reef/blob/23f7386b/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/TestFailedTaskEventHandler.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/TestFailedTaskEventHandler.cs b/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/TestFailedTaskEventHandler.cs
index 74fb5df..82e796a 100644
--- a/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/TestFailedTaskEventHandler.cs
+++ b/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/TestFailedTaskEventHandler.cs
@@ -50,7 +50,7 @@ namespace Org.Apache.REEF.Tests.Functional.Bridge
             string testFolder = DefaultRuntimeFolder + Guid.NewGuid().ToString("N").Substring(0, 4);
             CleanUp(testFolder);
             TestRun(DriverConfigurations(), typeof(FailedTaskDriver), 1, "failedTaskTest", "local", testFolder);
-            ValidateSuccessForLocalRuntime(numberOfEvaluatorsToClose: 1, numberOfTasksToFail: 1, testFolder: testFolder);
+            ValidateSuccessForLocalRuntime(numberOfContextsToClose: 1, numberOfTasksToFail: 1, testFolder: testFolder);
             ValidateMessageSuccessfullyLogged(FailedTaskMessage, testFolder);
             CleanUp(testFolder);
         }

http://git-wip-us.apache.org/repos/asf/reef/blob/23f7386b/lang/cs/Org.Apache.REEF.Tests/Functional/ReefFunctionalTest.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tests/Functional/ReefFunctionalTest.cs b/lang/cs/Org.Apache.REEF.Tests/Functional/ReefFunctionalTest.cs
index 29c1f99..e547988 100644
--- a/lang/cs/Org.Apache.REEF.Tests/Functional/ReefFunctionalTest.cs
+++ b/lang/cs/Org.Apache.REEF.Tests/Functional/ReefFunctionalTest.cs
@@ -138,7 +138,7 @@ namespace Org.Apache.REEF.Tests.Functional
             CleanUp();
         }
 
-        protected void ValidateSuccessForLocalRuntime(int numberOfEvaluatorsToClose, int numberOfTasksToFail = 0, int numberOfEvaluatorsToFail = 0, string testFolder = DefaultRuntimeFolder)
+        protected void ValidateSuccessForLocalRuntime(int numberOfContextsToClose, int numberOfTasksToFail = 0, int numberOfEvaluatorsToFail = 0, string testFolder = DefaultRuntimeFolder)
         {
             const string successIndication = "EXIT: ActiveContextClr2Java::Close";
             const string failedTaskIndication = "Java_org_apache_reef_javabridge_NativeInterop_clrSystemFailedTaskHandlerOnNext";
@@ -163,7 +163,7 @@ namespace Org.Apache.REEF.Tests.Functional
                 string[] successIndicators = lines.Where(s => s.Contains(successIndication)).ToArray();
                 string[] failedTaskIndicators = lines.Where(s => s.Contains(failedTaskIndication)).ToArray();
                 string[] failedIndicators = lines.Where(s => s.Contains(failedEvaluatorIndication)).ToArray();
-                Assert.Equal(numberOfEvaluatorsToClose, successIndicators.Length);
+                Assert.Equal(numberOfContextsToClose, successIndicators.Length);
                 Assert.Equal(numberOfTasksToFail, failedTaskIndicators.Length);
                 Assert.Equal(numberOfEvaluatorsToFail, failedIndicators.Length);
             }

http://git-wip-us.apache.org/repos/asf/reef/blob/23f7386b/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ClosedContextBridge.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ClosedContextBridge.java b/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ClosedContextBridge.java
index bba73e8..869b723 100644
--- a/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ClosedContextBridge.java
+++ b/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ClosedContextBridge.java
@@ -48,7 +48,12 @@ public final class ClosedContextBridge extends NativeBridge implements ClosedCon
   public ClosedContextBridge(final ClosedContext closedContext,
                              final ActiveContextBridgeFactory activeContextBridgeFactory) {
     jcloseContext = closedContext;
-    parentContext = activeContextBridgeFactory.getActiveContextBridge(closedContext.getParentContext());
+    if (closedContext.getParentContext() != null) {
+      parentContext = activeContextBridgeFactory.getActiveContextBridge(closedContext.getParentContext());
+    } else {
+      parentContext = null;
+    }
+
     contextId = closedContext.getId();
     evaluatorId = closedContext.getEvaluatorId();
     evaluatorDescriptor = closedContext.getEvaluatorDescriptor();
@@ -84,6 +89,10 @@ public final class ClosedContextBridge extends NativeBridge implements ClosedCon
     return descriptorString;
   }
 
+  public ActiveContextBridge getParentContextBridge() {
+    return parentContext;
+  }
+
   @Override
   public ActiveContext getParentContext() {
     return jcloseContext.getParentContext();