You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@edgent.apache.org by vd...@apache.org on 2016/03/21 19:43:33 UTC

[3/4] incubator-quarks git commit: Add JobMXBean health and lastError attributes

Add JobMXBean health and lastError attributes


Project: http://git-wip-us.apache.org/repos/asf/incubator-quarks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quarks/commit/750811f8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quarks/tree/750811f8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quarks/diff/750811f8

Branch: refs/heads/master
Commit: 750811f83064a79f5f260d03df6136e55f39dce5
Parents: b4e59b5
Author: Victor Dogaru <vd...@apache.org>
Authored: Fri Mar 18 16:35:43 2016 -0700
Committer: Victor Dogaru <vd...@apache.org>
Committed: Fri Mar 18 16:35:43 2016 -0700

----------------------------------------------------------------------
 .../java/quarks/execution/mbeans/JobMXBean.java | 111 ++++++++++++++-----
 .../runtime/etiao/mbeans/EtiaoJobBean.java      |  12 +-
 .../topology/DevelopmentSampleJobMXBean.java    |   8 +-
 3 files changed, 98 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/750811f8/api/execution/src/main/java/quarks/execution/mbeans/JobMXBean.java
----------------------------------------------------------------------
diff --git a/api/execution/src/main/java/quarks/execution/mbeans/JobMXBean.java b/api/execution/src/main/java/quarks/execution/mbeans/JobMXBean.java
index 63795a6..30c07d3 100644
--- a/api/execution/src/main/java/quarks/execution/mbeans/JobMXBean.java
+++ b/api/execution/src/main/java/quarks/execution/mbeans/JobMXBean.java
@@ -15,35 +15,6 @@ public interface JobMXBean {
     String TYPE = "job";
 
     /**
-     * Returns the identifier of the job.
-     * 
-     * @return the job identifier.
-     */
-    String getId();
-
-    /**
-     * Returns the name of the job.
-     *  
-     * @return the job name.
-     */
-    String getName();
-
-    /**
-     * Retrieves the current state of the job.
-     *
-     * @return the current state.
-     */
-    State getCurrentState();
-
-    /**
-     * Retrieves the next execution state when the job makes a state 
-     * transition.
-     *
-     * @return the destination state while in a state transition.
-     */
-    State getNextState();
-    
-    /**
      * Enumeration for the current status of the job.
      */
     enum State {  
@@ -63,7 +34,7 @@ public interface JobMXBean {
          * 
          * @param state specifies a job status string value.
          * 
-         * @return the corresponding Status enumeration value.
+         * @return the corresponding {@code Status} enumeration value.
          * 
          * @throws IllegalArgumentException if the input string does not map to an enumeration value.
          * @throws NullPointerException if the input value is null.
@@ -82,6 +53,86 @@ public interface JobMXBean {
     }
     
     /**
+     * Enumeration for the current job health indicator.
+     */
+    enum Health {  
+        /** 
+         * All graph nodes in the job are healthy.
+         */
+        HEALTHY,
+        /** 
+         * The execution of at least one graph node in the job has stopped
+         * because of an abnormal condition.
+         */
+        UNHEALTHY;
+        
+        /**
+         * Converts from a string representation of a job health to the corresponding enumeration value.
+         * 
+         * @param health specifies a job health string value.
+         * 
+         * @return the corresponding {@code Health} enumeration value.
+         * 
+         * @throws IllegalArgumentException if the input string does not map to an enumeration value.
+         * @throws NullPointerException if the input value is null.
+         */
+        static public Health fromString(String health) {
+            if (health ==  null) {
+                throw new NullPointerException("health");  
+            }
+            for (Health value : Health.values()) {
+                if (value.name().equals(health)) {
+                    return value;
+                }
+            }
+            throw new IllegalArgumentException(health);
+        }
+    }
+
+    /**
+     * Returns the identifier of the job.
+     * 
+     * @return the job identifier.
+     */
+    String getId();
+
+    /**
+     * Returns the name of the job.
+     *  
+     * @return the job name.
+     */
+    String getName();
+
+    /**
+     * Retrieves the current state of the job.
+     *
+     * @return the current state.
+     */
+    State getCurrentState();
+
+    /**
+     * Retrieves the next execution state when the job makes a state 
+     * transition.
+     *
+     * @return the destination state while in a state transition.
+     */
+    State getNextState();
+
+    /**
+     * Returns the summarized health indicator of the job.  
+     * 
+     * @return the summarized Job health.
+     */
+    Health getHealth();
+
+    /**
+     * Returns the last error message caught by the current job execution.  
+     * @return the last error message or an empty string if no error has 
+     *      been caught.
+     */
+    String getLastError();
+
+    /**
      * Takes a current snapshot of the running graph and returns it in JSON format.
      * <p>
      * <b>The graph snapshot JSON format</b>

http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/750811f8/runtime/etiao/src/main/java/quarks/runtime/etiao/mbeans/EtiaoJobBean.java
----------------------------------------------------------------------
diff --git a/runtime/etiao/src/main/java/quarks/runtime/etiao/mbeans/EtiaoJobBean.java b/runtime/etiao/src/main/java/quarks/runtime/etiao/mbeans/EtiaoJobBean.java
index 0d47825..50c49f7 100644
--- a/runtime/etiao/src/main/java/quarks/runtime/etiao/mbeans/EtiaoJobBean.java
+++ b/runtime/etiao/src/main/java/quarks/runtime/etiao/mbeans/EtiaoJobBean.java
@@ -12,7 +12,7 @@ import quarks.runtime.etiao.EtiaoJob;
 import quarks.runtime.etiao.graph.model.GraphType;
 
 /**
- * Implementation of a JMX control interface for a job.
+ * Implementation of a JMX control interface for the {@code EtiaoJob}.
  */
 public class EtiaoJobBean implements JobMXBean {
     private final EtiaoJob job;
@@ -45,4 +45,14 @@ public class EtiaoJobBean implements JobMXBean {
         Gson gson = new GsonBuilder().create();
         return gson.toJson(new GraphType(job.graph()));
     }
+
+    @Override
+    public Health getHealth() {
+        return Health.fromString(job.getHealth().name());
+    }
+
+    @Override
+    public String getLastError() {
+        return job.getLastError();
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/750811f8/samples/topology/src/main/java/quarks/samples/topology/DevelopmentSampleJobMXBean.java
----------------------------------------------------------------------
diff --git a/samples/topology/src/main/java/quarks/samples/topology/DevelopmentSampleJobMXBean.java b/samples/topology/src/main/java/quarks/samples/topology/DevelopmentSampleJobMXBean.java
index 0e45bbe..0ce2dec 100644
--- a/samples/topology/src/main/java/quarks/samples/topology/DevelopmentSampleJobMXBean.java
+++ b/samples/topology/src/main/java/quarks/samples/topology/DevelopmentSampleJobMXBean.java
@@ -41,7 +41,7 @@ public class DevelopmentSampleJobMXBean {
         StringBuffer sbuf = new StringBuffer();
         sbuf.append(DevelopmentProvider.JMX_DOMAIN);
         sbuf.append(":interface=");
-        sbuf.append(ObjectName.quote("quarks.graph.execution.mbeans.JobMXBean"));
+        sbuf.append(ObjectName.quote("quarks.execution.mbeans.JobMXBean"));
         sbuf.append(",type=");
         sbuf.append(ObjectName.quote("job"));
         sbuf.append(",*");
@@ -60,8 +60,12 @@ public class DevelopmentSampleJobMXBean {
         	String jobName = (String) mBeanServer.getAttribute(objectName, "Name");
         	String jobCurState = (String) mBeanServer.getAttribute(objectName, "CurrentState");
         	String jobNextState = (String) mBeanServer.getAttribute(objectName, "NextState");
+            String jobHealth = (String) mBeanServer.getAttribute(objectName, "Health");
+            String jobLastError = (String) mBeanServer.getAttribute(objectName, "LastError");
         	
-        	System.out.println("Found a job with JobId: " + jobId + " Name: " + jobName + " CurrentState: " + jobCurState + " NextState: " + jobNextState);
+        	System.out.println("Found a job with JobId: " + jobId + " Name: " + jobName + 
+                    " CurrentState: " + jobCurState + " NextState: " + jobNextState + 
+                    " Health: " + jobHealth + " LastError: \"" + jobLastError + "\"");
         }
     }
 }