CLOUDSTACK-8816: Project UUID is not showing for some of operations in RabbitMQ.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/3bd53521 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/3bd53521 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/3bd53521 Branch: refs/heads/master Commit: 3bd53521e8944db447bfa69494d7f01f73727808 Parents: b12d473 Author: Rajani Karuturi <[email protected]> Authored: Wed Sep 9 12:18:08 2015 +0530 Committer: Rajani Karuturi <[email protected]> Committed: Wed Sep 9 14:23:28 2015 +0530 ---------------------------------------------------------------------- api/src/org/apache/cloudstack/context/CallContext.java | 10 ++++++++++ server/src/com/cloud/api/ApiDispatcher.java | 9 +++++++++ server/src/com/cloud/event/ActionEventInterceptor.java | 2 +- server/src/com/cloud/event/ActionEventUtils.java | 2 +- server/src/com/cloud/projects/ProjectManagerImpl.java | 1 + 5 files changed, 22 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3bd53521/api/src/org/apache/cloudstack/context/CallContext.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/context/CallContext.java b/api/src/org/apache/cloudstack/context/CallContext.java index 73da826..2619f4a 100644 --- a/api/src/org/apache/cloudstack/context/CallContext.java +++ b/api/src/org/apache/cloudstack/context/CallContext.java @@ -21,6 +21,7 @@ import java.util.Map; import java.util.Stack; import java.util.UUID; +import com.cloud.projects.Project; import org.apache.log4j.Logger; import org.apache.log4j.NDC; @@ -59,6 +60,7 @@ public class CallContext { private User user; private long userId; private final Map<Object, Object> context = new HashMap<Object, Object>(); + private Project project; static EntityManager s_entityMgr; @@ -314,6 +316,14 @@ public class CallContext { this.eventDescription = eventDescription; } + public Project getProject() { + return this.project; + } + + public void setProject(Project project) { + this.project = project; + } + /** * Whether to display the event to the end user. * @return true - if the event is to be displayed to the end user, false otherwise. http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3bd53521/server/src/com/cloud/api/ApiDispatcher.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java index 0dc1164..7375588 100644 --- a/server/src/com/cloud/api/ApiDispatcher.java +++ b/server/src/com/cloud/api/ApiDispatcher.java @@ -21,6 +21,8 @@ import java.util.Map; import javax.annotation.PostConstruct; import javax.inject.Inject; +import com.cloud.projects.Project; +import com.cloud.utils.db.EntityManager; import org.apache.log4j.Logger; import org.apache.cloudstack.acl.ControlledEntity; @@ -54,6 +56,9 @@ public class ApiDispatcher { @Inject AccountManager _accountMgr; + @Inject + EntityManager _entityMgr; + @Inject() protected DispatchChainFactory dispatchChainFactory; @@ -102,6 +107,10 @@ public class ApiDispatcher { final CallContext ctx = CallContext.current(); ctx.setEventDisplayEnabled(cmd.isDisplay()); + if(params.get(ApiConstants.PROJECT_ID) != null) { + Project project = _entityMgr.findByUuidIncludingRemoved(Project.class, params.get(ApiConstants.PROJECT_ID)); + ctx.setProject(project); + } // TODO This if shouldn't be here. Use polymorphism and move it to validateSpecificParameters if (cmd instanceof BaseAsyncCmd) { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3bd53521/server/src/com/cloud/event/ActionEventInterceptor.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/event/ActionEventInterceptor.java b/server/src/com/cloud/event/ActionEventInterceptor.java index 5d2d51a..d2dacd9 100644 --- a/server/src/com/cloud/event/ActionEventInterceptor.java +++ b/server/src/com/cloud/event/ActionEventInterceptor.java @@ -84,7 +84,7 @@ public class ActionEventInterceptor implements ComponentMethodInterceptor, Metho for (ActionEvent actionEvent : getActionEvents(method)) { CallContext ctx = CallContext.current(); long userId = ctx.getCallingUserId(); - long accountId = ctx.getCallingAccountId(); + 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); String eventType = getEventType(actionEvent, ctx); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3bd53521/server/src/com/cloud/event/ActionEventUtils.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/event/ActionEventUtils.java b/server/src/com/cloud/event/ActionEventUtils.java index 29eade2..0ca41cc 100644 --- a/server/src/com/cloud/event/ActionEventUtils.java +++ b/server/src/com/cloud/event/ActionEventUtils.java @@ -120,7 +120,7 @@ public class ActionEventUtils { public static void onStartedActionEventFromContext(String eventType, String eventDescription, boolean eventDisplayEnabled) { CallContext ctx = CallContext.current(); long userId = ctx.getCallingUserId(); - long accountId = ctx.getCallingAccountId(); + 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(); if (!eventType.equals("")) http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3bd53521/server/src/com/cloud/projects/ProjectManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/projects/ProjectManagerImpl.java b/server/src/com/cloud/projects/ProjectManagerImpl.java index 510b55c..95cf68a 100644 --- a/server/src/com/cloud/projects/ProjectManagerImpl.java +++ b/server/src/com/cloud/projects/ProjectManagerImpl.java @@ -222,6 +222,7 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager { if (project != null) { CallContext.current().setEventDetails("Project id=" + project.getId()); + CallContext.current().putContextParameter(Project.class, project.getUuid()); } //Increment resource count
