use of com.cloud.network.rules.LoadBalancer in project cloudstack by apache.
the class ListLBStickinessPoliciesCmd method execute.
@Override
public void execute() {
LoadBalancer lb = null;
if (lbRuleId == null && id == null) {
throw new InvalidParameterValueException("load balancer rule ID and stickiness policy ID can't be null");
}
if (id != null) {
lb = _lbService.findLbByStickinessId(id);
if (lb == null) {
throw new InvalidParameterValueException("stickiness policy ID doesn't exist");
}
if ((lbRuleId != null) && (lbRuleId != lb.getId())) {
throw new InvalidParameterValueException("stickiness policy ID doesn't belong to lbId" + lbRuleId);
}
}
if (lbRuleId != null && lb == null) {
lb = _lbService.findById(getLbRuleId());
}
List<LBStickinessResponse> spResponses = new ArrayList<LBStickinessResponse>();
ListResponse<LBStickinessResponse> response = new ListResponse<LBStickinessResponse>();
if (lb != null) {
//check permissions
Account caller = CallContext.current().getCallingAccount();
_accountService.checkAccess(caller, null, true, lb);
List<? extends StickinessPolicy> stickinessPolicies = _lbService.searchForLBStickinessPolicies(this);
LBStickinessResponse spResponse = _responseGenerator.createLBStickinessPolicyResponse(stickinessPolicies, lb);
spResponses.add(spResponse);
response.setResponses(spResponses);
}
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
use of com.cloud.network.rules.LoadBalancer 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");
}
}
}
use of com.cloud.network.rules.LoadBalancer in project cloudstack by apache.
the class CreateLBStickinessPolicyCmd method execute.
@Override
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
StickinessPolicy policy = null;
boolean success = false;
try {
CallContext.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(ApiErrorCode.INTERNAL_ERROR, "Failed to create stickiness policy");
}
}
}
use of com.cloud.network.rules.LoadBalancer in project cloudstack by apache.
the class DeleteLBHealthCheckPolicyCmd method getSyncObjId.
@Override
public Long getSyncObjId() {
HealthCheckPolicy policy = _entityMgr.findById(HealthCheckPolicy.class, getId());
if (policy == null) {
throw new InvalidParameterValueException("Unable to find load balancer health check rule: " + id);
}
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();
}
use of com.cloud.network.rules.LoadBalancer in project cloudstack by apache.
the class UpdateLBStickinessPolicyCmd method execute.
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() {
StickinessPolicy policy = _lbService.updateLBStickinessPolicy(this.getId(), this.getCustomId(), this.getDisplay());
LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
LBStickinessResponse spResponse = _responseGenerator.createLBStickinessPolicyResponse(policy, lb);
setResponseObject(spResponse);
spResponse.setResponseName(getCommandName());
}
Aggregations