use of com.cloud.legacymodel.network.LoadBalancer in project cosmic by MissionCriticalCloud.
the class ListLoadBalancerRulesCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
final Pair<List<? extends LoadBalancer>, Integer> loadBalancers = _lbService.searchForLoadBalancers(this);
final ListResponse<LoadBalancerResponse> response = new ListResponse<>();
final List<LoadBalancerResponse> lbResponses = new ArrayList<>();
if (loadBalancers != null) {
for (final LoadBalancer loadBalancer : loadBalancers.first()) {
final LoadBalancerResponse lbResponse = _responseGenerator.createLoadBalancerResponse(loadBalancer);
lbResponse.setObjectName("loadbalancerrule");
lbResponses.add(lbResponse);
}
response.setResponses(lbResponses, loadBalancers.second());
}
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
use of com.cloud.legacymodel.network.LoadBalancer 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());
}
use of com.cloud.legacymodel.network.LoadBalancer in project cosmic by MissionCriticalCloud.
the class UpdateLoadBalancerRuleCmd method execute.
@Override
public void execute() {
if (algorithm != null && !NetUtils.isValidAlgorithm(algorithm)) {
throw new InvalidParameterValueException("Only source/roundrobin/leastconn are supported loadbalance algorithms.");
}
CallContext.current().setEventDetails("Load balancer ID: " + getId());
final LoadBalancer result = _lbService.updateLoadBalancerRule(this);
if (result != null) {
final LoadBalancerResponse response = _responseGenerator.createLoadBalancerResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update load balancer rule");
}
}
use of com.cloud.legacymodel.network.LoadBalancer in project cosmic by MissionCriticalCloud.
the class CreateLoadBalancerRuleCmd method execute.
@Override
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
final 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 (final Exception ex) {
s_logger.warn("Failed to create LB rule due to exception ", ex);
}
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");
}
}
use of com.cloud.legacymodel.network.LoadBalancer in project cosmic by MissionCriticalCloud.
the class LoadBalancingRulesManagerImpl method createPublicLoadBalancerRule.
@Override
@ActionEvent(eventType = EventTypes.EVENT_LOAD_BALANCER_CREATE, eventDescription = "creating load balancer")
public LoadBalancer createPublicLoadBalancerRule(final String xId, final String name, final String description, final int srcPortStart, final int srcPortEnd, final int defPortStart, final int defPortEnd, final Long ipAddrId, final String protocol, final String algorithm, final long networkId, final long lbOwnerId, final boolean openFirewall, final String lbProtocol, final Boolean forDisplay, Integer clientTimeout, Integer serverTimeout) throws NetworkRuleConflictException, InsufficientAddressCapacityException {
final Account lbOwner = _accountMgr.getAccount(lbOwnerId);
if (srcPortStart != srcPortEnd) {
throw new InvalidParameterValueException("Port ranges are not supported by the load balancer");
}
IPAddressVO ipVO = null;
if (ipAddrId != null) {
ipVO = _ipAddressDao.findById(ipAddrId);
}
final Network network = _networkModel.getNetwork(networkId);
LoadBalancer result = null;
if (result == null) {
IpAddress systemIp = null;
final NetworkOffering off = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
if (off.getElasticLb() && ipVO == null && network.getVpcId() == null) {
systemIp = _ipAddrMgr.assignSystemIp(networkId, lbOwner, true, false);
if (systemIp != null) {
ipVO = _ipAddressDao.findById(systemIp.getId());
}
}
// Validate ip address
if (ipVO == null) {
throw new InvalidParameterValueException("Unable to create load balance rule; can't find/allocate source IP");
} else if (ipVO.isOneToOneNat()) {
throw new NetworkRuleConflictException("Can't do load balance on ip address: " + ipVO.getAddress());
}
boolean performedIpAssoc = false;
try {
if (ipVO.getAssociatedWithNetworkId() == null) {
final boolean assignToVpcNtwk = network.getVpcId() != null && ipVO.getVpcId() != null && ipVO.getVpcId().longValue() == network.getVpcId();
if (assignToVpcNtwk) {
// set networkId just for verification purposes
_networkModel.checkIpForService(ipVO, Service.Lb, networkId);
s_logger.debug("The ip is not associated with the VPC network id=" + networkId + " so assigning");
ipVO = _ipAddrMgr.associateIPToGuestNetwork(ipAddrId, networkId, false);
performedIpAssoc = true;
}
} else {
_networkModel.checkIpForService(ipVO, Service.Lb, null);
}
if (ipVO.getAssociatedWithNetworkId() == null) {
throw new InvalidParameterValueException("Ip address " + ipVO + " is not assigned to the network " + network);
}
// Load default values and fallback to hardcoded if not available
final Integer defaultClientTimeout = NumbersUtil.parseInt(_configDao.getValue(Config.DefaultLoadBalancerClientTimeout.key()), 60000);
final Integer defaultServerTimeout = NumbersUtil.parseInt(_configDao.getValue(Config.DefaultLoadBalancerServerTimeout.key()), 60000);
// set timeouts, use defaults if not available
if (clientTimeout != null) {
clientTimeout = NumbersUtil.parseInt(clientTimeout.toString(), defaultClientTimeout);
} else {
clientTimeout = defaultClientTimeout;
}
if (serverTimeout != null) {
serverTimeout = NumbersUtil.parseInt(serverTimeout.toString(), defaultServerTimeout);
} else {
serverTimeout = defaultServerTimeout;
}
result = createPublicLoadBalancer(xId, name, description, srcPortStart, defPortStart, ipVO.getId(), protocol, algorithm, openFirewall, CallContext.current(), lbProtocol, forDisplay, clientTimeout, serverTimeout);
} catch (final Exception ex) {
s_logger.warn("Failed to create load balancer due to ", ex);
if (ex instanceof NetworkRuleConflictException) {
throw (NetworkRuleConflictException) ex;
}
if (ex instanceof InvalidParameterValueException) {
throw (InvalidParameterValueException) ex;
}
} finally {
if (result == null && systemIp != null) {
s_logger.debug("Releasing system IP address " + systemIp + " as corresponding lb rule failed to create");
_ipAddrMgr.handleSystemIpRelease(systemIp);
}
// release ip address if ipassoc was perfored
if (performedIpAssoc) {
ipVO = _ipAddressDao.findById(ipVO.getId());
_vpcMgr.unassignIPFromVpcNetwork(ipVO.getId(), networkId);
}
}
}
if (result == null) {
throw new CloudRuntimeException("Failed to create load balancer rule: " + name);
}
return result;
}
Aggregations