You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2014/12/12 06:39:00 UTC
stratos git commit: Introducing loop attribute to mock health
statistics pattern configuration
Repository: stratos
Updated Branches:
refs/heads/4.1.0-test 9a7b32bb6 -> d0a359b16
Introducing loop attribute to mock health statistics pattern configuration
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/d0a359b1
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/d0a359b1
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/d0a359b1
Branch: refs/heads/4.1.0-test
Commit: d0a359b16632ab5808eb3fd86e12da8d77cbfd19
Parents: 9a7b32b
Author: Imesh Gunaratne <im...@apache.org>
Authored: Fri Dec 12 11:08:53 2014 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Fri Dec 12 11:08:53 2014 +0530
----------------------------------------------------------------------
.../mock/config/MockIaasConfigParser.java | 28 +++++++++++-------
.../MockHealthStatisticsGenerator.java | 3 +-
.../generator/MockHealthStatisticsPattern.java | 30 +++++++++++++++++---
.../generator/MockHealthStatisticsUpdater.java | 14 +++++----
.../distribution/src/main/conf/mock-iaas.xml | 9 ++++--
5 files changed, 60 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/d0a359b1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/config/MockIaasConfigParser.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/config/MockIaasConfigParser.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/config/MockIaasConfigParser.java
index 796afeb..614dd2f 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/config/MockIaasConfigParser.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/config/MockIaasConfigParser.java
@@ -39,6 +39,7 @@ public class MockIaasConfigParser {
private static final QName ENABLED_ATTRIBUTE = new QName("enabled");
private static final QName TYPE_ATTRIBUTE = new QName("type");
private static final QName FACTOR_ATTRIBUTE = new QName("factor");
+ private static final QName LOOP_ATTRIBUTE = new QName("loop");
private static final String HEALTH_STATISTICS_ELEMENT = "health-statistics";
private static final String SAMPLE_VALUES_ELEMENT = "sampleValues";
private static final String SAMPLE_DURATION_ELEMENT = "sampleDuration";
@@ -80,14 +81,23 @@ public class MockIaasConfigParser {
while (patternIterator.hasNext()) {
OMElement patternElement = (OMElement) patternIterator.next();
- OMAttribute factorAttribute = patternElement.getAttribute(FACTOR_ATTRIBUTE);
+ OMAttribute factorAttribute = patternElement.getAttribute(FACTOR_ATTRIBUTE);
if (factorAttribute == null) {
throw new RuntimeException("Factor attribute not found in pattern element: " +
"[cartridge-type] " + cartridgeType);
}
String factorStr = factorAttribute.getAttributeValue();
MockAutoscalingFactor autoscalingFactor = convertAutoscalingFactor(factorStr);
+
+ OMAttribute loopAttribute = patternElement.getAttribute(LOOP_ATTRIBUTE);
+ if(loopAttribute == null) {
+ throw new RuntimeException("Loop attribute not found in pattern element: " +
+ "[cartridge-type] " + cartridgeType);
+ }
+ String loopStr = loopAttribute.getAttributeValue();
+ boolean loop = Boolean.parseBoolean(loopStr);
+
String sampleValuesStr = null;
String sampleDurationStr = null;
Iterator patternChildIterator = patternElement.getChildElements();
@@ -101,18 +111,16 @@ public class MockIaasConfigParser {
}
}
- if (sampleValuesStr == null) {
- throw new RuntimeException("Sample values not found in pattern [factor] " + factorStr);
- }
- if (sampleDurationStr == null) {
- throw new RuntimeException("Sample duration not found in pattern [factor] " + factorStr);
+ List<Integer> sampleValues = null;
+ int sampleDuration = -1;
+ if((StringUtils.isNotEmpty(sampleValuesStr)) && (StringUtils.isNotEmpty(sampleDurationStr))) {
+ String[] sampleValuesArray = sampleValuesStr.split(",");
+ sampleValues = convertStringArrayToIntegerList(sampleValuesArray);
+ sampleDuration = Integer.parseInt(sampleDurationStr);
}
- String[] sampleValuesArray = sampleValuesStr.split(",");
- List<Integer> sampleValues = convertStringArrayToIntegerList(sampleValuesArray);
MockHealthStatisticsPattern mockHealthStatisticsPattern = new MockHealthStatisticsPattern
- (cartridgeType, autoscalingFactor, sampleValues, Integer.parseInt(sampleDurationStr));
-
+ (cartridgeType, autoscalingFactor, loop, sampleValues, sampleDuration);
mockHealthStatisticsConfig.addStatisticsPattern(mockHealthStatisticsPattern);
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/d0a359b1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsGenerator.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsGenerator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsGenerator.java
index 1c1ef34..9d43071 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsGenerator.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsGenerator.java
@@ -81,7 +81,8 @@ public class MockHealthStatisticsGenerator {
}
for (MockHealthStatisticsPattern statisticsPattern : statisticsPatterns) {
- if (statisticsPattern.getCartridgeType().equals(serviceName)) {
+ if (statisticsPattern.getCartridgeType().equals(serviceName) &&
+ (statisticsPattern.getSampleDuration() > 0)) {
MockHealthStatisticsUpdater runnable = new MockHealthStatisticsUpdater(statisticsPattern);
ScheduledFuture<?> task = scheduledExecutorService.scheduleAtFixedRate(runnable, 0,
statisticsPattern.getSampleDuration(), TimeUnit.SECONDS);
http://git-wip-us.apache.org/repos/asf/stratos/blob/d0a359b1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsPattern.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsPattern.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsPattern.java
index 190941e..0aa15ad 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsPattern.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsPattern.java
@@ -30,14 +30,16 @@ import java.util.List;
public class MockHealthStatisticsPattern {
private String cartridgeType;
private MockAutoscalingFactor factor;
+ private boolean loop;
private List<Integer> sampleValues;
private int sampleDuration;
private Iterator sampleValuesIterator;
- public MockHealthStatisticsPattern(String cartridgeType, MockAutoscalingFactor factor, List<Integer> sampleValues,
+ public MockHealthStatisticsPattern(String cartridgeType, MockAutoscalingFactor factor, boolean loop, List<Integer> sampleValues,
int sampleDuration) {
this.cartridgeType = cartridgeType;
this.factor = factor;
+ this.loop = loop;
this.sampleValues = sampleValues;
this.sampleValuesIterator = this.sampleValues.iterator();
this.sampleDuration = sampleDuration;
@@ -56,15 +58,35 @@ public class MockHealthStatisticsPattern {
}
/**
+ * Returns looping is enabled or not.
+ * @return
+ */
+ public boolean isLoop() {
+ return loop;
+ }
+
+ /**
* Returns next sample value
* @return
*/
public int getNextSample() {
+ if((sampleValues == null) || (sampleValues.size() < 1)) {
+ return -1;
+ }
+
if(!sampleValuesIterator.hasNext()) {
- // Reset iterator
- sampleValuesIterator = sampleValues.iterator();
+ // Iterator has come to the end of the list
+ if(isLoop()) {
+ // Looping is enabled, reset the iterator
+ sampleValuesIterator = sampleValues.iterator();
+ return Integer.parseInt(sampleValuesIterator.next().toString());
+ } else {
+ // Looping is disabled, return the last value
+ return Integer.parseInt(sampleValues.get(sampleValues.size() - 1).toString());
+ }
+ } else {
+ return Integer.parseInt(sampleValuesIterator.next().toString());
}
- return Integer.parseInt(sampleValuesIterator.next().toString());
}
/**
http://git-wip-us.apache.org/repos/asf/stratos/blob/d0a359b1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsUpdater.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsUpdater.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsUpdater.java
index dd2aec8..07e85be 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsUpdater.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsUpdater.java
@@ -41,12 +41,14 @@ public class MockHealthStatisticsUpdater implements Runnable {
public void run() {
try {
int nextSample = statisticsPattern.getNextSample();
- MockHealthStatistics.getInstance().addStatistics(statisticsPattern.getCartridgeType(),
- statisticsPattern.getFactor(), nextSample);
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Mock statistics updated: [cartridge-type] %s [factor] %s [value] %d",
- statisticsPattern.getCartridgeType(), statisticsPattern.getFactor().toString(), nextSample));
+ if(nextSample != -1) {
+ MockHealthStatistics.getInstance().addStatistics(statisticsPattern.getCartridgeType(),
+ statisticsPattern.getFactor(), nextSample);
+
+ if (log.isInfoEnabled()) {
+ log.info(String.format("Mock statistics updated: [cartridge-type] %s [factor] %s [value] %d",
+ statisticsPattern.getCartridgeType(), statisticsPattern.getFactor().toString(), nextSample));
+ }
}
} catch (Exception e) {
log.error("Could not update mock statistics", e);
http://git-wip-us.apache.org/repos/asf/stratos/blob/d0a359b1/products/stratos/modules/distribution/src/main/conf/mock-iaas.xml
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/conf/mock-iaas.xml b/products/stratos/modules/distribution/src/main/conf/mock-iaas.xml
index 555d7f9..9b2403b 100644
--- a/products/stratos/modules/distribution/src/main/conf/mock-iaas.xml
+++ b/products/stratos/modules/distribution/src/main/conf/mock-iaas.xml
@@ -20,13 +20,16 @@
<mock-iaas enabled="true">
<health-statistics>
<cartridge type="tomcat">
- <pattern factor="memory-consumption">
+ <!-- factor:memory-consumption|load-average|request-in-flight-->
+ <!-- if loop is set to true after the last sample value it will loop from the beginning,
+ else the last sample value will be continued -->
+ <pattern factor="memory-consumption" loop="false">
<!-- Sample values -->
- <sampleValues>20,30,40,50,60,70,50,40,30,20,20,20,20,20,20,20</sampleValues>
+ <sampleValues>20,30,40,50,60,70,50,40,30,20</sampleValues>
<!-- Duration of each sample value in seconds -->
<sampleDuration>60</sampleDuration>
</pattern>
- <pattern factor="load-average">
+ <pattern factor="load-average" loop="false">
<!-- Sample values -->
<sampleValues>20</sampleValues>
<!-- Duration of each sample value in seconds -->