cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From muralire...@apache.org
Subject [3/3] git commit: updated refs/heads/master to 9c0f9ac
Date Fri, 31 May 2013 13:38:59 GMT
CLOUDSTACK-2332:[GSLB] deleteAccount is not cleaning the gslb rules
created by the account

revoking GSLB rules of account on delete


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

Branch: refs/heads/master
Commit: 9c0f9aceb8ccfef7b3b5d0a58a619cb8e32f1eea
Parents: 470995b
Author: Murali Reddy <muralimmreddy@gmail.com>
Authored: Fri May 31 19:02:34 2013 +0530
Committer: Murali Reddy <muralimmreddy@gmail.com>
Committed: Fri May 31 19:08:40 2013 +0530

----------------------------------------------------------------------
 .../region/ha/GlobalLoadBalancingRulesService.java |    3 +
 .../ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java   |   12 ++++-
 .../region/gslb/GlobalLoadBalancerDaoImpl.java     |   12 +++++
 .../region/gslb/GlobalLoadBalancerRuleDao.java     |    3 +
 server/src/com/cloud/user/AccountManagerImpl.java  |   12 +++++
 .../gslb/GlobalLoadBalancingRulesServiceImpl.java  |   33 +++++++++++++-
 6 files changed, 69 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c0f9ace/api/src/com/cloud/region/ha/GlobalLoadBalancingRulesService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/region/ha/GlobalLoadBalancingRulesService.java b/api/src/com/cloud/region/ha/GlobalLoadBalancingRulesService.java
index 186faf7..9375544 100644
--- a/api/src/com/cloud/region/ha/GlobalLoadBalancingRulesService.java
+++ b/api/src/com/cloud/region/ha/GlobalLoadBalancingRulesService.java
@@ -33,6 +33,9 @@ public interface GlobalLoadBalancingRulesService {
 
     GlobalLoadBalancerRule updateGlobalLoadBalancerRule(UpdateGlobalLoadBalancerRuleCmd updateGslbCmd);
 
+    boolean revokeAllGslbRulesForAccount(com.cloud.user.Account caller, long accountId)
+            throws com.cloud.exception.ResourceUnavailableException;
+
     /*
      * methods for managing sites participating in global load balancing
      */

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c0f9ace/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java
b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java
index fe5decd..77ec4e7 100644
--- a/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java
@@ -87,13 +87,19 @@ public class DeleteGlobalLoadBalancerRuleCmd extends BaseAsyncCmd {
 
     @Override
     public void execute(){
-        _gslbService.deleteGlobalLoadBalancerRule(this);
-        UserContext.current().setEventDetails("Deleting global Load balancer Id: " + getGlobalLoadBalancerId());
+        UserContext.current().setEventDetails("Deleting global Load balancer rule Id: " +
getGlobalLoadBalancerId());
+        boolean result = _gslbService.deleteGlobalLoadBalancerRule(this);
+        if (result) {
+            SuccessResponse response = new SuccessResponse(getCommandName());
+            this.setResponseObject(response);
+        } else {
+            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete Global
Load Balancer rule.");
+        }
     }
 
     @Override
     public String getSyncObjType() {
-        return BaseAsyncCmd.networkSyncObject;
+        return BaseAsyncCmd.gslbSyncObject;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c0f9ace/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerDaoImpl.java
b/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerDaoImpl.java
index 0020f5d..ba9dea0 100644
--- a/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerDaoImpl.java
+++ b/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerDaoImpl.java
@@ -31,12 +31,17 @@ public class GlobalLoadBalancerDaoImpl extends GenericDaoBase<GlobalLoadBalancer
 
     private final SearchBuilder<GlobalLoadBalancerRuleVO> listByDomainSearch;
     private final SearchBuilder<GlobalLoadBalancerRuleVO> listByRegionIDSearch;
+    private final SearchBuilder<GlobalLoadBalancerRuleVO> AccountIdSearch;
 
     public GlobalLoadBalancerDaoImpl() {
         listByDomainSearch = createSearchBuilder();
         listByDomainSearch.and("gslbDomain", listByDomainSearch.entity().getGslbDomain(),
SearchCriteria.Op.EQ);
         listByDomainSearch.done();
 
+        AccountIdSearch = createSearchBuilder();
+        AccountIdSearch.and("account", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+        AccountIdSearch.done();
+
         listByRegionIDSearch = createSearchBuilder();
         listByRegionIDSearch.and("region", listByRegionIDSearch.entity().getRegion(), SearchCriteria.Op.EQ);
         listByRegionIDSearch.done();
@@ -50,6 +55,13 @@ public class GlobalLoadBalancerDaoImpl extends GenericDaoBase<GlobalLoadBalancer
     }
 
     @Override
+    public List<GlobalLoadBalancerRuleVO> listByAccount(long accountId) {
+        SearchCriteria<GlobalLoadBalancerRuleVO> sc = AccountIdSearch.create();
+        sc.setParameters("account", accountId);
+        return listBy(sc, null);
+    }
+
+    @Override
     public GlobalLoadBalancerRuleVO findByDomainName(String domainName) {
         SearchCriteria<GlobalLoadBalancerRuleVO> sc = listByDomainSearch.create();
         sc.setParameters("gslbDomain", domainName);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c0f9ace/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerRuleDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerRuleDao.java
b/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerRuleDao.java
index 1b44caa..cfc8625 100644
--- a/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerRuleDao.java
+++ b/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerRuleDao.java
@@ -24,5 +24,8 @@ import java.util.List;
 public interface GlobalLoadBalancerRuleDao extends GenericDao<GlobalLoadBalancerRuleVO,
Long> {
 
     List<GlobalLoadBalancerRuleVO> listByRegionId(int regionId);
+
+    List<GlobalLoadBalancerRuleVO> listByAccount(long accountId);
+
     GlobalLoadBalancerRuleVO findByDomainName(String domainName);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c0f9ace/server/src/com/cloud/user/AccountManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java
index 292142f..0d89639 100755
--- a/server/src/com/cloud/user/AccountManagerImpl.java
+++ b/server/src/com/cloud/user/AccountManagerImpl.java
@@ -46,6 +46,7 @@ import org.apache.cloudstack.api.command.admin.account.UpdateAccountCmd;
 import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
 import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
 import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
+import org.apache.cloudstack.region.gslb.GlobalLoadBalancerRuleDao;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.log4j.Logger;
 
@@ -103,6 +104,7 @@ import com.cloud.projects.ProjectManager;
 import com.cloud.projects.ProjectVO;
 import com.cloud.projects.dao.ProjectAccountDao;
 import com.cloud.projects.dao.ProjectDao;
+import com.cloud.region.ha.GlobalLoadBalancingRulesService;
 import com.cloud.server.auth.UserAuthenticator;
 import com.cloud.storage.VMTemplateVO;
 import com.cloud.storage.Volume;
@@ -235,6 +237,10 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager,
M
     private ResourceLimitDao _resourceLimitDao;
     @Inject
     private DedicatedResourceDao _dedicatedDao;
+    @Inject
+    private GlobalLoadBalancerRuleDao _gslbRuleDao;
+    @Inject
+    public com.cloud.region.ha.GlobalLoadBalancingRulesService _gslbService;
 
     private List<UserAuthenticator> _userAuthenticators;
     List<UserAuthenticator> _userPasswordEncoders;
@@ -553,6 +559,12 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager,
M
                 }
             }
 
+            // delete global load balancer rules for the account.
+            List<org.apache.cloudstack.region.gslb.GlobalLoadBalancerRuleVO> gslbRules
= _gslbRuleDao.listByAccount(accountId);
+            if (gslbRules != null && !gslbRules.isEmpty()) {
+                _gslbService.revokeAllGslbRulesForAccount(caller, accountId);
+            }
+
             //delete the account from project accounts
             _projectAccountDao.removeAccountFromProjects(accountId);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c0f9ace/server/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImpl.java
b/server/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImpl.java
index 96ac76e..02c7720 100644
--- a/server/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImpl.java
+++ b/server/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImpl.java
@@ -373,16 +373,29 @@ public class GlobalLoadBalancingRulesServiceImpl implements GlobalLoadBalancingR
     }
 
     @Override
-    @DB
     @ActionEvent(eventType = EventTypes.EVENT_GLOBAL_LOAD_BALANCER_DELETE, eventDescription
=
             "Delete global load balancer rule")
     public boolean deleteGlobalLoadBalancerRule(DeleteGlobalLoadBalancerRuleCmd deleteGslbCmd)
{
 
         UserContext ctx = UserContext.current();
         Account caller = ctx.getCaller();
-
         long gslbRuleId =  deleteGslbCmd.getGlobalLoadBalancerId();
+
+        try {
+            revokeGslbRule(gslbRuleId, caller);
+        } catch (Exception e) {
+            s_logger.warn("Failed to delete GSLB rule due to" + e.getMessage());
+            return false;
+        }
+
+        return true;
+    }
+
+    @DB
+    private void revokeGslbRule(long gslbRuleId, Account caller) {
+
         GlobalLoadBalancerRuleVO gslbRule = _gslbRuleDao.findById(gslbRuleId);
+
         if (gslbRule == null) {
             throw new InvalidParameterValueException("Invalid global load balancer rule id:
" + gslbRuleId);
         }
@@ -428,10 +441,11 @@ public class GlobalLoadBalancingRulesServiceImpl implements GlobalLoadBalancingR
                 _gslbLbMapDao.remove(gslbLbMap.getId());
             }
         }
+
         //remove the GSLB rule itself
         _gslbRuleDao.remove(gslbRuleId);
+
         txn.commit();
-        return success;
     }
 
     @Override
@@ -609,6 +623,19 @@ public class GlobalLoadBalancingRulesServiceImpl implements GlobalLoadBalancingR
         return true;
     }
 
+    @Override
+    public boolean revokeAllGslbRulesForAccount(com.cloud.user.Account caller, long accountId)
+            throws com.cloud.exception.ResourceUnavailableException {
+        List<GlobalLoadBalancerRuleVO> gslbRules = _gslbRuleDao.listByAccount(accountId);
+        if (gslbRules != null && !gslbRules.isEmpty()) {
+            for (GlobalLoadBalancerRule gslbRule : gslbRules) {
+                revokeGslbRule(gslbRule.getId(), caller);
+            }
+        }
+        s_logger.debug("Successfully cleaned up GSLB rules for account id=" + accountId);
+        return true;
+    }
+
     private boolean checkGslbServiceEnabledInZone(long zoneId, long physicalNetworkId) {
 
         if (_gslbProvider == null) {


Mime
View raw message