Search in sources :

Example 1 with GlobalLoadBalancerConfigCommand

use of com.cloud.agent.api.routing.GlobalLoadBalancerConfigCommand in project cloudstack by apache.

the class GlobalLoadBalancingRulesServiceImpl method applyGlobalLoadBalancerRuleConfig.

private boolean applyGlobalLoadBalancerRuleConfig(long gslbRuleId, boolean revoke) throws ResourceUnavailableException {
    GlobalLoadBalancerRuleVO gslbRule = _gslbRuleDao.findById(gslbRuleId);
    assert (gslbRule != null);
    String lbMethod = gslbRule.getAlgorithm();
    String persistenceMethod = gslbRule.getPersistence();
    String serviceType = gslbRule.getServiceType();
    // each Gslb rule will have a FQDN, formed from the domain name associated with the gslb rule
    // 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(lookupGslbServiceProvider().getZoneGslbProviderPublicIp(dataCenterId, physicalNetworkId));
        siteLb.setGslbProviderPrivateIp(lookupGslbServiceProvider().getZoneGslbProviderPrivateIp(dataCenterId, physicalNetworkId));
        siteLb.setWeight(gslbLbMapVo.getWeight());
        zoneSiteLoadbalancerMap.put(network.getDataCenterId(), siteLb);
    }
    // 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 {
            lookupGslbServiceProvider().applyGlobalLoadBalancerRule(zoneId.first(), zoneId.second(), gslbConfigCmd);
        } catch (ResourceUnavailableException | NullPointerException e) {
            String msg = "Failed to configure GSLB rule in the zone " + zoneId.first() + " due to " + e.getMessage();
            s_logger.warn(msg);
            throw new CloudRuntimeException(msg);
        }
    }
    return true;
}
Also used : GlobalLoadBalancerConfigCommand(com.cloud.agent.api.routing.GlobalLoadBalancerConfigCommand) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) SiteLoadBalancerConfig(com.cloud.agent.api.routing.SiteLoadBalancerConfig) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) IPAddressVO(com.cloud.network.dao.IPAddressVO) Pair(com.cloud.utils.Pair)

Aggregations

GlobalLoadBalancerConfigCommand (com.cloud.agent.api.routing.GlobalLoadBalancerConfigCommand)1 SiteLoadBalancerConfig (com.cloud.agent.api.routing.SiteLoadBalancerConfig)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 Network (com.cloud.network.Network)1 IPAddressVO (com.cloud.network.dao.IPAddressVO)1 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)1 Pair (com.cloud.utils.Pair)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1