Return-Path: X-Original-To: apmail-brooklyn-commits-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8027318BB8 for ; Wed, 24 Jun 2015 08:05:45 +0000 (UTC) Received: (qmail 51705 invoked by uid 500); 24 Jun 2015 08:05:45 -0000 Delivered-To: apmail-brooklyn-commits-archive@brooklyn.apache.org Received: (qmail 51668 invoked by uid 500); 24 Jun 2015 08:05:45 -0000 Mailing-List: contact commits-help@brooklyn.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.incubator.apache.org Delivered-To: mailing list commits@brooklyn.incubator.apache.org Received: (qmail 51659 invoked by uid 99); 24 Jun 2015 08:05:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Jun 2015 08:05:45 +0000 X-ASF-Spam-Status: No, hits=-2001.4 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 24 Jun 2015 08:03:26 +0000 Received: (qmail 50170 invoked by uid 99); 24 Jun 2015 08:05:13 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Jun 2015 08:05:13 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id BAC45E364B; Wed, 24 Jun 2015 08:05:13 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: heneveld@apache.org To: commits@brooklyn.incubator.apache.org Date: Wed, 24 Jun 2015 08:05:26 -0000 Message-Id: <572657e07509439e9496fbdbac37a517@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [15/22] incubator-brooklyn git commit: set AutoScalerPolicy to have min size default of 1 not 0 X-Virus-Checked: Checked by ClamAV on apache.org 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 Authored: Mon Jun 22 23:11:09 2015 -0700 Committer: Alex Heneveld 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 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.builder().name("Auto-scaler") + .description("Auto-scaler recommending resize from "+currentPoolSize+" to "+desiredPoolSize) + .tag(BrooklynTaskTags.NON_TRANSIENT_TASK_TAG) + .body(new Callable() { + @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(); } /**