Search in sources :

Example 6 with LBStickinessPolicyVO

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

the class LoadBalancingRulesManagerImpl method getStickinessPolicies.

@Override
public List<LbStickinessPolicy> getStickinessPolicies(long lbId) {
    List<LbStickinessPolicy> stickinessPolicies = new ArrayList<LbStickinessPolicy>();
    List<LBStickinessPolicyVO> sDbpolicies = _lb2stickinesspoliciesDao.listByLoadBalancerId(lbId, false);
    for (LBStickinessPolicyVO sDbPolicy : sDbpolicies) {
        LbStickinessPolicy sPolicy = new LbStickinessPolicy(sDbPolicy.getMethodName(), sDbPolicy.getParams(), sDbPolicy.isRevoke());
        stickinessPolicies.add(sPolicy);
    }
    return stickinessPolicies;
}
Also used : ArrayList(java.util.ArrayList) LbStickinessPolicy(com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy) LBStickinessPolicyVO(com.cloud.network.dao.LBStickinessPolicyVO)

Example 7 with LBStickinessPolicyVO

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

the class LoadBalancingRulesManagerImpl method createLBStickinessPolicy.

@SuppressWarnings("rawtypes")
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_LB_STICKINESSPOLICY_CREATE, eventDescription = "create lb stickinesspolicy to load balancer", create = true)
public StickinessPolicy createLBStickinessPolicy(CreateLBStickinessPolicyCmd cmd) throws NetworkRuleConflictException {
    CallContext caller = CallContext.current();
    /* Validation : check corresponding load balancer rule exist */
    LoadBalancerVO loadBalancer = _lbDao.findById(cmd.getLbRuleId());
    if (loadBalancer == null) {
        throw new InvalidParameterValueException("Failed: LB rule id: " + cmd.getLbRuleId() + " not present ");
    }
    _accountMgr.checkAccess(caller.getCallingAccount(), null, true, loadBalancer);
    if (loadBalancer.getState() == FirewallRule.State.Revoke) {
        throw new InvalidParameterValueException("Failed:  LB rule id: " + cmd.getLbRuleId() + " is in deleting state: ");
    }
    /* Generic validations */
    if (!genericValidator(cmd)) {
        throw new InvalidParameterValueException("Failed to create Stickiness policy: Validation Failed " + cmd.getLbRuleId());
    }
    /*
         * Specific validations using network element validator for specific
         * validations
         */
    LBStickinessPolicyVO lbpolicy = new LBStickinessPolicyVO(loadBalancer.getId(), cmd.getLBStickinessPolicyName(), cmd.getStickinessMethodName(), cmd.getparamList(), cmd.getDescription());
    List<LbStickinessPolicy> policyList = new ArrayList<LbStickinessPolicy>();
    policyList.add(new LbStickinessPolicy(cmd.getStickinessMethodName(), lbpolicy.getParams()));
    Ip sourceIp = getSourceIp(loadBalancer);
    LoadBalancingRule lbRule = new LoadBalancingRule(loadBalancer, getExistingDestinations(lbpolicy.getId()), policyList, null, sourceIp, null, loadBalancer.getLbProtocol());
    if (!validateLbRule(lbRule)) {
        throw new InvalidParameterValueException("Failed to create Stickiness policy: Validation Failed " + cmd.getLbRuleId());
    }
    /* Finally Insert into DB */
    LBStickinessPolicyVO policy = new LBStickinessPolicyVO(loadBalancer.getId(), cmd.getLBStickinessPolicyName(), cmd.getStickinessMethodName(), cmd.getparamList(), cmd.getDescription());
    Boolean forDisplay = cmd.getDisplay();
    if (forDisplay != null) {
        policy.setDisplay(forDisplay);
    }
    policy = _lb2stickinesspoliciesDao.persist(policy);
    return policy;
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Ip(com.cloud.utils.net.Ip) PublicIp(com.cloud.network.addr.PublicIp) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) ArrayList(java.util.ArrayList) LBStickinessPolicyVO(com.cloud.network.dao.LBStickinessPolicyVO) LbStickinessPolicy(com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy) CallContext(org.apache.cloudstack.context.CallContext) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Aggregations

LBStickinessPolicyVO (com.cloud.network.dao.LBStickinessPolicyVO)7 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)6 ActionEvent (com.cloud.event.ActionEvent)4 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)3 InvalidParameterException (java.security.InvalidParameterException)3 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 LbStickinessPolicy (com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy)2 FirewallRule (com.cloud.network.rules.FirewallRule)2 DB (com.cloud.utils.db.DB)2 ArrayList (java.util.ArrayList)2 CallContext (org.apache.cloudstack.context.CallContext)2 PublicIp (com.cloud.network.addr.PublicIp)1 LbStickinessMethod (com.cloud.network.rules.LbStickinessMethod)1 LbStickinessMethodParam (com.cloud.network.rules.LbStickinessMethod.LbStickinessMethodParam)1 Account (com.cloud.user.Account)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 Ip (com.cloud.utils.net.Ip)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1