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:32 UTC
[2/4] incubator-quarks git commit: Add Job getHealth() and
getLastError()
Add Job getHealth() and getLastError()
Project: http://git-wip-us.apache.org/repos/asf/incubator-quarks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quarks/commit/a1536d33
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quarks/tree/a1536d33
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quarks/diff/a1536d33
Branch: refs/heads/master
Commit: a1536d3346d96cf31039ab432b185e0946716437
Parents: bcbce8a
Author: Victor Dogaru <vd...@apache.org>
Authored: Fri Mar 18 14:11:38 2016 -0700
Committer: Victor Dogaru <vd...@apache.org>
Committed: Fri Mar 18 15:15:05 2016 -0700
----------------------------------------------------------------------
.../src/main/java/quarks/execution/Job.java | 71 +++++++++++++++-----
.../java/quarks/runtime/etiao/EtiaoJob.java | 8 +++
.../java/quarks/runtime/etiao/Executable.java | 1 +
.../graph/spi/execution/AbstractGraphJob.java | 24 ++++++-
4 files changed, 86 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/a1536d33/api/execution/src/main/java/quarks/execution/Job.java
----------------------------------------------------------------------
diff --git a/api/execution/src/main/java/quarks/execution/Job.java b/api/execution/src/main/java/quarks/execution/Job.java
index 4897f9b..f426d37 100644
--- a/api/execution/src/main/java/quarks/execution/Job.java
+++ b/api/execution/src/main/java/quarks/execution/Job.java
@@ -10,7 +10,7 @@ import java.util.concurrent.TimeoutException;
/**
* Actions and states for execution of a Quarks job.
- * <p>
+ *
* The interface provides the main job lifecycle control, taking on the following
* execution state values:
*
@@ -31,8 +31,16 @@ import java.util.concurrent.TimeoutException;
* while the job is making a state transition after the client code
* calls {@link #stateChange(Job.Action)}.</li>
* <li> {@link #getNextState() Next} - The destination state while the job
- * is making a state transition; same as the {@link #getCurrentState() current}
- * state while the job state is stable (that is, not making a transition).</LI>
+ * is making a state transition; same as the current state while
+ * the job state is stable (that is, not making a transition).</LI>
+ * </ul>
+ *
+ * The interface provides access to the job nodes
+ * {@linkplain #getHealth() health summary}, described by the following values:
+ * <ul>
+ * <li><b>HEALTHY</b> All graph nodes in the job are healthy.</li>
+ * <li><b>UNHEALTHY</b> At least one graph node in the job is stopped or
+ * stopping.</li>
* </ul>
*/
public interface Job {
@@ -53,20 +61,19 @@ public interface Job {
}
/**
- * Retrieves the current state of this job.
- *
- * @return the current state.
+ * Enumeration for the summarized health indicator of the graph nodes.
*/
- State getCurrentState();
-
- /**
- * Retrieves the next execution state when this job makes a state
- * transition.
- *
- * @return the destination state while in a state transition;
- * otherwise the same as {@link #getCurrentState()}.
- */
- State getNextState();
+ public 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
+ }
/**
* Actions which trigger {@link Job.State} transitions.
@@ -85,7 +92,23 @@ public interface Job {
}
/**
- * Initiates a {@link Job.State State} change.
+ * Retrieves the current state of this job.
+ *
+ * @return the current state.
+ */
+ State getCurrentState();
+
+ /**
+ * Retrieves the next execution state when this job makes a state
+ * transition.
+ *
+ * @return the destination state while in a state transition;
+ * otherwise the same as {@link #getCurrentState()}.
+ */
+ State getNextState();
+
+ /**
+ * Initiates an execution state change.
*
* @param action which triggers the state change.
* @throws IllegalArgumentException if the job is not in an appropriate
@@ -94,6 +117,20 @@ public interface Job {
void stateChange(Action action) throws IllegalArgumentException;
/**
+ * Returns the summarized health indicator of the graph nodes.
+ *
+ * @return the summarized Job node 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();
+
+ /**
* Returns the name of this job. The name may be set when the job is
* {@linkplain quarks.execution.Submitter#submit(java.lang.Object,com.google.gson.JsonObject) submitted}.
* Implementations may create a job name if one is not specified at submit time.
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/a1536d33/runtime/etiao/src/main/java/quarks/runtime/etiao/EtiaoJob.java
----------------------------------------------------------------------
diff --git a/runtime/etiao/src/main/java/quarks/runtime/etiao/EtiaoJob.java b/runtime/etiao/src/main/java/quarks/runtime/etiao/EtiaoJob.java
index 6eced4c..35be86d 100644
--- a/runtime/etiao/src/main/java/quarks/runtime/etiao/EtiaoJob.java
+++ b/runtime/etiao/src/main/java/quarks/runtime/etiao/EtiaoJob.java
@@ -190,4 +190,12 @@ public class EtiaoJob extends AbstractGraphJob implements JobContext {
if (jobs != null)
jobs.updateJob(this);
}
+
+ void updateHealth(Throwable t) {
+ if (t != null) {
+ setHealth(Health.UNHEALTHY);
+ setLastError(t.getMessage());
+ }
+ updateRegistry();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/a1536d33/runtime/etiao/src/main/java/quarks/runtime/etiao/Executable.java
----------------------------------------------------------------------
diff --git a/runtime/etiao/src/main/java/quarks/runtime/etiao/Executable.java b/runtime/etiao/src/main/java/quarks/runtime/etiao/Executable.java
index 51cc612..de7511e 100644
--- a/runtime/etiao/src/main/java/quarks/runtime/etiao/Executable.java
+++ b/runtime/etiao/src/main/java/quarks/runtime/etiao/Executable.java
@@ -81,6 +81,7 @@ public class Executable implements RuntimeServices {
public void accept(Object source, Throwable t) {
if (t != null) {
Executable.this.setLastError(t);
+ job.updateHealth(t);
cleanup();
}
else if (job.getCurrentState() == Job.State.RUNNING &&
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/a1536d33/spi/graph/src/main/java/quarks/graph/spi/execution/AbstractGraphJob.java
----------------------------------------------------------------------
diff --git a/spi/graph/src/main/java/quarks/graph/spi/execution/AbstractGraphJob.java b/spi/graph/src/main/java/quarks/graph/spi/execution/AbstractGraphJob.java
index 1522f4c..e0d522f 100644
--- a/spi/graph/src/main/java/quarks/graph/spi/execution/AbstractGraphJob.java
+++ b/spi/graph/src/main/java/quarks/graph/spi/execution/AbstractGraphJob.java
@@ -13,10 +13,14 @@ import quarks.execution.Job;
public abstract class AbstractGraphJob implements Job {
private State currentState;
private State nextState;
-
+ private Health health;
+ private String lastError;
+
protected AbstractGraphJob() {
this.currentState = State.CONSTRUCTED;
this.nextState = currentState;
+ this.health = Health.HEALTHY;
+ this.lastError = new String();
}
@Override
@@ -32,6 +36,16 @@ public abstract class AbstractGraphJob implements Job {
@Override
public abstract void stateChange(Action action);
+ @Override
+ public Health getHealth() {
+ return health;
+ }
+
+ @Override
+ public String getLastError() {
+ return lastError;
+ }
+
protected synchronized boolean inTransition() {
return getNextState() != getCurrentState();
}
@@ -45,4 +59,12 @@ public abstract class AbstractGraphJob implements Job {
currentState = nextState;
}
}
+
+ protected void setHealth(Health value) {
+ this.health = value;
+ }
+
+ protected void setLastError(String value) {
+ this.lastError = value;
+ }
}