You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by is...@apache.org on 2014/10/19 06:39:25 UTC

[3/4] git commit: changes for Life Cycle State Manager contd.

changes for Life Cycle State Manager contd.


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

Branch: refs/heads/4.0.0-grouping
Commit: cd66b40a74510f57bda3e9486451f948806cc320
Parents: 17d68ab
Author: Isuru Haththotuwa <is...@apache.org>
Authored: Sun Oct 19 08:41:02 2014 +0530
Committer: Isuru Haththotuwa <is...@apache.org>
Committed: Sun Oct 19 09:42:42 2014 +0530

----------------------------------------------------------------------
 .../monitor/ApplicationMonitorFactory.java      |  8 +--
 .../autoscaler/monitor/group/GroupMonitor.java  |  3 +-
 .../status/checker/StatusChecker.java           |  2 +-
 .../controller/topology/TopologyBuilder.java    |  9 ++-
 .../messaging/domain/topology/Application.java  | 27 +++++++-
 .../domain/topology/ApplicationStatus.java      | 71 ++++++++++++++++++++
 .../messaging/domain/topology/Cluster.java      | 12 +++-
 .../domain/topology/ClusterStatus.java          | 24 +++++--
 .../messaging/domain/topology/Group.java        | 30 ++++++++-
 .../messaging/domain/topology/GroupStatus.java  | 70 +++++++++++++++++++
 .../messaging/domain/topology/Member.java       |  3 +-
 .../messaging/domain/topology/MemberStatus.java | 14 ++--
 .../domain/topology/ParentComponent.java        | 12 ++--
 .../lifecycle/LifeCycleStateManager.java        | 43 ++++++++++--
 .../domain/topology/util/GroupStatus.java       | 40 -----------
 .../ApplicationActivatedMessageProcessor.java   |  2 +-
 .../topology/ClusterActivatedProcessor.java     |  2 +
 .../ClusterMaintenanceModeMessageProcessor.java |  2 +
 .../topology/GroupActivatedProcessor.java       |  5 +-
 19 files changed, 301 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/cd66b40a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ApplicationMonitorFactory.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ApplicationMonitorFactory.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ApplicationMonitorFactory.java
index 86e0931..361e89a 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ApplicationMonitorFactory.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ApplicationMonitorFactory.java
@@ -106,10 +106,10 @@ public class ApplicationMonitorFactory {
             groupMonitor = new GroupMonitor(group, appId);
             groupMonitor.setAppId(appId);
             groupMonitor.setParent(parentMonitor);
-            if (group.getStatus() != groupMonitor.getStatus()) {
+            if (group.getTempStatus() != groupMonitor.getStatus()) {
                 //updating the status, if the group is not in created state when creating group Monitor
                 //so that groupMonitor will notify the parent (useful when restarting stratos)
-                groupMonitor.setStatus(group.getStatus());
+                groupMonitor.setStatus(group.getTempStatus());
             }
         } finally {
             TopologyManager.releaseReadLockForApplication(appId);
@@ -290,9 +290,9 @@ public class ApplicationMonitorFactory {
                 }
             }
 
-            if (cluster.getStatus() != clusterMonitor.getStatus()) {
+            if (cluster.getTempStatus() != clusterMonitor.getStatus()) {
                 //updating the status, so that it will notify the parent
-                clusterMonitor.setStatus(cluster.getStatus());
+                clusterMonitor.setStatus(cluster.getTempStatus());
             }
         } finally {
             //release read lock for the service and cluster

http://git-wip-us.apache.org/repos/asf/stratos/blob/cd66b40a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java
index 9f83578..9e36622 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java
@@ -54,7 +54,7 @@ public class GroupMonitor extends ParentComponentMonitor implements EventHandler
             TopologyInConsistentException {
         super(group);
         this.appId = appId;
-        this.setStatus(group.getStatus());
+        this.setStatus(group.getTempStatus());
         startDependency();
     }
 
@@ -92,6 +92,7 @@ public class GroupMonitor extends ParentComponentMonitor implements EventHandler
                     log.error(e);
                 }
             } else if (status1 == Status.In_Active) {
+
                 //TODO if C1 depends on C2, then if C2 is in_active, then by getting killdepend as C1 and
                 //TODO need to send in_active for c1. When C1 in_active receives, get dependent and
                 //TODO check whether dependent in_active. Then kill c1.

http://git-wip-us.apache.org/repos/asf/stratos/blob/cd66b40a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
index ff45af1..c59313c 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
@@ -267,7 +267,7 @@ public class StatusChecker {
     private boolean getGroupStatus(Map<String, Group> groups) {
         boolean groupActiveStatus = false;
         for (Group group : groups.values()) {
-            if (group.getStatus() == Status.Activated) {
+            if (group.getTempStatus() == Status.Activated) {
                 groupActiveStatus = true;
             } else {
                 groupActiveStatus = false;

http://git-wip-us.apache.org/repos/asf/stratos/blob/cd66b40a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java
index 9f74524..b9fb581 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java
@@ -213,6 +213,8 @@ public class TopologyBuilder {
                 log.error("Invalid State Transition from " + cluster.getStatus() + " to " + ClusterStatus.Inactive);
             }
             cluster.setStatus(ClusterStatus.Inactive);
+            // temporary; should be removed
+            cluster.setTempStatus(Status.In_Active);
             //cluster.setStatus(Status.In_Maintenance);
             TopologyManager.updateTopology(topology);
         } finally {
@@ -774,6 +776,9 @@ public class TopologyBuilder {
             TopologyManager.acquireWriteLock();
             //cluster.setStatus(Status.Activated);
             cluster.setStatus(ClusterStatus.Active);
+            // temporary; should be removed
+            cluster.setTempStatus(Status.Activated);
+
             log.info("Cluster activated adding status started");
 
             TopologyManager.updateTopology(topology);
@@ -807,7 +812,7 @@ public class TopologyBuilder {
                         groupActivatedEvent.getGroupId());
         try {
             TopologyManager.acquireWriteLock();
-            group.setStatus(Status.Activated);
+            group.setTempStatus(Status.Activated);
             log.info("Group activated adding status started");
 
             TopologyManager.updateTopology(topology);
@@ -833,7 +838,7 @@ public class TopologyBuilder {
                         applicationActivatedEvent.getAppId());
         try {
             TopologyManager.acquireWriteLock();
-            application.setStatus(Status.Activated);
+            application.setTempStatus(Status.Activated);
             log.info("Application activated adding status started for Topology");
 
             TopologyManager.updateTopology(topology);

http://git-wip-us.apache.org/repos/asf/stratos/blob/cd66b40a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Application.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Application.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Application.java
index c30d5b7..ecca8df 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Application.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Application.java
@@ -20,6 +20,7 @@
 package org.apache.stratos.messaging.domain.topology;
 
 import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.stratos.messaging.domain.topology.lifecycle.LifeCycleStateManager;
 
 import java.util.*;
 
@@ -27,7 +28,7 @@ import java.util.*;
  * Represents an Application in the Topology
  */
 
-public class Application extends ParentComponent {
+public class Application extends ParentComponent implements LifeCycleStateTransitionBehavior<ApplicationStatus> {
 
     private static final long serialVersionUID = -5092959597171649688L;
     // Unique id for the Application, defined in Application Definition
@@ -40,11 +41,15 @@ public class Application extends ParentComponent {
     private String tenantDomain;
     // tenant admin user
     private String tenantAdminUserName;
+    // Life cycle state manager
+    protected LifeCycleStateManager<ApplicationStatus> applicationStateManager;
 
     public Application (String id) {
         super();
         this.id = id;
         this.key = RandomStringUtils.randomAlphanumeric(16);
+        this.applicationStateManager =
+                new LifeCycleStateManager<ApplicationStatus>(ApplicationStatus.Created);
     }
 
     public String getUniqueIdentifier() {
@@ -79,6 +84,26 @@ public class Application extends ParentComponent {
         this.tenantAdminUserName = tenantAdminUserName;
     }
 
+    @Override
+    public boolean isStateTransitionValid(ApplicationStatus newState) {
+        return this.applicationStateManager.isStateTransitionValid(newState);
+    }
+
+    @Override
+    public Stack<ApplicationStatus> getTransitionedStates() {
+        return this.applicationStateManager.getStateStack();
+    }
+
+    @Override
+    public ApplicationStatus getStatus() {
+        return this.applicationStateManager.getCurrentState();
+    }
+
+    @Override
+    public void setStatus(ApplicationStatus newState) {
+        this.applicationStateManager.changeState(newState);
+    }
+
     public boolean equals(Object other) {
         if(other == null || !(other instanceof Application)) {
             return false;

http://git-wip-us.apache.org/repos/asf/stratos/blob/cd66b40a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/ApplicationStatus.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/ApplicationStatus.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/ApplicationStatus.java
new file mode 100644
index 0000000..6ca8e27
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/ApplicationStatus.java
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+package org.apache.stratos.messaging.domain.topology;
+
+import org.apache.stratos.messaging.domain.topology.lifecycle.LifeCycleState;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+public enum ApplicationStatus implements LifeCycleState {
+
+    Created (0) {
+        @Override
+        public Set<LifeCycleState> getNextStates() {
+            return new HashSet<LifeCycleState>(Arrays.asList(ApplicationStatus.Active,
+                    ApplicationStatus.Terminating));
+        }
+    },
+    Active (1) {
+        @Override
+        public Set<LifeCycleState> getNextStates() {
+            return new HashSet<LifeCycleState>(Arrays.asList(ApplicationStatus.Inactive));
+        }
+    },
+    Inactive (2) {
+        @Override
+        public Set<LifeCycleState> getNextStates() {
+            return new HashSet<LifeCycleState>(Arrays.asList(ApplicationStatus.Terminating));
+        }
+    },
+    Terminating (3) {
+        @Override
+        public Set<LifeCycleState> getNextStates() {
+            return new HashSet<LifeCycleState>(Arrays.asList(ApplicationStatus.Terminated));
+        }
+    },
+    Terminated (4) {
+        @Override
+        public Set<LifeCycleState> getNextStates() {
+            return null;
+        }
+    };
+
+    private int code;
+
+    private ApplicationStatus (int code) {
+        this.code = code;
+    }
+
+    public int getCode() {
+        return code;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cd66b40a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java
index 31b7bf1..3325561 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java
@@ -50,7 +50,7 @@ public class Cluster implements Serializable, LifeCycleStateTransitionBehavior<C
     @XmlJavaTypeAdapter(MapAdapter.class)
     private Map<String, Member> memberMap;
 
-    //private Status status;
+    private Status tempStatus;
 
     private String appId;
 
@@ -69,6 +69,8 @@ public class Cluster implements Serializable, LifeCycleStateTransitionBehavior<C
         this.memberMap = new HashMap<String, Member>();
         this.appId = appId;
         this.clusterStateManager = new LifeCycleStateManager<ClusterStatus>(ClusterStatus.Created);
+        // temporary; should be removed
+        this.tempStatus = Status.Created;
     }
 
     public String getServiceName() {
@@ -250,5 +252,13 @@ public class Cluster implements Serializable, LifeCycleStateTransitionBehavior<C
     public String getAppId() {
         return appId;
     }
+
+    public Status getTempStatus () {
+        return tempStatus;
+    }
+
+    public void setTempStatus (Status tempStatus)  {
+        this.tempStatus = tempStatus;
+    }
 }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/cd66b40a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/ClusterStatus.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/ClusterStatus.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/ClusterStatus.java
index a9f8afe..8ff5957 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/ClusterStatus.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/ClusterStatus.java
@@ -26,25 +26,41 @@ import java.util.HashSet;
 import java.util.Set;
 
 public enum ClusterStatus implements LifeCycleState {
+
     Created(0) {
         @Override
         public Set<LifeCycleState> getNextStates() {
-            return new HashSet<LifeCycleState>(Arrays.asList(ClusterStatus.Active));
+            return new HashSet<LifeCycleState>(Arrays.asList(ClusterStatus.Active,
+                    ClusterStatus.Terminating));
         }
     },
     Active(1) {
         @Override
         public Set<LifeCycleState> getNextStates() {
-            return new HashSet<LifeCycleState>(Arrays.asList(ClusterStatus.Inactive));
+            return new HashSet<LifeCycleState>(Arrays.asList(ClusterStatus.Inactive,
+                    ClusterStatus.Patching, ClusterStatus.Terminating));
+        }
+    },
+    Patching (2) {
+        @Override
+        public Set<LifeCycleState> getNextStates() {
+            return new HashSet<LifeCycleState>(Arrays.asList(ClusterStatus.Active));
         }
     },
     Inactive(3) {
         @Override
         public Set<LifeCycleState> getNextStates() {
-            return new HashSet<LifeCycleState>(Arrays.asList(ClusterStatus.Active, ClusterStatus.Terminated));
+            return new HashSet<LifeCycleState>(Arrays.asList(ClusterStatus.Active,
+                    ClusterStatus.Terminating));
+        }
+    },
+    Terminating(4) {
+        @Override
+        public Set<LifeCycleState> getNextStates() {
+            return new HashSet<LifeCycleState>(Arrays.asList(ClusterStatus.Terminated));
         }
     },
-    Terminated(4) {
+    Terminated(5) {
         @Override
         public Set<LifeCycleState> getNextStates() {
             return null;

http://git-wip-us.apache.org/repos/asf/stratos/blob/cd66b40a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Group.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Group.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Group.java
index 9b5a29e..0b64f67 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Group.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Group.java
@@ -19,11 +19,15 @@
 
 package org.apache.stratos.messaging.domain.topology;
 
+import org.apache.stratos.messaging.domain.topology.lifecycle.LifeCycleStateManager;
+
+import java.util.Stack;
+
 /**
  * Represents a Group/nested Group in an Application/Group
  */
 
-public class Group extends ParentComponent {
+public class Group extends ParentComponent implements LifeCycleStateTransitionBehavior<GroupStatus> {
 
     private static final long serialVersionUID = 8347096598203655846L;
     // Name of the Group, specified in Group Definition
@@ -34,11 +38,14 @@ public class Group extends ParentComponent {
     private String deploymentPolicy;
     // Group level autoscaling policy
     private String autoscalingPolicy;
+    // Life cycle state manager
+    protected LifeCycleStateManager<GroupStatus> groupStateManager;
 
     public Group (String name, String alias) {
         super();
         this.name = name;
         this.alias = alias;
+        this.groupStateManager = new LifeCycleStateManager<GroupStatus>(GroupStatus.Created);
     }
 
     public String getUniqueIdentifier() {
@@ -65,6 +72,26 @@ public class Group extends ParentComponent {
         this.autoscalingPolicy = autoscalingPolicy;
     }
 
+    @Override
+    public boolean isStateTransitionValid(GroupStatus newState) {
+        return groupStateManager.isStateTransitionValid(newState);
+    }
+
+    @Override
+    public Stack<GroupStatus> getTransitionedStates() {
+        return groupStateManager.getStateStack();
+    }
+
+    @Override
+    public GroupStatus getStatus() {
+        return groupStateManager.getCurrentState();
+    }
+
+    @Override
+    public void setStatus(GroupStatus newState) {
+        this.groupStateManager.changeState(newState);
+    }
+
     public boolean equals(Object other) {
         if(other == null || !(other instanceof Group)) {
             return false;
@@ -81,5 +108,4 @@ public class Group extends ParentComponent {
     public int hashCode () {
         return name.hashCode() + alias.hashCode();
     }
-
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/cd66b40a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/GroupStatus.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/GroupStatus.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/GroupStatus.java
new file mode 100644
index 0000000..55a7731
--- /dev/null
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/GroupStatus.java
@@ -0,0 +1,70 @@
+/*
+ * 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.
+ */
+package org.apache.stratos.messaging.domain.topology;
+
+import org.apache.stratos.messaging.domain.topology.lifecycle.LifeCycleState;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+public enum GroupStatus implements LifeCycleState {
+
+    Created(0) {
+        @Override
+        public Set<LifeCycleState> getNextStates() {
+            return new HashSet<LifeCycleState>(Arrays.asList(GroupStatus.Active, GroupStatus.Terminating));
+        }
+    },
+    Active(1) {
+        @Override
+        public Set<LifeCycleState> getNextStates() {
+            return new HashSet<LifeCycleState>(Arrays.asList(GroupStatus.Inactive, GroupStatus.Terminating));
+        }
+    },
+    Inactive(2) {
+        @Override
+        public Set<LifeCycleState> getNextStates() {
+            return new HashSet<LifeCycleState>(Arrays.asList(GroupStatus.Terminating));
+        }
+    },
+    Terminating(3) {
+        @Override
+        public Set<LifeCycleState> getNextStates() {
+            return new HashSet<LifeCycleState>(Arrays.asList(GroupStatus.Terminated));
+        }
+    },
+    Terminated(4) {
+        @Override
+        public Set<LifeCycleState> getNextStates() {
+            return null;
+        }
+    };
+
+    private int code;
+
+    private GroupStatus(int code) {
+        this.code = code;
+    }
+
+    public int getCode() {
+        return code;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cd66b40a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Member.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Member.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Member.java
index f0cde24..1d80b16 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Member.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Member.java
@@ -19,7 +19,6 @@
 
 package org.apache.stratos.messaging.domain.topology;
 
-import org.apache.stratos.messaging.domain.topology.lifecycle.LifeCycleState;
 import org.apache.stratos.messaging.domain.topology.lifecycle.LifeCycleStateManager;
 import org.apache.stratos.messaging.util.bean.type.map.MapAdapter;
 
@@ -90,7 +89,7 @@ public class Member implements Serializable, LifeCycleStateTransitionBehavior<Me
 
     @Override
     public void setStatus(MemberStatus newState) {
-        memberStateManager.changeState(newState);
+        this.memberStateManager.changeState(newState);
     }
 
     public boolean isActive () {

http://git-wip-us.apache.org/repos/asf/stratos/blob/cd66b40a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/MemberStatus.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/MemberStatus.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/MemberStatus.java
index 6d23c4b..a35766c 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/MemberStatus.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/MemberStatus.java
@@ -32,38 +32,38 @@ import java.util.Set;
 @XmlRootElement
 public enum MemberStatus implements LifeCycleState {
 
-    Created(1) {
+    Created(0) {
         @Override
         public Set<LifeCycleState> getNextStates() {
             return new HashSet<LifeCycleState>(Arrays.asList(MemberStatus.Starting));
         }
     },
-    Starting(2) {
+    Starting(1) {
         @Override
         public Set<LifeCycleState> getNextStates() {
             return new HashSet<LifeCycleState>(Arrays.asList(MemberStatus.Activated));
         }
     },
-    Activated(3) {
+    Activated(2) {
         @Override
         public Set<LifeCycleState> getNextStates() {
             return new HashSet<LifeCycleState>(Arrays.asList(MemberStatus.Suspended,
-                    MemberStatus.In_Maintenance));
+                    MemberStatus.In_Maintenance, MemberStatus.Starting));
         }
     },
-    In_Maintenance(4) {
+    In_Maintenance(3) {
         @Override
         public Set<LifeCycleState> getNextStates() {
             return new HashSet<LifeCycleState>(Arrays.asList(MemberStatus.ReadyToShutDown));
         }
     },
-    ReadyToShutDown(5) {
+    ReadyToShutDown(4) {
         @Override
         public Set<LifeCycleState> getNextStates() {
             return new HashSet<LifeCycleState>(Arrays.asList(MemberStatus.Terminated));
         }
     },
-    Suspended(0) {
+    Suspended(5) {
         @Override
         public Set<LifeCycleState> getNextStates() {
             return new HashSet<LifeCycleState>(Arrays.asList(MemberStatus.Terminated));

http://git-wip-us.apache.org/repos/asf/stratos/blob/cd66b40a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/ParentComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/ParentComponent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/ParentComponent.java
index 7ce813e..dc5dd20 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/ParentComponent.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/ParentComponent.java
@@ -36,10 +36,10 @@ public abstract class ParentComponent implements Serializable {
     // Cluster Id map, key = subscription alias for the cartridge type
     private Map<String, ClusterDataHolder> aliasToClusterDataMap;
     // Application status
-    private Status status;
+    private Status tempStatus;
 
     public ParentComponent () {
-        this.status = Status.Created;
+        this.tempStatus = Status.Created;
         aliasToGroupMap = new HashMap<String, Group>();
         aliasToClusterDataMap = new HashMap<String, ClusterDataHolder>();
     }
@@ -212,11 +212,11 @@ public abstract class ParentComponent implements Serializable {
         }
     }
 
-    public Status getStatus() {
-        return status;
+    public Status getTempStatus() {
+        return tempStatus;
     }
 
-    public void setStatus(Status status) {
-        this.status = status;
+    public void setTempStatus(Status status) {
+        this.tempStatus = status;
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/cd66b40a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/lifecycle/LifeCycleStateManager.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/lifecycle/LifeCycleStateManager.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/lifecycle/LifeCycleStateManager.java
index 8131b1d..edb4cb1 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/lifecycle/LifeCycleStateManager.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/lifecycle/LifeCycleStateManager.java
@@ -33,36 +33,69 @@ public class LifeCycleStateManager<T extends LifeCycleState> implements Serializ
     private Stack<T> stateStack;
 
     public LifeCycleStateManager(T initialState) {
+
         stateStack = new Stack<T>();
         stateStack.push(initialState);
-        //if (log.isDebugEnabled()) {
-            log.info("Life Cycle State Manager created, initial state: " + initialState.toString());
-        //}
+        log.info("Life Cycle State Manager created, initial state: " + initialState.toString());
     }
 
+    /**
+     * checks if any conditions that should be met for the state transfer is valid
+     *
+     * @param nextState possible next state for the topology element
+     * @param topologyEvent relevant ToplogyEvent
+     * @param <S> subclass of Topology event
+     * @return
+     */
     public <S extends TopologyEvent> boolean isPreConditionsValid (T nextState, S topologyEvent) {
         // TODO: implement
         return true;
     }
 
+    /**
+     * Checks if the state transition is valid
+     *
+     * @param nextState possible next state for the topology element
+     * @return true if transitioning for nextState from current state is valid, else false
+     */
     public boolean isStateTransitionValid (T nextState) {
-
         return stateStack.peek().getNextStates().contains(nextState);
     }
 
+    /**
+     * Changes the current state to nextState
+     *
+     * @param nextState
+     */
     public void changeState (T nextState)  {
-
         stateStack.push(nextState);
+        log.info("Life Cycle State changed from [ " + getPreviousState() + " ] to [ " +
+                getCurrentState() + " ]");
     }
 
+    /**
+     * Get all the states this element has gone through
+     *
+     * @return Stack of states
+     */
     public Stack<T> getStateStack () {
         return stateStack;
     }
 
+    /**
+     * Get the current state
+     *
+     * @return the current state
+     */
     public T getCurrentState () {
         return stateStack.peek();
     }
 
+    /**
+     * Retrieves the previous state
+     *
+     * @return previous state
+     */
     public T getPreviousState () {
         return stateStack.get(1);
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/cd66b40a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/util/GroupStatus.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/util/GroupStatus.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/util/GroupStatus.java
deleted file mode 100644
index e00d4fa..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/util/GroupStatus.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.
- */
-package org.apache.stratos.messaging.domain.topology.util;
-
-public enum GroupStatus {
-
-    Created(1),
-    In_Maintenance(2),
-    terminating(3),
-    Removed(4),
-    Running(5),
-    Active(6);
-
-    private int code;
-
-    private GroupStatus(int code) {
-        this.code = code;
-    }
-
-    public int getCode() {
-        return code;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/cd66b40a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationActivatedMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationActivatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationActivatedMessageProcessor.java
index d32cecf..9bcf47d 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationActivatedMessageProcessor.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationActivatedMessageProcessor.java
@@ -88,7 +88,7 @@ public class ApplicationActivatedMessageProcessor extends MessageProcessor {
             return false;
         } else {
             // Apply changes to the topology
-            application.setStatus(Status.Activated);
+            application.setTempStatus(Status.Activated);
             if (log.isInfoEnabled()) {
                 log.info(String.format("Application updated as activated : %s",
                         application.toString()));

http://git-wip-us.apache.org/repos/asf/stratos/blob/cd66b40a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterActivatedProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterActivatedProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterActivatedProcessor.java
index 69fc3e7..1a6ffc7 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterActivatedProcessor.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterActivatedProcessor.java
@@ -119,6 +119,8 @@ public class ClusterActivatedProcessor extends MessageProcessor {
                 log.error("Invalid State Transition from " + cluster.getStatus() + " to " + ClusterStatus.Active);
             }
             cluster.setStatus(ClusterStatus.Active);
+            // temporary; should be removed
+            cluster.setTempStatus(Status.Activated);
             if (log.isInfoEnabled()) {
                 log.info(String.format("Cluster updated as activated : %s",
                         cluster.toString()));

http://git-wip-us.apache.org/repos/asf/stratos/blob/cd66b40a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterMaintenanceModeMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterMaintenanceModeMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterMaintenanceModeMessageProcessor.java
index 35966e8..096c9a3 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterMaintenanceModeMessageProcessor.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterMaintenanceModeMessageProcessor.java
@@ -114,6 +114,8 @@ public class ClusterMaintenanceModeMessageProcessor extends MessageProcessor {
                 log.error("Invalid State Transition from " + cluster.getStatus() + " to " + ClusterStatus.Inactive);
             }
             cluster.setStatus(ClusterStatus.Inactive);
+            // temporary; should be removed
+            cluster.setTempStatus(Status.In_Active);
             if (log.isInfoEnabled()) {
                 log.info(String.format("Cluster updated as maintenance mode: %s",
                         cluster.toString()));

http://git-wip-us.apache.org/repos/asf/stratos/blob/cd66b40a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/GroupActivatedProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/GroupActivatedProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/GroupActivatedProcessor.java
index 5c8de02..1ed6b27 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/GroupActivatedProcessor.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/GroupActivatedProcessor.java
@@ -90,7 +90,10 @@ public class GroupActivatedProcessor extends MessageProcessor {
             }
         } else {
             // Apply changes to the topology
-            group.setStatus(Status.Activated);
+            if (!group.isStateTransitionValid(GroupStatus.Active)) {
+                log.error("Invalid State Transition from " + application.getTempStatus() + " to " + GroupStatus.Active);
+            }
+            group.setTempStatus(Status.Activated);
             if (log.isInfoEnabled())     {
                 log.info(String.format("Group updated as activated : %s",
                         group.getUniqueIdentifier()));