cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bfede...@apache.org
Subject [02/50] [abbrv] git commit: updated refs/heads/ui-ucs to 9334dab
Date Tue, 09 Jul 2013 20:45:44 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/f93c51e2
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/f93c51e2
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/f93c51e2

Branch: refs/heads/ui-ucs
Commit: f93c51e2bd86b321b2d5a7193a275f01739781a7
Parents: ac438a6
Author: Wei Zhou <w.zhou@leaseweb.com>
Authored: Fri Jul 5 10:02:29 2013 +0200
Committer: Wei Zhou <w.zhou@leaseweb.com>
Committed: Fri Jul 5 10:02:29 2013 +0200

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


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f93c51e2/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 470d9b8..6e0d0d7 100755
--- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
+++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
@@ -503,8 +503,8 @@ 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 "
+        if (stickinessPolicies.size() > 1) {
+            throw new InvalidParameterValueException("Failed to create Stickiness policy:
Already two policies attached "
                     + cmd.getLbRuleId());
         }
         return true;
@@ -651,14 +651,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) {
@@ -667,10 +678,25 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase
implements
             if (isRollBackAllowedForProvider(loadBalancer)) {
                 loadBalancer.setState(backupState);
                 _lbDao.persist(loadBalancer);
+                deleteLBStickinessPolicy(cmd.getEntityId(), false);
                 s_logger.debug("LB Rollback rule id: " + loadBalancer.getId()
                         + " lb state rolback while creating sticky policy");
+            } 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;
         }
 
@@ -759,7 +785,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase
implements
                 success = false;
             }
         } else {
-            _lb2stickinesspoliciesDao.remove(stickinessPolicy.getLoadBalancerId());
+            _lb2stickinesspoliciesDao.expunge(stickinessPolicyId);
         }
         return success;
     }
@@ -1690,7 +1716,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(),

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f93c51e2/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