mirror of https://github.com/apache/cloudstack.git
implements changes to 'SiteLoadBalancerConfig' details and
implementation of UpdateGlobalLoadBalancerRule command in service layer
This commit is contained in:
parent
70e2eeaea8
commit
54bff978fe
|
|
@ -17,9 +17,11 @@
|
|||
|
||||
package com.cloud.agent.api.routing;
|
||||
|
||||
// details of site participating in the GLSB service
|
||||
// details of site participating in the GLSB service, represents configuration load balancer rule and the zone
|
||||
// in which the rule is configured
|
||||
public class SiteLoadBalancerConfig {
|
||||
// true if the site is local (GSLB provider receiving GlobalLoadBalancerConfigCommand is in same site)
|
||||
|
||||
// true if the site details are local to the zone receiving 'GlobalLoadBalancerConfigCommand'
|
||||
boolean local;
|
||||
|
||||
// true if the site needs to be removed from GSLB service
|
||||
|
|
@ -34,8 +36,8 @@ public class SiteLoadBalancerConfig {
|
|||
// port corresponding to the site load balanced service
|
||||
String port;
|
||||
|
||||
// IP corresponding to the GSLB service provider in the site.
|
||||
String gslbProviderIp;
|
||||
// Private IP corresponding to the GSLB service provider in the site.
|
||||
String gslbProviderPrivateIp;
|
||||
|
||||
// Public IP corresponding to the GSLB service provider in the site.
|
||||
String gslbProviderPublicIp;
|
||||
|
|
@ -47,15 +49,12 @@ public class SiteLoadBalancerConfig {
|
|||
this.port = port;
|
||||
}
|
||||
|
||||
public SiteLoadBalancerConfig(String gslbProviderIp, String gslbProviderPublicIP, boolean local, boolean revoked,
|
||||
String serviceType, String servicePublicIp, String port) {
|
||||
this.gslbProviderIp = gslbProviderIp;
|
||||
public SiteLoadBalancerConfig(String gslbProviderPublicIP, String gslbProviderPrivateIp, boolean local,
|
||||
boolean revoked, String serviceType, String servicePublicIp, String port) {
|
||||
this(revoked, serviceType, servicePublicIp, port);
|
||||
this.gslbProviderPrivateIp = gslbProviderPrivateIp;
|
||||
this.gslbProviderPublicIp = gslbProviderPublicIP;
|
||||
this.local = local;
|
||||
this.revoked = revoked;
|
||||
this.serviceType = serviceType;
|
||||
this.servicePublicIp = servicePublicIp;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getServiceType() {
|
||||
|
|
@ -83,11 +82,11 @@ public class SiteLoadBalancerConfig {
|
|||
}
|
||||
|
||||
public String getGslbProviderPrivateIp() {
|
||||
return gslbProviderIp;
|
||||
return gslbProviderPrivateIp;
|
||||
}
|
||||
|
||||
public void setGslbProviderPrivateIp(String privateIp) {
|
||||
this.gslbProviderIp = privateIp;
|
||||
this.gslbProviderPrivateIp = privateIp;
|
||||
}
|
||||
|
||||
public String getGslbProviderPublicIp() {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class AssignToGlobalLoadBalancerRuleCmd extends BaseAsyncCmd {
|
|||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = GlobalLoadBalancerResponse.class,
|
||||
required=true, description="the ID of the load balancer rule")
|
||||
required=true, description="the ID of the global load balancer rule")
|
||||
private Long id;
|
||||
|
||||
@Parameter(name=ApiConstants.LOAD_BALANCER_RULE_LIST, type=CommandType.LIST, collectionType=CommandType.UUID,
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public class CreateGlobalLoadBalancerRuleCmd extends BaseAsyncCreateCmd {
|
|||
private Long domainId;
|
||||
|
||||
@Parameter(name=ApiConstants.GSLB_LB_METHOD, type=CommandType.STRING, required=false, description="load balancer algorithm (roundrobin, leastconn, proximity) " +
|
||||
"that is used to distributed traffic across the zones participating in global server load balancing, if not specified defaults to 'round robin'")
|
||||
"that method is used to distribute traffic across the zones participating in global server load balancing, if not specified defaults to 'round robin'")
|
||||
private String algorithm;
|
||||
|
||||
@Parameter(name=ApiConstants.GSLB_STICKY_SESSION_METHOD, type=CommandType.STRING, required=false, description="session sticky method (sourceip) if not specified defaults to sourceip")
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import org.apache.cloudstack.api.APICommand;
|
|||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.response.FirewallRuleResponse;
|
||||
import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse;
|
||||
import org.apache.cloudstack.api.response.LoadBalancerResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
@ -33,16 +32,25 @@ import javax.inject.Inject;
|
|||
public class UpdateGlobalLoadBalancerRuleCmd extends BaseListTaggedResourcesCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(GlobalLoadBalancerResponse.class.getName());
|
||||
|
||||
private static final String s_name = "updategloballoadbalancerrulesresponse";
|
||||
private static final String s_name = "updategloballoadbalancerruleresponse";
|
||||
|
||||
// ///////////////////////////////////////////////////
|
||||
// ////////////// API parameters /////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = FirewallRuleResponse.class,
|
||||
description = "the ID of the load balancer rule")
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = GlobalLoadBalancerResponse.class,
|
||||
required=true, description="the ID of the global load balancer rule")
|
||||
private Long id;
|
||||
|
||||
@Parameter(name=ApiConstants.DESCRIPTION, type=CommandType.STRING, description="the description of the load balancer rule", length=4096)
|
||||
private String description;
|
||||
|
||||
@Parameter(name=ApiConstants.GSLB_LB_METHOD, type=CommandType.STRING, required=false, description="load balancer algorithm (roundrobin, leastconn, proximity) " +
|
||||
"that is used to distributed traffic across the zones participating in global server load balancing, if not specified defaults to 'round robin'")
|
||||
private String algorithm;
|
||||
|
||||
@Parameter(name=ApiConstants.GSLB_STICKY_SESSION_METHOD, type=CommandType.STRING, required=false, description="session sticky method (sourceip) if not specified defaults to sourceip")
|
||||
private String stickyMethod;
|
||||
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////////// Accessors ///////////////////////
|
||||
|
|
@ -52,6 +60,22 @@ public class UpdateGlobalLoadBalancerRuleCmd extends BaseListTaggedResourcesCmd
|
|||
return id;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getAlgorithm() {
|
||||
return algorithm;
|
||||
}
|
||||
|
||||
public String getGslbMethod() {
|
||||
return algorithm;
|
||||
}
|
||||
|
||||
public String getStickyMethod() {
|
||||
return stickyMethod;
|
||||
}
|
||||
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////// API Implementation///////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -755,7 +755,7 @@ public class NetscalerResource implements ServerResource {
|
|||
String persistenceType = gslbCmd.getPersistenceType();
|
||||
String serviceType = gslbCmd.getServiceType();
|
||||
boolean forRevoke = gslbCmd.isForRevoke();
|
||||
GlobalLoadBalancerConfigCommand.SiteLoadBalancer[] sites = gslbCmd.getSiteDetails();
|
||||
List<SiteLoadBalancerConfig> sites = gslbCmd.getSiteDetails();
|
||||
|
||||
String domainName = gslbCmd.getDomainName();
|
||||
String vserverName = GSLB.generateVirtualServerName(domainName);
|
||||
|
|
@ -768,7 +768,7 @@ public class NetscalerResource implements ServerResource {
|
|||
GSLB.createVirtualServer(_netscalerService, vserverName, lbMethod, persistenceType, serviceType);
|
||||
|
||||
if (sites != null) { // check if there are any sites that are participating in global load balancing
|
||||
for (GlobalLoadBalancerConfigCommand.SiteLoadBalancer site : sites) {
|
||||
for (SiteLoadBalancerConfig site : sites) {
|
||||
|
||||
String sitePrivateIP = site.getGslbProviderPrivateIp();
|
||||
String sitePublicIP = site.getGslbProviderPublicIp();
|
||||
|
|
@ -822,7 +822,7 @@ public class NetscalerResource implements ServerResource {
|
|||
GSLB.createVserverDomainBinding(_netscalerService, vserverName, domainName);
|
||||
|
||||
if (sites != null) {
|
||||
for (GlobalLoadBalancerConfigCommand.SiteLoadBalancer site : sites) {
|
||||
for (SiteLoadBalancerConfig site : sites) {
|
||||
|
||||
String sitePrivateIP = site.getGslbProviderPrivateIp();
|
||||
String sitePublicIP = site.getGslbProviderPublicIp();
|
||||
|
|
|
|||
|
|
@ -311,7 +311,7 @@ public class GlobalLoadBalancingRulesServiceImpl implements GlobalLoadBalancingR
|
|||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
// update the mapping of gslb rule to Lb rule, to revoke state
|
||||
// update the mapping of gslb rule to Lb rule, to revoke state
|
||||
for (Long lbRuleId : lbRuleIdsToremove) {
|
||||
GlobalLoadBalancerLbRuleMapVO removeGslbLbMap = _gslbLbMapDao.findByGslbRuleIdAndLbRuleId(gslbRuleId, lbRuleId);
|
||||
removeGslbLbMap.setRevoke(true);
|
||||
|
|
@ -354,7 +354,41 @@ public class GlobalLoadBalancingRulesServiceImpl implements GlobalLoadBalancingR
|
|||
|
||||
@Override
|
||||
public GlobalLoadBalancerRule updateGlobalLoadBalancerRule(UpdateGlobalLoadBalancerRuleCmd updateGslbCmd) {
|
||||
return null;
|
||||
|
||||
String algorithm = updateGslbCmd.getAlgorithm();
|
||||
String stickyMethod = updateGslbCmd.getStickyMethod();
|
||||
String description = updateGslbCmd.getDescription();
|
||||
|
||||
long gslbRuleId = updateGslbCmd.getId();
|
||||
GlobalLoadBalancerRuleVO gslbRule = _gslbRuleDao.findById(gslbRuleId);
|
||||
if (gslbRule == null) {
|
||||
throw new InvalidParameterValueException("Invalid global load balancer rule id: " + gslbRuleId);
|
||||
}
|
||||
|
||||
UserContext ctx = UserContext.current();
|
||||
Account caller = ctx.getCaller();
|
||||
|
||||
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.ModifyEntry, true, gslbRule);
|
||||
|
||||
|
||||
if (!GlobalLoadBalancerRule.Algorithm.isValidAlgorithm(algorithm)) {
|
||||
throw new InvalidParameterValueException("Invalid Algorithm: " + algorithm);
|
||||
}
|
||||
|
||||
if (!GlobalLoadBalancerRule.Persistence.isValidPersistence(stickyMethod)) {
|
||||
throw new InvalidParameterValueException("Invalid persistence: " + stickyMethod);
|
||||
}
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
gslbRule.setAlgorithm(algorithm);
|
||||
gslbRule.setPersistence(stickyMethod);
|
||||
gslbRule.setDescription(description);
|
||||
_gslbRuleDao.update(gslbRule.getId(), gslbRule);
|
||||
txn.commit();
|
||||
|
||||
s_logger.debug("Updated global load balancer with id " + gslbRule.getUuid());
|
||||
return gslbRule;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -382,19 +416,31 @@ public class GlobalLoadBalancingRulesServiceImpl implements GlobalLoadBalancingR
|
|||
Map<Long, SiteLoadBalancerConfig> zoneSiteLoadbalancerMap = new HashMap<Long, SiteLoadBalancerConfig>();
|
||||
|
||||
List<GlobalLoadBalancerLbRuleMapVO> gslbLbMapVos = _gslbLbMapDao.listByGslbRuleId(gslbRuleId);
|
||||
|
||||
if (gslbLbMapVos == null || gslbLbMapVos.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (GlobalLoadBalancerLbRuleMapVO gslbLbMapVo : gslbLbMapVos) {
|
||||
// get the zone in which load balancer rule is deployed
|
||||
LoadBalancerVO loadBalancer = _lbDao.findById(gslbLbMapVo.getLoadBalancerId());
|
||||
Network network = _networkDao.findById(loadBalancer.getNetworkId());
|
||||
long dataCenterId = network.getDataCenterId();
|
||||
|
||||
gslbSiteIds.add(network.getDataCenterId());
|
||||
gslbSiteIds.add(dataCenterId);
|
||||
|
||||
IPAddressVO ip = _ipAddressDao.findById(loadBalancer.getSourceIpAddressId());
|
||||
SiteLoadBalancerConfig siteLb = new SiteLoadBalancerConfig(gslbLbMapVo.isRevoke(), serviceType,
|
||||
ip.getAddress().addr(), Integer.toString(loadBalancer.getDefaultPortStart()));
|
||||
|
||||
siteLb.setGslbProviderPublicIp(null);
|
||||
siteLb.setGslbProviderPrivateIp(null);
|
||||
|
||||
zoneSiteLoadbalancerMap.put(network.getDataCenterId(), siteLb);
|
||||
}
|
||||
|
||||
// loop through all the zones, participating in GSLB, and send GSLB config command
|
||||
// to the GSLB service provider in the zone
|
||||
for (long zoneId: gslbSiteIds) {
|
||||
|
||||
List<SiteLoadBalancerConfig> slbs = new ArrayList<SiteLoadBalancerConfig>();
|
||||
|
|
@ -405,9 +451,11 @@ public class GlobalLoadBalancingRulesServiceImpl implements GlobalLoadBalancingR
|
|||
slbs.add(siteLb);
|
||||
}
|
||||
|
||||
gslbConfigCmd.setSiteLoadBalancers(slbs);
|
||||
|
||||
// get the host Id corresponding to GSLB service provider in the zone
|
||||
long zoneGslbProviderHosId = 0;
|
||||
|
||||
gslbConfigCmd.setSiteLoadBalancers(slbs);
|
||||
Answer answer = _agentMgr.easySend(zoneGslbProviderHosId, gslbConfigCmd);
|
||||
if (answer == null) {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue