cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From weiz...@apache.org
Subject [2/2] git commit: updated refs/heads/4.1 to 7755986
Date Fri, 05 Jul 2013 09:33:36 GMT
CLOUDSTACK-3345: createLBStickinessPolicy replaces old stickiness policy if exists


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

Branch: refs/heads/4.1
Commit: 7755986652636c9571a0702b1f485bebd2e25c58
Parents: e92c5b0
Author: Wei Zhou <w.zhou@leaseweb.com>
Authored: Fri Jul 5 11:33:25 2013 +0200
Committer: Wei Zhou <w.zhou@leaseweb.com>
Committed: Fri Jul 5 11:33:25 2013 +0200

----------------------------------------------------------------------
 .../lb/LoadBalancingRulesManagerImpl.java       | 44 +++++++++++---
 ui/scripts/lbStickyPolicy.js                    | 63 +++++++++-----------
 2 files changed, 63 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/77559866/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
index a016cbc..0e68e61 100755
--- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
+++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
@@ -451,9 +451,9 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase
implements
         }
 
         /* Validation : check for the multiple policies to the rule id */
-        List<LBStickinessPolicyVO> stickinessPolicies = _lb2stickinesspoliciesDao.listByLoadBalancerId(cmd.getLbRuleId(),
false);
-        if (stickinessPolicies.size() > 0) {
-            throw new InvalidParameterValueException("Failed to create Stickiness policy:
Already policy attached " + cmd.getLbRuleId());
+        List<LBStickinessPolicyVO> stickinessPolicies = _lb2stickinesspoliciesDao.listByLoadBalancerId(cmd.getLbRuleId());
+        if (stickinessPolicies.size() > 1) {
+            throw new InvalidParameterValueException("Failed to create Stickiness policy:
Already two policies attached " + cmd.getLbRuleId());
         }
         return true;
     }
@@ -518,14 +518,25 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase
implements
     @ActionEvent(eventType = EventTypes.EVENT_LB_STICKINESSPOLICY_CREATE, eventDescription
= "Apply Stickinesspolicy to load balancer ", async = true)
     public boolean applyLBStickinessPolicy(CreateLBStickinessPolicyCmd cmd) {
         boolean success = true;
+        FirewallRule.State backupState = null;
+        long oldStickinessPolicyId = 0;
 
         LoadBalancerVO loadBalancer = _lbDao.findById(cmd.getLbRuleId());
         if (loadBalancer == null) {
             throw new InvalidParameterException("Invalid Load balancer Id:"  + cmd.getLbRuleId());
         }
-        FirewallRule.State backupState = loadBalancer.getState();
-        loadBalancer.setState(FirewallRule.State.Add);
-        _lbDao.persist(loadBalancer);
+        List<LBStickinessPolicyVO> stickinessPolicies = _lb2stickinesspoliciesDao.listByLoadBalancerId(cmd.getLbRuleId(),
false);
+        for (LBStickinessPolicyVO stickinessPolicy: stickinessPolicies) {
+            if (stickinessPolicy.getId() == cmd.getEntityId()) {
+                backupState = loadBalancer.getState();
+                loadBalancer.setState(FirewallRule.State.Add);
+                _lbDao.persist(loadBalancer);
+            } else {
+                oldStickinessPolicyId = stickinessPolicy.getId();
+                stickinessPolicy.setRevoke(true);
+                _lb2stickinesspoliciesDao.persist(stickinessPolicy);
+            }
+        }
         try {
             applyLoadBalancerConfig(cmd.getLbRuleId());
         } catch (ResourceUnavailableException e) {
@@ -534,8 +545,23 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase
implements
                 loadBalancer.setState(backupState);
                 _lbDao.persist(loadBalancer);
                 s_logger.debug("LB Rollback rule id: " + loadBalancer.getId() + " lb state
rolback while creating sticky policy");
+                deleteLBStickinessPolicy(cmd.getEntityId(), false);
+            } else {
+                deleteLBStickinessPolicy(cmd.getEntityId(), false);
+                if (oldStickinessPolicyId != 0) {
+                    LBStickinessPolicyVO stickinessPolicy = _lb2stickinesspoliciesDao.findById(oldStickinessPolicyId);
+                    stickinessPolicy.setRevoke(false);
+                    _lb2stickinesspoliciesDao.persist(stickinessPolicy);
+                    try {
+                        if (backupState.equals(FirewallRule.State.Active))
+                            applyLoadBalancerConfig(cmd.getLbRuleId());
+                    } catch (ResourceUnavailableException e1) {
+                    } finally {
+                        loadBalancer.setState(backupState);
+                        _lbDao.persist(loadBalancer);
+                    }
+                }
             }
-            deleteLBStickinessPolicy(cmd.getEntityId(), false);
             success = false;
         }
 
@@ -590,7 +616,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase
implements
                 success = false;
             }
         } else {
-            _lb2stickinesspoliciesDao.remove(stickinessPolicy.getLoadBalancerId());
+            _lb2stickinesspoliciesDao.expunge(stickinessPolicyId);
         }
 
         return success;
@@ -1322,7 +1348,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase
implements
     @Override
     public List<LbStickinessPolicy> getStickinessPolicies(long lbId) {
         List<LbStickinessPolicy> stickinessPolicies = new ArrayList<LbStickinessPolicy>();
-        List<LBStickinessPolicyVO> sDbpolicies = _lb2stickinesspoliciesDao.listByLoadBalancerId(lbId);
+        List<LBStickinessPolicyVO> sDbpolicies = _lb2stickinesspoliciesDao.listByLoadBalancerId(lbId,
false);
 
         for (LBStickinessPolicyVO sDbPolicy : sDbpolicies) {
             LbStickinessPolicy sPolicy = new LbStickinessPolicy(sDbPolicy.getMethodName(),
sDbPolicy.getParams(), sDbPolicy.isRevoke());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/77559866/ui/scripts/lbStickyPolicy.js
----------------------------------------------------------------------
diff --git a/ui/scripts/lbStickyPolicy.js b/ui/scripts/lbStickyPolicy.js
index 2d132da..02ebabe 100644
--- a/ui/scripts/lbStickyPolicy.js
+++ b/ui/scripts/lbStickyPolicy.js
@@ -259,6 +259,32 @@
           }
         });
       },
+      delete: function(stickyRuleID, complete, error) {
+        $.ajax({
+          url: createURL('deleteLBStickinessPolicy'),
+          data: {
+            id: stickyRuleID
+          },
+          success: function(json) {
+            cloudStack.ui.notifications.add(
+              {
+                desc: 'Remove previous LB sticky rule',
+                section: 'Network',
+                poll: pollAsyncJobResult,
+                _custom: {
+                  jobId: json.deleteLBstickinessrruleresponse.jobid
+                }
+              },
+              complete, {},
+              error, {}
+            );
+          },
+          error: function(json) {
+            complete();
+            cloudStack.dialog.notice({ message: parseXMLHttpResponse(json) });
+          }
+        });
+      },
       recreate: function(stickyRuleID, lbRuleID, data, complete, error) {
         var addStickyPolicy = function() {
           cloudStack.lbStickyPolicy.actions.add(
@@ -270,43 +296,10 @@
         };
         
         // Delete existing rule
-        if (stickyRuleID) {
-          $.ajax({
-            url: createURL('deleteLBStickinessPolicy'),
-            data: {
-              id: stickyRuleID
-            },
-            success: function(json) {
-              cloudStack.ui.notifications.add(
-                {
-                  desc: 'Remove previous LB sticky rule',
-                  section: 'Network',
-                  poll: pollAsyncJobResult,
-                  _custom: {
-                    jobId: json.deleteLBstickinessrruleresponse.jobid
-                  }
-                },
-                function() {
-                  if (data.methodname != 'None') {
-                    addStickyPolicy();
-                  } else {
-                    complete();
-                  }
-                }, {},
-                error, {}
-              );
-            },
-            error: function(json) {
-              cloudStack.dialog.notice({
-                message: parseXMLHttpResponse(json)
-              });
-              error();
-            }
-          });
-        } else if (data.methodname != 'None') {
+        if (data.methodname != 'None') {
           addStickyPolicy();
         } else {
-          complete();
+          cloudStack.lbStickyPolicy.actions.delete(stickyRuleID, complete, error);
         }
       }
     }


Mime
View raw message