From 5de9ae0bceddd751ae7f59fa4b7aec1d13f8bf59 Mon Sep 17 00:00:00 2001 From: David Grizzanti Date: Thu, 30 Jan 2014 17:30:42 +0530 Subject: [PATCH] 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. --- server/src/com/cloud/event/ActionEventUtils.java | 9 +++++++++ .../apache/cloudstack/affinity/AffinityApiUnitTest.java | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/server/src/com/cloud/event/ActionEventUtils.java b/server/src/com/cloud/event/ActionEventUtils.java index d435381b69b..c332a8e32e4 100755 --- a/server/src/com/cloud/event/ActionEventUtils.java +++ b/server/src/com/cloud/event/ActionEventUtils.java @@ -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 eventDescription = new HashMap(); + 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); diff --git a/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java b/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java index 061fd42ac6b..f891e70196d 100644 --- a/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java +++ b/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java @@ -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);