Search in sources :

Example 1 with LbAutoScaleVmGroup

use of com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method getLoadBalancerRuleToApply.

private LoadBalancingRule getLoadBalancerRuleToApply(LoadBalancerVO lb) {
    List<LbStickinessPolicy> policyList = getStickinessPolicies(lb.getId());
    Ip sourceIp = getSourceIp(lb);
    LbSslCert sslCert = getLbSslCert(lb.getId());
    LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, null, policyList, null, sourceIp, sslCert, lb.getLbProtocol());
    if (_autoScaleVmGroupDao.isAutoScaleLoadBalancer(lb.getId())) {
        // Get the associated VmGroup
        AutoScaleVmGroupVO vmGroup = _autoScaleVmGroupDao.listByAll(lb.getId(), null).get(0);
        LbAutoScaleVmGroup lbAutoScaleVmGroup = getLbAutoScaleVmGroup(vmGroup, vmGroup.getState(), lb);
        loadBalancing.setAutoScaleVmGroup(lbAutoScaleVmGroup);
    } else {
        List<LbDestination> dstList = getExistingDestinations(lb.getId());
        loadBalancing.setDestinations(dstList);
        List<LbHealthCheckPolicy> hcPolicyList = getHealthCheckPolicies(lb.getId());
        loadBalancing.setHealthCheckPolicies(hcPolicyList);
    }
    return loadBalancing;
}
Also used : LbSslCert(com.cloud.network.lb.LoadBalancingRule.LbSslCert) AutoScaleVmGroupVO(com.cloud.network.as.AutoScaleVmGroupVO) Ip(com.cloud.utils.net.Ip) PublicIp(com.cloud.network.addr.PublicIp) LbHealthCheckPolicy(com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy) LbStickinessPolicy(com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy) LbAutoScaleVmGroup(com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination)

Example 2 with LbAutoScaleVmGroup

use of com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method applyAutoScaleConfig.

private boolean applyAutoScaleConfig(LoadBalancerVO lb, AutoScaleVmGroupVO vmGroup, String currentState) throws ResourceUnavailableException {
    LbAutoScaleVmGroup lbAutoScaleVmGroup = getLbAutoScaleVmGroup(vmGroup, currentState, lb);
    /*
         * Regular config like destinations need not be packed for applying
         * autoscale config as of today.
         */
    List<LbStickinessPolicy> policyList = getStickinessPolicies(lb.getId());
    Ip sourceIp = getSourceIp(lb);
    LoadBalancingRule rule = new LoadBalancingRule(lb, null, policyList, null, sourceIp, null, lb.getLbProtocol());
    rule.setAutoScaleVmGroup(lbAutoScaleVmGroup);
    if (!isRollBackAllowedForProvider(lb)) {
        // entries will be rollbacked.
        return false;
    }
    List<LoadBalancingRule> rules = Arrays.asList(rule);
    if (!applyLbRules(rules, false)) {
        s_logger.debug("LB rules' autoscale config are not completely applied");
        return false;
    }
    return true;
}
Also used : Ip(com.cloud.utils.net.Ip) PublicIp(com.cloud.network.addr.PublicIp) LbStickinessPolicy(com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy) LbAutoScaleVmGroup(com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup)

Example 3 with LbAutoScaleVmGroup

use of com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup in project cloudstack by apache.

the class LoadBalancerTO method setAutoScaleVmGroup.

public void setAutoScaleVmGroup(LbAutoScaleVmGroup lbAutoScaleVmGroup) {
    List<LbAutoScalePolicy> lbAutoScalePolicies = lbAutoScaleVmGroup.getPolicies();
    List<AutoScalePolicyTO> autoScalePolicyTOs = new ArrayList<AutoScalePolicyTO>(lbAutoScalePolicies.size());
    for (LbAutoScalePolicy lbAutoScalePolicy : lbAutoScalePolicies) {
        List<LbCondition> lbConditions = lbAutoScalePolicy.getConditions();
        List<ConditionTO> conditionTOs = new ArrayList<ConditionTO>(lbConditions.size());
        for (LbCondition lbCondition : lbConditions) {
            Counter counter = lbCondition.getCounter();
            CounterTO counterTO = new CounterTO(counter.getName(), counter.getSource().toString(), "" + counter.getValue());
            Condition condition = lbCondition.getCondition();
            ConditionTO conditionTO = new ConditionTO(condition.getThreshold(), condition.getRelationalOperator().toString(), counterTO);
            conditionTOs.add(conditionTO);
        }
        AutoScalePolicy autoScalePolicy = lbAutoScalePolicy.getPolicy();
        autoScalePolicyTOs.add(new AutoScalePolicyTO(autoScalePolicy.getId(), autoScalePolicy.getDuration(), autoScalePolicy.getQuietTime(), autoScalePolicy.getAction(), conditionTOs, lbAutoScalePolicy.isRevoked()));
    }
    LbAutoScaleVmProfile lbAutoScaleVmProfile = lbAutoScaleVmGroup.getProfile();
    AutoScaleVmProfile autoScaleVmProfile = lbAutoScaleVmProfile.getProfile();
    AutoScaleVmProfileTO autoScaleVmProfileTO = new AutoScaleVmProfileTO(lbAutoScaleVmProfile.getZoneId(), lbAutoScaleVmProfile.getDomainId(), lbAutoScaleVmProfile.getCsUrl(), lbAutoScaleVmProfile.getAutoScaleUserApiKey(), lbAutoScaleVmProfile.getAutoScaleUserSecretKey(), lbAutoScaleVmProfile.getServiceOfferingId(), lbAutoScaleVmProfile.getTemplateId(), lbAutoScaleVmProfile.getVmName(), lbAutoScaleVmProfile.getNetworkId(), autoScaleVmProfile.getOtherDeployParams(), autoScaleVmProfile.getCounterParams(), autoScaleVmProfile.getDestroyVmGraceperiod());
    AutoScaleVmGroup autoScaleVmGroup = lbAutoScaleVmGroup.getVmGroup();
    autoScaleVmGroupTO = new AutoScaleVmGroupTO(autoScaleVmGroup.getUuid(), autoScaleVmGroup.getMinMembers(), autoScaleVmGroup.getMaxMembers(), autoScaleVmGroup.getMemberPort(), autoScaleVmGroup.getInterval(), autoScalePolicyTOs, autoScaleVmProfileTO, autoScaleVmGroup.getState(), lbAutoScaleVmGroup.getCurrentState());
}
Also used : LbCondition(com.cloud.network.lb.LoadBalancingRule.LbCondition) Condition(com.cloud.network.as.Condition) LbAutoScaleVmGroup(com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup) AutoScaleVmGroup(com.cloud.network.as.AutoScaleVmGroup) LbAutoScaleVmProfile(com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmProfile) LbAutoScalePolicy(com.cloud.network.lb.LoadBalancingRule.LbAutoScalePolicy) ArrayList(java.util.ArrayList) LbAutoScaleVmProfile(com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmProfile) AutoScaleVmProfile(com.cloud.network.as.AutoScaleVmProfile) Counter(com.cloud.network.as.Counter) LbAutoScalePolicy(com.cloud.network.lb.LoadBalancingRule.LbAutoScalePolicy) AutoScalePolicy(com.cloud.network.as.AutoScalePolicy) LbCondition(com.cloud.network.lb.LoadBalancingRule.LbCondition)

Example 4 with LbAutoScaleVmGroup

use of com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method getLbAutoScaleVmGroup.

private LbAutoScaleVmGroup getLbAutoScaleVmGroup(AutoScaleVmGroupVO vmGroup, String currentState, LoadBalancerVO lb) {
    long lbNetworkId = lb.getNetworkId();
    String lbName = lb.getName();
    List<AutoScaleVmGroupPolicyMapVO> vmGroupPolicyMapList = _autoScaleVmGroupPolicyMapDao.listByVmGroupId(vmGroup.getId());
    List<LbAutoScalePolicy> autoScalePolicies = new ArrayList<LbAutoScalePolicy>();
    for (AutoScaleVmGroupPolicyMapVO vmGroupPolicyMap : vmGroupPolicyMapList) {
        AutoScalePolicy autoScalePolicy = _autoScalePolicyDao.findById(vmGroupPolicyMap.getPolicyId());
        List<AutoScalePolicyConditionMapVO> autoScalePolicyConditionMapList = _autoScalePolicyConditionMapDao.listByAll(autoScalePolicy.getId(), null);
        List<LbCondition> lbConditions = new ArrayList<LbCondition>();
        for (AutoScalePolicyConditionMapVO autoScalePolicyConditionMap : autoScalePolicyConditionMapList) {
            Condition condition = _conditionDao.findById(autoScalePolicyConditionMap.getConditionId());
            Counter counter = _counterDao.findById(condition.getCounterid());
            lbConditions.add(new LbCondition(counter, condition));
        }
        autoScalePolicies.add(new LbAutoScalePolicy(autoScalePolicy, lbConditions));
    }
    AutoScaleVmProfile autoScaleVmProfile = _autoScaleVmProfileDao.findById(vmGroup.getProfileId());
    Long autoscaleUserId = autoScaleVmProfile.getAutoScaleUserId();
    User user = _userDao.findByIdIncludingRemoved(autoscaleUserId);
    String apiKey = user.getApiKey();
    String secretKey = user.getSecretKey();
    String csUrl = ApiServiceConfiguration.ApiServletPath.value();
    String zoneId = _dcDao.findById(autoScaleVmProfile.getZoneId()).getUuid();
    String domainId = _domainDao.findById(autoScaleVmProfile.getDomainId()).getUuid();
    String serviceOfferingId = _offeringsDao.findById(autoScaleVmProfile.getServiceOfferingId()).getUuid();
    String templateId = _templateDao.findById(autoScaleVmProfile.getTemplateId()).getUuid();
    String vmName = "AutoScale-LB-" + lbName;
    String lbNetworkUuid = null;
    DataCenter zone = _entityMgr.findById(DataCenter.class, 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(lbNetworkId);
            lbNetworkUuid = lbNetwork.getUuid();
        }
    }
    if (apiKey == null) {
        throw new InvalidParameterValueException("apiKey for user: " + user.getUsername() + " is empty. Please generate it");
    }
    if (secretKey == null) {
        throw new InvalidParameterValueException("secretKey for user: " + user.getUsername() + " is empty. Please generate it");
    }
    if (csUrl == null || csUrl.contains("localhost")) {
        throw new InvalidParameterValueException(String.format("Global setting %s has to be set to the Management Server's API end point", ApiServiceConfiguration.ApiServletPath.key()));
    }
    LbAutoScaleVmProfile lbAutoScaleVmProfile = new LbAutoScaleVmProfile(autoScaleVmProfile, apiKey, secretKey, csUrl, zoneId, domainId, serviceOfferingId, templateId, vmName, lbNetworkUuid);
    return new LbAutoScaleVmGroup(vmGroup, autoScalePolicies, lbAutoScaleVmProfile, currentState);
}
Also used : Condition(com.cloud.network.as.Condition) LbCondition(com.cloud.network.lb.LoadBalancingRule.LbCondition) AutoScaleVmGroupPolicyMapVO(com.cloud.network.as.AutoScaleVmGroupPolicyMapVO) NetworkVO(com.cloud.network.dao.NetworkVO) User(com.cloud.user.User) LbAutoScaleVmProfile(com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmProfile) LbAutoScalePolicy(com.cloud.network.lb.LoadBalancingRule.LbAutoScalePolicy) ArrayList(java.util.ArrayList) LbAutoScaleVmProfile(com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmProfile) AutoScaleVmProfile(com.cloud.network.as.AutoScaleVmProfile) Counter(com.cloud.network.as.Counter) DataCenter(com.cloud.dc.DataCenter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) LbAutoScalePolicy(com.cloud.network.lb.LoadBalancingRule.LbAutoScalePolicy) AutoScalePolicy(com.cloud.network.as.AutoScalePolicy) LbCondition(com.cloud.network.lb.LoadBalancingRule.LbCondition) LbAutoScaleVmGroup(com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup) AutoScalePolicyConditionMapVO(com.cloud.network.as.AutoScalePolicyConditionMapVO)

Aggregations

LbAutoScaleVmGroup (com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup)4 PublicIp (com.cloud.network.addr.PublicIp)2 AutoScalePolicy (com.cloud.network.as.AutoScalePolicy)2 AutoScaleVmProfile (com.cloud.network.as.AutoScaleVmProfile)2 Condition (com.cloud.network.as.Condition)2 Counter (com.cloud.network.as.Counter)2 LbAutoScalePolicy (com.cloud.network.lb.LoadBalancingRule.LbAutoScalePolicy)2 LbAutoScaleVmProfile (com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmProfile)2 LbCondition (com.cloud.network.lb.LoadBalancingRule.LbCondition)2 LbStickinessPolicy (com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy)2 Ip (com.cloud.utils.net.Ip)2 ArrayList (java.util.ArrayList)2 DataCenter (com.cloud.dc.DataCenter)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 AutoScalePolicyConditionMapVO (com.cloud.network.as.AutoScalePolicyConditionMapVO)1 AutoScaleVmGroup (com.cloud.network.as.AutoScaleVmGroup)1 AutoScaleVmGroupPolicyMapVO (com.cloud.network.as.AutoScaleVmGroupPolicyMapVO)1 AutoScaleVmGroupVO (com.cloud.network.as.AutoScaleVmGroupVO)1 NetworkVO (com.cloud.network.dao.NetworkVO)1 LbDestination (com.cloud.network.lb.LoadBalancingRule.LbDestination)1