Search in sources :

Example 6 with LoadBalancer

use of com.cloud.legacymodel.network.LoadBalancer in project cosmic by MissionCriticalCloud.

the class CreateLBHealthCheckPolicyCmd method execute.

@Override
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
    HealthCheckPolicy policy = null;
    boolean success = false;
    try {
        CallContext.current().setEventDetails("Load balancer health check policy ID : " + getEntityId());
        success = _lbService.applyLBHealthCheckPolicy(this);
        if (success) {
            // State might be different after the rule is applied, so get new object here
            policy = _entityMgr.findById(HealthCheckPolicy.class, getEntityId());
            final LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
            final LBHealthCheckResponse hcResponse = _responseGenerator.createLBHealthCheckPolicyResponse(policy, lb);
            setResponseObject(hcResponse);
            hcResponse.setResponseName(getCommandName());
        }
    } finally {
        if (!success || (policy == null)) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create health check policy");
        }
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) LoadBalancer(com.cloud.legacymodel.network.LoadBalancer) LBHealthCheckResponse(com.cloud.api.response.LBHealthCheckResponse) HealthCheckPolicy(com.cloud.network.rules.HealthCheckPolicy)

Example 7 with LoadBalancer

use of com.cloud.legacymodel.network.LoadBalancer in project cosmic by MissionCriticalCloud.

the class CreateLBStickinessPolicyCmd method execute.

@Override
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
    StickinessPolicy policy = null;
    boolean success = false;
    try {
        CallContext.current().setEventDetails("Rule Id: " + getEntityId());
        success = _lbService.applyLBStickinessPolicy(this);
        if (success) {
            // State might be different after the rule is applied, so get new object here
            policy = _entityMgr.findById(StickinessPolicy.class, getEntityId());
            final LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
            final LBStickinessResponse spResponse = _responseGenerator.createLBStickinessPolicyResponse(policy, lb);
            setResponseObject(spResponse);
            spResponse.setResponseName(getCommandName());
        }
    } finally {
        if (!success || (policy == null)) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create stickiness policy");
        }
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) LoadBalancer(com.cloud.legacymodel.network.LoadBalancer) StickinessPolicy(com.cloud.network.rules.StickinessPolicy) LBStickinessResponse(com.cloud.api.response.LBStickinessResponse)

Example 8 with LoadBalancer

use of com.cloud.legacymodel.network.LoadBalancer in project cosmic by MissionCriticalCloud.

the class CreateLoadBalancerRuleCmd method create.

@Override
public void create() {
    // cidr list parameter is deprecated
    if (cidrlist != null) {
        throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall rule for the specific CIDR, please refer to createFirewallRule command");
    }
    if (lbProtocol != null && !lbProtocol.toLowerCase().startsWith("tcp")) {
        throw new InvalidParameterValueException("Only TCP protocol is supported because HAProxy can only do TCP.");
    }
    if (getAlgorithm() != null && !NetUtils.isValidAlgorithm(getAlgorithm())) {
        throw new InvalidParameterValueException("Only source/roundrobin/leastconn are supported loadbalance algorithms.");
    }
    try {
        final LoadBalancer result = _lbService.createPublicLoadBalancerRule(getXid(), getName(), getDescription(), getSourcePortStart(), getSourcePortEnd(), getDefaultPortStart(), getDefaultPortEnd(), getSourceIpAddressId(), getProtocol(), getAlgorithm(), getNetworkId(), getEntityOwnerId(), getOpenFirewall(), getLbProtocol(), isDisplay(), getClientTimeout(), getServerTimeout());
        this.setEntityId(result.getId());
        this.setEntityUuid(result.getUuid());
    } catch (final NetworkRuleConflictException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
    } catch (final InsufficientAddressCapacityException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage());
    } catch (final InvalidParameterValueException e) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) InsufficientAddressCapacityException(com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException) LoadBalancer(com.cloud.legacymodel.network.LoadBalancer) NetworkRuleConflictException(com.cloud.legacymodel.exceptions.NetworkRuleConflictException)

Example 9 with LoadBalancer

use of com.cloud.legacymodel.network.LoadBalancer in project cosmic by MissionCriticalCloud.

the class DeleteLBHealthCheckPolicyCmd method getSyncObjId.

@Override
public Long getSyncObjId() {
    final HealthCheckPolicy policy = _entityMgr.findById(HealthCheckPolicy.class, getId());
    if (policy == null) {
        throw new InvalidParameterValueException("Unable to find load balancer health check rule: " + id);
    }
    final LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
    if (lb == null) {
        throw new InvalidParameterValueException("Unable to find load balancer rule for health check rule: " + id);
    }
    return lb.getNetworkId();
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) LoadBalancer(com.cloud.legacymodel.network.LoadBalancer) HealthCheckPolicy(com.cloud.network.rules.HealthCheckPolicy)

Example 10 with LoadBalancer

use of com.cloud.legacymodel.network.LoadBalancer in project cosmic by MissionCriticalCloud.

the class DeleteLBStickinessPolicyCmd method getSyncObjId.

@Override
public Long getSyncObjId() {
    final StickinessPolicy policy = _entityMgr.findById(StickinessPolicy.class, getId());
    if (policy == null) {
        throw new InvalidParameterValueException("Unable to find LB stickiness rule: " + id);
    }
    final LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
    if (lb == null) {
        throw new InvalidParameterValueException("Unable to find load balancer rule for stickiness rule: " + id);
    }
    return lb.getNetworkId();
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) LoadBalancer(com.cloud.legacymodel.network.LoadBalancer) StickinessPolicy(com.cloud.network.rules.StickinessPolicy)

Aggregations

LoadBalancer (com.cloud.legacymodel.network.LoadBalancer)15 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)9 ServerApiException (com.cloud.api.ServerApiException)5 ArrayList (java.util.ArrayList)5 Account (com.cloud.legacymodel.user.Account)4 LBHealthCheckResponse (com.cloud.api.response.LBHealthCheckResponse)3 LBStickinessResponse (com.cloud.api.response.LBStickinessResponse)3 ListResponse (com.cloud.api.response.ListResponse)3 LoadBalancerResponse (com.cloud.api.response.LoadBalancerResponse)3 InsufficientAddressCapacityException (com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException)3 NetworkRuleConflictException (com.cloud.legacymodel.exceptions.NetworkRuleConflictException)3 HealthCheckPolicy (com.cloud.network.rules.HealthCheckPolicy)3 StickinessPolicy (com.cloud.network.rules.StickinessPolicy)3 SslCertResponse (com.cloud.api.response.SslCertResponse)2 CallContext (com.cloud.context.CallContext)2 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)2 LoadBalancerCertMapVO (com.cloud.network.dao.LoadBalancerCertMapVO)2 Project (com.cloud.projects.Project)2 DomainVO (com.cloud.domain.DomainVO)1 ActionEvent (com.cloud.event.ActionEvent)1