From 10308d1ea6bc7f49174faff48a50c0c86128da4b Mon Sep 17 00:00:00 2001 From: alena Date: Fri, 23 Sep 2011 11:02:19 -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 Conflicts: server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java --- .../lb/LoadBalancingRulesManagerImpl.java | 9 +++--- .../cloud/network/rules/RulesManagerImpl.java | 30 +++++++++++-------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java index 238c2fcebda..b193694e254 100755 --- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java +++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java @@ -459,13 +459,14 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager, } throw new CloudRuntimeException("Unable to add rule for ip address id=" + newRule.getSourceIpAddressId(), e); } finally { - if (!success) { - txn.start(); - //no need to apply the rule as it wasn't programmed on the backend yet + if (!success && newRule != null) { + + txn.start(); _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 8ba464f5728..ca7c4e34d08 100755 --- a/server/src/com/cloud/network/rules/RulesManagerImpl.java +++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java @@ -223,12 +223,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; @@ -292,12 +296,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; }