Search in sources :

Example 1 with LBHealthCheckResponse

use of com.cloud.api.response.LBHealthCheckResponse in project cosmic by MissionCriticalCloud.

the class UpdateLBHealthCheckPolicyCmd method execute.

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

Example 2 with LBHealthCheckResponse

use of com.cloud.api.response.LBHealthCheckResponse in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createLBHealthCheckPolicyResponse.

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

Example 3 with LBHealthCheckResponse

use of com.cloud.api.response.LBHealthCheckResponse in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createLBHealthCheckPolicyResponse.

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

Example 4 with LBHealthCheckResponse

use of com.cloud.api.response.LBHealthCheckResponse 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.network.rules.LoadBalancer) LBHealthCheckResponse(com.cloud.api.response.LBHealthCheckResponse) HealthCheckPolicy(com.cloud.network.rules.HealthCheckPolicy)

Example 5 with LBHealthCheckResponse

use of com.cloud.api.response.LBHealthCheckResponse in project cosmic by MissionCriticalCloud.

the class ListLBHealthCheckPoliciesCmd method execute.

@Override
public void execute() {
    final List<LBHealthCheckResponse> hcpResponses = new ArrayList<>();
    final ListResponse<LBHealthCheckResponse> response = new ListResponse<>();
    Long lbRuleId = getLbRuleId();
    final 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");
        }
    }
    final LoadBalancer lb = _lbService.findById(lbRuleId);
    if (lb != null) {
        final List<? extends HealthCheckPolicy> healthCheckPolicies = _lbService.searchForLBHealthCheckPolicies(this);
        final LBHealthCheckResponse spResponse = _responseGenerator.createLBHealthCheckPolicyResponse(healthCheckPolicies, lb);
        hcpResponses.add(spResponse);
        response.setResponses(hcpResponses);
    }
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(com.cloud.api.response.ListResponse) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) LoadBalancer(com.cloud.network.rules.LoadBalancer) LBHealthCheckResponse(com.cloud.api.response.LBHealthCheckResponse)

Aggregations

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