Introducing mock iaas service and server profile to run mock iaas as a separate product
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/e16acd17 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/e16acd17 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/e16acd17 Branch: refs/heads/master Commit: e16acd17e0188016786179f64876ce8cf1ad06ee Parents: c262a80 Author: Imesh Gunaratne <[email protected]> Authored: Tue Jan 27 17:49:44 2015 +0530 Committer: Imesh Gunaratne <[email protected]> Committed: Tue Jan 27 17:51:30 2015 +0530 ---------------------------------------------------------------------- .../services/impl/AutoscalerServiceImpl.java | 1 - .../org.apache.stratos.cloud.controller/pom.xml | 16 +- .../parser/CloudControllerConfigParser.java | 15 +- .../config/parser/IaasProviderConfigParser.java | 13 +- .../deployers/CloudControllerDeployer.java | 3 +- .../controller/domain/InstanceMetadata.java | 1 + .../MalformedConfigurationFileException.java | 43 -- .../cloud/controller/iaases/mock/MockIaas.java | 54 +- .../iaases/mock/MockIaasPartitionValidator.java | 45 ++ .../iaases/mock/MockPartitionValidator.java | 45 -- .../mock/service/MockAutoscalingFactor.java | 27 - .../iaases/mock/service/MockConstants.java | 27 - .../iaases/mock/service/MockIPAddressPool.java | 108 --- .../iaases/mock/service/MockIaasService.java | 231 ------ .../iaases/mock/service/MockMember.java | 155 ---- .../iaases/mock/service/MockMemberContext.java | 81 --- .../mock/service/MockMemberEventPublisher.java | 125 ---- .../config/MockHealthStatisticsConfig.java | 44 -- .../mock/service/config/MockIaasConfig.java | 65 -- .../service/config/MockIaasConfigParser.java | 172 ----- .../ContinueLastSampleValueException.java | 36 - .../NoSampleValuesFoundException.java | 26 - .../exceptions/NoStatisticsFoundException.java | 26 - .../StopStatisticsPublishingException.java | 26 - .../statistics/MockHealthStatistics.java | 122 ---- .../statistics/StatisticsPatternMode.java | 27 - .../MockHealthStatisticsGenerator.java | 148 ---- .../generator/MockHealthStatisticsPattern.java | 110 --- .../generator/MockHealthStatisticsUpdater.java | 83 --- .../publisher/MockHealthStatisticsNotifier.java | 104 --- .../MockHealthStatisticsPublisher.java | 91 --- .../CloudControllerServiceComponent.java | 15 +- .../internal/ServiceReferenceHolder.java | 9 +- .../impl/CloudControllerServiceImpl.java | 13 +- .../controller/util/AxiomXpathParserUtil.java | 260 ------- .../service/axiom/AxiomValidationTest.java | 2 +- .../service/axiom/AxiomXpathParserTest.java | 2 +- .../MalformedConfigurationFileException.java | 43 ++ .../internal/StratosCommonServiceComponent.java | 2 +- .../common/util/AxiomXpathParserUtil.java | 262 +++++++ .../org.apache.stratos.custom.handlers/pom.xml | 2 - components/org.apache.stratos.messaging/pom.xml | 9 - .../org.apache.stratos.metadata.service/pom.xml | 5 +- .../org.apache.stratos.mock.iaas.api/pom.xml | 115 +++ .../stratos/mock/iaas/api/MockIaasApi.java | 154 ++++ .../api/exception/MockIaasApiException.java | 70 ++ .../api/handlers/BadRequestExceptionMapper.java | 64 ++ .../api/handlers/CustomExceptionMapper.java | 52 ++ .../CustomThrowableExceptionMapper.java | 58 ++ .../api/handlers/GenericExceptionMapper.java | 47 ++ .../mock/iaas/api/utils/MockIaasApiUtils.java | 37 + .../org.apache.stratos.mock.iaas.client/pom.xml | 109 +++ .../mock/iaas/client/MockIaasApiClient.java | 130 ++++ .../mock/iaas/client/rest/HttpResponse.java | 54 ++ .../iaas/client/rest/HttpResponseHandler.java | 69 ++ .../mock/iaas/client/rest/RestClient.java | 118 +++ components/org.apache.stratos.mock.iaas/pom.xml | 70 ++ .../iaas/config/MockHealthStatisticsConfig.java | 44 ++ .../mock/iaas/config/MockIaasConfig.java | 70 ++ .../mock/iaas/config/MockIaasConfigParser.java | 173 +++++ .../stratos/mock/iaas/domain/ErrorResponse.java | 57 ++ .../mock/iaas/domain/MockInstanceContext.java | 141 ++++ .../mock/iaas/domain/MockInstanceMetadata.java | 69 ++ .../publisher/MockMemberEventPublisher.java | 126 ++++ .../ContinueLastSampleValueException.java | 36 + .../mock/iaas/exceptions/MockIaasException.java | 38 + .../NoSampleValuesFoundException.java | 26 + .../exceptions/NoStatisticsFoundException.java | 26 + .../StopStatisticsPublishingException.java | 26 + .../iaas/internal/MockIaasServiceComponent.java | 84 +++ .../iaas/internal/ServiceReferenceHolder.java | 53 ++ .../persistence/MockPersistenceManager.java | 53 ++ .../iaas/persistence/PersistenceManager.java | 36 + .../persistence/PersistenceManagerFactory.java | 36 + .../persistence/PersistenceManagerType.java | 27 + .../mock/iaas/persistence/RegistryManager.java | 184 +++++ .../mock/iaas/services/MockIaasService.java | 66 ++ .../services/impl/MockAutoscalingFactor.java | 27 + .../mock/iaas/services/impl/MockConstants.java | 31 + .../iaas/services/impl/MockIPAddressPool.java | 116 +++ .../iaas/services/impl/MockIaasServiceImpl.java | 209 ++++++ .../iaas/services/impl/MockIaasServiceUtil.java | 83 +++ .../mock/iaas/services/impl/MockInstance.java | 157 ++++ .../iaas/statistics/MockHealthStatistics.java | 122 ++++ .../iaas/statistics/StatisticsPatternMode.java | 27 + .../MockHealthStatisticsGenerator.java | 148 ++++ .../generator/MockHealthStatisticsPattern.java | 110 +++ .../generator/MockHealthStatisticsUpdater.java | 83 +++ .../publisher/MockHealthStatisticsNotifier.java | 104 +++ .../MockHealthStatisticsPublisher.java | 91 +++ .../mock/iaas/test/MockIaasServiceTest.java | 127 ++++ .../src/test/resources/mock-iaas.xml | 43 ++ .../org.apache.stratos.rest.endpoint/pom.xml | 3 +- components/pom.xml | 4 + .../pom.xml | 3 +- features/autoscaler/pom.xml | 4 +- .../pom.xml | 87 +-- .../main/resources/conf/cloud-controller.xml | 1 + features/cloud-controller/pom.xml | 5 +- .../org.apache.stratos.common.feature/pom.xml | 77 ++ .../pom.xml | 241 ++++++ .../resources/build.properties | 23 + .../resources/conf/cloud-services-desc.xml | 198 +++++ .../resources/conf/identity.xml | 174 +++++ .../resources/conf/multitenancy-packages.xml | 100 +++ .../resources/conf/stratos.xml | 83 +++ .../resources/conf/tenant-mgt.xml | 38 + .../conf/usage-throttling-agent-config.xml | 49 ++ .../resources/p2.inf | 25 + .../src/main/resources/build.properties | 23 + .../main/resources/conf/cloud-services-desc.xml | 198 +++++ .../src/main/resources/conf/identity.xml | 174 +++++ .../resources/conf/multitenancy-packages.xml | 100 +++ .../src/main/resources/conf/stratos.xml | 83 +++ .../src/main/resources/conf/tenant-mgt.xml | 38 + .../conf/usage-throttling-agent-config.xml | 49 ++ .../src/main/resources/p2.inf | 25 + .../pom.xml | 128 ++++ .../pom.xml | 3 +- .../pom.xml | 112 --- features/common/pom.xml | 8 +- features/load-balancer/pom.xml | 2 +- .../org.apache.stratos.common.feature/pom.xml | 76 -- .../pom.xml | 239 ------ .../resources/build.properties | 23 - .../resources/conf/cloud-services-desc.xml | 198 ----- .../resources/conf/identity.xml | 174 ----- .../resources/conf/multitenancy-packages.xml | 100 --- .../resources/conf/stratos.xml | 83 --- .../resources/conf/tenant-mgt.xml | 38 - .../conf/usage-throttling-agent-config.xml | 49 -- .../resources/p2.inf | 25 - .../src/main/resources/build.properties | 23 - .../main/resources/conf/cloud-services-desc.xml | 198 ----- .../src/main/resources/conf/identity.xml | 174 ----- .../resources/conf/multitenancy-packages.xml | 100 --- .../src/main/resources/conf/stratos.xml | 83 --- .../src/main/resources/conf/tenant-mgt.xml | 38 - .../conf/usage-throttling-agent-config.xml | 49 -- .../src/main/resources/p2.inf | 25 - .../pom.xml | 126 ---- features/manager/common/pom.xml | 43 -- .../pom.xml | 113 +++ .../pom.xml | 305 ++++++++ .../src/main/resources/p2.inf | 22 + .../src/main/resources/tomcat/context.xml | 36 + .../tomcat/webapp-classloading-environments.xml | 64 ++ .../resources/tomcat/webapp-classloading.xml | 33 + .../pom.xml | 316 -------- .../src/main/resources/p2.inf | 23 - .../src/main/resources/tomcat/context.xml | 36 - .../tomcat/webapp-classloading-environments.xml | 68 -- .../resources/tomcat/webapp-classloading.xml | 33 - features/manager/pom.xml | 9 +- .../pom.xml | 11 - .../src/main/resources/p2.inf | 1 - .../tomcat/webapp-classloading-environments.xml | 4 - .../pom.xml | 299 ++++++++ .../src/main/resources/p2.inf | 22 + .../src/main/resources/tomcat/context.xml | 37 + .../tomcat/webapp-classloading-environments.xml | 67 ++ .../resources/tomcat/webapp-classloading.xml | 36 + features/mock-iaas/pom.xml | 39 + features/pom.xml | 8 +- .../load-balancer/modules/p2-profile/pom.xml | 11 - products/stratos/modules/distribution/pom.xml | 142 ++-- .../modules/distribution/src/assembly/bin.xml | 8 +- products/stratos/modules/p2-profile-gen/pom.xml | 725 ++++++++++++------- 168 files changed, 7934 insertions(+), 5146 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java index 3f595ca..1ce9072 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java @@ -229,7 +229,6 @@ public class AutoscalerServiceImpl implements AutoscalerService { ApplicationParser applicationParser = new DefaultApplicationParser(); Application application = applicationParser.parse(applicationContext); - // Create application clusters in cloud controller and send application created event ApplicationBuilder.handleApplicationCreatedEvent(application, applicationParser.getApplicationClusterContexts()); http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.cloud.controller/pom.xml ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/pom.xml b/components/org.apache.stratos.cloud.controller/pom.xml index 5d3b64b..d969d29 100644 --- a/components/org.apache.stratos.cloud.controller/pom.xml +++ b/components/org.apache.stratos.cloud.controller/pom.xml @@ -49,11 +49,11 @@ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> <Bundle-Name>${project.artifactId}</Bundle-Name> <Export-Package> - !org.apache.stratos.cloud.controller.internal.*, - org.apache.stratos.cloud.controller.*, + !org.apache.stratos.cloud.controller.internal.*, + org.apache.stratos.cloud.controller.*, </Export-Package> <Private-Package> - org.apache.stratos.cloud.controller.internal.*, + org.apache.stratos.cloud.controller.internal.*, </Private-Package> <Import-Package> !org.apache.commons.logging, @@ -65,9 +65,7 @@ *; resolution:=optional </Import-Package> <DynamicImport-Package>*</DynamicImport-Package> - <Axis2Deployer>CloudControllerDeployer</Axis2Deployer> - </instructions> </configuration> </plugin> @@ -161,7 +159,6 @@ <artifactId>guava</artifactId> </exclusion> </exclusions> - </dependency> <dependency> <groupId>org.wso2.andes.wso2</groupId> @@ -173,13 +170,11 @@ <artifactId>geronimo-jms_1.1_spec</artifactId> <version>${orbit.version.geronimo-jms_1.1_spec}</version> </dependency> - <dependency> <groupId>org.wso2.carbon</groupId> <artifactId>org.wso2.carbon.analytics.hive.stub</artifactId> <version>${wso2carbon.version}</version> </dependency> - <!-- jclouds dependencies --> <dependency> <groupId>org.apache.jclouds</groupId> @@ -312,6 +307,11 @@ <artifactId>org.apache.stratos.metadata.client</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.apache.stratos</groupId> + <artifactId>org.apache.stratos.mock.iaas.client</artifactId> + <version>${project.version}</version> + </dependency> </dependencies> <properties> <gson2.version>2.2</gson2.version> http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/config/parser/CloudControllerConfigParser.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/config/parser/CloudControllerConfigParser.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/config/parser/CloudControllerConfigParser.java index 73380b8..fc33c8f 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/config/parser/CloudControllerConfigParser.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/config/parser/CloudControllerConfigParser.java @@ -19,21 +19,21 @@ package org.apache.stratos.cloud.controller.config.parser; -import java.util.ArrayList; -import java.util.List; -import javax.xml.namespace.QName; - import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMNode; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.cloud.controller.config.CloudControllerConfig; -import org.apache.stratos.cloud.controller.util.AxiomXpathParserUtil; -import org.apache.stratos.cloud.controller.exception.MalformedConfigurationFileException; import org.apache.stratos.cloud.controller.domain.DataPublisherConfig; import org.apache.stratos.cloud.controller.domain.IaasProvider; import org.apache.stratos.cloud.controller.domain.TopologyConfig; +import org.apache.stratos.common.exception.MalformedConfigurationFileException; import org.apache.stratos.cloud.controller.util.CloudControllerConstants; +import org.apache.stratos.common.util.AxiomXpathParserUtil; + +import javax.xml.namespace.QName; +import java.util.ArrayList; +import java.util.List; /** * Parse the cloud-controller.xml @@ -65,8 +65,7 @@ public class CloudControllerConfigParser { List<IaasProvider> iaasProviders = CloudControllerConfig.getInstance().getIaasProviders(); if (iaasProviders == null) { - CloudControllerConfig.getInstance() - .setIaasProviders((iaasProviders = new ArrayList<IaasProvider>())); + CloudControllerConfig.getInstance().setIaasProviders((iaasProviders = new ArrayList<IaasProvider>())); } // this is a valid scenario. User can have 0..1 iaas provider elements http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/config/parser/IaasProviderConfigParser.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/config/parser/IaasProviderConfigParser.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/config/parser/IaasProviderConfigParser.java index 91bb580..aa98450 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/config/parser/IaasProviderConfigParser.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/config/parser/IaasProviderConfigParser.java @@ -18,22 +18,21 @@ */ package org.apache.stratos.cloud.controller.config.parser; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import javax.xml.namespace.QName; - import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMNode; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.exception.MalformedConfigurationFileException; import org.apache.stratos.cloud.controller.domain.IaasProvider; import org.apache.stratos.cloud.controller.util.CloudControllerConstants; +import org.apache.stratos.common.exception.MalformedConfigurationFileException; import org.wso2.securevault.SecretResolver; import org.wso2.securevault.SecretResolverFactory; +import javax.xml.namespace.QName; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + /** * Parse the iaas providers. * http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java index 8af29ad..e3484f1 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java @@ -26,8 +26,7 @@ import org.apache.axis2.deployment.repository.util.DeploymentFileData; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.cloud.controller.config.CloudControllerConfig; -import org.apache.stratos.cloud.controller.context.CloudControllerContext; -import org.apache.stratos.cloud.controller.util.AxiomXpathParserUtil; +import org.apache.stratos.common.util.AxiomXpathParserUtil; import org.apache.stratos.cloud.controller.config.parser.CloudControllerConfigParser; import org.apache.stratos.cloud.controller.domain.IaasProvider; http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceMetadata.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceMetadata.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceMetadata.java index 2971128..4c0895b 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceMetadata.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceMetadata.java @@ -27,6 +27,7 @@ import java.io.Serializable; public class InstanceMetadata implements Serializable { private static final long serialVersionUID = 2121193151475197625L; + private String hostname; private String hypervisor; private int ram; http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/MalformedConfigurationFileException.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/MalformedConfigurationFileException.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/MalformedConfigurationFileException.java deleted file mode 100644 index bfafcab..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/MalformedConfigurationFileException.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.stratos.cloud.controller.exception; - -public class MalformedConfigurationFileException extends RuntimeException { - - private static final long serialVersionUID = -1662095377704279326L; - private String message; - - public MalformedConfigurationFileException(String msg) { - super(msg); - this.setMessage(msg); - } - - public MalformedConfigurationFileException(String msg, Exception ex) { - super(msg, ex); - this.setMessage(msg); - } - - private void setMessage(String msg) { - this.message = msg; - } - - public String getMessage() { - return this.message; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaas.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaas.java index 6c16bc1..c548d5d 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaas.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaas.java @@ -19,21 +19,34 @@ package org.apache.stratos.cloud.controller.iaases.mock; +import org.apache.commons.lang.StringUtils; import org.apache.stratos.cloud.controller.domain.IaasProvider; import org.apache.stratos.cloud.controller.domain.MemberContext; import org.apache.stratos.cloud.controller.domain.Partition; import org.apache.stratos.cloud.controller.exception.*; import org.apache.stratos.cloud.controller.iaases.Iaas; import org.apache.stratos.cloud.controller.iaases.PartitionValidator; -import org.apache.stratos.cloud.controller.iaases.mock.service.MockIaasService; +import org.apache.stratos.mock.iaas.client.MockIaasApiClient; +import org.apache.stratos.mock.iaas.domain.MockInstanceContext; +import org.apache.stratos.mock.iaas.domain.MockInstanceMetadata; /** * Mock IaaS client for invoking mock IaaS service. */ public class MockIaas extends Iaas { + private MockIaasApiClient apiClient; + private PartitionValidator partitionValidator; + public MockIaas(IaasProvider iaasProvider) { super(iaasProvider); + String endpoint = iaasProvider.getProperty("api.endpoint"); + if(StringUtils.isBlank(endpoint)) { + throw new CloudControllerException("api.endpoint property not found in mock iaas provider in" + + "cloud-controller.xml file"); + } + apiClient = new MockIaasApiClient(endpoint); + partitionValidator = new MockIaasPartitionValidator(); } @Override @@ -42,71 +55,82 @@ public class MockIaas extends Iaas { @Override public MemberContext startInstance(MemberContext memberContext) { - return MockIaasService.getInstance().createInstance(memberContext); + MockInstanceContext mockInstanceContext = new MockInstanceContext( + memberContext.getApplicationId(), + memberContext.getCartridgeType(), + memberContext.getClusterId(), + memberContext.getMemberId(), + memberContext.getClusterInstanceId(), + memberContext.getNetworkPartitionId(), + memberContext.getPartition().getId() + ); + MockInstanceMetadata mockInstanceMetadata = apiClient.startInstance(mockInstanceContext); + memberContext.setInstanceId(mockInstanceMetadata.getInstanceId()); + return memberContext; } @Override public void releaseAddress(String ip) { - MockIaasService.getInstance().releaseAddress(ip); } @Override public boolean isValidRegion(String region) throws InvalidRegionException { - return MockIaasService.getInstance().isValidRegion(region); + return true; } @Override public boolean isValidZone(String region, String zone) throws InvalidZoneException, InvalidRegionException { - return MockIaasService.getInstance().isValidZone(region, zone); + return true; } @Override public boolean isValidHost(String zone, String host) throws InvalidHostException { - return MockIaasService.getInstance().isValidHost(zone, host); + return true; } @Override public PartitionValidator getPartitionValidator() { - return MockIaasService.getInstance().getPartitionValidator(); + return partitionValidator; } @Override public String createVolume(int sizeGB, String snapshotId) { - return MockIaasService.getInstance().createVolume(sizeGB, snapshotId); + return null; } @Override public String attachVolume(String instanceId, String volumeId, String deviceName) { - return MockIaasService.getInstance().attachVolume(instanceId, volumeId, deviceName); + return null; } @Override public void detachVolume(String instanceId, String volumeId) { - MockIaasService.getInstance().detachVolume(instanceId, volumeId); } @Override public void deleteVolume(String volumeId) { - MockIaasService.getInstance().deleteVolume(volumeId); } @Override public String getIaasDevice(String device) { - return MockIaasService.getInstance().getIaasDevice(device); + return null; } @Override public void allocateIpAddresses(String clusterId, MemberContext memberContext, Partition partition) { - MockIaasService.getInstance().allocateIpAddress(clusterId, memberContext, partition); + MockInstanceMetadata mockInstanceMetadata = apiClient.allocateIpAddress(memberContext.getInstanceId()); + if(mockInstanceMetadata != null) { + memberContext.setDefaultPrivateIP(mockInstanceMetadata.getDefaultPrivateIp()); + memberContext.setDefaultPublicIP(mockInstanceMetadata.getDefaultPublicIp()); + } } @Override public void setDynamicPayload(byte[] payload) { - MockIaasService.getInstance().setDynamicPayload(payload); } @Override public void terminateInstance(MemberContext memberContext) throws InvalidCartridgeTypeException, InvalidMemberException { - MockIaasService.getInstance().terminateInstance(memberContext); + apiClient.terminateInstance(memberContext.getInstanceId()); } } http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaasPartitionValidator.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaasPartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaasPartitionValidator.java new file mode 100644 index 0000000..d5241f8 --- /dev/null +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaasPartitionValidator.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.cloud.controller.iaases.mock; + +import org.apache.stratos.cloud.controller.domain.IaasProvider; +import org.apache.stratos.cloud.controller.domain.Partition; +import org.apache.stratos.cloud.controller.exception.InvalidPartitionException; +import org.apache.stratos.cloud.controller.iaases.PartitionValidator; + +import java.util.Properties; + +/** + * Mock partition validator. + */ +public class MockIaasPartitionValidator implements PartitionValidator { + + private IaasProvider iaasProvider; + + @Override + public void setIaasProvider(IaasProvider iaasProvider) { + this.iaasProvider = iaasProvider; + } + + @Override + public IaasProvider validate(Partition partition, Properties properties) throws InvalidPartitionException { + return iaasProvider; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockPartitionValidator.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockPartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockPartitionValidator.java deleted file mode 100644 index fbea11b..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockPartitionValidator.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.stratos.cloud.controller.iaases.mock; - -import org.apache.stratos.cloud.controller.domain.IaasProvider; -import org.apache.stratos.cloud.controller.domain.Partition; -import org.apache.stratos.cloud.controller.exception.InvalidPartitionException; -import org.apache.stratos.cloud.controller.iaases.PartitionValidator; - -import java.util.Properties; - -/** - * Mock partition validator. - */ -public class MockPartitionValidator implements PartitionValidator { - - private IaasProvider iaasProvider; - - @Override - public void setIaasProvider(IaasProvider iaasProvider) { - this.iaasProvider = iaasProvider; - } - - @Override - public IaasProvider validate(Partition partition, Properties properties) throws InvalidPartitionException { - return iaasProvider; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockAutoscalingFactor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockAutoscalingFactor.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockAutoscalingFactor.java deleted file mode 100644 index 684ce45..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockAutoscalingFactor.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.stratos.cloud.controller.iaases.mock.service; - -/** - * Mock autoscaling factor enumeration - */ -public enum MockAutoscalingFactor { - MemoryConsumption, LoadAverage, RequestInFlight -} http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockConstants.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockConstants.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockConstants.java deleted file mode 100644 index 360da68..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockConstants.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.stratos.cloud.controller.iaases.mock.service; - -/** - * Mock constant definitions. - */ -public class MockConstants { - public static final int MAX_MOCK_MEMBER_COUNT = 100; -} http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockIPAddressPool.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockIPAddressPool.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockIPAddressPool.java deleted file mode 100644 index 6723bf7..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockIPAddressPool.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.stratos.cloud.controller.iaases.mock.service; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.registry.RegistryManager; -import org.wso2.carbon.registry.core.exceptions.RegistryException; - -import java.io.Serializable; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Mock IP address pool is a singleton class for managing mocked private and public IP addresses. - */ -public class MockIPAddressPool { - private static final Log log = LogFactory.getLog(MockIPAddressPool.class); - - private static final String MOCK_IAAS_PRIVATE_IP_SEQUENCE = "/cloud.controller/mock/iaas/private-ip-sequence"; - private static final String MOCK_IAAS_PUBLIC_IP_SEQUENCE = "/cloud.controller/mock/iaas/public-ip-sequence"; - private static final String PRIVATE_IP_PREFIX = "10.0.0."; - private static final String PUBLIC_IP_PREFIX = "20.0.0."; - - private static volatile MockIPAddressPool instance; - - private AtomicInteger privateIpSequence; - private AtomicInteger publicIpSequence; - - private MockIPAddressPool() { - try { - privateIpSequence = (AtomicInteger) RegistryManager.getInstance().read(MOCK_IAAS_PRIVATE_IP_SEQUENCE); - if (privateIpSequence == null) { - privateIpSequence = new AtomicInteger(); - } - } catch (RegistryException e) { - String message = "Could not read private ip sequence from registry"; - log.error(message, e); - throw new RuntimeException(e); - } - - try { - publicIpSequence = (AtomicInteger) RegistryManager.getInstance().read(MOCK_IAAS_PUBLIC_IP_SEQUENCE); - if (publicIpSequence == null) { - publicIpSequence = new AtomicInteger(); - } - } catch (RegistryException e) { - String message = "Could not read public ip sequence from registry"; - log.error(message, e); - throw new RuntimeException(e); - } - } - - public static MockIPAddressPool getInstance() { - if (instance == null) { - synchronized (MockIPAddressPool.class) { - if (instance == null) { - instance = new MockIPAddressPool(); - } - } - } - return instance; - } - - public String getNextPrivateIpAddress() { - int nextSequence = privateIpSequence.incrementAndGet(); - String ipAddress = PRIVATE_IP_PREFIX + nextSequence; - persistInRegistry(MOCK_IAAS_PRIVATE_IP_SEQUENCE, privateIpSequence); - if (log.isInfoEnabled()) { - log.info("Mock private IP address allocated: " + ipAddress); - } - return ipAddress; - } - - public String getNextPublicIpAddress() { - int nextSequence = publicIpSequence.incrementAndGet(); - String ipAddress = PUBLIC_IP_PREFIX + nextSequence; - persistInRegistry(MOCK_IAAS_PRIVATE_IP_SEQUENCE, publicIpSequence); - if (log.isInfoEnabled()) { - log.info("Mock public IP address allocated: " + ipAddress); - } - return ipAddress; - } - - private void persistInRegistry(String resourcePath, Serializable serializable) { - try { - RegistryManager.getInstance().persist(resourcePath, serializable); - } catch (RegistryException e) { - log.error(String.format("Could not persist mock iaas ip sequence [%s] in registry", resourcePath), e); - } - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockIaasService.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockIaasService.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockIaasService.java deleted file mode 100644 index c2ba3a0..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockIaasService.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.stratos.cloud.controller.iaases.mock.service; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.domain.*; -import org.apache.stratos.cloud.controller.exception.*; -import org.apache.stratos.cloud.controller.iaases.mock.MockPartitionValidator; -import org.apache.stratos.cloud.controller.iaases.mock.service.config.MockIaasConfig; -import org.apache.stratos.cloud.controller.iaases.mock.service.statistics.generator.MockHealthStatisticsGenerator; -import org.apache.stratos.cloud.controller.iaases.PartitionValidator; -import org.apache.stratos.cloud.controller.registry.RegistryManager; -import org.apache.stratos.common.threading.StratosThreadPool; -import org.wso2.carbon.registry.core.exceptions.RegistryException; - -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; - -/** - * Mock IaaS service implementation. This is a singleton class that simulates a standard Infrastructure as a Service - * platform by creating mock members and managing their lifecycle states. - * - * How does this work: - * - Mock IaaS starts a Mock Member thread or each instance created - * - A sample private IP and a public IP will be assigned to the instance - * - Mock Member will publish Instance Started and Instance Activated events once the thread is started - * - Afterwards it will start publishing sample health statistics values to CEP - * - If the Mock IaaS was asked to terminate an instance it will stop the relevant thread - */ -public class MockIaasService { - - private static final Log log = LogFactory.getLog(MockIaasService.class); - - private static final ExecutorService mockMemberExecutorService = - StratosThreadPool.getExecutorService("MOCK_MEMBER_EXECUTOR_SERVICE", MockConstants.MAX_MOCK_MEMBER_COUNT); - private static final String MOCK_IAAS_MEMBERS = "/cloud.controller/mock/iaas/members"; - private static volatile MockIaasService instance; - - private MockPartitionValidator partitionValidator; - // Map<ServiceName, Map<MemberId,MockMember>> - private Map<String, Map<String, MockMember>> serviceNameToMockMemberMap; - - private MockIaasService() { - super(); - partitionValidator = new MockPartitionValidator(); - try { - serviceNameToMockMemberMap = readFromRegistry(); - } catch (RegistryException e) { - String message = "Could not read service name -> mock member map from registry"; - log.error(message, e); - throw new RuntimeException(message, e); - } - if(serviceNameToMockMemberMap == null) { - // No members found in registry, create a new map - serviceNameToMockMemberMap = new ConcurrentHashMap<String, Map<String, MockMember>>(); - } - } - - public static MockIaasService getInstance() { - if (instance == null) { - synchronized (MockIaasService.class) { - if (instance == null) { - if(!MockIaasConfig.getInstance().isEnabled()) { - throw new RuntimeException("Mock IaaS is not enabled"); - } - instance = new MockIaasService(); - } - } - } - return instance; - } - - /** - * Start mock members - */ - public void startMockMembers() { - if(serviceNameToMockMemberMap != null) { - for(Map.Entry<String, Map<String, MockMember>> serviceNameEntry : serviceNameToMockMemberMap.entrySet()) { - // Start mock members - for(Map.Entry<String, MockMember> memberEntry : serviceNameEntry.getValue().entrySet()) { - mockMemberExecutorService.submit(memberEntry.getValue()); - } - - // Schedule statistics updater tasks for service - if(serviceNameEntry.getValue().entrySet().size() > 0) { - MockHealthStatisticsGenerator.getInstance().scheduleStatisticsUpdaterTasks(serviceNameEntry.getKey()); - } - } - } - } - - public MemberContext createInstance(MemberContext memberContext) { - synchronized (MockIaasService.class) { - // Create mock member instance - MockMemberContext mockMemberContext = new MockMemberContext( - memberContext.getApplicationId(), memberContext.getCartridgeType(), - memberContext.getClusterId(), memberContext.getMemberId(), memberContext.getInstanceId(), - memberContext.getClusterInstanceId(), memberContext.getNetworkPartitionId(), - memberContext.getPartition().getId()); - - MockMember mockMember = new MockMember(mockMemberContext); - addMemberToMap(mockMember); - mockMemberExecutorService.submit(mockMember); - - // Generate instance id - memberContext.setInstanceId(UUID.randomUUID().toString()); - - // Persist changes - persistInRegistry(); - - String serviceName = mockMemberContext.getServiceName(); - MockHealthStatisticsGenerator.getInstance().scheduleStatisticsUpdaterTasks(serviceName); - - return memberContext; - } - } - - private void addMemberToMap(MockMember mockMember) { - String serviceName = mockMember.getMockMemberContext().getServiceName(); - Map<String, MockMember> memberMap = serviceNameToMockMemberMap.get(serviceName); - if(memberMap == null) { - memberMap = new ConcurrentHashMap<String, MockMember>(); - serviceNameToMockMemberMap.put(serviceName, memberMap); - } - memberMap.put(mockMember.getMockMemberContext().getMemberId(), mockMember); - } - - private void persistInRegistry() { - try { - RegistryManager.getInstance().persist(MOCK_IAAS_MEMBERS, - (ConcurrentHashMap<String, Map<String, MockMember>>)serviceNameToMockMemberMap); - } catch (RegistryException e) { - log.error("Could not persist mock iaas members in registry", e); - } - } - - private ConcurrentHashMap<String, Map<String, MockMember>> readFromRegistry() throws RegistryException { - return (ConcurrentHashMap<String, Map<String, MockMember>>) - RegistryManager.getInstance().read(MOCK_IAAS_MEMBERS); - } - - public void allocateIpAddress(String clusterId, MemberContext memberContext, Partition partition) { - // Allocate mock ip addresses - memberContext.setDefaultPrivateIP(MockIPAddressPool.getInstance().getNextPrivateIpAddress()); - memberContext.setDefaultPublicIP(MockIPAddressPool.getInstance().getNextPublicIpAddress()); - } - - public void releaseAddress(String ip) { - - } - - public boolean isValidRegion(String region) throws InvalidRegionException { - return true; - } - - public boolean isValidZone(String region, String zone) throws InvalidZoneException, InvalidRegionException { - return true; - } - - public boolean isValidHost(String zone, String host) throws InvalidHostException { - return true; - } - - public PartitionValidator getPartitionValidator() { - return partitionValidator; - } - - public String createVolume(int sizeGB, String snapshotId) { - return null; - } - - public String attachVolume(String instanceId, String volumeId, String deviceName) { - return null; - } - - public void detachVolume(String instanceId, String volumeId) { - - } - - public void deleteVolume(String volumeId) { - - } - - public String getIaasDevice(String device) { - return null; - } - - public void setDynamicPayload(byte[] payload) { - - } - - public void terminateInstance(MemberContext memberContext) throws InvalidCartridgeTypeException, InvalidMemberException { - synchronized (MockIaasService.class) { - String serviceName = memberContext.getCartridgeType(); - Map<String, MockMember> memberMap = serviceNameToMockMemberMap.get(serviceName); - if(memberMap != null) { - MockMember mockMember = memberMap.get(memberContext.getMemberId()); - if(mockMember != null) { - if (mockMember != null) { - mockMember.terminate(); - memberMap.remove(memberContext.getMemberId()); - } - - if (memberMap.size() == 0) { - MockHealthStatisticsGenerator.getInstance().stopStatisticsUpdaterTasks(serviceName); - } - } - } - } - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockMember.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockMember.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockMember.java deleted file mode 100644 index 529c590..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockMember.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.stratos.cloud.controller.iaases.mock.service; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.iaases.mock.service.statistics.publisher.MockHealthStatisticsNotifier; -import org.apache.stratos.common.threading.StratosThreadPool; -import org.apache.stratos.messaging.event.Event; -import org.apache.stratos.messaging.event.instance.notifier.InstanceCleanupClusterEvent; -import org.apache.stratos.messaging.event.instance.notifier.InstanceCleanupMemberEvent; -import org.apache.stratos.messaging.listener.instance.notifier.InstanceCleanupClusterEventListener; -import org.apache.stratos.messaging.listener.instance.notifier.InstanceCleanupMemberEventListener; -import org.apache.stratos.messaging.message.receiver.instance.notifier.InstanceNotifierEventReceiver; - -import java.io.Serializable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - -/** - * Mock member definition. - */ -public class MockMember implements Runnable, Serializable { - - private static final Log log = LogFactory.getLog(MockMember.class); - private static final ExecutorService instanceNotifierExecutorService = - StratosThreadPool.getExecutorService("MOCK_MEMBER_INSTANCE_NOTIFIER_EXECUTOR_SERVICE", 20); - private static final ScheduledExecutorService healthStatNotifierExecutorService = - StratosThreadPool.getScheduledExecutorService("MOCK_MEMBER_HEALTH_STAT_NOTIFIER_EXECUTOR_SERVICE", 20); - private static final int HEALTH_STAT_INTERVAL = 15; // 15 seconds - - private final MockMemberContext mockMemberContext; - private boolean terminated; - - public MockMember(MockMemberContext mockMemberContext) { - this.mockMemberContext = mockMemberContext; - } - - @Override - public void run() { - if (log.isInfoEnabled()) { - log.info(String.format("Mock member started: [member-id] %s", mockMemberContext.getMemberId())); - } - - sleep(5000); - MockMemberEventPublisher.publishInstanceStartedEvent(mockMemberContext); - - sleep(5000); - MockMemberEventPublisher.publishInstanceActivatedEvent(mockMemberContext); - - startInstanceNotifierReceiver(); - startHealthStatisticsPublisher(); - - while (!terminated) { - sleep(1000); - } - - if (log.isInfoEnabled()) { - log.info(String.format("Mock member terminated: [member-id] %s", mockMemberContext.getMemberId())); - } - } - - private void startInstanceNotifierReceiver() { - if (log.isDebugEnabled()) { - log.debug("Starting instance notifier event message receiver"); - } - - final InstanceNotifierEventReceiver instanceNotifierEventReceiver = new InstanceNotifierEventReceiver(); - instanceNotifierEventReceiver.addEventListener(new InstanceCleanupClusterEventListener() { - @Override - protected void onEvent(Event event) { - InstanceCleanupClusterEvent instanceCleanupClusterEvent = (InstanceCleanupClusterEvent) event; - if (mockMemberContext.getClusterId().equals(instanceCleanupClusterEvent.getClusterId()) && - mockMemberContext.getClusterInstanceId().equals( - instanceCleanupClusterEvent.getClusterInstanceId())) { - handleMemberTermination(); - } - } - }); - - instanceNotifierEventReceiver.addEventListener(new InstanceCleanupMemberEventListener() { - @Override - protected void onEvent(Event event) { - InstanceCleanupMemberEvent instanceCleanupClusterEvent = (InstanceCleanupMemberEvent) event; - if (mockMemberContext.getMemberId().equals(instanceCleanupClusterEvent.getMemberId())) { - handleMemberTermination(); - } - } - }); - - instanceNotifierExecutorService.submit(new Runnable() { - @Override - public void run() { - instanceNotifierEventReceiver.execute(); - } - }); - - if (log.isDebugEnabled()) { - log.debug("Instance notifier event message receiver started"); - } - } - - private void handleMemberTermination() { - MockMemberEventPublisher.publishMaintenanceModeEvent(mockMemberContext); - sleep(2000); - MockMemberEventPublisher.publishInstanceReadyToShutdownEvent(mockMemberContext); - } - - private void startHealthStatisticsPublisher() { - if (log.isDebugEnabled()) { - log.debug(String.format("Starting health statistics notifier: [member-id] %s", mockMemberContext.getMemberId())); - } - - healthStatNotifierExecutorService.scheduleAtFixedRate(new MockHealthStatisticsNotifier(mockMemberContext), - 0, HEALTH_STAT_INTERVAL, TimeUnit.SECONDS); - - if (log.isDebugEnabled()) { - log.debug(String.format("Health statistics notifier started: [member-id] %s", mockMemberContext.getMemberId())); - } - } - - private void sleep(long time) { - try { - Thread.sleep(time); - } catch (InterruptedException ignore) { - terminate(); - } - } - - public MockMemberContext getMockMemberContext() { - return mockMemberContext; - } - - public void terminate() { - terminated = true; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockMemberContext.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockMemberContext.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockMemberContext.java deleted file mode 100644 index f045746..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockMemberContext.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.stratos.cloud.controller.iaases.mock.service; - -import java.io.Serializable; - -/** - * Mock member context. - */ -public class MockMemberContext implements Serializable { - - private final String applicationId; - private final String serviceName; - private final String clusterId; - private final String memberId; - private final String instanceId; - private final String clusterInstanceId; - private final String networkPartitionId; - private final String partitionId; - - public MockMemberContext(String applicationId, String serviceName, String clusterId, String memberId, String instanceId, - String clusterInstanceId, String networkPartitionId, String partitionId) { - this.applicationId = applicationId; - this.serviceName = serviceName; - this.clusterId = clusterId; - this.memberId = memberId; - this.instanceId = instanceId; - this.clusterInstanceId = clusterInstanceId; - this.networkPartitionId = networkPartitionId; - this.partitionId = partitionId; - } - - public String getServiceName() { - return serviceName; - } - - public String getClusterId() { - return clusterId; - } - - public String getMemberId() { - return memberId; - } - - public String getInstanceId() { - return instanceId; - } - - public String getClusterInstanceId() { - return clusterInstanceId; - } - - public String getNetworkPartitionId() { - return networkPartitionId; - } - - public String getPartitionId() { - return partitionId; - } - - public String getApplicationId() { - return applicationId; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockMemberEventPublisher.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockMemberEventPublisher.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockMemberEventPublisher.java deleted file mode 100644 index 50e6e77..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/MockMemberEventPublisher.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.stratos.cloud.controller.iaases.mock.service; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.messaging.broker.publish.EventPublisher; -import org.apache.stratos.messaging.broker.publish.EventPublisherPool; -import org.apache.stratos.messaging.event.instance.status.InstanceActivatedEvent; -import org.apache.stratos.messaging.event.instance.status.InstanceMaintenanceModeEvent; -import org.apache.stratos.messaging.event.instance.status.InstanceReadyToShutdownEvent; -import org.apache.stratos.messaging.event.instance.status.InstanceStartedEvent; -import org.apache.stratos.messaging.util.Util; - -/** - * Mock member event publisher. - */ -public class MockMemberEventPublisher { - - private static final Log log = LogFactory.getLog(MockMemberEventPublisher.class); - - public static void publishInstanceStartedEvent(MockMemberContext mockMemberContext) { - if (log.isInfoEnabled()) { - log.info("Publishing instance started event"); - } - InstanceStartedEvent event = new InstanceStartedEvent( - mockMemberContext.getApplicationId(), - mockMemberContext.getServiceName(), - mockMemberContext.getClusterId(), - mockMemberContext.getMemberId(), - mockMemberContext.getClusterInstanceId(), - mockMemberContext.getNetworkPartitionId(), - mockMemberContext.getPartitionId()); - String topic = Util.getMessageTopicName(event); - EventPublisher eventPublisher = EventPublisherPool - .getPublisher(topic); - eventPublisher.publish(event); - if (log.isInfoEnabled()) { - log.info("Instance started event published"); - } - } - - public static void publishInstanceActivatedEvent(MockMemberContext mockMemberContext) { - if (log.isInfoEnabled()) { - log.info("Publishing instance activated event"); - } - InstanceActivatedEvent event = new InstanceActivatedEvent( - mockMemberContext.getServiceName(), - mockMemberContext.getClusterId(), - mockMemberContext.getMemberId(), - mockMemberContext.getInstanceId(), - mockMemberContext.getClusterInstanceId(), - mockMemberContext.getNetworkPartitionId(), - mockMemberContext.getPartitionId()); - - // Event publisher connection will - String topic = Util.getMessageTopicName(event); - EventPublisher eventPublisher = EventPublisherPool.getPublisher(topic); - eventPublisher.publish(event); - if (log.isInfoEnabled()) { - log.info("Instance activated event published"); - } - } - - public static void publishInstanceReadyToShutdownEvent(MockMemberContext mockMemberContext) { - if (log.isInfoEnabled()) { - log.info(String.format("Publishing instance ready to shutdown event: [member-id] %s", - mockMemberContext.getMemberId())); - } - InstanceReadyToShutdownEvent event = new InstanceReadyToShutdownEvent( - mockMemberContext.getServiceName(), - mockMemberContext.getClusterId(), - mockMemberContext.getMemberId(), - mockMemberContext.getClusterInstanceId(), - mockMemberContext.getNetworkPartitionId(), - mockMemberContext.getPartitionId()); - String topic = Util.getMessageTopicName(event); - EventPublisher eventPublisher = EventPublisherPool - .getPublisher(topic); - eventPublisher.publish(event); - if (log.isInfoEnabled()) { - log.info(String.format("Instance ready to shutDown event published: [member-id] %s", - mockMemberContext.getMemberId())); - } - } - - public static void publishMaintenanceModeEvent(MockMemberContext mockMemberContext) { - if (log.isInfoEnabled()) { - log.info(String.format("Publishing instance maintenance mode event: [member-id] %s", - mockMemberContext.getMemberId())); - } - InstanceMaintenanceModeEvent event = new InstanceMaintenanceModeEvent( - mockMemberContext.getServiceName(), - mockMemberContext.getClusterId(), - mockMemberContext.getMemberId(), - mockMemberContext.getClusterInstanceId(), - mockMemberContext.getNetworkPartitionId(), - mockMemberContext.getPartitionId()); - String topic = Util.getMessageTopicName(event); - EventPublisher eventPublisher = EventPublisherPool.getPublisher(topic); - eventPublisher.publish(event); - - if (log.isInfoEnabled()) { - log.info(String.format("Instance Maintenance mode event published: [member-id] %s", - mockMemberContext.getMemberId())); - } - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/config/MockHealthStatisticsConfig.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/config/MockHealthStatisticsConfig.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/config/MockHealthStatisticsConfig.java deleted file mode 100644 index 7abb118..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/config/MockHealthStatisticsConfig.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.stratos.cloud.controller.iaases.mock.service.config; - -import org.apache.stratos.cloud.controller.iaases.mock.service.statistics.generator.MockHealthStatisticsPattern; - -import java.util.ArrayList; -import java.util.List; - -/** - * Mock health statistics configuration. - */ -public class MockHealthStatisticsConfig { - List<MockHealthStatisticsPattern> statisticsPatternList; - - public MockHealthStatisticsConfig() { - statisticsPatternList = new ArrayList<MockHealthStatisticsPattern>(); - } - - public void addStatisticsPattern(MockHealthStatisticsPattern statisticsPattern) { - statisticsPatternList.add(statisticsPattern); - } - - public List<MockHealthStatisticsPattern> getStatisticsPatterns() { - return statisticsPatternList; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/config/MockIaasConfig.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/config/MockIaasConfig.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/config/MockIaasConfig.java deleted file mode 100644 index ba97c49..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/config/MockIaasConfig.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.stratos.cloud.controller.iaases.mock.service.config; - -/** - * Mock iaas configuration. - */ -public class MockIaasConfig { - private static final String MOCK_IAAS_CONFIG_FILE_NAME = "mock-iaas.xml"; - private static final String CARBON_HOME = "carbon.home"; - private static final String REPOSITORY_CONF = "/repository/conf/"; - - private static volatile MockIaasConfig instance; - - private boolean enabled; - private MockHealthStatisticsConfig mockHealthStatisticsConfig; - - public static MockIaasConfig getInstance() { - if (instance == null) { - synchronized (MockIaasConfig.class) { - if (instance == null) { - String confPath = System.getProperty(CARBON_HOME) + REPOSITORY_CONF; - instance = MockIaasConfigParser.parse(confPath + MOCK_IAAS_CONFIG_FILE_NAME); - } - } - } - return instance; - } - - MockIaasConfig() { - } - - void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - void setMockHealthStatisticsConfig(MockHealthStatisticsConfig mockHealthStatisticsConfig) { - this.mockHealthStatisticsConfig = mockHealthStatisticsConfig; - } - - public MockHealthStatisticsConfig getMockHealthStatisticsConfig() { - return mockHealthStatisticsConfig; - } - - public boolean isEnabled() { - return enabled; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/config/MockIaasConfigParser.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/config/MockIaasConfigParser.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/config/MockIaasConfigParser.java deleted file mode 100644 index 5faf92a..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/config/MockIaasConfigParser.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.stratos.cloud.controller.iaases.mock.service.config; - -import org.apache.axiom.om.OMAttribute; -import org.apache.axiom.om.OMElement; -import org.apache.commons.lang3.StringUtils; -import org.apache.stratos.cloud.controller.iaases.mock.service.MockAutoscalingFactor; -import org.apache.stratos.cloud.controller.iaases.mock.service.statistics.StatisticsPatternMode; -import org.apache.stratos.cloud.controller.iaases.mock.service.statistics.generator.MockHealthStatisticsPattern; -import org.apache.stratos.cloud.controller.util.AxiomXpathParserUtil; - -import javax.xml.namespace.QName; -import java.io.File; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -/** - * Mock health statistics configuration parser. - */ -public class MockIaasConfigParser { - private static final QName ENABLED_ATTRIBUTE = new QName("enabled"); - private static final QName TYPE_ATTRIBUTE = new QName("type"); - private static final QName FACTOR_ATTRIBUTE = new QName("factor"); - private static final QName MODE_ATTRIBUTE = new QName("mode"); - private static final String HEALTH_STATISTICS_ELEMENT = "health-statistics"; - private static final String SAMPLE_VALUES_ELEMENT = "sampleValues"; - private static final String SAMPLE_DURATION_ELEMENT = "sampleDuration"; - - /** - * Parse mock iaas configuration and return configuration object. - * @param filePath - * @return - */ - public static MockIaasConfig parse(String filePath) { - try { - MockIaasConfig mockIaasConfig = new MockIaasConfig(); - MockHealthStatisticsConfig mockHealthStatisticsConfig = new MockHealthStatisticsConfig(); - mockIaasConfig.setMockHealthStatisticsConfig(mockHealthStatisticsConfig); - - OMElement document = AxiomXpathParserUtil.parse(new File(filePath)); - String enabledStr = document.getAttributeValue(ENABLED_ATTRIBUTE); - if(StringUtils.isEmpty(enabledStr)) { - throw new RuntimeException("Enabled attribute not found in mock-iaas element"); - } - mockIaasConfig.setEnabled(Boolean.parseBoolean(enabledStr)); - - Iterator statisticsIterator = document.getChildElements(); - - while (statisticsIterator.hasNext()) { - OMElement statisticsElement = (OMElement) statisticsIterator.next(); - - if (HEALTH_STATISTICS_ELEMENT.equals(statisticsElement.getQName().getLocalPart())) { - Iterator cartridgeIterator = statisticsElement.getChildElements(); - - while (cartridgeIterator.hasNext()) { - OMElement cartridgeElement = (OMElement) cartridgeIterator.next(); - OMAttribute typeAttribute = cartridgeElement.getAttribute(TYPE_ATTRIBUTE); - if (typeAttribute == null) { - throw new RuntimeException("Type attribute not found in cartridge element"); - } - String cartridgeType = typeAttribute.getAttributeValue(); - Iterator patternIterator = cartridgeElement.getChildElements(); - - while (patternIterator.hasNext()) { - OMElement patternElement = (OMElement) patternIterator.next(); - - OMAttribute factorAttribute = patternElement.getAttribute(FACTOR_ATTRIBUTE); - if (factorAttribute == null) { - throw new RuntimeException("Factor attribute not found in pattern element: " + - "[cartridge-type] " + cartridgeType); - } - String factorStr = factorAttribute.getAttributeValue(); - MockAutoscalingFactor autoscalingFactor = convertAutoscalingFactor(factorStr); - - OMAttribute modeAttribute = patternElement.getAttribute(MODE_ATTRIBUTE); - if(modeAttribute == null) { - throw new RuntimeException("Mode attribute not found in pattern element: " + - "[cartridge-type] " + cartridgeType); - } - String modeStr = modeAttribute.getAttributeValue(); - StatisticsPatternMode mode = convertMode(modeStr); - - String sampleValuesStr = null; - String sampleDurationStr = null; - Iterator patternChildIterator = patternElement.getChildElements(); - - while (patternChildIterator.hasNext()) { - OMElement patternChild = (OMElement) patternChildIterator.next(); - if (SAMPLE_VALUES_ELEMENT.equals(patternChild.getQName().getLocalPart())) { - sampleValuesStr = patternChild.getText(); - } else if (SAMPLE_DURATION_ELEMENT.equals(patternChild.getQName().getLocalPart())) { - sampleDurationStr = patternChild.getText(); - } - } - - if (sampleValuesStr == null) { - throw new RuntimeException("Sample values not found in pattern [factor] " + factorStr); - } - if (sampleDurationStr == null) { - throw new RuntimeException("Sample duration not found in pattern [factor] " + factorStr); - } - - String[] sampleValuesArray = sampleValuesStr.split(","); - List<Integer> sampleValues = convertStringArrayToIntegerList(sampleValuesArray); - int sampleDuration = Integer.parseInt(sampleDurationStr); - - MockHealthStatisticsPattern mockHealthStatisticsPattern = new MockHealthStatisticsPattern - (cartridgeType, autoscalingFactor, mode, sampleValues, sampleDuration); - mockHealthStatisticsConfig.addStatisticsPattern(mockHealthStatisticsPattern); - } - } - } - } - return mockIaasConfig; - } catch (Exception e) { - throw new RuntimeException("Could not parse mock health statistics configuration", e); - } - } - - private static StatisticsPatternMode convertMode(String modeStr) { - if("loop".equals(modeStr)) { - return StatisticsPatternMode.Loop; - } - else if("continue".equals(modeStr)) { - return StatisticsPatternMode.Continue; - } - else if("stop".equals(modeStr)) { - return StatisticsPatternMode.Stop; - } - throw new RuntimeException("An unknown statistics pattern mode found: " + modeStr); - } - - private static MockAutoscalingFactor convertAutoscalingFactor(String factorStr) { - if("memory-consumption".equals(factorStr)) { - return MockAutoscalingFactor.MemoryConsumption; - } - else if("load-average".equals(factorStr)) { - return MockAutoscalingFactor.LoadAverage; - } - else if("request-in-flight".equals(factorStr)) { - return MockAutoscalingFactor.RequestInFlight; - } - throw new RuntimeException("An unknown autoscaling factor found: " + factorStr); - } - - private static List<Integer> convertStringArrayToIntegerList(String[] stringArray) { - List<Integer> integerList = new ArrayList<Integer>(); - for (String value : stringArray) { - integerList.add(Integer.parseInt(value)); - } - return integerList; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/e16acd17/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/exceptions/ContinueLastSampleValueException.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/exceptions/ContinueLastSampleValueException.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/exceptions/ContinueLastSampleValueException.java deleted file mode 100644 index ccb8c03..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/service/exceptions/ContinueLastSampleValueException.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.stratos.cloud.controller.iaases.mock.service.exceptions; - -/** - * Thrown when statistics pattern mode is set to continue and pattern reaches - * the last sample value. - */ -public class ContinueLastSampleValueException extends Exception { - private int lastSampleValue; - - public ContinueLastSampleValueException(int lastSampleValue) { - this.lastSampleValue = lastSampleValue; - } - - public int getLastSampleValue() { - return lastSampleValue; - } -}
