Merge with the stratos-4.1.x branch changes
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/be922cc6 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/be922cc6 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/be922cc6 Branch: refs/heads/master Commit: be922cc6ad1ff8c3b1db0da19204e5a7a3f1cc67 Parents: aece0c4 Author: gayangunarathne <[email protected]> Authored: Mon Nov 2 20:59:12 2015 +0530 Committer: gayangunarathne <[email protected]> Committed: Mon Nov 2 20:59:12 2015 +0530 ---------------------------------------------------------------------- .../services/impl/AutoscalerServiceImpl.java | 61 ++-- .../group/GroupStatusProcessorChain.java | 4 +- .../integration/common/TopologyHandler.java | 120 +++---- .../SingleClusterScalingTestCase.java | 354 ++++++++++++++++++- .../src/test/resources/common/jndi.properties | 22 ++ 5 files changed, 458 insertions(+), 103 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/be922cc6/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java index b9f436a..2264a82 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java @@ -25,21 +25,15 @@ import org.apache.stratos.autoscaler.algorithms.networkpartition.NetworkPartitio import org.apache.stratos.autoscaler.applications.ApplicationHolder; import org.apache.stratos.autoscaler.applications.parser.ApplicationParser; import org.apache.stratos.autoscaler.applications.parser.DefaultApplicationParser; -import org.apache.stratos.autoscaler.applications.pojo.ApplicationClusterContext; -import org.apache.stratos.autoscaler.applications.pojo.ApplicationContext; -import org.apache.stratos.autoscaler.applications.pojo.ArtifactRepositoryContext; -import org.apache.stratos.autoscaler.applications.pojo.CartridgeContext; -import org.apache.stratos.autoscaler.applications.pojo.ComponentContext; -import org.apache.stratos.autoscaler.applications.pojo.GroupContext; -import org.apache.stratos.autoscaler.applications.pojo.SubscribableInfoContext; +import org.apache.stratos.autoscaler.applications.pojo.*; import org.apache.stratos.autoscaler.applications.topic.ApplicationBuilder; +import org.apache.stratos.autoscaler.applications.topic.ApplicationsEventPublisher; import org.apache.stratos.autoscaler.client.AutoscalerCloudControllerClient; import org.apache.stratos.autoscaler.context.AutoscalerContext; import org.apache.stratos.autoscaler.context.InstanceContext; import org.apache.stratos.autoscaler.context.cluster.ClusterInstanceContext; import org.apache.stratos.autoscaler.context.partition.ClusterLevelPartitionContext; import org.apache.stratos.autoscaler.context.partition.network.NetworkPartitionContext; -import org.apache.stratos.autoscaler.event.publisher.ClusterStatusEventPublisher; import org.apache.stratos.autoscaler.exception.*; import org.apache.stratos.autoscaler.exception.application.ApplicationDefinitionException; import org.apache.stratos.autoscaler.exception.application.InvalidApplicationPolicyException; @@ -49,7 +43,6 @@ import org.apache.stratos.autoscaler.exception.policy.*; import org.apache.stratos.autoscaler.monitor.Monitor; import org.apache.stratos.autoscaler.monitor.cluster.ClusterMonitor; import org.apache.stratos.autoscaler.monitor.component.ApplicationMonitor; -import org.apache.stratos.autoscaler.monitor.component.GroupMonitor; import org.apache.stratos.autoscaler.pojo.Dependencies; import org.apache.stratos.autoscaler.pojo.ServiceGroup; import org.apache.stratos.autoscaler.pojo.policy.PolicyManager; @@ -80,7 +73,6 @@ import org.apache.stratos.messaging.domain.instance.ClusterInstance; import org.apache.stratos.messaging.domain.instance.Instance; import org.apache.stratos.messaging.domain.topology.Cluster; import org.apache.stratos.messaging.domain.topology.Member; -import org.apache.stratos.messaging.message.receiver.application.ApplicationManager; import org.apache.stratos.messaging.message.receiver.topology.TopologyManager; import org.wso2.carbon.registry.api.RegistryException; @@ -150,6 +142,7 @@ public class AutoscalerServiceImpl implements AutoscalerService { log.info(String.format("Application added successfully: [application-id] %s", applicationContext.getApplicationId())); } + ApplicationsEventPublisher.sendApplicationCreatedEvent(application); return true; } @@ -163,8 +156,9 @@ public class AutoscalerServiceImpl implements AutoscalerService { } if (AutoscalerContext.getInstance().getApplicationContext(applicationId) == null) { - String message = "Application is not found as ApplicationContext. Please add application before updating it: " + - "[application-id] " + applicationId; + String message = + "Application is not found as ApplicationContext. Please add application before updating it: " + + "[application-id] " + applicationId; log.error(message); throw new ApplicationDefinitionException(message); } @@ -310,7 +304,7 @@ public class AutoscalerServiceImpl implements AutoscalerService { * @param clusterIds */ private void addApplicationSignUp(ApplicationContext applicationContext, String applicationKey, - List<String> clusterIds) { + List<String> clusterIds) { try { if (log.isInfoEnabled()) { @@ -436,7 +430,7 @@ public class AutoscalerServiceImpl implements AutoscalerService { } private void updateArtifactRepositoryList(List<ArtifactRepository> artifactRepositoryList, - CartridgeContext[] cartridgeContexts) { + CartridgeContext[] cartridgeContexts) { if (cartridgeContexts == null) { return; @@ -463,7 +457,7 @@ public class AutoscalerServiceImpl implements AutoscalerService { public boolean undeployApplication(String applicationId, boolean force) throws RemoteException, StratosManagerServiceApplicationSignUpExceptionException, - UnremovableApplicationException { + UnremovableApplicationException { AutoscalerContext asCtx = AutoscalerContext.getInstance(); ApplicationMonitor appMonitor = asCtx.getAppMonitor(applicationId); @@ -509,7 +503,7 @@ public class AutoscalerServiceImpl implements AutoscalerService { return false; } else { log.info(String.format("Previous graceful un-deployment is in progress for " - + "[application-id] %s , thus terminating instances directly", applicationId)); + + "[application-id] %s , thus terminating instances directly", applicationId)); appMonitor.setForce(true); terminateAllMembersAndClustersForcefully(applicationId); } @@ -785,8 +779,9 @@ public class AutoscalerServiceImpl implements AutoscalerService { @Override public String findClusterId(String applicationId, String alias) { + ApplicationHolder.acquireReadLock(); try { - Application application = ApplicationManager.getApplications().getApplication(applicationId); + Application application = ApplicationHolder.getApplications().getApplication(applicationId); if (application != null) { ClusterDataHolder clusterData = application.getClusterDataHolderRecursivelyByAlias(alias); @@ -862,7 +857,8 @@ public class AutoscalerServiceImpl implements AutoscalerService { } @Override - public boolean removeApplicationPolicy(String applicationPolicyId) throws InvalidPolicyException, UnremovablePolicyException { + public boolean removeApplicationPolicy(String applicationPolicyId) + throws InvalidPolicyException, UnremovablePolicyException { if (removableApplicationPolicy(applicationPolicyId)) { return PolicyManager.getInstance().removeApplicationPolicy(applicationPolicyId); @@ -921,9 +917,9 @@ public class AutoscalerServiceImpl implements AutoscalerService { } Application application; + ApplicationHolder.acquireReadLock(); try { - ApplicationManager.acquireReadLockForApplication(applicationId); - application = ApplicationManager.getApplications().getApplication(applicationId); + application = ApplicationHolder.getApplications().getApplication(applicationId); if (application == null) { log.warn(String.format( "Could not find application, thus no members to be terminated " + "[application-id] %s", @@ -998,8 +994,8 @@ public class AutoscalerServiceImpl implements AutoscalerService { .terminateInstanceForcefully(memberIdToTerminate); } catch (Exception e) { log.error(String.format( - "Forceful termination of member %s has failed, but continuing forceful " - + "deletion of other members", memberIdToTerminate)); + "Forceful termination of member %s has failed, but continuing forceful " + + "deletion of other members", memberIdToTerminate)); } } } @@ -1160,7 +1156,7 @@ public class AutoscalerServiceImpl implements AutoscalerService { @Override public boolean updateDeploymentPolicy(DeploymentPolicy deploymentPolicy) throws RemoteException, InvalidDeploymentPolicyException, DeploymentPolicyNotExistsException, - InvalidPolicyException, CloudControllerConnectionException { + InvalidPolicyException, CloudControllerConnectionException { validateDeploymentPolicy(deploymentPolicy); @@ -1217,9 +1213,10 @@ public class AutoscalerServiceImpl implements AutoscalerService { throw new InvalidDeploymentPolicyException(message, e); } catch (CloudControllerServiceInvalidCartridgeTypeExceptionException e) { - String message = "Invalid cartridge type, Cluster monitor update failed for [deployment-policy] " - + deploymentPolicy.getDeploymentPolicyID() + " [cartridge] " - + clusterMonitor.getClusterContext().getServiceId(); + String message = + "Invalid cartridge type, Cluster monitor update failed for [deployment-policy] " + + deploymentPolicy.getDeploymentPolicyID() + " [cartridge] " + + clusterMonitor.getClusterContext().getServiceId(); log.error(message); throw new InvalidDeploymentPolicyException(message, e); } @@ -1231,13 +1228,15 @@ public class AutoscalerServiceImpl implements AutoscalerService { } private void removeOldPartitionsFromClusterMonitor(NetworkPartitionContext clusterLevelNetworkPartitionContext, - NetworkPartitionRef networkPartition) { + NetworkPartitionRef networkPartition) { - for (InstanceContext instanceContext : clusterLevelNetworkPartitionContext.getInstanceIdToInstanceContextMap().values()) { + for (InstanceContext instanceContext : clusterLevelNetworkPartitionContext.getInstanceIdToInstanceContextMap() + .values()) { ClusterInstanceContext clusterInstanceContext = (ClusterInstanceContext) instanceContext; - for (ClusterLevelPartitionContext clusterLevelPartitionContext : clusterInstanceContext.getPartitionCtxts()) { + for (ClusterLevelPartitionContext clusterLevelPartitionContext : clusterInstanceContext + .getPartitionCtxts()) { if (null == networkPartition.getPartitionRef(clusterLevelPartitionContext.getPartitionId())) { @@ -1264,9 +1263,9 @@ public class AutoscalerServiceImpl implements AutoscalerService { } private void addNewPartitionsToClusterMonitor(NetworkPartitionContext clusterLevelNetworkPartitionContext, - NetworkPartitionRef networkPartitionRef, String deploymentPolicyID, String cartridgeType) + NetworkPartitionRef networkPartitionRef, String deploymentPolicyID, String cartridgeType) throws RemoteException, CloudControllerServiceInvalidPartitionExceptionException, - CloudControllerServiceInvalidCartridgeTypeExceptionException { + CloudControllerServiceInvalidCartridgeTypeExceptionException { boolean validationOfNetworkPartitionRequired = false; for (PartitionRef partition : networkPartitionRef.getPartitionRefs()) { http://git-wip-us.apache.org/repos/asf/stratos/blob/be922cc6/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusProcessorChain.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusProcessorChain.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusProcessorChain.java index feddaf5..98ee1e0 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusProcessorChain.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusProcessorChain.java @@ -38,9 +38,9 @@ public class GroupStatusProcessorChain extends StatusProcessorChain { new GroupStatusTerminatedProcessor(); add(groupStatusTerminatedProcessor); - GroupStatusTerminatingProcessor groupStatusTerminatingProcessor = + /*GroupStatusTerminatingProcessor groupStatusTerminatingProcessor = new GroupStatusTerminatingProcessor(); - add(groupStatusTerminatingProcessor); + add(groupStatusTerminatingProcessor);*/ GroupStatusInactiveProcessor groupStatusInactiveProcessor = new GroupStatusInactiveProcessor(); http://git-wip-us.apache.org/repos/asf/stratos/blob/be922cc6/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/TopologyHandler.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/TopologyHandler.java b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/TopologyHandler.java index ad4887b..721a5c6 100644 --- a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/TopologyHandler.java +++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/TopologyHandler.java @@ -127,7 +127,8 @@ public class TopologyHandler { break; } } - assertEquals(String.format("Application Topology didn't get initialized "), applicationTopologyInitialized, true); + assertEquals(String.format("Application Topology didn't get initialized "), applicationTopologyInitialized, + true); } /** @@ -152,12 +153,11 @@ public class TopologyHandler { /** * Assert application activation * - * @param tenantId * @param applicationName */ - public void assertApplicationStatus(String applicationName, ApplicationStatus status, int tenantId) { + public void assertApplicationStatus(String applicationName, ApplicationStatus status) { long startTime = System.currentTimeMillis(); - Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationName, tenantId); + Application application = ApplicationManager.getApplications().getApplication(applicationName); while (!((application != null) && (application.getStatus() == status))) { try { Thread.sleep(1000); @@ -170,26 +170,14 @@ public class TopologyHandler { } } assertNotNull(String.format("Application is not found: [application-id] %s", applicationName), application); - assertEquals(String.format("Application status did not change to %s: [application-id] %s", - status.toString(), applicationName), - status, application.getStatus()); - } - - public Application getApplication(String applicationName, int tenantId) { - return ApplicationManager.getApplications().getApplicationByTenant(applicationName, tenantId); - } - - public void assertApplicationForNonAvailability(String applicationName, int tenantId) { - - Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationName, tenantId); - assertNull(String.format("Application is found for other tenant : [application-id] %s", applicationName),application); + assertEquals(String.format("Application status did not change to %s: [application-id] %s", status.toString(), + applicationName), status, application.getStatus()); } /** * Assert application activation * * @param applicationName - * @param tenantId */ public void assertGroupActivation(String applicationName) { Application application = ApplicationManager.getApplications().getApplication(applicationName); @@ -205,7 +193,6 @@ public class TopologyHandler { * Assert application activation * * @param applicationName - * @param tenantId */ public void assertClusterActivation(String applicationName) { Application application = ApplicationManager.getApplications().getApplication(applicationName); @@ -213,7 +200,7 @@ public class TopologyHandler { Set<ClusterDataHolder> clusterDataHolderSet = application.getClusterDataRecursively(); for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) { - String serviceUuid = clusterDataHolder.getServiceUuid(); + String serviceName = clusterDataHolder.getServiceType(); String clusterId = clusterDataHolder.getClusterId(); Service service = TopologyManager.getTopology().getService(serviceName); assertNotNull(String.format("Service is not found: [application-id] %s [service] %s", applicationName, @@ -228,9 +215,10 @@ public class TopologyHandler { member.getClusterId())); } boolean clusterActive = false; - + int activeInstances; for (ClusterInstance instance : cluster.getInstanceIdToInstanceContextMap().values()) { - int activeInstances = 0; + log.info("Checking for active members in cluster instance: " + instance.getInstanceId()); + activeInstances = 0; for (Member member : cluster.getMembers()) { if (member.getClusterInstanceId().equals(instance.getInstanceId())) { if (member.getStatus().equals(MemberStatus.Active)) { @@ -242,28 +230,24 @@ public class TopologyHandler { assertTrue(String.format("Cluster status did not change to active: [cluster-id] %s", clusterId), clusterActive); } - assertEquals(String.format("Cluster status did not change to active: [cluster-id] %s", clusterId), - clusterActive, true); } - } /** - * Assert application activation + * Get all the members that belongs to the cluster identified by cartridge name and application name in the + * topology * - * @param tenantId + * @param cartridgeName * @param applicationName */ - - public void terminateMemberFromCluster(String cartridgeName, String applicationName, IntegrationMockClient mockIaasApiClient, int tenantId) { - Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationName, tenantId); - assertNotNull(String.format("Application is not found: [application-id] %s", - applicationName), application); - + public Map<String, Member> getMembersForCluster(String cartridgeName, String applicationName) { + Application application = ApplicationManager.getApplications().getApplication(applicationName); + assertNotNull(String.format("Application is not found: [application-id] %s", applicationName), application); Set<ClusterDataHolder> clusterDataHolderSet = application.getClusterDataRecursively(); + Map<String, Member> memberMap = new HashMap<String, Member>(); for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) { - String serviceUuid = clusterDataHolder.getServiceUuid(); - if(cartridgeName.equals(serviceUuid)) { + String serviceName = clusterDataHolder.getServiceType(); + if (cartridgeName.equals(serviceName)) { String clusterId = clusterDataHolder.getClusterId(); Service service = TopologyManager.getTopology().getService(serviceName); assertNotNull(String.format("Service is not found: [application-id] %s [service] %s", applicationName, @@ -271,19 +255,16 @@ public class TopologyHandler { Cluster cluster = service.getCluster(clusterId); assertNotNull(String.format("Cluster is not found: [application-id] %s [service] %s [cluster-id] %s", - applicationName, serviceUuid, clusterId), cluster); - boolean memberTerminated = false; - + applicationName, serviceName, clusterId), cluster); for (ClusterInstance instance : cluster.getInstanceIdToInstanceContextMap().values()) { for (Member member : cluster.getMembers()) { - if (member.getClusterInstanceId().equals(instance.getInstanceId())) { - if (member.getStatus().equals(MemberStatus.Active)) { - mockIaasApiClient.terminateInstance(member.getMemberId()); - memberTerminated = true; - break; - } - } + memberMap.put(member.getMemberId(), member); } + } + } + } + return memberMap; + } /** * Terminate a member in mock iaas directly without involving Stratos REST API @@ -316,7 +297,6 @@ public class TopologyHandler { log.error("Member did not get removed from the topology within timeout period"); break; } - assertTrue("Any member couldn't be terminated from the mock IaaS client", memberTerminated); } try { Thread.sleep(1000); @@ -324,10 +304,11 @@ public class TopologyHandler { log.error("Could not sleep", e); } } - + assertTrue(String.format("Member [member-id] %s did not get removed from the topology", memberId), + hasMemberRemoved); } - public void assertClusterMinMemberCount(String applicationName, int minMembers, int tenantId) { + public void assertClusterMinMemberCount(String applicationName, int minMembers) { long startTime = System.currentTimeMillis(); Application application = ApplicationManager.getApplications().getApplication(applicationName); @@ -335,7 +316,7 @@ public class TopologyHandler { Set<ClusterDataHolder> clusterDataHolderSet = application.getClusterDataRecursively(); for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) { - String serviceName = clusterDataHolder.getServiceUuid(); + String serviceName = clusterDataHolder.getServiceType(); String clusterId = clusterDataHolder.getClusterId(); Service service = TopologyManager.getTopology().getService(serviceName); assertNotNull(String.format("Service is not found: [application-id] %s [service] %s", applicationName, @@ -377,8 +358,9 @@ public class TopologyHandler { } } clusterActive = activeInstances >= minMembers; - assertNotNull(String.format("Cluster is not found: [application-id] %s [service] %s [cluster-id] %s", - applicationName, serviceName, clusterId), cluster); + assertNotNull( + String.format("Cluster is not found: [application-id] %s [service] %s [cluster-id] %s", + applicationName, serviceName, clusterId), cluster); if ((System.currentTimeMillis() - startTime) > APPLICATION_ACTIVATION_TIMEOUT) { log.error("Cluster did not activate within timeout period"); @@ -396,11 +378,10 @@ public class TopologyHandler { * Assert application activation * * @param applicationName - * @param tenantId */ - public boolean assertApplicationUndeploy(String applicationName, int tenantId) { + public boolean assertApplicationUndeploy(String applicationName) { long startTime = System.currentTimeMillis(); - Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationName, tenantId); + Application application = ApplicationManager.getApplications().getApplication(applicationName); ApplicationContext applicationContext = null; try { applicationContext = AutoscalerServiceClient.getInstance().getApplication(applicationName); @@ -434,7 +415,8 @@ public class TopologyHandler { .equals(APPLICATION_STATUS_UNDEPLOYING)) { return false; } - assertEquals(String.format("Application status did not change to Created: [application-id] %s", applicationName), + assertEquals( + String.format("Application status did not change to Created: [application-id] %s", applicationName), APPLICATION_STATUS_CREATED, applicationContext.getStatus()); return true; } @@ -442,12 +424,11 @@ public class TopologyHandler { /** * Assert application activation * - * @param tenantId * @param applicationName */ - public void assertGroupInstanceCount(String applicationName, String groupAlias, int count, int tenantId) { + public void assertGroupInstanceCount(String applicationName, String groupAlias, int count) { long startTime = System.currentTimeMillis(); - Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationName, tenantId); + Application application = ApplicationManager.getApplications().getApplication(applicationName); if (application != null) { Group group = application.getGroupRecursively(groupAlias); while (group.getInstanceContextCount() != count) { @@ -472,7 +453,8 @@ public class TopologyHandler { } } } - assertEquals(String.format("Application status did not change to active: [application-id] %s", applicationName), + assertEquals( + String.format("Application status did not change to active: [application-id] %s", applicationName), group.getInstanceContextCount(), count); } assertNotNull(String.format("Application is not found: [application-id] %s", applicationName), application); @@ -481,7 +463,8 @@ public class TopologyHandler { public void assertApplicationNotExists(String applicationName) { Application application = ApplicationManager.getApplications().getApplication(applicationName); - assertNull(String.format("Application is found in the topology : [application-id] %s", applicationName), application); + assertNull(String.format("Application is found in the topology : [application-id] %s", applicationName), + application); } private void addTopologyEventListeners() { @@ -490,7 +473,10 @@ public class TopologyHandler { protected void onEvent(Event event) { MemberTerminatedEvent memberTerminatedEvent = (MemberTerminatedEvent) event; getTerminatedMembers().put(memberTerminatedEvent.getMemberId(), System.currentTimeMillis()); - + getActivateddMembers().remove(((MemberTerminatedEvent) event).getMemberId()); + getCreatedMembers().remove(((MemberTerminatedEvent) event).getMemberId()); + getInActiveMembers().remove(((MemberTerminatedEvent) event).getMemberId()); + getTerminatingMembers().remove(((MemberTerminatedEvent) event).getMemberId()); } }); @@ -610,8 +596,8 @@ public class TopologyHandler { return appId + "-" + groupId + "-" + instanceId; } - public String getClusterIdFromAlias(String applicationId, String alias,int tenantId) { - Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationId,tenantId); + public String getClusterIdFromAlias(String applicationId, String alias) { + Application application = ApplicationManager.getApplications().getApplication(applicationId); assertNotNull(application); ClusterDataHolder dataHolder = application.getClusterDataHolderRecursivelyByAlias(alias); @@ -621,14 +607,14 @@ public class TopologyHandler { } public void removeMembersFromMaps(String applicationId) { - for(Map.Entry<String, Long> entry: getActivateddMembers().entrySet()) { - if(entry.getKey().contains(applicationId)) { + for (Map.Entry<String, Long> entry : getActivateddMembers().entrySet()) { + if (entry.getKey().contains(applicationId)) { getActivateddMembers().remove(entry.getKey()); } } - for(Map.Entry<String, Long> entry: getTerminatedMembers().entrySet()) { - if(entry.getKey().contains(applicationId)) { + for (Map.Entry<String, Long> entry : getTerminatedMembers().entrySet()) { + if (entry.getKey().contains(applicationId)) { getTerminatedMembers().remove(entry.getKey()); } } http://git-wip-us.apache.org/repos/asf/stratos/blob/be922cc6/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTestCase.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTestCase.java index e84bc3c..0b96210 100644 --- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTestCase.java +++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTestCase.java @@ -1,7 +1,355 @@ +/* + * 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.integration.tests.application; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.common.beans.application.ApplicationBean; +import org.apache.stratos.common.beans.policy.deployment.ApplicationPolicyBean; +import org.apache.stratos.integration.common.RestConstants; +import org.apache.stratos.integration.common.TopologyHandler; +import org.apache.stratos.integration.tests.StratosIntegrationTest; +import org.apache.stratos.messaging.domain.application.Application; +import org.apache.stratos.messaging.domain.application.ApplicationStatus; +import org.apache.stratos.messaging.domain.application.ClusterDataHolder; +import org.apache.stratos.messaging.domain.instance.ClusterInstance; +import org.apache.stratos.messaging.domain.topology.Cluster; +import org.apache.stratos.messaging.domain.topology.Member; +import org.apache.stratos.messaging.domain.topology.MemberStatus; +import org.apache.stratos.messaging.domain.topology.Service; +import org.apache.stratos.messaging.message.receiver.application.ApplicationManager; +import org.apache.stratos.messaging.message.receiver.topology.TopologyManager; +import org.testng.annotations.Test; + +import java.util.Set; + +import static org.testng.Assert.assertEquals; +import static org.testng.AssertJUnit.assertNotNull; + /** - * Created by gayan on 11/2/15. + * This will handle the scale-up and scale-down of a particular cluster bursting test cases */ -public class SingleClusterScalingTestCase { -} +public class SingleClusterScalingTestCase extends StratosIntegrationTest { + private static final Log log = LogFactory.getLog(SingleClusterScalingTestCase.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(timeOut = APPLICATION_TEST_TIMEOUT, groups = {"stratos.application.deployment"}) + public void testDeployApplication() throws Exception { + TopologyHandler topologyHandler = TopologyHandler.getInstance(); + String autoscalingPolicyId = "autoscaling-policy-single-cluster-scaling-test"; + + boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + + "/" + autoscalingPolicyId + ".json", + RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); + assertEquals(addedScalingPolicy, true); + + boolean addedC1 = restClient.addEntity( + RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c7-single-cluster-scaling-test.json", + RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); + assertEquals(addedC1, true); + + boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + "network-partition-single-cluster-scaling-test.json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(addedN1, true); + + boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + + "deployment-policy-single-cluster-scaling-test.json", + RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertEquals(addedDep, true); + + boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" + + "single-cluster-scaling-test.json", RestConstants.APPLICATIONS, + RestConstants.APPLICATIONS_NAME); + assertEquals(added, true); + + ApplicationBean bean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, + "single-cluster-scaling-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); + assertEquals(bean.getApplicationId(), "single-cluster-scaling-test"); + + boolean addAppPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" + + "application-policy-single-cluster-scaling-test.json", RestConstants.APPLICATION_POLICIES, + RestConstants.APPLICATION_POLICIES_NAME); + assertEquals(addAppPolicy, true); + + ApplicationPolicyBean policyBean = (ApplicationPolicyBean) restClient.getEntity( + RestConstants.APPLICATION_POLICIES, + "application-policy-single-cluster-scaling-test", ApplicationPolicyBean.class, + RestConstants.APPLICATION_POLICIES_NAME); + + //deploy the application + String resourcePath = RestConstants.APPLICATIONS + "/" + "single-cluster-scaling-test" + + RestConstants.APPLICATIONS_DEPLOY + "/" + "application-policy-single-cluster-scaling-test"; + boolean deployed = restClient.deployEntity(resourcePath, + RestConstants.APPLICATIONS_NAME); + assertEquals(deployed, true); + + //Application active handling + topologyHandler.assertApplicationStatus(bean.getApplicationId() + , ApplicationStatus.Active); + + //Cluster active handling + topologyHandler.assertClusterActivation(bean.getApplicationId()); + + //Verifying whether members got created using round robin algorithm + assertClusterWithScalingup(bean.getApplicationId()); + + //assert scale-down + assertClusterWithScaleDown(bean.getApplicationId()); + + //Check whether cluster could scale-down upto the minimum + assertClusterScaleDownToMinimumCount(bean.getApplicationId()); + + boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, + autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME); + assertEquals(removedAuto, false); + + boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-single-cluster-scaling-test", + RestConstants.NETWORK_PARTITIONS_NAME); + //Trying to remove the used network partition + assertEquals(removedNet, false); + + boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, + "deployment-policy-single-cluster-scaling-test", RestConstants.DEPLOYMENT_POLICIES_NAME); + assertEquals(removedDep, false); + + //Un-deploying the application + String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + "single-cluster-scaling-test" + + RestConstants.APPLICATIONS_UNDEPLOY; + + boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy, + RestConstants.APPLICATIONS_NAME); + assertEquals(unDeployed, true); + + boolean undeploy = topologyHandler.assertApplicationUndeploy("single-cluster-scaling-test"); + if (!undeploy) { + //Need to forcefully undeploy the application + log.info("Force undeployment is going to start for the [application] " + "single-cluster-scaling-test"); + + restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + "single-cluster-scaling-test" + + RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS); + + boolean forceUndeployed = topologyHandler.assertApplicationUndeploy("single-cluster-scaling-test"); + assertEquals(forceUndeployed, true, String.format("Forceful undeployment failed for the application %s", + "single-cluster-scaling-test")); + } + + boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, "single-cluster-scaling-test", + RestConstants.APPLICATIONS_NAME); + assertEquals(removed, true); + + ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, + "single-cluster-scaling-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); + assertEquals(beanRemoved, null); + + boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c7-single-cluster-scaling-test", + RestConstants.CARTRIDGES_NAME); + assertEquals(removedC1, true); + + + removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, + autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME); + assertEquals(removedAuto, true); + + removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, + "deployment-policy-single-cluster-scaling-test", RestConstants.DEPLOYMENT_POLICIES_NAME); + assertEquals(removedDep, true); + + removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-single-cluster-scaling-test", RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(removedNet, false); + + + boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, + "application-policy-single-cluster-scaling-test", RestConstants.APPLICATION_POLICIES_NAME); + assertEquals(removeAppPolicy, true); + + removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-single-cluster-scaling-test", RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(removedNet, true); + } + + /** + * Assert application activation + * + * @param applicationName + */ + private void assertClusterWithScalingup(String applicationName) { + Application application = ApplicationManager.getApplications().getApplication(applicationName); + assertNotNull(String.format("Application is not found: [application-id] %s", + applicationName), application); + boolean clusterScaleup = false; + String clusterId = null; + long startTime = System.currentTimeMillis(); + while (!clusterScaleup) { + 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++; + } + } + } + + clusterScaleup = activeInstances > clusterDataHolder.getMinInstances(); + if (clusterScaleup) { + activeInstancesAfterScaleup = activeInstances; + break; + } + } + application = ApplicationManager.getApplications().getApplication(applicationName); + if ((System.currentTimeMillis() - startTime) > CLUSTER_SCALE_UP_TIMEOUT) { + break; + } + } + } + assertEquals(true, clusterScaleup, String.format("Cluster did not get scaled up: [cluster-id] %s", clusterId)); + } + + /** + * Assert application activation + * + * @param applicationName + */ + private void assertClusterWithScaleDown(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++; + } + } + } + + if (activeInstances > activeInstancesAfterScaleup) { + activeInstancesAfterScaleup = activeInstances; + } + + clusterScaleDown = activeInstancesAfterScaleup - 1 == activeInstances; + if (clusterScaleDown) { + break; + } + + } + + application = ApplicationManager.getApplications().getApplication(applicationName); + if ((System.currentTimeMillis() - startTime) > CLUSTER_SCALE_DOWN_TIMEOUT) { + break; + } + } + } + assertEquals(clusterScaleDown, true, + String.format("Cluster did not get scaled up: [cluster-id] %s", clusterId)); + } + + /** + * 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(clusterScaleDown, true, + String.format("Cluster did not get scaled up: [cluster-id] %s", clusterId)); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/be922cc6/products/stratos/modules/integration/test-integration/src/test/resources/common/jndi.properties ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/resources/common/jndi.properties b/products/stratos/modules/integration/test-integration/src/test/resources/common/jndi.properties index e69de29..cfe8c7e 100644 --- a/products/stratos/modules/integration/test-integration/src/test/resources/common/jndi.properties +++ b/products/stratos/modules/integration/test-integration/src/test/resources/common/jndi.properties @@ -0,0 +1,22 @@ +# +# 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. +# + +connectionfactoryName=TopicConnectionFactory +java.naming.provider.url=tcp://localhost:ACTIVEMQ_DYNAMIC_PORT +java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory \ No newline at end of file
