Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public String getEventType() {

@Override
public String getEventDescription() {
return "Adding user "+getUsername()+" to Project "+getProjectId();
return "Adding user " + getUsername() + " to project: " + getProjectId();
}

/////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public String getEventDescription() {
return "Removing user " + userId + " from project: " + projectId;
}


@Override
public long getEntityOwnerId() {
Project project = _projectService.getProject(projectId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ public void interceptComplete(Method method, Object target, Object event) {
for (ActionEvent actionEvent : getActionEvents(method)) {
CallContext ctx = CallContext.current();
long userId = ctx.getCallingUserId();
long accountId = ctx.getProject() != null ? ctx.getProject().getProjectAccountId() : ctx.getCallingAccountId(); //This should be the entity owner id rather than the Calling User Account Id.
long startEventId = ctx.getStartEventId();
String eventDescription = getEventDescription(actionEvent, ctx);
Long eventResourceId = getEventResourceId(actionEvent, ctx);
String eventResourceType = getEventResourceType(actionEvent, ctx);
String eventType = getEventType(actionEvent, ctx);
boolean isEventDisplayEnabled = ctx.isEventDisplayEnabled();
long accountId = ActionEventUtils.getOwnerAccountId(ctx, eventType, ctx.getCallingAccountId());

if (eventType.equals(""))
return;
Expand All @@ -118,13 +118,13 @@ public void interceptException(Method method, Object target, Object event) {
for (ActionEvent actionEvent : getActionEvents(method)) {
CallContext ctx = CallContext.current();
long userId = ctx.getCallingUserId();
long accountId = ctx.getCallingAccountId();
long startEventId = ctx.getStartEventId();
String eventDescription = getEventDescription(actionEvent, ctx);
Long eventResourceId = getEventResourceId(actionEvent, ctx);
String eventResourceType = getEventResourceType(actionEvent, ctx);
String eventType = getEventType(actionEvent, ctx);
boolean isEventDisplayEnabled = ctx.isEventDisplayEnabled();
long accountId = ActionEventUtils.getOwnerAccountId(ctx, eventType, ctx.getCallingAccountId());

if (eventType.equals(""))
return;
Expand Down
11 changes: 9 additions & 2 deletions server/src/main/java/com/cloud/event/ActionEventUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
Expand Down Expand Up @@ -110,6 +111,8 @@ public static Long onActionEvent(Long userId, Long accountId, Long domainId, Str
*/
public static Long onScheduledActionEvent(Long userId, Long accountId, String type, String description, Long resourceId, String resourceType, boolean eventDisplayEnabled, long startEventId) {
Ternary<Long, String, String> resourceDetails = getResourceDetails(resourceId, resourceType, type);
CallContext ctx = CallContext.current();
accountId = getOwnerAccountId(ctx, type, accountId);
publishOnEventBus(userId, accountId, EventCategory.ACTION_EVENT.getName(), type, com.cloud.event.Event.State.Scheduled, description, resourceDetails.second(), resourceDetails.third());
Event event = persistActionEvent(userId, accountId, null, null, type, Event.State.Scheduled, eventDisplayEnabled, description, resourceDetails.first(), resourceDetails.third(), startEventId);
return event.getId();
Expand All @@ -123,7 +126,7 @@ public static void startNestedActionEvent(String eventType, String eventDescript
public static void onStartedActionEventFromContext(String eventType, String eventDescription, Long resourceId, String resourceType, boolean eventDisplayEnabled) {
CallContext ctx = CallContext.current();
long userId = ctx.getCallingUserId();
long accountId = ctx.getProject() != null ? ctx.getProject().getProjectAccountId() : ctx.getCallingAccountId(); //This should be the entity owner id rather than the Calling User Account Id.
long accountId = getOwnerAccountId(ctx, eventType, ctx.getCallingAccountId());
long startEventId = ctx.getStartEventId();

if (!eventType.equals(""))
Expand Down Expand Up @@ -393,7 +396,11 @@ private static void populateFirstClassEntities(Map<String, String> eventDescript
s_logger.trace("Caught exception while populating first class entities for event bus, moving on");
}
}

}

public static long getOwnerAccountId(CallContext ctx, String eventType, long callingAccountId) {
List<String> mainProjectEvents = List.of(EventTypes.EVENT_PROJECT_CREATE, EventTypes.EVENT_PROJECT_UPDATE, EventTypes.EVENT_PROJECT_DELETE);
long accountId = ctx.getProject() != null && !mainProjectEvents.stream().anyMatch(eventType::equalsIgnoreCase) ? ctx.getProject().getProjectAccountId() : callingAccountId; //This should be the entity owner id rather than the Calling User Account Id.
return accountId;
}
}
16 changes: 8 additions & 8 deletions server/src/main/java/com/cloud/projects/ProjectManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,16 @@ public Project doInTransaction(TransactionStatus status) {
assignAccountToProject(project, ownerFinal.getId(), ProjectAccount.Role.Admin,
Optional.ofNullable(finalUser).map(User::getId).orElse(null), null);

if (project != null) {
CallContext.current().setEventDetails("Project id=" + project.getId());
CallContext.current().putContextParameter(Project.class, project.getUuid());
}
if (project != null) {
CallContext.current().setEventDetails("Project id=" + project.getId());
CallContext.current().putContextParameter(Project.class, project.getUuid());
}

//Increment resource count
//Increment resource count
_resourceLimitMgr.incrementResourceCount(ownerFinal.getId(), ResourceType.project);

return project;
}
return project;
}
});

messageBus.publish(_name, ProjectManager.MESSAGE_CREATE_TUNGSTEN_PROJECT_EVENT, PublishScope.LOCAL, project);
Expand Down Expand Up @@ -1275,7 +1275,7 @@ public List<Long> listPermittedProjectAccounts(long accountId) {
}

@Override
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_ACTIVATE, eventDescription = "activating project")
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_ACTIVATE, eventDescription = "activating project", async = true)
@DB
public Project activateProject(final long projectId) {
Account caller = CallContext.current().getCallingAccount();
Expand Down