Updated Branches: refs/heads/autoscale 70bbd8b07 -> 6aa780d63
Enabling aUtoscale VMs to be provisioned in a loadbalancer's network Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/6aa780d6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/6aa780d6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/6aa780d6 Branch: refs/heads/autoscale Commit: 6aa780d637e67685b616636d067534bb3c8b9934 Parents: 70bbd8b Author: Vijay Vekatachalam <[email protected]> Authored: Thu Sep 27 18:05:10 2012 +0530 Committer: Pranav Saxena <[email protected]> Committed: Thu Sep 27 18:05:10 2012 +0530 ---------------------------------------------------------------------- api/src/com/cloud/agent/api/to/LoadBalancerTO.java | 29 ++++--- .../com/cloud/network/lb/LoadBalancingRule.java | 10 ++- .../cloud/network/resource/NetscalerResource.java | 15 ++-- .../com/cloud/network/as/AutoScaleManagerImpl.java | 7 +- .../network/lb/LoadBalancingRulesManagerImpl.java | 64 ++++++++++----- 5 files changed, 81 insertions(+), 44 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6aa780d6/api/src/com/cloud/agent/api/to/LoadBalancerTO.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/agent/api/to/LoadBalancerTO.java b/api/src/com/cloud/agent/api/to/LoadBalancerTO.java index 9a58d9a..be366a1 100644 --- a/api/src/com/cloud/agent/api/to/LoadBalancerTO.java +++ b/api/src/com/cloud/agent/api/to/LoadBalancerTO.java @@ -49,7 +49,7 @@ public class LoadBalancerTO { final static int MAX_STICKINESS_POLICIES = 1; public LoadBalancerTO(String uuid, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, List<LbDestination> destinations) { - if(destinations == null) { // for autoscaleconfig destinations will be null; + if (destinations == null) { // for autoscaleconfig destinations will be null; destinations = new ArrayList<LbDestination>(); } this.uuid = uuid; @@ -185,7 +185,7 @@ public class LoadBalancerTO { return alreadyAdded; } } - public static class CounterTO implements Serializable{ + public static class CounterTO implements Serializable { private final String name; private final String source; private final String value; @@ -209,7 +209,7 @@ public class LoadBalancerTO { } } - public static class ConditionTO implements Serializable{ + public static class ConditionTO implements Serializable { private final long threshold; private final String relationalOperator; private final CounterTO counter; @@ -234,7 +234,7 @@ public class LoadBalancerTO { } } - public static class AutoScalePolicyTO implements Serializable{ + public static class AutoScalePolicyTO implements Serializable { private final long id; private final int duration; private final int quietTime; @@ -276,7 +276,7 @@ public class LoadBalancerTO { } } - public static class AutoScaleVmProfileTO implements Serializable{ + public static class AutoScaleVmProfileTO implements Serializable { private final String zoneId; private final String domainId; private final String serviceOfferingId; @@ -288,9 +288,10 @@ public class LoadBalancerTO { private final String cloudStackApiUrl; private final String autoScaleUserApiKey; private final String autoScaleUserSecretKey; + private final String networkId; - public AutoScaleVmProfileTO(String zoneId, String domainId, String cloudStackApiUrl, String autoScaleUserApiKey, String autoScaleUserSecretKey, String serviceOfferingId, String templateId, - String otherDeployParams, String snmpCommunity, Integer snmpPort, Integer destroyVmGraceperiod) { + public AutoScaleVmProfileTO(String zoneId, String domainId, String cloudStackApiUrl, String autoScaleUserApiKey, String autoScaleUserSecretKey, String serviceOfferingId, + String templateId, String networkId, String otherDeployParams, String snmpCommunity, Integer snmpPort, Integer destroyVmGraceperiod) { this.zoneId = zoneId; this.domainId = domainId; this.serviceOfferingId = serviceOfferingId; @@ -302,6 +303,7 @@ public class LoadBalancerTO { this.cloudStackApiUrl = cloudStackApiUrl; this.autoScaleUserApiKey = autoScaleUserApiKey; this.autoScaleUserSecretKey = autoScaleUserSecretKey; + this.networkId = networkId; } public String getZoneId() { @@ -347,9 +349,13 @@ public class LoadBalancerTO { public String getAutoScaleUserSecretKey() { return autoScaleUserSecretKey; } + + public String getNetworkId() { + return networkId; + } } - public static class AutoScaleVmGroupTO implements Serializable{ + public static class AutoScaleVmGroupTO implements Serializable { private final int minMembers; private final int maxMembers; private final int memberPort; @@ -401,7 +407,7 @@ public class LoadBalancerTO { public String getCurrentState() { return currentState; - } + } } public void setAutoScaleVmGroup(LbAutoScaleVmGroup lbAutoScaleVmGroup) @@ -428,8 +434,9 @@ public class LoadBalancerTO { AutoScaleVmProfileTO autoScaleVmProfileTO = new AutoScaleVmProfileTO(lbAutoScaleVmProfile.getZoneId(), lbAutoScaleVmProfile.getDomainId(), lbAutoScaleVmProfile.getCsUrl(), lbAutoScaleVmProfile.getAutoScaleUserApiKey(), lbAutoScaleVmProfile.getAutoScaleUserSecretKey(), - lbAutoScaleVmProfile.getServiceOfferingId(), lbAutoScaleVmProfile.getTemplateId(), autoScaleVmProfile.getOtherDeployParams(), - autoScaleVmProfile.getSnmpCommunity(), autoScaleVmProfile.getSnmpPort(), autoScaleVmProfile.getDestroyVmGraceperiod()); + lbAutoScaleVmProfile.getServiceOfferingId(), lbAutoScaleVmProfile.getTemplateId(), lbAutoScaleVmProfile.getNetworkId(), + autoScaleVmProfile.getOtherDeployParams(), autoScaleVmProfile.getSnmpCommunity(), autoScaleVmProfile.getSnmpPort(), + autoScaleVmProfile.getDestroyVmGraceperiod()); AutoScaleVmGroup autoScaleVmGroup = lbAutoScaleVmGroup.getVmGroup(); autoScaleVmGroupTO = new AutoScaleVmGroupTO(autoScaleVmGroup.getMinMembers(), autoScaleVmGroup.getMaxMembers(), autoScaleVmGroup.getMemberPort(), http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6aa780d6/api/src/com/cloud/network/lb/LoadBalancingRule.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/network/lb/LoadBalancingRule.java b/api/src/com/cloud/network/lb/LoadBalancingRule.java index 6647b8e..c4e8dca 100644 --- a/api/src/com/cloud/network/lb/LoadBalancingRule.java +++ b/api/src/com/cloud/network/lb/LoadBalancingRule.java @@ -301,8 +301,9 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer { private final String domainId; private final String serviceOfferingId; private final String templateId; + private final String networkId; - public LbAutoScaleVmProfile(AutoScaleVmProfile profile, String autoScaleUserApiKey, String autoScaleUserSecretKey, String csUrl, String zoneId, String domainId, String serviceOfferingId, String templateId) { + public LbAutoScaleVmProfile(AutoScaleVmProfile profile, String autoScaleUserApiKey, String autoScaleUserSecretKey, String csUrl, String zoneId, String domainId, String serviceOfferingId, String templateId, String networkId) { this.profile = profile; this.autoScaleUserApiKey = autoScaleUserApiKey; this.autoScaleUserSecretKey = autoScaleUserSecretKey; @@ -311,6 +312,7 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer { this.domainId = domainId; this.serviceOfferingId = serviceOfferingId; this.templateId = templateId; + this.networkId = networkId; } public AutoScaleVmProfile getProfile() { @@ -343,7 +345,11 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer { public String getTemplateId() { return templateId; - } + } + + public String getNetworkId() { + return networkId; + } } public static class LbAutoScaleVmGroup { http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6aa780d6/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java b/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java index b78e770..f49251d 100644 --- a/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java +++ b/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java @@ -264,7 +264,7 @@ public class NetscalerResource implements ServerResource { } else { _netscalerSdxService = new com.citrix.sdx.nitro.service.nitro_service(_ip, "https"); _netscalerSdxService.set_credential(_username, _password); - com.citrix.sdx.nitro.resource.base.login login = _netscalerSdxService.login(); + com.citrix.sdx.nitro.resource.base.login login = _netscalerSdxService.login(); if (login == null) { throw new ExecutionException ("Failed to log in to Netscaler SDX device at " + _ip + " due to error " + apiCallResult.errorcode + " and message " + apiCallResult.message); } @@ -1364,7 +1364,7 @@ public class NetscalerResource implements ServerResource { } private void addLBVirtualServer(String virtualServerName, String publicIp, int publicPort, String lbAlgorithm, String protocol, StickinessPolicyTO[] stickyPolicies, AutoScaleVmGroupTO vmGroupTO) - throws ExecutionException { + throws ExecutionException { try { String lbMethod; if ("roundrobin".equalsIgnoreCase(lbAlgorithm)) { @@ -1569,7 +1569,7 @@ public class NetscalerResource implements ServerResource { disableAutoScaleConfig(loadBalancerTO, false); } - if(isServiceGroupBoundToVirtualServer(nsVirtualServerName, serviceGroupName)) { + if (isServiceGroupBoundToVirtualServer(nsVirtualServerName, serviceGroupName)) { // UnBind autoscale service group // unbind lb vserver lb lb_autoscaleGroup lbvserver_servicegroup_binding vserver_servicegroup_binding = new lbvserver_servicegroup_binding(); @@ -1709,8 +1709,9 @@ public class NetscalerResource implements ServerResource { ApiConstants.ZONE_ID + "=" + profileTO.getZoneId()+ "&" + ApiConstants.SERVICE_OFFERING_ID + "=" + profileTO.getServiceOfferingId()+ "&" + ApiConstants.TEMPLATE_ID + "=" + profileTO.getTemplateId()+ "&" + + ((profileTO.getNetworkId() == null)? "" : (ApiConstants.NETWORK_IDS + "=" + profileTO.getNetworkId()+ "&")) + ((profileTO.getOtherDeployParams() == null)? "" : (profileTO.getOtherDeployParams() + "&")) + - "lbruleid=" + loadBalancerTO.getUuid(); + "lbruleid=" + loadBalancerTO.getUuid(); scaleUpAction.set_parameters(scaleUpParameters); scaleUpAction.add(_netscalerService, scaleUpAction); } catch (Exception e) { @@ -1729,7 +1730,7 @@ public class NetscalerResource implements ServerResource { scaleDownAction.set_profilename(profileName); scaleDownAction.set_quiettime(scaleDownQuietTime); String scaleDownParameters = "command=destroyVirtualMachine" + "&" + - "lbruleid=" + loadBalancerTO.getUuid(); + "lbruleid=" + loadBalancerTO.getUuid(); scaleDownAction.set_parameters(scaleDownParameters); scaleDownAction.set_vmdestroygraceperiod(destroyVmGracePeriod); scaleDownAction.add(_netscalerService, scaleDownAction); @@ -1860,7 +1861,7 @@ public class NetscalerResource implements ServerResource { } // SYS.VSERVER("abcd").SNMP_TABLE(0).AVERAGE_VALUE.GT(80) int counterIndex = snmpMetrics.get(counterName); // TODO: temporary fix. later on counter name -// will be added as a param to SNMP_TABLE. + // will be added as a param to SNMP_TABLE. formatter.format("SYS.VSERVER(\"%s\").SNMP_TABLE(%d).AVERAGE_VALUE.%s(%d)",nsVirtualServerName, counterIndex, operator, threshold); } else if (counterTO.getSource().equals("netscaler")) @@ -2066,7 +2067,7 @@ public class NetscalerResource implements ServerResource { // For now it is bound globally. // bind timer trigger lb_astimer -policyName lb_policy_scaleUp -vserver lb -priority 1 -samplesize 5 // TODO: later bind to lbvserver. bind timer trigger lb_astimer -policyName lb_policy_scaleUp -vserver lb -// -priority 1 -samplesize 5 + // -priority 1 -samplesize 5 // -thresholdsize 5 nstimer_autoscalepolicy_binding timer_policy_binding = new nstimer_autoscalepolicy_binding(); int sampleSize = duration/interval; http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6aa780d6/server/src/com/cloud/network/as/AutoScaleManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/as/AutoScaleManagerImpl.java b/server/src/com/cloud/network/as/AutoScaleManagerImpl.java index 62b5e47..b536b0b 100644 --- a/server/src/com/cloud/network/as/AutoScaleManagerImpl.java +++ b/server/src/com/cloud/network/as/AutoScaleManagerImpl.java @@ -178,7 +178,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleManager, AutoScaleSe for (Counter counter : counters) { if (!supportedCounters.contains(counter.getSource().name().toString())) { throw new InvalidParameterException("AutoScale counter with source='" + counter.getSource() + "' is not supported " + - "in the network where lb is configured"); + "in the network where lb is configured"); } } } @@ -315,6 +315,9 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleManager, AutoScaleSe // validations HashMap<String, String> deployParams = cmd.getDeployParamMap(); + if(deployParams.containsKey("networks") && deployParams.get("networks").length() > 0) { + throw new InvalidParameterValueException("'networks' is not a valid parameter, network for an AutoScaled VM is chosen automatically. An autoscaled VM is deployed in the loadbalancer's network"); + } /* * Just for making sure the values are right in other deploy params. * For ex. if projectId is given as a string instead of an long value, this @@ -566,7 +569,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleManager, AutoScaleSe Account caller = UserContext.current().getCaller(); Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, - ListProjectResourcesCriteria>(domainId, isRecursive, null); + ListProjectResourcesCriteria>(domainId, isRecursive, null); _accountMgr.buildACLSearchParameters(caller, id, accountName, null, permittedAccounts, domainIdRecursiveListProject, listAll, false); domainId = domainIdRecursiveListProject.first(); http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6aa780d6/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java index 59ae8e6..9014213 100755 --- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java +++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java @@ -42,6 +42,8 @@ import com.cloud.api.response.ServiceResponse; import com.cloud.configuration.Config; import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.dc.DataCenter; +import com.cloud.dc.DataCenter.NetworkType; import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.VlanDao; import com.cloud.domain.dao.DomainDao; @@ -244,7 +246,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa } return null; } - private LbAutoScaleVmGroup getLbAutoScaleVmGroup(AutoScaleVmGroup vmGroup, String currentState) { + private LbAutoScaleVmGroup getLbAutoScaleVmGroup(AutoScaleVmGroupVO vmGroup, String currentState, long networkId) { List<AutoScaleVmGroupPolicyMapVO> vmGroupPolicyMapList = _autoScaleVmGroupPolicyMapDao.listByVmGroupId(vmGroup.getId()); List<LbAutoScalePolicy> autoScalePolicies = new ArrayList<LbAutoScalePolicy>(); for (AutoScaleVmGroupPolicyMapVO vmGroupPolicyMap : vmGroupPolicyMapList) { @@ -268,31 +270,46 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa String domainId = _domainDao.findById(autoScaleVmProfile.getDomainId()).getUuid(); String serviceOfferingId = _offeringsDao.findById(autoScaleVmProfile.getServiceOfferingId()).getUuid(); String templateId = _templateDao.findById(autoScaleVmProfile.getTemplateId()).getUuid(); + String lbNetworkUuid = null; - if(apiKey == null) { + DataCenter zone = _configMgr.getZone(vmGroup.getZoneId()); + if (zone == null) { + // This should never happen, but still a cautious check + s_logger.warn("Unable to find zone while packaging AutoScale Vm Group, zoneid: " + vmGroup.getZoneId()); + throw new InvalidParameterValueException("Unable to find zone"); + } else { + if (zone.getNetworkType() == NetworkType.Advanced) { + NetworkVO lbNetwork = _networkDao.findById(networkId); + lbNetworkUuid = lbNetwork.getUuid(); + } + } + + + if (apiKey == null) { throw new InvalidParameterValueException("apiKey for user: " + user.getUsername() + " is empty. Please generate it"); } - if(secretKey == null) { + if (secretKey == null) { throw new InvalidParameterValueException("secretKey for user: " + user.getUsername() + " is empty. Please generate it"); } - if(csUrl == null || csUrl.contains("localhost")) { + if (csUrl == null || csUrl.contains("localhost")) { throw new InvalidParameterValueException("Global setting endpointe.url has to be set to the Management Server's API end point"); } - LbAutoScaleVmProfile lbAutoScaleVmProfile = new LbAutoScaleVmProfile(autoScaleVmProfile, apiKey, secretKey, csUrl, zoneId, domainId, serviceOfferingId, templateId); + + LbAutoScaleVmProfile lbAutoScaleVmProfile = new LbAutoScaleVmProfile(autoScaleVmProfile, apiKey, secretKey, csUrl, zoneId, domainId, serviceOfferingId, templateId, lbNetworkUuid); return new LbAutoScaleVmGroup(vmGroup, autoScalePolicies, lbAutoScaleVmProfile, currentState); } private boolean applyAutoScaleConfig(LoadBalancerVO lb, AutoScaleVmGroupVO vmGroup, String currentState) throws ResourceUnavailableException { - LbAutoScaleVmGroup lbAutoScaleVmGroup = getLbAutoScaleVmGroup(vmGroup, currentState); + LbAutoScaleVmGroup lbAutoScaleVmGroup = getLbAutoScaleVmGroup(vmGroup, currentState, lb.getNetworkId()); /* Regular config like destinations need not be packed for applying autoscale config as of today.*/ LoadBalancingRule rule = new LoadBalancingRule(lb, null, null); rule.setAutoScaleVmGroup(lbAutoScaleVmGroup); if (!isRollBackAllowedForProvider(lb)) { - // this is for Netscalar type of devices. if their is failure the db entries will be rollbacked. + // this is for Netscaler type of devices. if their is failure the db entries will be rollbacked. return false; } @@ -331,11 +348,11 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa success = applyAutoScaleConfig(loadBalancer, vmGroup, currentState); } catch (ResourceUnavailableException e) { s_logger.warn("Unable to configure AutoScaleVmGroup to the lb rule: " + loadBalancer.getId() + " because resource is unavaliable:", e); - if (isRollBackAllowedForProvider(loadBalancer)) { - loadBalancer.setState(backupState); - _lbDao.persist(loadBalancer); - s_logger.debug("LB Rollback rule id: " + loadBalancer.getId() + " lb state rolback while creating AutoscaleVmGroup"); - } + if (isRollBackAllowedForProvider(loadBalancer)) { + loadBalancer.setState(backupState); + _lbDao.persist(loadBalancer); + s_logger.debug("LB Rollback rule id: " + loadBalancer.getId() + " lb state rolback while creating AutoscaleVmGroup"); + } throw e; } finally { if (!success) { @@ -625,8 +642,9 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa } txn.commit(); if (_autoScaleVmGroupDao.isAutoScaleLoadBalancer(loadBalancerId)) { - // Nothing needs to be done for an autoscaled loadbalancer, - // just persist and proceed. + // For autoscaled loadbalancer, the rules need not be applied, + // meaning the call need not reach the resource layer. + // We can consider the job done. return true; } boolean success = false; @@ -695,8 +713,10 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa } if (_autoScaleVmGroupDao.isAutoScaleLoadBalancer(loadBalancerId)) { - // Nothing needs to be done for an autoscaled loadbalancer, - // just persist and proceed. + // For autoscaled loadbalancer, the rules need not be applied, + // meaning the call need not reach the resource layer. + // We can consider the job done and only need to remove the rules in DB + _lb2VmMapDao.remove(loadBalancer.getId(), instanceIds, null); return true; } @@ -834,10 +854,10 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa if (apply) { try { - if (!applyLoadBalancerConfig(loadBalancerId)) { - s_logger.warn("Unable to apply the load balancer config"); - return false; - } + if (!applyLoadBalancerConfig(loadBalancerId)) { + s_logger.warn("Unable to apply the load balancer config"); + return false; + } } catch (ResourceUnavailableException e) { if (rollBack && isRollBackAllowedForProvider(lb)) { if (backupMaps != null) { @@ -906,7 +926,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa } _networkMgr.checkIpForService(ipAddressVo, Service.Lb); - } + } // FIXME: breaking the dependency on ELB manager. This breaks functionality of ELB using virtual router // Bug CS-15411 opened to document this @@ -919,7 +939,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa if (off.getElasticLb() && ipAddressVo == null) { ip = _networkMgr.assignSystemIp(lb.getNetworkId(), lbOwner, true, false); lb.setSourceIpAddressId(ip.getId()); - } + } try { result = createLoadBalancer(lb, openFirewall); } catch (Exception ex) {
