Search in sources :

Example 46 with LoadBalancerVO

use of com.cloud.network.dao.LoadBalancerVO in project cosmic by MissionCriticalCloud.

the class LoadBalancingRulesManagerImpl method deleteLoadBalancerRule.

@Override
@ActionEvent(eventType = EventTypes.EVENT_LOAD_BALANCER_DELETE, eventDescription = "deleting load balancer", async = true)
public boolean deleteLoadBalancerRule(final long loadBalancerId, final boolean apply) {
    final CallContext ctx = CallContext.current();
    final Account caller = ctx.getCallingAccount();
    final LoadBalancerVO rule = _lbDao.findById(loadBalancerId);
    if (rule == null) {
        throw new InvalidParameterValueException("Unable to find load balancer rule " + loadBalancerId);
    }
    _accountMgr.checkAccess(caller, null, true, rule);
    final boolean result = deleteLoadBalancerRule(loadBalancerId, apply, caller, ctx.getCallingUserId(), true);
    if (!result) {
        throw new CloudRuntimeException("Unable to remove load balancer rule " + loadBalancerId);
    }
    return result;
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) CallContext(com.cloud.context.CallContext) ActionEvent(com.cloud.event.ActionEvent)

Example 47 with LoadBalancerVO

use of com.cloud.network.dao.LoadBalancerVO in project cosmic by MissionCriticalCloud.

the class LoadBalancingRulesManagerImpl method validateHealthCheck.

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

Example 48 with LoadBalancerVO

use of com.cloud.network.dao.LoadBalancerVO in project cosmic by MissionCriticalCloud.

the class LoadBalancingRulesManagerImpl method deleteLBHealthCheckPolicy.

@DB
@Override
@ActionEvent(eventType = EventTypes.EVENT_LB_HEALTHCHECKPOLICY_DELETE, eventDescription = "revoking LB HealthCheck policy ", async = true)
public boolean deleteLBHealthCheckPolicy(final long healthCheckPolicyId, final boolean apply) {
    boolean success = true;
    final CallContext caller = CallContext.current();
    final LBHealthCheckPolicyVO healthCheckPolicy = _lb2healthcheckDao.findById(healthCheckPolicyId);
    if (healthCheckPolicy == null) {
        throw new InvalidParameterException("Invalid HealthCheck policy id value: " + healthCheckPolicyId);
    }
    final 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();
    final 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);
        }
        final 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(final TransactionStatus status) {
                    s_logger.debug("Resetting health state policy for services in loadbalancing rule id : " + loadBalancerId);
                    for (final 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 (final 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(com.cloud.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 49 with LoadBalancerVO

use of com.cloud.network.dao.LoadBalancerVO in project cosmic by MissionCriticalCloud.

the class LoadBalancingRulesManagerImpl method assignSSLCertToLoadBalancerRule.

@Override
public boolean assignSSLCertToLoadBalancerRule(final Long lbId, final String certName, final String publicCert, final String privateKey) {
    s_logger.error("Calling the manager for LB");
    final LoadBalancerVO loadBalancer = _lbDao.findById(lbId);
    // TODO
    return false;
}
Also used : LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO)

Example 50 with LoadBalancerVO

use of com.cloud.network.dao.LoadBalancerVO in project cosmic by MissionCriticalCloud.

the class LoadBalancingRulesManagerImpl method searchForLBStickinessPolicies.

@Override
public List<LBStickinessPolicyVO> searchForLBStickinessPolicies(final ListLBStickinessPoliciesCmd cmd) throws PermissionDeniedException {
    final Account caller = CallContext.current().getCallingAccount();
    final Long loadBalancerId = cmd.getLbRuleId();
    final Long stickinessId = cmd.getId();
    final 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);
    final 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)

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