Search in sources :

Example 1 with LoadBalancerResponse

use of org.apache.cloudstack.api.response.LoadBalancerResponse 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 2 with LoadBalancerResponse

use of org.apache.cloudstack.api.response.LoadBalancerResponse 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 3 with LoadBalancerResponse

use of org.apache.cloudstack.api.response.LoadBalancerResponse in project cloudstack by apache.

the class CreateLoadBalancerRuleCmd method execute.

@Override
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
    CallContext callerContext = CallContext.current();
    boolean success = true;
    LoadBalancer rule = null;
    try {
        CallContext.current().setEventDetails("Rule Id: " + getEntityId());
        if (getOpenFirewall()) {
            success = success && _firewallService.applyIngressFirewallRules(getSourceIpAddressId(), callerContext.getCallingAccount());
        }
        // 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(ApiErrorCode.INTERNAL_ERROR, "Failed to create load balancer rule");
        }
    }
}
Also used : LoadBalancerResponse(org.apache.cloudstack.api.response.LoadBalancerResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) LoadBalancer(com.cloud.network.rules.LoadBalancer) CallContext(org.apache.cloudstack.context.CallContext) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException)

Example 4 with LoadBalancerResponse

use of org.apache.cloudstack.api.response.LoadBalancerResponse in project cloudstack by apache.

the class ListLoadBalancerRulesCmd method execute.

@Override
public void execute() {
    Pair<List<? extends LoadBalancer>, Integer> loadBalancers = _lbService.searchForLoadBalancers(this);
    ListResponse<LoadBalancerResponse> response = new ListResponse<LoadBalancerResponse>();
    List<LoadBalancerResponse> lbResponses = new ArrayList<LoadBalancerResponse>();
    if (loadBalancers != null) {
        for (LoadBalancer loadBalancer : loadBalancers.first()) {
            LoadBalancerResponse lbResponse = _responseGenerator.createLoadBalancerResponse(loadBalancer);
            lbResponse.setObjectName("loadbalancerrule");
            lbResponses.add(lbResponse);
        }
        response.setResponses(lbResponses, loadBalancers.second());
    }
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : LoadBalancerResponse(org.apache.cloudstack.api.response.LoadBalancerResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) LoadBalancer(com.cloud.network.rules.LoadBalancer) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with LoadBalancerResponse

use of org.apache.cloudstack.api.response.LoadBalancerResponse in project cloudstack by apache.

the class ApiResponseHelper method createLoadBalancerResponse.

@Override
public LoadBalancerResponse createLoadBalancerResponse(LoadBalancer loadBalancer) {
    LoadBalancerResponse lbResponse = new LoadBalancerResponse();
    lbResponse.setId(loadBalancer.getUuid());
    lbResponse.setName(loadBalancer.getName());
    lbResponse.setDescription(loadBalancer.getDescription());
    List<String> cidrs = ApiDBUtils.findFirewallSourceCidrs(loadBalancer.getId());
    lbResponse.setCidrList(StringUtils.join(cidrs, ","));
    IPAddressVO publicIp = ApiDBUtils.findIpAddressById(loadBalancer.getSourceIpAddressId());
    lbResponse.setPublicIpId(publicIp.getUuid());
    lbResponse.setPublicIp(publicIp.getAddress().addr());
    lbResponse.setPublicPort(Integer.toString(loadBalancer.getSourcePortStart()));
    lbResponse.setPrivatePort(Integer.toString(loadBalancer.getDefaultPortStart()));
    lbResponse.setAlgorithm(loadBalancer.getAlgorithm());
    lbResponse.setLbProtocol(loadBalancer.getLbProtocol());
    lbResponse.setForDisplay(loadBalancer.isDisplay());
    FirewallRule.State state = loadBalancer.getState();
    String stateToSet = state.toString();
    if (state.equals(FirewallRule.State.Revoke)) {
        stateToSet = "Deleting";
    }
    lbResponse.setState(stateToSet);
    populateOwner(lbResponse, loadBalancer);
    DataCenter zone = ApiDBUtils.findZoneById(publicIp.getDataCenterId());
    if (zone != null) {
        lbResponse.setZoneId(zone.getUuid());
        lbResponse.setZoneName(zone.getName());
    }
    // set tag information
    List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.LoadBalancer, loadBalancer.getId());
    List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
    for (ResourceTag tag : tags) {
        ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    lbResponse.setTags(tagResponses);
    Network ntwk = ApiDBUtils.findNetworkById(loadBalancer.getNetworkId());
    lbResponse.setNetworkId(ntwk.getUuid());
    lbResponse.setObjectName("loadbalancer");
    return lbResponse;
}
Also used : ArrayList(java.util.ArrayList) GlobalLoadBalancerResponse(org.apache.cloudstack.api.response.GlobalLoadBalancerResponse) ApplicationLoadBalancerResponse(org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse) LoadBalancerResponse(org.apache.cloudstack.api.response.LoadBalancerResponse) DataCenter(com.cloud.dc.DataCenter) ResourceTag(com.cloud.server.ResourceTag) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse) IPAddressVO(com.cloud.network.dao.IPAddressVO) FirewallRule(com.cloud.network.rules.FirewallRule)

Aggregations

LoadBalancerResponse (org.apache.cloudstack.api.response.LoadBalancerResponse)5 LoadBalancer (com.cloud.network.rules.LoadBalancer)4 ArrayList (java.util.ArrayList)3 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 ApplicationLoadBalancerResponse (org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse)2 GlobalLoadBalancerResponse (org.apache.cloudstack.api.response.GlobalLoadBalancerResponse)2 DataCenter (com.cloud.dc.DataCenter)1 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)1 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 Network (com.cloud.network.Network)1 PhysicalNetwork (com.cloud.network.PhysicalNetwork)1 IPAddressVO (com.cloud.network.dao.IPAddressVO)1 FirewallRule (com.cloud.network.rules.FirewallRule)1 ResourceTag (com.cloud.server.ResourceTag)1 List (java.util.List)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 ResourceTagResponse (org.apache.cloudstack.api.response.ResourceTagResponse)1