You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ch...@apache.org on 2013/07/17 19:35:04 UTC
[05/50] [abbrv] 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 cod
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
index a24300e..292b73e 100644
--- a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
+++ b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
@@ -35,6 +35,8 @@ import org.apache.cloudstack.api.command.user.vpn.ListVpnCustomerGatewaysCmd;
import org.apache.cloudstack.api.command.user.vpn.ListVpnGatewaysCmd;
import org.apache.cloudstack.api.command.user.vpn.ResetVpnConnectionCmd;
import org.apache.cloudstack.api.command.user.vpn.UpdateVpnCustomerGatewayCmd;
+import org.apache.cloudstack.context.CallContext;
+
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@@ -64,7 +66,6 @@ import com.cloud.network.vpc.dao.VpcDao;
import com.cloud.projects.Project.ListProjectResourcesCriteria;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
-import com.cloud.user.UserContext;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
@@ -112,7 +113,7 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn
@Override
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_GATEWAY_CREATE, eventDescription = "creating s2s vpn gateway", create=true)
public Site2SiteVpnGateway createVpnGateway(CreateVpnGatewayCmd cmd) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId());
//Verify that caller can perform actions in behalf of vpc owner
@@ -157,7 +158,7 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn
@Override
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CUSTOMER_GATEWAY_CREATE, eventDescription = "creating s2s customer gateway", create=true)
public Site2SiteCustomerGateway createCustomerGateway(CreateVpnCustomerGatewayCmd cmd) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId());
//Verify that caller can perform actions in behalf of vpc owner
@@ -225,7 +226,7 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn
@Override
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CONNECTION_CREATE, eventDescription = "creating s2s vpn connection", create=true)
public Site2SiteVpnConnection createVpnConnection(CreateVpnConnectionCmd cmd) throws NetworkRuleConflictException {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId());
//Verify that caller can perform actions in behalf of vpc owner
@@ -337,8 +338,8 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn
@Override
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CUSTOMER_GATEWAY_DELETE, eventDescription = "deleting s2s vpn customer gateway", create=true)
public boolean deleteCustomerGateway(DeleteVpnCustomerGatewayCmd cmd) {
- UserContext.current().setEventDetails(" Id: " + cmd.getId());
- Account caller = UserContext.current().getCaller();
+ CallContext.current().setEventDetails(" Id: " + cmd.getId());
+ Account caller = CallContext.current().getCallingAccount();
Long id = cmd.getId();
Site2SiteCustomerGateway customerGateway = _customerGatewayDao.findById(id);
@@ -371,8 +372,8 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn
@Override
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_GATEWAY_DELETE, eventDescription = "deleting s2s vpn gateway", create=true)
public boolean deleteVpnGateway(DeleteVpnGatewayCmd cmd) {
- UserContext.current().setEventDetails(" Id: " + cmd.getId());
- Account caller = UserContext.current().getCaller();
+ CallContext.current().setEventDetails(" Id: " + cmd.getId());
+ Account caller = CallContext.current().getCallingAccount();
Long id = cmd.getId();
Site2SiteVpnGateway vpnGateway = _vpnGatewayDao.findById(id);
@@ -389,8 +390,8 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn
@Override
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CUSTOMER_GATEWAY_UPDATE, eventDescription = "update s2s vpn customer gateway", create=true)
public Site2SiteCustomerGateway updateCustomerGateway(UpdateVpnCustomerGatewayCmd cmd) {
- UserContext.current().setEventDetails(" Id: " + cmd.getId());
- Account caller = UserContext.current().getCaller();
+ CallContext.current().setEventDetails(" Id: " + cmd.getId());
+ Account caller = CallContext.current().getCallingAccount();
Long id = cmd.getId();
Site2SiteCustomerGatewayVO gw = _customerGatewayDao.findById(id);
@@ -478,8 +479,8 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn
@Override
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CONNECTION_DELETE, eventDescription = "deleting s2s vpn connection", create=true)
public boolean deleteVpnConnection(DeleteVpnConnectionCmd cmd) throws ResourceUnavailableException {
- UserContext.current().setEventDetails(" Id: " + cmd.getId());
- Account caller = UserContext.current().getCaller();
+ CallContext.current().setEventDetails(" Id: " + cmd.getId());
+ Account caller = CallContext.current().getCallingAccount();
Long id = cmd.getId();
Site2SiteVpnConnectionVO conn = _vpnConnectionDao.findById(id);
@@ -528,8 +529,8 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn
@Override
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CONNECTION_RESET, eventDescription = "reseting s2s vpn connection", create=true)
public Site2SiteVpnConnection resetVpnConnection(ResetVpnConnectionCmd cmd) throws ResourceUnavailableException {
- UserContext.current().setEventDetails(" Id: " + cmd.getId());
- Account caller = UserContext.current().getCaller();
+ CallContext.current().setEventDetails(" Id: " + cmd.getId());
+ Account caller = CallContext.current().getCallingAccount();
Long id = cmd.getId();
Site2SiteVpnConnectionVO conn = _vpnConnectionDao.findById(id);
@@ -559,7 +560,7 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn
long startIndex = cmd.getStartIndex();
long pageSizeVal = cmd.getPageSizeVal();
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
List<Long> permittedAccounts = new ArrayList<Long>();
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean,
@@ -598,7 +599,7 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn
long startIndex = cmd.getStartIndex();
long pageSizeVal = cmd.getPageSizeVal();
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
List<Long> permittedAccounts = new ArrayList<Long>();
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean,
@@ -642,7 +643,7 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn
long startIndex = cmd.getStartIndex();
long pageSizeVal = cmd.getPageSizeVal();
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
List<Long> permittedAccounts = new ArrayList<Long>();
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean,
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/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 7ab385f..97fa413 100755
--- a/server/src/com/cloud/projects/ProjectManagerImpl.java
+++ b/server/src/com/cloud/projects/ProjectManagerImpl.java
@@ -40,6 +40,8 @@ import javax.mail.internet.InternetAddress;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
+import org.apache.cloudstack.context.CallContext;
+
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@@ -72,7 +74,6 @@ import com.cloud.user.AccountVO;
import com.cloud.user.DomainManager;
import com.cloud.user.ResourceLimitService;
import com.cloud.user.User;
-import com.cloud.user.UserContext;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.DateUtil;
import com.cloud.utils.NumbersUtil;
@@ -82,6 +83,7 @@ import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
+
import com.sun.mail.smtp.SMTPMessage;
import com.sun.mail.smtp.SMTPSSLTransport;
import com.sun.mail.smtp.SMTPTransport;
@@ -175,7 +177,7 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager {
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_CREATE, eventDescription = "creating project", create=true)
@DB
public Project createProject(String name, String displayText, String accountName, Long domainId) throws ResourceAllocationException{
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
Account owner = caller;
//check if the user authorized to create the project
@@ -215,7 +217,7 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager {
assignAccountToProject(project, owner.getId(), ProjectAccount.Role.Admin);
if (project != null) {
- UserContext.current().setEventDetails("Project id=" + project.getId());
+ CallContext.current().setEventDetails("Project id=" + project.getId());
}
//Increment resource count
@@ -231,7 +233,7 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager {
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_CREATE, eventDescription = "creating project", async=true)
@DB
public Project enableProject(long projectId){
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
ProjectVO project= getProject(projectId);
//verify input parameters
@@ -252,7 +254,7 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager {
@Override
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_DELETE, eventDescription = "deleting project", async = true)
public boolean deleteProject(long projectId) {
- UserContext ctx = UserContext.current();
+ CallContext ctx = CallContext.current();
ProjectVO project= getProject(projectId);
//verify input parameters
@@ -260,9 +262,9 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager {
throw new InvalidParameterValueException("Unable to find project by id " + projectId);
}
- _accountMgr.checkAccess(ctx.getCaller(),AccessType.ModifyProject, true, _accountMgr.getAccount(project.getProjectAccountId()));
+ _accountMgr.checkAccess(ctx.getCallingAccount(),AccessType.ModifyProject, true, _accountMgr.getAccount(project.getProjectAccountId()));
- return deleteProject(ctx.getCaller(), ctx.getCallerUserId(), project);
+ return deleteProject(ctx.getCallingAccount(), ctx.getCallingUserId(), project);
}
@DB
@@ -442,7 +444,7 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager {
@Override @DB
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_UPDATE, eventDescription = "updating project", async=true)
public Project updateProject(long projectId, String displayText, String newOwnerName) throws ResourceAllocationException{
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
//check that the project exists
ProjectVO project = getProject(projectId);
@@ -503,7 +505,7 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager {
@Override
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_ACCOUNT_ADD, eventDescription = "adding account to project", async=true)
public boolean addAccountToProject(long projectId, String accountName, String email) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
//check that the project exists
Project project = getProject(projectId);
@@ -589,7 +591,7 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager {
@Override
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_ACCOUNT_REMOVE, eventDescription = "removing account from project", async=true)
public boolean deleteAccountFromProject(long projectId, String accountName) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
//check that the project exists
Project project = getProject(projectId);
@@ -710,7 +712,7 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager {
@Override @DB
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_INVITATION_UPDATE, eventDescription = "updating project invitation", async=true)
public boolean updateInvitation(long projectId, String accountName, String token, boolean accept) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
Long accountId = null;
boolean result = true;
@@ -794,7 +796,7 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager {
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_ACTIVATE, eventDescription = "activating project")
@DB
public Project activateProject(long projectId) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
//check that the project exists
ProjectVO project = getProject(projectId);
@@ -837,7 +839,7 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager {
@Override
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_SUSPEND, eventDescription = "suspending project", async = true)
public Project suspendProject (long projectId) throws ConcurrentOperationException, ResourceUnavailableException {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
ProjectVO project= getProject(projectId);
//verify input parameters
@@ -979,7 +981,7 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager {
@Override @DB
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_INVITATION_REMOVE, eventDescription = "removing project invitation", async=true)
public boolean deleteProjectInvitation(long id) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
ProjectInvitation invitation = _projectInvitationDao.findById(id);
if (invitation == null) {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/src/com/cloud/resource/ResourceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java
index df40066..d7652f4 100755
--- a/server/src/com/cloud/resource/ResourceManagerImpl.java
+++ b/server/src/com/cloud/resource/ResourceManagerImpl.java
@@ -43,6 +43,7 @@ import org.apache.cloudstack.api.command.admin.host.PrepareForMaintenanceCmd;
import org.apache.cloudstack.api.command.admin.host.ReconnectHostCmd;
import org.apache.cloudstack.api.command.admin.host.UpdateHostCmd;
import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
+import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.region.dao.RegionDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
@@ -134,7 +135,6 @@ import com.cloud.template.VirtualMachineTemplate;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.User;
-import com.cloud.user.UserContext;
import com.cloud.utils.Pair;
import com.cloud.utils.StringUtils;
import com.cloud.utils.UriUtils;
@@ -378,7 +378,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
throw ex;
}
- Account account = UserContext.current().getCaller();
+ Account account = CallContext.current().getCallingAccount();
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) {
PermissionDeniedException ex = new PermissionDeniedException(
"Cannot perform this operation, Zone with specified id is currently disabled");
@@ -573,7 +573,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
String password = cmd.getPassword();
List<String> hostTags = cmd.getHostTags();
- dcId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), dcId);
+ dcId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), dcId);
// this is for standalone option
if (clusterName == null && clusterId == null) {
@@ -623,7 +623,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
throw new InvalidParameterValueException("Can't find zone by id " + dcId);
}
- Account account = UserContext.current().getCaller();
+ Account account = CallContext.current().getCallingAccount();
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) {
PermissionDeniedException ex = new PermissionDeniedException(
"Cannot perform this operation, Zone with specified id is currently disabled");
@@ -818,13 +818,13 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
@DB
protected boolean doDeleteHost(long hostId, boolean isForced, boolean isForceDeleteStorage) {
- User caller = _accountMgr.getActiveUser(UserContext.current().getCallerUserId());
+ User caller = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
// Verify that host exists
HostVO host = _hostDao.findById(hostId);
if (host == null) {
throw new InvalidParameterValueException("Host with id " + hostId + " doesn't exist");
}
- _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), host.getDataCenterId());
+ _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), host.getDataCenterId());
if (!isForced && host.getResourceState() != ResourceState.Maintenance) {
throw new CloudRuntimeException("Host " + host.getUuid() + " cannot be deleted as it is not in maintenance mode. Either put the host into maintenance or perform a forced deletion.");
@@ -2043,7 +2043,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
s_logger.debug("Deleting Host: " + host.getId() + " Guid:" + host.getGuid());
}
- User caller = _accountMgr.getActiveUser(UserContext.current().getCallerUserId());
+ User caller = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
if (forceDestroyStorage) {
// put local storage into mainenance mode, will set all the VMs on
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
index b5c060d..9ec27bd 100755
--- a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
+++ b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
@@ -30,8 +30,10 @@ import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
+import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
+
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@@ -78,7 +80,6 @@ import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.AccountVO;
import com.cloud.user.ResourceLimitService;
-import com.cloud.user.UserContext;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.ManagerBase;
@@ -424,7 +425,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
@Override
public List<ResourceLimitVO> searchForLimits(Long id, Long accountId, Long domainId, Integer type, Long startIndex, Long pageSizeVal) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
List<ResourceLimitVO> limits = new ArrayList<ResourceLimitVO>();
boolean isAccount = true;
@@ -568,7 +569,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
@Override
public ResourceLimitVO updateResourceLimit(Long accountId, Long domainId, Integer typeId, Long max) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
if (max == null) {
max = new Long(Resource.RESOURCE_UNLIMITED);
@@ -666,7 +667,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
@Override
public List<ResourceCountVO> recalculateResourceCount(Long accountId, Long domainId, Integer typeId) throws InvalidParameterValueException, CloudRuntimeException, PermissionDeniedException {
- Account callerAccount = UserContext.current().getCaller();
+ Account callerAccount = CallContext.current().getCallingAccount();
long count = 0;
List<ResourceCountVO> counts = new ArrayList<ResourceCountVO>();
List<ResourceType> resourceTypes = new ArrayList<ResourceType>();
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index f7fc834..8d979c7 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -41,15 +41,19 @@ import javax.naming.ConfigurationException;
import com.cloud.exception.*;
import com.cloud.vm.*;
+
import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
import org.apache.cloudstack.api.ApiConstants;
import com.cloud.event.ActionEventUtils;
+
import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoCmd;
import org.apache.cloudstack.api.command.admin.region.*;
+
import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Logger;
+
import org.apache.cloudstack.affinity.AffinityGroupProcessor;
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
import org.apache.cloudstack.api.command.admin.account.CreateAccountCmd;
@@ -513,7 +517,6 @@ import com.cloud.user.AccountService;
import com.cloud.user.SSHKeyPair;
import com.cloud.user.SSHKeyPairVO;
import com.cloud.user.User;
-import com.cloud.user.UserContext;
import com.cloud.user.UserVO;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.SSHKeyPairDao;
@@ -554,6 +557,7 @@ import org.apache.cloudstack.api.command.admin.region.AddRegionCmd;
import org.apache.cloudstack.api.command.admin.region.RemoveRegionCmd;
import org.apache.cloudstack.api.command.admin.region.UpdateRegionCmd;
import org.apache.cloudstack.api.command.admin.config.ListDeploymentPlannersCmd;
+import org.apache.cloudstack.context.CallContext;
public class ManagementServerImpl extends ManagerBase implements ManagementServer {
@@ -837,7 +841,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
@Override
public boolean archiveEvents(ArchiveEventsCmd cmd) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
List<Long> ids = cmd.getIds();
boolean result =true;
List<Long> permittedAccountIds = new ArrayList<Long>();
@@ -852,7 +856,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
List<EventVO> events = _eventDao.listToArchiveOrDeleteEvents(ids, cmd.getType(), cmd.getStartDate(), cmd.getEndDate(), permittedAccountIds);
ControlledEntity[] sameOwnerEvents = events.toArray(new ControlledEntity[events.size()]);
- _accountMgr.checkAccess(UserContext.current().getCaller(), null, true, sameOwnerEvents);
+ _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, sameOwnerEvents);
if (ids != null && events.size() < ids.size()) {
result = false;
@@ -864,7 +868,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
@Override
public boolean deleteEvents(DeleteEventsCmd cmd) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
List<Long> ids = cmd.getIds();
boolean result =true;
List<Long> permittedAccountIds = new ArrayList<Long>();
@@ -879,7 +883,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
List<EventVO> events = _eventDao.listToArchiveOrDeleteEvents(ids, cmd.getType(), cmd.getStartDate(), cmd.getEndDate(), permittedAccountIds);
ControlledEntity[] sameOwnerEvents = events.toArray(new ControlledEntity[events.size()]);
- _accountMgr.checkAccess(UserContext.current().getCaller(), null, true, sameOwnerEvents);
+ _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, sameOwnerEvents);
if (ids != null && events.size() < ids.size()) {
result = false;
@@ -906,7 +910,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
Filter searchFilter = new Filter(ClusterVO.class, "id", true, startIndex, pageSizeVal);
SearchCriteria<ClusterVO> sc = _clusterDao.createSearchCriteria();
- zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
+ zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), zoneId);
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
sc.addAnd("hypervisorType", SearchCriteria.Op.EQ, hypervisorType);
@@ -924,7 +928,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
Object clusterType = cmd.getClusterType();
Object allocationState = cmd.getAllocationState();
String keyword = cmd.getKeyword();
- zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
+ zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), zoneId);
Filter searchFilter = new Filter(ClusterVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
@@ -981,7 +985,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
@Override
public Pair<List<? extends Host>, Integer> searchForServers(ListHostsCmd cmd) {
- Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), cmd.getZoneId());
+ Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
Object name = cmd.getHostName();
Object type = cmd.getType();
Object state = cmd.getState();
@@ -1001,7 +1005,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
public Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Host, Boolean>>
listHostsForMigrationOfVM(Long vmId, Long startIndex, Long pageSize) {
// access check - only root admin can migrate VM
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Caller is not a root admin, permission denied to migrate the VM");
@@ -1188,7 +1192,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
@Override
public Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolume(Long volumeId) {
// Access check - only root administrator can migrate volumes.
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Caller is not a root admin, permission denied to migrate the volume");
@@ -1387,7 +1391,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
Long zoneId = cmd.getZoneId();
Object keyword = cmd.getKeyword();
Object allocationState = cmd.getAllocationState();
- zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
+ zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), zoneId);
Filter searchFilter = new Filter(HostPodVO.class, "dataCenterId", true, cmd.getStartIndex(), cmd.getPageSizeVal());
@@ -1745,7 +1749,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
Integer sortKey = cmd.getSortKey();
Boolean isDynamicallyScalable = cmd.isDynamicallyScalable();
Boolean isRoutingTemplate = cmd.isRoutingType();
- Account account = UserContext.current().getCaller();
+ Account account = CallContext.current().getCallingAccount();
// verify that template exists
VMTemplateVO template = _templateDao.findById(id);
@@ -1865,7 +1869,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
List<Long> permittedAccounts = new ArrayList<Long>();
ListProjectResourcesCriteria listProjectResourcesCriteria = null;
if (isAllocated) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(
cmd.getDomainId(), cmd.isRecursive(), null);
@@ -2056,9 +2060,9 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
private ConsoleProxyVO stopConsoleProxy(VMInstanceVO systemVm, boolean isForced) throws ResourceUnavailableException, OperationTimedoutException,
ConcurrentOperationException {
- User caller = _userDao.findById(UserContext.current().getCallerUserId());
+ User caller = _userDao.findById(CallContext.current().getCallingUserId());
- if (_itMgr.advanceStop(systemVm, isForced, caller, UserContext.current().getCaller())) {
+ if (_itMgr.advanceStop(systemVm, isForced, caller, CallContext.current().getCallingAccount())) {
return _consoleProxyDao.findById(systemVm.getId());
}
return null;
@@ -2132,7 +2136,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
}
// check permissions
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
_accountMgr.checkAccess(caller, domain);
// domain name is unique under the parent domain
@@ -2216,7 +2220,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
Object type = cmd.getType();
Object keyword = cmd.getKeyword();
- Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), null);
+ Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), null);
if (id != null) {
sc.addAnd("id", SearchCriteria.Op.EQ, id);
}
@@ -2242,14 +2246,14 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
@Override
public boolean archiveAlerts(ArchiveAlertsCmd cmd) {
- Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), null);
+ Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), null);
boolean result = _alertDao.archiveAlert(cmd.getIds(), cmd.getType(), cmd.getStartDate(), cmd.getEndDate(), zoneId);
return result;
}
@Override
public boolean deleteAlerts(DeleteAlertsCmd cmd) {
- Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), null);
+ Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), null);
boolean result = _alertDao.deleteAlert(cmd.getIds(), cmd.getType(), cmd.getStartDate(), cmd.getEndDate(), zoneId);
return result;
}
@@ -2265,7 +2269,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
if (clusterId != null) {
throw new InvalidParameterValueException("Currently clusterId param is not suppoerted");
}
- zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
+ zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), zoneId);
List<SummedCapacity> summedCapacities = new ArrayList<SummedCapacity>();
if (zoneId == null && podId == null) {// Group by Zone, capacity type
@@ -2374,7 +2378,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
Long clusterId = cmd.getClusterId();
Boolean fetchLatest = cmd.getFetchLatest();
- zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
+ zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), zoneId);
if (fetchLatest != null && fetchLatest) {
_alertMgr.recalculateCapacity();
}
@@ -2945,9 +2949,9 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
private SecondaryStorageVmVO stopSecondaryStorageVm(VMInstanceVO systemVm, boolean isForced) throws ResourceUnavailableException,
OperationTimedoutException, ConcurrentOperationException {
- User caller = _userDao.findById(UserContext.current().getCallerUserId());
+ User caller = _userDao.findById(CallContext.current().getCallingUserId());
- if (_itMgr.advanceStop(systemVm, isForced, caller, UserContext.current().getCaller())) {
+ if (_itMgr.advanceStop(systemVm, isForced, caller, CallContext.current().getCallingAccount())) {
return _secStorageVmDao.findById(systemVm.getId());
}
return null;
@@ -2971,7 +2975,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
@Override
public Pair<List<? extends VirtualMachine>, Integer> searchForSystemVm(ListSystemVMsCmd cmd) {
String type = cmd.getSystemVmType();
- Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), cmd.getZoneId());
+ Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
Long id = cmd.getId();
String name = cmd.getSystemVmName();
String state = cmd.getState();
@@ -3153,7 +3157,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
@Override
public ArrayList<String> getCloudIdentifierResponse(long userId) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
// verify that user exists
User user = _accountMgr.getUserIncludingRemoved(userId);
@@ -3241,7 +3245,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
@Override
public InstanceGroupVO updateVmGroup(UpdateVMGroupCmd cmd) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
Long groupId = cmd.getId();
String groupName = cmd.getGroupName();
@@ -3439,7 +3443,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
@Override
public SSHKeyPair createSSHKeyPair(CreateSSHKeyPairCmd cmd) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
String accountName = cmd.getAccountName();
Long domainId = cmd.getDomainId();
Long projectId = cmd.getProjectId();
@@ -3463,7 +3467,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
@Override
public boolean deleteSSHKeyPair(DeleteSSHKeyPairCmd cmd) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
String accountName = cmd.getAccountName();
Long domainId = cmd.getDomainId();
Long projectId = cmd.getProjectId();
@@ -3491,7 +3495,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
String name = cmd.getName();
String fingerPrint = cmd.getFingerprint();
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
List<Long> permittedAccounts = new ArrayList<Long>();
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(
@@ -3523,7 +3527,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
@Override
@ActionEvent(eventType = EventTypes.EVENT_REGISTER_SSH_KEYPAIR, eventDescription = "registering ssh keypair", async = true)
public SSHKeyPair registerSSHKeyPair(RegisterSSHKeyPairCmd cmd) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
Account owner = _accountMgr.finalizeOwner(caller, cmd.getAccountName(), cmd.getDomainId(), cmd.getProjectId());
@@ -3561,7 +3565,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
@Override
public String getVMPassword(GetVMPasswordCmd cmd) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
UserVmVO vm = _userVmDao.findById(cmd.getId());
if (vm == null) {
@@ -3708,7 +3712,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
if (_hypervisorCapabilitiesDao.update(id, hpvCapabilities)) {
hpvCapabilities = _hypervisorCapabilitiesDao.findById(id);
- UserContext.current().setEventDetails("Hypervisor Capabilities id=" + hpvCapabilities.getId());
+ CallContext.current().setEventDetails("Hypervisor Capabilities id=" + hpvCapabilities.getId());
return hpvCapabilities;
} else {
return null;
@@ -3737,7 +3741,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
}
private VirtualMachine upgradeStoppedSystemVm(Long systemVmId, Long serviceOfferingId){
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(systemVmId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm);
if (systemVm == null) {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/src/com/cloud/storage/StorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java
index 830fd36..2b57bae 100755
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -51,6 +51,7 @@ import org.apache.cloudstack.api.command.admin.storage.CreateStoragePoolCmd;
import org.apache.cloudstack.api.command.admin.storage.DeleteImageStoreCmd;
import org.apache.cloudstack.api.command.admin.storage.DeletePoolCmd;
import org.apache.cloudstack.api.command.admin.storage.UpdateStoragePoolCmd;
+import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle;
@@ -148,7 +149,6 @@ import com.cloud.template.TemplateManager;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.User;
-import com.cloud.user.UserContext;
import com.cloud.user.dao.UserDao;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
@@ -698,7 +698,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
throw new InvalidParameterValueException("unable to find zone by id " + zoneId);
}
// Check if zone is disabled
- Account account = UserContext.current().getCaller();
+ Account account = CallContext.current().getCallingAccount();
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) {
throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId);
}
@@ -1195,9 +1195,9 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
@DB
public PrimaryDataStoreInfo preparePrimaryStorageForMaintenance(Long primaryStorageId) throws ResourceUnavailableException,
InsufficientCapacityException {
- Long userId = UserContext.current().getCallerUserId();
+ Long userId = CallContext.current().getCallingUserId();
User user = _userDao.findById(userId);
- Account account = UserContext.current().getCaller();
+ Account account = CallContext.current().getCallingAccount();
boolean restart = true;
StoragePoolVO primaryStorage = null;
@@ -1226,9 +1226,9 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
@DB
public PrimaryDataStoreInfo cancelPrimaryStorageForMaintenance(CancelPrimaryStorageMaintenanceCmd cmd) throws ResourceUnavailableException {
Long primaryStorageId = cmd.getId();
- Long userId = UserContext.current().getCallerUserId();
+ Long userId = CallContext.current().getCallingUserId();
User user = _userDao.findById(userId);
- Account account = UserContext.current().getCaller();
+ Account account = CallContext.current().getCallingAccount();
StoragePoolVO primaryStorage = null;
primaryStorage = _storagePoolDao.findById(primaryStorageId);
@@ -1679,7 +1679,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
throw new InvalidParameterValueException("Can't find zone by id " + dcId);
}
- Account account = UserContext.current().getCaller();
+ Account account = CallContext.current().getCallingAccount();
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) {
PermissionDeniedException ex = new PermissionDeniedException(
"Cannot perform this operation, Zone with specified id is currently disabled");
@@ -1754,13 +1754,13 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
@Override
public boolean deleteImageStore(DeleteImageStoreCmd cmd) {
long storeId = cmd.getId();
- User caller = _accountMgr.getActiveUser(UserContext.current().getCallerUserId());
+ User caller = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
// Verify that image store exists
ImageStoreVO store = _imageStoreDao.findById(storeId);
if (store == null) {
throw new InvalidParameterValueException("Image store with id " + storeId + " doesn't exist");
}
- _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), store.getDataCenterId());
+ _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), store.getDataCenterId());
// Verify that there are no live snapshot, template, volume on the image
// store to be deleted
@@ -1833,7 +1833,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
throw new InvalidParameterValueException("Can't find zone by id " + dcId);
}
- Account account = UserContext.current().getCaller();
+ Account account = CallContext.current().getCallingAccount();
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) {
PermissionDeniedException ex = new PermissionDeniedException(
"Cannot perform this operation, Zone with specified id is currently disabled");
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/src/com/cloud/storage/StoragePoolAutomationImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/StoragePoolAutomationImpl.java b/server/src/com/cloud/storage/StoragePoolAutomationImpl.java
index f6b39f1..5c97183 100644
--- a/server/src/com/cloud/storage/StoragePoolAutomationImpl.java
+++ b/server/src/com/cloud/storage/StoragePoolAutomationImpl.java
@@ -23,9 +23,11 @@ import java.util.List;
import javax.inject.Inject;
+import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.subsystem.api.storage.*;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@@ -44,7 +46,6 @@ import com.cloud.storage.dao.StoragePoolWorkDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.user.Account;
import com.cloud.user.User;
-import com.cloud.user.UserContext;
import com.cloud.user.dao.UserDao;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.exception.ExecutionException;
@@ -103,9 +104,9 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation {
@Override
public boolean maintain(DataStore store) {
- Long userId = UserContext.current().getCallerUserId();
+ Long userId = CallContext.current().getCallingUserId();
User user = _userDao.findById(userId);
- Account account = UserContext.current().getCaller();
+ Account account = CallContext.current().getCallingAccount();
StoragePoolVO pool = this.primaryDataStoreDao.findById(store.getId());
try {
List<StoragePoolVO> spes = null;
@@ -355,9 +356,9 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation {
@Override
public boolean cancelMaintain(DataStore store) {
// Change the storage state back to up
- Long userId = UserContext.current().getCallerUserId();
+ Long userId = CallContext.current().getCallingUserId();
User user = _userDao.findById(userId);
- Account account = UserContext.current().getCaller();
+ Account account = CallContext.current().getCallingAccount();
StoragePoolVO poolVO = this.primaryDataStoreDao
.findById(store.getId());
StoragePool pool = (StoragePool)store;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/src/com/cloud/storage/VolumeManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/VolumeManagerImpl.java b/server/src/com/cloud/storage/VolumeManagerImpl.java
index 72d27bc..a8a3e1a 100644
--- a/server/src/com/cloud/storage/VolumeManagerImpl.java
+++ b/server/src/com/cloud/storage/VolumeManagerImpl.java
@@ -44,6 +44,7 @@ import org.apache.cloudstack.api.command.user.volume.MigrateVolumeCmd;
import org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd;
import org.apache.cloudstack.api.command.user.volume.UpdateVolumeCmd;
import org.apache.cloudstack.api.command.user.volume.UploadVolumeCmd;
+import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
@@ -153,7 +154,6 @@ import com.cloud.template.TemplateManager;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.ResourceLimitService;
-import com.cloud.user.UserContext;
import com.cloud.user.VmDiskStatisticsVO;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserDao;
@@ -386,7 +386,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_UPLOAD, eventDescription = "uploading volume", async = true)
public VolumeVO uploadVolume(UploadVolumeCmd cmd)
throws ResourceAllocationException {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
long ownerId = cmd.getEntityOwnerId();
Account owner = _accountDao.findById(ownerId);
Long zoneId = cmd.getZoneId();
@@ -753,7 +753,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
.getDomainId());
volume.setFormat(ImageFormat.valueOf(format));
volume = _volsDao.persist(volume);
- UserContext.current().setEventDetails("Volume Id: " + volume.getId());
+ CallContext.current().setEventDetails("Volume Id: " + volume.getId());
// Increment resource count during allocation; if actual creation fails,
// decrement it
@@ -823,7 +823,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
public VolumeVO allocVolume(CreateVolumeCmd cmd)
throws ResourceAllocationException {
// FIXME: some of the scheduled event stuff might be missing here...
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
long ownerId = cmd.getEntityOwnerId();
Boolean displayVolumeEnabled = cmd.getDisplayVolume();
@@ -1043,7 +1043,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
_usageEventDao.persist(usageEvent);
}
- UserContext.current().setEventDetails("Volume Id: " + volume.getId());
+ CallContext.current().setEventDetails("Volume Id: " + volume.getId());
// Increment resource count during allocation; if actual creation fails,
// decrement it
@@ -1178,8 +1178,8 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
if (newDiskOffering.getDomainId() == null) {
// do nothing as offering is public
} else {
- _configMgr.checkDiskOfferingAccess(UserContext.current()
- .getCaller(), newDiskOffering);
+ _configMgr.checkDiskOfferingAccess(CallContext.current()
+ .getCallingAccount(), newDiskOffering);
}
if (newDiskOffering.isCustomized()) {
@@ -1207,7 +1207,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
}
/* does the caller have the authority to act on this volume? */
- _accountMgr.checkAccess(UserContext.current().getCaller(), null, true,
+ _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true,
volume);
UserVmVO userVm = _userVmDao.findById(volume.getInstanceId());
@@ -1702,7 +1702,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
Long vmId = command.getVirtualMachineId();
Long volumeId = command.getId();
Long deviceId = command.getDeviceId();
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
// Check that the volume ID is valid
VolumeInfo volume = volFactory.getVolume(volumeId);
@@ -1901,7 +1901,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
@Override
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_DETACH, eventDescription = "detaching volume", async = true)
public Volume detachVolumeFromVM(DetachVolumeCmd cmmd) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
if ((cmmd.getId() == null && cmmd.getDeviceId() == null && cmmd
.getVirtualMachineId() == null)
|| (cmmd.getId() != null && (cmmd.getDeviceId() != null || cmmd
@@ -2663,7 +2663,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
@Override
public Snapshot allocSnapshot(Long volumeId, Long policyId) throws ResourceAllocationException {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
VolumeInfo volume = volFactory.getVolume(volumeId);
if (volume == null) {
@@ -2704,7 +2704,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
Long volumeId = cmd.getId();
Long zoneId = cmd.getZoneId();
String mode = cmd.getMode();
- Account account = UserContext.current().getCaller();
+ Account account = CallContext.current().getCallingAccount();
if (!_accountMgr.isRootAdmin(account.getType()) && ApiDBUtils.isExtractionDisabled()) {
throw new PermissionDeniedException("Extraction has been disabled by admin");
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
index ec663da..9408d48 100755
--- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
+++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
@@ -31,6 +31,7 @@ import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
+import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
@@ -107,7 +108,6 @@ import com.cloud.template.TemplateManager;
import com.cloud.user.Account;
import com.cloud.user.AccountService;
import com.cloud.user.User;
-import com.cloud.user.UserContext;
import com.cloud.utils.DateUtil;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
@@ -1208,9 +1208,9 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
//release elastic IP here
IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId());
if (ip != null && ip.getSystem()) {
- UserContext ctx = UserContext.current();
+ CallContext ctx = CallContext.current();
try {
- _rulesMgr.disableStaticNat(ip.getId(), ctx.getCaller(), ctx.getCallerUserId(), true);
+ _rulesMgr.disableStaticNat(ip.getId(), ctx.getCallingAccount(), ctx.getCallingUserId(), true);
} catch (Exception ex) {
s_logger.warn("Failed to disable static nat and release system ip " + ip + " as a part of vm " + profile.getVirtualMachine() + " stop due to exception ", ex);
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
index 2c9ef82..ddba735 100755
--- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
+++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
@@ -30,6 +30,7 @@ import org.apache.cloudstack.api.command.user.snapshot.CreateSnapshotPolicyCmd;
import org.apache.cloudstack.api.command.user.snapshot.DeleteSnapshotPoliciesCmd;
import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotPoliciesCmd;
import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotsCmd;
+import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
@@ -44,6 +45,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
+
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@@ -109,7 +111,6 @@ import com.cloud.user.AccountVO;
import com.cloud.user.DomainManager;
import com.cloud.user.ResourceLimitService;
import com.cloud.user.User;
-import com.cloud.user.UserContext;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.DateUtil;
import com.cloud.utils.DateUtil.IntervalType;
@@ -280,7 +281,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
boolean backedUp = false;
// does the caller have the authority to act on this volume
- _accountMgr.checkAccess(UserContext.current().getCaller(), null, true, volume);
+ _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, volume);
SnapshotInfo snapshot = this.snapshotFactory.getSnapshot(snapshotId, DataStoreRole.Primary);
@@ -427,7 +428,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
}
private Long getSnapshotUserId() {
- Long userId = UserContext.current().getCallerUserId();
+ Long userId = CallContext.current().getCallingUserId();
if (userId == null) {
return User.UID_SYSTEM;
}
@@ -476,7 +477,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
@DB
@ActionEvent(eventType = EventTypes.EVENT_SNAPSHOT_DELETE, eventDescription = "deleting snapshot", async = true)
public boolean deleteSnapshot(long snapshotId) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
// Verify parameters
SnapshotVO snapshotCheck = this._snapshotDao.findById(snapshotId);
@@ -534,14 +535,14 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
String intervalTypeStr = cmd.getIntervalType();
Map<String, String> tags = cmd.getTags();
Long zoneId = cmd.getZoneId();
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
List<Long> permittedAccounts = new ArrayList<Long>();
// Verify parameters
if (volumeId != null) {
VolumeVO volume = _volsDao.findById(volumeId);
if (volume != null) {
- _accountMgr.checkAccess(UserContext.current().getCaller(), null, true, volume);
+ _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, volume);
}
}
@@ -712,7 +713,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
throw new InvalidParameterValueException("Failed to create snapshot policy, unable to find a volume with id " + volumeId);
}
- _accountMgr.checkAccess(UserContext.current().getCaller(), null, true, volume);
+ _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, volume);
if (volume.getState() != Volume.State.Ready) {
throw new InvalidParameterValueException("VolumeId: " + volumeId + " is not in " + Volume.State.Ready + " state but " + volume.getState() + ". Cannot take snapshot.");
@@ -810,7 +811,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
if (volume == null) {
throw new InvalidParameterValueException("Unable to find a volume with id " + volumeId);
}
- _accountMgr.checkAccess(UserContext.current().getCaller(), null, true, volume);
+ _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, volume);
Pair<List<SnapshotPolicyVO>, Integer> result = _snapshotPolicyDao.listAndCountByVolumeId(volumeId);
return new Pair<List<? extends SnapshotPolicy>, Integer>(result.first(), result.second());
}
@@ -847,7 +848,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
public List<SnapshotScheduleVO> findRecurringSnapshotSchedule(ListRecurringSnapshotScheduleCmd cmd) {
Long volumeId = cmd.getVolumeId();
Long policyId = cmd.getSnapshotPolicyId();
- Account account = UserContext.current().getCaller();
+ Account account = CallContext.current().getCallingAccount();
// Verify parameters
VolumeVO volume = _volsDao.findById(volumeId);
@@ -1070,7 +1071,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
throw new InvalidParameterValueException("Policy id given: " + policy + " does not belong to a valid volume");
}
- _accountMgr.checkAccess(UserContext.current().getCaller(), null, true, volume);
+ _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, volume);
}
boolean success = true;
@@ -1102,7 +1103,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
@Override
public Snapshot allocSnapshot(Long volumeId, Long policyId) throws ResourceAllocationException {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
VolumeInfo volume = this.volFactory.getVolume(volumeId);
supportedByHypervisor(volume);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/src/com/cloud/tags/TaggedResourceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/tags/TaggedResourceManagerImpl.java b/server/src/com/cloud/tags/TaggedResourceManagerImpl.java
index 5f25499..e90481c 100644
--- a/server/src/com/cloud/tags/TaggedResourceManagerImpl.java
+++ b/server/src/com/cloud/tags/TaggedResourceManagerImpl.java
@@ -27,9 +27,12 @@ import javax.naming.ConfigurationException;
import com.cloud.vm.dao.NicDao;
import com.cloud.network.vpc.NetworkACLItemDao;
+
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
+import org.apache.cloudstack.context.CallContext;
+
import com.cloud.api.query.dao.ResourceTagJoinDao;
import com.cloud.domain.Domain;
import com.cloud.event.ActionEvent;
@@ -56,7 +59,6 @@ import com.cloud.tags.dao.ResourceTagDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.DomainManager;
-import com.cloud.user.UserContext;
import com.cloud.utils.Pair;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.db.DB;
@@ -248,7 +250,7 @@ public class TaggedResourceManagerImpl extends ManagerBase implements TaggedReso
@ActionEvent(eventType = EventTypes.EVENT_TAGS_CREATE, eventDescription = "creating resource tags")
public List<ResourceTag> createTags(List<String> resourceIds, TaggedResourceType resourceType,
Map<String, String> tags, String customer) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
List<ResourceTag> resourceTags = new ArrayList<ResourceTag>(tags.size());
@@ -332,7 +334,7 @@ public class TaggedResourceManagerImpl extends ManagerBase implements TaggedReso
@DB
@ActionEvent(eventType = EventTypes.EVENT_TAGS_DELETE, eventDescription = "deleting resource tags")
public boolean deleteTags(List<String> resourceIds, TaggedResourceType resourceType, Map<String, String> tags) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
SearchBuilder<ResourceTagVO> sb = _resourceTagDao.createSearchBuilder();
sb.and().op("resourceId", sb.entity().getResourceId(), SearchCriteria.Op.IN);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/src/com/cloud/template/TemplateAdapterBase.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/TemplateAdapterBase.java b/server/src/com/cloud/template/TemplateAdapterBase.java
index 4f29fcd..0e03cf4 100755
--- a/server/src/com/cloud/template/TemplateAdapterBase.java
+++ b/server/src/com/cloud/template/TemplateAdapterBase.java
@@ -27,9 +27,11 @@ import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd;
import org.apache.cloudstack.api.command.user.template.DeleteTemplateCmd;
import org.apache.cloudstack.api.command.user.template.ExtractTemplateCmd;
import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd;
+import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
+
import org.apache.log4j.Logger;
import com.cloud.api.ApiDBUtils;
@@ -59,7 +61,6 @@ import com.cloud.storage.dao.VMTemplateZoneDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.ResourceLimitService;
-import com.cloud.user.UserContext;
import com.cloud.user.UserVO;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserDao;
@@ -201,7 +202,7 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat
if (zone == null) {
throw new IllegalArgumentException("Please specify a valid zone.");
}
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
if(Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())){
throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: "+ zoneId );
}
@@ -215,7 +216,7 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat
}
Long id = _tmpltDao.getNextInSequence(Long.class, "id");
- UserContext.current().setEventDetails("Id: " +id+ " name: " + name);
+ CallContext.current().setEventDetails("Id: " +id+ " name: " + name);
return new TemplateProfile(id, userId, name, displayText, bits, passwordEnabled, requiresHVM, url, isPublic,
featured, isExtractable, imgfmt, guestOSId, zoneId, hypervisorType, templateOwner.getAccountName(), templateOwner.getDomainId(),
templateOwner.getAccountId(), chksum, bootable, templateTag, details, sshkeyEnabled, null, isDynamicallyScalable, templateType);
@@ -225,13 +226,13 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat
@Override
public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocationException {
//check if the caller can operate with the template owner
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId());
_accountMgr.checkAccess(caller, null, true, owner);
boolean isRouting = (cmd.isRoutingType() == null) ? false : cmd.isRoutingType();
- return prepare(false, UserContext.current().getCallerUserId(), cmd.getTemplateName(), cmd.getDisplayText(),
+ return prepare(false, CallContext.current().getCallingUserId(), cmd.getTemplateName(), cmd.getDisplayText(),
cmd.getBits(), cmd.isPasswordEnabled(), cmd.getRequiresHvm(), cmd.getUrl(), cmd.isPublic(), cmd.isFeatured(),
cmd.isExtractable(), cmd.getFormat(), cmd.getOsTypeId(), cmd.getZoneId(), HypervisorType.getType(cmd.getHypervisor()),
cmd.getChecksum(), true, cmd.getTemplateTag(), owner, cmd.getDetails(), cmd.isSshKeyEnabled(), null, cmd.isDynamicallyScalable(),
@@ -242,11 +243,11 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat
@Override
public TemplateProfile prepare(RegisterIsoCmd cmd) throws ResourceAllocationException {
//check if the caller can operate with the template owner
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId());
_accountMgr.checkAccess(caller, null, true, owner);
- return prepare(true, UserContext.current().getCallerUserId(), cmd.getIsoName(), cmd.getDisplayText(), 64, false,
+ return prepare(true, CallContext.current().getCallingUserId(), cmd.getIsoName(), cmd.getDisplayText(), 64, false,
true, cmd.getUrl(), cmd.isPublic(), cmd.isFeatured(), cmd.isExtractable(), ImageFormat.ISO.toString(), cmd.getOsTypeId(),
cmd.getZoneId(), HypervisorType.None, cmd.getChecksum(), cmd.isBootable(), null, owner, null, false, cmd.getImageStoreUuid(), cmd.isDynamicallyScalable(),
TemplateType.USER);
@@ -323,8 +324,8 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat
@Override
public TemplateProfile prepareDelete(DeleteTemplateCmd cmd) {
Long templateId = cmd.getId();
- Long userId = UserContext.current().getCallerUserId();
- Account account = UserContext.current().getCaller();
+ Long userId = CallContext.current().getCallingUserId();
+ Account account = CallContext.current().getCallingAccount();
Long zoneId = cmd.getZoneId();
VMTemplateVO template = _tmpltDao.findById(templateId.longValue());
@@ -348,7 +349,7 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat
public TemplateProfile prepareExtractTemplate(ExtractTemplateCmd cmd) {
Long templateId = cmd.getId();
- Long userId = UserContext.current().getCallerUserId();
+ Long userId = CallContext.current().getCallingUserId();
Long zoneId = cmd.getZoneId();
VMTemplateVO template = _tmpltDao.findById(templateId.longValue());
@@ -360,8 +361,8 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat
public TemplateProfile prepareDelete(DeleteIsoCmd cmd) {
Long templateId = cmd.getId();
- Long userId = UserContext.current().getCallerUserId();
- Account account = UserContext.current().getCaller();
+ Long userId = CallContext.current().getCallingUserId();
+ Account account = CallContext.current().getCallingAccount();
Long zoneId = cmd.getZoneId();
VMTemplateVO template = _tmpltDao.findById(templateId.longValue());
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/src/com/cloud/template/TemplateManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java
index 18a69ca..c7cc818 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -25,6 +25,7 @@ import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
@@ -47,6 +48,7 @@ import org.apache.cloudstack.api.command.user.template.ListTemplatePermissionsCm
import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd;
import org.apache.cloudstack.api.command.user.template.UpdateTemplateCmd;
import org.apache.cloudstack.api.command.user.template.UpdateTemplatePermissionsCmd;
+import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
@@ -72,6 +74,7 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
+
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@@ -79,7 +82,6 @@ import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.ComputeChecksumCommand;
-
import com.cloud.agent.api.storage.DestroyCommand;
import com.cloud.agent.api.to.DataTO;
import com.cloud.agent.api.to.DiskTO;
@@ -113,7 +115,6 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.hypervisor.HypervisorGuruManager;
import com.cloud.projects.Project;
import com.cloud.projects.ProjectManager;
-
import com.cloud.resource.ResourceManager;
import com.cloud.server.ConfigurationServer;
import com.cloud.storage.GuestOSVO;
@@ -121,7 +122,6 @@ import com.cloud.storage.LaunchPermissionVO;
import com.cloud.storage.Snapshot;
import com.cloud.storage.SnapshotVO;
import com.cloud.storage.Storage;
-
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.Storage.TemplateType;
import com.cloud.storage.DataStoreRole;
@@ -133,7 +133,6 @@ import com.cloud.storage.StoragePoolStatus;
import com.cloud.storage.TemplateProfile;
import com.cloud.storage.Upload;
import com.cloud.storage.VMTemplateZoneVO;
-
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.VMTemplateStoragePoolVO;
import com.cloud.storage.VMTemplateStorageResourceAssoc;
@@ -157,14 +156,12 @@ import com.cloud.storage.download.DownloadMonitor;
import com.cloud.storage.secondary.SecondaryStorageVmManager;
import com.cloud.storage.upload.UploadMonitor;
import com.cloud.template.TemplateAdapter.TemplateAdapterType;
-
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.AccountService;
import com.cloud.user.AccountVO;
import com.cloud.user.ResourceLimitService;
import com.cloud.user.User;
-import com.cloud.user.UserContext;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserAccountDao;
import com.cloud.user.dao.UserDao;
@@ -332,7 +329,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
@Override
@ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_CREATE, eventDescription = "creating template")
public VirtualMachineTemplate registerTemplate(RegisterTemplateCmd cmd) throws URISyntaxException, ResourceAllocationException {
- Account account = UserContext.current().getCaller();
+ Account account = CallContext.current().getCallingAccount();
if (cmd.getTemplateTag() != null) {
if (!_accountService.isRootAdmin(account.getType())) {
throw new PermissionDeniedException("Parameter templatetag can only be specified by a Root Admin, permission denied");
@@ -374,7 +371,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
@Override
@ActionEvent(eventType = EventTypes.EVENT_ISO_EXTRACT, eventDescription = "extracting ISO", async = true)
public String extract(ExtractIsoCmd cmd) {
- Account account = UserContext.current().getCaller();
+ Account account = CallContext.current().getCallingAccount();
Long templateId = cmd.getId();
Long zoneId = cmd.getZoneId();
String url = cmd.getUrl();
@@ -387,7 +384,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
@Override
@ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_EXTRACT, eventDescription = "extracting template", async = true)
public String extract(ExtractTemplateCmd cmd) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
Long templateId = cmd.getId();
Long zoneId = cmd.getZoneId();
String url = cmd.getUrl();
@@ -412,7 +409,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
throw new InvalidParameterValueException("Unable to find template id=" + templateId);
}
- _accountMgr.checkAccess(UserContext.current().getCaller(), AccessType.ModifyEntry, true, vmTemplate);
+ _accountMgr.checkAccess(CallContext.current().getCallingAccount(), AccessType.ModifyEntry, true, vmTemplate);
prepareTemplateInAllStoragePools(vmTemplate, zoneId);
return vmTemplate;
@@ -677,10 +674,10 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
@ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_COPY, eventDescription = "copying template", async = true)
public VirtualMachineTemplate copyTemplate(CopyTemplateCmd cmd) throws StorageUnavailableException, ResourceAllocationException {
Long templateId = cmd.getId();
- Long userId = UserContext.current().getCallerUserId();
+ Long userId = CallContext.current().getCallingUserId();
Long sourceZoneId = cmd.getSourceZoneId();
Long destZoneId = cmd.getDestinationZoneId();
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
// Verify parameters
if (sourceZoneId.equals(destZoneId)) {
@@ -888,8 +885,8 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
@Override
@ActionEvent(eventType = EventTypes.EVENT_ISO_DETACH, eventDescription = "detaching ISO", async = true)
public boolean detachIso(long vmId) {
- Account caller = UserContext.current().getCaller();
- Long userId = UserContext.current().getCallerUserId();
+ Account caller = CallContext.current().getCallingAccount();
+ Long userId = CallContext.current().getCallingUserId();
// Verify input parameters
UserVmVO vmInstanceCheck = _userVmDao.findById(vmId);
@@ -908,7 +905,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
if (isoId == null) {
throw new InvalidParameterValueException("The specified VM has no ISO attached to it.");
}
- UserContext.current().setEventDetails("Vm Id: " + vmId + " ISO Id: " + isoId);
+ CallContext.current().setEventDetails("Vm Id: " + vmId + " ISO Id: " + isoId);
State vmState = userVM.getState();
if (vmState != State.Running && vmState != State.Stopped) {
@@ -927,8 +924,8 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
@Override
@ActionEvent(eventType = EventTypes.EVENT_ISO_ATTACH, eventDescription = "attaching ISO", async = true)
public boolean attachIso(long isoId, long vmId) {
- Account caller = UserContext.current().getCaller();
- Long userId = UserContext.current().getCallerUserId();
+ Account caller = CallContext.current().getCallingAccount();
+ Long userId = CallContext.current().getCallingUserId();
// Verify input parameters
UserVmVO vm = _userVmDao.findById(vmId);
@@ -1045,7 +1042,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
@ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_DELETE, eventDescription = "deleting template", async = true)
public boolean deleteTemplate(DeleteTemplateCmd cmd) {
Long templateId = cmd.getId();
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
VirtualMachineTemplate template = getTemplate(templateId);
if (template == null) {
@@ -1067,7 +1064,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
@ActionEvent(eventType = EventTypes.EVENT_ISO_DELETE, eventDescription = "deleting iso", async = true)
public boolean deleteIso(DeleteIsoCmd cmd) {
Long templateId = cmd.getId();
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
Long zoneId = cmd.getZoneId();
VirtualMachineTemplate template = getTemplate(templateId);
@@ -1112,7 +1109,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
@Override
public List<String> listTemplatePermissions(BaseListTemplateOrIsoPermissionsCmd cmd) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
Long id = cmd.getId();
if (id.equals(Long.valueOf(1))) {
@@ -1163,7 +1160,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
// Input validation
Long id = cmd.getId();
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
List<String> accountNames = cmd.getAccountNames();
List<Long> projectIds = cmd.getProjectIds();
Boolean isFeatured = cmd.isFeatured();
@@ -1325,7 +1322,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
@DB
@ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_CREATE, eventDescription = "creating template", async = true)
public VirtualMachineTemplate createPrivateTemplate(CreateTemplateCmd command) throws CloudRuntimeException {
- Long userId = UserContext.current().getCallerUserId();
+ Long userId = CallContext.current().getCallingUserId();
if (userId == null) {
userId = User.UID_SYSTEM;
}
@@ -1433,9 +1430,9 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
@Override
@ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_CREATE, eventDescription = "creating template", create = true)
public VMTemplateVO createPrivateTemplateRecord(CreateTemplateCmd cmd, Account templateOwner) throws ResourceAllocationException {
- Long userId = UserContext.current().getCallerUserId();
+ Long userId = CallContext.current().getCallingUserId();
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
boolean isAdmin = (isAdmin(caller.getType()));
_accountMgr.checkAccess(caller, null, true, templateOwner);
@@ -1687,7 +1684,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
Boolean isRoutingTemplate = cmd.isRoutingType();
Boolean bootable = cmd.isBootable();
Integer sortKey = cmd.getSortKey();
- Account account = UserContext.current().getCaller();
+ Account account = CallContext.current().getCallingAccount();
// verify that template exists
VMTemplateVO template = _tmpltDao.findById(id);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/src/com/cloud/usage/UsageServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/usage/UsageServiceImpl.java b/server/src/com/cloud/usage/UsageServiceImpl.java
index ae0a585..e6e6ab9 100755
--- a/server/src/com/cloud/usage/UsageServiceImpl.java
+++ b/server/src/com/cloud/usage/UsageServiceImpl.java
@@ -30,8 +30,10 @@ import javax.naming.ConfigurationException;
import org.apache.cloudstack.api.command.admin.usage.GenerateUsageRecordsCmd;
import org.apache.cloudstack.api.command.admin.usage.GetUsageRecordsCmd;
import org.apache.cloudstack.api.response.UsageTypeResponse;
+import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.usage.UsageService;
import org.apache.cloudstack.usage.UsageTypes;
+
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@@ -46,7 +48,6 @@ import com.cloud.usage.dao.UsageDao;
import com.cloud.usage.dao.UsageJobDao;
import com.cloud.user.Account;
import com.cloud.user.AccountVO;
-import com.cloud.user.UserContext;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.component.Manager;
import com.cloud.utils.component.ManagerBase;
@@ -115,7 +116,7 @@ public class UsageServiceImpl extends ManagerBase implements UsageService, Manag
Long domainId = cmd.getDomainId();
String accountName = cmd.getAccountName();
Account userAccount = null;
- Account caller = (Account)UserContext.current().getCaller();
+ Account caller = (Account)CallContext.current().getCallingAccount();
Long usageType = cmd.getUsageType();
Long projectId = cmd.getProjectId();