You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by la...@apache.org on 2014/12/14 12:37:11 UTC

[4/5] stratos git commit: Adding hasScalingDependents to all the monitor classes

Adding hasScalingDependents to all the monitor classes


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

Branch: refs/heads/4.1.0-test
Commit: 5076a648c0c3884626065cd757a123b4157aceb8
Parents: 5ee5b1e
Author: Lahiru Sandaruwan <la...@apache.org>
Authored: Sun Dec 14 16:54:56 2014 +0530
Committer: Lahiru Sandaruwan <la...@apache.org>
Committed: Sun Dec 14 17:04:48 2014 +0530

----------------------------------------------------------------------
 .../stratos/autoscaler/monitor/Monitor.java     | 21 --------------------
 .../monitor/cluster/ClusterMonitorFactory.java  | 15 +++++++-------
 .../cluster/KubernetesClusterMonitor.java       |  4 ++--
 .../KubernetesServiceClusterMonitor.java        |  4 ++--
 .../monitor/cluster/VMClusterMonitor.java       | 19 +++++++++++++-----
 .../monitor/component/GroupMonitor.java         | 11 +++++-----
 6 files changed, 31 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/5076a648/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 9589719..25e54a1 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
@@ -18,7 +18,6 @@
  */
 package org.apache.stratos.autoscaler.monitor;
 
-import org.apache.stratos.autoscaler.exception.application.MonitorNotFoundException;
 import org.apache.stratos.autoscaler.monitor.component.ParentComponentMonitor;
 import org.apache.stratos.messaging.domain.instance.Instance;
 
@@ -39,8 +38,6 @@ public abstract class Monitor implements EventHandler {
     protected ParentComponentMonitor parent;
     //has startup dependents
     protected boolean hasStartupDependents;
-    //has scaling dependents
-    protected boolean hasGroupScalingDependent;
     //monitors map, key=InstanceId and value=ClusterInstance/GroupInstance/ApplicationInstance
     protected Map<String, Instance> instanceIdToInstanceMap;
 
@@ -117,15 +114,6 @@ public abstract class Monitor implements EventHandler {
     }
 
     /**
-     * Return whether this monitor has scaling dependencies
-     *
-     * @return startup dependencies exist or not
-     */
-    public boolean hasGroupScalingDependent() {
-        return hasGroupScalingDependent;
-    }
-
-    /**
      * To set whether monitor has any startup dependencies
      *
      * @param hasDependent
@@ -135,15 +123,6 @@ public abstract class Monitor implements EventHandler {
     }
 
     /**
-     * To set whether monitor has any scaling dependencies
-     *
-     * @param hasDependent
-     */
-    public void setHasGroupScalingDependent(boolean hasDependent) {
-        this.hasGroupScalingDependent = hasDependent;
-    }
-
-    /**
      * This will add the instance
      *
      * @param instance instance to be added

http://git-wip-us.apache.org/repos/asf/stratos/blob/5076a648/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitorFactory.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitorFactory.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitorFactory.java
index cba5357..8ed3e0b 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitorFactory.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitorFactory.java
@@ -43,7 +43,7 @@ public class ClusterMonitorFactory {
      * @throws PolicyValidationException    when deployment policy is not valid
      * @throws PartitionValidationException when partition is not valid
      */
-    public static AbstractClusterMonitor getMonitor(Cluster cluster)
+    public static AbstractClusterMonitor getMonitor(Cluster cluster, boolean hasScalingDependents)
             throws PolicyValidationException, PartitionValidationException {
 
         AbstractClusterMonitor clusterMonitor;
@@ -52,20 +52,20 @@ public class ClusterMonitorFactory {
 //////        } else if (cluster.isLbCluster()) {
 //////            clusterMonitor = getVMLbClusterMonitor(cluster);
 //        } else {
-            clusterMonitor = getVMClusterMonitor(cluster);
+            clusterMonitor = getVMClusterMonitor(cluster, hasScalingDependents);
 //        }
 
         return clusterMonitor;
     }
 
-    private static VMClusterMonitor getVMClusterMonitor(Cluster cluster)
+    private static VMClusterMonitor getVMClusterMonitor(Cluster cluster, boolean hasScalingDependents)
             throws PolicyValidationException, PartitionValidationException {
 
         if (null == cluster) {
             return null;
         }
 
-        VMClusterMonitor clusterMonitor = new VMClusterMonitor(cluster);
+        VMClusterMonitor clusterMonitor = new VMClusterMonitor(cluster, hasScalingDependents);
 
         // find lb reference type
         java.util.Properties props = cluster.getProperties();
@@ -156,7 +156,7 @@ public class ClusterMonitorFactory {
 //                cluster.getClusterId(), cluster.getServiceName(),  autoscalePolicy, minReplicas, maxReplicas);
 
 
-        KubernetesClusterMonitor dockerClusterMonitor = new KubernetesClusterMonitor(cluster);
+//        KubernetesClusterMonitor dockerClusterMonitor = new KubernetesClusterMonitor(cluster);
 
         //populate the members after restarting
 //        for (Member member : cluster.getMembers()) {
@@ -201,7 +201,8 @@ public class ClusterMonitorFactory {
 //            }
 //        }
 
-        log.info("KubernetesServiceClusterMonitor created: " + dockerClusterMonitor.toString());
-        return dockerClusterMonitor;
+//        log.info("KubernetesServiceClusterMonitor created: " + dockerClusterMonitor.toString());
+//        return dockerClusterMonitor;
+        return null;
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/5076a648/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/KubernetesClusterMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/KubernetesClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/KubernetesClusterMonitor.java
index c2b0f31..e82bc52 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/KubernetesClusterMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/KubernetesClusterMonitor.java
@@ -64,9 +64,9 @@ public class KubernetesClusterMonitor extends VMClusterMonitor {
 
 //    private StatefulKnowledgeSession dependentScaleCheckKnowledgeSession;
 
-    protected KubernetesClusterMonitor(Cluster cluster) {
+    protected KubernetesClusterMonitor(Cluster cluster, boolean hasScalingDependents) {
 
-        super(cluster);
+        super(cluster, hasScalingDependents);
 
         autoscalerRuleEvaluator = new AutoscalerRuleEvaluator();
         autoscalerRuleEvaluator.parseAndBuildKnowledgeBaseForDroolsFile(StratosConstants.CONTAINER_OBSOLETE_CHECK_DROOL_FILE);

http://git-wip-us.apache.org/repos/asf/stratos/blob/5076a648/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/KubernetesServiceClusterMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/KubernetesServiceClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/KubernetesServiceClusterMonitor.java
index d456a43..1934183 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/KubernetesServiceClusterMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/KubernetesServiceClusterMonitor.java
@@ -46,8 +46,8 @@ public final class KubernetesServiceClusterMonitor extends KubernetesClusterMoni
 
     private String lbReferenceType;
 
-    public KubernetesServiceClusterMonitor(Cluster cluster) {
-        super(cluster);
+    public KubernetesServiceClusterMonitor(Cluster cluster, boolean hasScalingDependents) {
+        super(cluster, hasScalingDependents);
         readConfigurations();
     }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/5076a648/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java
index f21bac8..606f3a5 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java
@@ -76,10 +76,13 @@ public class VMClusterMonitor extends AbstractClusterMonitor {
     private boolean hasPrimary;
     private float scalingFactorBasedOnDependencies = 1.0f;
 
-    protected VMClusterMonitor(Cluster cluster) {
+    //has scaling dependents
+    private boolean hasScalingDependents;
+
+    protected VMClusterMonitor(Cluster cluster, boolean hasScalingDependents) {
         super(cluster);
         this.networkPartitionIdToClusterLevelNetworkPartitionCtxts = new HashMap<String, ClusterLevelNetworkPartitionContext>();
-
+        this.hasScalingDependents = hasScalingDependents;
         readConfigurations();
         autoscalerRuleEvaluator = new AutoscalerRuleEvaluator();
         autoscalerRuleEvaluator.parseAndBuildKnowledgeBaseForDroolsFile(StratosConstants.VM_OBSOLETE_CHECK_DROOL_FILE);
@@ -1137,18 +1140,21 @@ public class VMClusterMonitor extends AbstractClusterMonitor {
             partitionId = parentMonitorInstance.getPartitionId();
         }
         if (parentMonitorInstance != null) {
+
             ClusterInstance clusterInstance = cluster.getInstanceContexts(parentInstanceId);
             if (clusterInstance != null) {
+
                 // Cluster instance is already there. No need to create one.
                 VMClusterContext clusterContext = (VMClusterContext) this.getClusterContext();
                 if(clusterContext == null) {
-                    clusterContext =
-                            ClusterContextFactory.getVMClusterContext(clusterInstance.getInstanceId(), cluster);
+
+                    clusterContext = ClusterContextFactory.getVMClusterContext(clusterInstance.getInstanceId(), cluster,
+                                    this.hasScalingDependents);
                     this.setClusterContext(clusterContext);
                 }
 
                 // create VMClusterContext and then add all the instanceContexts
-                clusterContext.addInstanceContext(parentInstanceId, cluster, this.hasGroupScalingDependent());
+                clusterContext.addInstanceContext(parentInstanceId, cluster, this.hasScalingDependents);
                 if (this.getInstance(clusterInstance.getInstanceId()) == null) {
                     this.addInstance(clusterInstance);
                 }
@@ -1223,4 +1229,7 @@ public class VMClusterMonitor extends AbstractClusterMonitor {
     }
 
 
+    public boolean hasScalingDependents() {
+        return hasScalingDependents;
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/5076a648/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
index 92867e9..1ed28d0 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
@@ -22,8 +22,6 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.algorithm.AutoscaleAlgorithm;
 import org.apache.stratos.autoscaler.applications.ApplicationHolder;
-import org.apache.stratos.autoscaler.applications.dependency.context.ApplicationChildContext;
-import org.apache.stratos.autoscaler.applications.dependency.context.GroupChildContext;
 import org.apache.stratos.autoscaler.applications.topic.ApplicationBuilder;
 import org.apache.stratos.autoscaler.context.group.GroupInstanceContext;
 import org.apache.stratos.autoscaler.context.partition.GroupLevelPartitionContext;
@@ -50,11 +48,9 @@ import org.apache.stratos.messaging.domain.topology.ClusterStatus;
 import org.apache.stratos.messaging.domain.topology.lifecycle.LifeCycleState;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 /**
  * This is GroupMonitor to monitor the group which consists of
@@ -74,6 +70,8 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
     //Monitoring interval of the monitor
     private int monitoringIntervalMilliseconds = 60000;     //TODO get this from config file
 
+    //has scaling dependents
+    protected boolean hasScalingDependents;
     /**
      * Constructor of GroupMonitor
      *
@@ -81,11 +79,12 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
      * @throws DependencyBuilderException    throws when couldn't build the Topology
      * @throws TopologyInConsistentException throws when topology is inconsistent
      */
-    public GroupMonitor(Group group, String appId, List<String> parentInstanceId) throws DependencyBuilderException,
+    public GroupMonitor(Group group, String appId, List<String> parentInstanceId, boolean hasScalingDependents) throws DependencyBuilderException,
             TopologyInConsistentException {
         super(group);
         this.appId = appId;
         networkPartitionCtxts = new HashMap<String, GroupLevelNetworkPartitionContext>();
+        this.hasScalingDependents = hasScalingDependents;
     }
 
     @Override
@@ -251,7 +250,7 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
     @Override
     public void onChildScalingEvent(MonitorScalingEvent scalingEvent) {
 
-        if (hasGroupScalingDependent) {
+        if (hasScalingDependents) {
 
             //notify parent
             parent.onChildScalingEvent(scalingEvent);