From d9b843ed9db8d7b3d65f1bbbd6cad91c919af702 Mon Sep 17 00:00:00 2001 From: Vijay Date: Tue, 14 Aug 2012 16:30:44 +0530 Subject: [PATCH] CS-15938. Support for multiple guest networks with autoscale The loadbalancers network and the VM's network are the same. Hence not getting the input from user and passing the loadbalancers network for the AutoScale VMs (for advanced network). --- .../cloud/agent/api/to/LoadBalancerTO.java | 15 ++++++++---- .../cloud/network/lb/LoadBalancingRule.java | 8 ++++++- .../network/resource/NetscalerResource.java | 1 + .../network/as/AutoScaleManagerImpl.java | 3 +++ .../lb/LoadBalancingRulesManagerImpl.java | 24 +++++++++++++++---- 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/api/src/com/cloud/agent/api/to/LoadBalancerTO.java b/api/src/com/cloud/agent/api/to/LoadBalancerTO.java index 2f3fcdce237..64c85c035a3 100644 --- a/api/src/com/cloud/agent/api/to/LoadBalancerTO.java +++ b/api/src/com/cloud/agent/api/to/LoadBalancerTO.java @@ -287,9 +287,10 @@ public class LoadBalancerTO implements Serializable { 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; @@ -301,6 +302,7 @@ public class LoadBalancerTO implements Serializable { this.cloudStackApiUrl = cloudStackApiUrl; this.autoScaleUserApiKey = autoScaleUserApiKey; this.autoScaleUserSecretKey = autoScaleUserSecretKey; + this.networkId = networkId; } public String getZoneId() { @@ -346,6 +348,10 @@ public class LoadBalancerTO implements Serializable { public String getAutoScaleUserSecretKey() { return autoScaleUserSecretKey; } + + public String getNetworkId() { + return networkId; + } } public static class AutoScaleVmGroupTO implements Serializable { @@ -427,8 +433,9 @@ public class LoadBalancerTO implements Serializable { 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(), diff --git a/api/src/com/cloud/network/lb/LoadBalancingRule.java b/api/src/com/cloud/network/lb/LoadBalancingRule.java index a2471fe1dd5..9d9caec097b 100644 --- a/api/src/com/cloud/network/lb/LoadBalancingRule.java +++ b/api/src/com/cloud/network/lb/LoadBalancingRule.java @@ -307,8 +307,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; @@ -317,6 +318,7 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer { this.domainId = domainId; this.serviceOfferingId = serviceOfferingId; this.templateId = templateId; + this.networkId = networkId; } public AutoScaleVmProfile getProfile() { @@ -350,6 +352,10 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer { public String getTemplateId() { return templateId; } + + public String getNetworkId() { + return networkId; + } } public static class LbAutoScaleVmGroup { diff --git a/core/src/com/cloud/network/resource/NetscalerResource.java b/core/src/com/cloud/network/resource/NetscalerResource.java index a42b7074537..ee8555475c5 100644 --- a/core/src/com/cloud/network/resource/NetscalerResource.java +++ b/core/src/com/cloud/network/resource/NetscalerResource.java @@ -1717,6 +1717,7 @@ 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(); scaleUpAction.set_parameters(scaleUpParameters); diff --git a/server/src/com/cloud/network/as/AutoScaleManagerImpl.java b/server/src/com/cloud/network/as/AutoScaleManagerImpl.java index 0eefca09a6d..460e8a4e159 100644 --- a/server/src/com/cloud/network/as/AutoScaleManagerImpl.java +++ b/server/src/com/cloud/network/as/AutoScaleManagerImpl.java @@ -315,6 +315,9 @@ public class AutoScaleManagerImpl implements AutoScaleService, Manager { // validations HashMap 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", null); + } /* * 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 diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java index d1e03203cfe..e2fce3d2d81 100755 --- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java +++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java @@ -38,6 +38,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; @@ -248,7 +250,7 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa return null; } - private LbAutoScaleVmGroup getLbAutoScaleVmGroup(AutoScaleVmGroup vmGroup, String currentState) { + private LbAutoScaleVmGroup getLbAutoScaleVmGroup(AutoScaleVmGroupVO vmGroup, String currentState, long networkId) { List vmGroupPolicyMapList = _autoScaleVmGroupPolicyMapDao.listByVmGroupId(vmGroup.getId()); List autoScalePolicies = new ArrayList(); for (AutoScaleVmGroupPolicyMapVO vmGroupPolicyMap : vmGroupPolicyMapList) { @@ -272,6 +274,18 @@ public class LoadBalancingRulesManagerImpl 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; + + DataCenter zone = _configMgr.getZone(vmGroup.getZoneId()); + if (zone == null) { + throw new InvalidParameterValueException("Unable to find zone by id", null); + } 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", null); @@ -285,18 +299,19 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa throw new InvalidParameterValueException("Global setting endpointe.url has to be set to the Management Server's API end point", null); } - 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; } @@ -714,6 +729,7 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa if (_autoScaleVmGroupDao.isAutoScaleLoadBalancer(loadBalancerId)) { // Nothing needs to be done for an autoscaled loadbalancer, // just persist and proceed. + _lb2VmMapDao.remove(loadBalancer.getId(), instanceIds, null); return true; }