You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ma...@apache.org on 2013/11/07 05:55:44 UTC
git commit: Make scheduler values configurable
Updated Branches:
refs/heads/master ec60dd817 -> f7086d899
Make scheduler values configurable
Signed-off-by: Manula Thantriwatte <ma...@wso2.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/f7086d89
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/f7086d89
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/f7086d89
Branch: refs/heads/master
Commit: f7086d89947195094ceea83c58e6efd2cf36d629
Parents: ec60dd8
Author: Melan Nimesh <me...@gmail.com>
Authored: Wed Nov 6 18:14:15 2013 +0530
Committer: Manula Thantriwatte <ma...@wso2.com>
Committed: Thu Nov 7 10:25:06 2013 +0530
----------------------------------------------------------------------
.../org.apache.stratos.autoscaler/pom.xml | 5 ++
.../apache/stratos/autoscaler/Constants.java | 6 ++
.../autoscaler/rule/ExecutorTaskScheduler.java | 17 +++++-
.../stratos/autoscaler/util/ConfUtil.java | 63 ++++++++++++++++++++
.../distribution/src/main/conf/autoscaler.xml | 29 +++++++++
5 files changed, 117 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f7086d89/components/org.apache.stratos.autoscaler/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/pom.xml b/components/org.apache.stratos.autoscaler/pom.xml
index 122885b..2c54d36 100644
--- a/components/org.apache.stratos.autoscaler/pom.xml
+++ b/components/org.apache.stratos.autoscaler/pom.xml
@@ -50,6 +50,11 @@
<artifactId>xstream</artifactId>
<version>1.4.1</version>
</dependency>
+ <dependency>
+ <groupId>commons-configuration</groupId>
+ <artifactId>commons-configuration</artifactId>
+ <version>1.9</version>
+ </dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr</artifactId>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f7086d89/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/Constants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/Constants.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/Constants.java
index 18e215e..0dc54ea 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/Constants.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/Constants.java
@@ -12,6 +12,12 @@ public class Constants {
public static String AVERAGE_REQUESTS_IN_FLIGHT = "average_requests_in_flight";
public static String SECOND_DERIVATIVE_OF_REQUESTS_IN_FLIGHT = "second_derivative_of_requests_in_flight";
+ //scheduler
+ public static final int SCHEDULE_DEFAULT_INITIAL_DELAY = 30;
+ public static final int SCHEDULE_DEFAULT_PERIOD = 15;
+
+ public static final String AUTOSCALER_CONFIG_FILE_NAME = "autoscaler.xml";
+
// public void a(){
// Cluster cluster = null;
//// log.info("cluster " + clusterId);
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f7086d89/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/ExecutorTaskScheduler.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/ExecutorTaskScheduler.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/ExecutorTaskScheduler.java
index cd1972f..9d78de4 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/ExecutorTaskScheduler.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/ExecutorTaskScheduler.java
@@ -19,10 +19,13 @@
package org.apache.stratos.autoscaler.rule;
+import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.autoscaler.AutoscalerContext;
+import org.apache.stratos.autoscaler.Constants;
import org.apache.stratos.autoscaler.message.receiver.TopologyManager;
+import org.apache.stratos.autoscaler.util.ConfUtil;
import org.apache.stratos.messaging.domain.topology.Cluster;
import org.apache.stratos.messaging.domain.topology.Service;
@@ -36,7 +39,16 @@ import java.util.concurrent.TimeUnit;
*/
public class ExecutorTaskScheduler {
private static final Log log = LogFactory.getLog(ExecutorTaskScheduler.class);
-
+
+ private static int initialDelay;
+ private static int period;
+
+ public ExecutorTaskScheduler() {
+ XMLConfiguration conf = ConfUtil.getInstance().getConfiguration();
+ initialDelay = conf.getInt("autoscaler.rulesEvaluator.schedule.initialDelay", Constants.SCHEDULE_DEFAULT_INITIAL_DELAY);
+ period = conf.getInt("autoscaler.rulesEvaluator.schedule.period", Constants.SCHEDULE_DEFAULT_PERIOD);
+ }
+
public void start(){
final Runnable rulesEvaluator = new Runnable() {
public void run() {
@@ -73,7 +85,6 @@ public class ExecutorTaskScheduler {
}
};
ScheduledExecutorService ex = Executors.newSingleThreadScheduledExecutor();
- //TODO make scheduler values configurable
- ex.scheduleWithFixedDelay(rulesEvaluator, 30, 15, TimeUnit.SECONDS);
+ ex.scheduleWithFixedDelay(rulesEvaluator, initialDelay, period, TimeUnit.SECONDS);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f7086d89/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/ConfUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/ConfUtil.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/ConfUtil.java
new file mode 100644
index 0000000..200d6b3
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/ConfUtil.java
@@ -0,0 +1,63 @@
+/*
+ * 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.util;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.autoscaler.Constants;
+import org.wso2.carbon.utils.CarbonUtils;
+
+import java.io.File;
+
+/**
+ * This class contains utility methods for read Autoscaler configuration file.
+ */
+public class ConfUtil {
+
+ private static Log log = LogFactory.getLog(ConfUtil.class);
+
+ private XMLConfiguration config;
+
+ private static ConfUtil instance = null;
+
+ private ConfUtil() {
+ log.info("Loading configuration.....");
+ try {
+ File confFile = new File(CarbonUtils.getCarbonConfigDirPath(),Constants.AUTOSCALER_CONFIG_FILE_NAME);
+ config = new XMLConfiguration(confFile);
+ } catch (ConfigurationException e) {
+ log.error("Unable to load autoscaler configuration file",e);
+ config = new XMLConfiguration(); // continue with default values
+ }
+ }
+
+ public static ConfUtil getInstance() {
+ if (instance == null) {
+ instance = new ConfUtil ();
+ }
+ return instance;
+ }
+
+ public XMLConfiguration getConfiguration(){
+ return config;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f7086d89/products/autoscaler/modules/distribution/src/main/conf/autoscaler.xml
----------------------------------------------------------------------
diff --git a/products/autoscaler/modules/distribution/src/main/conf/autoscaler.xml b/products/autoscaler/modules/distribution/src/main/conf/autoscaler.xml
new file mode 100644
index 0000000..af5a45e
--- /dev/null
+++ b/products/autoscaler/modules/distribution/src/main/conf/autoscaler.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+-->
+<configuration>
+ <autoscaler>
+ <rulesEvaluator>
+ <schedule>
+ <initialDelay>30</initialDelay>
+ <period>15</period>
+ </schedule>
+ </rulesEvaluator>
+ </autoscaler>
+</configuration>