From 3bd53521e8944db447bfa69494d7f01f73727808 Mon Sep 17 00:00:00 2001 From: Rajani Karuturi Date: Wed, 9 Sep 2015 12:18:08 +0530 Subject: [PATCH] CLOUDSTACK-8816: Project UUID is not showing for some of operations in RabbitMQ. --- 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(-) diff --git a/api/src/org/apache/cloudstack/context/CallContext.java b/api/src/org/apache/cloudstack/context/CallContext.java index 73da826155e..2619f4a2e2c 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 context = new HashMap(); + 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. diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java index 0dc11643ba9..73755883697 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) { diff --git a/server/src/com/cloud/event/ActionEventInterceptor.java b/server/src/com/cloud/event/ActionEventInterceptor.java index 5d2d51a102a..d2dacd98a42 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); diff --git a/server/src/com/cloud/event/ActionEventUtils.java b/server/src/com/cloud/event/ActionEventUtils.java index 29eade21c96..0ca41cc3a73 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("")) diff --git a/server/src/com/cloud/projects/ProjectManagerImpl.java b/server/src/com/cloud/projects/ProjectManagerImpl.java index 510b55ca1a2..95cf68a354a 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