From 2e9511e2ae537e8d3afbad859e3a61abd8e27424 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Tue, 21 Feb 2012 15:32:13 -0800 Subject: [PATCH] Changed isElastic to isSystem for the publicIpAddress assigned during the vm deployment in EIP enabled network Reviewed-by: Chiradeep --- api/src/com/cloud/api/ApiConstants.java | 1 - .../cloud/api/response/IPAddressResponse.java | 10 ++-- api/src/com/cloud/network/IpAddress.java | 2 +- api/src/com/cloud/network/NetworkService.java | 2 +- core/src/com/cloud/event/UsageEventVO.java | 4 +- .../src/com/cloud/api/ApiResponseHelper.java | 4 +- .../api/commands/GetUsageRecordsCmd.java | 4 +- .../ConfigurationManagerImpl.java | 6 ++- server/src/com/cloud/network/IPAddressVO.java | 14 +++--- .../src/com/cloud/network/NetworkManager.java | 6 +-- .../com/cloud/network/NetworkManagerImpl.java | 46 +++++++++---------- .../src/com/cloud/network/addr/PublicIp.java | 4 +- .../cloud/network/dao/IPAddressDaoImpl.java | 2 +- .../lb/LoadBalancingRulesManagerImpl.java | 22 ++++----- .../com/cloud/network/rules/RulesManager.java | 2 +- .../cloud/network/rules/RulesManagerImpl.java | 36 +++++++-------- .../api/response/UsageRecordResponse.java | 8 ++-- .../src/com/cloud/usage/UsageIPAddressVO.java | 12 ++--- .../usage/dao/UsageIPAddressDaoImpl.java | 10 ++-- .../src/com/cloud/vm/UserVmManagerImpl.java | 8 ++-- .../cloud/network/MockNetworkManagerImpl.java | 8 ++-- setup/db/create-schema-premium.sql | 2 +- setup/db/create-schema.sql | 2 +- .../src/com/cloud/usage/UsageManagerImpl.java | 4 +- .../usage/parser/IPAddressUsageParser.java | 19 +++----- 25 files changed, 117 insertions(+), 121 deletions(-) diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index 4ed625c40f7..665bfac9527 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -325,7 +325,6 @@ public class ApiConstants { public static final String TRAFFIC_TYPE_IMPLEMENTOR = "traffictypeimplementor"; public static final String KEYWORD = "keyword"; public static final String LIST_ALL = "listall"; - public static final String IS_ELASTIC = "iselastic"; public static final String SPECIFY_IP_RANGES = "specifyipranges"; public static final String IS_SOURCE_NAT = "issourcenat"; public static final String IS_STATIC_NAT = "isstaticnat"; diff --git a/api/src/com/cloud/api/response/IPAddressResponse.java b/api/src/com/cloud/api/response/IPAddressResponse.java index 0617aef844a..b78c16ead2d 100644 --- a/api/src/com/cloud/api/response/IPAddressResponse.java +++ b/api/src/com/cloud/api/response/IPAddressResponse.java @@ -71,8 +71,8 @@ public class IPAddressResponse extends BaseResponse implements ControlledEntityR @SerializedName("isstaticnat") @Param(description="true if this ip is for static nat, false otherwise") private Boolean staticNat; - @SerializedName(ApiConstants.IS_ELASTIC) @Param(description="true if this ip is elastic ip (was allocated as a part of deployVm or createLbRule)") - private Boolean isElastic; + @SerializedName(ApiConstants.IS_SYSTEM) @Param(description="true if this ip is system ip (was allocated as a part of deployVm or createLbRule)") + private Boolean isSystem; @SerializedName(ApiConstants.VIRTUAL_MACHINE_ID) @Param(description="virutal machine id the ip address is assigned to (not null only for static nat Ip)") private IdentityProxy virtualMachineId = new IdentityProxy("vm_instance"); @@ -95,7 +95,7 @@ public class IPAddressResponse extends BaseResponse implements ControlledEntityR @SerializedName(ApiConstants.PHYSICAL_NETWORK_ID) @Param(description="the physical network this belongs to") private IdentityProxy physicalNetworkId = new IdentityProxy("physical_network"); - @SerializedName(ApiConstants.PURPOSE) @Param(description="purpose of the IP address. In Acton this value is not null for Elastic IPs only, and can have either StaticNat or LB value") + @SerializedName(ApiConstants.PURPOSE) @Param(description="purpose of the IP address. In Acton this value is not null for Ips with isSystem=true, and can have either StaticNat or LB value") private String purpose; /* @@ -210,8 +210,8 @@ public class IPAddressResponse extends BaseResponse implements ControlledEntityR this.physicalNetworkId.setValue(physicalNetworkId); } - public void setIsElastic(Boolean isElastic) { - this.isElastic = isElastic; + public void setIsSystem(Boolean isSystem) { + this.isSystem = isSystem; } public void setPurpose(String purpose) { diff --git a/api/src/com/cloud/network/IpAddress.java b/api/src/com/cloud/network/IpAddress.java index e4eefe89d6b..d60a43537b5 100644 --- a/api/src/com/cloud/network/IpAddress.java +++ b/api/src/com/cloud/network/IpAddress.java @@ -83,6 +83,6 @@ public interface IpAddress extends ControlledEntity { Long getAllocatedInDomainId(); - boolean getElastic(); + boolean getSystem(); } diff --git a/api/src/com/cloud/network/NetworkService.java b/api/src/com/cloud/network/NetworkService.java index bbb102c6f46..4d7e6b68192 100755 --- a/api/src/com/cloud/network/NetworkService.java +++ b/api/src/com/cloud/network/NetworkService.java @@ -42,7 +42,7 @@ public interface NetworkService { List getIsolatedNetworksOwnedByAccountInZone(long zoneId, Account owner); - IpAddress allocateIP(long networkId, Account ipOwner, boolean isElastic) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException; + IpAddress allocateIP(long networkId, Account ipOwner, boolean isSystem) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException; /** * Associates a public IP address for a router. diff --git a/core/src/com/cloud/event/UsageEventVO.java b/core/src/com/cloud/event/UsageEventVO.java index d717233e651..24d3801e4ac 100644 --- a/core/src/com/cloud/event/UsageEventVO.java +++ b/core/src/com/cloud/event/UsageEventVO.java @@ -94,7 +94,7 @@ public class UsageEventVO implements UsageEvent { } //IPAddress usage event - public UsageEventVO(String usageType, long accountId, long zoneId, long ipAddressId, String ipAddress, boolean isSourceNat, String guestType, boolean isElastic) { + public UsageEventVO(String usageType, long accountId, long zoneId, long ipAddressId, String ipAddress, boolean isSourceNat, String guestType, boolean isSystem) { this.type = usageType; this.accountId = accountId; this.zoneId = zoneId; @@ -102,7 +102,7 @@ public class UsageEventVO implements UsageEvent { this.resourceName = ipAddress; this.size = (isSourceNat ? 1L : 0L); this.resourceType = guestType; - this.templateId = (isElastic ? 1L : 0L); + this.templateId = (isSystem ? 1L : 0L); } public UsageEventVO(String usageType, long accountId, long zoneId, long resourceId, String resourceName, Long offeringId, Long templateId, String resourceType) { diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index b55273c1e11..071479b71fb 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -715,7 +715,7 @@ public class ApiResponseHelper implements ResponseGenerator { ipResponse.setZoneId(zoneId); ipResponse.setZoneName(ApiDBUtils.findZoneById(ipAddress.getDataCenterId()).getName()); ipResponse.setSourceNat(ipAddress.isSourceNat()); - ipResponse.setIsElastic(ipAddress.getElastic()); + ipResponse.setIsSystem(ipAddress.getSystem()); // get account information populateOwner(ipResponse, ipAddress); @@ -764,7 +764,7 @@ public class ApiResponseHelper implements ResponseGenerator { ipResponse.setVlanName(ApiDBUtils.findVlanById(ipAddress.getVlanId()).getVlanTag()); } - if (ipAddress.getElastic()) { + if (ipAddress.getSystem()) { if (ipAddress.isOneToOneNat()) { ipResponse.setPurpose(IpAddress.Purpose.StaticNat.toString()); } else { diff --git a/server/src/com/cloud/api/commands/GetUsageRecordsCmd.java b/server/src/com/cloud/api/commands/GetUsageRecordsCmd.java index 968c7792d62..0e217b6e2f0 100644 --- a/server/src/com/cloud/api/commands/GetUsageRecordsCmd.java +++ b/server/src/com/cloud/api/commands/GetUsageRecordsCmd.java @@ -261,8 +261,8 @@ public class GetUsageRecordsCmd extends BaseListCmd { } else if(usageRecord.getUsageType() == UsageTypes.IP_ADDRESS){ //isSourceNAT usageRecResponse.setSourceNat((usageRecord.getType().equals("SourceNat"))?true:false); - //isElastic - usageRecResponse.setElastic((usageRecord.getSize() == 1)?true:false); + //isSystem + usageRecResponse.setSystem((usageRecord.getSize() == 1)?true:false); //IP Address ID usageRecResponse.setUsageId(identityDao.getIdentityUuid("user_ip_address", usageRecord.getUsageId().toString())); diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index d9c94dab2f3..57cbe8ed28b 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -3486,7 +3486,11 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } if (tags != null) { - sc.addAnd("tags", SearchCriteria.Op.EQ, tags); + if (tags.isEmpty()) { + sc.addAnd("tags", SearchCriteria.Op.NULL); + } else { + sc.addAnd("tags", SearchCriteria.Op.EQ, tags); + } } List offerings = _networkOfferingDao.search(sc, searchFilter); diff --git a/server/src/com/cloud/network/IPAddressVO.java b/server/src/com/cloud/network/IPAddressVO.java index db0aa8b8060..cc72aef50ac 100644 --- a/server/src/com/cloud/network/IPAddressVO.java +++ b/server/src/com/cloud/network/IPAddressVO.java @@ -96,8 +96,8 @@ public class IPAddressVO implements IpAddress, Identity { @Column(name="physical_network_id") private Long physicalNetworkId; - @Column(name="is_elastic") - private boolean elastic; + @Column(name="is_system") + private boolean system; @Column(name="account_id") @Transient @@ -269,14 +269,12 @@ public class IPAddressVO implements IpAddress, Identity { this.physicalNetworkId = physicalNetworkId; } - - @Override - public boolean getElastic() { - return elastic; + public boolean getSystem() { + return system; } - public void setElastic(boolean isElastic) { - this.elastic = isElastic; + public void setSystem(boolean isSystem) { + this.system = isSystem; } } diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 3948b3045d3..6cff9ee8654 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -81,7 +81,7 @@ public interface NetworkManager extends NetworkService { * @throws InsufficientAddressCapacityException */ - PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp, boolean isElastic) throws InsufficientAddressCapacityException; + PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp, boolean isSystem) throws InsufficientAddressCapacityException; /** * assigns a source nat ip address to an account within a network. @@ -289,11 +289,11 @@ public interface NetworkManager extends NetworkService { Provider getDefaultUniqueProviderForService(String serviceName); - IpAddress assignElasticIp(long networkId, Account owner, + IpAddress assignSystemIp(long networkId, Account owner, boolean forElasticLb, boolean forElasticIp) throws InsufficientAddressCapacityException; - boolean handleElasticIpRelease(IpAddress ip); + boolean handleSystemIpRelease(IpAddress ip); void checkNetworkPermissions(Account owner, Network network); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 7c962c4ca67..9d4cd3d61b3 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -354,12 +354,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } @Override - public PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp, boolean isElastic) throws InsufficientAddressCapacityException { - return fetchNewPublicIp(dcId, podId, null, owner, type, networkId, false, true, requestedIp, isElastic); + public PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp, boolean isSystem) throws InsufficientAddressCapacityException { + return fetchNewPublicIp(dcId, podId, null, owner, type, networkId, false, true, requestedIp, isSystem); } @DB - public PublicIp fetchNewPublicIp(long dcId, Long podId, Long vlanDbId, Account owner, VlanType vlanUse, Long networkId, boolean sourceNat, boolean assign, String requestedIp, boolean isElastic) + public PublicIp fetchNewPublicIp(long dcId, Long podId, Long vlanDbId, Account owner, VlanType vlanUse, Long networkId, boolean sourceNat, boolean assign, String requestedIp, boolean isSystem) throws InsufficientAddressCapacityException { StringBuilder errorMessage = new StringBuilder("Unable to get ip adress in "); Transaction txn = Transaction.currentTxn(); @@ -414,7 +414,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag addr.setAllocatedTime(new Date()); addr.setAllocatedInDomainId(owner.getDomainId()); addr.setAllocatedToAccountId(owner.getId()); - addr.setElastic(isElastic); + addr.setSystem(isSystem); if (assign) { markPublicIpAsAllocated(addr); @@ -459,7 +459,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag String guestType = vlan.getVlanType().toString(); - UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_ASSIGN, owner.getId(), addr.getDataCenterId(), addr.getId(), addr.getAddress().toString(), addr.isSourceNat(), guestType, addr.getElastic()); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_ASSIGN, owner.getId(), addr.getDataCenterId(), addr.getId(), addr.getAddress().toString(), addr.isSourceNat(), guestType, addr.getSystem()); _usageEventDao.persist(usageEvent); // don't increment resource count for direct ip addresses if (addr.getAssociatedWithNetworkId() != null) { @@ -946,7 +946,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override @DB @ActionEvent(eventType = EventTypes.EVENT_NET_IP_ASSIGN, eventDescription = "allocating Ip", create = true) - public IpAddress allocateIP(long networkId, Account ipOwner, boolean isElastic) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { + public IpAddress allocateIP(long networkId, Account ipOwner, boolean isSystem) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { Account caller = UserContext.current().getCaller(); long userId = UserContext.current().getCallerUserId(); @@ -1025,7 +1025,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } - ip = fetchNewPublicIp(zone.getId(), null, null, ipOwner, vlanType, network.getId(), isSourceNat, assign, null, isElastic); + ip = fetchNewPublicIp(zone.getId(), null, null, ipOwner, vlanType, network.getId(), isSourceNat, assign, null, isSystem); if (ip == null) { throw new InsufficientAddressCapacityException("Unable to find available public IP addresses", DataCenter.class, zone.getId()); @@ -1953,9 +1953,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag throw new InvalidParameterValueException("Ip address id=" + ipAddressId + " belongs to Account wide IP pool and cannot be disassociated"); } - // don't allow releasing elastic ip address - if (ipVO.getElastic()) { - throw new InvalidParameterValueException("Can't release elastic IP address " + ipVO); + // don't allow releasing system ip address + if (ipVO.getSystem()) { + throw new InvalidParameterValueException("Can't release system IP address " + ipVO); } boolean success = releasePublicIpAddress(ipAddressId, userId, caller); @@ -1964,7 +1964,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag NetworkOffering offering = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId()); Long vmId = ipVO.getAssociatedWithVmId(); if (offering.getElasticIp() && vmId != null) { - _rulesMgr.enableElasticIpAndStaticNatForVm(_userVmDao.findById(vmId), true); + _rulesMgr.getSystemIpAndEnableStaticNatForVm(_userVmDao.findById(vmId), true); return true; } return true; @@ -3569,7 +3569,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag addr.setAllocatedTime(new Date()); addr.setAllocatedInDomainId(owner.getDomainId()); addr.setAllocatedToAccountId(owner.getId()); - addr.setElastic(false); + addr.setSystem(false); addr.setState(IpAddress.State.Allocating); markPublicIpAsAllocated(addr); } @@ -3798,7 +3798,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag String guestType = vlan.getVlanType().toString(); - UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, ip.getAllocatedToAccountId(), ip.getDataCenterId(), addrId, ip.getAddress().addr(), ip.isSourceNat(), guestType, ip.getElastic()); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, ip.getAllocatedToAccountId(), ip.getDataCenterId(), addrId, ip.getAddress().addr(), ip.isSourceNat(), guestType, ip.getSystem()); _usageEventDao.persist(usageEvent); } @@ -6130,28 +6130,28 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } - public IpAddress assignElasticIp(long networkId, Account owner, boolean forElasticLb, boolean forElasticIp) throws InsufficientAddressCapacityException { + public IpAddress assignSystemIp(long networkId, Account owner, boolean forElasticLb, boolean forElasticIp) throws InsufficientAddressCapacityException { Network guestNetwork = getNetwork(networkId); NetworkOffering off = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId()); IpAddress ip = null; if ((off.getElasticLb() && forElasticLb) || (off.getElasticIp() && forElasticIp)) { try { - s_logger.debug("Allocating elastic IP address for load balancer rule..."); + s_logger.debug("Allocating system IP address for load balancer rule..."); // allocate ip ip = allocateIP(networkId, owner, true); // apply ip associations ip = associateIP(ip.getId()); } catch (ResourceAllocationException ex) { - throw new CloudRuntimeException("Failed to allocate elastic ip due to ", ex); + throw new CloudRuntimeException("Failed to allocate system ip due to ", ex); } catch (ConcurrentOperationException ex) { - throw new CloudRuntimeException("Failed to allocate elastic lb ip due to ", ex); + throw new CloudRuntimeException("Failed to allocate system lb ip due to ", ex); } catch (ResourceUnavailableException ex) { - throw new CloudRuntimeException("Failed to allocate elastic lb ip due to ", ex); + throw new CloudRuntimeException("Failed to allocate system lb ip due to ", ex); } if (ip == null) { - throw new CloudRuntimeException("Failed to allocate elastic ip"); + throw new CloudRuntimeException("Failed to allocate system ip"); } } @@ -6159,17 +6159,17 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } @Override - public boolean handleElasticIpRelease(IpAddress ip) { + public boolean handleSystemIpRelease(IpAddress ip) { boolean success = true; Long networkId = ip.getAssociatedWithNetworkId(); if (networkId != null) { - if (ip.getElastic()) { + if (ip.getSystem()) { UserContext ctx = UserContext.current(); if (!releasePublicIpAddress(ip.getId(), ctx.getCallerUserId(), ctx.getCaller())) { - s_logger.warn("Unable to release elastic ip address id=" + ip.getId()); + s_logger.warn("Unable to release system ip address id=" + ip.getId()); success = false; } else { - s_logger.warn("Successfully released elastic ip address id=" + ip.getId()); + s_logger.warn("Successfully released system ip address id=" + ip.getId()); } } } diff --git a/server/src/com/cloud/network/addr/PublicIp.java b/server/src/com/cloud/network/addr/PublicIp.java index 91e1eea453f..473764b2791 100644 --- a/server/src/com/cloud/network/addr/PublicIp.java +++ b/server/src/com/cloud/network/addr/PublicIp.java @@ -183,7 +183,7 @@ public class PublicIp implements PublicIpAddress { } @Override - public boolean getElastic() { - return _addr.getElastic(); + public boolean getSystem() { + return _addr.getSystem(); } } diff --git a/server/src/com/cloud/network/dao/IPAddressDaoImpl.java b/server/src/com/cloud/network/dao/IPAddressDaoImpl.java index eb897ca632a..3f5678bad89 100755 --- a/server/src/com/cloud/network/dao/IPAddressDaoImpl.java +++ b/server/src/com/cloud/network/dao/IPAddressDaoImpl.java @@ -146,7 +146,7 @@ public class IPAddressDaoImpl extends GenericDaoBase implemen address.setAssociatedWithVmId(null); address.setState(State.Free); address.setAssociatedWithNetworkId(null); - address.setElastic(false); + address.setSystem(false); update(ipAddressId, address); } diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java index 21efb5923fa..3ea045dfbee 100755 --- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java +++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java @@ -721,7 +721,7 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa Network guestNetwork = _networkMgr.getNetwork(lb.getNetworkId()); NetworkOffering off = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId()); if (off.getElasticLb() && ipAddressVo == null) { - ip = _networkMgr.assignElasticIp(lb.getNetworkId(), lbOwner, true, false); + ip = _networkMgr.assignSystemIp(lb.getNetworkId(), lbOwner, true, false); lb.setSourceIpAddressId(ip.getId()); } try { @@ -733,8 +733,8 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa } } finally { if (result == null && ip != null) { - s_logger.debug("Releasing elastic IP address " + ip + " as corresponding lb rule failed to create"); - _networkMgr.handleElasticIpRelease(ip); + s_logger.debug("Releasing system IP address " + ip + " as corresponding lb rule failed to create"); + _networkMgr.handleSystemIpRelease(ip); } } } @@ -914,13 +914,13 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa long count = _firewallDao.countRulesByIpId(lb.getSourceIpAddressId()); if (count == 0) { try { - success = handleElasticLBIpRelease(lb); + success = handleSystemLBIpRelease(lb); } catch (Exception ex) { - s_logger.warn("Failed to release elastic ip as a part of lb rule " + lb + " deletion due to exception ", ex); + s_logger.warn("Failed to release system ip as a part of lb rule " + lb + " deletion due to exception ", ex); success = false; } finally { if (!success) { - s_logger.warn("Failed to release elastic ip as a part of lb rule " + lb + " deletion"); + s_logger.warn("Failed to release system ip as a part of lb rule " + lb + " deletion"); } } } @@ -931,16 +931,16 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa return true; } - protected boolean handleElasticLBIpRelease(LoadBalancerVO lb) { + protected boolean handleSystemLBIpRelease(LoadBalancerVO lb) { IpAddress ip = _ipAddressDao.findById(lb.getSourceIpAddressId()); boolean success = true; - if (ip.getElastic()) { - s_logger.debug("Releasing elastic ip address " + lb.getSourceIpAddressId() + " as a part of delete lb rule"); + if (ip.getSystem()) { + s_logger.debug("Releasing system ip address " + lb.getSourceIpAddressId() + " as a part of delete lb rule"); if (!_networkMgr.releasePublicIpAddress(lb.getSourceIpAddressId(), UserContext.current().getCallerUserId(), UserContext.current().getCaller())) { - s_logger.warn("Unable to release elastic ip address id=" + lb.getSourceIpAddressId() + " as a part of delete lb rule"); + s_logger.warn("Unable to release system ip address id=" + lb.getSourceIpAddressId() + " as a part of delete lb rule"); success = false; } else { - s_logger.warn("Successfully released elastic ip address id=" + lb.getSourceIpAddressId() + " as a part of delete lb rule"); + s_logger.warn("Successfully released system ip address id=" + lb.getSourceIpAddressId() + " as a part of delete lb rule"); } } diff --git a/server/src/com/cloud/network/rules/RulesManager.java b/server/src/com/cloud/network/rules/RulesManager.java index eee213785b2..4d1cb113f35 100644 --- a/server/src/com/cloud/network/rules/RulesManager.java +++ b/server/src/com/cloud/network/rules/RulesManager.java @@ -74,7 +74,7 @@ public interface RulesManager extends RulesService { boolean applyStaticNatsForNetwork(long networkId, boolean continueOnError, Account caller); - void enableElasticIpAndStaticNatForVm(UserVm vm, boolean getNewIp) throws InsufficientAddressCapacityException; + void getSystemIpAndEnableStaticNatForVm(UserVm vm, boolean getNewIp) throws InsufficientAddressCapacityException; boolean disableStaticNat(long ipAddressId, Account caller, long callerUserId, boolean releaseIpIfElastic) throws ResourceUnavailableException; diff --git a/server/src/com/cloud/network/rules/RulesManagerImpl.java b/server/src/com/cloud/network/rules/RulesManagerImpl.java index af5a70086ba..38458404842 100755 --- a/server/src/com/cloud/network/rules/RulesManagerImpl.java +++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java @@ -1028,8 +1028,8 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { IPAddressVO ipAddress = _ipAddressDao.findById(ipId); checkIpAndUserVm(ipAddress, null, caller); - if (ipAddress.getElastic()) { - throw new InvalidParameterValueException("Can't disable static nat for elastic IP address " + ipAddress); + if (ipAddress.getSystem()) { + throw new InvalidParameterValueException("Can't disable static nat for system IP address " + ipAddress); } Long vmId = ipAddress.getAssociatedWithVmId(); @@ -1043,7 +1043,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { Network guestNetwork = _networkMgr.getNetwork(ipAddress.getAssociatedWithNetworkId()); NetworkOffering offering = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId()); if (offering.getElasticIp()) { - enableElasticIpAndStaticNatForVm(_vmDao.findById(vmId), true); + getSystemIpAndEnableStaticNatForVm(_vmDao.findById(vmId), true); return true; } else { return disableStaticNat(ipId, caller, ctx.getCallerUserId(), false); @@ -1080,17 +1080,17 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { } if (success) { - boolean isIpElastic = ipAddress.getElastic(); + boolean isIpSystem = ipAddress.getSystem(); ipAddress.setOneToOneNat(false); ipAddress.setAssociatedWithVmId(null); - if (isIpElastic && !releaseIpIfElastic) { - ipAddress.setElastic(false); + if (isIpSystem && !releaseIpIfElastic) { + ipAddress.setSystem(false); } _ipAddressDao.update(ipAddress.getId(), ipAddress); - if (isIpElastic && releaseIpIfElastic && !_networkMgr.handleElasticIpRelease(ipAddress)) { - s_logger.warn("Failed to release elastic ip address " + ipAddress); + if (isIpSystem && releaseIpIfElastic && !_networkMgr.handleSystemIpRelease(ipAddress)) { + s_logger.warn("Failed to release system ip address " + ipAddress); success = false; } @@ -1177,7 +1177,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { } @Override - public void enableElasticIpAndStaticNatForVm(UserVm vm, boolean getNewIp) throws InsufficientAddressCapacityException { + public void getSystemIpAndEnableStaticNatForVm(UserVm vm, boolean getNewIp) throws InsufficientAddressCapacityException { boolean success = true; // enable static nat if eIp capability is supported @@ -1189,17 +1189,17 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { // check if there is already static nat enabled if (_ipAddressDao.findByAssociatedVmId(vm.getId()) != null && !getNewIp) { - s_logger.debug("Vm " + vm + " already has elastic ip associated with it in guest network " + guestNetwork); + s_logger.debug("Vm " + vm + " already has ip associated with it in guest network " + guestNetwork); continue; } - s_logger.debug("Allocating elastic ip and enabling static nat for it for the vm " + vm + " in guest network " + guestNetwork); - IpAddress ip = _networkMgr.assignElasticIp(guestNetwork.getId(), _accountMgr.getAccount(vm.getAccountId()), false, true); + s_logger.debug("Allocating system ip and enabling static nat for it for the vm " + vm + " in guest network " + guestNetwork); + IpAddress ip = _networkMgr.assignSystemIp(guestNetwork.getId(), _accountMgr.getAccount(vm.getAccountId()), false, true); if (ip == null) { - throw new CloudRuntimeException("Failed to allocate elastic ip for vm " + vm + " in guest network " + guestNetwork); + throw new CloudRuntimeException("Failed to allocate system ip for vm " + vm + " in guest network " + guestNetwork); } - s_logger.debug("Allocated elastic ip " + ip + ", now enabling static nat on it for vm " + vm); + s_logger.debug("Allocated system ip " + ip + ", now enabling static nat on it for vm " + vm); try { success = enableStaticNat(ip.getId(), vm.getId()); @@ -1212,11 +1212,11 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { } if (!success) { - s_logger.warn("Failed to enable static nat on elastic ip " + ip + " for the vm " + vm + ", releasing the ip..."); - _networkMgr.handleElasticIpRelease(ip); - throw new CloudRuntimeException("Failed to enable static nat on elastic ip for the vm " + vm); + s_logger.warn("Failed to enable static nat on system ip " + ip + " for the vm " + vm + ", releasing the ip..."); + _networkMgr.handleSystemIpRelease(ip); + throw new CloudRuntimeException("Failed to enable static nat on system ip for the vm " + vm); } else { - s_logger.warn("Succesfully enabled static nat on elastic ip " + ip + " for the vm " + vm); + s_logger.warn("Succesfully enabled static nat on system ip " + ip + " for the vm " + vm); } } } diff --git a/server/src/com/cloud/server/api/response/UsageRecordResponse.java b/server/src/com/cloud/server/api/response/UsageRecordResponse.java index 6f1aed58273..9ad62ba624d 100644 --- a/server/src/com/cloud/server/api/response/UsageRecordResponse.java +++ b/server/src/com/cloud/server/api/response/UsageRecordResponse.java @@ -91,8 +91,8 @@ public class UsageRecordResponse extends BaseResponse implements ControlledEntit @SerializedName("issourcenat") @Param(description="True if the IPAddress is source NAT") private Boolean isSourceNat; - @SerializedName("iselastic") @Param(description="True if the IPAddress is elastic") - private Boolean isElastic; + @SerializedName(ApiConstants.IS_SYSTEM) @Param(description="True if the IPAddress is system IP - allocated during vm deploy or lb rule create") + private Boolean isSystem; @SerializedName("networkid") @Param(description="id of the network") private String networkId; @@ -174,8 +174,8 @@ public class UsageRecordResponse extends BaseResponse implements ControlledEntit this.isSourceNat = isSourceNat; } - public void setElastic(Boolean isElastic) { - this.isElastic = isElastic; + public void setSystem(Boolean isSystem) { + this.isSystem = isSystem; } @Override diff --git a/server/src/com/cloud/usage/UsageIPAddressVO.java b/server/src/com/cloud/usage/UsageIPAddressVO.java index cc6375a3626..478981b1b72 100644 --- a/server/src/com/cloud/usage/UsageIPAddressVO.java +++ b/server/src/com/cloud/usage/UsageIPAddressVO.java @@ -48,8 +48,8 @@ public class UsageIPAddressVO { @Column(name="is_source_nat") private boolean isSourceNat = false; - @Column(name="is_elastic") - private boolean isElastic = false; + @Column(name="is_system") + private boolean isSystem = false; @Column(name="assigned") @Temporal(value=TemporalType.TIMESTAMP) @@ -62,14 +62,14 @@ public class UsageIPAddressVO { protected UsageIPAddressVO() { } - public UsageIPAddressVO(long id, long accountId, long domainId, long zoneId, String address, boolean isSourceNat, boolean isElastic, Date assigned, Date released) { + public UsageIPAddressVO(long id, long accountId, long domainId, long zoneId, String address, boolean isSourceNat, boolean isSystem, Date assigned, Date released) { this.id = id; this.accountId = accountId; this.domainId = domainId; this.zoneId = zoneId; this.address = address; this.isSourceNat = isSourceNat; - this.isElastic = isElastic; + this.isSystem = isSystem; this.assigned = assigned; this.released = released; } @@ -105,8 +105,8 @@ public class UsageIPAddressVO { return isSourceNat; } - public boolean isElastic() { - return isElastic; + public boolean isSystem() { + return isSystem; } public Date getAssigned() { diff --git a/server/src/com/cloud/usage/dao/UsageIPAddressDaoImpl.java b/server/src/com/cloud/usage/dao/UsageIPAddressDaoImpl.java index 29145ec49a4..aeac0da44a8 100644 --- a/server/src/com/cloud/usage/dao/UsageIPAddressDaoImpl.java +++ b/server/src/com/cloud/usage/dao/UsageIPAddressDaoImpl.java @@ -41,15 +41,15 @@ public class UsageIPAddressDaoImpl extends GenericDaoBase= ?)))"; - protected static final String GET_USAGE_RECORDS_BY_DOMAIN = "SELECT id, account_id, domain_id, zone_id, public_ip_address, is_source_nat, is_elastic, assigned, released " + + protected static final String GET_USAGE_RECORDS_BY_DOMAIN = "SELECT id, account_id, domain_id, zone_id, public_ip_address, is_source_nat, is_system, assigned, released " + "FROM usage_ip_address " + "WHERE domain_id = ? AND ((released IS NULL AND assigned <= ?) OR (assigned BETWEEN ? AND ?) OR " + " (released BETWEEN ? AND ?) OR ((assigned <= ?) AND (released >= ?)))"; - protected static final String GET_ALL_USAGE_RECORDS = "SELECT id, account_id, domain_id, zone_id, public_ip_address, is_source_nat, is_elastic, assigned, released " + + protected static final String GET_ALL_USAGE_RECORDS = "SELECT id, account_id, domain_id, zone_id, public_ip_address, is_source_nat, is_system, assigned, released " + "FROM usage_ip_address " + "WHERE (released IS NULL AND assigned <= ?) OR (assigned BETWEEN ? AND ?) OR " + " (released BETWEEN ? AND ?) OR ((assigned <= ?) AND (released >= ?))"; @@ -119,7 +119,7 @@ public class UsageIPAddressDaoImpl extends GenericDaoBase profile, StopAnswer answer) { //release elastic IP here IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId()); - if (ip != null && ip.getElastic()) { + if (ip != null && ip.getSystem()) { UserContext ctx = UserContext.current(); try { _rulesMgr.disableStaticNat(ip.getId(), ctx.getCaller(), ctx.getCallerUserId(), true); } catch (Exception ex) { - s_logger.warn("Failed to disable static nat and release elastic ip " + ip + " as a part of vm " + profile.getVirtualMachine() + " stop due to exception ", ex); + s_logger.warn("Failed to disable static nat and release system ip " + ip + " as a part of vm " + profile.getVirtualMachine() + " stop due to exception ", ex); } } } diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java index 50c130e7c79..2a2470a30af 100755 --- a/server/test/com/cloud/network/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java @@ -770,7 +770,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS @Override public IpAddress allocateIP(long networkId, Account ipOwner, - boolean isElastic) throws ResourceAllocationException, + boolean isSystem) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { // TODO Auto-generated method stub return null; @@ -778,7 +778,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS @Override public PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, - VlanType type, Long networkId, String requestedIp, boolean isElastic) + VlanType type, Long networkId, String requestedIp, boolean isSystem) throws InsufficientAddressCapacityException { // TODO Auto-generated method stub return null; @@ -798,7 +798,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS } @Override - public IpAddress assignElasticIp(long networkId, Account owner, + public IpAddress assignSystemIp(long networkId, Account owner, boolean forElasticLb, boolean forElasticIp) throws InsufficientAddressCapacityException { // TODO Auto-generated method stub @@ -806,7 +806,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS } @Override - public boolean handleElasticIpRelease(IpAddress ip) { + public boolean handleSystemIpRelease(IpAddress ip) { // TODO Auto-generated method stub return false; } diff --git a/setup/db/create-schema-premium.sql b/setup/db/create-schema-premium.sql index 2056005c4f8..b472699c70a 100644 --- a/setup/db/create-schema-premium.sql +++ b/setup/db/create-schema-premium.sql @@ -96,7 +96,7 @@ CREATE TABLE `cloud_usage`.`usage_ip_address` ( `zone_id` bigint unsigned NOT NULL, `public_ip_address` varchar(15) NOT NULL, `is_source_nat` smallint(1) NOT NULL, - `is_elastic` smallint(1) NOT NULL, + `is_system` smallint(1) NOT NULL, `assigned` DATETIME NOT NULL, `released` DATETIME NULL, UNIQUE KEY (`id`, `assigned`) diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 44cb8ca3f11..875525ddc43 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -921,7 +921,7 @@ CREATE TABLE `cloud`.`user_ip_address` ( `source_network_id` bigint unsigned NOT NULL COMMENT 'network id ip belongs to', `network_id` bigint unsigned COMMENT 'network this public ip address is associated with', `physical_network_id` bigint unsigned NOT NULL COMMENT 'physical network id that this configuration is based on', - `is_elastic` int(1) unsigned NOT NULL default '0', + `is_system` int(1) unsigned NOT NULL default '0', PRIMARY KEY (`id`), UNIQUE (`public_ip_address`, `source_network_id`), CONSTRAINT `fk_user_ip_address__source_network_id` FOREIGN KEY (`source_network_id`) REFERENCES `networks`(`id`), diff --git a/usage/src/com/cloud/usage/UsageManagerImpl.java b/usage/src/com/cloud/usage/UsageManagerImpl.java index b6f59b4a993..0879b22cb05 100644 --- a/usage/src/com/cloud/usage/UsageManagerImpl.java +++ b/usage/src/com/cloud/usage/UsageManagerImpl.java @@ -1028,8 +1028,8 @@ public class UsageManagerImpl implements UsageManager, Runnable { long id = event.getResourceId(); long sourceNat = event.getSize(); boolean isSourceNat = (sourceNat == 1) ? true : false ; - boolean isElastic = (event.getTemplateId() == null || event.getTemplateId() == 0) ? false : true ; - UsageIPAddressVO ipAddressVO = new UsageIPAddressVO(id, event.getAccountId(), acct.getDomainId(), zoneId, ipAddress, isSourceNat, isElastic, event.getCreateDate(), null); + boolean isSystem = (event.getTemplateId() == null || event.getTemplateId() == 0) ? false : true ; + UsageIPAddressVO ipAddressVO = new UsageIPAddressVO(id, event.getAccountId(), acct.getDomainId(), zoneId, ipAddress, isSourceNat, isSystem, event.getCreateDate(), null); m_usageIPAddressDao.persist(ipAddressVO); } else if (EventTypes.EVENT_NET_IP_RELEASE.equals(event.getType())) { SearchCriteria sc = m_usageIPAddressDao.createSearchCriteria(); diff --git a/usage/src/com/cloud/usage/parser/IPAddressUsageParser.java b/usage/src/com/cloud/usage/parser/IPAddressUsageParser.java index 0eb30676b5b..309fa087d95 100644 --- a/usage/src/com/cloud/usage/parser/IPAddressUsageParser.java +++ b/usage/src/com/cloud/usage/parser/IPAddressUsageParser.java @@ -78,7 +78,7 @@ public class IPAddressUsageParser { String key = ""+IpId; // store the info in the IP map - IPMap.put(key, new IpInfo(usageIp.getZoneId(), IpId, usageIp.getAddress(), usageIp.isSourceNat(), usageIp.isElastic())); + IPMap.put(key, new IpInfo(usageIp.getZoneId(), IpId, usageIp.getAddress(), usageIp.isSourceNat(), usageIp.isSystem())); Date IpAssignDate = usageIp.getAssigned(); Date IpReleaseDeleteDate = usageIp.getReleased(); @@ -104,7 +104,7 @@ public class IPAddressUsageParser { // Only create a usage record if we have a runningTime of bigger than zero. if (useTime > 0L) { IpInfo info = IPMap.get(ipIdKey); - createUsageRecord(info.getZoneId(), useTime, startDate, endDate, account, info.getIpId(), info.getIPAddress(), info.isSourceNat(), info.isElastic); + createUsageRecord(info.getZoneId(), useTime, startDate, endDate, account, info.getIpId(), info.getIPAddress(), info.isSourceNat(), info.isSystem); } } @@ -123,7 +123,7 @@ public class IPAddressUsageParser { usageDataMap.put(key, ipUsageInfo); } - private static void createUsageRecord(long zoneId, long runningTime, Date startDate, Date endDate, AccountVO account, long IpId, String IPAddress, boolean isSourceNat, boolean isElastic) { + private static void createUsageRecord(long zoneId, long runningTime, Date startDate, Date endDate, AccountVO account, long IpId, String IPAddress, boolean isSourceNat, boolean isSystem) { if (s_logger.isDebugEnabled()) { s_logger.debug("Total usage time " + runningTime + "ms"); } @@ -142,7 +142,7 @@ public class IPAddressUsageParser { // Create the usage record UsageVO usageRecord = new UsageVO(zoneId, account.getAccountId(), account.getDomainId(), usageDesc, usageDisplay + " Hrs", UsageTypes.IP_ADDRESS, new Double(usage), IpId, - (isElastic?1:0), (isSourceNat?"SourceNat":""), startDate, endDate); + (isSystem?1:0), (isSourceNat?"SourceNat":""), startDate, endDate); m_usageDao.persist(usageRecord); } @@ -151,14 +151,14 @@ public class IPAddressUsageParser { private long IpId; private String IPAddress; private boolean isSourceNat; - private boolean isElastic; + private boolean isSystem; - public IpInfo(long zoneId,long IpId, String IPAddress, boolean isSourceNat, boolean isElastic) { + public IpInfo(long zoneId,long IpId, String IPAddress, boolean isSourceNat, boolean isSystem) { this.zoneId = zoneId; this.IpId = IpId; this.IPAddress = IPAddress; this.isSourceNat = isSourceNat; - this.isElastic = isElastic; + this.isSystem = isSystem; } public long getZoneId() { @@ -176,10 +176,5 @@ public class IPAddressUsageParser { public boolean isSourceNat() { return isSourceNat; } - - public boolean isElastic() { - return isElastic; - } } - }