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 08:13:08 UTC

stratos git commit: Introducing mock health statistics pattern mode: loop|continue|stop

Repository: stratos
Updated Branches:
  refs/heads/4.1.0-test 361bde0c5 -> d106a0504


Introducing mock health statistics pattern mode: loop|continue|stop


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

Branch: refs/heads/4.1.0-test
Commit: d106a05046ba4415ed5e440edc655fd8cbc21239
Parents: 361bde0
Author: Imesh Gunaratne <im...@apache.org>
Authored: Fri Dec 12 12:42:48 2014 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Fri Dec 12 12:43:01 2014 +0530

----------------------------------------------------------------------
 .../mock/config/MockIaasConfigParser.java       | 43 +++++++----
 .../NoSampleValuesFoundException.java           | 26 +++++++
 .../exceptions/NoStatisticsFoundException.java  | 26 +++++++
 .../StopStatisticsPublishingException.java      | 26 +++++++
 .../mock/statistics/MockHealthStatistics.java   | 43 ++++++++++-
 .../mock/statistics/StatisticsPatternMode.java  | 27 +++++++
 .../generator/MockHealthStatisticsPattern.java  | 32 +++++---
 .../generator/MockHealthStatisticsUpdater.java  | 29 +++++--
 .../publisher/MockHealthStatisticsNotifier.java | 79 ++++++++++++--------
 .../distribution/src/main/conf/mock-iaas.xml    | 11 ++-
 10 files changed, 269 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/d106a050/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 614dd2f..ec39265 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
@@ -23,6 +23,7 @@ import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMElement;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.stratos.cloud.controller.iaases.mock.MockAutoscalingFactor;
+import org.apache.stratos.cloud.controller.iaases.mock.statistics.StatisticsPatternMode;
 import org.apache.stratos.cloud.controller.iaases.mock.statistics.generator.MockHealthStatisticsPattern;
 import org.apache.stratos.cloud.controller.util.AxiomXpathParserUtil;
 
@@ -39,7 +40,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 QName MODE_ATTRIBUTE = new QName("mode");
     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";
@@ -90,13 +91,13 @@ public class MockIaasConfigParser {
                             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: " +
+                            OMAttribute modeAttribute = patternElement.getAttribute(MODE_ATTRIBUTE);
+                            if(modeAttribute == null) {
+                                throw new RuntimeException("Mode attribute not found in pattern element: " +
                                         "[cartridge-type] " + cartridgeType);
                             }
-                            String loopStr = loopAttribute.getAttributeValue();
-                            boolean loop = Boolean.parseBoolean(loopStr);
+                            String modeStr = modeAttribute.getAttributeValue();
+                            StatisticsPatternMode mode = convertMode(modeStr);
 
                             String sampleValuesStr = null;
                             String sampleDurationStr = null;
@@ -111,16 +112,19 @@ public class MockIaasConfigParser {
                                 }
                             }
 
-                            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);
+                            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);
+                            }
+
+                            String[] sampleValuesArray = sampleValuesStr.split(",");
+                            List<Integer> sampleValues = convertStringArrayToIntegerList(sampleValuesArray);
+                            int sampleDuration = Integer.parseInt(sampleDurationStr);
 
                             MockHealthStatisticsPattern mockHealthStatisticsPattern = new MockHealthStatisticsPattern
-                                    (cartridgeType, autoscalingFactor, loop, sampleValues, sampleDuration);
+                                    (cartridgeType, autoscalingFactor, mode, sampleValues, sampleDuration);
                             mockHealthStatisticsConfig.addStatisticsPattern(mockHealthStatisticsPattern);
                         }
                     }
@@ -132,6 +136,19 @@ public class MockIaasConfigParser {
         }
     }
 
+    private static StatisticsPatternMode convertMode(String modeStr) {
+        if("loop".equals(modeStr)) {
+            return StatisticsPatternMode.Loop;
+        }
+        else if("continue".equals(modeStr)) {
+            return StatisticsPatternMode.Continue;
+        }
+        else if("stop".equals(modeStr)) {
+            return StatisticsPatternMode.Stop;
+        }
+        throw new RuntimeException("An unknown statistics pattern mode found: " + modeStr);
+    }
+
     private static MockAutoscalingFactor convertAutoscalingFactor(String factorStr) {
         if("memory-consumption".equals(factorStr)) {
             return MockAutoscalingFactor.MemoryConsumption;

http://git-wip-us.apache.org/repos/asf/stratos/blob/d106a050/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/exceptions/NoSampleValuesFoundException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/exceptions/NoSampleValuesFoundException.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/exceptions/NoSampleValuesFoundException.java
new file mode 100644
index 0000000..31ffa9e
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/exceptions/NoSampleValuesFoundException.java
@@ -0,0 +1,26 @@
+/*
+ * 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.cloud.controller.iaases.mock.exceptions;
+
+/**
+ * No sample values found exception.
+ */
+public class NoSampleValuesFoundException extends Exception {
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/d106a050/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/exceptions/NoStatisticsFoundException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/exceptions/NoStatisticsFoundException.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/exceptions/NoStatisticsFoundException.java
new file mode 100644
index 0000000..3952d1d
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/exceptions/NoStatisticsFoundException.java
@@ -0,0 +1,26 @@
+/*
+ * 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.cloud.controller.iaases.mock.exceptions;
+
+/**
+ * No statistics found exception.
+ */
+public class NoStatisticsFoundException extends Exception {
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/d106a050/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/exceptions/StopStatisticsPublishingException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/exceptions/StopStatisticsPublishingException.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/exceptions/StopStatisticsPublishingException.java
new file mode 100644
index 0000000..84dbf44
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/exceptions/StopStatisticsPublishingException.java
@@ -0,0 +1,26 @@
+/*
+ * 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.cloud.controller.iaases.mock.exceptions;
+
+/**
+ * Stop statistics publishing exception.
+ */
+public class StopStatisticsPublishingException extends Exception {
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/d106a050/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/MockHealthStatistics.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/MockHealthStatistics.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/MockHealthStatistics.java
index 9ac4d8a..baf3b3e 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/MockHealthStatistics.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/MockHealthStatistics.java
@@ -20,6 +20,7 @@
 package org.apache.stratos.cloud.controller.iaases.mock.statistics;
 
 import org.apache.stratos.cloud.controller.iaases.mock.MockAutoscalingFactor;
+import org.apache.stratos.cloud.controller.iaases.mock.exceptions.NoStatisticsFoundException;
 
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -52,6 +53,12 @@ public class MockHealthStatistics {
         return instance;
     }
 
+    /**
+     * Add statistics value for a cartridge type, autoscaling factor
+     * @param cartridgeType
+     * @param autoscalingFactor
+     * @param value
+     */
     public void addStatistics(String cartridgeType, MockAutoscalingFactor autoscalingFactor, Integer value) {
         Map<String, Integer> factorValueMap = statisticsMap.get(cartridgeType);
         if(factorValueMap == null) {
@@ -65,14 +72,44 @@ public class MockHealthStatistics {
         factorValueMap.put(autoscalingFactor.toString(), value);
     }
 
-    public int getStatistics(String cartridgeType, MockAutoscalingFactor autoscalingFactor) {
+    /**
+     * Returns current statistics of the given cartridge type, autoscaling factor
+     * @param cartridgeType
+     * @param autoscalingFactor
+     * @return
+     */
+    public int getStatistics(String cartridgeType, MockAutoscalingFactor autoscalingFactor) throws NoStatisticsFoundException {
         Map<String, Integer> factorValueMap = statisticsMap.get(cartridgeType);
-        if((factorValueMap != null) && (factorValueMap.containsKey(autoscalingFactor.toString())) ){
-            return factorValueMap.get(autoscalingFactor.toString());
+        if(factorValueMap != null) {
+            if(factorValueMap.containsKey(autoscalingFactor.toString())) {
+                return factorValueMap.get(autoscalingFactor.toString());
+            } else {
+                throw new NoStatisticsFoundException();
+            }
         }
+        // No statistics patterns found, return default
         return findDefault(autoscalingFactor);
     }
 
+    /**
+     * Remove statistics found for the cartridge type, autoscaling factor
+     * @param cartridgeType
+     * @param autoscalingFactor
+     */
+    public void removeStatistics(String cartridgeType, MockAutoscalingFactor autoscalingFactor) {
+        Map<String, Integer> factorValueMap = statisticsMap.get(cartridgeType);
+        if(factorValueMap != null) {
+            if(factorValueMap.containsKey(autoscalingFactor.toString())) {
+                factorValueMap.remove(autoscalingFactor.toString());
+            }
+        }
+    }
+
+    /**
+     * Find default statistics value of the given autoscaling factor
+     * @param autoscalingFactor
+     * @return
+     */
     private int findDefault(MockAutoscalingFactor autoscalingFactor) {
         if(autoscalingFactor == MockAutoscalingFactor.MemoryConsumption) {
             return DEFAULT_MEMORY_CONSUMPTION;

http://git-wip-us.apache.org/repos/asf/stratos/blob/d106a050/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/StatisticsPatternMode.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/StatisticsPatternMode.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/StatisticsPatternMode.java
new file mode 100644
index 0000000..23a80d6
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/StatisticsPatternMode.java
@@ -0,0 +1,27 @@
+/*
+ * 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.cloud.controller.iaases.mock.statistics;
+
+/**
+ * Statistics pattern mode.
+ */
+public enum StatisticsPatternMode {
+    Loop, Continue, Stop
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/d106a050/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 0aa15ad..4385a51 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
@@ -20,6 +20,9 @@
 package org.apache.stratos.cloud.controller.iaases.mock.statistics.generator;
 
 import org.apache.stratos.cloud.controller.iaases.mock.MockAutoscalingFactor;
+import org.apache.stratos.cloud.controller.iaases.mock.exceptions.NoSampleValuesFoundException;
+import org.apache.stratos.cloud.controller.iaases.mock.exceptions.StopStatisticsPublishingException;
+import org.apache.stratos.cloud.controller.iaases.mock.statistics.StatisticsPatternMode;
 
 import java.util.Iterator;
 import java.util.List;
@@ -28,18 +31,19 @@ import java.util.List;
  * Mock health statistics pattern definition.
  */
 public class MockHealthStatisticsPattern {
+
     private String cartridgeType;
     private MockAutoscalingFactor factor;
-    private boolean loop;
+    private StatisticsPatternMode mode;
     private List<Integer> sampleValues;
     private int sampleDuration;
     private Iterator sampleValuesIterator;
 
-    public MockHealthStatisticsPattern(String cartridgeType, MockAutoscalingFactor factor, boolean loop, List<Integer> sampleValues,
+    public MockHealthStatisticsPattern(String cartridgeType, MockAutoscalingFactor factor, StatisticsPatternMode mode, List<Integer> sampleValues,
                                        int sampleDuration) {
         this.cartridgeType = cartridgeType;
         this.factor = factor;
-        this.loop = loop;
+        this.mode = mode;
         this.sampleValues = sampleValues;
         this.sampleValuesIterator = this.sampleValues.iterator();
         this.sampleDuration = sampleDuration;
@@ -58,31 +62,35 @@ public class MockHealthStatisticsPattern {
     }
 
     /**
-     * Returns looping is enabled or not.
+     * Returns statistics pattern mode
      * @return
      */
-    public boolean isLoop() {
-        return loop;
+    public StatisticsPatternMode getMode() {
+        return mode;
     }
 
     /**
      * Returns next sample value
      * @return
      */
-    public int getNextSample() {
+    public int getNextSample() throws NoSampleValuesFoundException, StopStatisticsPublishingException {
         if((sampleValues == null) || (sampleValues.size() < 1)) {
-            return -1;
+            throw new NoSampleValuesFoundException();
         }
 
         if(!sampleValuesIterator.hasNext()) {
             // Iterator has come to the end of the list
-            if(isLoop()) {
-                // Looping is enabled, reset the iterator
+            if(getMode() == StatisticsPatternMode.Loop) {
+                // Looping: reset the iterator
                 sampleValuesIterator = sampleValues.iterator();
                 return Integer.parseInt(sampleValuesIterator.next().toString());
-            } else {
-                // Looping is disabled, return the last value
+            } else if(getMode() == StatisticsPatternMode.Continue) {
+                // Continue: return the last value
                 return Integer.parseInt(sampleValues.get(sampleValues.size() - 1).toString());
+            } else if(getMode() == StatisticsPatternMode.Stop) {
+                throw new StopStatisticsPublishingException();
+            } else {
+                throw new RuntimeException("An unknown statistics pattern mode found");
             }
         } else {
             return Integer.parseInt(sampleValuesIterator.next().toString());

http://git-wip-us.apache.org/repos/asf/stratos/blob/d106a050/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 07e85be..eed649f 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
@@ -21,6 +21,9 @@ package org.apache.stratos.cloud.controller.iaases.mock.statistics.generator;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.iaases.mock.exceptions.NoSampleValuesFoundException;
+import org.apache.stratos.cloud.controller.iaases.mock.exceptions.NoStatisticsFoundException;
+import org.apache.stratos.cloud.controller.iaases.mock.exceptions.StopStatisticsPublishingException;
 import org.apache.stratos.cloud.controller.iaases.mock.statistics.MockHealthStatistics;
 
 /**
@@ -41,14 +44,24 @@ public class MockHealthStatisticsUpdater implements Runnable {
     public void run() {
         try {
             int nextSample = statisticsPattern.getNextSample();
-            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));
-                }
+            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 (NoSampleValuesFoundException ignore) {
+            if(log.isDebugEnabled()) {
+                log.debug(String.format("No sample values found for: [cartridge-type] %s [factor] %s",
+                        statisticsPattern.getCartridgeType(), statisticsPattern.getFactor().toString()));
+            }
+        } catch (StopStatisticsPublishingException action) {
+            MockHealthStatistics.getInstance().removeStatistics(statisticsPattern.getCartridgeType(),
+                    statisticsPattern.getFactor());
+            if(log.isDebugEnabled()) {
+                log.debug(String.format("Statistics removed: [cartridge-type] %s [factor] %s",
+                        statisticsPattern.getCartridgeType(), statisticsPattern.getFactor().toString()));
             }
         } catch (Exception e) {
             log.error("Could not update mock statistics", e);

http://git-wip-us.apache.org/repos/asf/stratos/blob/d106a050/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/publisher/MockHealthStatisticsNotifier.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/publisher/MockHealthStatisticsNotifier.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/publisher/MockHealthStatisticsNotifier.java
index 94744af..4962e2c 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/publisher/MockHealthStatisticsNotifier.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/publisher/MockHealthStatisticsNotifier.java
@@ -23,6 +23,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.cloud.controller.iaases.mock.MockAutoscalingFactor;
 import org.apache.stratos.cloud.controller.iaases.mock.MockMemberContext;
+import org.apache.stratos.cloud.controller.iaases.mock.exceptions.NoStatisticsFoundException;
 import org.apache.stratos.cloud.controller.iaases.mock.statistics.MockHealthStatistics;
 
 /**
@@ -45,43 +46,55 @@ public class MockHealthStatisticsNotifier implements Runnable {
 
     @Override
     public void run() {
+        if (!statsPublisher.isEnabled()) {
+            if (log.isWarnEnabled()) {
+                log.warn("Statistics publisher is disabled");
+            }
+            return;
+        }
+
         try {
-            if (statsPublisher.isEnabled()) {
-                double memoryConsumption = MockHealthStatistics.getInstance().getStatistics(
-                        mockMemberContext.getServiceName(), MockAutoscalingFactor.MemoryConsumption);
-                double loadAvereage = MockHealthStatistics.getInstance().getStatistics(
-                        mockMemberContext.getServiceName(), MockAutoscalingFactor.LoadAverage);
+            double memoryConsumption = MockHealthStatistics.getInstance().getStatistics(
+                    mockMemberContext.getServiceName(), MockAutoscalingFactor.MemoryConsumption);
 
-                if (log.isDebugEnabled()) {
-                    log.debug(String.format("Publishing memory consumption: [member-id] %s [value] %f",
-                            mockMemberContext.getMemberId(), memoryConsumption));
-                }
-                statsPublisher.publish(
-                        mockMemberContext.getClusterId(),
-                        mockMemberContext.getInstanceId(),
-                        mockMemberContext.getNetworkPartitionId(),
-                        mockMemberContext.getMemberId(),
-                        mockMemberContext.getPartitionId(),
-                        MEMORY_CONSUMPTION,
-                        memoryConsumption
-                );
+            if (log.isDebugEnabled()) {
+                log.debug(String.format("Publishing memory consumption: [member-id] %s [value] %f",
+                        mockMemberContext.getMemberId(), memoryConsumption));
+            }
+            statsPublisher.publish(
+                    mockMemberContext.getClusterId(),
+                    mockMemberContext.getInstanceId(),
+                    mockMemberContext.getNetworkPartitionId(),
+                    mockMemberContext.getMemberId(),
+                    mockMemberContext.getPartitionId(),
+                    MEMORY_CONSUMPTION,
+                    memoryConsumption
+            );
+        } catch (NoStatisticsFoundException ignore) {
+        } catch (Exception e) {
+            if (log.isErrorEnabled()) {
+                log.error("Could not publish health statistics", e);
+            }
+        }
 
-                if (log.isDebugEnabled()) {
-                    log.debug(String.format("Publishing load average: [member-id] %s [value] %f",
-                            mockMemberContext.getMemberId(), loadAvereage));
-                }
-                statsPublisher.publish(
-                        mockMemberContext.getClusterId(),
-                        mockMemberContext.getInstanceId(),
-                        mockMemberContext.getNetworkPartitionId(),
-                        mockMemberContext.getMemberId(),
-                        mockMemberContext.getPartitionId(),
-                        LOAD_AVERAGE,
-                        loadAvereage
-                );
-            } else if (log.isWarnEnabled()) {
-                log.warn("Statistics publisher is disabled");
+
+        try {
+            double loadAvereage = MockHealthStatistics.getInstance().getStatistics(
+                    mockMemberContext.getServiceName(), MockAutoscalingFactor.LoadAverage);
+            if (log.isDebugEnabled()) {
+                log.debug(String.format("Publishing load average: [member-id] %s [value] %f",
+                        mockMemberContext.getMemberId(), loadAvereage));
             }
+            statsPublisher.publish(
+                    mockMemberContext.getClusterId(),
+                    mockMemberContext.getInstanceId(),
+                    mockMemberContext.getNetworkPartitionId(),
+                    mockMemberContext.getMemberId(),
+                    mockMemberContext.getPartitionId(),
+                    LOAD_AVERAGE,
+                    loadAvereage
+            );
+        } catch (NoStatisticsFoundException ignore) {
         } catch (Exception e) {
             if (log.isErrorEnabled()) {
                 log.error("Could not publish health statistics", e);

http://git-wip-us.apache.org/repos/asf/stratos/blob/d106a050/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 9b2403b..944a0d8 100644
--- a/products/stratos/modules/distribution/src/main/conf/mock-iaas.xml
+++ b/products/stratos/modules/distribution/src/main/conf/mock-iaas.xml
@@ -21,15 +21,18 @@
     <health-statistics>
         <cartridge type="tomcat">
             <!-- 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">
+            <!-- mode:loop|continue|stop -->
+            <!-- Mode defines the action needs to be taken after the last sample value:
+                 loop: start from beginning
+                 continue: continue the last sample value
+                 stop: stop publishing statistics -->
+            <pattern factor="memory-consumption" mode="continue">
                 <!-- Sample values -->
                 <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" loop="false">
+            <pattern factor="load-average" mode="continue">
                 <!-- Sample values -->
                 <sampleValues>20</sampleValues>
                 <!-- Duration of each sample value in seconds -->