Skip to content

Commit a8c9238

Browse files
committed
CLOUDSTACK-6065: Fix NPE problem caused by the lack of context setup in threads from agent manager thread pool
1 parent ee2adab commit a8c9238

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJobExecutionContext.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import com.cloud.exception.ConcurrentOperationException;
3030
import com.cloud.exception.InsufficientCapacityException;
3131
import com.cloud.exception.ResourceUnavailableException;
32+
import com.cloud.user.Account;
33+
import com.cloud.user.User;
3234

3335
public class AsyncJobExecutionContext {
3436
private static final Logger s_logger = Logger.getLogger(AsyncJobExecutionContext.class);
@@ -167,10 +169,15 @@ public void completeJobAndJoin(JobInfo.Status joinStatus, String joinResult) {
167169
public static AsyncJobExecutionContext getCurrentExecutionContext() {
168170
AsyncJobExecutionContext context = s_currentExectionContext.get();
169171
if (context == null) {
170-
// TODO, this has security implicitions
172+
// TODO, this has security implications, operations carried from API layer should always
173+
// set its context, otherwise, the fall-back here will use system security context
174+
//
171175
s_logger.warn("Job is executed without a context, setup psudo job for the executing thread");
172-
context = registerPseudoExecutionContext(CallContext.current().getCallingAccountId(),
173-
CallContext.current().getCallingUserId());
176+
if (CallContext.current() != null)
177+
context = registerPseudoExecutionContext(CallContext.current().getCallingAccountId(),
178+
CallContext.current().getCallingUserId());
179+
else
180+
context = registerPseudoExecutionContext(Account.ACCOUNT_ID_SYSTEM, User.UID_SYSTEM);
174181
}
175182
return context;
176183
}

0 commit comments

Comments
 (0)