You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by re...@apache.org on 2015/06/19 15:00:41 UTC

[1/2] stratos git commit: fixing group scaling issue and undeployment issue

Repository: stratos
Updated Branches:
  refs/heads/master e6133c809 -> dbfc27fe8


fixing group scaling issue and undeployment issue


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

Branch: refs/heads/master
Commit: 6a82e67685445560c7272508c27bd719e1beeb48
Parents: afbf95a
Author: reka <rt...@gmail.com>
Authored: Fri Jun 19 18:30:03 2015 +0530
Committer: reka <rt...@gmail.com>
Committed: Fri Jun 19 18:30:03 2015 +0530

----------------------------------------------------------------------
 .../partition/ClusterLevelPartitionContext.java | 16 +++++-
 .../monitor/cluster/ClusterMonitor.java         | 60 ++++++--------------
 .../monitor/component/GroupMonitor.java         | 27 ++++++++-
 .../component/ParentComponentMonitor.java       |  2 +-
 4 files changed, 56 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/6a82e676/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/ClusterLevelPartitionContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/ClusterLevelPartitionContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/ClusterLevelPartitionContext.java
index c6a1626..92626e0 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/ClusterLevelPartitionContext.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/ClusterLevelPartitionContext.java
@@ -29,7 +29,9 @@ import org.apache.stratos.cloud.controller.stub.domain.MemberContext;
 import org.apache.stratos.common.client.CloudControllerServiceClient;
 import org.apache.stratos.common.constants.StratosConstants;
 import org.apache.stratos.common.partition.PartitionRef;
+import org.apache.stratos.messaging.domain.topology.Cluster;
 import org.apache.stratos.messaging.domain.topology.ClusterStatus;
+import org.apache.stratos.messaging.domain.topology.Service;
 import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
 
 import java.io.Serializable;
@@ -659,13 +661,21 @@ public class ClusterLevelPartitionContext extends PartitionContext implements Se
                         String clusterInstanceId = pendingMember.getClusterInstanceId();
                         String clusterId = pendingMember.getClusterId();
                         String serviceName = pendingMember.getCartridgeType();
-                        ClusterStatus status = TopologyManager.getTopology().
-                                getService(serviceName).getCluster(clusterId).
-                                getInstanceContexts(clusterInstanceId).getStatus();
+                         Service service = TopologyManager.getTopology().
+                                getService(serviceName);
+
+                        ClusterStatus status = ClusterStatus.Terminated;
+                        if(service != null) {
+                            Cluster cluster = service.getCluster(clusterId);
+                            if(cluster != null) {
+                                status = cluster. getInstanceContexts(clusterInstanceId).getStatus();
+                            }
+                        }
 
                         if (pendingMember == null) {
                             continue;
                         }
+
                         long pendingTime = System.currentTimeMillis() - pendingMember.getInitTime();
                         if (pendingTime >= expiryTime || status.equals(ClusterStatus.Terminating)) {
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/6a82e676/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
index 7613ad6..945c3e1 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
@@ -74,10 +74,7 @@ import org.drools.runtime.rule.FactHandle;
 
 import java.rmi.RemoteException;
 import java.util.*;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.RejectedExecutionException;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.*;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
@@ -92,12 +89,13 @@ public class ClusterMonitor extends Monitor {
 
     protected boolean hasFaultyMember = false;
     protected ClusterContext clusterContext;
+    // future to cancel it when destroying monitors
+    private ScheduledFuture<?> schedulerFuture;
     protected String serviceType;
     private AtomicBoolean monitoringStarted;
     protected String clusterId;
     private Cluster cluster;
     private int monitoringIntervalMilliseconds;
-    private boolean isDestroyed;
     //has scaling dependents
     private boolean hasScalingDependents;
     private boolean groupScalingEnabledSubtree;
@@ -130,7 +128,8 @@ public class ClusterMonitor extends Monitor {
     }
 
     public void startScheduler() {
-        scheduler.scheduleAtFixedRate(this, 0, getMonitorIntervalMilliseconds(), TimeUnit.MILLISECONDS);
+        schedulerFuture = scheduler.scheduleAtFixedRate(this, 0,
+                getMonitorIntervalMilliseconds(), TimeUnit.MILLISECONDS);
     }
 
     @Override
@@ -205,14 +204,6 @@ public class ClusterMonitor extends Monitor {
         this.monitoringIntervalMilliseconds = monitorIntervalMilliseconds;
     }
 
-    public boolean isDestroyed() {
-        return isDestroyed;
-    }
-
-    public void setDestroyed(boolean isDestroyed) {
-        this.isDestroyed = isDestroyed;
-    }
-
     public void setHasFaultyMember(boolean hasFaultyMember) {
         this.hasFaultyMember = hasFaultyMember;
     }
@@ -304,22 +295,18 @@ public class ClusterMonitor extends Monitor {
 
     @Override
     public void run() {
-        while (!isDestroyed()) {
-            try {
-                if (log.isDebugEnabled()) {
-                    log.debug("Cluster monitor is running.. " + this.toString());
-                }
-                monitor();
-            } catch (Exception e) {
-                log.error("Cluster monitor: Monitor failed." + this.toString(), e);
-            }
-            try {
-                Thread.sleep(getMonitorIntervalMilliseconds());
-            } catch (InterruptedException ignore) {
+        try {
+            if (log.isDebugEnabled()) {
+                log.debug("Cluster monitor is running.. " + this.toString());
             }
+            monitor();
+        } catch (Exception e) {
+            log.error("Cluster monitor: Monitor failed." + this.toString(), e);
+        }
+        try {
+            Thread.sleep(getMonitorIntervalMilliseconds());
+        } catch (InterruptedException ignore) {
         }
-
-
     }
 
     private boolean isPrimaryMember(MemberContext memberContext) {
@@ -532,22 +519,11 @@ public class ClusterMonitor extends Monitor {
 
     @Override
     public void destroy() {
-        for (ClusterLevelNetworkPartitionContext networkPartitionContext : getNetworkPartitionCtxts()) {
-
-            Collection<InstanceContext> clusterInstanceContexts = networkPartitionContext.
-                    getInstanceIdToInstanceContextMap().values();
-
-            for (final InstanceContext pInstanceContext : clusterInstanceContexts) {
-                ClusterInstanceContext instanceContext = (ClusterInstanceContext) pInstanceContext;
-                instanceContext.getMinCheckKnowledgeSession().dispose();
-                instanceContext.getObsoleteCheckKnowledgeSession().dispose();
-                instanceContext.getScaleCheckKnowledgeSession().dispose();
-            }
-        }
+        //shutting down the scheduler
+        schedulerFuture.cancel(true);
 
-        setDestroyed(true);
         if (log.isDebugEnabled()) {
-            log.debug("ClusterMonitor Drools session has been disposed. " + this.toString());
+            log.debug("ClusterMonitor task has been stopped " + this.toString());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/6a82e676/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 8f0fd6d..822b625 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
@@ -183,6 +183,12 @@ public class GroupMonitor extends ParentComponentMonitor {
                                             getActiveInstancesCount();
                                     if (activeAppInstances > 0) {
                                         //Creating new group instance based on the existing parent instances
+                                        if(log.isDebugEnabled()) {
+                                            log.debug("Creating a group instance of [application] "
+                                                    + appId + " [group] " + id +
+                                                    " as the the minimum required instances not met");
+
+                                        }
                                         createInstanceOnDemand(parentInstanceContext.getId());
                                     }
                                 }
@@ -200,6 +206,12 @@ public class GroupMonitor extends ParentComponentMonitor {
                             for (int i = 0; i < instancesToBeTerminated; i++) {
                                 InstanceContext instanceContext = contextList.get(i);
                                 //scale down only when extra instances found
+                                if(log.isDebugEnabled()) {
+                                    log.debug("Terminating a group instance of [application] "
+                                            + appId + " [group] " + id + " as it exceeded the " +
+                                            "maximum no of instances by " + instancesToBeTerminated);
+
+                                }
                                 handleScalingDownBeyondMin(instanceContext,
                                         networkPartitionContext, true);
 
@@ -312,9 +324,8 @@ public class GroupMonitor extends ParentComponentMonitor {
                 //one of the child is loaded and max out.
                 // Hence creating new group instance
                 if (log.isDebugEnabled()) {
-                    log.debug("Handling group scaling for the [group] " + id +
-                            "upon a max out event from " +
-                            "the children");
+                    log.debug("Handling group scaling for the [application] " + appId + " [group] "
+                            + id + " upon a max out event from the children");
                 }
                 boolean createOnDemand = createInstanceOnDemand(parentInstanceId);
                 if (!createOnDemand) {
@@ -560,6 +571,10 @@ public class GroupMonitor extends ParentComponentMonitor {
         } else if (statusEvent.getStatus() == ClusterStatus.Created ||
                 statusEvent.getStatus() == GroupStatus.Created) {
             //starting a new instance of this monitor
+            if(log.isDebugEnabled()) {
+                log.debug("Creating a [group-instance] for [application] " + appId + " [group] " +
+                id + " as the parent scaled by group or application bursting");
+            }
             createInstanceOnDemand(statusEvent.getInstanceId());
         }
     }
@@ -816,6 +831,9 @@ public class GroupMonitor extends ParentComponentMonitor {
         boolean initialStartup = true;
         List<String> instanceIdsToStart = new ArrayList<String>();
 
+        log.info("Creating a group instance of [application] " + appId + " [group] " + id +
+                " in order to satisfy the minimum required instances");
+
         for (String parentInstanceId : parentInstanceIds) {
             // Get parent instance context
             Instance parentInstanceContext = getParentInstanceContext(parentInstanceId);
@@ -923,6 +941,9 @@ public class GroupMonitor extends ParentComponentMonitor {
         Group group = ApplicationHolder.getApplications().
                 getApplication(this.appId).getGroupRecursively(this.id);
 
+        log.info("Creating a group instance of [application] " + appId + " [group] " + id +
+                " in order to satisfy the demand on scaling for " +
+                "[parent-instance] " + parentInstanceId);
         // Get existing or create new GroupLevelNetworkPartitionContext
         ParentLevelNetworkPartitionContext parentLevelNetworkPartitionContext =
                 getGroupLevelNetworkPartitionContext(group.getUniqueIdentifier(),

http://git-wip-us.apache.org/repos/asf/stratos/blob/6a82e676/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java
index 6efa726..e4eea04 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java
@@ -311,7 +311,7 @@ public abstract class ParentComponentMonitor extends Monitor {
             }
         }
         //calling monitor to go for group scaling or notify the parent
-        this.monitor();
+        //this.monitor();
 
     }
 


[2/2] stratos git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/stratos

Posted by re...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/stratos


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

Branch: refs/heads/master
Commit: dbfc27fe81762cc1120e0028f5b8e17eaea8815c
Parents: 6a82e67 e6133c8
Author: reka <rt...@gmail.com>
Authored: Fri Jun 19 18:30:20 2015 +0530
Committer: reka <rt...@gmail.com>
Committed: Fri Jun 19 18:30:20 2015 +0530

----------------------------------------------------------------------
 .../services/impl/AutoscalerServiceImpl.java    |  24 ++-
 .../rest/endpoint/api/StratosApiV41.java        |  29 ++--
 .../rest/endpoint/api/StratosApiV41Utils.java   | 150 +++++++++----------
 .../exception/InvalidCartridgeException.java    |  70 +++++++++
 4 files changed, 180 insertions(+), 93 deletions(-)
----------------------------------------------------------------------