mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-11-04 00:02:37 +01:00 
			
		
		
		
	Changed isElastic to isSystem for the publicIpAddress assigned during the vm deployment in EIP enabled network
Reviewed-by: Chiradeep
This commit is contained in:
		
							parent
							
								
									a9a1475302
								
							
						
					
					
						commit
						2e9511e2ae
					
				@ -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";
 | 
			
		||||
 | 
			
		||||
@ -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) {
 | 
			
		||||
 | 
			
		||||
@ -83,6 +83,6 @@ public interface IpAddress extends ControlledEntity {
 | 
			
		||||
 | 
			
		||||
    Long getAllocatedInDomainId();
 | 
			
		||||
 | 
			
		||||
    boolean getElastic();
 | 
			
		||||
    boolean getSystem();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -42,7 +42,7 @@ public interface NetworkService {
 | 
			
		||||
 | 
			
		||||
    List<? extends Network> 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.
 | 
			
		||||
 | 
			
		||||
@ -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) {
 | 
			
		||||
 | 
			
		||||
@ -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 {
 | 
			
		||||
 | 
			
		||||
@ -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()));
 | 
			
		||||
                    
 | 
			
		||||
 | 
			
		||||
@ -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<NetworkOfferingVO> offerings = _networkOfferingDao.search(sc, searchFilter);
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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());
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -183,7 +183,7 @@ public class PublicIp implements PublicIpAddress {
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
    public boolean getElastic() {
 | 
			
		||||
        return _addr.getElastic();
 | 
			
		||||
    public boolean getSystem() {
 | 
			
		||||
        return _addr.getSystem();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -146,7 +146,7 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
 | 
			
		||||
        address.setAssociatedWithVmId(null);
 | 
			
		||||
        address.setState(State.Free);
 | 
			
		||||
        address.setAssociatedWithNetworkId(null);
 | 
			
		||||
        address.setElastic(false);
 | 
			
		||||
        address.setSystem(false);
 | 
			
		||||
        update(ipAddressId, address);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -721,7 +721,7 @@ public class LoadBalancingRulesManagerImpl<Type> 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<Type> 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<Type> 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<Type> 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");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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() {
 | 
			
		||||
 | 
			
		||||
@ -41,15 +41,15 @@ public class UsageIPAddressDaoImpl extends GenericDaoBase<UsageIPAddressVO, Long
 | 
			
		||||
	public static final Logger s_logger = Logger.getLogger(UsageIPAddressDaoImpl.class.getName());
 | 
			
		||||
 | 
			
		||||
	protected static final String UPDATE_RELEASED = "UPDATE usage_ip_address SET released = ? WHERE account_id = ? AND public_ip_address = ? and released IS NULL";
 | 
			
		||||
    protected static final String GET_USAGE_RECORDS_BY_ACCOUNT = "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_ACCOUNT = "SELECT id, account_id, domain_id, zone_id, public_ip_address, is_source_nat, is_system, assigned, released " +
 | 
			
		||||
                                                                 "FROM usage_ip_address " +
 | 
			
		||||
                                                                 "WHERE account_id = ? AND ((released IS NULL AND assigned <= ?) OR (assigned BETWEEN ? AND ?) OR " +
 | 
			
		||||
                                                                 "      (released BETWEEN ? AND ?) OR ((assigned <= ?) AND (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_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<UsageIPAddressVO, Long
 | 
			
		||||
                Long zId = Long.valueOf(rs.getLong(4));
 | 
			
		||||
                String addr = rs.getString(5);
 | 
			
		||||
                Boolean isSourceNat = Boolean.valueOf(rs.getBoolean(6));
 | 
			
		||||
                Boolean isElastic = Boolean.valueOf(rs.getBoolean(7));
 | 
			
		||||
                Boolean isSystem = Boolean.valueOf(rs.getBoolean(7));
 | 
			
		||||
                Date assignedDate = null;
 | 
			
		||||
                Date releasedDate = null;
 | 
			
		||||
                String assignedTS = rs.getString(8);
 | 
			
		||||
@ -132,7 +132,7 @@ public class UsageIPAddressDaoImpl extends GenericDaoBase<UsageIPAddressVO, Long
 | 
			
		||||
                    releasedDate = DateUtil.parseDateString(s_gmtTimeZone, releasedTS);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                usageRecords.add(new UsageIPAddressVO(id, acctId, dId, zId, addr, isSourceNat, isElastic, assignedDate, releasedDate));
 | 
			
		||||
                usageRecords.add(new UsageIPAddressVO(id, acctId, dId, zId, addr, isSourceNat, isSystem, assignedDate, releasedDate));
 | 
			
		||||
            }
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            txn.rollback();
 | 
			
		||||
 | 
			
		||||
@ -2727,8 +2727,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        //enable elastic ip for vm
 | 
			
		||||
         _rulesMgr.enableElasticIpAndStaticNatForVm(profile.getVirtualMachine(), false);
 | 
			
		||||
        //get system ip and create static nat rule for the vm
 | 
			
		||||
         _rulesMgr.getSystemIpAndEnableStaticNatForVm(profile.getVirtualMachine(), false);
 | 
			
		||||
         
 | 
			
		||||
         return true;
 | 
			
		||||
    }
 | 
			
		||||
@ -2790,12 +2790,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
 | 
			
		||||
    public void finalizeStop(VirtualMachineProfile<UserVmVO> 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);
 | 
			
		||||
    		}
 | 
			
		||||
    	}
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -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`)
 | 
			
		||||
 | 
			
		||||
@ -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`),
 | 
			
		||||
 | 
			
		||||
@ -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<UsageIPAddressVO> sc = m_usageIPAddressDao.createSearchCriteria();
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user