Uplifting automation engine to v4.4.3, dynamically pick ports for integration tests
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/c0664270 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/c0664270 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/c0664270 Branch: refs/heads/master Commit: c066427087dd884e618d76c41935f308a6708555 Parents: 83e94cf Author: Akila Perera <[email protected]> Authored: Fri Sep 11 03:19:40 2015 +0530 Committer: Akila Perera <[email protected]> Committed: Fri Sep 11 03:19:40 2015 +0530 ---------------------------------------------------------------------- pom.xml | 64 ++ products/stratos/modules/integration/pom.xml | 170 +-- .../integration/tests/RestConstants.java | 63 -- .../tests/StratosTestServerManager.java | 282 ----- .../integration/tests/TopologyHandler.java | 666 ----------- .../application/ApplicationBurstingTest.java | 242 ---- .../application/ApplicationUpdateTest.java | 261 ----- .../application/GroupStartupOrderTest.java | 260 ----- .../GroupTerminationBehaviorTest.java | 402 ------- .../PartitionOneAfterAnotherClusterTest.java | 298 ----- .../PartitionRoundRobinClusterTest.java | 311 ------ .../application/SampleApplicationsTest.java | 252 ----- .../application/SingleClusterScalingTest.java | 359 ------ .../tests/group/CartridgeGroupTest.java | 150 --- .../integration/tests/group/CartridgeTest.java | 191 ---- .../tests/policies/ApplicationPolicyTest.java | 190 ---- .../tests/policies/AutoscalingPolicyTest.java | 138 --- .../tests/policies/DeploymentPolicyTest.java | 230 ---- .../tests/policies/NetworkPartitionTest.java | 124 --- .../integration/tests/rest/ErrorResponse.java | 56 - .../integration/tests/rest/HttpResponse.java | 59 - .../tests/rest/HttpResponseHandler.java | 68 -- .../tests/rest/IntegrationMockClient.java | 102 -- .../integration/tests/rest/RestClient.java | 403 ------- .../tests/rest/WebClientWrapper.java | 62 -- .../integration/tests/users/TenantTest.java | 44 - .../integration/tests/users/UserTest.java | 115 -- ...cation-policy-application-bursting-test.json | 18 - .../app-bursting-single-cartriddge-group.json | 70 -- ...caling-policy-application-bursting-test.json | 14 - ...esb-php-group-application-bursting-test.json | 19 - .../mock/esb-application-bursting-test.json | 50 - .../mock/php-application-bursting-test.json | 51 - .../mock/tomcat-application-bursting-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 - ...cation-policy-application-policy-test-1.json | 18 - ...cation-policy-application-policy-test-2.json | 18 - ...lication-policy-application-policy-test.json | 18 - ...ork-partition-application-policy-test-1.json | 24 - ...ork-partition-application-policy-test-2.json | 15 - ...lication-policy-application-update-test.json | 18 - .../g-sc-G123-1-application-update-test-v1.json | 86 -- .../g-sc-G123-1-application-update-test.json | 86 -- ...oscaling-policy-application-update-test.json | 14 - ...rdige-nested-application-update-test-v1.json | 50 - ...artrdige-nested-application-update-test.json | 50 - .../mock/c1-application-update-test.json | 45 - .../mock/c2-application-update-test.json | 45 - .../mock/c3-application-update-test.json | 45 - ...yment-policy-application-update-test-v1.json | 36 - ...ployment-policy-application-update-test.json | 32 - ...-partition-application-update-test-1-v1.json | 28 - ...ork-partition-application-update-test-1.json | 15 - ...ork-partition-application-update-test-2.json | 24 - ...caling-policy-autoscaling-policy-test-1.json | 14 - ...caling-policy-autoscaling-policy-test-2.json | 14 - ...aling-policy-autoscaling-policy-test-v1.json | 14 - ...oscaling-policy-autoscaling-policy-test.json | 14 - .../g4-g5-g6-cartridge-group-test-v1.json | 50 - .../g4-g5-g6-cartridge-group-test.json | 50 - .../group-1-cartridge-group-test.json | 50 - .../group-2-cartridge-group-test.json | 50 - .../mock/c4-cartridge-group-test.json | 45 - .../mock/c5-cartridge-group-test.json | 124 --- .../mock/c6-cartridge-group-test.json | 45 - .../cartridges/mock/c0-cartridge-test-v1.json | 124 --- .../cartridges/mock/c0-cartridge-test.json | 124 --- .../cartridges/mock/c1-cartridge-test.json | 124 --- .../cartridges/mock/c2-cartridge-test.json | 124 --- .../test/resources/common/JMSOutputAdaptor.xml | 30 - .../src/test/resources/common/jndi.properties | 22 - .../src/test/resources/common/log4j.properties | 206 ---- .../src/test/resources/common/mock-iaas.xml | 123 -- .../src/test/resources/common/scaling.drl | 311 ------ ...loyment-policy-deployment-policy-test-1.json | 32 - ...loyment-policy-deployment-policy-test-2.json | 32 - ...oyment-policy-deployment-policy-test-v1.json | 36 - ...eployment-policy-deployment-policy-test.json | 32 - ...k-partition-deployment-policy-test-1-v1.json | 28 - ...work-partition-deployment-policy-test-1.json | 15 - ...work-partition-deployment-policy-test-2.json | 24 - ...cation-policy-application-bursting-test.json | 18 - ...ication-policy-group-startup-order-test.json | 13 - .../app-bursting-single-cartriddge-group.json | 70 -- .../applications/group-startup-order-test.json | 206 ---- ...caling-policy-application-bursting-test.json | 14 - ...scaling-policy-group-startup-order-test.json | 14 - ...esb-php-group-application-bursting-test.json | 19 - .../group6-group-startup-order-test.json | 44 - .../group8-group-startup-order-test.json | 18 - .../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 - .../stratos-lb-group-startup-order-test.json | 44 - .../mock/tomcat-application-bursting-test.json | 53 - .../mock/tomcat-group-startup-order-test.json | 53 - .../mock/tomcat1-group-startup-order-test.json | 45 - .../mock/tomcat2-group-startup-order-test.json | 49 - .../mock/tomcat3-group-startup-order-test.json | 31 - ...oyment-policy-application-bursting-test.json | 32 - ...loyment-policy-group-startup-order-test.json | 18 - ...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 ----------------- ...-policy-group-termination-behavior-test.json | 17 - .../group-termination-behavior-test.json | 101 -- ...-policy-group-termination-behavior-test.json | 14 - ...-groups-group-termination-behavior-test.json | 58 - .../c1-group-termination-behavior-test.json | 45 - .../c2-group-termination-behavior-test.json | 45 - .../c3-group-termination-behavior-test.json | 45 - .../c4-group-termination-behavior-test.json | 45 - ...-policy-group-termination-behavior-test.json | 18 - ...ition-group-termination-behavior-test-1.json | 15 - .../src/test/resources/instrumentation.txt | 1 - .../src/test/resources/keys/wso2carbon.jks | Bin 33260 -> 0 bytes ...work-partition-network-partition-test-1.json | 15 - ...work-partition-network-partition-test-2.json | 15 - ...ork-partition-network-partition-test-v1.json | 28 - ...etwork-partition-network-partition-test.json | 15 - ...ation-policy-partition-round-robin-test.json | 13 - .../partition-round-robin-test.json | 28 - ...aling-policy-partition-round-robin-test.json | 14 - .../mock/c7-partition-round-robin-test.json | 45 - ...yment-policy-partition-round-robin-test.json | 22 - ...rk-partition-partition-round-robin-test.json | 24 - ...ication-policy-sample-applications-test.json | 18 - ...g-sc-G123-1-sample-applications-test-v1.json | 86 -- .../g-sc-G123-1-sample-applications-test.json | 86 -- .../sample-applications-test-1.json | 86 -- .../sample-applications-test-2.json | 86 -- ...scaling-policy-sample-applications-test.json | 14 - ...dige-nested-sample-applications-test-v1.json | 50 - ...rtrdige-nested-sample-applications-test.json | 50 - .../mock/c1-sample-applications-test.json | 45 - .../mock/c2-sample-applications-test.json | 45 - .../mock/c3-sample-applications-test.json | 45 - ...ment-policy-sample-applications-test-v1.json | 36 - ...loyment-policy-sample-applications-test.json | 32 - ...partition-sample-applications-test-1-v1.json | 28 - ...rk-partition-sample-applications-test-1.json | 15 - ...rk-partition-sample-applications-test-2.json | 24 - ...tion-policy-single-cluster-scaling-test.json | 13 - .../single-cluster-scaling-test.json | 28 - ...ling-policy-single-cluster-scaling-test.json | 14 - .../mock/c7-single-cluster-scaling-test.json | 45 - ...ment-policy-single-cluster-scaling-test.json | 22 - ...k-partition-single-cluster-scaling-test.json | 24 - .../src/test/resources/stratos-testing.xml | 82 -- .../src/test/resources/tenant/tenant1.json | 9 - .../src/test/resources/tenant/tenant2.json | 9 - .../test-conf/integration-test.properties | 30 - .../src/test/resources/user-test/tenant-1.json | 9 - .../src/test/resources/user-test/user-1-v1.json | 8 - .../src/test/resources/user-test/user-1.json | 8 - .../modules/integration/test-common/pom.xml | 126 +++ .../integration/common/RestConstants.java | 63 ++ .../common/StratosTestServerManager.java | 619 ++++++++++ .../integration/common/TopologyHandler.java | 689 ++++++++++++ .../apache/stratos/integration/common/Util.java | 84 ++ .../extensions/StratosServerExtension.java | 196 ++++ .../integration/common/rest/ErrorResponse.java | 56 + .../integration/common/rest/HttpResponse.java | 59 + .../common/rest/HttpResponseHandler.java | 68 ++ .../common/rest/IntegrationMockClient.java | 102 ++ .../integration/common/rest/RestClient.java | 403 +++++++ .../common/rest/WebClientWrapper.java | 62 ++ .../integration/test-integration/pom.xml | 226 ++++ .../tests/StratosIntegrationTest.java | 108 ++ .../application/ApplicationBurstingTest.java | 241 ++++ .../application/ApplicationUpdateTest.java | 275 +++++ .../application/GroupStartupOrderTest.java | 387 +++++++ .../GroupTerminationBehaviorTest.java | 430 +++++++ .../PartitionOneAfterAnotherClusterTest.java | 300 +++++ .../PartitionRoundRobinClusterTest.java | 312 ++++++ .../application/SampleApplicationsTest.java | 261 +++++ .../application/SingleClusterScalingTest.java | 373 +++++++ .../tests/group/CartridgeGroupTest.java | 149 +++ .../integration/tests/group/CartridgeTest.java | 191 ++++ .../tests/policies/ApplicationPolicyTest.java | 195 ++++ .../tests/policies/AutoscalingPolicyTest.java | 144 +++ .../tests/policies/DeploymentPolicyTest.java | 234 ++++ .../tests/policies/NetworkPartitionTest.java | 126 +++ .../integration/tests/users/TenantTest.java | 42 + .../integration/tests/users/UserTest.java | 114 ++ ...cation-policy-application-bursting-test.json | 18 + .../app-bursting-single-cartriddge-group.json | 70 ++ ...caling-policy-application-bursting-test.json | 14 + ...esb-php-group-application-bursting-test.json | 19 + .../mock/esb-application-bursting-test.json | 50 + .../mock/php-application-bursting-test.json | 51 + .../mock/tomcat-application-bursting-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 + ...cation-policy-application-policy-test-1.json | 18 + ...cation-policy-application-policy-test-2.json | 18 + ...lication-policy-application-policy-test.json | 18 + ...ork-partition-application-policy-test-1.json | 24 + ...ork-partition-application-policy-test-2.json | 15 + ...lication-policy-application-update-test.json | 18 + .../g-sc-G123-1-application-update-test-v1.json | 86 ++ .../g-sc-G123-1-application-update-test.json | 86 ++ ...oscaling-policy-application-update-test.json | 14 + ...rdige-nested-application-update-test-v1.json | 50 + ...artrdige-nested-application-update-test.json | 50 + .../mock/c1-application-update-test.json | 45 + .../mock/c2-application-update-test.json | 45 + .../mock/c3-application-update-test.json | 45 + ...yment-policy-application-update-test-v1.json | 36 + ...ployment-policy-application-update-test.json | 32 + ...-partition-application-update-test-1-v1.json | 28 + ...ork-partition-application-update-test-1.json | 15 + ...ork-partition-application-update-test-2.json | 24 + .../src/test/resources/automation.xml | 235 ++++ .../src/test/resources/automationSchema.xsd | 573 ++++++++++ ...caling-policy-autoscaling-policy-test-1.json | 14 + ...caling-policy-autoscaling-policy-test-2.json | 14 + ...aling-policy-autoscaling-policy-test-v1.json | 14 + ...oscaling-policy-autoscaling-policy-test.json | 14 + .../g4-g5-g6-cartridge-group-test-v1.json | 50 + .../g4-g5-g6-cartridge-group-test.json | 50 + .../group-1-cartridge-group-test.json | 50 + .../group-2-cartridge-group-test.json | 50 + .../mock/c4-cartridge-group-test.json | 45 + .../mock/c5-cartridge-group-test.json | 124 +++ .../mock/c6-cartridge-group-test.json | 45 + .../cartridges/mock/c0-cartridge-test-v1.json | 124 +++ .../cartridges/mock/c0-cartridge-test.json | 124 +++ .../cartridges/mock/c1-cartridge-test.json | 124 +++ .../cartridges/mock/c2-cartridge-test.json | 124 +++ .../test/resources/common/JMSOutputAdaptor.xml | 30 + .../src/test/resources/common/autoscaler.xml | 57 + .../common/cartridge-config.properties | 27 + .../test/resources/common/cloud-controller.xml | 81 ++ .../src/test/resources/common/identity.xml | 260 +++++ .../src/test/resources/common/jndi.properties | 22 + .../src/test/resources/common/log4j.properties | 206 ++++ .../src/test/resources/common/mock-iaas.xml | 123 ++ .../src/test/resources/common/scaling.drl | 324 ++++++ .../resources/common/thrift-client-config.xml | 27 + ...loyment-policy-deployment-policy-test-1.json | 32 + ...loyment-policy-deployment-policy-test-2.json | 32 + ...oyment-policy-deployment-policy-test-v1.json | 36 + ...eployment-policy-deployment-policy-test.json | 32 + ...k-partition-deployment-policy-test-1-v1.json | 28 + ...work-partition-deployment-policy-test-1.json | 15 + ...work-partition-deployment-policy-test-2.json | 24 + .../src/test/resources/filters.txt | 16 + ...ication-policy-group-startup-order-test.json | 13 + .../applications/group-startup-order-test.json | 206 ++++ ...scaling-policy-group-startup-order-test.json | 14 + .../group6-group-startup-order-test.json | 44 + .../group8-group-startup-order-test.json | 18 + .../mock/esb-group-startup-order-test.json | 50 + .../mock/php-group-startup-order-test.json | 51 + .../stratos-lb-group-startup-order-test.json | 44 + .../mock/tomcat-group-startup-order-test.json | 53 + .../mock/tomcat1-group-startup-order-test.json | 45 + .../mock/tomcat2-group-startup-order-test.json | 49 + .../mock/tomcat3-group-startup-order-test.json | 31 + ...loyment-policy-group-startup-order-test.json | 18 + ...rk-partition-group-startup-order-test-1.json | 15 + ...rk-partition-group-startup-order-test-2.json | 24 + ...-policy-group-termination-behavior-test.json | 17 + .../group-termination-behavior-test.json | 101 ++ ...-policy-group-termination-behavior-test.json | 14 + ...-groups-group-termination-behavior-test.json | 58 + .../c1-group-termination-behavior-test.json | 45 + .../c2-group-termination-behavior-test.json | 45 + .../c3-group-termination-behavior-test.json | 45 + .../c4-group-termination-behavior-test.json | 45 + ...-policy-group-termination-behavior-test.json | 18 + ...ition-group-termination-behavior-test-1.json | 15 + .../src/test/resources/instrumentation.txt | 1 + .../keystores/products/client-truststore.jks | Bin 0 -> 37935 bytes .../resources/keystores/products/userRP.jks | Bin 0 -> 33278 bytes .../resources/keystores/products/wso2carbon.jks | Bin 0 -> 33260 bytes ...work-partition-network-partition-test-1.json | 15 + ...work-partition-network-partition-test-2.json | 15 + ...ork-partition-network-partition-test-v1.json | 28 + ...etwork-partition-network-partition-test.json | 15 + ...ation-policy-partition-round-robin-test.json | 13 + .../partition-round-robin-test.json | 28 + ...aling-policy-partition-round-robin-test.json | 14 + .../mock/c7-partition-round-robin-test.json | 45 + ...yment-policy-partition-round-robin-test.json | 22 + ...rk-partition-partition-round-robin-test.json | 24 + ...ication-policy-sample-applications-test.json | 18 + ...g-sc-G123-1-sample-applications-test-v1.json | 86 ++ .../g-sc-G123-1-sample-applications-test.json | 86 ++ .../sample-applications-test-1.json | 86 ++ .../sample-applications-test-2.json | 86 ++ ...scaling-policy-sample-applications-test.json | 14 + ...dige-nested-sample-applications-test-v1.json | 50 + ...rtrdige-nested-sample-applications-test.json | 50 + .../mock/c1-sample-applications-test.json | 45 + .../mock/c2-sample-applications-test.json | 45 + .../mock/c3-sample-applications-test.json | 45 + ...ment-policy-sample-applications-test-v1.json | 36 + ...loyment-policy-sample-applications-test.json | 32 + ...partition-sample-applications-test-1-v1.json | 28 + ...rk-partition-sample-applications-test-1.json | 15 + ...rk-partition-sample-applications-test-2.json | 24 + ...tion-policy-single-cluster-scaling-test.json | 13 + .../single-cluster-scaling-test.json | 28 + ...ling-policy-single-cluster-scaling-test.json | 14 + .../mock/c7-single-cluster-scaling-test.json | 45 + ...ment-policy-single-cluster-scaling-test.json | 22 + ...k-partition-single-cluster-scaling-test.json | 24 + .../src/test/resources/stratos-testng.xml | 101 ++ .../src/test/resources/tenant/tenant1.json | 9 + .../src/test/resources/tenant/tenant2.json | 9 + .../src/test/resources/user-test/tenant-1.json | 9 + .../src/test/resources/user-test/user-1-v1.json | 8 + .../src/test/resources/user-test/user-1.json | 8 + 341 files changed, 13201 insertions(+), 16089 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/c0664270/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index e52aa6f..3c1171f 100644 --- a/pom.xml +++ b/pom.xml @@ -395,6 +395,12 @@ <dependencyManagement> <dependencies> <dependency> + <groupId>org.wso2.carbon</groupId> + <artifactId>SecVerifier</artifactId> + <type>aar</type> + <version>${carbon.kernel.version}</version> + </dependency> + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> @@ -464,6 +470,57 @@ <artifactId>org.wso2.carbon.databridge.core</artifactId> <version>${carbon.analytics.common.version}</version> </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-exec</artifactId> + <version>${commons.exec.version}</version> + </dependency> + + <!-- Automation framework dependencies --> + <dependency> + <groupId>org.wso2.carbon.automation</groupId> + <artifactId>org.wso2.carbon.automation.test.utils</artifactId> + <version>${carbon.automation.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.wso2.carbon.automation</groupId> + <artifactId>org.wso2.carbon.automation.engine</artifactId> + <version>${carbon.automation.version}</version> + </dependency> + <dependency> + <groupId>org.wso2.carbon.automation</groupId> + <artifactId>org.wso2.carbon.automation.extensions</artifactId> + <version>${carbon.automation.version}</version> + </dependency> + <dependency> + <groupId>org.wso2.carbon.automationutils</groupId> + <artifactId>org.wso2.carbon.integration.common.utils</artifactId> + <version>${carbon.automationutils.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.wso2.carbon.automationutils</groupId> + <artifactId>org.wso2.carbon.integration.common.admin.client</artifactId> + <version>${carbon.automationutils.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.wso2.carbon.automationutils</groupId> + <artifactId>org.wso2.carbon.integration.common.extensions</artifactId> + <version>${carbon.automationutils.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <version>${testng.version}</version> + </dependency> + <dependency> + <groupId>org.jacoco</groupId> + <artifactId>org.jacoco.agent</artifactId> + <version>${jacoco.agent.version}</version> + </dependency> </dependencies> </dependencyManagement> @@ -683,6 +740,8 @@ <!-- Carbon related versions --> <carbon.kernel.version>4.2.0</carbon.kernel.version> <carbon.deployment.version>4.2.3</carbon.deployment.version> + <carbon.automation.version>4.4.2</carbon.automation.version> + <carbon.automationutils.version>4.4.2</carbon.automationutils.version> <carbon.ui.stratos.version>4.2.0-stratosv2</carbon.ui.stratos.version> <carbon.p2.plugin.version>1.5.3</carbon.p2.plugin.version> <carbon.platform.patch.version.4.2.1>4.2.1</carbon.platform.patch.version.4.2.1> @@ -739,6 +798,11 @@ <siddhi.version>2.0.0-wso2v5</siddhi.version> <siddhi.event.processor.version>1.0.0</siddhi.event.processor.version> <scr.annotations.version>1.9.12</scr.annotations.version> + <testng.version>6.1.1</testng.version> + <jacoco.agent.version>0.7.4.201502262128</jacoco.agent.version> + <commons.exec.version>1.0.1</commons.exec.version> + <httpcore.version>4.3.0.wso2v1</httpcore.version> + <httpclient.version>4.2.5.wso2v1</httpclient.version> <!-- OSGi import ranges --> <axiom.osgi.version.range>[1.2.11.wso2v4, 1.3.0)</axiom.osgi.version.range> http://git-wip-us.apache.org/repos/asf/stratos/blob/c0664270/products/stratos/modules/integration/pom.xml ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/pom.xml b/products/stratos/modules/integration/pom.xml index d04ac0e..1bda132 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 @@ -17,9 +16,8 @@ ~ specific language governing permissions and limitations ~ under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.apache.stratos</groupId> @@ -29,162 +27,12 @@ </parent> <artifactId>stratos-integration</artifactId> - <name>Apache Stratos - Integration Tests</name> - <packaging>jar</packaging> + <packaging>pom</packaging> + <name>Apache Stratos - Integration Aggregation Module</name> + <description>Apache Stratos - Integration Aggregation Module</description> - <dependencies> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-exec</artifactId> - <version>1.0.1</version> - </dependency> - <dependency> - <groupId>org.apache.stratos</groupId> - <artifactId>org.apache.stratos.common</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.wso2.carbon</groupId> - <artifactId>org.wso2.carbon.integration.framework</artifactId> - <version>${carbon.kernel.version}</version> - </dependency> - <dependency> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - <version>6.1.1</version> - </dependency> - <dependency> - <groupId>org.apache.axis2.wso2</groupId> - <artifactId>axis2-client</artifactId> - <version>${axis2.wso2.version}</version> - </dependency> - <dependency> - <groupId>org.wso2.carbon</groupId> - <artifactId>org.wso2.carbon.addressing</artifactId> - <version>${carbon.kernel.version}</version> - </dependency> - <dependency> - <groupId>org.wso2.carbon</groupId> - <artifactId>org.wso2.carbon.integration.core</artifactId> - <version>${carbon.kernel.version}</version> - <classifier>tests</classifier> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.wso2.carbon</groupId> - <artifactId>SecVerifier</artifactId> - <version>${carbon.kernel.version}</version> - <type>aar</type> - </dependency> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>activemq-all</artifactId> - <version>5.10.0</version> - </dependency> - <dependency> - <groupId>org.apache.httpcomponents.wso2</groupId> - <artifactId>httpcore</artifactId> - <version>4.3.0.wso2v1</version> - </dependency> - <dependency> - <groupId>org.apache.httpcomponents.wso2</groupId> - <artifactId>httpclient</artifactId> - <version>4.2.5.wso2v1</version> - </dependency> - <dependency> - <groupId>org.apache.stratos</groupId> - <artifactId>org.apache.stratos.messaging</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.stratos</groupId> - <artifactId>org.apache.stratos.mock.iaas.client</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.wso2.andes.wso2</groupId> - <artifactId>andes-client</artifactId> - <version>0.13.wso2v8</version> - </dependency> - </dependencies> - - <build> - <testResources> - <testResource> - <directory>src/test/resources/test-conf</directory> - <filtering>true</filtering> - </testResource> - <testResource> - <directory>src/test/resources/common</directory> - <includes> - <include>**/jndi.properties</include> - </includes> - </testResource> - <testResource> - <directory>src/test/resources</directory> - </testResource> - </testResources> - <plugins> - <plugin> - <artifactId>maven-surefire-plugin</artifactId> - <inherited>false</inherited> - <configuration> - <systemProperties> - <maven.test.haltafterfailure>false</maven.test.haltafterfailure> - <sec.verifier.dir>${basedir}/target/security-verifier/</sec.verifier.dir> - <extracted.dir>stratos-parent-${project.version}</extracted.dir> - <emma.home>${basedir}/target/emma</emma.home> - </systemProperties> - <suiteXmlFiles> - <suiteXmlFile>src/test/resources/stratos-testing.xml</suiteXmlFile> - </suiteXmlFiles> - <workingDirectory>${basedir}/target</workingDirectory> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>test-jar</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> - <executions> - <execution> - <id>copy-emma-dependencies</id> - <phase>compile</phase> - <goals> - <goal>copy-dependencies</goal> - </goals> - <configuration> - <outputDirectory>${project.build.directory}/emma</outputDirectory> - <includeTypes>jar</includeTypes> - <includeArtifactIds>emma,org.wso2.carbon.integration.framework</includeArtifactIds> - </configuration> - </execution> - <execution> - <id>copy-secVerifier</id> - <phase>compile</phase> - <goals> - <goal>copy-dependencies</goal> - </goals> - <configuration> - <outputDirectory>${basedir}/target/security-verifier</outputDirectory> - <includeTypes>aar</includeTypes> - <includeArtifactIds>SecVerifier</includeArtifactIds> - <stripVersion>true</stripVersion> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> + <modules> + <module>test-common</module> + <module>test-integration</module> + </modules> </project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/c0664270/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/RestConstants.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/RestConstants.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/RestConstants.java deleted file mode 100644 index 2f52da6..0000000 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/RestConstants.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.stratos.integration.tests; - -/** - * Constant class to keep track of rest endpoint context - */ -public class RestConstants { - public static final String API = "api"; - public static final String AUTOSCALING_POLICIES = "/" + API + "/autoscalingPolicies"; - public static final String USERS = "/" + API + "/users"; - public static final String TENANTS = "/" + API + "/tenants"; - public static final String DEPLOYMENT_POLICIES = "/" + API + "/deploymentPolicies"; - public static final String NETWORK_PARTITIONS = "/" + API + "/networkPartitions"; - public static final String CARTRIDGES = "/" + API + "/cartridges"; - public static final String CARTRIDGE_GROUPS = "/" + API + "/cartridgeGroups"; - public static final String APPLICATION_POLICIES = "/" + API + "/applicationPolicies"; - public static final String APPLICATIONS = "/" + API + "/applications"; - public static final String APPLICATIONS_RUNTIME = "/runtime"; - public static final String APPLICATIONS_DEPLOY = "/deploy"; - public static final String APPLICATIONS_UNDEPLOY = "/undeploy"; - - public static final String AUTOSCALING_POLICIES_PATH = "/autoscaling-policies/"; - public static final String AUTOSCALING_POLICIES_NAME = "autoscalingPolicy"; - public static final String CARTRIDGE_GROUPS_PATH = "/cartridges-groups/"; - public static final String CARTRIDGE_GROUPS_NAME = "cartridgeGroup"; - public static final String CARTRIDGES_PATH = "/cartridges/mock/"; - public static final String CARTRIDGES_NAME = "cartridge"; - public static final String NETWORK_PARTITIONS_PATH = "/network-partitions/mock/"; - public static final String NETWORK_PARTITIONS_NAME = "networkPartition"; - public static final String USERS_NAME = "users"; - public static final String DEPLOYMENT_POLICIES_PATH = "/deployment-policies/"; - public static final String DEPLOYMENT_POLICIES_NAME = "deploymentPolicy"; - public static final String APPLICATIONS_PATH = "/applications/"; - public static final String APPLICATIONS_NAME = "application"; - public static final String APPLICATION_POLICIES_PATH = "/application-policies/"; - public static final String APPLICATION_POLICIES_NAME = "applicationPolicy"; - - public static final String TENANT1_RESOURCE ="/tenant/tenant1.json"; - public static final String TENANT2_RESOURCE ="/tenant/tenant2.json"; - public static final String TENANT1_GET_RESOURCE ="test1.com"; - public static final String TENANT2_GET_RESOURCE ="test2.com"; - public static final String TENANT_API = "/" + API + "/tenants"; - public static final String TENANTS_NAME = "tenants"; - - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/c0664270/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 deleted file mode 100755 index 52293ba..0000000 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/StratosTestServerManager.java +++ /dev/null @@ -1,282 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.stratos.integration.tests; - -import org.apache.activemq.broker.BrokerService; -import org.apache.commons.io.FileUtils; -import org.apache.commons.logging.Log; -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.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; -import org.wso2.carbon.integration.framework.utils.ServerUtils; -import org.wso2.carbon.integration.framework.utils.TestUtil; - -import java.io.File; -import java.io.IOException; -import java.util.Properties; - -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 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; - protected IntegrationMockClient mockIaasApiClient; - protected RestClient restClientTenant1; - protected RestClient restClientTenant2; - protected int tenant1Id; - protected int tenant2Id; - - public StratosTestServerManager() { - 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(); - 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 - @BeforeSuite(timeOut = 600000) - public String startServer() throws IOException { - Logger.getRootLogger().addAppender(testLogAppender); - Logger.getRootLogger().setLevel(Level.INFO); - - try { - // Start ActiveMQ - long time1 = System.currentTimeMillis(); - log.info("Starting ActiveMQ..."); - broker.setDataDirectory(StratosTestServerManager.class.getResource("/").getPath() + - File.separator + ".." + File.separator + "activemq-data"); - broker.setBrokerName("testBroker"); - broker.addConnector(activemqBindAddress); - broker.start(); - long time2 = System.currentTimeMillis(); - log.info(String.format("ActiveMQ started in %d sec", (time2 - time1) / 1000)); - } - catch (Exception e) { - throw new RuntimeException("Could not start ActiveMQ", e); - } - - try { - log.info("Setting up Stratos server..."); - long time3 = System.currentTimeMillis(); - String carbonZip = getCarbonZip(); - if (carbonZip == null) { - carbonZip = System.getProperty("carbon.zip"); - } - - if (carbonZip == null) { - throw new IllegalArgumentException("carbon zip file is null"); - } else { - 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", portOffset, null); - FrameworkSettings.init(); - - while (!serverStarted()) { - log.info("Waiting for topology to be initialized..."); - Thread.sleep(5000); - } - - while (!mockServiceStarted()) { - log.info("Waiting for mock service to be initialized..."); - Thread.sleep(1000); - } - - long time4 = System.currentTimeMillis(); - log.info(String.format("Stratos server started in %d sec", (time4 - time3) / 1000)); - createTenants(); - return carbonHome; - } - } - catch (Exception e) { - throw new RuntimeException("Could not start Stratos server", e); - } - } - - 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")) { - return true; - } - } - return false; - } - - @Override - @AfterSuite(timeOut = 600000) - public void stopServer() throws Exception { - super.stopServer(); - /* - while (!serverStopped()) { - log.info("Waiting for server to be shutdown..."); - Thread.sleep(1000); - } - log.info("Stopped Apache Stratos server."); - */ - broker.stop(); - log.info("Stopped ActiveMQ server."); - } - - protected void copyArtifacts(String carbonHome) throws IOException { - 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 filePath, String fileName, String destinationFolder) - throws - IOException { - - 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("Copying file [source] " + srcFile.getAbsolutePath() + " to [dest] " + destFile.getAbsolutePath()); - } - - private boolean serverStopped() { - for (String message : testLogAppender.getMessages()) { - if (message.contains("Halting JVM")) { - return true; - } - } - return false; - } - - - private boolean serverStarted() { - for (String message : testLogAppender.getMessages()) { - if (message.contains("Topology initialized")) { - return true; - } - } - return false; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/c0664270/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 deleted file mode 100644 index a8e516f..0000000 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/TopologyHandler.java +++ /dev/null @@ -1,666 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.stratos.integration.tests; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.autoscaler.stub.pojo.ApplicationContext; -import org.apache.stratos.common.client.AutoscalerServiceClient; -import org.apache.stratos.common.threading.StratosThreadPool; -import org.apache.stratos.integration.tests.rest.IntegrationMockClient; -import org.apache.stratos.messaging.domain.application.*; -import org.apache.stratos.messaging.domain.instance.ClusterInstance; -import org.apache.stratos.messaging.domain.instance.GroupInstance; -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.event.Event; -import org.apache.stratos.messaging.event.application.*; -import org.apache.stratos.messaging.event.topology.*; -import org.apache.stratos.messaging.listener.application.*; -import org.apache.stratos.messaging.listener.topology.*; -import org.apache.stratos.messaging.message.receiver.application.ApplicationManager; -import org.apache.stratos.messaging.message.receiver.application.ApplicationsEventReceiver; -import org.apache.stratos.messaging.message.receiver.topology.TopologyEventReceiver; -import org.apache.stratos.messaging.message.receiver.topology.TopologyManager; - -import java.io.File; -import java.rmi.RemoteException; -import java.util.Collection; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; - -import static junit.framework.Assert.*; - -/** - * To start the Topology receivers - */ -public class TopologyHandler { - private static final Log log = LogFactory.getLog(TopologyHandler.class); - - - 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; - private TopologyEventReceiver topologyEventReceiver; - public static TopologyHandler topologyHandler; - private Map<String, Long> terminatedMembers = new ConcurrentHashMap<String, Long>(); - private Map<String, Long> terminatingMembers = new ConcurrentHashMap<String, Long>(); - private Map<String, Long> createdMembers = new ConcurrentHashMap<String, Long>(); - private Map<String, Long> inActiveMembers = new ConcurrentHashMap<String, Long>(); - private Map<String, Long> activateddMembers = new ConcurrentHashMap<String, Long>(); - - private TopologyHandler() { - // Set jndi.properties.dir system property for initializing event receivers - System.setProperty("jndi.properties.dir", getResourcesFolderPath()); - System.setProperty("autoscaler.service.url", "https://localhost:9443/services/AutoscalerService"); - initializeApplicationEventReceiver(); - initializeTopologyEventReceiver(); - assertApplicationTopologyInitialized(); - assertTopologyInitialized(); - addTopologyEventListeners(); - addApplicationEventListeners(); - } - - public static TopologyHandler getInstance() { - if (topologyHandler == null) { - synchronized (TopologyHandler.class) { - if (topologyHandler == null) { - topologyHandler = new TopologyHandler(); - } - } - } - return topologyHandler; - } - - - /** - * Initialize application event receiver - */ - private void initializeApplicationEventReceiver() { - if (applicationsEventReceiver == null) { - applicationsEventReceiver = new ApplicationsEventReceiver(); - ExecutorService executorService = StratosThreadPool.getExecutorService("STRATOS_TEST_SERVER", 1); - applicationsEventReceiver.setExecutorService(executorService); - applicationsEventReceiver.execute(); - } - } - - /** - * Initialize Topology event receiver - */ - private void initializeTopologyEventReceiver() { - if (topologyEventReceiver == null) { - topologyEventReceiver = new TopologyEventReceiver(); - ExecutorService executorService = StratosThreadPool.getExecutorService("STRATOS_TEST_SERVER1", 1); - topologyEventReceiver.setExecutorService(executorService); - topologyEventReceiver.execute(); - } - } - - /** - * Assert application Topology initialization - */ - private void assertApplicationTopologyInitialized() { - long startTime = System.currentTimeMillis(); - boolean applicationTopologyInitialized = ApplicationManager.getApplications().isInitialized(); - while (!applicationTopologyInitialized) { - try { - Thread.sleep(1000); - } catch (InterruptedException ignore) { - } - applicationTopologyInitialized = ApplicationManager.getApplications().isInitialized(); - if ((System.currentTimeMillis() - startTime) > APPLICATION_TOPOLOGY_TIMEOUT) { - break; - } - } - assertEquals(String.format("Application Topology didn't get initialized "), applicationTopologyInitialized, true); - } - - /** - * Assert Topology initialization - */ - private void assertTopologyInitialized() { - long startTime = System.currentTimeMillis(); - boolean topologyInitialized = TopologyManager.getTopology().isInitialized(); - while (!topologyInitialized) { - try { - Thread.sleep(1000); - } catch (InterruptedException ignore) { - } - topologyInitialized = TopologyManager.getTopology().isInitialized(); - if ((System.currentTimeMillis() - startTime) > APPLICATION_TOPOLOGY_TIMEOUT) { - break; - } - } - assertEquals(String.format("Topology didn't get initialized "), topologyInitialized, true); - } - - /** - * Assert application activation - * - * @param tenantId - * @param applicationName - */ - public void assertApplicationStatus(String applicationName, ApplicationStatus status, int tenantId) { - long startTime = System.currentTimeMillis(); - Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationName, tenantId); - while (!((application != null) && (application.getStatus() == status))) { - try { - Thread.sleep(1000); - } catch (InterruptedException ignore) { - } - application = ApplicationManager.getApplications().getApplicationByTenant(applicationName,tenantId); - if ((System.currentTimeMillis() - startTime) > APPLICATION_ACTIVATION_TIMEOUT) { - break; - } - } - 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); - } - - /** - * Assert application activation - * - * @param applicationName - * @param tenantId - */ - 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); - - Collection<Group> groups = application.getAllGroupsRecursively(); - for (Group group : groups) { - assertEquals(group.getInstanceContextCount() >= group.getGroupMinInstances(), true); - } - } - - /** - * Assert application activation - * - * @param applicationName - * @param tenantId - */ - 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 serviceUuid = clusterDataHolder.getServiceUuid(); - String clusterId = clusterDataHolder.getClusterId(); - Service service = TopologyManager.getTopology().getService(serviceUuid); - assertNotNull(String.format("Service is not found: [application-id] %s [service] %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, serviceUuid, clusterId), cluster); - boolean clusterActive = false; - - 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++; - } - } - } - clusterActive = activeInstances >= clusterDataHolder.getMinInstances(); - - if (!clusterActive) { - break; - } - } - assertEquals(String.format("Cluster status did not change to active: [cluster-id] %s", clusterId), - clusterActive, true); - } - - } - - /** - * Assert application activation - * - * @param tenantId - * @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); - - Set<ClusterDataHolder> clusterDataHolderSet = application.getClusterDataRecursively(); - for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) { - String serviceUuid = clusterDataHolder.getServiceUuid(); - if(cartridgeName.equals(serviceUuid)) { - String clusterId = clusterDataHolder.getClusterId(); - 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, serviceUuid, clusterId), cluster); - boolean memberTerminated = false; - - 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; - } - } - } - - if(memberTerminated) { - break; - } - - } - assertTrue("Any member couldn't be terminated from the mock IaaS client", memberTerminated); - } - - } - - } - - public void assertClusterMinMemberCount(String applicationName, int minMembers, int tenantId) { - long startTime = System.currentTimeMillis(); - - 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.getServiceUuid(); - 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); - - Cluster cluster = service.getCluster(clusterId); - assertNotNull(String.format("Cluster is not found: [application-id] %s [service] %s [cluster-id] %s", - applicationName, serviceName, clusterId), cluster); - boolean clusterActive = false; - - 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++; - } - } - } - clusterActive = activeInstances >= minMembers; - - while (!clusterActive) { - try { - Thread.sleep(1000); - } catch (InterruptedException ignore) { - } - service = TopologyManager.getTopology().getService(serviceName); - assertNotNull(String.format("Service is not found: [application-id] %s [service] %s", - applicationName, serviceName), service); - - cluster = service.getCluster(clusterId); - activeInstances = 0; - for (Member member : cluster.getMembers()) { - if (member.getClusterInstanceId().equals(instance.getInstanceId())) { - if (member.getStatus().equals(MemberStatus.Active)) { - activeInstances++; - } - } - } - clusterActive = activeInstances >= minMembers; - 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) { - break; - } - } - } - assertEquals(String.format("Cluster status did not change to active: [cluster-id] %s", clusterId), - clusterActive, true); - } - - } - - - /** - * Assert application activation - * - * @param applicationName - * @param tenantId - */ - public boolean assertApplicationUndeploy(String applicationName, int tenantId) { - long startTime = System.currentTimeMillis(); - Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationName, tenantId); - ApplicationContext applicationContext = null; - try { - applicationContext = AutoscalerServiceClient.getInstance().getApplicationByTenant(applicationName,tenantId); - } catch (RemoteException e) { - log.error("Error while getting the application context for [application] " + applicationName); - } - while (((application != null) && application.getInstanceContextCount() > 0) || - (applicationContext == null || applicationContext.getStatus().equals(APPLICATION_STATUS_UNDEPLOYING))) { - try { - Thread.sleep(1000); - } catch (InterruptedException ignore) { - } - application = ApplicationManager.getApplications().getApplicationByTenant(applicationName,tenantId); - try { - applicationContext = AutoscalerServiceClient.getInstance().getApplicationByTenant(applicationName,tenantId); - } catch (RemoteException e) { - log.error("Error while getting the application context for [application] " + applicationName); - } - if ((System.currentTimeMillis() - startTime) > APPLICATION_UNDEPLOYMENT_TIMEOUT) { - break; - } - } - - assertNotNull(String.format("Application is not found: [application-id] %s", - applicationName), application); - assertNotNull(String.format("Application Context is not found: [application-id] %s", - applicationName), applicationContext); - - //Force undeployment after the graceful deployment - if (application.getInstanceContextCount() > 0 || - applicationContext.getStatus().equals(APPLICATION_STATUS_UNDEPLOYING)) { - return false; - } - assertEquals(String.format("Application status did not change to Created: [application-id] %s", applicationName), - APPLICATION_STATUS_CREATED, applicationContext.getStatus()); - return true; - } - - /** - * Assert application activation - * - * @param tenantId - * @param applicationName - */ - public void assertGroupInstanceCount(String applicationName, String groupAlias, int count, int tenantId) { - long startTime = System.currentTimeMillis(); - Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationName, tenantId); - if (application != null) { - Group group = application.getGroupRecursively(groupAlias); - while (group.getInstanceContextCount() != count) { - try { - Thread.sleep(1000); - } catch (InterruptedException ignore) { - } - if ((System.currentTimeMillis() - startTime) > APPLICATION_ACTIVATION_TIMEOUT) { - break; - } - } - for (GroupInstance instance : group.getInstanceIdToInstanceContextMap().values()) { - while (!instance.getStatus().equals(GroupStatus.Active)) { - try { - Thread.sleep(1000); - } catch (InterruptedException ignore) { - } - if ((System.currentTimeMillis() - startTime) > APPLICATION_ACTIVATION_TIMEOUT) { - break; - } - } - } - 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); - - } - - 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); - } - - /** - * Get resources folder path - * - * @return - */ - private String getResourcesFolderPath() { - String path = getClass().getResource("/").getPath(); - return StringUtils.removeEnd(path, File.separator); - } - - private void addTopologyEventListeners() { - topologyEventReceiver.addEventListener(new MemberTerminatedEventListener() { - @Override - protected void onEvent(Event event) { - MemberTerminatedEvent memberTerminatedEvent = (MemberTerminatedEvent) event; - getTerminatedMembers().put(memberTerminatedEvent.getMemberId(), System.currentTimeMillis()); - - } - }); - - - topologyEventReceiver.addEventListener(new ClusterInstanceCreatedEventListener() { - @Override - protected void onEvent(Event event) { - ClusterInstanceCreatedEvent event1 = (ClusterInstanceCreatedEvent) event; - String clusterId = event1.getClusterId(); - getCreatedMembers().put(clusterId, System.currentTimeMillis()); - } - }); - - topologyEventReceiver.addEventListener(new ClusterInstanceActivatedEventListener() { - @Override - protected void onEvent(Event event) { - ClusterInstanceActivatedEvent event1 = (ClusterInstanceActivatedEvent) event; - String clusterId = event1.getClusterId(); - getActivateddMembers().put(clusterId, System.currentTimeMillis()); - - } - }); - - topologyEventReceiver.addEventListener(new ClusterInstanceInactivateEventListener() { - @Override - protected void onEvent(Event event) { - ClusterInstanceInactivateEvent event1 = (ClusterInstanceInactivateEvent) event; - String clusterId = event1.getClusterId(); - getInActiveMembers().put(clusterId, System.currentTimeMillis()); - } - }); - - topologyEventReceiver.addEventListener(new ClusterInstanceTerminatedEventListener() { - @Override - protected void onEvent(Event event) { - ClusterInstanceTerminatedEvent event1 = (ClusterInstanceTerminatedEvent) event; - String clusterId = event1.getClusterId(); - getTerminatedMembers().put(clusterId, System.currentTimeMillis()); - } - }); - - topologyEventReceiver.addEventListener(new ClusterInstanceTerminatingEventListener() { - @Override - protected void onEvent(Event event) { - ClusterInstanceTerminatingEvent event1 = (ClusterInstanceTerminatingEvent) event; - String clusterId = event1.getClusterId(); - getTerminatingMembers().put(clusterId, System.currentTimeMillis()); - } - }); - - - } - - private void addApplicationEventListeners() { - - applicationsEventReceiver.addEventListener(new GroupInstanceCreatedEventListener() { - @Override - protected void onEvent(Event event) { - GroupInstanceCreatedEvent event1 = (GroupInstanceCreatedEvent) event; - String appId = event1.getAppId(); - String groupId = event1.getGroupId(); - String instanceId = event1.getGroupInstance().getInstanceId(); - String id = generateId(appId, groupId, instanceId); - getCreatedMembers().put(id, System.currentTimeMillis()); - - } - }); - - applicationsEventReceiver.addEventListener(new GroupInstanceActivatedEventListener() { - @Override - protected void onEvent(Event event) { - GroupInstanceActivatedEvent event1 = (GroupInstanceActivatedEvent) event; - String appId = event1.getAppId(); - String groupId = event1.getGroupId(); - String instanceId = event1.getInstanceId(); - String id = generateId(appId, groupId, instanceId); - getActivateddMembers().put(id, System.currentTimeMillis()); - } - }); - - applicationsEventReceiver.addEventListener(new GroupInstanceInactivateEventListener() { - @Override - protected void onEvent(Event event) { - GroupInstanceInactivatedEvent event1 = (GroupInstanceInactivatedEvent) event; - String appId = event1.getAppId(); - String groupId = event1.getGroupId(); - String instanceId = event1.getInstanceId(); - String id = generateId(appId, groupId, instanceId); - getInActiveMembers().put(id, System.currentTimeMillis()); - } - }); - - applicationsEventReceiver.addEventListener(new GroupInstanceTerminatedEventListener() { - @Override - protected void onEvent(Event event) { - GroupInstanceTerminatedEvent event1 = (GroupInstanceTerminatedEvent) event; - String appId = event1.getAppId(); - String groupId = event1.getGroupId(); - String instanceId = event1.getInstanceId(); - String id = generateId(appId, groupId, instanceId); - getTerminatedMembers().put(id, System.currentTimeMillis()); - } - }); - - applicationsEventReceiver.addEventListener(new GroupInstanceTerminatingEventListener() { - @Override - protected void onEvent(Event event) { - GroupInstanceTerminatingEvent event1 = (GroupInstanceTerminatingEvent) event; - String appId = event1.getAppId(); - String groupId = event1.getGroupId(); - String instanceId = event1.getInstanceId(); - String id = generateId(appId, groupId, instanceId); - getTerminatingMembers().put(id, System.currentTimeMillis()); - } - }); - } - - public String generateId(String appId, String groupId, String instanceId) { - return appId + "-" + groupId + "-" + instanceId; - } - - public String getClusterIdFromAlias(String applicationId, String alias,int tenantId) { - Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationId,tenantId); - assertNotNull(application); - - ClusterDataHolder dataHolder = application.getClusterDataHolderRecursivelyByAlias(alias); - assertNotNull(dataHolder); - - return dataHolder.getClusterId(); - } - - - public void removeMembersFromMaps(String 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)) { - getTerminatedMembers().remove(entry.getKey()); - } - } - } - - public Map<String, Long> getTerminatedMembers() { - return terminatedMembers; - } - - public void setTerminatedMembers(Map<String, Long> terminatedMembers) { - this.terminatedMembers = terminatedMembers; - } - - public Map<String, Long> getTerminatingMembers() { - return terminatingMembers; - } - - public void setTerminatingMembers(Map<String, Long> terminatingMembers) { - this.terminatingMembers = terminatingMembers; - } - - public Map<String, Long> getCreatedMembers() { - return createdMembers; - } - - public void setCreatedMembers(Map<String, Long> createdMembers) { - this.createdMembers = createdMembers; - } - - public Map<String, Long> getInActiveMembers() { - return inActiveMembers; - } - - public void setInActiveMembers(Map<String, Long> inActiveMembers) { - this.inActiveMembers = inActiveMembers; - } - - public Map<String, Long> getActivateddMembers() { - return activateddMembers; - } - - public void setActivateddMembers(Map<String, Long> activateddMembers) { - this.activateddMembers = activateddMembers; - } -}
