Skip to content

Commit 11e1e58

Browse files
author
ahuang
committed
UserContext switched to CallContext. Added generic storage mechanism for other code to carry information throughout a call. Made the calling User and Account a must have. Added an interface to carry entities in error. Fixed up the code. Part of the vmsync branch
1 parent fa9ca72 commit 11e1e58

270 files changed

Lines changed: 2352 additions & 1804 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/src/com/cloud/user/UserContext.java

Lines changed: 0 additions & 163 deletions
This file was deleted.

api/src/com/cloud/user/UserContextInitializer.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

api/src/org/apache/cloudstack/api/BaseAsyncCmd.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
package org.apache.cloudstack.api;
1818

1919
import org.apache.cloudstack.api.response.AsyncJobResponse;
20+
import org.apache.cloudstack.context.CallContext;
2021

2122
import com.cloud.async.AsyncJob;
2223
import com.cloud.user.User;
23-
import com.cloud.user.UserContext;
2424

2525
/**
2626
* queryAsyncJobResult API command.
@@ -109,8 +109,8 @@ protected long saveStartedEvent() {
109109
}
110110

111111
protected long saveStartedEvent(String eventType, String description, Long startEventId) {
112-
UserContext ctx = UserContext.current();
113-
Long userId = ctx.getCallerUserId();
112+
CallContext ctx = CallContext.current();
113+
Long userId = ctx.getCallingUserId();
114114
userId = (userId == null) ? User.UID_SYSTEM : userId;
115115
Long startEvent = startEventId;
116116
if (startEvent == null) {
@@ -124,8 +124,8 @@ protected long saveCompletedEvent(String level, String description) {
124124
}
125125

126126
protected long saveCompletedEvent(String level, String eventType, String description, Long startEventId) {
127-
UserContext ctx = UserContext.current();
128-
Long userId = ctx.getCallerUserId();
127+
CallContext ctx = CallContext.current();
128+
Long userId = ctx.getCallingUserId();
129129
userId = (userId == null) ? User.UID_SYSTEM : userId;
130130
Long startEvent = startEventId;
131131
if (startEvent == null) {

api/src/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
import java.util.List;
2020

2121
import org.apache.cloudstack.api.response.TemplatePermissionsResponse;
22+
import org.apache.cloudstack.context.CallContext;
23+
2224
import org.apache.log4j.Logger;
2325

2426
import com.cloud.template.VirtualMachineTemplate;
2527
import com.cloud.user.Account;
26-
import com.cloud.user.UserContext;
2728

2829
public class BaseListTemplateOrIsoPermissionsCmd extends BaseCmd {
2930
public Logger s_logger = getLogger();
@@ -79,7 +80,7 @@ protected Logger getLogger() {
7980
public void execute(){
8081
List<String> accountNames = _templateService.listTemplatePermissions(this);
8182

82-
Account account = UserContext.current().getCaller();
83+
Account account = CallContext.current().getCallingAccount();
8384
boolean isAdmin = (isAdmin(account.getType()));
8485

8586
TemplatePermissionsResponse response = _responseGenerator.createTemplatePermissionsResponse(accountNames, id, isAdmin);

api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import com.cloud.user.Account;
2020
import com.cloud.user.UserAccount;
21-
import com.cloud.user.UserContext;
21+
2222
import org.apache.cloudstack.api.APICommand;
2323
import org.apache.cloudstack.api.ApiConstants;
2424
import org.apache.cloudstack.api.ApiErrorCode;
@@ -27,6 +27,8 @@
2727
import org.apache.cloudstack.api.ServerApiException;
2828
import org.apache.cloudstack.api.response.AccountResponse;
2929
import org.apache.cloudstack.api.response.DomainResponse;
30+
import org.apache.cloudstack.context.CallContext;
31+
3032
import org.apache.log4j.Logger;
3133

3234
import java.util.Collection;
@@ -160,7 +162,7 @@ public long getEntityOwnerId() {
160162

161163
@Override
162164
public void execute(){
163-
UserContext.current().setEventDetails("Account Name: "+getAccountName()+", Domain Id:"+getDomainId());
165+
CallContext.current().setEventDetails("Account Name: "+getAccountName()+", Domain Id:"+getDomainId());
164166
UserAccount userAccount = _accountService.createUserAccount(getUsername(), getPassword(), getFirstName(), getLastName(), getEmail(), getTimeZone(), getAccountName(), getAccountType(),
165167
getDomainId(), getNetworkDomain(), getDetails(), getAccountUUID(), getUserUUID());
166168
if (userAccount != null) {

api/src/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727
import org.apache.cloudstack.api.ServerApiException;
2828
import org.apache.cloudstack.api.response.AccountResponse;
2929
import org.apache.cloudstack.api.response.SuccessResponse;
30+
import org.apache.cloudstack.context.CallContext;
3031
import org.apache.cloudstack.region.RegionService;
32+
3133
import org.apache.log4j.Logger;
3234

3335
import com.cloud.event.EventTypes;
3436
import com.cloud.user.Account;
3537
import com.cloud.user.User;
36-
import com.cloud.user.UserContext;
3738

3839
@APICommand(name = "deleteAccount", description="Deletes a account, and all users associated with this account", responseObject=SuccessResponse.class)
3940
public class DeleteAccountCmd extends BaseAsyncCmd {
@@ -74,7 +75,7 @@ public String getCommandName() {
7475

7576
@Override
7677
public long getEntityOwnerId() {
77-
Account account = UserContext.current().getCaller();// Let's give the caller here for event logging.
78+
Account account = CallContext.current().getCallingAccount();// Let's give the caller here for event logging.
7879
if (account != null) {
7980
return account.getAccountId();
8081
}
@@ -95,7 +96,7 @@ public String getEventDescription() {
9596

9697
@Override
9798
public void execute(){
98-
UserContext.current().setEventDetails("Account Id: "+getId());
99+
CallContext.current().setEventDetails("Account Id: "+getId());
99100

100101
boolean result = _regionService.deleteUserAccount(this);
101102
if (result) {

api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
import org.apache.cloudstack.api.ServerApiException;
2828
import org.apache.cloudstack.api.response.AccountResponse;
2929
import org.apache.cloudstack.api.response.DomainResponse;
30+
import org.apache.cloudstack.context.CallContext;
3031
import org.apache.cloudstack.region.RegionService;
32+
3133
import org.apache.log4j.Logger;
3234

3335
import com.cloud.event.EventTypes;
3436
import com.cloud.exception.ConcurrentOperationException;
3537
import com.cloud.exception.ResourceUnavailableException;
3638
import com.cloud.user.Account;
37-
import com.cloud.user.UserContext;
3839

3940
@APICommand(name = "disableAccount", description="Disables an account", responseObject=AccountResponse.class)
4041
public class DisableAccountCmd extends BaseAsyncCmd {
@@ -116,7 +117,7 @@ public String getEventDescription() {
116117

117118
@Override
118119
public void execute() throws ConcurrentOperationException, ResourceUnavailableException{
119-
UserContext.current().setEventDetails("Account Name: "+getAccountName()+", Domain Id:"+getDomainId());
120+
CallContext.current().setEventDetails("Account Name: "+getAccountName()+", Domain Id:"+getDomainId());
120121
Account result = _regionService.disableAccount(this);
121122
if (result != null){
122123
AccountResponse response = _responseGenerator.createAccountResponse(result);

api/src/org/apache/cloudstack/api/command/admin/domain/CreateDomainCmd.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
import org.apache.cloudstack.api.Parameter;
2424
import org.apache.cloudstack.api.ServerApiException;
2525
import org.apache.cloudstack.api.response.DomainResponse;
26+
import org.apache.cloudstack.context.CallContext;
27+
2628
import org.apache.log4j.Logger;
2729

2830
import com.cloud.domain.Domain;
2931
import com.cloud.user.Account;
30-
import com.cloud.user.UserContext;
3132

3233
@APICommand(name = "createDomain", description="Creates a domain", responseObject=DomainResponse.class)
3334
public class CreateDomainCmd extends BaseCmd {
@@ -88,7 +89,7 @@ public long getEntityOwnerId() {
8889

8990
@Override
9091
public void execute(){
91-
UserContext.current().setEventDetails("Domain Name: "+getDomainName()+((getParentDomainId()!=null)?", Parent DomainId :"+getParentDomainId():""));
92+
CallContext.current().setEventDetails("Domain Name: "+getDomainName()+((getParentDomainId()!=null)?", Parent DomainId :"+getParentDomainId():""));
9293
Domain domain = _domainService.createDomain(getDomainName(), getParentDomainId(), getNetworkDomain(), getDomainUUID());
9394
if (domain != null) {
9495
DomainResponse response = _responseGenerator.createDomainResponse(domain);

api/src/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@
2626
import org.apache.cloudstack.api.ServerApiException;
2727
import org.apache.cloudstack.api.response.DomainResponse;
2828
import org.apache.cloudstack.api.response.SuccessResponse;
29+
import org.apache.cloudstack.context.CallContext;
2930
import org.apache.cloudstack.region.RegionService;
31+
3032
import org.apache.log4j.Logger;
3133

3234
import com.cloud.domain.Domain;
3335
import com.cloud.event.EventTypes;
3436
import com.cloud.user.Account;
35-
import com.cloud.user.UserContext;
3637

3738
@APICommand(name = "deleteDomain", description="Deletes a specified domain", responseObject=SuccessResponse.class)
3839
public class DeleteDomainCmd extends BaseAsyncCmd {
@@ -95,7 +96,7 @@ public String getEventDescription() {
9596

9697
@Override
9798
public void execute(){
98-
UserContext.current().setEventDetails("Domain Id: "+getId());
99+
CallContext.current().setEventDetails("Domain Id: "+getId());
99100
boolean result = _regionService.deleteDomain(this);
100101
if (result) {
101102
SuccessResponse response = new SuccessResponse(getCommandName());

0 commit comments

Comments
 (0)