Updated Branches: refs/heads/4.3-forward e8f93f28f -> 1283919f0
CLOUDSTACK-6065: Fix NPE problem caused by the lack of context setup in threads from agent manager thread pool Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/1283919f Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/1283919f Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/1283919f Branch: refs/heads/4.3-forward Commit: 1283919f02e2c4d2652ca18693b6cf2906b2263d Parents: e8f93f2 Author: Kelven Yang <[email protected]> Authored: Thu Feb 13 14:34:06 2014 -0800 Committer: Kelven Yang <[email protected]> Committed: Thu Feb 13 14:34:06 2014 -0800 ---------------------------------------------------------------------- .../framework/jobs/AsyncJobExecutionContext.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1283919f/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJobExecutionContext.java ---------------------------------------------------------------------- diff --git a/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJobExecutionContext.java b/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJobExecutionContext.java index 966e638..4343a4d 100644 --- a/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJobExecutionContext.java +++ b/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJobExecutionContext.java @@ -29,6 +29,8 @@ import org.apache.cloudstack.managed.threadlocal.ManagedThreadLocal; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.user.Account; +import com.cloud.user.User; public class AsyncJobExecutionContext { private static final Logger s_logger = Logger.getLogger(AsyncJobExecutionContext.class); @@ -167,10 +169,15 @@ public class AsyncJobExecutionContext { public static AsyncJobExecutionContext getCurrentExecutionContext() { AsyncJobExecutionContext context = s_currentExectionContext.get(); if (context == null) { - // TODO, this has security implicitions + // TODO, this has security implications, operations carried from API layer should always + // set its context, otherwise, the fall-back here will use system security context + // s_logger.warn("Job is executed without a context, setup psudo job for the executing thread"); - context = registerPseudoExecutionContext(CallContext.current().getCallingAccountId(), - CallContext.current().getCallingUserId()); + if (CallContext.current() != null) + context = registerPseudoExecutionContext(CallContext.current().getCallingAccountId(), + CallContext.current().getCallingUserId()); + else + context = registerPseudoExecutionContext(Account.ACCOUNT_ID_SYSTEM, User.UID_SYSTEM); } return context; }
