cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prachida...@apache.org
Subject git commit: updated refs/heads/rbac to fac9f2d
Date Tue, 14 Jan 2014 06:16:17 GMT
Updated Branches:
  refs/heads/rbac bae498c89 -> fac9f2da0


Adding messageBus events for adding and removal of an account.


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

Branch: refs/heads/rbac
Commit: fac9f2da0fa40cb1dc9420ea27af9b546634b69a
Parents: bae498c
Author: Prachi Damle <prachi@cloud.com>
Authored: Mon Jan 13 22:10:22 2014 -0800
Committer: Prachi Damle <prachi@cloud.com>
Committed: Mon Jan 13 22:12:39 2014 -0800

----------------------------------------------------------------------
 .../spring-engine-schema-core-daos-context.xml  |  7 ----
 server/src/com/cloud/user/AccountManager.java   |  4 +++
 .../src/com/cloud/user/AccountManagerImpl.java  | 13 ++++---
 .../cloudstack/acl/api/AclApiServiceImpl.java   | 38 ++++++++++++++++++++
 .../cloudstack/acl/AclApiServiceTest.java       |  7 +++-
 5 files changed, 56 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fac9f2da/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml
----------------------------------------------------------------------
diff --git a/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml
b/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml
index 2974615..b19ee52 100644
--- a/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml
+++ b/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml
@@ -317,13 +317,6 @@
   <bean id="AffinityGroupVMMapDaoImpl" class="org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDaoImpl"
/>
   <bean id="AffinityGroupDomainMapDaoImpl" class="org.apache.cloudstack.affinity.dao.AffinityGroupDomainMapDaoImpl"
/>
   <bean id="FirewallRuleDetailsDaoImpl" class="org.apache.cloudstack.resourcedetail.dao.FirewallRuleDetailsDaoImpl"
/>
-  <bean id="AclGroupDaoImpl" class="org.apache.cloudstack.acl.dao.AclGroupDaoImpl"/>
-  <bean id="AclGroupJoinDaoImpl" class="com.cloud.api.query.dao.AclGroupJoinDaoImpl"/>
     
-  <bean id="AclPolicyDaoImpl" class="org.apache.cloudstack.acl.dao.AclPolicyDaoImpl"/>
 
-  <bean id="AclPolicyJoinDaoImpl" class="com.cloud.api.query.dao.AclPolicyJoinDaoImpl"/>
-  <bean id="AclGroupAccountMapDaoImpl" class="org.apache.cloudstack.acl.dao.AclGroupAccountMapDaoImpl"/>
-  <bean id="AclGroupPolicyMapDaoImpl" class="org.apache.cloudstack.acl.dao.AclGroupPolicyMapDaoImpl"/>

-  <bean id="AclPolicyPermissionDaoImpl" class="org.apache.cloudstack.acl.dao.AclPolicyPermissionDaoImpl"/>
 
     
   <bean id="databaseIntegrityChecker" class="com.cloud.upgrade.DatabaseIntegrityChecker"
/>
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fac9f2da/server/src/com/cloud/user/AccountManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/AccountManager.java b/server/src/com/cloud/user/AccountManager.java
index 5a95327..84eadea 100755
--- a/server/src/com/cloud/user/AccountManager.java
+++ b/server/src/com/cloud/user/AccountManager.java
@@ -190,4 +190,8 @@ public interface AccountManager extends AccountService {
      * @return account object
      */
     Account lockAccount(String accountName, Long domainId, Long accountId);
+
+    public static final String MESSAGE_ADD_ACCOUNT_EVENT = "Message.AddAccount.Event";
+
+    public static final String MESSAGE_REMOVE_ACCOUNT_EVENT = "Message.RemoveAccount.Event";
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fac9f2da/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 183353c..bd41520 100755
--- a/server/src/com/cloud/user/AccountManagerImpl.java
+++ b/server/src/com/cloud/user/AccountManagerImpl.java
@@ -56,6 +56,8 @@ import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
 import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+import org.apache.cloudstack.framework.messagebus.MessageBus;
+import org.apache.cloudstack.framework.messagebus.PublishScope;
 import org.apache.cloudstack.managed.context.ManagedContextRunnable;
 import org.apache.cloudstack.region.gslb.GlobalLoadBalancerRuleDao;
 
@@ -252,11 +254,10 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager,
M
     private GlobalLoadBalancerRuleDao _gslbRuleDao;
 
     @Inject
-    private AclProxyService _aclProxy;
-
-    @Inject
     QuerySelector _aclQuerySelector;  // we assume that there should be one type of QuerySelector
adapter
 
+    @Inject
+    MessageBus _messageBus;
 
     @Inject
     public com.cloud.region.ha.GlobalLoadBalancingRulesService _gslbService;
@@ -635,7 +636,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager,
M
             _projectAccountDao.removeAccountFromProjects(accountId);
 
             //delete the account from group
-            _aclProxy.removeAccountFromAclGroups(accountId);
+            _messageBus.publish(_name, MESSAGE_REMOVE_ACCOUNT_EVENT, PublishScope.LOCAL,
accountId);
 
             // delete all vm groups belonging to accont
             List<InstanceGroupVO> groups = _vmGroupDao.listByAccountId(accountId);
@@ -988,7 +989,9 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager,
M
 
                 // create correct account and group association based on accountType
                 if (accountType != Account.ACCOUNT_TYPE_PROJECT) {
-                    _aclProxy.addAccountToAclGroup(accountId, accountType + 1);
+                    Map<Long, Long> accountGroupMap = new HashMap<Long, Long>();
+                    accountGroupMap.put(accountId, new Long(accountType + 1));
+                    _messageBus.publish(_name, MESSAGE_ADD_ACCOUNT_EVENT, PublishScope.LOCAL,
accountGroupMap);
                 }
 
                 return new Pair<Long, Account>(user.getId(), account);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fac9f2da/services/iam/plugin/src/org/apache/cloudstack/acl/api/AclApiServiceImpl.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/acl/api/AclApiServiceImpl.java
b/services/iam/plugin/src/org/apache/cloudstack/acl/api/AclApiServiceImpl.java
index a6c69cc..cb6ef0c 100644
--- a/services/iam/plugin/src/org/apache/cloudstack/acl/api/AclApiServiceImpl.java
+++ b/services/iam/plugin/src/org/apache/cloudstack/acl/api/AclApiServiceImpl.java
@@ -17,10 +17,13 @@
 package org.apache.cloudstack.acl.api;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.ejb.Local;
 import javax.inject.Inject;
+import javax.naming.ConfigurationException;
 
 import org.apache.log4j.Logger;
 
@@ -45,6 +48,8 @@ import org.apache.cloudstack.acl.api.response.AclPolicyResponse;
 import org.apache.cloudstack.api.BaseListCmd;
 import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.framework.messagebus.MessageBus;
+import org.apache.cloudstack.framework.messagebus.MessageSubscriber;
 import org.apache.cloudstack.iam.api.AclGroup;
 import org.apache.cloudstack.iam.api.AclPolicy;
 import org.apache.cloudstack.iam.api.AclPolicyPermission;
@@ -88,6 +93,39 @@ public class AclApiServiceImpl extends ManagerBase implements AclApiService,
Man
     @Inject
     AccountManager _accountMgr;
 
+    @Inject
+    MessageBus _messageBus;
+
+    @Override
+    public boolean configure(final String name, final Map<String, Object> params) throws
ConfigurationException {
+        _messageBus.subscribe(AccountManager.MESSAGE_ADD_ACCOUNT_EVENT, new MessageSubscriber()
{
+            @Override
+            public void onPublishMessage(String senderAddress, String subject, Object obj)
{
+                HashMap<Long, Long> acctGroupMap = (HashMap<Long, Long>) obj;
+                for (Long accountId : acctGroupMap.keySet()) {
+                    Long groupId = acctGroupMap.get(accountId);
+                    s_logger.debug("MessageBus message: new Account Added: " + accountId
+ ", adding it to groupId :"
+                            + groupId);
+                    addAccountToAclGroup(accountId, groupId);
+                }
+            }
+        });
+
+        _messageBus.subscribe(AccountManager.MESSAGE_REMOVE_ACCOUNT_EVENT, new MessageSubscriber()
{
+            @Override
+            public void onPublishMessage(String senderAddress, String subject, Object obj)
{
+                Long accountId = ((Long) obj);
+                if (accountId != null) {
+                    s_logger.debug("MessageBus message: Account removed: " + accountId
+                            + ", releasing the group associations");
+                    removeAccountFromAclGroups(accountId);
+                }
+            }
+        });
+
+        return super.configure(name, params);
+    }
+
     @DB
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_ACL_GROUP_CREATE, eventDescription = "Creating
Acl Group", create = true)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fac9f2da/services/iam/plugin/test/org/apache/cloudstack/acl/AclApiServiceTest.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/test/org/apache/cloudstack/acl/AclApiServiceTest.java b/services/iam/plugin/test/org/apache/cloudstack/acl/AclApiServiceTest.java
index 11515ad..3a38ce7 100644
--- a/services/iam/plugin/test/org/apache/cloudstack/acl/AclApiServiceTest.java
+++ b/services/iam/plugin/test/org/apache/cloudstack/acl/AclApiServiceTest.java
@@ -52,7 +52,7 @@ import org.apache.cloudstack.iam.server.AclGroupVO;
 import org.apache.cloudstack.iam.server.AclPolicyPermissionVO;
 import org.apache.cloudstack.iam.server.AclPolicyVO;
 import org.apache.cloudstack.test.utils.SpringUtils;
-
+import org.apache.cloudstack.framework.messagebus.MessageBus;
 import com.cloud.api.ApiServerService;
 import com.cloud.domain.DomainVO;
 import com.cloud.domain.dao.DomainDao;
@@ -327,6 +327,11 @@ public class AclApiServiceTest {
         public AccountManager accountManager() {
             return Mockito.mock(AccountManager.class);
         }
+        
+        @Bean
+        public MessageBus messageBus() {
+            return Mockito.mock(MessageBus.class);
+        }
 
         @Bean
         public ApiServerService apiServerService() {


Mime
View raw message