brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [15/22] incubator-brooklyn git commit: set AutoScalerPolicy to have min size default of 1 not 0
Date Wed, 24 Jun 2015 08:05:26 GMT
set AutoScalerPolicy to have min size default of 1 not 0

else it might scale to 0 if the metric hits 0, and then it won't usually scale back out as
nothing is generating load!


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

Branch: refs/heads/master
Commit: 48974708b40d73fc4b901268974eaf8c5bf2a4f0
Parents: 7ba5833
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Mon Jun 22 23:11:09 2015 -0700
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Wed Jun 24 00:40:34 2015 -0700

----------------------------------------------------------------------
 .../policy/autoscaling/AutoScalerPolicy.java    | 24 ++++++++++++++++----
 1 file changed, 19 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/48974708/policy/src/main/java/brooklyn/policy/autoscaling/AutoScalerPolicy.java
----------------------------------------------------------------------
diff --git a/policy/src/main/java/brooklyn/policy/autoscaling/AutoScalerPolicy.java b/policy/src/main/java/brooklyn/policy/autoscaling/AutoScalerPolicy.java
index b693955..f453aa5 100644
--- a/policy/src/main/java/brooklyn/policy/autoscaling/AutoScalerPolicy.java
+++ b/policy/src/main/java/brooklyn/policy/autoscaling/AutoScalerPolicy.java
@@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
 import groovy.lang.Closure;
 
 import java.util.Map;
+import java.util.concurrent.Callable;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ThreadFactory;
@@ -35,6 +36,8 @@ import org.slf4j.LoggerFactory;
 import brooklyn.catalog.Catalog;
 import brooklyn.config.ConfigKey;
 import brooklyn.entity.Entity;
+import brooklyn.entity.basic.BrooklynTaskTags;
+import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.EntityLocal;
 import brooklyn.entity.trait.Resizable;
 import brooklyn.entity.trait.Startable;
@@ -51,6 +54,7 @@ import brooklyn.policy.loadbalancing.LoadBalancingPolicy;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.flags.SetFromFlag;
 import brooklyn.util.flags.TypeCoercions;
+import brooklyn.util.task.Tasks;
 import brooklyn.util.time.Duration;
 
 import com.google.common.base.Function;
@@ -88,7 +92,7 @@ public class AutoScalerPolicy extends AbstractPolicy {
         private Entity entityWithMetric;
         private Number metricUpperBound;
         private Number metricLowerBound;
-        private int minPoolSize = 0;
+        private int minPoolSize = 1;
         private int maxPoolSize = Integer.MAX_VALUE;
         private Integer resizeDownIterationIncrement;
         private Integer resizeDownIterationMax;
@@ -357,7 +361,7 @@ public class AutoScalerPolicy extends AbstractPolicy {
     @SetFromFlag("minPoolSize")
     public static final ConfigKey<Integer> MIN_POOL_SIZE = BasicConfigKey.builder(Integer.class)
             .name("autoscaler.minPoolSize")
-            .defaultValue(0)
+            .defaultValue(1)
             .reconfigurable(true)
             .build();
     
@@ -1034,7 +1038,7 @@ public class AutoScalerPolicy extends AbstractPolicy {
     private void resizeNow() {
         long currentPoolSize = getCurrentSizeOperator().apply(poolEntity);
         CalculatedDesiredPoolSize calculatedDesiredPoolSize = calculateDesiredPoolSize(currentPoolSize);
-        long desiredPoolSize = calculatedDesiredPoolSize.size;
+        final long desiredPoolSize = calculatedDesiredPoolSize.size;
         boolean stable = calculatedDesiredPoolSize.stable;
         
         if (!stable) {
@@ -1054,8 +1058,18 @@ public class AutoScalerPolicy extends AbstractPolicy {
         if (LOG.isDebugEnabled()) LOG.debug("{} requesting resize to {}; current {}, min
{}, max {}", 
                 new Object[] {this, desiredPoolSize, currentPoolSize, getMinPoolSize(), getMaxPoolSize()});
         
-        // TODO Should we use int throughout, rather than casting here?
-        getResizeOperator().resize(poolEntity, (int) desiredPoolSize);
+        Entities.submit(entity, Tasks.<Void>builder().name("Auto-scaler")
+            .description("Auto-scaler recommending resize from "+currentPoolSize+" to "+desiredPoolSize)
+            .tag(BrooklynTaskTags.NON_TRANSIENT_TASK_TAG)
+            .body(new Callable<Void>() {
+                @Override
+                public Void call() throws Exception {
+                    // TODO Should we use int throughout, rather than casting here?
+                    getResizeOperator().resize(poolEntity, (int) desiredPoolSize);
+                    return null;
+                }
+            }).build())
+            .blockUntilEnded();
     }
     
     /**


Mime
View raw message