.
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/1afe6ae4 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/1afe6ae4 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/1afe6ae4 Branch: refs/heads/master Commit: 1afe6ae41682dd0f3883dac0f3791e70a4d87dac Parents: 4b86447 Author: gayangunarathne <[email protected]> Authored: Mon Nov 2 17:24:00 2015 +0530 Committer: gayangunarathne <[email protected]> Committed: Mon Nov 2 17:24:00 2015 +0530 ---------------------------------------------------------------------- products/stratos/modules/integration/pom.xml | 9 +- .../tests/StratosTestServerManager.java | 155 ++- .../integration/tests/TopologyHandler.java | 88 +- .../application/ApplicationBurstingTest.java | 189 ++-- .../application/ApplicationUpdateTest.java | 312 +++--- .../GroupTerminationBehaviorTest.java | 111 +- .../PartitionOneAfterAnotherClusterTest.java | 56 +- .../PartitionRoundRobinClusterTest.java | 90 +- .../application/SampleApplicationsTest.java | 233 +--- .../application/SingleClusterScalingTest.java | 90 +- .../tests/group/CartridgeGroupTest.java | 226 +--- .../integration/tests/group/CartridgeTest.java | 138 ++- .../tests/policies/ApplicationPolicyTest.java | 179 ++- .../tests/policies/AutoscalingPolicyTest.java | 146 +-- .../tests/policies/DeploymentPolicyTest.java | 199 ++-- .../tests/policies/NetworkPartitionTest.java | 108 +- .../integration/tests/users/UserTest.java | 12 +- ...cation-policy-application-bursting-test.json | 18 + .../app-bursting-single-cartriddge-group.json | 70 ++ ...caling-policy-application-bursting-test.json | 14 + ...scaling-policy-group-startup-order-test.json | 14 - ...esb-php-group-application-bursting-test.json | 19 + .../mock/esb-application-bursting-test.json | 50 + .../mock/esb-group-startup-order-test.json | 50 - .../mock/php-application-bursting-test.json | 51 + .../mock/php-group-startup-order-test.json | 51 - .../mock/tomcat-application-bursting-test.json | 53 + .../mock/tomcat-group-startup-order-test.json | 53 - ...oyment-policy-application-bursting-test.json | 32 + ...k-partition-application-bursting-test-1.json | 15 + ...k-partition-application-bursting-test-2.json | 24 + ...rk-partition-group-startup-order-test-1.json | 15 - ...rk-partition-group-startup-order-test-2.json | 24 - .../RegionOne.json | 17 + .../application-martin.json | 100 ++ .../application-policy-1.json | 17 + .../application-s-g-c1-c2-c3-s.json | 130 +++ .../application.json | 108 ++ .../startup-order-termination-behavior/c1.json | 45 + .../startup-order-termination-behavior/c2.json | 45 + .../startup-order-termination-behavior/c3.json | 45 + .../startup-order-termination-behavior/c4.json | 45 + .../startup-order-termination-behavior/c5.json | 132 +++ .../cartridge-groups-s-g-c1-c2-c3-s.json | 26 + .../cartridge-groups-working.json | 34 + .../cartridge-groups.json | 77 ++ .../cartridge-groups.json.back | 53 + .../deploy.sh | 43 + .../economy-policy.json | 15 + .../static-1.json | 17 + .../wso2carbon 2.log | 992 +++++++++++++++++ .../wso2carbon-working 2.log | 1053 ++++++++++++++++++ .../wso2carbon-working.log | 1053 ++++++++++++++++++ .../wso2carbon.log | 992 +++++++++++++++++ .../src/test/resources/stratos-testing.xml | 94 -- .../src/test/resources/tenant/tenant1.json | 9 + .../src/test/resources/tenant/tenant2.json | 9 + 57 files changed, 6409 insertions(+), 1636 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/1afe6ae4/products/stratos/modules/integration/pom.xml ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/pom.xml b/products/stratos/modules/integration/pom.xml index 7020370..ce37586 100755 --- a/products/stratos/modules/integration/pom.xml +++ b/products/stratos/modules/integration/pom.xml @@ -1,4 +1,3 @@ -<?xml version="1.0" encoding="UTF-8"?> <!-- ~ Licensed to the Apache Software Foundation (ASF) under one ~ or more contributor license agreements. See the NOTICE file @@ -111,13 +110,11 @@ </dependencies> <build> - <resources> - <resource> + <testResources> + <testResource> <directory>src/test/resources/test-conf</directory> <filtering>true</filtering> - </resource> - </resources> - <testResources> + </testResource> <testResource> <directory>src/test/resources/common</directory> <includes> http://git-wip-us.apache.org/repos/asf/stratos/blob/1afe6ae4/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/StratosTestServerManager.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/StratosTestServerManager.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/StratosTestServerManager.java index a7dd781..52293ba 100755 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/StratosTestServerManager.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/StratosTestServerManager.java @@ -26,10 +26,11 @@ import org.apache.commons.logging.LogFactory; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.stratos.common.test.TestLogAppender; -import org.apache.stratos.integration.tests.application.SampleApplicationsTest; import org.apache.stratos.integration.tests.rest.IntegrationMockClient; import org.apache.stratos.integration.tests.rest.RestClient; +import org.apache.stratos.messaging.domain.tenant.Tenant; import org.testng.annotations.AfterSuite; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeSuite; import org.wso2.carbon.integration.framework.TestServerManager; import org.wso2.carbon.integration.framework.utils.FrameworkSettings; @@ -38,39 +39,91 @@ import org.wso2.carbon.integration.framework.utils.TestUtil; import java.io.File; import java.io.IOException; -import java.net.URL; +import java.util.Properties; -import static org.testng.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.testng.Assert.assertEquals; /** * Prepare activemq, Stratos server for tests, enables mock iaas, starts servers and stop them after the tests. */ public class StratosTestServerManager extends TestServerManager { - private static final Log log = LogFactory.getLog(StratosTestServerManager.class); + public static final String PATH_SEP = File.separator; + public static final String BASE_PATH = StratosTestServerManager.class.getResource(PATH_SEP).getPath(); + public static final String CARBON_CONF_PATH = "repository" + PATH_SEP + "conf"; + public static final String STRATOS_DISTRIBUTION_NAME = "distribution.path"; + public final static String PORT_OFFSET = "carbon.port.offset"; + public static final String ACTIVEMQ_BIND_ADDRESS = "activemq.bind.address"; + public static final String STRATOS_ENDPOINT = "stratos.endpoint"; + public static final String ADMIN_USERNAME = "stratos.admin.username"; + public static final String ADMIN_PASSWORD = "stratos.admin.password"; + private static final String TENANT1_USER_NAME = "stratos.tenant1.username"; + private static final String TENANT1_PASSWD = "stratos.tenant1.password"; + private static final String TENANT2_USER_NAME = "stratos.tenant2.username"; + private static final String TENANT2_PASSWD = "stratos.tenant2.password"; + public static final String MOCK_IAAS_XML_FILENAME = "mock-iaas.xml"; + public static final String SCALING_DROOL_FILENAME = "scaling.drl"; + public static final String JNDI_PROPERTIES_FILENAME = "jndi.properties"; + public static final String JMS_OUTPUT_ADAPTER_FILENAME = "JMSOutputAdaptor.xml"; + private static final String LOG4J_PROPERTIES_FILENAME = "log4j.properties"; - private final static String CARBON_ZIP = SampleApplicationsTest.class.getResource("/").getPath() + - "/../../../distribution/target/apache-stratos-4.2.0-SNAPSHOT.zip"; - private final static int PORT_OFFSET = 0; - private static final String ACTIVEMQ_BIND_ADDRESS = "tcp://localhost:61617"; - private static final String MOCK_IAAS_XML_FILE = "mock-iaas.xml"; - private static final String SCALING_DROOL_FILE = "scaling.drl"; - private static final String JNDI_PROPERTIES_FILE = "jndi.properties"; - private static final String JMS_OUTPUT_ADAPTER_FILE = "JMSOutputAdaptor.xml"; - protected RestClient restClient; - private String endpoint = "http://localhost:9763"; - + private static Properties integrationProperties; + protected String distributionName; + protected int portOffset; + protected String adminUsername; + protected String adminPassword; + protected String tenant1UserName; + protected String tenant1Password; + protected String tenant2UserName; + protected String tenant2Password; + protected String stratosEndpoint; + protected String activemqBindAddress; + protected RestClient restClientAdmin; private BrokerService broker = new BrokerService(); private TestLogAppender testLogAppender = new TestLogAppender(); private ServerUtils serverUtils; - private String carbonHome; protected IntegrationMockClient mockIaasApiClient; + protected RestClient restClientTenant1; + protected RestClient restClientTenant2; + protected int tenant1Id; + protected int tenant2Id; public StratosTestServerManager() { - super(CARBON_ZIP, PORT_OFFSET); + super(BASE_PATH + getIntegrationTestProperty(STRATOS_DISTRIBUTION_NAME), + Integer.parseInt(getIntegrationTestProperty(PORT_OFFSET))); + + distributionName = integrationProperties.getProperty(STRATOS_DISTRIBUTION_NAME); + portOffset = Integer.parseInt(integrationProperties.getProperty(PORT_OFFSET)); + adminUsername = integrationProperties.getProperty(ADMIN_USERNAME); + adminPassword = integrationProperties.getProperty(ADMIN_PASSWORD); + tenant1UserName = integrationProperties.getProperty(TENANT1_USER_NAME); + tenant1Password = integrationProperties.getProperty(TENANT1_PASSWD); + tenant2UserName = integrationProperties.getProperty(TENANT2_USER_NAME); + tenant2Password = integrationProperties.getProperty(TENANT2_PASSWD); + stratosEndpoint = integrationProperties.getProperty(STRATOS_ENDPOINT); + activemqBindAddress = integrationProperties.getProperty(ACTIVEMQ_BIND_ADDRESS); serverUtils = new ServerUtils(); - restClient = new RestClient(endpoint, "admin", "admin"); - mockIaasApiClient = new IntegrationMockClient(endpoint + "/mock-iaas/api"); + mockIaasApiClient = new IntegrationMockClient(stratosEndpoint + "/mock-iaas/api"); + restClientAdmin = new RestClient(stratosEndpoint, adminUsername, adminPassword); + restClientTenant1 = new RestClient(stratosEndpoint, tenant1UserName, tenant1Password); + restClientTenant2 = new RestClient(stratosEndpoint, tenant2UserName, tenant2Password); + } + + private static String getIntegrationTestProperty(String key) { + if (integrationProperties == null) { + integrationProperties = new Properties(); + try { + integrationProperties + .load(StratosTestServerManager.class.getResourceAsStream("/integration-test.properties")); + log.info("Stratos integration properties: " + integrationProperties.toString()); + } + catch (IOException e) { + log.error("Error loading integration-test.properties file from classpath. Please make sure that file " + + "exists in classpath.", e); + } + } + return integrationProperties.getProperty(key); } @Override @@ -86,7 +139,7 @@ public class StratosTestServerManager extends TestServerManager { broker.setDataDirectory(StratosTestServerManager.class.getResource("/").getPath() + File.separator + ".." + File.separator + "activemq-data"); broker.setBrokerName("testBroker"); - broker.addConnector(ACTIVEMQ_BIND_ADDRESS); + broker.addConnector(activemqBindAddress); broker.start(); long time2 = System.currentTimeMillis(); log.info(String.format("ActiveMQ started in %d sec", (time2 - time1) / 1000)); @@ -106,13 +159,13 @@ public class StratosTestServerManager extends TestServerManager { if (carbonZip == null) { throw new IllegalArgumentException("carbon zip file is null"); } else { - carbonHome = this.serverUtils.setUpCarbonHome(carbonZip); + String carbonHome = this.serverUtils.setUpCarbonHome(carbonZip); TestUtil.copySecurityVerificationService(carbonHome); this.copyArtifacts(carbonHome); log.info("Stratos server setup completed"); log.info("Starting Stratos server..."); - this.serverUtils.startServerUsingCarbonHome(carbonHome, carbonHome, "stratos", PORT_OFFSET, null); + this.serverUtils.startServerUsingCarbonHome(carbonHome, carbonHome, "stratos", portOffset, null); FrameworkSettings.init(); while (!serverStarted()) { @@ -127,6 +180,7 @@ public class StratosTestServerManager extends TestServerManager { long time4 = System.currentTimeMillis(); log.info(String.format("Stratos server started in %d sec", (time4 - time3) / 1000)); + createTenants(); return carbonHome; } } @@ -135,6 +189,29 @@ public class StratosTestServerManager extends TestServerManager { } } + private void createTenants() { + log.info("Added tenants to the testing suit"); + boolean addedTenant1 = restClientAdmin + .addEntity(RestConstants.TENANT1_RESOURCE, RestConstants.TENANT_API, RestConstants.TENANTS_NAME); + assertEquals(addedTenant1, true); + boolean addedTenant2 = restClientAdmin + .addEntity(RestConstants.TENANT2_RESOURCE, RestConstants.TENANT_API, RestConstants.TENANTS_NAME); + assertEquals(addedTenant2, true); + } + + + @BeforeClass + public void getTenantDetails() { + Tenant tenant1 = (Tenant) restClientAdmin + .getEntity(RestConstants.TENANT_API, RestConstants.TENANT1_GET_RESOURCE, Tenant.class, + RestConstants.TENANTS_NAME); + tenant1Id = tenant1.getTenantId(); + Tenant tenant2 = (Tenant) restClientAdmin + .getEntity(RestConstants.TENANT_API, RestConstants.TENANT2_GET_RESOURCE, Tenant.class, + RestConstants.TENANTS_NAME); + tenant2Id = tenant2.getTenantId(); + } + private boolean mockServiceStarted() { for (String message : testLogAppender.getMessages()) { if (message.contains("Mock IaaS service component activated")) { @@ -160,24 +237,28 @@ public class StratosTestServerManager extends TestServerManager { } protected void copyArtifacts(String carbonHome) throws IOException { - copyConfigFile(carbonHome, MOCK_IAAS_XML_FILE); - copyConfigFile(carbonHome, JNDI_PROPERTIES_FILE); - copyConfigFile(carbonHome, SCALING_DROOL_FILE, "repository/conf/drools"); - copyConfigFile(carbonHome, JMS_OUTPUT_ADAPTER_FILE, "repository/deployment/server/outputeventadaptors"); + String commonResourcesPath = BASE_PATH + PATH_SEP + ".." + PATH_SEP + ".." + PATH_SEP + "src" + PATH_SEP + + "test" + PATH_SEP + "resources" + PATH_SEP + "common"; + copyConfigFile(carbonHome, commonResourcesPath, MOCK_IAAS_XML_FILENAME, CARBON_CONF_PATH); + copyConfigFile(carbonHome, commonResourcesPath, JNDI_PROPERTIES_FILENAME, CARBON_CONF_PATH); + copyConfigFile(carbonHome, commonResourcesPath, LOG4J_PROPERTIES_FILENAME, CARBON_CONF_PATH); + //copyConfigFile(carbonHome, commonResourcesPath, SCALING_DROOL_FILENAME, CARBON_CONF_PATH + PATH_SEP + + // "drools"); + copyConfigFile(carbonHome, commonResourcesPath, JMS_OUTPUT_ADAPTER_FILENAME, + "repository" + PATH_SEP + "deployment" + PATH_SEP + "server" + PATH_SEP + "outputeventadaptors"); } - private void copyConfigFile(String carbonHome, String sourceFilePath) throws IOException { - copyConfigFile(carbonHome, sourceFilePath, "repository/conf"); - } + private void copyConfigFile(String carbonHome, String filePath, String fileName, String destinationFolder) + throws + IOException { - private void copyConfigFile(String carbonHome, String sourceFilePath, String destinationFolder) throws IOException { - log.info("Copying file: " + sourceFilePath); - URL fileURL = getClass().getResource("/" + sourceFilePath); - assertNotNull(fileURL); - File srcFile = new File(fileURL.getFile()); - File destFile = new File(carbonHome + "/" + destinationFolder + "/" + sourceFilePath); + String fileAbsPath = filePath + PATH_SEP + fileName; + log.info("Copying file: " + fileAbsPath); + File srcFile = new File(fileAbsPath); + assertTrue(srcFile.exists()); + File destFile = new File(carbonHome + PATH_SEP + destinationFolder + PATH_SEP + fileName); FileUtils.copyFile(srcFile, destFile); - log.info(sourceFilePath + " file copied"); + log.info("Copying file [source] " + srcFile.getAbsolutePath() + " to [dest] " + destFile.getAbsolutePath()); } private boolean serverStopped() { @@ -198,4 +279,4 @@ public class StratosTestServerManager extends TestServerManager { } return false; } -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/1afe6ae4/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/TopologyHandler.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/TopologyHandler.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/TopologyHandler.java index 9c9764b..a8e516f 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/TopologyHandler.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/TopologyHandler.java @@ -58,9 +58,11 @@ import static junit.framework.Assert.*; public class TopologyHandler { private static final Log log = LogFactory.getLog(TopologyHandler.class); - public static final int APPLICATION_ACTIVATION_TIMEOUT = 360000; - public static final int APPLICATION_UNDEPLOYMENT_TIMEOUT = 120000; - public static final int APPLICATION_TOPOLOGY_TIMEOUT = 90000; + + public static final int APPLICATION_ACTIVATION_TIMEOUT = 400000; + public static final int APPLICATION_UNDEPLOYMENT_TIMEOUT = 60000; + public static final int APPLICATION_TOPOLOGY_TIMEOUT = 60000; + public static final String APPLICATION_STATUS_CREATED = "Created"; public static final String APPLICATION_STATUS_UNDEPLOYING = "Undeploying"; private ApplicationsEventReceiver applicationsEventReceiver; @@ -161,17 +163,18 @@ public class TopologyHandler { /** * Assert application activation * + * @param tenantId * @param applicationName */ - public void assertApplicationStatus(String applicationName, ApplicationStatus status) { + public void assertApplicationStatus(String applicationName, ApplicationStatus status, int tenantId) { long startTime = System.currentTimeMillis(); - Application application = ApplicationManager.getApplications().getApplication(applicationName); + Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationName, tenantId); while (!((application != null) && (application.getStatus() == status))) { try { Thread.sleep(1000); } catch (InterruptedException ignore) { } - application = ApplicationManager.getApplications().getApplication(applicationName); + application = ApplicationManager.getApplications().getApplicationByTenant(applicationName,tenantId); if ((System.currentTimeMillis() - startTime) > APPLICATION_ACTIVATION_TIMEOUT) { break; } @@ -182,13 +185,24 @@ public class TopologyHandler { 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); + } + /** * Assert application activation * * @param applicationName + * @param tenantId */ - public void assertGroupActivation(String applicationName) { - Application application = ApplicationManager.getApplications().getApplication(applicationName); + public void assertGroupActivation(String applicationName, int tenantId) { + Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationName, tenantId); assertNotNull(String.format("Application is not found: [application-id] %s", applicationName), application); @@ -202,23 +216,24 @@ public class TopologyHandler { * Assert application activation * * @param applicationName + * @param tenantId */ - public void assertClusterActivation(String applicationName) { - Application application = ApplicationManager.getApplications().getApplication(applicationName); + public void assertClusterActivation(String applicationName, int tenantId) { + Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationName, tenantId); assertNotNull(String.format("Application is not found: [application-id] %s", applicationName), application); Set<ClusterDataHolder> clusterDataHolderSet = application.getClusterDataRecursively(); for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) { - String serviceName = clusterDataHolder.getServiceType(); + String serviceUuid = clusterDataHolder.getServiceUuid(); String clusterId = clusterDataHolder.getClusterId(); - Service service = TopologyManager.getTopology().getService(serviceName); + Service service = TopologyManager.getTopology().getService(serviceUuid); assertNotNull(String.format("Service is not found: [application-id] %s [service] %s", - applicationName, serviceName), service); + applicationName, serviceUuid), 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); + applicationName, serviceUuid, clusterId), cluster); boolean clusterActive = false; for (ClusterInstance instance : cluster.getInstanceIdToInstanceContextMap().values()) { @@ -245,26 +260,27 @@ public class TopologyHandler { /** * Assert application activation * + * @param tenantId * @param applicationName */ - public void terminateMemberFromCluster(String cartridgeName, String applicationName, - IntegrationMockClient mockIaasApiClient) { - Application application = ApplicationManager.getApplications().getApplication(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); Set<ClusterDataHolder> clusterDataHolderSet = application.getClusterDataRecursively(); for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) { - String serviceName = clusterDataHolder.getServiceType(); - if(cartridgeName.equals(serviceName)) { + String serviceUuid = clusterDataHolder.getServiceUuid(); + if(cartridgeName.equals(serviceUuid)) { String clusterId = clusterDataHolder.getClusterId(); - Service service = TopologyManager.getTopology().getService(serviceName); - assertNotNull(String.format("Service is not found: [application-id] %s [service] %s", - applicationName, serviceName), service); + Service service = TopologyManager.getTopology().getService(serviceUuid); + assertNotNull(String.format("Service is not found: [application-id] %s [service uuid] %s", + applicationName, serviceUuid), 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); + applicationName, serviceUuid, clusterId), cluster); boolean memberTerminated = false; for (ClusterInstance instance : cluster.getInstanceIdToInstanceContextMap().values()) { @@ -290,16 +306,16 @@ public class TopologyHandler { } - public void assertClusterMinMemberCount(String applicationName, int minMembers) { + public void assertClusterMinMemberCount(String applicationName, int minMembers, int tenantId) { long startTime = System.currentTimeMillis(); - Application application = ApplicationManager.getApplications().getApplication(applicationName); + Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationName, tenantId); assertNotNull(String.format("Application is not found: [application-id] %s", applicationName), application); Set<ClusterDataHolder> clusterDataHolderSet = application.getClusterDataRecursively(); for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) { - String serviceName = clusterDataHolder.getServiceType(); + String serviceName = clusterDataHolder.getServiceUuid(); String clusterId = clusterDataHolder.getClusterId(); Service service = TopologyManager.getTopology().getService(serviceName); assertNotNull(String.format("Service is not found: [application-id] %s [service] %s", @@ -359,13 +375,14 @@ public class TopologyHandler { * Assert application activation * * @param applicationName + * @param tenantId */ - public boolean assertApplicationUndeploy(String applicationName) { + public boolean assertApplicationUndeploy(String applicationName, int tenantId) { long startTime = System.currentTimeMillis(); - Application application = ApplicationManager.getApplications().getApplication(applicationName); + Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationName, tenantId); ApplicationContext applicationContext = null; try { - applicationContext = AutoscalerServiceClient.getInstance().getApplication(applicationName); + applicationContext = AutoscalerServiceClient.getInstance().getApplicationByTenant(applicationName,tenantId); } catch (RemoteException e) { log.error("Error while getting the application context for [application] " + applicationName); } @@ -375,9 +392,9 @@ public class TopologyHandler { Thread.sleep(1000); } catch (InterruptedException ignore) { } - application = ApplicationManager.getApplications().getApplication(applicationName); + application = ApplicationManager.getApplications().getApplicationByTenant(applicationName,tenantId); try { - applicationContext = AutoscalerServiceClient.getInstance().getApplication(applicationName); + applicationContext = AutoscalerServiceClient.getInstance().getApplicationByTenant(applicationName,tenantId); } catch (RemoteException e) { log.error("Error while getting the application context for [application] " + applicationName); } @@ -404,11 +421,12 @@ public class TopologyHandler { /** * Assert application activation * + * @param tenantId * @param applicationName */ - public void assertGroupInstanceCount(String applicationName, String groupAlias, int count) { + public void assertGroupInstanceCount(String applicationName, String groupAlias, int count, int tenantId) { long startTime = System.currentTimeMillis(); - Application application = ApplicationManager.getApplications().getApplication(applicationName); + Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationName, tenantId); if (application != null) { Group group = application.getGroupRecursively(groupAlias); while (group.getInstanceContextCount() != count) { @@ -581,8 +599,8 @@ public class TopologyHandler { return appId + "-" + groupId + "-" + instanceId; } - public String getClusterIdFromAlias(String applicationId, String alias) { - Application application = ApplicationManager.getApplications().getApplication(applicationId); + public String getClusterIdFromAlias(String applicationId, String alias,int tenantId) { + Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationId,tenantId); assertNotNull(application); ClusterDataHolder dataHolder = application.getClusterDataHolderRecursivelyByAlias(alias); http://git-wip-us.apache.org/repos/asf/stratos/blob/1afe6ae4/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTest.java index 70f79f2..f210b12 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTest.java @@ -29,7 +29,8 @@ import org.apache.stratos.integration.tests.TopologyHandler; import org.apache.stratos.messaging.domain.application.ApplicationStatus; import org.testng.annotations.Test; -import static junit.framework.Assert.*; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; /** * This will handle the application bursting test cases @@ -42,67 +43,74 @@ public class ApplicationBurstingTest extends StratosTestServerManager { @Test public void testApplicationBusting() { try { - log.info("-------------------------------Started application Bursting test case-------------------------------"); - TopologyHandler topologyHandler = TopologyHandler.getInstance(); + log.info("----------------------------Started application Bursting test case----------------------------"); + String autoscalingPolicyId = "autoscaling-policy-application-bursting-test"; - boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH - + "/" + autoscalingPolicyId + ".json", - RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); - assertTrue(addedScalingPolicy); + boolean addedScalingPolicy = + restClientTenant1.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 + "/" + "esb-application-bursting-test.json", + boolean addedC1 = restClientTenant1.addEntity( + RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "esb-application-bursting-test.json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertTrue(addedC1); + assertEquals(addedC1, true); - boolean addedC2 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "php-application-bursting-test.json", + boolean addedC2 = restClientTenant1.addEntity( + RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "php-application-bursting-test.json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertTrue(addedC2); + assertEquals(addedC2, true); - boolean addedC3 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "tomcat-application-bursting-test.json", + boolean addedC3 = restClientTenant1.addEntity( + RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "tomcat-application-bursting-test.json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertTrue(addedC3); + assertEquals(addedC3, true); - boolean addedG1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH + + boolean addedG1 = restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH + "/" + "esb-php-group-application-bursting-test.json", RestConstants.CARTRIDGE_GROUPS, RestConstants.CARTRIDGE_GROUPS_NAME); - assertTrue(addedG1); + assertEquals(addedG1, true); - CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClient. + CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClientTenant1. getEntity(RestConstants.CARTRIDGE_GROUPS, "esb-php-group-application-bursting-test", CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME); assertEquals(beanG1.getName(), "esb-php-group-application-bursting-test"); - boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + boolean addedN1 = restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + "network-partition-application-bursting-test-1.json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(addedN1); + assertEquals(addedN1, true); - boolean addedN2 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + boolean addedN2 = restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + "network-partition-application-bursting-test-2.json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(addedN2); + assertEquals(addedN2, true); - boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + - "deployment-policy-application-bursting-test.json", - RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertTrue(addedDep); + boolean addedDep = + restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + + "deployment-policy-application-bursting-test.json", + RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertEquals(addedDep, true); - boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" + + boolean added = restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" + "app-bursting-single-cartriddge-group.json", RestConstants.APPLICATIONS, RestConstants.APPLICATIONS_NAME); - assertTrue(added); + assertEquals(added, true); - ApplicationBean bean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, + ApplicationBean bean = (ApplicationBean) restClientTenant1.getEntity(RestConstants.APPLICATIONS, "application-bursting-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); assertEquals(bean.getApplicationId(), "application-bursting-test"); - boolean addAppPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" + - "application-policy-application-bursting-test.json", RestConstants.APPLICATION_POLICIES, - RestConstants.APPLICATION_POLICIES_NAME); - assertTrue(addAppPolicy); + boolean addAppPolicy = + restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" + + "application-policy-application-bursting-test.json", + RestConstants.APPLICATION_POLICIES, + RestConstants.APPLICATION_POLICIES_NAME); + assertEquals(addAppPolicy, true); - ApplicationPolicyBean policyBean = (ApplicationPolicyBean) restClient.getEntity( + ApplicationPolicyBean policyBean = (ApplicationPolicyBean) restClientTenant1.getEntity( RestConstants.APPLICATION_POLICIES, "application-policy-application-bursting-test", ApplicationPolicyBean.class, RestConstants.APPLICATION_POLICIES_NAME); @@ -110,118 +118,125 @@ public class ApplicationBurstingTest extends StratosTestServerManager { //deploy the application String resourcePath = RestConstants.APPLICATIONS + "/" + "application-bursting-test" + RestConstants.APPLICATIONS_DEPLOY + "/" + "application-policy-application-bursting-test"; - boolean deployed = restClient.deployEntity(resourcePath, + boolean deployed = restClientTenant1.deployEntity(resourcePath, RestConstants.APPLICATIONS_NAME); - assertTrue(deployed); + assertEquals(deployed, true); //Application active handling - topologyHandler.assertApplicationStatus(bean.getApplicationId(), - ApplicationStatus.Active); + TopologyHandler.getInstance().assertApplicationStatus(bean.getApplicationId(), + ApplicationStatus.Active, tenant1Id); //Group active handling - topologyHandler.assertGroupActivation(bean.getApplicationId()); + TopologyHandler.getInstance().assertGroupActivation(bean.getApplicationId(), tenant1Id); //Cluster active handling - topologyHandler.assertClusterActivation(bean.getApplicationId()); + TopologyHandler.getInstance().assertClusterActivation(bean.getApplicationId(), tenant1Id); - boolean removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "esb-php-group-application-bursting-test", - RestConstants.CARTRIDGE_GROUPS_NAME); - assertFalse(removedGroup); + boolean removedGroup = restClientTenant1 + .removeEntity(RestConstants.CARTRIDGE_GROUPS, "esb-php-group-application-bursting-test", + RestConstants.CARTRIDGE_GROUPS_NAME); + assertEquals(removedGroup, false); - boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, + boolean removedAuto = restClientTenant1.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME); - assertFalse(removedAuto); + assertEquals(removedAuto, false); - boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + boolean removedNet = restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-bursting-test-1", RestConstants.NETWORK_PARTITIONS_NAME); //Trying to remove the used network partition - assertFalse(removedNet); + assertEquals(removedNet, false); - boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, + boolean removedDep = restClientTenant1.removeEntity(RestConstants.DEPLOYMENT_POLICIES, "deployment-policy-application-bursting-test", RestConstants.DEPLOYMENT_POLICIES_NAME); - assertFalse(removedDep); + assertEquals(removedDep, false); //Un-deploying the application String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + "application-bursting-test" + RestConstants.APPLICATIONS_UNDEPLOY; - boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy, + boolean unDeployed = restClientTenant1.undeployEntity(resourcePathUndeploy, RestConstants.APPLICATIONS_NAME); - assertTrue(unDeployed); + assertEquals(unDeployed, true); - boolean undeploy = topologyHandler.assertApplicationUndeploy("application-bursting-test"); + boolean undeploy = TopologyHandler.getInstance().assertApplicationUndeploy("application-bursting-test", + tenant1Id); if (!undeploy) { //Need to forcefully undeploy the application log.info("Force undeployment is going to start for the [application] " + "application-bursting-test"); - restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + "application-bursting-test" + + restClientTenant1.undeployEntity(RestConstants.APPLICATIONS + "/" + "application-bursting-test" + RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS); - boolean forceUndeployed = topologyHandler.assertApplicationUndeploy("application-bursting-test"); + boolean forceUndeployed = TopologyHandler.getInstance().assertApplicationUndeploy( + "application-bursting-test", tenant1Id); assertEquals(String.format("Forceful undeployment failed for the application %s", - "application-bursting-test"), forceUndeployed); + "application-bursting-test"), forceUndeployed, true); } - boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, "application-bursting-test", + boolean removed = restClientTenant1.removeEntity(RestConstants.APPLICATIONS, "application-bursting-test", RestConstants.APPLICATIONS_NAME); - assertTrue(removed); + assertEquals(removed, true); - ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, + ApplicationBean beanRemoved = (ApplicationBean) restClientTenant1.getEntity(RestConstants.APPLICATIONS, "application-bursting-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); - assertNull(beanRemoved); + assertEquals(beanRemoved, null); - removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "esb-php-group-application-bursting-test", - RestConstants.CARTRIDGE_GROUPS_NAME); - assertTrue(removedGroup); + removedGroup = restClientTenant1 + .removeEntity(RestConstants.CARTRIDGE_GROUPS, "esb-php-group-application-bursting-test", + RestConstants.CARTRIDGE_GROUPS_NAME); + assertEquals(removedGroup, true); - boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "esb-application-bursting-test", - RestConstants.CARTRIDGES_NAME); - assertTrue(removedC1); + boolean removedC1 = + restClientTenant1.removeEntity(RestConstants.CARTRIDGES, "esb-application-bursting-test", + RestConstants.CARTRIDGES_NAME); + assertEquals(removedC1, true); - boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "php-application-bursting-test", - RestConstants.CARTRIDGES_NAME); - assertTrue(removedC2); + boolean removedC2 = + restClientTenant1.removeEntity(RestConstants.CARTRIDGES, "php-application-bursting-test", + RestConstants.CARTRIDGES_NAME); + assertEquals(removedC2, true); - boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "tomcat-application-bursting-test", - RestConstants.CARTRIDGES_NAME); - assertTrue(removedC3); + boolean removedC3 = + restClientTenant1.removeEntity(RestConstants.CARTRIDGES, "tomcat-application-bursting-test", + RestConstants.CARTRIDGES_NAME); + assertEquals(removedC3, true); - removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, + removedAuto = restClientTenant1.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME); - assertTrue(removedAuto); + assertEquals(removedAuto, true); - removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, + removedDep = restClientTenant1.removeEntity(RestConstants.DEPLOYMENT_POLICIES, "deployment-policy-application-bursting-test", RestConstants.DEPLOYMENT_POLICIES_NAME); - assertTrue(removedDep); + assertEquals(removedDep, true); - removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + removedNet = restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-bursting-test-1", RestConstants.NETWORK_PARTITIONS_NAME); - assertFalse(removedNet); + assertEquals(removedNet, false); - boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + boolean removedN2 = restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-bursting-test-2", RestConstants.NETWORK_PARTITIONS_NAME); - assertFalse(removedN2); + assertEquals(removedN2, false); - boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, + boolean removeAppPolicy = restClientTenant1.removeEntity(RestConstants.APPLICATION_POLICIES, "application-policy-application-bursting-test", RestConstants.APPLICATION_POLICIES_NAME); - assertTrue(removeAppPolicy); + assertEquals(removeAppPolicy, true); - removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + removedNet = restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-bursting-test-1", RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(removedNet); + assertEquals(removedNet, true); - removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + removedN2 = restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-bursting-test-2", RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(removedN2); + assertEquals(removedN2, true); - log.info("-------------------------------Ended application bursting test case-------------------------------"); + log.info("----------------------------Ended application bursting test case----------------------------"); - } catch (Exception e) { + } + catch (Exception e) { log.error("An error occurred while handling application bursting", e); assertTrue("An error occurred while handling application bursting", false); } } -} - +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/1afe6ae4/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTest.java index f3f1b91..9ba62f6 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTest.java @@ -27,6 +27,7 @@ import org.apache.stratos.common.beans.policy.deployment.ApplicationPolicyBean; import org.apache.stratos.integration.tests.RestConstants; import org.apache.stratos.integration.tests.StratosTestServerManager; import org.apache.stratos.integration.tests.TopologyHandler; +import org.apache.stratos.integration.tests.rest.RestClient; import org.apache.stratos.messaging.domain.application.ApplicationStatus; import org.testng.annotations.Test; @@ -43,201 +44,218 @@ public class ApplicationUpdateTest extends StratosTestServerManager { @Test public void testDeployApplication() { try { - log.info("-------------------------Started application runtime update test case-------------------------"); - TopologyHandler topologyHandler = TopologyHandler.getInstance(); - String autoscalingPolicyId = "autoscaling-policy-application-update-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 + "/" + "c1-application-update-test.json", - RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertEquals(addedC1, true); - - boolean addedC2 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c2-application-update-test.json", - RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertEquals(addedC2, true); - - boolean addedC3 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c3-application-update-test.json", - RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertEquals(addedC3, true); - - boolean addedG1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH + - "/" + "cartrdige-nested-application-update-test.json", RestConstants.CARTRIDGE_GROUPS, - RestConstants.CARTRIDGE_GROUPS_NAME); - assertEquals(addedG1, true); - - CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClient. - getEntity(RestConstants.CARTRIDGE_GROUPS, "G1-application-update-test", - CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME); - assertEquals(beanG1.getName(), "G1-application-update-test"); - - boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-application-update-test-1.json", - RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(addedN1, true); - - boolean addedN2 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-application-update-test-2.json", - RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(addedN2, true); - - boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + - "deployment-policy-application-update-test.json", - RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertEquals(addedDep, true); - - boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" + - "g-sc-G123-1-application-update-test.json", RestConstants.APPLICATIONS, - RestConstants.APPLICATIONS_NAME); - assertEquals(added, true); - - ApplicationBean bean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, - "g-sc-G123-1-application-update-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); - assertEquals(bean.getApplicationId(), "g-sc-G123-1-application-update-test"); - - boolean addAppPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" + - "application-policy-application-update-test.json", RestConstants.APPLICATION_POLICIES, - RestConstants.APPLICATION_POLICIES_NAME); - assertEquals(addAppPolicy, true); - - ApplicationPolicyBean policyBean = (ApplicationPolicyBean) restClient.getEntity( - RestConstants.APPLICATION_POLICIES, - "application-policy-application-update-test", ApplicationPolicyBean.class, - RestConstants.APPLICATION_POLICIES_NAME); - - //deploy the application - String resourcePath = RestConstants.APPLICATIONS + "/" + "g-sc-G123-1-application-update-test" + - RestConstants.APPLICATIONS_DEPLOY + "/" + "application-policy-application-update-test"; - boolean deployed = restClient.deployEntity(resourcePath, - RestConstants.APPLICATIONS_NAME); - assertEquals(deployed, true); - //Application active handling - topologyHandler.assertApplicationStatus(bean.getApplicationId(), - ApplicationStatus.Active); + String autoscalingPolicyId = "autoscaling-policy-application-update-test"; + String applicationId="g-sc-G123-1-application-update-test"; - //Group active handling - topologyHandler.assertGroupActivation(bean.getApplicationId()); + testApplicationRuntimeForTenant(restClientTenant1,tenant1Id,autoscalingPolicyId) ; - //Cluster active handling - topologyHandler.assertClusterActivation(bean.getApplicationId()); + TopologyHandler.getInstance().assertApplicationForNonAvailability(applicationId,tenant2Id); //Updating application - boolean updated = restClient.updateEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" + + boolean updated = restClientTenant1.updateEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" + "g-sc-G123-1-application-update-test-v1.json", RestConstants.APPLICATIONS, RestConstants.APPLICATIONS_NAME); assertEquals(updated, true); - topologyHandler.assertGroupInstanceCount(bean.getApplicationId(), "group3-application-update-test", 2); + TopologyHandler.getInstance().assertGroupInstanceCount(applicationId, "group3-application-update-test", 1, tenant1Id); - topologyHandler.assertClusterMinMemberCount(bean.getApplicationId(), 2); + TopologyHandler.getInstance().assertClusterMinMemberCount(applicationId, 1, tenant1Id); - ApplicationBean updatedBean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, + ApplicationBean updatedBean = (ApplicationBean) restClientTenant1.getEntity(RestConstants.APPLICATIONS, "g-sc-G123-1-application-update-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); assertEquals(updatedBean.getApplicationId(), "g-sc-G123-1-application-update-test"); - boolean removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1-application-update-test", + TopologyHandler.getInstance().assertApplicationForNonAvailability(applicationId,tenant2Id); + + boolean removedGroup = restClientTenant1.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1-application-update-test", RestConstants.CARTRIDGE_GROUPS_NAME); assertEquals(removedGroup, false); - boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, + boolean removedAuto = restClientTenant1.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME); assertEquals(removedAuto, false); - boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + boolean removedNet = restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-update-test-1", RestConstants.NETWORK_PARTITIONS_NAME); //Trying to remove the used network partition assertEquals(removedNet, false); - boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, + boolean removedDep = restClientTenant1.removeEntity(RestConstants.DEPLOYMENT_POLICIES, "deployment-policy-application-update-test", RestConstants.DEPLOYMENT_POLICIES_NAME); assertEquals(removedDep, false); - //Un-deploying the application - String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + "g-sc-G123-1-application-update-test" + - RestConstants.APPLICATIONS_UNDEPLOY; + testApplicationRuntimeForTenant(restClientTenant2,tenant2Id,autoscalingPolicyId); - boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy, - RestConstants.APPLICATIONS_NAME); - assertEquals(unDeployed, true); + testApplicationUndeplymentForTenant(restClientTenant1,tenant1Id,autoscalingPolicyId); - boolean undeploy = topologyHandler.assertApplicationUndeploy("g-sc-G123-1-application-update-test"); - if (!undeploy) { - //Need to forcefully undeploy the application - log.info("Force undeployment is going to start for the [application] " + "g-sc-G123-1-application-update-test"); + TopologyHandler.getInstance().assertApplicationForNonAvailability(applicationId,tenant1Id); - restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + "g-sc-G123-1-application-update-test" + - RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS); + testApplicationUndeplymentForTenant(restClientTenant2,tenant2Id,autoscalingPolicyId); - boolean forceUndeployed = topologyHandler.assertApplicationUndeploy("g-sc-G123-1-application-update-test"); - assertEquals(String.format("Forceful undeployment failed for the application %s", - "g-sc-G123-1-application-update-test"), forceUndeployed, true); + log.info("-------------------------Ended application runtime update test case-------------------------"); - } + } catch (Exception e) { + log.error("An error occurred while handling application deployment/undeployment and update", e); + assertTrue("An error occurred while handling application deployment/undeployment and update", false); + } + } - boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, "g-sc-G123-1-application-update-test", - RestConstants.APPLICATIONS_NAME); - assertEquals(removed, true); + private void testApplicationRuntimeForTenant(RestClient restClientTenant,int tenantId, String autoscalingPolicyId ){ + + boolean addedScalingPolicy = restClientTenant.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + + "/" + autoscalingPolicyId + ".json", + RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); + assertEquals(addedScalingPolicy, true); + + boolean addedC1 = restClientTenant.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c1-application-update-test.json", + RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); + assertEquals(addedC1, true); + + boolean addedC2 = restClientTenant.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c2-application-update-test.json", + RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); + assertEquals(addedC2, true); + + boolean addedC3 = restClientTenant.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c3-application-update-test.json", + RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); + assertEquals(addedC3, true); + + boolean addedG1 = restClientTenant.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH + + "/" + "cartrdige-nested-application-update-test.json", RestConstants.CARTRIDGE_GROUPS, + RestConstants.CARTRIDGE_GROUPS_NAME); + assertEquals(addedG1, true); + + CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClientTenant. + getEntity(RestConstants.CARTRIDGE_GROUPS, "G1-application-update-test", + CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME); + assertEquals(beanG1.getName(), "G1-application-update-test"); + + boolean addedN1 = restClientTenant.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + "network-partition-application-update-test-1.json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(addedN1, true); + + boolean addedN2 = restClientTenant.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + "network-partition-application-update-test-2.json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(addedN2, true); + + boolean addedDep = restClientTenant.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + + "deployment-policy-application-update-test.json", + RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertEquals(addedDep, true); + + boolean added = restClientTenant.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" + + "g-sc-G123-1-application-update-test.json", RestConstants.APPLICATIONS, + RestConstants.APPLICATIONS_NAME); + assertEquals(added, true); + + ApplicationBean bean = (ApplicationBean) restClientTenant.getEntity(RestConstants.APPLICATIONS, + "g-sc-G123-1-application-update-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); + assertEquals(bean.getApplicationId(), "g-sc-G123-1-application-update-test"); + + boolean addAppPolicy = restClientTenant.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" + + "application-policy-application-update-test.json", RestConstants.APPLICATION_POLICIES, + RestConstants.APPLICATION_POLICIES_NAME); + assertEquals(addAppPolicy, true); + + ApplicationPolicyBean policyBean = (ApplicationPolicyBean) restClientTenant.getEntity( + RestConstants.APPLICATION_POLICIES, + "application-policy-application-update-test", ApplicationPolicyBean.class, + RestConstants.APPLICATION_POLICIES_NAME); + + //deploy the application + String resourcePath = RestConstants.APPLICATIONS + "/" + "g-sc-G123-1-application-update-test" + + RestConstants.APPLICATIONS_DEPLOY + "/" + "application-policy-application-update-test"; + boolean deployed = restClientTenant.deployEntity(resourcePath, + RestConstants.APPLICATIONS_NAME); + assertEquals(deployed, true); + + //Application active handling + TopologyHandler.getInstance().assertApplicationStatus(bean.getApplicationId(), + ApplicationStatus.Active, tenantId); + + //Group active handling + TopologyHandler.getInstance().assertGroupActivation(bean.getApplicationId(), tenantId); + + //Cluster active handling + TopologyHandler.getInstance().assertClusterActivation(bean.getApplicationId(), tenantId); + } - ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, - "g-sc-G123-1-application-update-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); - assertEquals(beanRemoved, null); + private void testApplicationUndeplymentForTenant(RestClient restClientTenant,int tenantId,String autoscalingPolicyId){ - removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1-application-update-test", - RestConstants.CARTRIDGE_GROUPS_NAME); - assertEquals(removedGroup, true); + String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + "g-sc-G123-1-application-update-test" + + RestConstants.APPLICATIONS_UNDEPLOY; - boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c1-application-update-test", - RestConstants.CARTRIDGES_NAME); - assertEquals(removedC1, true); + boolean unDeployed = restClientTenant.undeployEntity(resourcePathUndeploy, + RestConstants.APPLICATIONS_NAME); + assertEquals(unDeployed, true); - boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c2-application-update-test", - RestConstants.CARTRIDGES_NAME); - assertEquals(removedC2, true); + boolean undeploy = TopologyHandler.getInstance().assertApplicationUndeploy("g-sc-G123-1-application-update-test", tenantId); + if (!undeploy) { + //Need to forcefully undeploy the application + log.info("Force undeployment is going to start for the [application] " + "g-sc-G123-1-application-update-test"); - boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c3-application-update-test", - RestConstants.CARTRIDGES_NAME); - assertEquals(removedC3, true); + restClientTenant.undeployEntity(RestConstants.APPLICATIONS + "/" + "g-sc-G123-1-application-update-test" + + RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS); - removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, - autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME); - assertEquals(removedAuto, true); + boolean forceUndeployed = TopologyHandler.getInstance().assertApplicationUndeploy("g-sc-G123-1-application-update-test", tenantId); + assertEquals(String.format("Forceful undeployment failed for the application %s", + "g-sc-G123-1-application-update-test"), forceUndeployed, true); - removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, - "deployment-policy-application-update-test", RestConstants.DEPLOYMENT_POLICIES_NAME); - assertEquals(removedDep, true); + } - removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-application-update-test-1", RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(removedNet, false); + boolean removed = restClientTenant.removeEntity(RestConstants.APPLICATIONS, "g-sc-G123-1-application-update-test", + RestConstants.APPLICATIONS_NAME); + assertEquals(removed, true); - boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-application-update-test-2", RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(removedN2, false); + ApplicationBean beanRemoved = (ApplicationBean) restClientTenant.getEntity(RestConstants.APPLICATIONS, + "g-sc-G123-1-application-update-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); + assertEquals(beanRemoved, null); - boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, - "application-policy-application-update-test", RestConstants.APPLICATION_POLICIES_NAME); - assertEquals(removeAppPolicy, true); + boolean removedGroup = restClientTenant.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1-application-update-test", + RestConstants.CARTRIDGE_GROUPS_NAME); + assertEquals(removedGroup, true); - removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-application-update-test-1", RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(removedNet, true); + boolean removedC1 = restClientTenant.removeEntity(RestConstants.CARTRIDGES, "c1-application-update-test", + RestConstants.CARTRIDGES_NAME); + assertEquals(removedC1, true); - removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-application-update-test-2", RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(removedN2, true); + boolean removedC2 = restClientTenant.removeEntity(RestConstants.CARTRIDGES, "c2-application-update-test", + RestConstants.CARTRIDGES_NAME); + assertEquals(removedC2, true); - log.info("-------------------------Ended application runtime update test case-------------------------"); + boolean removedC3 = restClientTenant.removeEntity(RestConstants.CARTRIDGES, "c3-application-update-test", + RestConstants.CARTRIDGES_NAME); + assertEquals(removedC3, true); - } catch (Exception e) { - log.error("An error occurred while handling application deployment/undeployment and update", e); - assertTrue("An error occurred while handling application deployment/undeployment and update", false); - } - } + boolean removedAuto = restClientTenant.removeEntity(RestConstants.AUTOSCALING_POLICIES, + autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME); + assertEquals(removedAuto, true); + + boolean removedDep = restClientTenant.removeEntity(RestConstants.DEPLOYMENT_POLICIES, + "deployment-policy-application-update-test", RestConstants.DEPLOYMENT_POLICIES_NAME); + assertEquals(removedDep, true); + boolean removedNet = restClientTenant.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-application-update-test-1", RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(removedNet, false); + boolean removedN2 = restClientTenant.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-application-update-test-2", RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(removedN2, false); + + boolean removeAppPolicy = restClientTenant.removeEntity(RestConstants.APPLICATION_POLICIES, + "application-policy-application-update-test", RestConstants.APPLICATION_POLICIES_NAME); + assertEquals(removeAppPolicy, true); + + removedNet = restClientTenant.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-application-update-test-1", RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(removedNet, true); + + removedN2 = restClientTenant.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-application-update-test-2", RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(removedN2, true); + } }
