mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-5496 : Account included in ActionEvents is Project Account ID
When Action Events are generated and placed on the Event Bus, an "account" parameter is included with the event. When these events are generated for resources within projects, this "account" parameter is not useful as it's the UUID of the project account, instead of the project. To solve this, I updated ActionEventsUtil class to include a "project" parameter in the generated events when the resource is being changed/add/deleted in a project.
This commit is contained in:
parent
85d0f8f93a
commit
5de9ae0bce
|
|
@ -41,6 +41,8 @@ import com.cloud.user.AccountVO;
|
|||
import com.cloud.user.User;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
import com.cloud.user.dao.UserDao;
|
||||
import com.cloud.projects.dao.ProjectDao;
|
||||
import com.cloud.projects.Project;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
|
||||
public class ActionEventUtils {
|
||||
|
|
@ -48,6 +50,7 @@ public class ActionEventUtils {
|
|||
|
||||
private static EventDao s_eventDao;
|
||||
private static AccountDao s_accountDao;
|
||||
private static ProjectDao s_projectDao;
|
||||
protected static UserDao s_userDao;
|
||||
protected static EventBus s_eventBus = null;
|
||||
|
||||
|
|
@ -63,6 +66,8 @@ public class ActionEventUtils {
|
|||
AccountDao accountDao;
|
||||
@Inject
|
||||
UserDao userDao;
|
||||
@Inject
|
||||
ProjectDao projectDao;
|
||||
|
||||
public ActionEventUtils() {
|
||||
}
|
||||
|
|
@ -72,6 +77,7 @@ public class ActionEventUtils {
|
|||
s_eventDao = eventDao;
|
||||
s_accountDao = accountDao;
|
||||
s_userDao = userDao;
|
||||
s_projectDao = projectDao;
|
||||
}
|
||||
|
||||
public static Long onActionEvent(Long userId, Long accountId, Long domainId, String type, String description) {
|
||||
|
|
@ -185,6 +191,7 @@ public class ActionEventUtils {
|
|||
new org.apache.cloudstack.framework.events.Event(ManagementService.Name, eventCategory, eventType, EventTypes.getEntityForEvent(eventType), entityUuid);
|
||||
|
||||
Map<String, String> eventDescription = new HashMap<String, String>();
|
||||
Project project = s_projectDao.findByProjectAccountId(accountId);
|
||||
Account account = s_accountDao.findById(accountId);
|
||||
User user = s_userDao.findById(userId);
|
||||
// if account has been deleted, this might be called during cleanup of resources and results in null pointer
|
||||
|
|
@ -192,6 +199,8 @@ public class ActionEventUtils {
|
|||
return;
|
||||
if (user == null)
|
||||
return;
|
||||
if (project != null)
|
||||
eventDescription.put("project", project.getUuid());
|
||||
eventDescription.put("user", user.getUuid());
|
||||
eventDescription.put("account", account.getUuid());
|
||||
eventDescription.put("event", eventType);
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ import com.cloud.utils.component.ComponentContext;
|
|||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.projects.dao.ProjectDao;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
|
||||
|
|
@ -110,6 +111,9 @@ public class AffinityApiUnitTest {
|
|||
@Inject
|
||||
AccountDao _accountDao;
|
||||
|
||||
@Inject
|
||||
ProjectDao _projectDao;
|
||||
|
||||
@Inject
|
||||
EventDao _eventDao;
|
||||
|
||||
|
|
@ -217,6 +221,11 @@ public class AffinityApiUnitTest {
|
|||
return Mockito.mock(AccountDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ProjectDao projectDao() {
|
||||
return Mockito.mock(ProjectDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AccountService accountService() {
|
||||
return Mockito.mock(AccountService.class);
|
||||
|
|
|
|||
Loading…
Reference in New Issue