Search in sources :

Example 86 with LoadBalancerVO

use of com.cloud.network.dao.LoadBalancerVO in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method searchForLBStickinessPolicies.

@Override
public List<LBStickinessPolicyVO> searchForLBStickinessPolicies(ListLBStickinessPoliciesCmd cmd) throws PermissionDeniedException {
    Account caller = CallContext.current().getCallingAccount();
    Long loadBalancerId = cmd.getLbRuleId();
    Long stickinessId = cmd.getId();
    boolean forDisplay = cmd.getDisplay();
    LoadBalancerVO loadBalancer = null;
    if (loadBalancerId == null) {
        loadBalancer = findLbByStickinessId(stickinessId);
    } else {
        loadBalancer = _lbDao.findById(loadBalancerId);
    }
    if (loadBalancer == null) {
        return null;
    }
    _accountMgr.checkAccess(caller, null, true, loadBalancer);
    List<LBStickinessPolicyVO> sDbpolicies = _lb2stickinesspoliciesDao.listByLoadBalancerIdAndDisplayFlag(loadBalancer.getId(), forDisplay);
    return sDbpolicies;
}
Also used : Account(com.cloud.user.Account) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) LBStickinessPolicyVO(com.cloud.network.dao.LBStickinessPolicyVO)

Example 87 with LoadBalancerVO

use of com.cloud.network.dao.LoadBalancerVO in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method validateHealthCheck.

private boolean validateHealthCheck(CreateLBHealthCheckPolicyCmd cmd) {
    LoadBalancerVO loadBalancer = _lbDao.findById(cmd.getLbRuleId());
    String capability = getLBCapability(loadBalancer.getNetworkId(), Capability.HealthCheckPolicy.getName());
    if (capability != null) {
        return true;
    }
    return false;
}
Also used : LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO)

Example 88 with LoadBalancerVO

use of com.cloud.network.dao.LoadBalancerVO in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method deleteLBHealthCheckPolicy.

@DB
@Override
@ActionEvent(eventType = EventTypes.EVENT_LB_HEALTHCHECKPOLICY_DELETE, eventDescription = "revoking LB HealthCheck policy ", async = true)
public boolean deleteLBHealthCheckPolicy(long healthCheckPolicyId, boolean apply) {
    boolean success = true;
    CallContext caller = CallContext.current();
    LBHealthCheckPolicyVO healthCheckPolicy = _lb2healthcheckDao.findById(healthCheckPolicyId);
    if (healthCheckPolicy == null) {
        throw new InvalidParameterException("Invalid HealthCheck policy id value: " + healthCheckPolicyId);
    }
    LoadBalancerVO loadBalancer = _lbDao.findById(Long.valueOf(healthCheckPolicy.getLoadBalancerId()));
    if (loadBalancer == null) {
        throw new InvalidParameterException("Invalid Load balancer : " + healthCheckPolicy.getLoadBalancerId() + " for HealthCheck policy id: " + healthCheckPolicyId);
    }
    final long loadBalancerId = loadBalancer.getId();
    FirewallRule.State backupState = loadBalancer.getState();
    _accountMgr.checkAccess(caller.getCallingAccount(), null, true, loadBalancer);
    if (apply) {
        if (loadBalancer.getState() == FirewallRule.State.Active) {
            loadBalancer.setState(FirewallRule.State.Add);
            _lbDao.persist(loadBalancer);
        }
        boolean backupStickyState = healthCheckPolicy.isRevoke();
        healthCheckPolicy.setRevoke(true);
        _lb2healthcheckDao.persist(healthCheckPolicy);
        s_logger.debug("Set health check policy to revoke for loadbalancing rule id : " + loadBalancerId + ", healthCheckpolicyID " + healthCheckPolicyId);
        // removing the state of services set by the monitor.
        final List<LoadBalancerVMMapVO> maps = _lb2VmMapDao.listByLoadBalancerId(loadBalancerId);
        if (maps != null) {
            Transaction.execute(new TransactionCallbackNoReturn() {

                @Override
                public void doInTransactionWithoutResult(TransactionStatus status) {
                    s_logger.debug("Resetting health state policy for services in loadbalancing rule id : " + loadBalancerId);
                    for (LoadBalancerVMMapVO map : maps) {
                        map.setState(null);
                        _lb2VmMapDao.persist(map);
                    }
                }
            });
        }
        try {
            if (!applyLoadBalancerConfig(loadBalancerId)) {
                s_logger.warn("Failed to remove load balancer rule id " + loadBalancerId + " for healthCheckpolicyID " + healthCheckPolicyId);
                throw new CloudRuntimeException("Failed to remove load balancer rule id " + loadBalancerId + " for healthCheckpolicyID " + healthCheckPolicyId);
            }
        } catch (ResourceUnavailableException e) {
            if (isRollBackAllowedForProvider(loadBalancer)) {
                healthCheckPolicy.setRevoke(backupStickyState);
                _lb2healthcheckDao.persist(healthCheckPolicy);
                loadBalancer.setState(backupState);
                _lbDao.persist(loadBalancer);
                s_logger.debug("LB Rollback rule id: " + loadBalancer.getId() + "  while deleting healthcheck policy: " + healthCheckPolicyId);
            }
            s_logger.warn("Unable to apply the load balancer config because resource is unavaliable.", e);
            success = false;
        }
    } else {
        _lb2healthcheckDao.remove(healthCheckPolicy.getLoadBalancerId());
    }
    return success;
}
Also used : LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) LBHealthCheckPolicyVO(com.cloud.network.LBHealthCheckPolicyVO) CallContext(org.apache.cloudstack.context.CallContext) InvalidParameterException(java.security.InvalidParameterException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) LoadBalancerVMMapVO(com.cloud.network.dao.LoadBalancerVMMapVO) FirewallRule(com.cloud.network.rules.FirewallRule) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 89 with LoadBalancerVO

use of com.cloud.network.dao.LoadBalancerVO in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method genericValidator.

private boolean genericValidator(CreateLBStickinessPolicyCmd cmd) throws InvalidParameterValueException {
    LoadBalancerVO loadBalancer = _lbDao.findById(cmd.getLbRuleId());
    /* Validation : check for valid Method name and params */
    List<LbStickinessMethod> stickinessMethodList = getStickinessMethods(loadBalancer.getNetworkId());
    boolean methodMatch = false;
    if (stickinessMethodList == null) {
        throw new InvalidParameterValueException("Failed:  No Stickiness method available for LB rule:" + cmd.getLbRuleId());
    }
    for (LbStickinessMethod method : stickinessMethodList) {
        if (method.getMethodName().equalsIgnoreCase(cmd.getStickinessMethodName())) {
            methodMatch = true;
            Map apiParamList = cmd.getparamList();
            List<LbStickinessMethodParam> methodParamList = method.getParamList();
            Map<String, String> tempParamList = new HashMap<String, String>();
            /*
                 * validation-1: check for any extra params that are not
                 * required by the policymethod(capability), FIXME: make the
                 * below loop simple without using raw data type
                 */
            if (apiParamList != null) {
                Collection userGroupCollection = apiParamList.values();
                Iterator iter = userGroupCollection.iterator();
                while (iter.hasNext()) {
                    HashMap<String, String> paramKVpair = (HashMap) iter.next();
                    String paramName = paramKVpair.get("name");
                    String paramValue = paramKVpair.get("value");
                    tempParamList.put(paramName, paramValue);
                    Boolean found = false;
                    for (LbStickinessMethodParam param : methodParamList) {
                        if (param.getParamName().equalsIgnoreCase(paramName)) {
                            if ((param.getIsflag() == false) && (paramValue == null)) {
                                throw new InvalidParameterValueException("Failed : Value expected for the Param :" + param.getParamName());
                            }
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        throw new InvalidParameterValueException("Failed : Stickiness policy does not support param name :" + paramName);
                    }
                }
            }
            /* validation-2: check for mandatory params */
            for (LbStickinessMethodParam param : methodParamList) {
                if (param.getRequired()) {
                    if (tempParamList.get(param.getParamName()) == null) {
                        throw new InvalidParameterValueException("Failed : Missing Manadatory Param :" + param.getParamName());
                    }
                }
            }
            /* Successfully completed the Validation */
            break;
        }
    }
    if (methodMatch == false) {
        throw new InvalidParameterValueException("Failed to match Stickiness method name for LB rule:" + cmd.getLbRuleId());
    }
    /* Validation : check for the multiple policies to the rule id */
    List<LBStickinessPolicyVO> stickinessPolicies = _lb2stickinesspoliciesDao.listByLoadBalancerId(cmd.getLbRuleId(), false);
    if (stickinessPolicies.size() > 1) {
        throw new InvalidParameterValueException("Failed to create Stickiness policy: Already two policies attached " + cmd.getLbRuleId());
    }
    return true;
}
Also used : HashMap(java.util.HashMap) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) LBStickinessPolicyVO(com.cloud.network.dao.LBStickinessPolicyVO) LbStickinessMethod(com.cloud.network.rules.LbStickinessMethod) LbStickinessMethodParam(com.cloud.network.rules.LbStickinessMethod.LbStickinessMethodParam) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Iterator(java.util.Iterator) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap)

Example 90 with LoadBalancerVO

use of com.cloud.network.dao.LoadBalancerVO in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method removeCertFromLoadBalancer.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_LB_CERT_REMOVE, eventDescription = "removing certificate from load balancer", async = true)
public boolean removeCertFromLoadBalancer(long lbRuleId) {
    CallContext caller = CallContext.current();
    LoadBalancerVO loadBalancer = _lbDao.findById(lbRuleId);
    LoadBalancerCertMapVO lbCertMap = _lbCertMapDao.findByLbRuleId(lbRuleId);
    if (loadBalancer == null) {
        throw new InvalidParameterException("Invalid load balancer value: " + lbRuleId);
    }
    if (lbCertMap == null) {
        throw new InvalidParameterException("No certificate is bound to lb with id: " + lbRuleId);
    }
    _accountMgr.checkAccess(caller.getCallingAccount(), null, true, loadBalancer);
    boolean success = false;
    FirewallRule.State backupState = loadBalancer.getState();
    try {
        loadBalancer.setState(FirewallRule.State.Add);
        _lbDao.persist(loadBalancer);
        lbCertMap.setRevoke(true);
        _lbCertMapDao.persist(lbCertMap);
        if (!applyLoadBalancerConfig(lbRuleId)) {
            s_logger.warn("Failed to remove cert from load balancer rule id " + lbRuleId);
            CloudRuntimeException ex = new CloudRuntimeException("Failed to remove certificate load balancer rule id " + lbRuleId);
            ex.addProxyObject(loadBalancer.getUuid(), "loadBalancerId");
            throw ex;
        }
        success = true;
    } catch (ResourceUnavailableException e) {
        if (isRollBackAllowedForProvider(loadBalancer)) {
            lbCertMap.setRevoke(false);
            _lbCertMapDao.persist(lbCertMap);
            loadBalancer.setState(backupState);
            _lbDao.persist(loadBalancer);
            s_logger.debug("Rolled back certificate removal lb id " + lbRuleId);
        }
        s_logger.warn("Unable to apply the load balancer config because resource is unavaliable.", e);
        if (!success) {
            CloudRuntimeException ex = new CloudRuntimeException("Failed to remove certificate from load balancer rule id " + lbRuleId);
            ex.addProxyObject(loadBalancer.getUuid(), "loadBalancerId");
            throw ex;
        }
    }
    return success;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) LoadBalancerCertMapVO(com.cloud.network.dao.LoadBalancerCertMapVO) CallContext(org.apache.cloudstack.context.CallContext) FirewallRule(com.cloud.network.rules.FirewallRule) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Aggregations

LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)96 ArrayList (java.util.ArrayList)45 ActionEvent (com.cloud.event.ActionEvent)31 Account (com.cloud.user.Account)30 DB (com.cloud.utils.db.DB)30 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)29 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)27 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)23 LoadBalancerVMMapVO (com.cloud.network.dao.LoadBalancerVMMapVO)23 InvalidParameterException (java.security.InvalidParameterException)22 FirewallRule (com.cloud.network.rules.FirewallRule)21 Ip (com.cloud.utils.net.Ip)18 List (java.util.List)17 NetworkVO (com.cloud.network.dao.NetworkVO)15 TransactionStatus (com.cloud.utils.db.TransactionStatus)14 IPAddressVO (com.cloud.network.dao.IPAddressVO)13 LoadBalancerDao (com.cloud.network.dao.LoadBalancerDao)13 LbDestination (com.cloud.network.lb.LoadBalancingRule.LbDestination)13 LbHealthCheckPolicy (com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy)13 HashMap (java.util.HashMap)13