You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ga...@apache.org on 2015/09/08 07:17:39 UTC
stratos git commit: Update the mock health statistics
Repository: stratos
Updated Branches:
refs/heads/master fa985691e -> 78300f465
Update the mock health statistics
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/78300f46
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/78300f46
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/78300f46
Branch: refs/heads/master
Commit: 78300f46511abd218b77d8647b8800ed68afbd74
Parents: fa98569
Author: gayangunarathne <ga...@wso2.com>
Authored: Tue Sep 8 10:47:18 2015 +0530
Committer: gayangunarathne <ga...@wso2.com>
Committed: Tue Sep 8 10:47:18 2015 +0530
----------------------------------------------------------------------
.../iaas/statistics/MockHealthStatistics.java | 3 +-
.../application/SingleClusterScalingTest.java | 114 +++++++++++++++++++
2 files changed, 116 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/78300f46/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/statistics/MockHealthStatistics.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/statistics/MockHealthStatistics.java b/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/statistics/MockHealthStatistics.java
index 0acfd96..d8563c5 100644
--- a/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/statistics/MockHealthStatistics.java
+++ b/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/statistics/MockHealthStatistics.java
@@ -80,7 +80,8 @@ public class MockHealthStatistics {
* @return
*/
public int getStatistics(String cartridgeType, MockScalingFactor scalingFactor) throws NoStatisticsFoundException {
- Map<String, Integer> factorValueMap = statisticsMap.get(cartridgeType);
+ String[] cartridgeDetails=cartridgeType.split("~");
+ Map<String, Integer> factorValueMap = statisticsMap.get(cartridgeDetails[0]);
if (factorValueMap != null) {
if (factorValueMap.containsKey(scalingFactor.toString())) {
return factorValueMap.get(scalingFactor.toString());
http://git-wip-us.apache.org/repos/asf/stratos/blob/78300f46/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java
index 5f40baf..46412db 100644
--- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java
@@ -48,6 +48,8 @@ public class SingleClusterScalingTest extends StratosTestServerManager {
private static final Log log = LogFactory.getLog(SampleApplicationsTest.class);
private static final String RESOURCES_PATH = "/single-cluster-scaling-test";
private static final int CLUSTER_SCALE_UP_TIMEOUT = 180000;
+ private static final int CLUSTER_SCALE_DOWN_TIMEOUT = 360000;
+ private int activeInstancesAfterScaleup = 0;
@Test
@@ -230,6 +232,7 @@ public class SingleClusterScalingTest extends StratosTestServerManager {
}
clusterScaleup = activeInstances >= clusterDataHolder.getMinInstances();
if(clusterScaleup) {
+ activeInstancesAfterScaleup = activeInstances;
break;
}
}
@@ -242,4 +245,115 @@ public class SingleClusterScalingTest extends StratosTestServerManager {
assertEquals(String.format("Cluster did not get scaled up: [cluster-id] %s", clusterId),
clusterScaleup, true);
}
+
+ /**
+ * Assert application activation
+ *
+ * @param applicationName
+ */
+ private void assertClusterWithScaleDown(String applicationName,int tenantId) {
+ Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationName,tenantId);
+ assertNotNull(String.format("Application is not found: [application-id] %s",
+ applicationName), application);
+ boolean clusterScaleDown = false;
+ String clusterId = null;
+ long startTime = System.currentTimeMillis();
+ while (!clusterScaleDown) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ignore) {
+ }
+ Set<ClusterDataHolder> clusterDataHolderSet = application.getClusterDataRecursively();
+ for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) {
+ String serviceName = clusterDataHolder.getServiceUuid();
+ clusterId = clusterDataHolder.getClusterId();
+ Service service = TopologyManager.getTopology().getService(serviceName);
+ assertNotNull(String.format("Service is not found: [application-id] %s [service] %s",
+ applicationName, serviceName), service);
+
+ Cluster cluster = service.getCluster(clusterId);
+ assertNotNull(String.format("Cluster is not found: [application-id] %s [service] %s [cluster-id] %s",
+ applicationName, serviceName, clusterId), cluster);
+ for (ClusterInstance instance : cluster.getInstanceIdToInstanceContextMap().values()) {
+ int activeInstances = 0;
+ for (Member member : cluster.getMembers()) {
+ if (member.getClusterInstanceId().equals(instance.getInstanceId())) {
+ if (member.getStatus().equals(MemberStatus.Active)) {
+ activeInstances++;
+ }
+ }
+ }
+
+ if(activeInstances > activeInstancesAfterScaleup) {
+ activeInstancesAfterScaleup = activeInstances;
+ }
+
+ clusterScaleDown = activeInstancesAfterScaleup - 1 == activeInstances;
+ if(clusterScaleDown) {
+ break;
+ }
+
+ }
+
+ application = ApplicationManager.getApplications().getApplicationByTenant(applicationName,tenantId);
+ if ((System.currentTimeMillis() - startTime) > CLUSTER_SCALE_DOWN_TIMEOUT) {
+ break;
+ }
+ }
+ }
+ assertEquals(String.format("Cluster did not get scaled up: [cluster-id] %s", clusterId),
+ clusterScaleDown, true);
+ }
+
+ /**
+ * Assert application activation
+ *
+ * @param applicationName
+ */
+ private void assertClusterScaleDownToMinimumCount(String applicationName) {
+ Application application = ApplicationManager.getApplications().getApplication(applicationName);
+ assertNotNull(String.format("Application is not found: [application-id] %s",
+ applicationName), application);
+ boolean clusterScaleDown = false;
+ String clusterId = null;
+ long startTime = System.currentTimeMillis();
+ while (!clusterScaleDown) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ignore) {
+ }
+ Set<ClusterDataHolder> clusterDataHolderSet = application.getClusterDataRecursively();
+ for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) {
+ String serviceName = clusterDataHolder.getServiceType();
+ clusterId = clusterDataHolder.getClusterId();
+ Service service = TopologyManager.getTopology().getService(serviceName);
+ assertNotNull(String.format("Service is not found: [application-id] %s [service] %s",
+ applicationName, serviceName), service);
+
+ Cluster cluster = service.getCluster(clusterId);
+ assertNotNull(String.format("Cluster is not found: [application-id] %s [service] %s [cluster-id] %s",
+ applicationName, serviceName, clusterId), cluster);
+ for (ClusterInstance instance : cluster.getInstanceIdToInstanceContextMap().values()) {
+ int activeInstances = 0;
+ for (Member member : cluster.getMembers()) {
+ if (member.getClusterInstanceId().equals(instance.getInstanceId())) {
+ if (member.getStatus().equals(MemberStatus.Active)) {
+ activeInstances++;
+ }
+ }
+ }
+ clusterScaleDown = activeInstances == clusterDataHolder.getMinInstances();
+ if(clusterScaleDown) {
+ break;
+ }
+ }
+ application = ApplicationManager.getApplications().getApplication(applicationName);
+ if ((System.currentTimeMillis() - startTime) > CLUSTER_SCALE_DOWN_TIMEOUT) {
+ break;
+ }
+ }
+ }
+ assertEquals(String.format("Cluster did not get scaled up: [cluster-id] %s", clusterId),
+ clusterScaleDown, true);
+ }
}