Skip to content

Commit 5de9ae0

Browse files
David Grizzantimurali-reddy
authored andcommitted
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.
1 parent 85d0f8f commit 5de9ae0

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎server/src/com/cloud/event/ActionEventUtils.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@
4141
import com.cloud.user.User;
4242
import com.cloud.user.dao.AccountDao;
4343
import com.cloud.user.dao.UserDao;
44+
import com.cloud.projects.dao.ProjectDao;
45+
import com.cloud.projects.Project;
4446
import com.cloud.utils.component.ComponentContext;
4547

4648
public class ActionEventUtils {
4749
private static final Logger s_logger = Logger.getLogger(ActionEventUtils.class);
4850

4951
private static EventDao s_eventDao;
5052
private static AccountDao s_accountDao;
53+
private static ProjectDao s_projectDao;
5154
protected static UserDao s_userDao;
5255
protected static EventBus s_eventBus = null;
5356

@@ -63,6 +66,8 @@ public class ActionEventUtils {
6366
AccountDao accountDao;
6467
@Inject
6568
UserDao userDao;
69+
@Inject
70+
ProjectDao projectDao;
6671

6772
public ActionEventUtils() {
6873
}
@@ -72,6 +77,7 @@ void init() {
7277
s_eventDao = eventDao;
7378
s_accountDao = accountDao;
7479
s_userDao = userDao;
80+
s_projectDao = projectDao;
7581
}
7682

7783
public static Long onActionEvent(Long userId, Long accountId, Long domainId, String type, String description) {
@@ -185,13 +191,16 @@ private static void publishOnEventBus(long userId, long accountId, String eventC
185191
new org.apache.cloudstack.framework.events.Event(ManagementService.Name, eventCategory, eventType, EventTypes.getEntityForEvent(eventType), entityUuid);
186192

187193
Map<String, String> eventDescription = new HashMap<String, String>();
194+
Project project = s_projectDao.findByProjectAccountId(accountId);
188195
Account account = s_accountDao.findById(accountId);
189196
User user = s_userDao.findById(userId);
190197
// if account has been deleted, this might be called during cleanup of resources and results in null pointer
191198
if (account == null)
192199
return;
193200
if (user == null)
194201
return;
202+
if (project != null)
203+
eventDescription.put("project", project.getUuid());
195204
eventDescription.put("user", user.getUuid());
196205
eventDescription.put("account", account.getUuid());
197206
eventDescription.put("event", eventType);

‎server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import com.cloud.vm.UserVmVO;
7979
import com.cloud.vm.VirtualMachine;
8080
import com.cloud.vm.dao.UserVmDao;
81+
import com.cloud.projects.dao.ProjectDao;
8182

8283
@RunWith(SpringJUnit4ClassRunner.class)
8384
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
@@ -110,6 +111,9 @@ public class AffinityApiUnitTest {
110111
@Inject
111112
AccountDao _accountDao;
112113

114+
@Inject
115+
ProjectDao _projectDao;
116+
113117
@Inject
114118
EventDao _eventDao;
115119

@@ -217,6 +221,11 @@ public AccountDao accountDao() {
217221
return Mockito.mock(AccountDao.class);
218222
}
219223

224+
@Bean
225+
public ProjectDao projectDao() {
226+
return Mockito.mock(ProjectDao.class);
227+
}
228+
220229
@Bean
221230
public AccountService accountService() {
222231
return Mockito.mock(AccountService.class);

0 commit comments

Comments
 (0)