You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ud...@apache.org on 2014/12/12 11:11:30 UTC
[28/50] stratos git commit: Introducing mock health statistics
generation based on custom patterns
Introducing mock health statistics generation based on custom patterns
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/97297b70
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/97297b70
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/97297b70
Branch: refs/heads/master
Commit: 97297b70155937bc33522b749dc05ba8d89b798b
Parents: d08f7b2
Author: Imesh Gunaratne <im...@apache.org>
Authored: Thu Dec 11 22:21:21 2014 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Thu Dec 11 22:21:35 2014 +0530
----------------------------------------------------------------------
.../iaases/mock/MockAutoscalingFactor.java | 27 ++++
.../iaases/mock/MockIPAddressPool.java | 1 +
.../controller/iaases/mock/MockIaasService.java | 15 +-
.../controller/iaases/mock/MockMember.java | 4 +-
.../mock/config/MockHealthStatisticsConfig.java | 44 ++++++
.../MockHealthStatisticsConfigParser.java | 136 +++++++++++++++++++
.../iaases/mock/config/MockIaasConfig.java | 55 ++++++++
.../mock/statistics/MockHealthStatistics.java | 117 ++++++++++++++++
.../MockHealthStatisticsNotifier.java | 86 ------------
.../MockHealthStatisticsPublisher.java | 91 -------------
.../MockHealthStatisticsGenerator.java | 72 ++++++++++
.../generator/MockHealthStatisticsPattern.java | 77 +++++++++++
.../generator/MockHealthStatisticsUpdater.java | 57 ++++++++
.../publisher/MockHealthStatisticsNotifier.java | 97 +++++++++++++
.../MockHealthStatisticsPublisher.java | 91 +++++++++++++
.../modules/distribution/src/assembly/bin.xml | 6 +
.../distribution/src/main/conf/mock-iaas.xml | 37 +++++
17 files changed, 832 insertions(+), 181 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/97297b70/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockAutoscalingFactor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockAutoscalingFactor.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockAutoscalingFactor.java
new file mode 100644
index 0000000..aac0f2d
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockAutoscalingFactor.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;
+
+/**
+ * Mock autoscaling factor enumeration
+ */
+public enum MockAutoscalingFactor {
+ MemoryConsumption, LoadAverage, RequestInFlight
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/97297b70/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIPAddressPool.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIPAddressPool.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIPAddressPool.java
index 865a137..ac16a0e 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIPAddressPool.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIPAddressPool.java
@@ -32,6 +32,7 @@ import java.util.concurrent.atomic.AtomicInteger;
*/
public class MockIPAddressPool {
private static final Log log = LogFactory.getLog(MockIPAddressPool.class);
+
private static final String MOCK_IAAS_PRIVATE_IP_SEQUENCE = "/mock/iaas/private-ip-sequence";
private static final String MOCK_IAAS_PUBLIC_IP_SEQUENCE = "/mock/iaas/public-ip-sequence";
private static final String PRIVATE_IP_PREFIX = "10.0.0.";
http://git-wip-us.apache.org/repos/asf/stratos/blob/97297b70/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaasService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaasService.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaasService.java
index 5c3d83f..a026cfc 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaasService.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaasService.java
@@ -25,8 +25,8 @@ import org.apache.stratos.cloud.controller.domain.ClusterContext;
import org.apache.stratos.cloud.controller.domain.MemberContext;
import org.apache.stratos.cloud.controller.domain.Partition;
import org.apache.stratos.cloud.controller.exception.*;
+import org.apache.stratos.cloud.controller.iaases.mock.statistics.generator.MockHealthStatisticsGenerator;
import org.apache.stratos.cloud.controller.iaases.validators.PartitionValidator;
-import org.apache.stratos.cloud.controller.messaging.topology.TopologyBuilder;
import org.apache.stratos.cloud.controller.registry.RegistryManager;
import org.apache.stratos.common.threading.StratosThreadPool;
import org.jclouds.compute.domain.NodeMetadata;
@@ -85,11 +85,14 @@ public class MockIaasService {
*/
public static void startMockMembersIfPresentInRegistry() {
ConcurrentHashMap<String, MockMember> membersMap = readFromRegistry();
- if(membersMap != null) {
+ if((membersMap != null) && (membersMap.size() > 0)) {
+ // Start existing mock members
ExecutorService executorService = StratosThreadPool.getExecutorService("MOCK_IAAS_THREAD_EXECUTOR", 100);
for (MockMember mockMember : membersMap.values()) {
executorService.submit(mockMember);
}
+ // Schedule health statistics updaters
+ MockHealthStatisticsGenerator.scheduleStatisticsUpdaters();
}
}
@@ -110,6 +113,10 @@ public class MockIaasService {
// Persist changes
persistInRegistry();
+ if(!MockHealthStatisticsGenerator.isScheduled()) {
+ MockHealthStatisticsGenerator.scheduleStatisticsUpdaters();
+ }
+
return nodeMetadata;
}
}
@@ -184,6 +191,10 @@ public class MockIaasService {
mockMember.terminate();
membersMap.remove(memberContext.getMemberId());
}
+
+ if(membersMap.size() == 0) {
+ MockHealthStatisticsGenerator.stopStatisticsUpdaters();
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/97297b70/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockMember.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockMember.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockMember.java
index 007a87a..e22ea57 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockMember.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockMember.java
@@ -21,7 +21,7 @@ package org.apache.stratos.cloud.controller.iaases.mock;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.cloud.controller.iaases.mock.statistics.MockHealthStatisticsNotifier;
+import org.apache.stratos.cloud.controller.iaases.mock.statistics.publisher.MockHealthStatisticsNotifier;
import org.apache.stratos.common.threading.StratosThreadPool;
import org.apache.stratos.messaging.event.Event;
import org.apache.stratos.messaging.event.instance.notifier.InstanceCleanupClusterEvent;
@@ -131,7 +131,7 @@ public class MockMember implements Runnable, Serializable {
}
healthStatNotifierExecutorService.scheduleAtFixedRate(new MockHealthStatisticsNotifier(mockMemberContext),
- HEALTH_STAT_INTERVAL, HEALTH_STAT_INTERVAL, TimeUnit.SECONDS);
+ 0, HEALTH_STAT_INTERVAL, TimeUnit.SECONDS);
if (log.isDebugEnabled()) {
log.debug(String.format("Health statistics notifier started: [member-id] %s", mockMemberContext.getMemberId()));
http://git-wip-us.apache.org/repos/asf/stratos/blob/97297b70/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/config/MockHealthStatisticsConfig.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/config/MockHealthStatisticsConfig.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/config/MockHealthStatisticsConfig.java
new file mode 100644
index 0000000..28975c2
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/config/MockHealthStatisticsConfig.java
@@ -0,0 +1,44 @@
+/*
+ * 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.config;
+
+import org.apache.stratos.cloud.controller.iaases.mock.statistics.generator.MockHealthStatisticsPattern;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Mock health statistics configuration.
+ */
+public class MockHealthStatisticsConfig {
+ List<MockHealthStatisticsPattern> statisticsPatternList;
+
+ public MockHealthStatisticsConfig() {
+ statisticsPatternList = new ArrayList<MockHealthStatisticsPattern>();
+ }
+
+ public void addStatisticsPattern(MockHealthStatisticsPattern statisticsPattern) {
+ statisticsPatternList.add(statisticsPattern);
+ }
+
+ public List<MockHealthStatisticsPattern> getStatisticsPatterns() {
+ return statisticsPatternList;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/97297b70/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/config/MockHealthStatisticsConfigParser.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/config/MockHealthStatisticsConfigParser.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/config/MockHealthStatisticsConfigParser.java
new file mode 100644
index 0000000..fe61078
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/config/MockHealthStatisticsConfigParser.java
@@ -0,0 +1,136 @@
+/*
+ * 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.config;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.stratos.cloud.controller.iaases.mock.MockAutoscalingFactor;
+import org.apache.stratos.cloud.controller.iaases.mock.statistics.generator.MockHealthStatisticsPattern;
+import org.apache.stratos.cloud.controller.util.AxiomXpathParserUtil;
+
+import javax.xml.namespace.QName;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Mock health statistics configuration parser.
+ */
+public class MockHealthStatisticsConfigParser {
+ private static final QName TYPE_ATTRIBUTE = new QName("type");
+ private static final QName FACTOR_ATTRIBUTE = new QName("factor");
+ 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";
+
+ /**
+ * Parse mock iaas health statistics configuration and return configuration object.
+ * @param filePath
+ * @return
+ */
+ public static MockHealthStatisticsConfig parse(String filePath) {
+ try {
+ MockHealthStatisticsConfig mockHealthStatisticsConfig = new MockHealthStatisticsConfig();
+ OMElement document = AxiomXpathParserUtil.parse(new File(filePath));
+ Iterator statisticsIterator = document.getChildElements();
+
+ while (statisticsIterator.hasNext()) {
+ OMElement statisticsElement = (OMElement) statisticsIterator.next();
+
+ if (HEALTH_STATISTICS_ELEMENT.equals(statisticsElement.getQName().getLocalPart())) {
+ Iterator cartridgeIterator = statisticsElement.getChildElements();
+
+ while (cartridgeIterator.hasNext()) {
+ OMElement cartridgeElement = (OMElement) cartridgeIterator.next();
+ OMAttribute typeAttribute = cartridgeElement.getAttribute(TYPE_ATTRIBUTE);
+ if (typeAttribute == null) {
+ throw new RuntimeException("Type attribute not found in cartridge element");
+ }
+ String cartridgeType = typeAttribute.getAttributeValue();
+ Iterator patternIterator = cartridgeElement.getChildElements();
+
+ while (patternIterator.hasNext()) {
+ OMElement patternElement = (OMElement) patternIterator.next();
+ 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);
+ String sampleValuesStr = null;
+ String sampleDurationStr = null;
+ Iterator patternChildIterator = patternElement.getChildElements();
+
+ while (patternChildIterator.hasNext()) {
+ OMElement patternChild = (OMElement) patternChildIterator.next();
+ if (SAMPLE_VALUES_ELEMENT.equals(patternChild.getQName().getLocalPart())) {
+ sampleValuesStr = patternChild.getText();
+ } else if (SAMPLE_DURATION_ELEMENT.equals(patternChild.getQName().getLocalPart())) {
+ sampleDurationStr = patternChild.getText();
+ }
+ }
+
+ 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);
+ MockHealthStatisticsPattern mockHealthStatisticsPattern = new MockHealthStatisticsPattern
+ (cartridgeType, autoscalingFactor, sampleValues, Integer.parseInt(sampleDurationStr));
+
+ mockHealthStatisticsConfig.addStatisticsPattern(mockHealthStatisticsPattern);
+ }
+ }
+ }
+ }
+ return mockHealthStatisticsConfig;
+ } catch (Exception e) {
+ throw new RuntimeException("Could not parse mock health statistics configuration", e);
+ }
+ }
+
+ private static MockAutoscalingFactor convertAutoscalingFactor(String factorStr) {
+ if("memory-consumption".equals(factorStr)) {
+ return MockAutoscalingFactor.MemoryConsumption;
+ }
+ else if("load-average".equals(factorStr)) {
+ return MockAutoscalingFactor.LoadAverage;
+ }
+ else if("request-in-flight".equals(factorStr)) {
+ return MockAutoscalingFactor.RequestInFlight;
+ }
+ throw new RuntimeException("An unknown autoscaling factor found: " + factorStr);
+ }
+
+ private static List<Integer> convertStringArrayToIntegerList(String[] stringArray) {
+ List<Integer> integerList = new ArrayList<Integer>();
+ for (String value : stringArray) {
+ integerList.add(Integer.parseInt(value));
+ }
+ return integerList;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/97297b70/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/config/MockIaasConfig.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/config/MockIaasConfig.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/config/MockIaasConfig.java
new file mode 100644
index 0000000..8452f56
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/config/MockIaasConfig.java
@@ -0,0 +1,55 @@
+/*
+ * 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.config;
+
+import org.wso2.carbon.context.CarbonContext;
+
+/**
+ * Mock iaas configuration.
+ */
+public class MockIaasConfig {
+ private static final String MOCK_IAAS_CONFIG_FILE_NAME = "mock-iaas.xml";
+ private static final String CARBON_HOME = "carbon.home";
+ private static final String REPOSITORY_CONF = "/repository/conf/";
+
+ private static volatile MockIaasConfig instance;
+
+ private MockHealthStatisticsConfig mockHealthStatisticsConfig;
+
+ public static MockIaasConfig getInstance() {
+ if (instance == null) {
+ synchronized (MockIaasConfig.class) {
+ if (instance == null) {
+ instance = new MockIaasConfig();
+ }
+ }
+ }
+ return instance;
+ }
+
+ private MockIaasConfig() {
+ String confPath = System.getProperty(CARBON_HOME) + REPOSITORY_CONF;
+ mockHealthStatisticsConfig = MockHealthStatisticsConfigParser.parse(confPath + MOCK_IAAS_CONFIG_FILE_NAME);
+ }
+
+ public MockHealthStatisticsConfig getMockHealthStatisticsConfig() {
+ return mockHealthStatisticsConfig;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/97297b70/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
new file mode 100644
index 0000000..50e6564
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/MockHealthStatistics.java
@@ -0,0 +1,117 @@
+/*
+ * 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;
+
+import org.apache.stratos.cloud.controller.iaases.mock.MockAutoscalingFactor;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ * Mock health statistics singleton class.
+ */
+public class MockHealthStatistics {
+ private final static int DEFAULT_MEMORY_CONSUMPTION = 20;
+ private final static int DEFAULT_LOAD_AVERAGE = 20;
+ private final static int DEFAULT_REQUESTS_IN_FLIGHT = 1;
+
+ private static volatile MockHealthStatistics instance;
+
+ private Map<String, ReentrantReadWriteLock> lockMap;
+ private Map<String, Map<String, Integer>> statisticsMap;
+
+ private MockHealthStatistics() {
+ lockMap = new ConcurrentHashMap<String, ReentrantReadWriteLock>();
+ statisticsMap = new ConcurrentHashMap<String, Map<String, Integer>>();
+ }
+
+ public static MockHealthStatistics getInstance() {
+ if (instance == null) {
+ synchronized (MockHealthStatistics.class) {
+ if (instance == null) {
+ instance = new MockHealthStatistics();
+ }
+ }
+ }
+ return instance;
+ }
+
+ public void acquireReadLock(String cartridgeType) {
+ ReentrantReadWriteLock lock = getLock(cartridgeType);
+ lock.readLock().lock();
+ }
+
+ public void acquireWriteLock(String cartridgeType) {
+ ReentrantReadWriteLock lock = getLock(cartridgeType);
+ lock.writeLock().lock();
+ }
+
+ public void releaseReadLock(String cartridgeType) {
+ ReentrantReadWriteLock lock = getLock(cartridgeType);
+ lock.readLock().unlock();
+ }
+
+ public void releaseWriteLock(String cartridgeType) {
+ ReentrantReadWriteLock lock = getLock(cartridgeType);
+ lock.writeLock().unlock();
+ }
+
+ private ReentrantReadWriteLock getLock(String cartridgeType) {
+ ReentrantReadWriteLock lock = lockMap.get(cartridgeType);
+ if(lock == null) {
+ synchronized (MockHealthStatistics.class) {
+ if(lock == null) {
+ lock = new ReentrantReadWriteLock();
+ lockMap.put(cartridgeType, lock);
+ }
+ }
+ }
+ return lock;
+ }
+
+ public void addStatistics(String cartridgeType, MockAutoscalingFactor autoscalingFactor, Integer value) {
+ Map<String, Integer> factorValueMap = statisticsMap.get(cartridgeType);
+ if(factorValueMap == null) {
+ factorValueMap = new ConcurrentHashMap<String, Integer>();
+ statisticsMap.put(cartridgeType, factorValueMap);
+ }
+ factorValueMap.put(autoscalingFactor.toString(), value);
+ }
+
+ public int getStatistics(String cartridgeType, MockAutoscalingFactor autoscalingFactor) {
+ Map<String, Integer> factorValueMap = statisticsMap.get(cartridgeType);
+ if((factorValueMap != null) && (factorValueMap.containsKey(autoscalingFactor.toString())) ){
+ return factorValueMap.get(autoscalingFactor.toString());
+ }
+ return findDefault(autoscalingFactor);
+ }
+
+ private int findDefault(MockAutoscalingFactor autoscalingFactor) {
+ if(autoscalingFactor == MockAutoscalingFactor.MemoryConsumption) {
+ return DEFAULT_MEMORY_CONSUMPTION;
+ } else if(autoscalingFactor == MockAutoscalingFactor.LoadAverage) {
+ return DEFAULT_LOAD_AVERAGE;
+ } else if(autoscalingFactor == MockAutoscalingFactor.RequestInFlight) {
+ return DEFAULT_REQUESTS_IN_FLIGHT;
+ }
+ throw new RuntimeException("An unknown autoscaling factor found: " + autoscalingFactor);
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/97297b70/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/MockHealthStatisticsNotifier.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/MockHealthStatisticsNotifier.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/MockHealthStatisticsNotifier.java
deleted file mode 100644
index 97680ec..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/MockHealthStatisticsNotifier.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * 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;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.cloud.controller.iaases.mock.MockMemberContext;
-
-/**
- * Health statistics notifier thread for publishing statistics periodically to CEP.
- */
-public class MockHealthStatisticsNotifier implements Runnable {
- private static final Log log = LogFactory.getLog(MockHealthStatisticsNotifier.class);
-
- public static final String MEMORY_CONSUMPTION = "memory_consumption";
- public static final String LOAD_AVERAGE = "load_average";
-
- private final MockMemberContext mockMemberContext;
- private final MockHealthStatisticsPublisher statsPublisher;
- private final double memoryConsumption = 20.0;
- private final double loadAvereage = 40.0;
-
- public MockHealthStatisticsNotifier(MockMemberContext mockMemberContext) {
- this.mockMemberContext = mockMemberContext;
- this.statsPublisher = new MockHealthStatisticsPublisher();
- this.statsPublisher.setEnabled(true);
- }
-
- @Override
- public void run() {
- try {
- if (statsPublisher.isEnabled()) {
- 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 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");
- }
- } catch (Exception e) {
- if (log.isErrorEnabled()) {
- log.error("Could not publish health statistics", e);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/97297b70/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/MockHealthStatisticsPublisher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/MockHealthStatisticsPublisher.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/MockHealthStatisticsPublisher.java
deleted file mode 100644
index 7305aa5..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/MockHealthStatisticsPublisher.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.common.statistics.publisher.WSO2CEPStatisticsPublisher;
-import org.wso2.carbon.databridge.commons.Attribute;
-import org.wso2.carbon.databridge.commons.AttributeType;
-import org.wso2.carbon.databridge.commons.StreamDefinition;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Health statistics publisher for publishing statistics to CEP.
- */
-public class MockHealthStatisticsPublisher extends WSO2CEPStatisticsPublisher {
- private static final Log log = LogFactory.getLog(MockHealthStatisticsPublisher.class);
-
- private static final String DATA_STREAM_NAME = "cartridge_agent_health_stats";
- private static final String VERSION = "1.0.0";
-
- private static StreamDefinition createStreamDefinition() {
- try {
- StreamDefinition streamDefinition = new StreamDefinition(DATA_STREAM_NAME, VERSION);
- streamDefinition.setNickName("agent health stats");
- streamDefinition.setDescription("agent health stats");
- // Payload definition
- List<Attribute> payloadData = new ArrayList<Attribute>();
- payloadData.add(new Attribute("cluster_id", AttributeType.STRING));
- payloadData.add(new Attribute("instance_id", AttributeType.STRING));
- payloadData.add(new Attribute("network_partition_id", AttributeType.STRING));
- payloadData.add(new Attribute("member_id", AttributeType.STRING));
- payloadData.add(new Attribute("partition_id", AttributeType.STRING));
- payloadData.add(new Attribute("health_description", AttributeType.STRING));
- payloadData.add(new Attribute("value", AttributeType.DOUBLE));
- streamDefinition.setPayloadData(payloadData);
- return streamDefinition;
- } catch (Exception e) {
- throw new RuntimeException("Could not create stream definition", e);
- }
- }
-
- public MockHealthStatisticsPublisher() {
- super(createStreamDefinition());
- }
-
- /**
- * Publish health statistics to cep.
- * @param clusterId
- * @param networkPartitionId
- * @param memberId
- * @param partitionId
- * @param health
- * @param value
- */
- public void publish(String clusterId, String instanceId, String networkPartitionId, String memberId, String partitionId, String health, double value) {
- if(log.isDebugEnabled()) {
- log.debug(String.format("Publishing health statistics: [cluster] %s [network-partition] %s [partition] %s [member] %s [health] %s [value] %f",
- clusterId, networkPartitionId, partitionId, memberId, health, value));
- }
- List<Object> payload = new ArrayList<Object>();
- // Payload values
- payload.add(clusterId);
- payload.add(instanceId);
- payload.add(networkPartitionId);
- payload.add(memberId);
- payload.add(partitionId);
- payload.add(health);
- payload.add(value);
- super.publish(payload.toArray());
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/97297b70/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
new file mode 100644
index 0000000..c4fe8fd
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsGenerator.java
@@ -0,0 +1,72 @@
+/*
+ * 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.generator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.iaases.mock.config.MockIaasConfig;
+import org.apache.stratos.common.threading.StratosThreadPool;
+
+import java.util.List;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Mock health statistics generator.
+ */
+public class MockHealthStatisticsGenerator {
+
+ private static final Log log = LogFactory.getLog(MockHealthStatisticsGenerator.class);
+
+ private static ScheduledExecutorService scheduledExecutorService =
+ StratosThreadPool.getScheduledExecutorService("MOCK_STATISTICS_GENERATOR_EXECUTOR_SERVICE", 100);
+ private static boolean scheduled;
+
+ public static void scheduleStatisticsUpdaters() {
+ if(!scheduled) {
+ synchronized (MockHealthStatisticsGenerator.class) {
+ if(!scheduled) {
+ List<MockHealthStatisticsPattern> statisticsPatterns = MockIaasConfig.getInstance().
+ getMockHealthStatisticsConfig().getStatisticsPatterns();
+
+ for (MockHealthStatisticsPattern statisticsPattern : statisticsPatterns) {
+ scheduledExecutorService.scheduleAtFixedRate(new MockHealthStatisticsUpdater(statisticsPattern), 0,
+ statisticsPattern.getSampleDuration(), TimeUnit.SECONDS);
+ }
+
+ if (log.isInfoEnabled()) {
+ log.info("Mock statistics updaters scheduled");
+ }
+ scheduled = true;
+ }
+ }
+ }
+ }
+
+ public static void stopStatisticsUpdaters() {
+ synchronized (MockHealthStatisticsGenerator.class) {
+ scheduledExecutorService.shutdownNow();
+ }
+ }
+
+ public static boolean isScheduled() {
+ return scheduled;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/97297b70/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
new file mode 100644
index 0000000..190941e
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsPattern.java
@@ -0,0 +1,77 @@
+/*
+ * 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.generator;
+
+import org.apache.stratos.cloud.controller.iaases.mock.MockAutoscalingFactor;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Mock health statistics pattern definition.
+ */
+public class MockHealthStatisticsPattern {
+ private String cartridgeType;
+ private MockAutoscalingFactor factor;
+ private List<Integer> sampleValues;
+ private int sampleDuration;
+ private Iterator sampleValuesIterator;
+
+ public MockHealthStatisticsPattern(String cartridgeType, MockAutoscalingFactor factor, List<Integer> sampleValues,
+ int sampleDuration) {
+ this.cartridgeType = cartridgeType;
+ this.factor = factor;
+ this.sampleValues = sampleValues;
+ this.sampleValuesIterator = this.sampleValues.iterator();
+ this.sampleDuration = sampleDuration;
+ }
+
+ public String getCartridgeType() {
+ return cartridgeType;
+ }
+
+ /**
+ * Returns autoscaling factor
+ * @return
+ */
+ public MockAutoscalingFactor getFactor() {
+ return factor;
+ }
+
+ /**
+ * Returns next sample value
+ * @return
+ */
+ public int getNextSample() {
+ if(!sampleValuesIterator.hasNext()) {
+ // Reset iterator
+ sampleValuesIterator = sampleValues.iterator();
+ }
+ return Integer.parseInt(sampleValuesIterator.next().toString());
+ }
+
+ /**
+ * Returns sample duration in seconds
+ * @return
+ */
+ public int getSampleDuration() {
+ return sampleDuration;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/97297b70/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
new file mode 100644
index 0000000..8d61887
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsUpdater.java
@@ -0,0 +1,57 @@
+/*
+ * 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.generator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.iaases.mock.statistics.MockHealthStatistics;
+
+/**
+ * Update health statistics according to the given sample pattern, for each pattern there will be
+ * one updater runnable created.
+ */
+public class MockHealthStatisticsUpdater implements Runnable {
+
+ private static final Log log = LogFactory.getLog(MockHealthStatisticsGenerator.class);
+
+ private MockHealthStatisticsPattern statisticsPattern;
+
+ public MockHealthStatisticsUpdater(MockHealthStatisticsPattern statisticsPattern) {
+ this.statisticsPattern = statisticsPattern;
+ }
+
+ @Override
+ public void run() {
+ try {
+ MockHealthStatistics.getInstance().acquireWriteLock(statisticsPattern.getCartridgeType());
+
+ 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] % [value] %d",
+ statisticsPattern.getCartridgeType(), statisticsPattern.getFactor().toString(), nextSample));
+ }
+ } finally {
+ MockHealthStatistics.getInstance().releaseWriteLock(statisticsPattern.getCartridgeType());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/97297b70/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
new file mode 100644
index 0000000..eb61eaa
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/publisher/MockHealthStatisticsNotifier.java
@@ -0,0 +1,97 @@
+/*
+ * 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.publisher;
+
+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.statistics.MockHealthStatistics;
+
+/**
+ * Health statistics notifier thread for publishing statistics periodically to CEP.
+ */
+public class MockHealthStatisticsNotifier implements Runnable {
+ private static final Log log = LogFactory.getLog(MockHealthStatisticsNotifier.class);
+
+ public static final String MEMORY_CONSUMPTION = "memory_consumption";
+ public static final String LOAD_AVERAGE = "load_average";
+
+ private final MockMemberContext mockMemberContext;
+ private final MockHealthStatisticsPublisher statsPublisher;
+
+ public MockHealthStatisticsNotifier(MockMemberContext mockMemberContext) {
+ this.mockMemberContext = mockMemberContext;
+ this.statsPublisher = new MockHealthStatisticsPublisher();
+ this.statsPublisher.setEnabled(true);
+ }
+
+ @Override
+ public void run() {
+ try {
+ if (statsPublisher.isEnabled()) {
+ try {
+ MockHealthStatistics.getInstance().acquireReadLock(mockMemberContext.getServiceName());
+
+ double memoryConsumption = MockHealthStatistics.getInstance().getStatistics(
+ mockMemberContext.getServiceName(), MockAutoscalingFactor.MemoryConsumption);
+ double loadAvereage = MockHealthStatistics.getInstance().getStatistics(
+ mockMemberContext.getServiceName(), MockAutoscalingFactor.LoadAverage);
+
+ 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 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
+ );
+ } finally {
+ MockHealthStatistics.getInstance().releaseReadLock(mockMemberContext.getServiceName());
+ }
+ } else if (log.isWarnEnabled()) {
+ log.warn("Statistics publisher is disabled");
+ }
+ } catch (Exception e) {
+ if (log.isErrorEnabled()) {
+ log.error("Could not publish health statistics", e);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/97297b70/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/publisher/MockHealthStatisticsPublisher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/publisher/MockHealthStatisticsPublisher.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/publisher/MockHealthStatisticsPublisher.java
new file mode 100644
index 0000000..a4b968c
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/publisher/MockHealthStatisticsPublisher.java
@@ -0,0 +1,91 @@
+/*
+ * 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.publisher;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.statistics.publisher.WSO2CEPStatisticsPublisher;
+import org.wso2.carbon.databridge.commons.Attribute;
+import org.wso2.carbon.databridge.commons.AttributeType;
+import org.wso2.carbon.databridge.commons.StreamDefinition;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Health statistics publisher for publishing statistics to CEP.
+ */
+public class MockHealthStatisticsPublisher extends WSO2CEPStatisticsPublisher {
+ private static final Log log = LogFactory.getLog(MockHealthStatisticsPublisher.class);
+
+ private static final String DATA_STREAM_NAME = "cartridge_agent_health_stats";
+ private static final String VERSION = "1.0.0";
+
+ private static StreamDefinition createStreamDefinition() {
+ try {
+ StreamDefinition streamDefinition = new StreamDefinition(DATA_STREAM_NAME, VERSION);
+ streamDefinition.setNickName("agent health stats");
+ streamDefinition.setDescription("agent health stats");
+ // Payload definition
+ List<Attribute> payloadData = new ArrayList<Attribute>();
+ payloadData.add(new Attribute("cluster_id", AttributeType.STRING));
+ payloadData.add(new Attribute("instance_id", AttributeType.STRING));
+ payloadData.add(new Attribute("network_partition_id", AttributeType.STRING));
+ payloadData.add(new Attribute("member_id", AttributeType.STRING));
+ payloadData.add(new Attribute("partition_id", AttributeType.STRING));
+ payloadData.add(new Attribute("health_description", AttributeType.STRING));
+ payloadData.add(new Attribute("value", AttributeType.DOUBLE));
+ streamDefinition.setPayloadData(payloadData);
+ return streamDefinition;
+ } catch (Exception e) {
+ throw new RuntimeException("Could not create stream definition", e);
+ }
+ }
+
+ public MockHealthStatisticsPublisher() {
+ super(createStreamDefinition());
+ }
+
+ /**
+ * Publish health statistics to cep.
+ * @param clusterId
+ * @param networkPartitionId
+ * @param memberId
+ * @param partitionId
+ * @param health
+ * @param value
+ */
+ public void publish(String clusterId, String instanceId, String networkPartitionId, String memberId, String partitionId, String health, double value) {
+ if(log.isDebugEnabled()) {
+ log.debug(String.format("Publishing health statistics: [cluster] %s [network-partition] %s [partition] %s [member] %s [health] %s [value] %f",
+ clusterId, networkPartitionId, partitionId, memberId, health, value));
+ }
+ List<Object> payload = new ArrayList<Object>();
+ // Payload values
+ payload.add(clusterId);
+ payload.add(instanceId);
+ payload.add(networkPartitionId);
+ payload.add(memberId);
+ payload.add(partitionId);
+ payload.add(health);
+ payload.add(value);
+ super.publish(payload.toArray());
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/97297b70/products/stratos/modules/distribution/src/assembly/bin.xml
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/assembly/bin.xml b/products/stratos/modules/distribution/src/assembly/bin.xml
index 374236b..a7abaf9 100755
--- a/products/stratos/modules/distribution/src/assembly/bin.xml
+++ b/products/stratos/modules/distribution/src/assembly/bin.xml
@@ -662,6 +662,12 @@
<filtered>true</filtered>
<fileMode>755</fileMode>
</file>
+ <file>
+ <source>src/main/conf/mock-iaas.xml</source>
+ <outputDirectory>${pom.artifactId}-${pom.version}/repository/conf</outputDirectory>
+ <filtered>true</filtered>
+ <fileMode>755</fileMode>
+ </file>
<!--iindentity.xml and application-authentication.xml for oAuth feature -->
<file>
<source>src/main/conf/identity.xml</source>
http://git-wip-us.apache.org/repos/asf/stratos/blob/97297b70/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
new file mode 100644
index 0000000..a535a4c
--- /dev/null
+++ b/products/stratos/modules/distribution/src/main/conf/mock-iaas.xml
@@ -0,0 +1,37 @@
+<!--
+ ~ 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.
+ -->
+
+<mock-iaas>
+ <health-statistics>
+ <cartridge type="tomcat">
+ <pattern factor="memory-consumption">
+ <!-- Sample values -->
+ <sampleValues>20,30,40,50,60,70,50,40,30,20,20,20,20,20,20,20</sampleValues>
+ <!-- Duration of each sample value in seconds -->
+ <sampleDuration>30</sampleDuration>
+ </pattern>
+ <pattern factor="load-average">
+ <!-- Sample values -->
+ <sampleValues>20</sampleValues>
+ <!-- Duration of each sample value in seconds -->
+ <sampleDuration>60</sampleDuration>
+ </pattern>
+ </cartridge>
+ </health-statistics>
+</mock-iaas>
\ No newline at end of file