Adding messageBus events for adding and removal of an account.

This commit is contained in:
Prachi Damle 2014-01-13 22:10:22 -08:00
parent bae498c89e
commit fac9f2da0f
5 changed files with 56 additions and 13 deletions

View File

@ -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" />

View File

@ -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";
}

View File

@ -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;
@ -251,12 +253,11 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
@Inject
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);

View File

@ -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)

View File

@ -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() {