Repository: stratos
Updated Branches:
  refs/heads/4.0.0-grouping 47f302a6b -> 10ed5ef2f


adding exception and fixing monitor startup issues


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

Branch: refs/heads/4.0.0-grouping
Commit: 81428ba2d5e38ec7230ebd692923e9fdb9f48bff
Parents: 2536b30
Author: reka <[email protected]>
Authored: Thu Oct 9 10:21:25 2014 +0530
Committer: reka <[email protected]>
Committed: Thu Oct 9 10:21:25 2014 +0530

----------------------------------------------------------------------
 .../exception/DependencyBuilderException.java   | 48 ++++++++++++++
 .../TopologyInConsistentException.java          | 47 +++++++++++++
 .../grouping/dependency/DependencyBuilder.java  | 51 ++------------
 .../AutoscalerTopologyEventReceiver.java        | 61 +++++++++--------
 .../stratos/autoscaler/monitor/Monitor.java     | 44 +++++++-----
 .../monitor/application/ApplicationMonitor.java | 38 +++++------
 .../autoscaler/monitor/group/GroupMonitor.java  | 70 +++++++++++---------
 .../stratos/autoscaler/util/AutoscalerUtil.java | 12 +++-
 8 files changed, 226 insertions(+), 145 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/81428ba2/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/DependencyBuilderException.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/DependencyBuilderException.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/DependencyBuilderException.java
new file mode 100644
index 0000000..cb535cc
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/DependencyBuilderException.java
@@ -0,0 +1,48 @@
+/*
+ * 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.autoscaler.exception;
+
+/**
+ * This will use to throw any exception when building dependencies
+ */
+public class DependencyBuilderException extends Exception {
+
+    private static final long serialVersionUID = -7521673271244696906L;
+    private String message;
+
+    public DependencyBuilderException(String message, Exception exception){
+        super(message, exception);
+        this.message = message;
+    }
+
+
+    public DependencyBuilderException(Exception exception){
+        super(exception);
+    }
+
+    public DependencyBuilderException(String msg){
+        super(msg);
+        this.message = msg;
+    }
+
+    @Override
+    public String getMessage() {
+        return this.message;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/81428ba2/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/TopologyInConsistentException.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/TopologyInConsistentException.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/TopologyInConsistentException.java
new file mode 100644
index 0000000..ab2d32d
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/TopologyInConsistentException.java
@@ -0,0 +1,47 @@
+/*
+ * 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.autoscaler.exception;
+
+/**
+ * This will use to throw when Topology in consistency found.
+ */
+public class TopologyInConsistentException extends Exception {
+    private static final long serialVersionUID = -7521673271244696906L;
+    private String message;
+
+    public TopologyInConsistentException(String message, Exception exception){
+        super(message, exception);
+        this.message = message;
+    }
+
+
+    public TopologyInConsistentException(Exception exception){
+        super(exception);
+    }
+
+    public TopologyInConsistentException(String msg){
+        super(msg);
+        this.message = msg;
+    }
+
+    @Override
+    public String getMessage() {
+        return this.message;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/81428ba2/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyBuilder.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyBuilder.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyBuilder.java
index 59b9bf8..cf8004e 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyBuilder.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyBuilder.java
@@ -21,6 +21,7 @@ package org.apache.stratos.autoscaler.grouping.dependency;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.*;
+import org.apache.stratos.autoscaler.exception.DependencyBuilderException;
 import 
org.apache.stratos.autoscaler.grouping.dependency.context.ApplicationContext;
 import 
org.apache.stratos.autoscaler.grouping.dependency.context.ApplicationContextFactory;
 import 
org.apache.stratos.autoscaler.grouping.dependency.context.ClusterContext;
@@ -53,7 +54,7 @@ public class DependencyBuilder {
      * @param component it will give the necessary information to build the 
tree
      * @return the dependency tree out of the dependency orders
      */
-    public DependencyTree buildDependency(ParentBehavior component) {
+    public DependencyTree buildDependency(ParentBehavior component) throws 
DependencyBuilderException {
         String alias = null;
         if(component instanceof Application) {
             alias = ((Application)component).getId();
@@ -117,9 +118,9 @@ public class DependencyBuilder {
                                         "for the next dependency to follow");
                             }
                         } else {
-                            //TODO Throw exception, since another same start 
order already found
-                            log.warn("Startup order is not consistent. It 
contains the group/cluster " +
-                                    "which has been used more than one in 
another startup order");
+                            String msg = "Startup order is not consistent. It 
contains the group/cluster " +
+                                    "which has been used more than one in 
another startup order";
+                            throw new DependencyBuilderException(msg);
                         }
 
                     }
@@ -149,46 +150,4 @@ public class DependencyBuilder {
         }
         return dependencyTree;
     }
-
-    /*public static Queue<String> getStartupOrder(ParentBehavior component) {
-
-
-        Queue<String> startup = new LinkedList<String>();
-        DependencyOrder dependencyOrder = component.getDependencyOrder();
-        if (dependencyOrder != null) {
-            Set<StartupOrder> startupOrderSet = 
dependencyOrder.getStartupOrders();
-            for (StartupOrder startupOrder : startupOrderSet) {
-
-                String start = startupOrder.getStart();
-                String after = startupOrder.getAfter();
-
-                if (!startup.contains(start)) {
-                    startup.add(start);
-                    if (!startup.contains(after)) {
-                        startup.add(after);
-
-                    } else {
-                        //TODO throw exception since after is there before 
start
-                    }
-                } else {
-                    if (!startup.contains(after)) {
-                        startup.add(after);
-                    } else {
-                        //TODO throw exception since start and after already 
there
-                    }
-                }
-            }
-        }
-        //TODO adding all the missed groups or clusters as the top child to 
the list
-        //TODO handle by application and group itself groupName and serviceName
-
-        if (component instanceof Application) {
-
-        } else if (component instanceof Group) {
-
-        }
-        return startup;
-
-    }*/
-
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/81428ba2/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java
index 3e1bfe2..9098a04 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java
@@ -24,7 +24,9 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.*;
 import 
org.apache.stratos.autoscaler.client.cloud.controller.CloudControllerClient;
 import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
+import org.apache.stratos.autoscaler.exception.DependencyBuilderException;
 import org.apache.stratos.autoscaler.exception.TerminationException;
+import org.apache.stratos.autoscaler.exception.TopologyInConsistentException;
 import org.apache.stratos.autoscaler.monitor.AbstractClusterMonitor;
 import org.apache.stratos.autoscaler.monitor.application.ApplicationMonitor;
 import org.apache.stratos.autoscaler.monitor.group.GroupMonitor;
@@ -92,8 +94,8 @@ public class AutoscalerTopologyEventReceiver implements 
Runnable {
             protected void onEvent(Event event) {
                 try {
                     TopologyManager.acquireReadLock();
-                    if(!topologyInitialized) {
-                          topologyInitialized = true;
+                    if (!topologyInitialized) {
+                        topologyInitialized = true;
                         for (Application application : 
TopologyManager.getTopology().getApplications()) {
                             startApplicationMonitor(application);
                         }
@@ -187,7 +189,6 @@ public class AutoscalerTopologyEventReceiver implements 
Runnable {
         });
 
 
-
         topologyEventReceiver.addEventListener(new 
ApplicationRemovedEventListener() {
             @Override
             protected void onEvent(Event event) {
@@ -203,10 +204,10 @@ public class AutoscalerTopologyEventReceiver implements 
Runnable {
                     //TODO remove monitors as well as any starting or pending 
threads
                     ApplicationMonitor monitor = 
AutoscalerContext.getInstance().
                             
getAppMonitor(applicationRemovedEvent.getApplicationId());
-                    if(monitor != null) {
+                    if (monitor != null) {
                         List<String> clusters = monitor.
                                 
findClustersOfApplication(applicationRemovedEvent.getApplicationId());
-                        for(String clusterId: clusters) {
+                        for (String clusterId : clusters) {
                             //stopping the cluster monitor and remove it from 
the AS
                             
AutoscalerContext.getInstance().getMonitor(clusterId).setDestroyed(true);
                             
AutoscalerContext.getInstance().removeMonitor(clusterId);
@@ -233,7 +234,7 @@ public class AutoscalerTopologyEventReceiver implements 
Runnable {
             protected void onEvent(Event event) {
                 try {
                     MemberReadyToShutdownEvent memberReadyToShutdownEvent =
-                                                                
(MemberReadyToShutdownEvent) event;
+                            (MemberReadyToShutdownEvent) event;
                     AutoscalerContext asCtx = AutoscalerContext.getInstance();
                     AbstractClusterMonitor monitor;
                     String clusterId = 
memberReadyToShutdownEvent.getClusterId();
@@ -253,7 +254,7 @@ public class AutoscalerTopologyEventReceiver implements 
Runnable {
 
                     NetworkPartitionContext nwPartitionCtxt;
                     nwPartitionCtxt = monitor.getNetworkPartitionCtxt(
-                                            
memberReadyToShutdownEvent.getNetworkPartitionId());
+                            
memberReadyToShutdownEvent.getNetworkPartitionId());
 
                     // start a new member in the same Partition
                     String partitionId = 
monitor.getPartitionOfMember(memberId);
@@ -291,11 +292,11 @@ public class AutoscalerTopologyEventReceiver implements 
Runnable {
                     Cluster cluster = service.getCluster(e.getClusterId());
                     if 
(AutoscalerContext.getInstance().monitorExist((cluster.getClusterId()))) {
                         
AutoscalerContext.getInstance().getMonitor(e.getClusterId()).
-                                                        
setStatus(e.getStatus());
+                                setStatus(e.getStatus());
                     } else if (AutoscalerContext.getInstance().
-                                        
lbMonitorExist((cluster.getClusterId()))) {
+                            lbMonitorExist((cluster.getClusterId()))) {
                         
AutoscalerContext.getInstance().getLBMonitor(e.getClusterId()).
-                                                        
setStatus(e.getStatus());
+                                setStatus(e.getStatus());
                     } else {
                         log.error("cluster monitor not exists for the cluster: 
" + cluster.toString());
                     }
@@ -323,7 +324,7 @@ public class AutoscalerTopologyEventReceiver implements 
Runnable {
 
                     if (e.isLbCluster()) {
                         DeploymentPolicy depPolicy = 
PolicyManager.getInstance().
-                                                        
getDeploymentPolicy(deploymentPolicy);
+                                getDeploymentPolicy(deploymentPolicy);
                         if (depPolicy != null) {
                             List<NetworkPartitionLbHolder> lbHolders = 
PartitionManager.getInstance()
                                     .getNetworkPartitionLbHolders(depPolicy);
@@ -396,10 +397,10 @@ public class AutoscalerTopologyEventReceiver implements 
Runnable {
                     }
 
                     NetworkPartitionContext networkPartitionContext = monitor.
-                                                        
getNetworkPartitionCtxt(networkPartitionId);
+                            getNetworkPartitionCtxt(networkPartitionId);
 
                     PartitionContext partitionContext = 
networkPartitionContext.
-                                                                    
getPartitionCtxt(partitionId);
+                            getPartitionCtxt(partitionId);
                     String memberId = e.getMemberId();
                     partitionContext.removeMemberStatsContext(memberId);
 
@@ -471,7 +472,7 @@ public class AutoscalerTopologyEventReceiver implements 
Runnable {
 
                     if (log.isInfoEnabled()) {
                         log.info(String.format("Member stat context has been 
added " +
-                                                "successfully: [member] %s", 
memberId));
+                                "successfully: [member] %s", memberId));
                     }
 //                partitionContext.incrementCurrentActiveMemberCount(1);
                     
partitionContext.movePendingMemberToActiveMembers(memberId);
@@ -505,16 +506,16 @@ public class AutoscalerTopologyEventReceiver implements 
Runnable {
                     if 
(AutoscalerContext.getInstance().monitorExist(clusterId)) {
                         monitor = 
AutoscalerContext.getInstance().getMonitor(clusterId);
                         partitionContext = 
monitor.getNetworkPartitionCtxt(networkPartitionId).
-                                                                    
getPartitionCtxt(partitionId);
+                                getPartitionCtxt(partitionId);
                     } else {
                         monitor = 
AutoscalerContext.getInstance().getLBMonitor(clusterId);
                         partitionContext = 
monitor.getNetworkPartitionCtxt(networkPartitionId).
-                                                                    
getPartitionCtxt(partitionId);
+                                getPartitionCtxt(partitionId);
                     }
                     partitionContext.addMemberStatsContext(new 
MemberStatsContext(memberId));
                     if (log.isDebugEnabled()) {
                         log.debug(String.format("Member has been moved as 
pending termination: " +
-                                                "[member] %s", memberId));
+                                "[member] %s", memberId));
                     }
                     
partitionContext.moveActiveMemberToTerminationPendingMembers(memberId);
 
@@ -553,7 +554,7 @@ public class AutoscalerTopologyEventReceiver implements 
Runnable {
             if (log.isDebugEnabled()) {
                 log.debug(String
                         .format("Application monitor thread has been started 
successfully: " +
-                                        "[application] %s ", 
application.getId()));
+                                "[application] %s ", application.getId()));
             }
         }
     }
@@ -569,23 +570,28 @@ public class AutoscalerTopologyEventReceiver implements 
Runnable {
             ApplicationMonitor applicationMonitor = null;
             int retries = 5;
             boolean success = false;
-             do {
-                 try {
-                     Thread.sleep(5000);
-                 } catch (InterruptedException e1) {
-                 }
+            do {
+                try {
+                    Thread.sleep(5000);
+                } catch (InterruptedException e1) {
+                }
                 try {
                     long start = System.currentTimeMillis();
-                    if(log.isDebugEnabled()) {
+                    if (log.isDebugEnabled()) {
                         log.debug("application monitor is going to be started 
for [application] " +
                                 application.getId());
                     }
                     applicationMonitor = 
AutoscalerUtil.getApplicationMonitor(application);
+
                     long end = System.currentTimeMillis();
-                    log.info("Time taken to start Napp monitor: " + (end - 
start)/1000);
+                    log.info("Time taken to start Napp monitor: " + (end - 
start) / 1000);
                     success = true;
                     //TODO exception handling
-                } catch (Exception e) {
+                } catch (DependencyBuilderException e) {
+                    String msg = "Application monitor creation failed for 
Application: ";
+                    log.warn(msg, e);
+                    retries--;
+                } catch (TopologyInConsistentException e) {
                     String msg = "Application monitor creation failed for 
Application: ";
                     log.warn(msg, e);
                     retries--;
@@ -600,11 +606,10 @@ public class AutoscalerTopologyEventReceiver implements 
Runnable {
             }
 
             AutoscalerContext.getInstance().addAppMonitor(applicationMonitor);
-            //TODO should start the appMonitor
 
             if (log.isInfoEnabled()) {
                 log.info(String.format("Application monitor has been added 
successfully: " +
-                                "[application] %s", 
applicationMonitor.getId()));
+                        "[application] %s", applicationMonitor.getId()));
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/81428ba2/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
index 0554406..bdf2099 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
@@ -21,8 +21,10 @@ package org.apache.stratos.autoscaler.monitor;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.AutoscalerContext;
+import org.apache.stratos.autoscaler.exception.DependencyBuilderException;
 import org.apache.stratos.autoscaler.exception.PartitionValidationException;
 import org.apache.stratos.autoscaler.exception.PolicyValidationException;
+import org.apache.stratos.autoscaler.exception.TopologyInConsistentException;
 import org.apache.stratos.autoscaler.grouping.dependency.DependencyBuilder;
 import org.apache.stratos.autoscaler.grouping.dependency.DependencyTree;
 import 
org.apache.stratos.autoscaler.grouping.dependency.context.ApplicationContext;
@@ -62,16 +64,17 @@ public abstract class Monitor implements EventHandler {
     //status of the monitor whether it is running/in_maintainable/terminated
     protected Status status;
 
-    public Monitor(ParentBehavior component) {
+    public Monitor(ParentBehavior component) throws DependencyBuilderException 
{
         aliasToGroupMonitorsMap = new HashMap<String, GroupMonitor>();
         clusterIdToClusterMonitorsMap = new HashMap<String, 
AbstractClusterMonitor>();
-        //preOrderTraverse = new LinkedList<String>();
         this.component = component;
+        //Building the dependency for this monitor within the immediate 
children
         dependencyTree = 
DependencyBuilder.getInstance().buildDependency(component);
     }
 
     /**
-     *
+     * Will monitor the immediate children upon any event triggers from 
parent/children
+     * @param statusEvent will be sent by parent/children with the current 
status
      */
     protected abstract void monitor(MonitorStatusEvent statusEvent);
 
@@ -81,7 +84,7 @@ public abstract class Monitor implements EventHandler {
      * it will get invoked when the monitor starts up only.
      * //TODO restarting the whole group
      */
-    public void startDependency() {
+    public void startDependency() throws TopologyInConsistentException {
         //start the first dependency
         List<ApplicationContext> applicationContexts = 
this.dependencyTree.getStarAbleDependencies();
         startDependency(applicationContexts);
@@ -93,9 +96,9 @@ public abstract class Monitor implements EventHandler {
      *
      * @param id alias/clusterId of which receive the activated event
      */
-    public void startDependency(String id) {
+    public boolean startDependency(String id) throws 
TopologyInConsistentException {
         List<ApplicationContext> applicationContexts = 
this.dependencyTree.getStarAbleDependencies(id);
-        startDependency(applicationContexts);
+        return startDependency(applicationContexts);
     }
 
     /**
@@ -103,10 +106,13 @@ public abstract class Monitor implements EventHandler {
      *
      * @param applicationContexts the found applicationContexts to be started
      */
-    private void startDependency(List<ApplicationContext> applicationContexts) 
{
+    private boolean startDependency(List<ApplicationContext> 
applicationContexts)
+                                throws TopologyInConsistentException{
         if (applicationContexts == null) {
             //all the groups/clusters have been started and waiting for 
activation
-            log.warn("There is no child found for the [group]: " + this.id);
+            log.info("There is no child found for the [group]: " + this.id);
+            return false;
+
         }
         for (ApplicationContext context : applicationContexts) {
             if (log.isDebugEnabled()) {
@@ -130,15 +136,19 @@ public abstract class Monitor implements EventHandler {
                         }
                         startClusterMonitor(this, cluster);
                     } else {
-                        log.warn("[Cluster] " + clusterId + " cannot be found 
in the " +
-                                "Topology for [service] " + serviceName);
+                        String msg = "[Cluster] " + clusterId + " cannot be 
found in the " +
+                                "Topology for [service] " + serviceName;
+                        throw new TopologyInConsistentException(msg);
                     }
                 } else {
-                    log.warn("[Service] " + serviceName + " cannot be found in 
the Topology");
+                    String msg = "[Service] " + serviceName + " cannot be 
found in the Topology";
+                    throw new TopologyInConsistentException(msg);
+
                 }
                 //TopologyManager.releaseReadLock();
             }
         }
+        return true;
 
     }
 
@@ -321,13 +331,14 @@ public abstract class Monitor implements EventHandler {
                     monitor.setParent(parent);
                     //monitor.addObserver(parent);
                     success = true;
-
-                } catch (Exception e) {
+                } catch (DependencyBuilderException e) {
+                    String msg = "Group monitor creation failed for group: " + 
dependency;
+                    log.warn(msg, e);
+                    retries--;
+                } catch (TopologyInConsistentException e) {
                     String msg = "Group monitor creation failed for group: " + 
dependency;
                     log.warn(msg, e);
                     retries--;
-
-
                 }
             } while (!success && retries != 0);
 
@@ -335,7 +346,8 @@ public abstract class Monitor implements EventHandler {
                 String msg = "Group monitor creation failed, even after 
retrying for 5 times, "
                         + "for group: " + dependency;
                 log.error(msg);
-                //TODO parent.notify();
+                //TODO parent.notify(); as it got to failed
+
                 throw new RuntimeException(msg);
             }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/81428ba2/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitor.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitor.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitor.java
index a0f0a39..fbfb2f0 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitor.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitor.java
@@ -20,6 +20,8 @@ package org.apache.stratos.autoscaler.monitor.application;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.autoscaler.exception.DependencyBuilderException;
+import org.apache.stratos.autoscaler.exception.TopologyInConsistentException;
 import 
org.apache.stratos.autoscaler.grouping.dependency.context.ApplicationContext;
 import org.apache.stratos.autoscaler.monitor.AbstractClusterMonitor;
 import org.apache.stratos.autoscaler.monitor.Monitor;
@@ -38,30 +40,14 @@ import java.util.List;
 public class ApplicationMonitor extends Monitor {
     private static final Log log = LogFactory.getLog(ApplicationMonitor.class);
 
-    public ApplicationMonitor(Application application) {
+    public ApplicationMonitor(Application application) throws 
DependencyBuilderException,
+                                                        
TopologyInConsistentException {
         super(application);
         this.id = application.getId();
+        //starting the first set of dependencies from its children
         startDependency();
     }
 
-    /*@Override
-    public void update(Observable observable, Object event) {
-        if (event instanceof MonitorStatusEvent1111) {
-            MonitorStatusEvent1111 statusEvent = (MonitorStatusEvent1111) 
event;
-            Status childStatus = statusEvent.getStatus();
-            String notifier = statusEvent.getNotifierId();
-            log.info(String.format("[Monitor] %s got notified from the [child] 
%s" +
-                    "on its state change from %s to %s", id, notifier, 
this.status, status));
-            if (childStatus == Status.Activated) {
-                //update the notifier as active in the dependency tree
-
-                //start the next dependency
-                startDependency(notifier);
-            }
-        }
-    }*/
-
-
     /**
      * To find all the clusters of an application
      *
@@ -234,7 +220,7 @@ public class ApplicationMonitor extends Monitor {
 
     @Override
     public void onEvent(MonitorStatusEvent statusEvent) {
-        this.monitor(statusEvent);
+        monitor(statusEvent);
     }
 
     @Override
@@ -242,9 +228,17 @@ public class ApplicationMonitor extends Monitor {
         ApplicationContext context = this.dependencyTree.
                 findApplicationContextWithId(statusEvent.getId());
         if(context.getStatusLifeCycle().isEmpty()) {
-            startDependency(statusEvent.getId());
+            try {
+                //if life cycle is empty, need to start the monitor
+                startDependency(statusEvent.getId());
+                //updating the life cycle
+                context.addStatusToLIfeCycle(statusEvent.getStatus());
+            } catch (TopologyInConsistentException e) {
+                //TODO revert the siblings
+                log.error(e);
+            }
         } else {
-            //TODO act based on life cyle events
+            //TODO act based on life cycle events
         }
 
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/81428ba2/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 735bcd6..2774f20 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
@@ -20,6 +20,8 @@ package org.apache.stratos.autoscaler.monitor.group;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.autoscaler.exception.DependencyBuilderException;
+import org.apache.stratos.autoscaler.exception.TopologyInConsistentException;
 import 
org.apache.stratos.autoscaler.grouping.dependency.context.ApplicationContext;
 import org.apache.stratos.autoscaler.monitor.EventHandler;
 import org.apache.stratos.autoscaler.monitor.Monitor;
@@ -38,63 +40,69 @@ import 
org.apache.stratos.messaging.event.application.status.StatusEvent;
 public class GroupMonitor extends Monitor implements EventHandler {
     private static final Log log = LogFactory.getLog(GroupMonitor.class);
 
+    //Parent monitor of this monitor
     private Monitor parent;
 
-    public GroupMonitor(Group group) {
+    /**
+     * Constructor of GroupMonitor
+     * @param group Takes the group from the Topology
+     * @throws DependencyBuilderException throws when couldn't build the 
Topology
+     * @throws TopologyInConsistentException throws when topology is 
inconsistent
+     */
+    public GroupMonitor(Group group) throws DependencyBuilderException,
+                                            TopologyInConsistentException {
         super(group);
         this.id = group.getAlias();
         startDependency();
 
     }
 
-    /*@Override
-    public void update(Observable observable, Object event) {
-        MonitorStatusEvent1111 statusEvent = (MonitorStatusEvent1111) event;
-        Status childStatus = statusEvent.getStatus();
-        String notifier = statusEvent.getNotifierId();
-        log.info(String.format("[Monitor] %s got notified from the [child] %s" 
+
-                "on its state change from %s to %s", id, notifier, 
this.status, status));
-        if (childStatus == Status.Activated) {
-            //start the next dependency
-            startDependency(notifier);
-        } else if(childStatus == Status.In_Maintenance) {
-
-        }
-    }*/
-
-
+    /**
+     * Will set the status of the monitor based on Topology Group status/child 
status like scaling
+     * @param status
+     */
     public void setStatus(Status status) {
         log.info(String.format("[Monitor] %s is notifying the parent" +
                 "on its state change from %s to %s", id, this.status, status));
         this.status = status;
         //notifying the parent
         MonitorStatusEventBuilder.handleGroupStatusEvent(this.parent, 
this.status, this.id);
-        //setChanged();
-        //notifyObservers(new MonitorStatusEvent1111(status, id));
     }
 
     @Override
     public void onEvent(MonitorStatusEvent statusEvent) {
-        this.monitor(statusEvent);
-    }
-
-    public Monitor getParent() {
-        return parent;
-    }
-
-    public void setParent(Monitor parent) {
-        this.parent = parent;
+        monitor(statusEvent);
     }
 
     @Override
     protected void monitor(MonitorStatusEvent statusEvent) {
         ApplicationContext context = this.dependencyTree.
-                                            
findApplicationContextWithId(statusEvent.getId());
+                findApplicationContextWithId(statusEvent.getId());
         if(context.getStatusLifeCycle().isEmpty()) {
-            startDependency(statusEvent.getId());
+            try {
+                //if life cycle is empty, need to start the monitor
+                boolean startDep = startDependency(statusEvent.getId());
+                //updating the life cycle
+                context.addStatusToLIfeCycle(statusEvent.getStatus());
+                if(!startDep) {
+                    
+                }
+            } catch (TopologyInConsistentException e) {
+                //TODO revert the siblings and notify parent, change a flag 
for reverting/un-subscription
+                log.error(e);
+            }
         } else {
-            //TODO act based on life cyle events
+            //TODO act based on life cycle events
         }
 
     }
+
+    public Monitor getParent() {
+        return parent;
+    }
+
+    public void setParent(Monitor parent) {
+        this.parent = parent;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/81428ba2/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
index 6a05371..5fd74ae 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
@@ -28,8 +28,10 @@ import 
org.apache.stratos.autoscaler.NetworkPartitionLbHolder;
 import org.apache.stratos.autoscaler.PartitionContext;
 import 
org.apache.stratos.autoscaler.client.cloud.controller.CloudControllerClient;
 import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
+import org.apache.stratos.autoscaler.exception.DependencyBuilderException;
 import org.apache.stratos.autoscaler.exception.PartitionValidationException;
 import org.apache.stratos.autoscaler.exception.PolicyValidationException;
+import org.apache.stratos.autoscaler.exception.TopologyInConsistentException;
 import org.apache.stratos.autoscaler.monitor.application.ApplicationMonitor;
 import org.apache.stratos.autoscaler.monitor.cluster.ClusterMonitor;
 import org.apache.stratos.autoscaler.monitor.group.GroupMonitor;
@@ -320,20 +322,26 @@ public class AutoscalerUtil {
         return clusterMonitor;
     }
 
-    public static GroupMonitor getGroupMonitor(Group group) {
+    //TODO moving it into factory class
+    public static GroupMonitor getGroupMonitor(Group group) throws 
DependencyBuilderException,
+                                                            
TopologyInConsistentException {
         GroupMonitor groupMonitor =
                 new GroupMonitor(group);
         return groupMonitor;
 
     }
 
-    public static ApplicationMonitor getApplicationMonitor(Application 
application) {
+    public static ApplicationMonitor getApplicationMonitor(Application 
application)
+                                            throws DependencyBuilderException,
+                                            TopologyInConsistentException {
         ApplicationMonitor applicationMonitor =
                 new ApplicationMonitor(application);
         return applicationMonitor;
 
     }
 
+
+
     public static Properties getProperties(final OMElement elt) {
 
         Iterator<?> it = elt.getChildrenWithName(new 
QName(AutoScalerConstants.PROPERTY_ELEMENT));

Reply via email to