bug 6474,6475: porting over the expunge fixes for port forwarding rules to 2.2

status 6474,6475: resolved fixed
This commit is contained in:
abhishek 2010-11-15 17:32:07 -08:00
parent 6f6a01adb1
commit d5ab597fcf
8 changed files with 66 additions and 15 deletions

View File

@ -45,5 +45,6 @@ public interface FirewallRulesDao extends GenericDao<FirewallRuleVO, Long> {
public List<FirewallRuleVO> listByLoadBalancerId(long loadBalancerId);
public List<FirewallRuleVO> listForwardingByPubAndPrivIp(boolean forwarding, String publicIPAddress, String privateIp);
public FirewallRuleVO findByGroupAndPrivateIp(long groupId, String privateIp, boolean forwarding);
List<FirewallRuleVO> findByPublicIpPrivateIpForNatRule(String publicIp,String privateIp);
List<FirewallRuleVO> findByPublicIpPrivateIpForNatRule(String publicIp,String privateIp);
List<FirewallRuleVO> listByPrivateIp(String privateIp);
}

View File

@ -322,5 +322,12 @@ public class FirewallRulesDaoImpl extends GenericDaoBase<FirewallRuleVO, Long> i
sc.setParameters("publicIpAddress", publicIp);
sc.setParameters("privateIpAddress", privateIp);
return listBy(sc);
}
}
@Override
public List<FirewallRuleVO> listByPrivateIp(String privateIp) {
SearchCriteria<FirewallRuleVO> sc = FWByPrivateIPSearch.create();
sc.setParameters("privateIpAddress", privateIp);
return listBy(sc);
}
}

View File

@ -736,7 +736,7 @@ public class ApiResponseHelper {
}
ipResponse.setForVirtualNetwork(forVirtualNetworks);
ipResponse.setOneToOneNat(ipAddress.isOneToOneNat());
ipResponse.setStaticNat(ipAddress.isOneToOneNat());
//show this info to admin only
Account account = UserContext.current().getAccount();

View File

@ -63,7 +63,7 @@ public class DeletePortForwardingRuleCmd extends BaseCmd {
@Override
public void execute() throws ServerApiException, InvalidParameterValueException, PermissionDeniedException, InsufficientAddressCapacityException, InsufficientCapacityException, ConcurrentOperationException{
boolean result = BaseCmd._networkMgr.deletePortForwardingRule(this);
boolean result = BaseCmd._networkMgr.deletePortForwardingRule(id,false);
if (result) {
SuccessResponse response = new SuccessResponse(getName());
this.setResponseObject(response);

View File

@ -56,8 +56,8 @@ public class IPAddressResponse extends BaseResponse {
@SerializedName("vlanname") @Param(description="the VLAN associated with the IP address")
private String vlanName;
@SerializedName("onetoonenat") @Param(description="whether this ip is for one-to-one nat")
private Boolean oneToOneNat;
@SerializedName("isstaticnat") @Param(description="true if this ip is for static nat, false otherwise")
private Boolean staticNat;
public String getIpAddress() {
return ipAddress;
@ -147,11 +147,12 @@ public class IPAddressResponse extends BaseResponse {
this.vlanName = vlanName;
}
public Boolean getOneToOneNat() {
return oneToOneNat;
public Boolean getStaticNat() {
return staticNat;
}
public void setOneToOneNat(Boolean oneToOneNat) {
this.oneToOneNat = oneToOneNat;
public void setStaticNat(Boolean staticNat) {
this.staticNat = staticNat;
}
}

View File

@ -364,7 +364,7 @@ public interface NetworkManager {
FirewallRuleVO createIpForwardingRuleInDb(String ipAddr, Long virtualMachineId) throws ServerApiException;
public boolean deletePortForwardingRule(DeletePortForwardingRuleCmd cmd);
public boolean deletePortForwardingRule(Long id, boolean sysContext);
FirewallRuleVO createIpForwardingRuleOnDomr(Long ruleId);

View File

@ -2512,10 +2512,18 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
@Override @DB
public boolean deletePortForwardingRule(DeletePortForwardingRuleCmd cmd) {
Long ruleId = cmd.getId();
Long userId = UserContext.current().getUserId();
Account account = UserContext.current().getAccount();
public boolean deletePortForwardingRule(Long id, boolean sysContext) {
Long ruleId = id;
Long userId = null;
Account account = null;
if(sysContext){
userId = User.UID_SYSTEM;
account = _accountDao.findById(User.UID_SYSTEM);
}else{
userId = UserContext.current().getUserId();
account = UserContext.current().getAccount();
}
//verify input parameters here
FirewallRuleVO rule = _firewallRulesDao.findById(ruleId);

View File

@ -2339,6 +2339,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
List<UserVmVO> vms = _vmDao.findDestroyedVms(new Date(System.currentTimeMillis() - ((long)_expungeDelay << 10)));
s_logger.info("Found " + vms.size() + " vms to expunge.");
for (UserVmVO vm : vms) {
boolean deleteRules = true;
String privateIpAddress = vm.getPrivateIpAddress();
long vmId = vm.getId();
releaseGuestIpAddress(vm);
vm.setGuestNetmask(null);
@ -2348,6 +2350,38 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
continue;
}
if(VirtualMachineName.isValidRouterName(vm.getHostName()) && !vm.getState().equals(State.Running)){
deleteRules = false;
}
if(deleteRules)
{
List<FirewallRuleVO> forwardingRules = null;
forwardingRules = _rulesDao.listByPrivateIp(privateIpAddress);
for(FirewallRuleVO rule: forwardingRules)
{
try
{
IPAddressVO publicIp = _ipAddressDao.findById(rule.getPublicIpAddress());
if(publicIp != null)
{
if((publicIp.getAccountId().longValue() == vm.getAccountId()))
{
_networkMgr.deletePortForwardingRule(rule.getId(),true);//delete the rule with the sys user's credentials
if(s_logger.isDebugEnabled())
s_logger.debug("Rule "+rule.getId()+" for vm:"+vm.getHostName()+" is deleted successfully during expunge operation");
}
}
}
catch(Exception e)
{
s_logger.warn("Failed to delete rule:"+rule.getId()+" for vm:"+vm.getHostName());
}
}
}
List<VolumeVO> vols = null;
try {
vols = _volsDao.findByInstanceIdDestroyed(vmId);