Repository: airavata
Updated Branches:
  refs/heads/master 2fe26fb6e -> 473723565


Added Experiment state transition validate method to Experiment Registry


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

Branch: refs/heads/master
Commit: 563c62488c6cc735080613d771096878d71f3f21
Parents: 16b58b8
Author: shamrath <[email protected]>
Authored: Wed May 13 15:40:29 2015 -0400
Committer: shamrath <[email protected]>
Committed: Wed May 13 15:40:29 2015 -0400

----------------------------------------------------------------------
 .../registry/jpa/impl/ExperimentRegistry.java   | 55 +++++++++++++++++---
 1 file changed, 49 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/563c6248/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ExperimentRegistry.java
----------------------------------------------------------------------
diff --git 
a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ExperimentRegistry.java
 
b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ExperimentRegistry.java
index a0e9ecf..acc6779 100644
--- 
a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ExperimentRegistry.java
+++ 
b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ExperimentRegistry.java
@@ -482,14 +482,15 @@ public class ExperimentRegistry {
             }
             status.setExperimentResource(experiment);
             
status.setStatusUpdateTime(AiravataUtils.getTime(experimentStatus.getTimeOfStateChange()));
-            if (experimentStatus.getExperimentState() == null) {
-                status.setState(ExperimentState.UNKNOWN.toString());
-            } else {
+            if (status.getState() == null) {
+                status.setState(ExperimentState.UNKNOWN.name());
+            }
+            if 
(isValidStatusTransition(ExperimentState.valueOf(status.getState()), 
experimentStatus.getExperimentState())) {
                 
status.setState(experimentStatus.getExperimentState().toString());
+                status.setStatusType(StatusType.EXPERIMENT.toString());
+                status.save();
+                logger.debugId(expId, "Updated experiment {} status to {}.", 
expId, experimentStatus.toString());
             }
-            status.setStatusType(StatusType.EXPERIMENT.toString());
-            status.save();
-            logger.debugId(expId, "Updated experiment {} status to {}.", 
expId, experimentStatus.toString());
         } catch (Exception e) {
             logger.errorId(expId, "Error while updating experiment status...", 
e);
             throw new RegistryException(e);
@@ -3011,4 +3012,46 @@ public class ExperimentRegistry {
             throw new RegistryException(e);
         }
     }
+
+    public boolean isValidStatusTransition(ExperimentState oldState, 
ExperimentState nextState) {
+        if (nextState == null) {
+            return false;
+        }
+        switch (oldState) {
+            case CREATED:
+                return true;
+            case VALIDATED:
+                return nextState != ExperimentState.CREATED;
+            case SCHEDULED:
+                return nextState != ExperimentState.CREATED
+                        || nextState != ExperimentState.VALIDATED;
+            case LAUNCHED:
+                return nextState != ExperimentState.CREATED
+                        || nextState != ExperimentState.VALIDATED
+                        || nextState != ExperimentState.SCHEDULED;
+            case EXECUTING:
+                return nextState != ExperimentState.CREATED
+                        || nextState != ExperimentState.VALIDATED
+                        || nextState != ExperimentState.SCHEDULED
+                        || nextState != ExperimentState.LAUNCHED;
+
+            case CANCELING:
+                return nextState == ExperimentState.CANCELING
+                        || nextState == ExperimentState.CANCELED
+                        || nextState == ExperimentState.COMPLETED
+                        || nextState == ExperimentState.FAILED;
+            case CANCELED:
+                return nextState == ExperimentState.CANCELED;
+            case COMPLETED:
+                return nextState == ExperimentState.COMPLETED;
+            case FAILED:
+                return nextState == ExperimentState.FAILED;
+            //case SUSPENDED:  // We don't change state to SUSPEND
+            case UNKNOWN:
+                return true;
+            default:
+                return false;
+        }
+    }
+ß
 }

Reply via email to