Search in sources :

Example 6 with HealthCheckPolicy

use of com.cloud.network.rules.HealthCheckPolicy 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 7 with HealthCheckPolicy

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

the class CreateLBHealthCheckPolicyCmd method create.

@Override
public void create() {
    try {
        HealthCheckPolicy result = _lbService.createLBHealthCheckPolicy(this);
        this.setEntityId(result.getId());
        this.setEntityUuid(result.getUuid());
    } catch (InvalidParameterValueException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, e.getMessage());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) HealthCheckPolicy(com.cloud.network.rules.HealthCheckPolicy)

Example 8 with HealthCheckPolicy

use of com.cloud.network.rules.HealthCheckPolicy 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 9 with HealthCheckPolicy

use of com.cloud.network.rules.HealthCheckPolicy 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.utils.exception.InvalidParameterValueException) LoadBalancer(com.cloud.network.rules.LoadBalancer) HealthCheckPolicy(com.cloud.network.rules.HealthCheckPolicy)

Example 10 with HealthCheckPolicy

use of com.cloud.network.rules.HealthCheckPolicy 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

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