// and the deployment DNS name configured in global config parameter 'cloud.dns.name'
String domainName = gslbRule.getGslbDomain();
String providerDnsName = _globalConfigDao.getValue(Config.CloudDnsName.key());
String gslbFqdn = domainName + "." + providerDnsName;
GlobalLoadBalancerConfigCommand gslbConfigCmd = new GlobalLoadBalancerConfigCommand(gslbFqdn,
lbMethod, persistenceMethod, serviceType, gslbRuleId, revoke);
// list of the physical network participating in global load balancing
List<Pair<Long, Long>> gslbSiteIds = new ArrayList<Pair<Long, Long>>();
// map of the zone and info corresponding to the load balancer configured in the zone
Map<Long, SiteLoadBalancerConfig> zoneSiteLoadbalancerMap = new HashMap<Long, SiteLoadBalancerConfig>();
List<GlobalLoadBalancerLbRuleMapVO> gslbLbMapVos = _gslbLbMapDao.listByGslbRuleId(gslbRuleId);
assert (gslbLbMapVos != null && !gslbLbMapVos.isEmpty());
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();
long physicalNetworkId = network.getPhysicalNetworkId();
gslbSiteIds.add(new Pair<Long, Long>(dataCenterId, physicalNetworkId));
IPAddressVO ip = _ipAddressDao.findById(loadBalancer.getSourceIpAddressId());
SiteLoadBalancerConfig siteLb = new SiteLoadBalancerConfig(gslbLbMapVo.isRevoke(), serviceType,
ip.getAddress().addr(), Integer.toString(loadBalancer.getDefaultPortStart()),
dataCenterId);
siteLb.setGslbProviderPublicIp(_gslbProvider.getZoneGslbProviderPublicIp(dataCenterId, physicalNetworkId));
siteLb.setGslbProviderPrivateIp(_gslbProvider.getZoneGslbProviderPrivateIp(dataCenterId, physicalNetworkId));
siteLb.setWeight(gslbLbMapVo.getWeight());
zoneSiteLoadbalancerMap.put(network.getDataCenterId(), siteLb);
}
// loop through all the zones, participating in GSLB, and send GSLB config command
// to the corresponding GSLB service provider in that zone
for (Pair<Long,Long> zoneId: gslbSiteIds) {
List<SiteLoadBalancerConfig> slbs = new ArrayList<SiteLoadBalancerConfig>();
// set site as 'local' for the site in that zone
for (Pair<Long,Long> innerLoopZoneId: gslbSiteIds) {
SiteLoadBalancerConfig siteLb = zoneSiteLoadbalancerMap.get(innerLoopZoneId.first());
siteLb.setLocal(zoneId.first() == innerLoopZoneId.first());
slbs.add(siteLb);
}
gslbConfigCmd.setSiteLoadBalancers(slbs);
gslbConfigCmd.setForRevoke(revoke);
// revoke GSLB configuration completely on the site GSLB provider for the sites that no longer
// are participants of a GSLB rule
SiteLoadBalancerConfig siteLb = zoneSiteLoadbalancerMap.get(zoneId.first());
if (siteLb.forRevoke()) {
gslbConfigCmd.setForRevoke(true);
}
try {
_gslbProvider.applyGlobalLoadBalancerRule(zoneId.first(), zoneId.second(), gslbConfigCmd);
} catch (ResourceUnavailableException e) {