From 2ee6986e240e4a68c1093685f3321618dff50010 Mon Sep 17 00:00:00 2001 From: alena Date: Fri, 23 Sep 2011 10:55:59 -0700 Subject: [PATCH] bug 11555: Fixed NPE happening during LB rule cleanup in case when createLB fails status 11555: resolved fixed Reviewed-by: frank@cloud.com --- .../lb/LoadBalancingRulesManagerImpl.java | 8 +++-- .../cloud/network/rules/RulesManagerImpl.java | 30 +++++++++++-------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java index dceef5ae37f..df5941b39fc 100755 --- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java +++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java @@ -457,13 +457,15 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager, } throw new CloudRuntimeException("Unable to add rule for ip address id=" + newRule.getSourceIpAddressId(), e); } finally { - if (!success) { + if (!success && newRule != null) { txn.start(); - _firewallDao.remove(_firewallDao.findByRelatedId(newRule.getId()).getId()); + + _firewallMgr.revokeRelatedFirewallRule(newRule.getId(), false); _lbDao.remove(newRule.getId()); + txn.commit(); - + } } diff --git a/server/src/com/cloud/network/rules/RulesManagerImpl.java b/server/src/com/cloud/network/rules/RulesManagerImpl.java index 41cf4efd73b..7525705c2bc 100755 --- a/server/src/com/cloud/network/rules/RulesManagerImpl.java +++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java @@ -222,12 +222,16 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { return newRule; } catch (Exception e) { - txn.start(); - //no need to apply the rule as it wasn't programmed on the backend yet - _firewallMgr.revokeRelatedFirewallRule(newRule.getId(), false); - _forwardingDao.remove(newRule.getId()); - - txn.commit(); + + if (newRule != null) { + + txn.start(); + //no need to apply the rule as it wasn't programmed on the backend yet + _firewallMgr.revokeRelatedFirewallRule(newRule.getId(), false); + _forwardingDao.remove(newRule.getId()); + + txn.commit(); + } if (e instanceof NetworkRuleConflictException) { throw (NetworkRuleConflictException) e; @@ -288,12 +292,14 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { return staticNatRule; } catch (Exception e) { - txn.start(); - //no need to apply the rule as it wasn't programmed on the backend yet - _firewallMgr.revokeRelatedFirewallRule(newRule.getId(), false); - _forwardingDao.remove(newRule.getId()); - txn.commit(); - + if (newRule != null) { + txn.start(); + //no need to apply the rule as it wasn't programmed on the backend yet + _firewallMgr.revokeRelatedFirewallRule(newRule.getId(), false); + _forwardingDao.remove(newRule.getId()); + txn.commit(); + } + if (e instanceof NetworkRuleConflictException) { throw (NetworkRuleConflictException) e; }