Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos into lb_logic_refactoring
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/eaedb07c Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/eaedb07c Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/eaedb07c Branch: refs/heads/master Commit: eaedb07ca0dec60fc22e86bd450a8817be8d83d8 Parents: 459ebb4 d2be6fe Author: Isuru <[email protected]> Authored: Sat Feb 15 13:15:12 2014 +0530 Committer: Isuru <[email protected]> Committed: Sat Feb 15 13:15:12 2014 +0530 ---------------------------------------------------------------------- .gitignore | 3 + .../autoscaler/NetworkPartitionLbHolder.java | 41 +- .../stratos/autoscaler/PartitionContext.java | 17 + .../topology/AutoscalerTopologyReceiver.java | 51 +- .../autoscaler/partition/PartitionManager.java | 14 + .../stratos/cartridge/agent/CartridgeAgent.java | 72 +- .../apache/stratos/cartridge/agent/Main.java | 1 + .../config/CartridgeAgentConfiguration.java | 15 + .../agent/data/publisher/DataContext.java | 52 ++ .../agent/data/publisher/DataPublisher.java | 97 ++ .../publisher/DataPublisherConfiguration.java | 161 ++++ .../exception/DataPublisherException.java | 31 + .../agent/data/publisher/log/Constants.java | 29 + .../publisher/log/FileBasedLogPublisher.java | 109 +++ .../agent/data/publisher/log/LogPublisher.java | 49 + .../data/publisher/log/LogPublisherManager.java | 105 +++ .../publisher/HealthStatisticsNotifier.java | 2 +- .../publisher/HealthStatisticsReader.java | 3 +- .../agent/util/CartridgeAgentConstants.java | 3 + .../agent/util/CartridgeAgentUtils.java | 12 +- .../java/org/apache/stratos/cli/CliTool.java | 2 +- .../stratos/cli/CommandLineApplication.java | 32 +- .../apache/stratos/cli/GenericRestClient.java | 4 +- .../java/org/apache/stratos/cli/RestClient.java | 38 +- .../stratos/cli/RestCommandLineService.java | 624 ++++++++++--- .../apache/stratos/cli/StratosApplication.java | 40 +- .../stratos/cli/beans/cartridge/Cartridge.java | 18 + .../beans/cartridge/ServiceDefinitionBean.java | 86 ++ .../cli/commands/ActivateTenantCommand.java | 70 ++ .../cli/commands/DeactivateTenantCommand.java | 70 ++ .../cli/commands/DeleteTenantCommand.java | 70 ++ .../DeployServiceDeploymentCommand.java | 139 +++ .../DescribeAutoScalingPolicyCommand.java | 2 +- .../stratos/cli/commands/ExitCommand.java | 7 +- .../cli/commands/ListDeployServiceCommand.java | 65 ++ .../UndeployCartridgeDefinitionCommand.java | 70 ++ .../UndeployServiceDefinitionCommand.java | 70 ++ .../apache/stratos/cli/utils/CliConstants.java | 36 +- .../org.apache.stratos.cloud.controller/pom.xml | 3 - .../axiom/parser/CartridgeConfigParser.java | 384 -------- .../parser/CloudControllerConfigParser.java | 2 +- .../cloud/controller/iaases/AWSEC2Iaas.java | 114 +++ .../controller/iaases/OpenstackNovaIaas.java | 134 ++- .../cloud/controller/iaases/VCloudIaas.java | 24 + .../impl/CloudControllerServiceImpl.java | 104 ++- .../cloud/controller/interfaces/Iaas.java | 29 + .../jcloud/ComputeServiceBuilderUtil.java | 5 + .../cloud/controller/pojo/CartridgeConfig.java | 10 + .../cloud/controller/pojo/CartridgeInfo.java | 28 +- .../cloud/controller/pojo/ClusterContext.java | 53 +- .../cloud/controller/pojo/IaasProvider.java | 9 + .../cloud/controller/pojo/MemberContext.java | 10 + .../controller/pojo/PersistanceMapping.java | 27 +- .../runtime/FasterLookUpDataHolder.java | 223 +---- .../controller/topology/TopologyBuilder.java | 6 +- .../topology/TopologyEventPublisher.java | 4 +- .../controller/util/CloudControllerUtil.java | 57 +- .../validate/AWSEC2PartitionValidator.java | 2 +- .../OpenstackNovaPartitionValidator.java | 2 +- .../axiom/FasterLookupDataHolderTest.java | 92 ++ .../balancer/algorithm/AlgorithmContext.java | 10 +- .../balancer/cache/AlgorithmContextCache.java | 45 + .../load/balancer/cache/LoadBalancerCache.java | 130 +++ .../stratos/load/balancer/util/Constants.java | 3 + .../balancer/test/RoundRobinAlgorithmTest.java | 70 -- .../console/cartridge_info.jag | 9 + .../console/cartridges.jag | 4 +- .../console/config/console.js | 23 +- .../console/config/console.json | 8 +- .../console/configure_stratos.jag | 20 +- .../console/configure_stratos_wizard.jag | 16 +- .../controllers/cartridgeDefintionSubmit.jag | 7 +- .../controllers/cartridgeSubscribeSubmit.jag | 10 + .../controllers/cartridgeUnsubscribeSubmit.jag | 11 + .../console/controllers/login.jag | 2 +- .../console/controllers/loginSubmit.jag | 3 +- .../console/controllers/logout.jag | 5 +- .../console/controllers/router.jag | 27 +- .../console/controllers/wizardSubmit.jag | 33 +- .../console/index.jag | 1 - .../console/lbs.jag | 20 - .../console/modules/pinch.min.js | 4 + .../console/subscribe_cartridge.jag | 6 +- .../console/themes/theme1/pages/index.hbs | 19 + .../themes/theme1/partials/cartridge_info.hbs | 37 + .../themes/theme1/partials/cartridges.hbs | 25 +- .../partials/configure_stratos_wizard.hbs | 779 ++++++++-------- .../console/themes/theme1/partials/header.hbs | 242 +++-- .../console/themes/theme1/partials/lbs.hbs | 88 -- .../themes/theme1/partials/mycartridges.hbs | 25 +- .../theme1/partials/subscribe_cartridge.hbs | 101 ++- .../themes/theme1/partials/tenant_new.hbs | 4 +- .../theme1/renderers/cartridge_deployments.js | 45 - .../themes/theme1/renderers/cartridge_info.js | 42 + .../themes/theme1/renderers/cartridges.js | 11 +- .../theme1/renderers/configure_stratos.js | 54 +- .../renderers/configure_stratos_wizard.js | 55 +- .../console/themes/theme1/renderers/index.js | 18 +- .../console/themes/theme1/renderers/lbs.js | 47 - .../theme1/renderers/mt_service_deployments.js | 48 - .../theme1/renderers/partition_deployments.js | 46 - .../theme1/renderers/policy_deployments.js | 46 - .../theme1/renderers/subscribe_cartridge.js | 5 +- .../console/themes/theme1/theme.js | 7 + .../console/themes/theme1/ui/css/main.css | 66 +- .../themes/theme1/ui/custom-fonts/style.css | 25 +- .../console/themes/theme1/ui/js/mycartridges.js | 12 + .../console/themes/theme1/ui/js/popup.js | 80 ++ .../console/themes/theme1/ui/js/wizard.js | 32 +- .../console/util/utility.jag | 85 +- .../client/CloudControllerServiceClient.java | 6 +- .../DataCartridgeSubscriptionConnector.java | 34 +- .../stratos/manager/deploy/service/Service.java | 7 +- .../service/ServiceDeploymentManager.java | 24 + .../apache/stratos/manager/dto/Cartridge.java | 76 +- .../internal/ADCManagementServerComponent.java | 2 - .../manager/lookup/LookupDataHolder.java | 21 + .../manager/lookup/SubscriptionContext.java | 2 + .../manager/CartridgeSubscriptionManager.java | 123 ++- .../manager/persistence/PersistenceManager.java | 2 + .../RegistryBasedPersistenceManager.java | 95 ++ .../DataInsertionAndRetrievalManager.java | 20 + .../service/ApplicationManagementService.java | 677 -------------- .../InstanceInformationManagementService.java | 58 -- .../service/RepoNotificationService.java | 128 --- .../manager/service/RepositoryInfoBean.java | 3 +- .../subscription/CartridgeSubscription.java | 97 +- .../subscription/DataCartridgeSubscription.java | 6 +- .../manager/subscription/SubscriptionData.java | 172 ++++ .../SubscriptionSingleTenantBehaviour.java | 12 +- .../utils/CartridgeSubscriptionUtils.java | 9 +- .../model/TopologyClusterInformationModel.java | 2 +- .../utils/ApplicationManagementUtil.java | 860 +----------------- .../manager/utils/CartridgeConstants.java | 23 - .../manager/utils/PersistenceManager.java | 892 ------------------- .../manager/utils/RepositoryFactory.java | 131 --- .../stratos/manager/utils/StratosDBUtils.java | 213 ----- .../src/main/resources/META-INF/services.xml | 57 +- .../messaging/domain/topology/Service.java | 4 +- .../event/topology/ClusterRemovedEvent.java | 8 +- .../stratos/messaging/util/Constants.java | 11 +- .../rest/endpoint/bean/CartridgeInfoBean.java | 36 + .../stratos/rest/endpoint/bean/Error.java | 25 + .../endpoint/bean/StratosAdminResponse.java | 36 + .../definition/CartridgeDefinitionBean.java | 2 + .../definition/PersistanceMappingBean.java | 4 +- .../bean/util/converter/PojoConverter.java | 30 +- .../stratos/rest/endpoint/mock/MockContext.java | 43 + .../rest/endpoint/mock/StratosTestAdmin.java | 56 +- .../rest/endpoint/services/ServiceUtils.java | 438 ++++++--- .../rest/endpoint/services/StratosAdmin.java | 328 +++++-- .../main/webapp/stratos/WEB-INF/cxf-servlet.xml | 2 +- .../resources/conf/cartridge-config.properties | 64 -- .../src/main/resources/p2.inf | 1 - .../distribution/src/main/conf/autoscaler.xml | 3 + .../distribution/src/main/bin/stratos.sh | 12 +- .../distribution/src/main/conf/axis2.xml | 125 ++- .../load-balancer/modules/integration/pom.xml | 19 +- .../tests/AlgorithmContextCacheTest.java | 55 ++ .../tests/LoadBalancerTestServerManager.java | 69 ++ .../tests/RoundRobinAlgorithmTest.java | 70 ++ .../tests/LoadBalancerTestServerManager.java | 53 -- .../src/test/resources/instrumentation.txt | 2 +- .../src/test/resources/loadbalancer.conf | 142 +++ .../integration/src/test/resources/testng.xml | 31 + .../src/main/conf/cartridge-config.properties | 42 +- .../main/resources/CloudControllerService.wsdl | 32 +- .../puppet/etc/puppet/files/cartridge-agent.sh | 13 + tools/puppet/manifests/classes/lb_cartridge.pp | 12 +- tools/puppet/manifests/classes/mysql.pp | 4 +- tools/puppet/manifests/classes/php_cartridge.pp | 12 +- tools/puppet/manifests/nodes.pp | 104 ++- tools/stratos-installer/README.txt | 17 +- tools/stratos-installer/conf/setup.conf | 52 +- .../cc/repository/conf/cloud-controller.xml | 1 - .../config/cep/repository/conf/jndi.properties | 16 +- .../repository/conf/cartridge-config.properties | 27 - tools/stratos-installer/ec2.sh | 12 - tools/stratos-installer/openstack.sh | 9 - tools/stratos-installer/setup.sh | 80 +- 180 files changed, 6295 insertions(+), 5702 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/eaedb07c/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java ---------------------------------------------------------------------- diff --cc components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java index e80b921,6ea9cb2..d71e107 --- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java +++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java @@@ -201,233 -167,13 +201,240 @@@ public class CartridgeSubscriptionUtil public static boolean isAliasTaken (int tenantId, String alias) { DataInsertionAndRetrievalManager dataInsertionAndRetrievalManager = new DataInsertionAndRetrievalManager(); - return (dataInsertionAndRetrievalManager.getCartridgeSubscription(tenantId, alias) == null) ? false : true; + // return (dataInsertionAndRetrievalManager.getCartridgeSubscription(tenantId, alias) == null) ? false : true; + // fixing STRATOS-427, making the alias globally unique + return (dataInsertionAndRetrievalManager.getCartridgeSubscriptionForAlias(alias) == null) ? false : true; + } + + public static String limitLengthOfString (String source, int length) { + + return source.substring(0, length); } + + public static LBDataContext getLoadBalancerDataContext (SubscriptionData subscriptionData, LoadbalancerConfig lbConfig) throws UnregisteredCartridgeException, ADCException { + + String lbCartridgeType = lbConfig.getType(); + + LBDataContext lbDataCtxt = new LBDataContext(); + // set tenant Id + lbDataCtxt.setTenantId(subscriptionData.getTenantId()); + + Properties lbReferenceProperties = lbConfig.getProperties(); + + Property lbRefProperty = new Property(); + lbRefProperty.setName(org.apache.stratos.messaging.util.Constants.LOAD_BALANCER_REF); + + for (org.apache.stratos.cloud.controller.pojo.Property prop : lbReferenceProperties.getProperties()) { + + String name = prop.getName(); + String value = prop.getValue(); + + // TODO make following a chain of responsibility pattern + if (Constants.NO_LOAD_BALANCER.equals(name)) { + + if ("true".equals(value)) { + if (log.isDebugEnabled()) { + log.debug("This cartridge does not require a load balancer. " + + "[Type] " + subscriptionData.getCartridgeType()); + } + lbRefProperty.setValue(name); + lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty); + break; + } + } else if (Constants.EXISTING_LOAD_BALANCERS.equals(name)) { + + String clusterIdsVal = value; + if (log.isDebugEnabled()) { + log.debug("This cartridge refers to existing load balancers. " + "[Type] " + + subscriptionData.getCartridgeType() + "[Referenced Cluster Ids] " + clusterIdsVal); + } + + String[] clusterIds = clusterIdsVal.split(","); + + for (String clusterId : clusterIds) { + try { + AutoscalerServiceClient.getServiceClient().checkLBExistenceAgainstPolicy(clusterId, subscriptionData.getDeploymentPolicyName()); + } catch (Exception ex) { + // we don't need to throw the error here. + log.error(ex.getMessage(), ex); + } + } + + lbRefProperty.setValue(name); + lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty); + break; + + } else if (Constants.DEFAULT_LOAD_BALANCER.equals(name)) { + + if ("true".equals(value)) { + + lbRefProperty.setValue(name); + + CartridgeInfo lbCartridgeInfo; + + try { + lbCartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(lbCartridgeType); + + } catch (UnregisteredCartridgeException e) { + String message = lbCartridgeType + " is not a valid cartridgeSubscription type"; + log.error(message); + throw e; + + } catch (Exception e) { + String message = "Error getting info for " + lbCartridgeType; + log.error(message, e); + throw new ADCException(message, e); + } + + lbDataCtxt.setLbCartridgeInfo(lbCartridgeInfo); + + if (log.isDebugEnabled()) { + log.debug("This cartridge uses default load balancer. " + "[Type] " + subscriptionData.getCartridgeType()); + } + + try { + // get the valid policies for lb cartridge + DeploymentPolicy[] lbCartridgeDepPolicies = + getAutoscalerServiceClient().getDeploymentPolicies(lbCartridgeType); + // traverse deployment policies of lb cartridge + for (DeploymentPolicy policy : lbCartridgeDepPolicies) { + + // check existence of the subscribed policy + if (subscriptionData.getDeploymentPolicyName().equals(policy.getId())) { + + if (!getAutoscalerServiceClient().checkDefaultLBExistenceAgainstPolicy(subscriptionData.getDeploymentPolicyName())) { + + Properties lbProperties = new Properties(); + + // if LB cartridge definition has properties as well, combine + if (lbCartridgeInfo.getProperties() != null && lbCartridgeInfo.getProperties().length > 0) { + lbProperties.setProperties(combine(lbCartridgeInfo.getProperties(), new Property[]{lbRefProperty})); + + } else { + lbProperties.setProperties(new Property[]{lbRefProperty}); + } + + lbDataCtxt.addLBProperties(lbProperties); + } + } + } + + } catch (Exception ex) { + // we don't need to throw the error here. + log.error(ex.getMessage(), ex); + } + + // set deployment and autoscaling policies + lbDataCtxt.setDeploymentPolicy(subscriptionData.getDeploymentPolicyName()); + lbDataCtxt.setAutoscalePolicy(lbCartridgeInfo.getDefaultAutoscalingPolicy()); + + lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty); + break; + } + + } else if (Constants.SERVICE_AWARE_LOAD_BALANCER.equals(name)) { + + if ("true".equals(value)) { + + lbRefProperty.setValue(name); + + CartridgeInfo lbCartridgeInfo; + + try { + lbCartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(lbCartridgeType); + + } catch (UnregisteredCartridgeException e) { + String message = lbCartridgeType + " is not a valid cartridgeSubscription type"; + log.error(message); + throw e; + + } catch (Exception e) { + String message = "Error getting info for " + lbCartridgeType; + log.error(message, e); + throw new ADCException(message, e); + } + + lbDataCtxt.setLbCartridgeInfo(lbCartridgeInfo); + + // add a property for the service type + Property loadBalancedServiceTypeProperty = new Property(); + loadBalancedServiceTypeProperty.setName(Constants.LOAD_BALANCED_SERVICE_TYPE); + // set the load balanced service type + loadBalancedServiceTypeProperty.setValue(subscriptionData.getCartridgeType()); + + if (log.isDebugEnabled()) { + log.debug("This cartridge uses a service aware load balancer. [Type] " + subscriptionData.getCartridgeType()); + } + + try { + + // get the valid policies for lb cartridge + DeploymentPolicy[] lbCartridgeDepPolicies = getAutoscalerServiceClient().getDeploymentPolicies(lbCartridgeType); + // traverse deployment policies of lb cartridge + for (DeploymentPolicy policy : lbCartridgeDepPolicies) { + // check existence of the subscribed policy + if (subscriptionData.getDeploymentPolicyName().equals(policy.getId())) { + + if (!getAutoscalerServiceClient().checkServiceLBExistenceAgainstPolicy(subscriptionData.getCartridgeType(), + subscriptionData.getDeploymentPolicyName())) { + + Properties lbProperties = new Properties(); + + // if LB cartridge definition has properties as well, combine + if (lbCartridgeInfo.getProperties() != null && lbCartridgeInfo.getProperties().length > 0) { + lbProperties.setProperties(combine(lbCartridgeInfo.getProperties(), new Property[]{lbRefProperty, loadBalancedServiceTypeProperty})); + + } else { + lbProperties.setProperties(new Property[]{lbRefProperty, loadBalancedServiceTypeProperty}); + } + + // set a payload property for load balanced service type + Property payloadProperty = new Property(); + payloadProperty.setName("LOAD_BALANCED_SERVICE_TYPE"); //TODO: refactor hardcoded name + payloadProperty.setValue(subscriptionData.getCartridgeType()); + + lbDataCtxt.addLBProperties(lbProperties); + } + } + } + + } catch (Exception ex) { + // we don't need to throw the error here. + log.error(ex.getMessage(), ex); + } + + // set deployment and autoscaling policies + lbDataCtxt.setDeploymentPolicy(subscriptionData.getDeploymentPolicyName()); + lbDataCtxt.setAutoscalePolicy(lbCartridgeInfo.getDefaultAutoscalingPolicy()); + + lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty); + break; + } + } + } + + return lbDataCtxt; + } + + private static AutoscalerServiceClient getAutoscalerServiceClient () throws ADCException { + + try { + return AutoscalerServiceClient.getServiceClient(); + + } catch (AxisFault axisFault) { + String errorMsg = "Error in getting AutoscalerServiceClient instance"; + log.error(errorMsg, axisFault); + throw new ADCException (errorMsg, axisFault); + } + } + + private static Property[] combine (Property[] propertyArray1, Property[] propertyArray2) { + + int length = propertyArray1.length + propertyArray2.length; + Property[] combinedProperties = new Property[length]; + System.arraycopy(propertyArray1, 0, combinedProperties, 0, propertyArray1.length); + System.arraycopy(propertyArray2, 0, combinedProperties, propertyArray1.length, propertyArray2.length); + + return combinedProperties; + } }
