Search in sources :

Example 11 with LoadBalancer

use of com.cloud.network.rules.LoadBalancer in project cloudstack by apache.

the class UpdateLoadBalancerRuleCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Load balancer ID: " + getId());
    LoadBalancer result = _lbService.updateLoadBalancerRule(this);
    if (result != null) {
        LoadBalancerResponse response = _responseGenerator.createLoadBalancerResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update load balancer rule");
    }
}
Also used : LoadBalancerResponse(org.apache.cloudstack.api.response.LoadBalancerResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) LoadBalancer(com.cloud.network.rules.LoadBalancer)

Example 12 with LoadBalancer

use of com.cloud.network.rules.LoadBalancer in project cloudstack by apache.

the class ApiResponseHelper method createGlobalLoadBalancerResponse.

@Override
public GlobalLoadBalancerResponse createGlobalLoadBalancerResponse(GlobalLoadBalancerRule globalLoadBalancerRule) {
    GlobalLoadBalancerResponse response = new GlobalLoadBalancerResponse();
    response.setAlgorithm(globalLoadBalancerRule.getAlgorithm());
    response.setStickyMethod(globalLoadBalancerRule.getPersistence());
    response.setServiceType(globalLoadBalancerRule.getServiceType());
    response.setServiceDomainName(globalLoadBalancerRule.getGslbDomain() + "." + ApiDBUtils.getDnsNameConfiguredForGslb());
    response.setName(globalLoadBalancerRule.getName());
    response.setDescription(globalLoadBalancerRule.getDescription());
    response.setRegionIdId(globalLoadBalancerRule.getRegion());
    response.setId(globalLoadBalancerRule.getUuid());
    populateOwner(response, globalLoadBalancerRule);
    response.setObjectName("globalloadbalancer");
    List<LoadBalancerResponse> siteLbResponses = new ArrayList<LoadBalancerResponse>();
    List<? extends LoadBalancer> siteLoadBalaners = ApiDBUtils.listSiteLoadBalancers(globalLoadBalancerRule.getId());
    for (LoadBalancer siteLb : siteLoadBalaners) {
        LoadBalancerResponse siteLbResponse = createLoadBalancerResponse(siteLb);
        siteLbResponses.add(siteLbResponse);
    }
    response.setSiteLoadBalancers(siteLbResponses);
    return response;
}
Also used : GlobalLoadBalancerResponse(org.apache.cloudstack.api.response.GlobalLoadBalancerResponse) GlobalLoadBalancerResponse(org.apache.cloudstack.api.response.GlobalLoadBalancerResponse) ApplicationLoadBalancerResponse(org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse) LoadBalancerResponse(org.apache.cloudstack.api.response.LoadBalancerResponse) ArrayList(java.util.ArrayList) LoadBalancer(com.cloud.network.rules.LoadBalancer)

Example 13 with LoadBalancer

use of com.cloud.network.rules.LoadBalancer in project cloudstack by apache.

the class CertServiceImpl method createCertResponse.

public SslCertResponse createCertResponse(final SslCertVO cert, final List<LoadBalancerCertMapVO> lbCertMap) {
    Preconditions.checkNotNull(cert);
    final SslCertResponse response = new SslCertResponse();
    final Account account = _accountDao.findByIdIncludingRemoved(cert.getAccountId());
    if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
        // find the project
        final Project project = _projectMgr.findByProjectAccountIdIncludingRemoved(account.getId());
        if (project != null) {
            response.setProjectId(project.getUuid());
            response.setProjectName(project.getName());
        } else {
            response.setAccountName(account.getAccountName());
        }
    } else {
        response.setAccountName(account.getAccountName());
    }
    final DomainVO domain = _domainDao.findByIdIncludingRemoved(cert.getDomainId());
    response.setDomainId(domain.getUuid());
    response.setDomainName(domain.getName());
    response.setObjectName("sslcert");
    response.setId(cert.getUuid());
    response.setCertificate(cert.getCertificate());
    response.setFingerprint(cert.getFingerPrint());
    if (cert.getChain() != null) {
        response.setCertchain(cert.getChain());
    }
    if (lbCertMap != null && !lbCertMap.isEmpty()) {
        final List<String> lbIds = new ArrayList<String>();
        for (final LoadBalancerCertMapVO mapVO : lbCertMap) {
            final LoadBalancer lb = _entityMgr.findById(LoadBalancerVO.class, mapVO.getLbId());
            if (lb != null) {
                lbIds.add(lb.getUuid());
            }
        }
        response.setLbIds(lbIds);
    }
    return response;
}
Also used : Account(com.cloud.user.Account) Project(com.cloud.projects.Project) DomainVO(com.cloud.domain.DomainVO) ArrayList(java.util.ArrayList) LoadBalancerCertMapVO(com.cloud.network.dao.LoadBalancerCertMapVO) LoadBalancer(com.cloud.network.rules.LoadBalancer) SslCertResponse(org.apache.cloudstack.api.response.SslCertResponse)

Example 14 with LoadBalancer

use of com.cloud.network.rules.LoadBalancer in project CloudStack-archive by CloudStack-extras.

the class CreateLBStickinessPolicyCmd method execute.

@Override
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
    StickinessPolicy policy = null;
    boolean success = false;
    try {
        UserContext.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());
            LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
            LBStickinessResponse spResponse = _responseGenerator.createLBStickinessPolicyResponse(policy, lb);
            setResponseObject(spResponse);
            spResponse.setResponseName(getCommandName());
        }
    } finally {
        if (!success || (policy == null)) {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create stickiness policy ");
        }
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) LoadBalancer(com.cloud.network.rules.LoadBalancer) StickinessPolicy(com.cloud.network.rules.StickinessPolicy) LBStickinessResponse(com.cloud.api.response.LBStickinessResponse)

Example 15 with LoadBalancer

use of com.cloud.network.rules.LoadBalancer in project CloudStack-archive by CloudStack-extras.

the class CreateLoadBalancerRuleCmd method execute.

@Override
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
    UserContext callerContext = UserContext.current();
    boolean success = true;
    LoadBalancer rule = null;
    try {
        UserContext.current().setEventDetails("Rule Id: " + getEntityId());
        if (getOpenFirewall()) {
            success = success && _firewallService.applyFirewallRules(getSourceIpAddressId(), callerContext.getCaller());
        }
        // State might be different after the rule is applied, so get new object here
        rule = _entityMgr.findById(LoadBalancer.class, getEntityId());
        LoadBalancerResponse lbResponse = new LoadBalancerResponse();
        if (rule != null) {
            lbResponse = _responseGenerator.createLoadBalancerResponse(rule);
            setResponseObject(lbResponse);
        }
        lbResponse.setResponseName(getCommandName());
    } catch (Exception ex) {
        s_logger.warn("Failed to create LB rule due to exception ", ex);
    } finally {
        if (!success || rule == null) {
            if (getOpenFirewall()) {
                _firewallService.revokeRelatedFirewallRule(getEntityId(), true);
            }
            // no need to apply the rule on the backend as it exists in the db only
            _lbService.deleteLoadBalancerRule(getEntityId(), false);
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create load balancer rule");
        }
    }
}
Also used : LoadBalancerResponse(com.cloud.api.response.LoadBalancerResponse) ServerApiException(com.cloud.api.ServerApiException) UserContext(com.cloud.user.UserContext) LoadBalancer(com.cloud.network.rules.LoadBalancer) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ServerApiException(com.cloud.api.ServerApiException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException)

Aggregations

LoadBalancer (com.cloud.network.rules.LoadBalancer)26 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)12 ArrayList (java.util.ArrayList)9 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)6 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)5 StickinessPolicy (com.cloud.network.rules.StickinessPolicy)5 Account (com.cloud.user.Account)5 ServerApiException (org.apache.cloudstack.api.ServerApiException)5 ServerApiException (com.cloud.api.ServerApiException)4 LoadBalancerResponse (org.apache.cloudstack.api.response.LoadBalancerResponse)4 LoadBalancerResponse (com.cloud.api.response.LoadBalancerResponse)3 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)3 HealthCheckPolicy (com.cloud.network.rules.HealthCheckPolicy)3 LBHealthCheckResponse (org.apache.cloudstack.api.response.LBHealthCheckResponse)3 LBStickinessResponse (org.apache.cloudstack.api.response.LBStickinessResponse)3 ListResponse (org.apache.cloudstack.api.response.ListResponse)3 LBStickinessResponse (com.cloud.api.response.LBStickinessResponse)2 ListResponse (com.cloud.api.response.ListResponse)2 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)2 Network (com.cloud.network.Network)2