Search in sources :

Example 1 with LBHealthCheckResponse

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

the class ListLBHealthCheckPoliciesCmd method execute.

@Override
public void execute() {
    List<LBHealthCheckResponse> hcpResponses = new ArrayList<LBHealthCheckResponse>();
    ListResponse<LBHealthCheckResponse> response = new ListResponse<LBHealthCheckResponse>();
    Long lbRuleId = getLbRuleId();
    Long hId = getId();
    if (lbRuleId == null) {
        if (hId != null) {
            lbRuleId = _lbService.findLBIdByHealtCheckPolicyId(hId);
        } else {
            throw new InvalidParameterValueException("Either load balancer rule ID or health check policy ID should be specified");
        }
    }
    LoadBalancer lb = _lbService.findById(lbRuleId);
    if (lb != null) {
        List<? extends HealthCheckPolicy> healthCheckPolicies = _lbService.searchForLBHealthCheckPolicies(this);
        LBHealthCheckResponse spResponse = _responseGenerator.createLBHealthCheckPolicyResponse(healthCheckPolicies, lb);
        hcpResponses.add(spResponse);
        response.setResponses(hcpResponses);
    }
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) LoadBalancer(com.cloud.network.rules.LoadBalancer) LBHealthCheckResponse(org.apache.cloudstack.api.response.LBHealthCheckResponse)

Example 2 with LBHealthCheckResponse

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

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());
            LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
            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(org.apache.cloudstack.api.ServerApiException) LoadBalancer(com.cloud.network.rules.LoadBalancer) LBHealthCheckResponse(org.apache.cloudstack.api.response.LBHealthCheckResponse) HealthCheckPolicy(com.cloud.network.rules.HealthCheckPolicy)

Example 3 with LBHealthCheckResponse

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

the class ApiResponseHelper method createLBHealthCheckPolicyResponse.

@Override
public LBHealthCheckResponse createLBHealthCheckPolicyResponse(HealthCheckPolicy healthcheckPolicy, LoadBalancer lb) {
    LBHealthCheckResponse hcResponse = new LBHealthCheckResponse();
    hcResponse.setlbRuleId(lb.getUuid());
    Account accountTemp = ApiDBUtils.findAccountById(lb.getAccountId());
    if (accountTemp != null) {
        hcResponse.setAccountName(accountTemp.getAccountName());
        Domain domain = ApiDBUtils.findDomainById(accountTemp.getDomainId());
        if (domain != null) {
            hcResponse.setDomainId(domain.getUuid());
            hcResponse.setDomainName(domain.getName());
        }
    }
    List<LBHealthCheckPolicyResponse> responses = new ArrayList<LBHealthCheckPolicyResponse>();
    LBHealthCheckPolicyResponse ruleResponse = new LBHealthCheckPolicyResponse(healthcheckPolicy);
    responses.add(ruleResponse);
    hcResponse.setRules(responses);
    hcResponse.setObjectName("healthcheckpolicies");
    return hcResponse;
}
Also used : ProjectAccount(com.cloud.projects.ProjectAccount) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) LBHealthCheckPolicyResponse(org.apache.cloudstack.api.response.LBHealthCheckPolicyResponse) ArrayList(java.util.ArrayList) LBHealthCheckResponse(org.apache.cloudstack.api.response.LBHealthCheckResponse) Domain(com.cloud.domain.Domain)

Example 4 with LBHealthCheckResponse

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

the class UpdateLBHealthCheckPolicyCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    HealthCheckPolicy policy = _lbService.updateLBHealthCheckPolicy(this.getId(), this.getCustomId(), this.getDisplay());
    LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
    LBHealthCheckResponse hcResponse = _responseGenerator.createLBHealthCheckPolicyResponse(policy, lb);
    setResponseObject(hcResponse);
    hcResponse.setResponseName(getCommandName());
}
Also used : LoadBalancer(com.cloud.network.rules.LoadBalancer) LBHealthCheckResponse(org.apache.cloudstack.api.response.LBHealthCheckResponse) HealthCheckPolicy(com.cloud.network.rules.HealthCheckPolicy)

Example 5 with LBHealthCheckResponse

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

the class ApiResponseHelper method createLBHealthCheckPolicyResponse.

@Override
public LBHealthCheckResponse createLBHealthCheckPolicyResponse(List<? extends HealthCheckPolicy> healthcheckPolicies, LoadBalancer lb) {
    LBHealthCheckResponse hcResponse = new LBHealthCheckResponse();
    if (lb == null) {
        return hcResponse;
    }
    hcResponse.setlbRuleId(lb.getUuid());
    Account account = ApiDBUtils.findAccountById(lb.getAccountId());
    if (account != null) {
        hcResponse.setAccountName(account.getAccountName());
        Domain domain = ApiDBUtils.findDomainById(account.getDomainId());
        if (domain != null) {
            hcResponse.setDomainId(domain.getUuid());
            hcResponse.setDomainName(domain.getName());
        }
    }
    List<LBHealthCheckPolicyResponse> responses = new ArrayList<LBHealthCheckPolicyResponse>();
    for (HealthCheckPolicy healthcheckPolicy : healthcheckPolicies) {
        LBHealthCheckPolicyResponse ruleResponse = new LBHealthCheckPolicyResponse(healthcheckPolicy);
        responses.add(ruleResponse);
    }
    hcResponse.setRules(responses);
    hcResponse.setObjectName("healthcheckpolicies");
    return hcResponse;
}
Also used : ProjectAccount(com.cloud.projects.ProjectAccount) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) LBHealthCheckPolicyResponse(org.apache.cloudstack.api.response.LBHealthCheckPolicyResponse) ArrayList(java.util.ArrayList) LBHealthCheckResponse(org.apache.cloudstack.api.response.LBHealthCheckResponse) Domain(com.cloud.domain.Domain) HealthCheckPolicy(com.cloud.network.rules.HealthCheckPolicy)

Aggregations

LBHealthCheckResponse (org.apache.cloudstack.api.response.LBHealthCheckResponse)5 HealthCheckPolicy (com.cloud.network.rules.HealthCheckPolicy)3 LoadBalancer (com.cloud.network.rules.LoadBalancer)3 ArrayList (java.util.ArrayList)3 Domain (com.cloud.domain.Domain)2 ProjectAccount (com.cloud.projects.ProjectAccount)2 Account (com.cloud.user.Account)2 UserAccount (com.cloud.user.UserAccount)2 LBHealthCheckPolicyResponse (org.apache.cloudstack.api.response.LBHealthCheckPolicyResponse)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 ServerApiException (org.apache.cloudstack.api.ServerApiException)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1