You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ts...@apache.org on 2013/02/09 11:48:40 UTC

git commit: refs/heads/4.0 - CLOUDSTACK-1088: EnableStaticNat error will clear the data in database

Updated Branches:
  refs/heads/4.0 19d5f39c5 -> a61a2b18f


CLOUDSTACK-1088: EnableStaticNat error will clear the data in database

The issue occur in two conditions

(1) If I use two sessions or browsers to EnableStaticNat on CloudStack
UI. one is successful, the other is failed. However, there is no ip in
database.

(2) If I use API call EnableStaticNat several times The first time
succeed, the second failed, the third succeed. the result is
success-fail-success-fail-success-fail, which it is not correct.

Reported-by: Wei Zhou <w....@leaseweb.com>
Reviewed-by: https://reviews.apache.org/r/9254/
Signed-off-by: Prasanna Santhanam <ts...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/a61a2b18
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/a61a2b18
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/a61a2b18

Branch: refs/heads/4.0
Commit: a61a2b18fa1df60d5abc5d070094338b9ab0f4a3
Parents: 19d5f39
Author: Wei Zhou <w....@leaseweb.com>
Authored: Sat Feb 9 16:14:26 2013 +0530
Committer: Prasanna Santhanam <ts...@apache.org>
Committed: Sat Feb 9 16:17:49 2013 +0530

----------------------------------------------------------------------
 .../com/cloud/network/rules/RulesManagerImpl.java  |   24 +++++++--------
 1 files changed, 11 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a61a2b18/server/src/com/cloud/network/rules/RulesManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/rules/RulesManagerImpl.java b/server/src/com/cloud/network/rules/RulesManagerImpl.java
index 2383366..6c1e27a 100755
--- a/server/src/com/cloud/network/rules/RulesManagerImpl.java
+++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java
@@ -406,7 +406,8 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
 
         // Verify input parameters
         boolean performedIpAssoc = false;
-        boolean result = false;
+        boolean isOneToOneNat = ipAddress.isOneToOneNat();
+        Long associatedWithVmId = ipAddress.getAssociatedWithVmId();
         try {
             Network network = _networkMgr.getNetwork(networkId);
             if (network == null) {
@@ -470,28 +471,25 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
                 // enable static nat on the backend
                 s_logger.trace("Enabling static nat for ip address " + ipAddress + " and vm id=" + vmId + " on the backend");
                 if (applyStaticNatForIp(ipId, false, caller, false)) {
-                    result = true;
+                    return true;
                 } else {
                     s_logger.warn("Failed to enable static nat rule for ip address " + ipId + " on the backend");
+                    ipAddress.setOneToOneNat(isOneToOneNat);
+                    ipAddress.setAssociatedWithVmId(associatedWithVmId);
+                    _ipAddressDao.update(ipAddress.getId(), ipAddress);
                 }
             } else {
                 s_logger.warn("Failed to update ip address " + ipAddress + " in the DB as a part of enableStaticNat");
                 
             }
         } finally {
-            if (!result) {
-                ipAddress.setOneToOneNat(false);
-                ipAddress.setAssociatedWithVmId(null);
-                _ipAddressDao.update(ipAddress.getId(), ipAddress);  
-                
-                if (performedIpAssoc) {
-                    //if the rule is the last one for the ip address assigned to VPC, unassign it from the network
-                    IpAddress ip = _ipAddressDao.findById(ipAddress.getId());
-                    _vpcMgr.unassignIPFromVpcNetwork(ip.getId(), networkId);
-                }
+            if (performedIpAssoc) {
+                //if the rule is the last one for the ip address assigned to VPC, unassign it from the network
+                IpAddress ip = _ipAddressDao.findById(ipAddress.getId());
+                _vpcMgr.unassignIPFromVpcNetwork(ip.getId(), networkId);
             }
         }
-        return result;
+        return false;
     }
 
     protected void isIpReadyForStaticNat(long vmId, IPAddressVO ipAddress, Account caller, long callerUserId)