private void throwExceptionIfSuppliedlLbNameIsNotAssociatedWithIpAddress(final CreateLoadBalancerRuleCmd lb) { final List<LoadBalancerVO> existingLbs = findExistingLoadBalancers(lb.getName(), null, lb.getAccountId(), lb.getDomainId(), null); if (existingLbs != null) { throw new InvalidParameterValueException("Supplied LB name " + lb.getName() + " is not associated with IP " + lb.getSourceIpAddressId()); } }
@Override public void create() { //cidr list parameter is deprecated if (cidrlist != null) { throw new InvalidParameterValueException( "Parameter cidrList is deprecated; if you need to open firewall rule for the specific CIDR, please refer to createFirewallRule command"); } try { LoadBalancer result = _lbService.createPublicLoadBalancerRule(getXid(), getName(), getDescription(), getSourcePortStart(), getSourcePortEnd(), getDefaultPortStart(), getDefaultPortEnd(), getSourceIpAddressId(), getProtocol(), getAlgorithm(), getNetworkId(), getEntityOwnerId(), getOpenFirewall(), getLbProtocol(), isDisplay()); this.setEntityId(result.getId()); this.setEntityUuid(result.getUuid()); } catch (NetworkRuleConflictException e) { s_logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } catch (InsufficientAddressCapacityException e) { s_logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage()); } catch (InvalidParameterValueException e) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage()); } }
@Override public String getEventDescription() { return "creating load balancer: " + getName() + " account: " + getAccountName(); }
Long ipId = null; boolean newIp = false; List<LoadBalancerVO> existingLbs = findExistingLoadBalancers(lb.getName(), lb.getSourceIpAddressId(), lb.getAccountId(), lb.getDomainId(), lb.getSourcePortStart()); if (existingLbs == null) { existingLbs = findExistingLoadBalancers(lb.getName(), lb.getSourceIpAddressId(), lb.getAccountId(), lb.getDomainId(), null); if (existingLbs == null) { if (lb.getSourceIpAddressId() != null) { throwExceptionIfSuppliedlLbNameIsNotAssociatedWithIpAddress(lb); } else { lb.setSourceIpAddressId(ipId); result = _lbMgr.createPublicLoadBalancer(lb.getXid(), lb.getName(), lb.getDescription(), lb.getSourcePortStart(), lb.getDefaultPortStart(), ipId.longValue(), lb.getProtocol(), lb.getAlgorithm(), false, CallContext.current(), lb.getLbProtocol(), true); } catch (final NetworkRuleConflictException e) { s_logger.warn("Failed to create LB rule, not continuing with ELB deployment"); if (elbVm == null) { final Network network = _networkModel.getNetwork(networkId); s_logger.warn("Failed to deploy a new ELB vm for ip " + ipAddr + " in network " + network + "lb name=" + lb.getName()); if (newIp) { releaseIp(ipId, CallContext.current().getCallingUserId(), account);
return networkId; Long zoneId = getZoneId(); Long ipId = getSourceIpAddressId(); if (ipId == null) { throw new InvalidParameterValueException("Either networkId or zoneId or publicIpId has to be specified"); DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId); if (zone.getNetworkType() == NetworkType.Advanced) { List<? extends Network> networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(), _accountService.getAccount(getEntityOwnerId())); if (networks.size() == 0) { String domain = _domainService.getDomain(getDomainId()).getName(); throw new InvalidParameterValueException("Account name=" + getAccountName() + " domain=" + domain + " doesn't have virtual networks in zone=" + zone.getName()); Network defaultGuestNetwork = _networkService.getExclusiveGuestNetwork(zoneId); if (defaultGuestNetwork == null) { throw new InvalidParameterValueException("Unable to find a default guest network for account " + getAccountName() + " in domain ID=" + getDomainId()); } else { return defaultGuestNetwork.getId();
LoadBalancer rule = null; try { CallContext.current().setEventDetails("Rule Id: " + getEntityId()); if (getOpenFirewall()) { success = success && _firewallService.applyIngressFirewallRules(getSourceIpAddressId(), callerContext.getCallingAccount()); rule = _entityMgr.findById(LoadBalancer.class, getEntityId()); LoadBalancerResponse lbResponse = new LoadBalancerResponse(); if (rule != null) { lbResponse = _responseGenerator.createLoadBalancerResponse(rule); setResponseObject(lbResponse); lbResponse.setResponseName(getCommandName()); } catch (Exception ex) { s_logger.warn("Failed to create LB rule due to exception ", ex); if (!success || rule == null) { if (getOpenFirewall()) { _firewallService.revokeRelatedFirewallRule(getEntityId(), true); _lbService.deleteLoadBalancerRule(getEntityId(), false);
public LoadBalancer handleCreateLoadBalancerRule(final CreateLoadBalancerRuleCmd lb, Account account, final long networkId) throws InsufficientAddressCapacityException, NetworkRuleConflictException { //this part of code is executed when the LB provider is Elastic Load Balancer vm if (!_networkModel.isProviderSupportServiceInNetwork(lb.getNetworkId(), Service.Lb, Provider.ElasticLoadBalancerVm)) { return null; } final Long ipId = lb.getSourceIpAddressId(); if (ipId != null) { return null; } account = _accountDao.acquireInLockTable(account.getId()); if (account == null) { s_logger.warn("ELB: CreateLoadBalancer: Failed to acquire lock on account"); throw new CloudRuntimeException("Failed to acquire lock on account"); } try { return handleCreateLoadBalancerRuleWithLock(lb, account, networkId); } finally { if (account != null) { _accountDao.releaseFromLockTable(account.getId()); } } }
public long getDomainId() { if (publicIpId != null) return _networkService.getIp(getSourceIpAddressId()).getDomainId(); if (domainId != null) { return domainId; } return CallContext.current().getCallingAccount().getDomainId(); }
@Override public Long getSyncObjId() { return getNetworkId(); } }
@Override public long getEntityOwnerId() { return getAccountId(); }
public long getAccountId() { if (publicIpId != null) return _networkService.getIp(getSourceIpAddressId()).getAccountId(); Account account = null; if ((domainId != null) && (accountName != null)) { account = _responseGenerator.findAccountByNameDomain(accountName, domainId); if (account != null) { return account.getId(); } else { throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain ID=" + domainId); } } else { throw new InvalidParameterValueException("Can't define IP owner. Either specify account/domainId or publicIpId"); } }