cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahu...@apache.org
Subject [12/12] git commit: updated refs/heads/master to aa13152
Date Tue, 16 Jul 2013 18:24:35 GMT
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


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/11e1e585
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/11e1e585
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/11e1e585

Branch: refs/heads/master
Commit: 11e1e585b16562f02f7671d928cb34aafebeab98
Parents: fa9ca72
Author: ahuang <alex.huang@citrix.com>
Authored: Tue Jul 16 02:41:08 2013 -0700
Committer: ahuang <alex.huang@citrix.com>
Committed: Tue Jul 16 11:24:21 2013 -0700

----------------------------------------------------------------------
 api/src/com/cloud/user/UserContext.java         | 163 -------------
 .../com/cloud/user/UserContextInitializer.java  |  40 ----
 .../org/apache/cloudstack/api/BaseAsyncCmd.java |  10 +-
 .../BaseListTemplateOrIsoPermissionsCmd.java    |   5 +-
 .../command/admin/account/CreateAccountCmd.java |   6 +-
 .../command/admin/account/DeleteAccountCmd.java |   7 +-
 .../admin/account/DisableAccountCmd.java        |   5 +-
 .../command/admin/domain/CreateDomainCmd.java   |   5 +-
 .../command/admin/domain/DeleteDomainCmd.java   |   5 +-
 .../command/admin/domain/UpdateDomainCmd.java   |   5 +-
 .../admin/host/CancelMaintenanceCmd.java        |   5 +-
 .../admin/host/PrepareForMaintenanceCmd.java    |   5 +-
 .../command/admin/host/ReconnectHostCmd.java    |   5 +-
 .../admin/host/ReleaseHostReservationCmd.java   |   5 +-
 ...ConfigureInternalLoadBalancerElementCmd.java |   7 +-
 .../CreateInternalLoadBalancerElementCmd.java   |   5 +-
 .../admin/internallb/StartInternalLBVMCmd.java  |   7 +-
 .../admin/internallb/StopInternalLBVMCmd.java   |   7 +-
 .../network/AddNetworkServiceProviderCmd.java   |   5 +-
 .../admin/network/CreatePhysicalNetworkCmd.java |   5 +-
 .../admin/network/DeletePhysicalNetworkCmd.java |   5 +-
 .../ReleaseDedicatedGuestVlanRangeCmd.java      |   6 +-
 .../ConfigureVirtualRouterElementCmd.java       |   5 +-
 .../router/CreateVirtualRouterElementCmd.java   |   5 +-
 .../command/admin/router/DestroyRouterCmd.java  |   7 +-
 .../command/admin/router/RebootRouterCmd.java   |   5 +-
 .../command/admin/router/StartRouterCmd.java    |   5 +-
 .../api/command/admin/router/StopRouterCmd.java |   5 +-
 .../CancelPrimaryStorageMaintenanceCmd.java     |   5 +-
 .../PreparePrimaryStorageForMaintenanceCmd.java |   5 +-
 .../admin/systemvm/DestroySystemVmCmd.java      |   7 +-
 .../admin/systemvm/MigrateSystemVMCmd.java      |   7 +-
 .../admin/systemvm/RebootSystemVmCmd.java       |   7 +-
 .../admin/systemvm/ScaleSystemVMCmd.java        |   8 +-
 .../admin/systemvm/StartSystemVMCmd.java        |   7 +-
 .../command/admin/systemvm/StopSystemVmCmd.java |   7 +-
 .../admin/systemvm/UpgradeSystemVMCmd.java      |   7 +-
 .../command/admin/usage/AddTrafficTypeCmd.java  |   5 +-
 .../api/command/admin/user/CreateUserCmd.java   |   7 +-
 .../api/command/admin/user/DeleteUserCmd.java   |   5 +-
 .../api/command/admin/user/DisableUserCmd.java  |   5 +-
 .../api/command/admin/user/EnableUserCmd.java   |   5 +-
 .../api/command/admin/user/UpdateUserCmd.java   |   5 +-
 .../api/command/admin/vm/MigrateVMCmd.java      |   7 +-
 .../vm/MigrateVirtualMachineWithVolumeCmd.java  |   5 +-
 .../admin/vpc/DeletePrivateGatewayCmd.java      |   5 +-
 .../api/command/admin/zone/CreateZoneCmd.java   |   5 +-
 .../api/command/admin/zone/DeleteZoneCmd.java   |   5 +-
 .../api/command/admin/zone/UpdateZoneCmd.java   |   5 +-
 .../user/account/AddAccountToProjectCmd.java    |   5 +-
 .../account/DeleteAccountFromProjectCmd.java    |   5 +-
 .../user/address/AssociateIPAddrCmd.java        |  11 +-
 .../user/address/DisassociateIPAddrCmd.java     |   5 +-
 .../affinitygroup/CreateAffinityGroupCmd.java   |   5 +-
 .../affinitygroup/DeleteAffinityGroupCmd.java   |   5 +-
 .../affinitygroup/UpdateVMAffinityGroupCmd.java |   5 +-
 .../autoscale/CreateAutoScaleVmProfileCmd.java  |   7 +-
 .../user/autoscale/CreateConditionCmd.java      |   9 +-
 .../autoscale/DeleteAutoScalePolicyCmd.java     |   5 +-
 .../autoscale/DeleteAutoScaleVmGroupCmd.java    |   5 +-
 .../autoscale/DeleteAutoScaleVmProfileCmd.java  |   5 +-
 .../autoscale/UpdateAutoScalePolicyCmd.java     |   5 +-
 .../autoscale/UpdateAutoScaleVmGroupCmd.java    |   5 +-
 .../autoscale/UpdateAutoScaleVmProfileCmd.java  |   5 +-
 .../command/user/event/ArchiveEventsCmd.java    |   5 +-
 .../api/command/user/event/DeleteEventsCmd.java |   5 +-
 .../firewall/CreateEgressFirewallRuleCmd.java   |  11 +-
 .../user/firewall/CreateFirewallRuleCmd.java    |  11 +-
 .../firewall/CreatePortForwardingRuleCmd.java   |  13 +-
 .../firewall/DeleteEgressFirewallRuleCmd.java   |   5 +-
 .../user/firewall/DeleteFirewallRuleCmd.java    |   5 +-
 .../firewall/DeletePortForwardingRuleCmd.java   |   5 +-
 .../api/command/user/iso/AttachIsoCmd.java      |   5 +-
 .../api/command/user/iso/DeleteIsoCmd.java      |   5 +-
 .../api/command/user/iso/ExtractIsoCmd.java     |   5 +-
 .../api/command/user/iso/ListIsosCmd.java       |   5 +-
 .../api/command/user/iso/RegisterIsoCmd.java    |   5 +-
 .../AssignToLoadBalancerRuleCmd.java            |   5 +-
 .../CreateApplicationLoadBalancerCmd.java       |   5 +-
 .../CreateLBHealthCheckPolicyCmd.java           |  10 +-
 .../CreateLBStickinessPolicyCmd.java            |   7 +-
 .../loadbalancer/CreateLoadBalancerRuleCmd.java |  11 +-
 .../DeleteApplicationLoadBalancerCmd.java       |   5 +-
 .../DeleteLBHealthCheckPolicyCmd.java           |   8 +-
 .../DeleteLBStickinessPolicyCmd.java            |   7 +-
 .../loadbalancer/DeleteLoadBalancerRuleCmd.java |   5 +-
 .../ListLBHealthCheckPoliciesCmd.java           |   3 +-
 .../ListLBStickinessPoliciesCmd.java            |   5 +-
 .../RemoveFromLoadBalancerRuleCmd.java          |   5 +-
 .../loadbalancer/UpdateLoadBalancerRuleCmd.java |   5 +-
 .../user/nat/CreateIpForwardingRuleCmd.java     |  11 +-
 .../user/nat/DeleteIpForwardingRuleCmd.java     |   5 +-
 .../user/network/CreateNetworkACLCmd.java       |   8 +-
 .../user/network/CreateNetworkACLListCmd.java   |   4 +-
 .../command/user/network/CreateNetworkCmd.java  |   5 +-
 .../user/network/DeleteNetworkACLCmd.java       |   8 +-
 .../user/network/DeleteNetworkACLListCmd.java   |   8 +-
 .../command/user/network/DeleteNetworkCmd.java  |   5 +-
 .../user/network/ReplaceNetworkACLListCmd.java  |   8 +-
 .../user/network/UpdateNetworkACLItemCmd.java   |   8 +-
 .../command/user/network/UpdateNetworkCmd.java  |   5 +-
 .../user/project/ActivateProjectCmd.java        |   5 +-
 .../command/user/project/CreateProjectCmd.java  |  11 +-
 .../command/user/project/DeleteProjectCmd.java  |   5 +-
 .../project/DeleteProjectInvitationCmd.java     |   5 +-
 .../command/user/project/SuspendProjectCmd.java |   5 +-
 .../command/user/project/UpdateProjectCmd.java  |   5 +-
 .../project/UpdateProjectInvitationCmd.java     |   5 +-
 .../gslb/AssignToGlobalLoadBalancerRuleCmd.java |   7 +-
 .../gslb/CreateGlobalLoadBalancerRuleCmd.java   |  10 +-
 .../gslb/DeleteGlobalLoadBalancerRuleCmd.java   |   6 +-
 .../RemoveFromGlobalLoadBalancerRuleCmd.java    |   7 +-
 .../gslb/UpdateGlobalLoadBalancerRuleCmd.java   |   2 +-
 .../user/resource/UpdateResourceCountCmd.java   |   5 +-
 .../user/resource/UpdateResourceLimitCmd.java   |   5 +-
 .../AuthorizeSecurityGroupEgressCmd.java        |   5 +-
 .../AuthorizeSecurityGroupIngressCmd.java       |   5 +-
 .../securitygroup/CreateSecurityGroupCmd.java   |   5 +-
 .../securitygroup/DeleteSecurityGroupCmd.java   |   5 +-
 .../user/snapshot/CreateSnapshotCmd.java        |   5 +-
 .../user/snapshot/DeleteSnapshotCmd.java        |   5 +-
 .../command/user/ssh/CreateSSHKeyPairCmd.java   |   5 +-
 .../command/user/ssh/DeleteSSHKeyPairCmd.java   |   5 +-
 .../command/user/ssh/RegisterSSHKeyPairCmd.java |   5 +-
 .../command/user/template/CopyTemplateCmd.java  |   5 +-
 .../user/template/CreateTemplateCmd.java        |   6 +-
 .../user/template/DeleteTemplateCmd.java        |   4 +-
 .../user/template/ExtractTemplateCmd.java       |   4 +-
 .../command/user/template/ListTemplatesCmd.java |   5 +-
 .../user/template/RegisterTemplateCmd.java      |   5 +-
 .../api/command/user/vm/AddIpToVmNicCmd.java    |  11 +-
 .../api/command/user/vm/AddNicToVMCmd.java      |   5 +-
 .../api/command/user/vm/DeployVMCmd.java        |  11 +-
 .../api/command/user/vm/DestroyVMCmd.java       |   5 +-
 .../api/command/user/vm/ListNicsCmd.java        |   8 +-
 .../api/command/user/vm/RebootVMCmd.java        |   5 +-
 .../command/user/vm/RemoveIpFromVmNicCmd.java   |  10 +-
 .../api/command/user/vm/RemoveNicFromVMCmd.java |   5 +-
 .../api/command/user/vm/ResetVMPasswordCmd.java |   5 +-
 .../api/command/user/vm/ResetVMSSHKeyCmd.java   |   4 +-
 .../api/command/user/vm/RestoreVMCmd.java       |   5 +-
 .../api/command/user/vm/ScaleVMCmd.java         |   4 +-
 .../api/command/user/vm/StartVMCmd.java         |   5 +-
 .../api/command/user/vm/StopVMCmd.java          |   5 +-
 .../user/vm/UpdateDefaultNicForVMCmd.java       |   5 +-
 .../api/command/user/vm/UpdateVMCmd.java        |   5 +-
 .../api/command/user/vm/UpgradeVMCmd.java       |   5 +-
 .../command/user/vmgroup/CreateVMGroupCmd.java  |   5 +-
 .../user/vmsnapshot/CreateVMSnapshotCmd.java    |   4 +-
 .../user/vmsnapshot/DeleteVMSnapshotCmd.java    |   5 +-
 .../user/vmsnapshot/RevertToVMSnapshotCmd.java  |   4 +-
 .../user/volume/AddResourceDetailCmd.java       |   4 +-
 .../command/user/volume/AttachVolumeCmd.java    |   5 +-
 .../command/user/volume/CreateVolumeCmd.java    |   7 +-
 .../command/user/volume/DeleteVolumeCmd.java    |   7 +-
 .../command/user/volume/DetachVolumeCmd.java    |   5 +-
 .../command/user/volume/ExtractVolumeCmd.java   |   5 +-
 .../user/volume/RemoveResourceDetailCmd.java    |   4 +-
 .../command/user/volume/ResizeVolumeCmd.java    |   5 +-
 .../command/user/volume/UpdateVolumeCmd.java    |   5 +-
 .../command/user/volume/UploadVolumeCmd.java    |   5 +-
 .../command/user/vpc/CreateStaticRouteCmd.java  |   5 +-
 .../api/command/user/vpc/CreateVPCCmd.java      |   5 +-
 .../command/user/vpc/DeleteStaticRouteCmd.java  |   5 +-
 .../api/command/user/vpn/AddVpnUserCmd.java     |   5 +-
 .../user/vpn/CreateVpnCustomerGatewayCmd.java   |   5 +-
 .../user/vpn/DeleteRemoteAccessVpnCmd.java      |   5 +-
 .../api/command/user/vpn/RemoveVpnUserCmd.java  |   7 +-
 .../command/user/vpn/ResetVpnConnectionCmd.java |   5 +-
 .../user/vpn/UpdateVpnCustomerGatewayCmd.java   |   5 +-
 .../apache/cloudstack/context/CallContext.java  | 218 +++++++++++++++++
 client/tomcatconf/applicationContext.xml.in     |   1 -
 .../api/command/user/discovery/ListApisCmd.java |   5 +-
 .../admin/ratelimit/ResetApiLimitCmd.java       |   5 +-
 .../command/user/ratelimit/GetApiLimitCmd.java  |   7 +-
 .../dedicated/DedicatedResourceManagerImpl.java |  12 +-
 .../dedicated/manager/DedicatedApiUnitTest.java |  28 ++-
 .../implicitplanner/ImplicitPlannerTest.java    |  31 ++-
 .../cloudstack/api/AddBaremetalDhcpCmd.java     |   5 +-
 .../cloudstack/api/AddBaremetalPxeCmd.java      |   5 +-
 .../vmware/VmwareDatacenterApiUnitTest.java     |  30 ++-
 .../api/commands/AddBigSwitchVnsDeviceCmd.java  |   4 +-
 .../commands/DeleteBigSwitchVnsDeviceCmd.java   |   4 +-
 .../commands/AddCiscoAsa1000vResourceCmd.java   |   5 +-
 .../api/commands/AddCiscoVnmcResourceCmd.java   |   5 +-
 .../DeleteCiscoAsa1000vResourceCmd.java         |   5 +-
 .../commands/DeleteCiscoVnmcResourceCmd.java    |   5 +-
 .../cloud/network/element/CiscoVnmcElement.java |   7 +-
 .../lb/ElasticLoadBalancerManagerImpl.java      |   8 +-
 .../api/commands/AddF5LoadBalancerCmd.java      |   6 +-
 .../commands/ConfigureF5LoadBalancerCmd.java    |   6 +-
 .../api/commands/DeleteF5LoadBalancerCmd.java   |   6 +-
 .../InternalLBVMServiceTest.java                |  19 +-
 .../cloud/api/commands/AddSrxFirewallCmd.java   |   6 +-
 .../api/commands/ConfigureSrxFirewallCmd.java   |   5 +-
 .../api/commands/DeleteSrxFirewallCmd.java      |   5 +-
 .../commands/AddNetscalerLoadBalancerCmd.java   |   6 +-
 .../ConfigureNetscalerLoadBalancerCmd.java      |   6 +-
 .../DeleteNetscalerLoadBalancerCmd.java         |   5 +-
 .../api/commands/AddNiciraNvpDeviceCmd.java     |   6 +-
 .../api/commands/DeleteNiciraNvpDeviceCmd.java  |   6 +-
 .../cloud/network/guru/OvsGuestNetworkGuru.java |   6 +-
 .../cloudstack/api/commands/AddSspCmd.java      |   5 +-
 .../cloudstack/api/commands/DeleteSspCmd.java   |   5 +-
 .../cloud/agent/manager/AgentManagerImpl.java   |  38 +--
 server/src/com/cloud/api/ApiDispatcher.java     | 136 ++++++-----
 server/src/com/cloud/api/ApiResponseHelper.java |   7 +-
 server/src/com/cloud/api/ApiServer.java         |  85 +++----
 server/src/com/cloud/api/ApiServlet.java        |  27 ++-
 .../com/cloud/api/query/QueryManagerImpl.java   |  49 ++--
 .../com/cloud/api/query/ViewResponseHelper.java |  12 +-
 .../api/query/dao/DataCenterJoinDaoImpl.java    |   7 +-
 .../api/query/dao/TemplateJoinDaoImpl.java      |   7 +-
 .../cloud/api/query/dao/VolumeJoinDaoImpl.java  |   5 +-
 .../com/cloud/async/AsyncJobManagerImpl.java    |  42 ++--
 .../configuration/ConfigurationManagerImpl.java |  70 +++---
 .../consoleproxy/ConsoleProxyManagerImpl.java   |   6 +-
 .../com/cloud/event/ActionEventInterceptor.java |  21 +-
 .../src/com/cloud/event/ActionEventUtils.java   |  37 +--
 .../metadata/ResourceMetaDataManagerImpl.java   |   5 +-
 .../com/cloud/network/NetworkManagerImpl.java   |  31 +--
 .../com/cloud/network/NetworkServiceImpl.java   |  61 ++---
 .../cloud/network/NetworkUsageManagerImpl.java  |   3 +-
 .../cloud/network/as/AutoScaleManagerImpl.java  |  44 ++--
 .../network/firewall/FirewallManagerImpl.java   |  17 +-
 .../network/guru/ExternalGuestNetworkGuru.java  |   6 +-
 .../cloud/network/guru/GuestNetworkGuru.java    |   8 +-
 .../network/lb/LoadBalancingRulesManager.java   |   5 +-
 .../lb/LoadBalancingRulesManagerImpl.java       |  61 ++---
 .../VirtualNetworkApplianceManagerImpl.java     | 238 ++++++++++---------
 .../cloud/network/rules/RulesManagerImpl.java   |  43 ++--
 .../security/SecurityGroupManagerImpl.java      |  17 +-
 .../network/vpc/NetworkACLManagerImpl.java      |   7 +-
 .../network/vpc/NetworkACLServiceImpl.java      |  19 +-
 .../com/cloud/network/vpc/VpcManagerImpl.java   |  57 ++---
 .../network/vpn/RemoteAccessVpnManagerImpl.java |  28 +--
 .../network/vpn/Site2SiteVpnManagerImpl.java    |  35 +--
 .../com/cloud/projects/ProjectManagerImpl.java  |  30 +--
 .../com/cloud/resource/ResourceManagerImpl.java |  14 +-
 .../resourcelimit/ResourceLimitManagerImpl.java |   9 +-
 .../com/cloud/server/ManagementServerImpl.java  |  70 +++---
 .../com/cloud/storage/StorageManagerImpl.java   |  20 +-
 .../storage/StoragePoolAutomationImpl.java      |  11 +-
 .../com/cloud/storage/VolumeManagerImpl.java    |  24 +-
 .../secondary/SecondaryStorageManagerImpl.java  |   6 +-
 .../storage/snapshot/SnapshotManagerImpl.java   |  23 +-
 .../cloud/tags/TaggedResourceManagerImpl.java   |   8 +-
 .../com/cloud/template/TemplateAdapterBase.java |  25 +-
 .../com/cloud/template/TemplateManagerImpl.java |  47 ++--
 .../src/com/cloud/usage/UsageServiceImpl.java   |   5 +-
 .../src/com/cloud/user/AccountManagerImpl.java  |  75 +++---
 .../src/com/cloud/user/DomainManagerImpl.java   |  32 +--
 server/src/com/cloud/vm/UserVmManagerImpl.java  |  85 ++++---
 .../vm/snapshot/VMSnapshotManagerImpl.java      |   7 +-
 .../affinity/AffinityGroupServiceImpl.java      |  12 +-
 .../lb/ApplicationLoadBalancerManagerImpl.java  |   9 +-
 .../GlobalLoadBalancingRulesServiceImpl.java    |  25 +-
 .../configuration/ConfigurationManagerTest.java |  43 ++--
 .../network/DedicateGuestVlanRangesTest.java    |  43 ++--
 server/test/com/cloud/vm/UserVmManagerTest.java | 156 +++++++++---
 .../com/cloud/vpc/NetworkACLManagerTest.java    |  65 +++--
 .../com/cloud/vpc/NetworkACLServiceTest.java    |  61 +++--
 server/test/com/cloud/vpc/VpcTest.java          |  71 +++---
 .../affinity/AffinityApiUnitTest.java           |  34 ++-
 .../lb/ApplicationLoadBalancerTest.java         |  39 +--
 .../networkoffering/ChildTestConfiguration.java |  26 +-
 .../CreateNetworkOfferingTest.java              |  42 ++--
 .../cloudstack/region/RegionManagerTest.java    |   3 +-
 ...GlobalLoadBalancingRulesServiceImplTest.java | 114 +++++----
 .../utils/exception/CloudRuntimeException.java  |  21 +-
 270 files changed, 2352 insertions(+), 1804 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/com/cloud/user/UserContext.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/user/UserContext.java b/api/src/com/cloud/user/UserContext.java
deleted file mode 100644
index fdd19d4..0000000
--- a/api/src/com/cloud/user/UserContext.java
+++ /dev/null
@@ -1,163 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.user;
-
-import com.cloud.utils.component.ComponentContext;
-import javax.inject.Inject;
-
-public class UserContext {
-    private static ThreadLocal<UserContext> s_currentContext = new ThreadLocal<UserContext>();
-
-    private long userId;
-    private String sessionId;
-    private Account account;
-    private long startEventId = 0;
-    private long accountId;
-    private String eventDetails;
-    private boolean apiServer;
-    private Class entityType;
-    private String entityUUID;
-
-    @Inject private AccountService _accountMgr = null;
-
-    public UserContext() {
-    }
-
-    public UserContext(long userId, Account accountObject, String sessionId, boolean apiServer) {
-        this.userId = userId;
-        this.account = accountObject;
-        this.sessionId = sessionId;
-        this.apiServer = apiServer;
-    }
-
-    public long getCallerUserId() {
-        return userId;
-    }
-
-    public User getCallerUser() {
-        if (_accountMgr == null) {
-            _accountMgr = ComponentContext.getComponent(AccountService.class);
-        }
-        return _accountMgr.getActiveUser(userId);
-    }
-
-    public void setCallerUserId(long userId) {
-        this.userId = userId;
-    }
-
-    public String getSessionId() {
-        return sessionId;
-    }
-
-    public Account getCaller() {
-        return account;
-    }
-
-    public void setCaller(Account accountObject) {
-        this.account = accountObject;
-    }
-
-    public void setSessionKey(String sessionId) {
-        this.sessionId = sessionId;
-    }
-
-    public boolean isApiServer() {
-        return apiServer;
-    }
-
-    public void setApiServer(boolean apiServer) {
-        this.apiServer = apiServer;
-    }
-
-    public static UserContext current() {
-        UserContext context = s_currentContext.get();
-        if (context == null) {
-            //
-            // TODO: we should enforce explicit UserContext setup at major entry-points for security concerns,
-            // however, there are many places that run background jobs assume the system context.
-            //
-            // If there is a security concern, all entry points from user (including the front end that takes HTTP
-            // request in and
-            // the core async-job manager that runs commands from user) have explicitly setup the UserContext.
-            //
-            return UserContextInitializer.getInstance().getAdminContext();
-        }
-        return context;
-    }
-
-    public static void updateContext(long userId, Account accountObject, String sessionId) {
-        UserContext context = current();
-        assert (context != null) : "Context should be already setup before you can call this one";
-
-        context.setCallerUserId(userId);
-        context.setCaller(accountObject);
-        context.setSessionKey(sessionId);
-    }
-
-    public static void registerContext(long userId, Account accountObject, String sessionId, boolean apiServer) {
-        s_currentContext.set(new UserContext(userId, accountObject, sessionId, apiServer));
-    }
-
-    public static void unregisterContext() {
-        s_currentContext.set(null);
-    }
-
-    public void setStartEventId(long startEventId) {
-        this.startEventId = startEventId;
-    }
-
-    public long getStartEventId() {
-        return startEventId;
-    }
-
-    public long getAccountId() {
-        return accountId;
-    }
-
-    public void setAccountId(long accountId) {
-        this.accountId = accountId;
-    }
-
-    public void setEventDetails(String eventDetails) {
-        this.eventDetails = eventDetails;
-    }
-
-    public String getEventDetails() {
-        return eventDetails;
-    }
-
-    public void setEntityDetails(Class entityType, String uuid) {
-        this.entityType = entityType;
-        this.entityUUID = uuid;
-    }
-
-    public String getEntityType() {
-        return (entityType != null) ? entityType.getName() : null;
-    }
-
-    public void setEntityType(Class entityType) {
-        this.entityType = entityType;
-    }
-
-    public String getEntityUUID() {
-        return entityUUID;
-    }
-
-    public void setEntityUUID(String entityUUID) {
-        this.entityUUID = entityUUID;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/com/cloud/user/UserContextInitializer.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/user/UserContextInitializer.java b/api/src/com/cloud/user/UserContextInitializer.java
deleted file mode 100644
index a545963..0000000
--- a/api/src/com/cloud/user/UserContextInitializer.java
+++ /dev/null
@@ -1,40 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.user;
-
-import javax.inject.Inject;
-
-import org.springframework.stereotype.Component;
-
-@Component
-public class UserContextInitializer {
-	@Inject private AccountService _accountMgr;
-
-    private static UserContextInitializer s_instance;
-    
-    public UserContextInitializer() {
-    	s_instance = this;
-    }
-    
-    public static UserContextInitializer getInstance() {
-    	return s_instance;
-    }
-    
-    public UserContext getAdminContext() {
-    	return new UserContext(_accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount(), null, false);
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/BaseAsyncCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/BaseAsyncCmd.java b/api/src/org/apache/cloudstack/api/BaseAsyncCmd.java
index 022157a..0e6f95d 100644
--- a/api/src/org/apache/cloudstack/api/BaseAsyncCmd.java
+++ b/api/src/org/apache/cloudstack/api/BaseAsyncCmd.java
@@ -17,10 +17,10 @@
 package org.apache.cloudstack.api;
 
 import org.apache.cloudstack.api.response.AsyncJobResponse;
+import org.apache.cloudstack.context.CallContext;
 
 import com.cloud.async.AsyncJob;
 import com.cloud.user.User;
-import com.cloud.user.UserContext;
 
 /**
  * queryAsyncJobResult API command.
@@ -109,8 +109,8 @@ public abstract class BaseAsyncCmd extends BaseCmd {
     }
 
     protected long saveStartedEvent(String eventType, String description, Long startEventId) {
-        UserContext ctx = UserContext.current();
-        Long userId = ctx.getCallerUserId();
+        CallContext ctx = CallContext.current();
+        Long userId = ctx.getCallingUserId();
         userId = (userId == null) ? User.UID_SYSTEM : userId;
         Long startEvent = startEventId;
         if (startEvent == null) {
@@ -124,8 +124,8 @@ public abstract class BaseAsyncCmd extends BaseCmd {
     }
 
     protected long saveCompletedEvent(String level, String eventType, String description, Long startEventId) {
-        UserContext ctx = UserContext.current();
-        Long userId = ctx.getCallerUserId();
+        CallContext ctx = CallContext.current();
+        Long userId = ctx.getCallingUserId();
         userId = (userId == null) ? User.UID_SYSTEM : userId;
         Long startEvent = startEventId;
         if (startEvent == null) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java b/api/src/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java
index 47aa679..88732ae 100644
--- a/api/src/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java
+++ b/api/src/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java
@@ -19,11 +19,12 @@ package org.apache.cloudstack.api;
 import java.util.List;
 
 import org.apache.cloudstack.api.response.TemplatePermissionsResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.template.VirtualMachineTemplate;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 public class BaseListTemplateOrIsoPermissionsCmd extends BaseCmd {
     public Logger s_logger = getLogger();
@@ -79,7 +80,7 @@ public class BaseListTemplateOrIsoPermissionsCmd extends BaseCmd {
     public void execute(){
         List<String> accountNames = _templateService.listTemplatePermissions(this);
 
-        Account account = UserContext.current().getCaller();
+        Account account = CallContext.current().getCallingAccount();
         boolean isAdmin = (isAdmin(account.getType()));
 
         TemplatePermissionsResponse response = _responseGenerator.createTemplatePermissionsResponse(accountNames, id, isAdmin);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java
index cc74eb2..94325f6 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java
@@ -18,7 +18,7 @@ package org.apache.cloudstack.api.command.admin.account;
 
 import com.cloud.user.Account;
 import com.cloud.user.UserAccount;
-import com.cloud.user.UserContext;
+
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.ApiErrorCode;
@@ -27,6 +27,8 @@ import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.AccountResponse;
 import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import java.util.Collection;
@@ -160,7 +162,7 @@ public class CreateAccountCmd extends BaseCmd {
 
     @Override
     public void execute(){
-        UserContext.current().setEventDetails("Account Name: "+getAccountName()+", Domain Id:"+getDomainId());
+        CallContext.current().setEventDetails("Account Name: "+getAccountName()+", Domain Id:"+getDomainId());
         UserAccount userAccount = _accountService.createUserAccount(getUsername(), getPassword(), getFirstName(), getLastName(), getEmail(), getTimeZone(), getAccountName(), getAccountType(),
                 getDomainId(), getNetworkDomain(), getDetails(), getAccountUUID(), getUserUUID());
         if (userAccount != null) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java
index 4a42fde..b46036b 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java
@@ -27,13 +27,14 @@ import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.AccountResponse;
 import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.region.RegionService;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.user.Account;
 import com.cloud.user.User;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "deleteAccount", description="Deletes a account, and all users associated with this account", responseObject=SuccessResponse.class)
 public class DeleteAccountCmd extends BaseAsyncCmd {
@@ -74,7 +75,7 @@ public class DeleteAccountCmd extends BaseAsyncCmd {
 
     @Override
     public long getEntityOwnerId() {
-        Account account = UserContext.current().getCaller();// Let's give the caller here for event logging.
+        Account account = CallContext.current().getCallingAccount();// Let's give the caller here for event logging.
         if (account != null) {
             return account.getAccountId();
         }
@@ -95,7 +96,7 @@ public class DeleteAccountCmd extends BaseAsyncCmd {
 
     @Override
     public void execute(){
-        UserContext.current().setEventDetails("Account Id: "+getId());
+        CallContext.current().setEventDetails("Account Id: "+getId());
 
         boolean	result = _regionService.deleteUserAccount(this);
         if (result) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java
index 6d25fde..806a8a5 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java
@@ -27,14 +27,15 @@ import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.AccountResponse;
 import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.region.RegionService;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "disableAccount", description="Disables an account", responseObject=AccountResponse.class)
 public class DisableAccountCmd extends BaseAsyncCmd {
@@ -116,7 +117,7 @@ public class DisableAccountCmd extends BaseAsyncCmd {
 
     @Override
     public void execute() throws ConcurrentOperationException, ResourceUnavailableException{
-        UserContext.current().setEventDetails("Account Name: "+getAccountName()+", Domain Id:"+getDomainId());
+        CallContext.current().setEventDetails("Account Name: "+getAccountName()+", Domain Id:"+getDomainId());
         Account result = _regionService.disableAccount(this);
         if (result != null){
             AccountResponse response = _responseGenerator.createAccountResponse(result);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/domain/CreateDomainCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/domain/CreateDomainCmd.java b/api/src/org/apache/cloudstack/api/command/admin/domain/CreateDomainCmd.java
index 91d61cc..c46318e 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/domain/CreateDomainCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/domain/CreateDomainCmd.java
@@ -23,11 +23,12 @@ import org.apache.cloudstack.api.BaseCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.domain.Domain;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "createDomain", description="Creates a domain", responseObject=DomainResponse.class)
 public class CreateDomainCmd extends BaseCmd {
@@ -88,7 +89,7 @@ public class CreateDomainCmd extends BaseCmd {
 
     @Override
     public void execute(){
-        UserContext.current().setEventDetails("Domain Name: "+getDomainName()+((getParentDomainId()!=null)?", Parent DomainId :"+getParentDomainId():""));
+        CallContext.current().setEventDetails("Domain Name: "+getDomainName()+((getParentDomainId()!=null)?", Parent DomainId :"+getParentDomainId():""));
         Domain domain = _domainService.createDomain(getDomainName(), getParentDomainId(), getNetworkDomain(), getDomainUUID());
         if (domain != null) {
             DomainResponse response = _responseGenerator.createDomainResponse(domain);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java b/api/src/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java
index 488a758..6302c2e 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java
@@ -26,13 +26,14 @@ import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.DomainResponse;
 import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.region.RegionService;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.domain.Domain;
 import com.cloud.event.EventTypes;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "deleteDomain", description="Deletes a specified domain", responseObject=SuccessResponse.class)
 public class DeleteDomainCmd extends BaseAsyncCmd {
@@ -95,7 +96,7 @@ public class DeleteDomainCmd extends BaseAsyncCmd {
 
     @Override
     public void execute(){
-        UserContext.current().setEventDetails("Domain Id: "+getId());
+        CallContext.current().setEventDetails("Domain Id: "+getId());
         boolean result = _regionService.deleteDomain(this);
         if (result) {
             SuccessResponse response = new SuccessResponse(getCommandName());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java b/api/src/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java
index e658f49..e4962d6 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java
@@ -25,13 +25,14 @@ import org.apache.cloudstack.api.BaseCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.region.RegionService;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.domain.Domain;
 import com.cloud.user.Account;
 import com.cloud.user.UserAccount;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "updateDomain", description="Updates a domain with a new name", responseObject=DomainResponse.class)
 public class UpdateDomainCmd extends BaseCmd {
@@ -86,7 +87,7 @@ public class UpdateDomainCmd extends BaseCmd {
 
     @Override
     public void execute(){
-        UserContext.current().setEventDetails("Domain Id: "+getId());
+        CallContext.current().setEventDetails("Domain Id: "+getId());
         Domain domain =  _regionService.updateDomain(this);
 
         if (domain != null) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/host/CancelMaintenanceCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/host/CancelMaintenanceCmd.java b/api/src/org/apache/cloudstack/api/command/admin/host/CancelMaintenanceCmd.java
index ea85d12..3179e50 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/host/CancelMaintenanceCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/host/CancelMaintenanceCmd.java
@@ -24,12 +24,13 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.HostResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.host.Host;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "cancelHostMaintenance", description="Cancels host maintenance.", responseObject=HostResponse.class)
 public class CancelMaintenanceCmd extends BaseAsyncCmd  {
@@ -68,7 +69,7 @@ public class CancelMaintenanceCmd extends BaseAsyncCmd  {
 
     @Override
     public long getEntityOwnerId() {
-        Account account = UserContext.current().getCaller();
+        Account account = CallContext.current().getCallingAccount();
         if (account != null) {
             return account.getId();
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/host/PrepareForMaintenanceCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/host/PrepareForMaintenanceCmd.java b/api/src/org/apache/cloudstack/api/command/admin/host/PrepareForMaintenanceCmd.java
index fd3685a..02d29b3 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/host/PrepareForMaintenanceCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/host/PrepareForMaintenanceCmd.java
@@ -24,12 +24,13 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.HostResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.host.Host;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "prepareHostForMaintenance", description="Prepares a host for maintenance.", responseObject=HostResponse.class)
 public class PrepareForMaintenanceCmd extends BaseAsyncCmd {
@@ -68,7 +69,7 @@ public class PrepareForMaintenanceCmd extends BaseAsyncCmd {
 
     @Override
     public long getEntityOwnerId() {
-        Account account = UserContext.current().getCaller();
+        Account account = CallContext.current().getCallingAccount();
         if (account != null) {
             return account.getId();
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java b/api/src/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java
index 8a1ef79..ec5f65e 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java
@@ -24,12 +24,13 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.HostResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.host.Host;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "reconnectHost", description="Reconnects a host.", responseObject=HostResponse.class)
 public class ReconnectHostCmd extends BaseAsyncCmd {
@@ -68,7 +69,7 @@ public class ReconnectHostCmd extends BaseAsyncCmd {
 
     @Override
     public long getEntityOwnerId() {
-        Account account = UserContext.current().getCaller();
+        Account account = CallContext.current().getCallingAccount();
         if (account != null) {
             return account.getId();
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/host/ReleaseHostReservationCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/host/ReleaseHostReservationCmd.java b/api/src/org/apache/cloudstack/api/command/admin/host/ReleaseHostReservationCmd.java
index b11bcd2..2de452e 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/host/ReleaseHostReservationCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/host/ReleaseHostReservationCmd.java
@@ -25,11 +25,12 @@ import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.HostResponse;
 import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "releaseHostReservation", description = "Releases host reservation.", responseObject = SuccessResponse.class)
 public class ReleaseHostReservationCmd extends BaseAsyncCmd {
@@ -64,7 +65,7 @@ public class ReleaseHostReservationCmd extends BaseAsyncCmd {
 
     @Override
     public long getEntityOwnerId() {
-        Account account = UserContext.current().getCaller();
+        Account account = CallContext.current().getCallingAccount();
         if (account != null) {
             return account.getId();
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/internallb/ConfigureInternalLoadBalancerElementCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/internallb/ConfigureInternalLoadBalancerElementCmd.java b/api/src/org/apache/cloudstack/api/command/admin/internallb/ConfigureInternalLoadBalancerElementCmd.java
index 86f3006..bfbe85e 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/internallb/ConfigureInternalLoadBalancerElementCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/internallb/ConfigureInternalLoadBalancerElementCmd.java
@@ -23,7 +23,7 @@ import com.cloud.exception.InsufficientCapacityException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.VirtualRouterProvider;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
+
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.ApiErrorCode;
@@ -31,10 +31,13 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.InternalLoadBalancerElementResponse;
+import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.network.element.InternalLoadBalancerElementService;
+
 import org.apache.log4j.Logger;
 
 import javax.inject.Inject;
+
 import java.util.List;
 
 @APICommand(name = "configureInternalLoadBalancerElement", responseObject=InternalLoadBalancerElementResponse.class,
@@ -96,7 +99,7 @@ public class ConfigureInternalLoadBalancerElementCmd extends BaseAsyncCmd {
 
     @Override
     public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
-        UserContext.current().setEventDetails("Internal load balancer element: " + id);
+        CallContext.current().setEventDetails("Internal load balancer element: " + id);
         VirtualRouterProvider result = _service.get(0).configureInternalLoadBalancerElement(getId(), getEnabled());
         if (result != null){
             InternalLoadBalancerElementResponse routerResponse = _responseGenerator.createInternalLbElementResponse(result);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/internallb/CreateInternalLoadBalancerElementCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/internallb/CreateInternalLoadBalancerElementCmd.java b/api/src/org/apache/cloudstack/api/command/admin/internallb/CreateInternalLoadBalancerElementCmd.java
index 2902f7a..0079949 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/internallb/CreateInternalLoadBalancerElementCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/internallb/CreateInternalLoadBalancerElementCmd.java
@@ -28,14 +28,15 @@ import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.InternalLoadBalancerElementResponse;
 import org.apache.cloudstack.api.response.ProviderResponse;
+import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.network.element.InternalLoadBalancerElementService;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.exception.ResourceAllocationException;
 import com.cloud.network.VirtualRouterProvider;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "createInternalLoadBalancerElement", responseObject=InternalLoadBalancerElementResponse.class, description="Create an Internal Load Balancer element.",since="4.2.0")
 public class CreateInternalLoadBalancerElementCmd extends BaseAsyncCreateCmd {
@@ -82,7 +83,7 @@ public class CreateInternalLoadBalancerElementCmd extends BaseAsyncCreateCmd {
 
     @Override
     public void execute(){
-        UserContext.current().setEventDetails("Virtual router element Id: "+getEntityId());
+        CallContext.current().setEventDetails("Virtual router element Id: "+getEntityId());
         VirtualRouterProvider result = _service.get(0).getInternalLoadBalancerElement(getEntityId());
         if (result != null) {
             InternalLoadBalancerElementResponse response = _responseGenerator.createInternalLbElementResponse(result);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/internallb/StartInternalLBVMCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/internallb/StartInternalLBVMCmd.java b/api/src/org/apache/cloudstack/api/command/admin/internallb/StartInternalLBVMCmd.java
index 256804f..f70e04c 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/internallb/StartInternalLBVMCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/internallb/StartInternalLBVMCmd.java
@@ -24,6 +24,8 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.DomainRouterResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
@@ -33,7 +35,6 @@ import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.router.VirtualRouter;
 import com.cloud.network.router.VirtualRouter.Role;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "startInternalLoadBalancerVM", responseObject=DomainRouterResponse.class, description="Starts an existing internal lb vm.")
 public class StartInternalLBVMCmd extends BaseAsyncCmd {
@@ -100,13 +101,13 @@ public class StartInternalLBVMCmd extends BaseAsyncCmd {
 
     @Override
     public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
-        UserContext.current().setEventDetails("Internal Lb Vm Id: "+getId());
+        CallContext.current().setEventDetails("Internal Lb Vm Id: "+getId());
         VirtualRouter result = null;
         VirtualRouter router = _routerService.findRouter(getId());
         if (router == null || router.getRole() != Role.INTERNAL_LB_VM) {
             throw new InvalidParameterValueException("Can't find internal lb vm by id");
         } else {
-            result = _internalLbSvc.startInternalLbVm(getId(), UserContext.current().getCaller(), UserContext.current().getCallerUserId());
+            result = _internalLbSvc.startInternalLbVm(getId(), CallContext.current().getCallingAccount(), CallContext.current().getCallingUserId());
         }
         
         if (result != null){

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/internallb/StopInternalLBVMCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/internallb/StopInternalLBVMCmd.java b/api/src/org/apache/cloudstack/api/command/admin/internallb/StopInternalLBVMCmd.java
index fd6a7dd..d84f3ab 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/internallb/StopInternalLBVMCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/internallb/StopInternalLBVMCmd.java
@@ -24,6 +24,8 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.DomainRouterResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
@@ -32,7 +34,6 @@ import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.router.VirtualRouter;
 import com.cloud.network.router.VirtualRouter.Role;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "stopInternalLoadBalancerVM", description = "Stops an Internal LB vm.", responseObject = DomainRouterResponse.class)
 public class StopInternalLBVMCmd extends BaseAsyncCmd {
@@ -103,13 +104,13 @@ public class StopInternalLBVMCmd extends BaseAsyncCmd {
 
     @Override
     public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
-        UserContext.current().setEventDetails("Internal lb vm Id: "+getId());
+        CallContext.current().setEventDetails("Internal lb vm Id: "+getId());
         VirtualRouter result = null;
         VirtualRouter vm = _routerService.findRouter(getId());
         if (vm == null || vm.getRole() != Role.INTERNAL_LB_VM) {
             throw new InvalidParameterValueException("Can't find internal lb vm by id");
         } else {
-            result = _internalLbSvc.stopInternalLbVm(getId(), isForced(), UserContext.current().getCaller(), UserContext.current().getCallerUserId());
+            result = _internalLbSvc.stopInternalLbVm(getId(), isForced(), CallContext.current().getCallingAccount(), CallContext.current().getCallingUserId());
         } 
         
         if (result != null) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/network/AddNetworkServiceProviderCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/AddNetworkServiceProviderCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/AddNetworkServiceProviderCmd.java
index 280369a..d56deb8 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/network/AddNetworkServiceProviderCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/network/AddNetworkServiceProviderCmd.java
@@ -27,13 +27,14 @@ import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
 import org.apache.cloudstack.api.response.ProviderResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.exception.ResourceAllocationException;
 import com.cloud.network.PhysicalNetworkServiceProvider;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "addNetworkServiceProvider", description="Adds a network serviceProvider to a physical network", responseObject=ProviderResponse.class, since="3.0.0")
 public class AddNetworkServiceProviderCmd extends BaseAsyncCreateCmd {
@@ -96,7 +97,7 @@ public class AddNetworkServiceProviderCmd extends BaseAsyncCreateCmd {
 
     @Override
     public void execute(){
-        UserContext.current().setEventDetails("Network ServiceProvider Id: "+getEntityId());
+        CallContext.current().setEventDetails("Network ServiceProvider Id: "+getEntityId());
         PhysicalNetworkServiceProvider result = _networkService.getCreatedPhysicalNetworkServiceProvider(getEntityId());
         if (result != null) {
             ProviderResponse response = _responseGenerator.createNetworkServiceProviderResponse(result);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/network/CreatePhysicalNetworkCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/CreatePhysicalNetworkCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/CreatePhysicalNetworkCmd.java
index 6c1100a..3627e55 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/network/CreatePhysicalNetworkCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/network/CreatePhysicalNetworkCmd.java
@@ -28,13 +28,14 @@ import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.DomainResponse;
 import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
 import org.apache.cloudstack.api.response.ZoneResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.exception.ResourceAllocationException;
 import com.cloud.network.PhysicalNetwork;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "createPhysicalNetwork", description="Creates a physical network", responseObject=PhysicalNetworkResponse.class, since="3.0.0")
 public class CreatePhysicalNetworkCmd extends BaseAsyncCreateCmd {
@@ -144,7 +145,7 @@ public class CreatePhysicalNetworkCmd extends BaseAsyncCreateCmd {
 
     @Override
     public void execute(){
-        UserContext.current().setEventDetails("Physical Network Id: "+getEntityId());
+        CallContext.current().setEventDetails("Physical Network Id: "+getEntityId());
         PhysicalNetwork result = _networkService.getCreatedPhysicalNetwork(getEntityId());
         if (result != null) {
             PhysicalNetworkResponse response = _responseGenerator.createPhysicalNetworkResponse(result);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/network/DeletePhysicalNetworkCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/DeletePhysicalNetworkCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/DeletePhysicalNetworkCmd.java
index b5c015a..1764127 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/network/DeletePhysicalNetworkCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/network/DeletePhysicalNetworkCmd.java
@@ -25,11 +25,12 @@ import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
 import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "deletePhysicalNetwork", description="Deletes a Physical Network.", responseObject=SuccessResponse.class, since="3.0.0")
 public class DeletePhysicalNetworkCmd extends BaseAsyncCmd {
@@ -68,7 +69,7 @@ public class DeletePhysicalNetworkCmd extends BaseAsyncCmd {
 
     @Override
     public void execute(){
-        UserContext.current().setEventDetails("Physical Network Id: " + id);
+        CallContext.current().setEventDetails("Physical Network Id: " + id);
         boolean result = _networkService.deletePhysicalNetwork(getId());
         if (result) {
             SuccessResponse response = new SuccessResponse(getCommandName());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/network/ReleaseDedicatedGuestVlanRangeCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/ReleaseDedicatedGuestVlanRangeCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/ReleaseDedicatedGuestVlanRangeCmd.java
index f9e96f6..49a3d36 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/network/ReleaseDedicatedGuestVlanRangeCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/network/ReleaseDedicatedGuestVlanRangeCmd.java
@@ -20,11 +20,13 @@ package org.apache.cloudstack.api.command.admin.network;
 import com.cloud.event.EventTypes;
 import com.cloud.exception.ResourceInUseException;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
+
 import org.apache.cloudstack.api.*;
 import org.apache.cloudstack.api.response.CounterResponse;
 import org.apache.cloudstack.api.response.GuestVlanRangeResponse;
 import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 @APICommand(name = "releaseDedicatedGuestVlanRange", description = "Releases a dedicated guest vlan range to the system", responseObject = SuccessResponse.class)
@@ -80,7 +82,7 @@ public class ReleaseDedicatedGuestVlanRangeCmd extends BaseAsyncCmd {
 
     @Override
     public void execute(){
-        UserContext.current().setEventDetails("Dedicated guest vlan range Id: " + id);
+        CallContext.current().setEventDetails("Dedicated guest vlan range Id: " + id);
         boolean result = _networkService.releaseDedicatedGuestVlanRange(getId());
         if (result) {
             SuccessResponse response = new SuccessResponse(getCommandName());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/router/ConfigureVirtualRouterElementCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/router/ConfigureVirtualRouterElementCmd.java b/api/src/org/apache/cloudstack/api/command/admin/router/ConfigureVirtualRouterElementCmd.java
index e28e916..625abf0 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/router/ConfigureVirtualRouterElementCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/router/ConfigureVirtualRouterElementCmd.java
@@ -28,6 +28,8 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.VirtualRouterProviderResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
@@ -37,7 +39,6 @@ import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.VirtualRouterProvider;
 import com.cloud.network.element.VirtualRouterElementService;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "configureVirtualRouterElement", responseObject=VirtualRouterProviderResponse.class, description="Configures a virtual router element.")
 public class ConfigureVirtualRouterElementCmd extends BaseAsyncCmd {
@@ -116,7 +117,7 @@ public class ConfigureVirtualRouterElementCmd extends BaseAsyncCmd {
 
     @Override
     public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
-        UserContext.current().setEventDetails("Virtual router element: " + id);
+        CallContext.current().setEventDetails("Virtual router element: " + id);
         VirtualRouterProvider result = _service.get(0).configure(this);
         if (result != null){
             VirtualRouterProviderResponse routerResponse = _responseGenerator.createVirtualRouterProviderResponse(result);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java b/api/src/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java
index b3fca5a..66c8ae5 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java
@@ -28,6 +28,8 @@ import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.ProviderResponse;
 import org.apache.cloudstack.api.response.VirtualRouterProviderResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
@@ -37,7 +39,6 @@ import com.cloud.network.VirtualRouterProvider;
 import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
 import com.cloud.network.element.VirtualRouterElementService;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "createVirtualRouterElement", responseObject=VirtualRouterProviderResponse.class, description="Create a virtual router element.")
 public class CreateVirtualRouterElementCmd extends BaseAsyncCreateCmd {
@@ -98,7 +99,7 @@ public class CreateVirtualRouterElementCmd extends BaseAsyncCreateCmd {
 
     @Override
     public void execute(){
-        UserContext.current().setEventDetails("Virtual router element Id: "+getEntityId());
+        CallContext.current().setEventDetails("Virtual router element Id: "+getEntityId());
         VirtualRouterProvider result = _service.get(0).getCreatedElement(getEntityId());
         if (result != null) {
             VirtualRouterProviderResponse response = _responseGenerator.createVirtualRouterProviderResponse(result);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/router/DestroyRouterCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/router/DestroyRouterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/router/DestroyRouterCmd.java
index d0dda29..44ca56b 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/router/DestroyRouterCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/router/DestroyRouterCmd.java
@@ -24,6 +24,8 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.DomainRouterResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
@@ -31,7 +33,6 @@ import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.router.VirtualRouter;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "destroyRouter", description = "Destroys a router.", responseObject = DomainRouterResponse.class)
 public class DestroyRouterCmd extends BaseAsyncCmd {
@@ -95,10 +96,10 @@ public class DestroyRouterCmd extends BaseAsyncCmd {
 
     @Override
     public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
-        UserContext ctx = UserContext.current();
+        CallContext ctx = CallContext.current();
         ctx.setEventDetails("Router Id: "+getId());
 
-        VirtualRouter result = _routerService.destroyRouter(getId(), ctx.getCaller(), ctx.getCallerUserId());
+        VirtualRouter result = _routerService.destroyRouter(getId(), ctx.getCallingAccount(), ctx.getCallingUserId());
         if (result != null) {
             DomainRouterResponse response = _responseGenerator.createDomainRouterResponse(result);
             response.setResponseName(getCommandName());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/router/RebootRouterCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/router/RebootRouterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/router/RebootRouterCmd.java
index 504b715..0c2cbc3 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/router/RebootRouterCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/router/RebootRouterCmd.java
@@ -24,6 +24,8 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.DomainRouterResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
@@ -32,7 +34,6 @@ import com.cloud.exception.InsufficientCapacityException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.router.VirtualRouter;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "rebootRouter", description="Starts a router.", responseObject=DomainRouterResponse.class)
 public class RebootRouterCmd extends BaseAsyncCmd {
@@ -95,7 +96,7 @@ public class RebootRouterCmd extends BaseAsyncCmd {
 
     @Override
     public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
-        UserContext.current().setEventDetails("Router Id: "+getId());
+        CallContext.current().setEventDetails("Router Id: "+getId());
         VirtualRouter result = _routerService.rebootRouter(this.getId(), true);
         if (result != null){
             DomainRouterResponse response = _responseGenerator.createDomainRouterResponse(result);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/router/StartRouterCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/router/StartRouterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/router/StartRouterCmd.java
index b575bf5..6981907 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/router/StartRouterCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/router/StartRouterCmd.java
@@ -24,6 +24,8 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.DomainRouterResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
@@ -34,7 +36,6 @@ import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.router.VirtualRouter;
 import com.cloud.network.router.VirtualRouter.Role;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "startRouter", responseObject=DomainRouterResponse.class, description="Starts a router.")
 public class StartRouterCmd extends BaseAsyncCmd {
@@ -101,7 +102,7 @@ public class StartRouterCmd extends BaseAsyncCmd {
 
     @Override
     public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
-        UserContext.current().setEventDetails("Router Id: "+getId());
+        CallContext.current().setEventDetails("Router Id: "+getId());
         VirtualRouter result = null;
         VirtualRouter router = _routerService.findRouter(getId());
         if (router == null || router.getRole() != Role.VIRTUAL_ROUTER) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/router/StopRouterCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/router/StopRouterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/router/StopRouterCmd.java
index 10aebc0..ab631e8 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/router/StopRouterCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/router/StopRouterCmd.java
@@ -24,6 +24,8 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.DomainRouterResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
@@ -33,7 +35,6 @@ import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.router.VirtualRouter;
 import com.cloud.network.router.VirtualRouter.Role;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "stopRouter", description = "Stops a router.", responseObject = DomainRouterResponse.class)
 public class StopRouterCmd extends BaseAsyncCmd {
@@ -104,7 +105,7 @@ public class StopRouterCmd extends BaseAsyncCmd {
 
     @Override
     public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
-        UserContext.current().setEventDetails("Router Id: "+getId());
+        CallContext.current().setEventDetails("Router Id: "+getId());
         VirtualRouter result = null;
         VirtualRouter router = _routerService.findRouter(getId());
         if (router == null || router.getRole() != Role.VIRTUAL_ROUTER) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/storage/CancelPrimaryStorageMaintenanceCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/storage/CancelPrimaryStorageMaintenanceCmd.java b/api/src/org/apache/cloudstack/api/command/admin/storage/CancelPrimaryStorageMaintenanceCmd.java
index 525e923..0a5efda 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/storage/CancelPrimaryStorageMaintenanceCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/storage/CancelPrimaryStorageMaintenanceCmd.java
@@ -24,13 +24,14 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.StoragePoolResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.storage.StoragePool;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "cancelStorageMaintenance", description="Cancels maintenance for primary storage", responseObject=StoragePoolResponse.class)
 public class CancelPrimaryStorageMaintenanceCmd extends BaseAsyncCmd {
@@ -81,7 +82,7 @@ public class CancelPrimaryStorageMaintenanceCmd extends BaseAsyncCmd {
 
     @Override
     public long getEntityOwnerId() {
-        Account account = UserContext.current().getCaller();
+        Account account = CallContext.current().getCallingAccount();
         if (account != null) {
             return account.getId();
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/storage/PreparePrimaryStorageForMaintenanceCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/storage/PreparePrimaryStorageForMaintenanceCmd.java b/api/src/org/apache/cloudstack/api/command/admin/storage/PreparePrimaryStorageForMaintenanceCmd.java
index 565ed07..9a784ee 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/storage/PreparePrimaryStorageForMaintenanceCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/storage/PreparePrimaryStorageForMaintenanceCmd.java
@@ -24,6 +24,8 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.StoragePoolResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
@@ -31,7 +33,6 @@ import com.cloud.exception.InsufficientCapacityException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.storage.StoragePool;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 
 @APICommand(name = "enableStorageMaintenance", description="Puts storage pool into maintenance state", responseObject=StoragePoolResponse.class)
 public class PreparePrimaryStorageForMaintenanceCmd extends BaseAsyncCmd {
@@ -79,7 +80,7 @@ public class PreparePrimaryStorageForMaintenanceCmd extends BaseAsyncCmd {
 
     @Override
     public long getEntityOwnerId() {
-        Account account = UserContext.current().getCaller();
+        Account account = CallContext.current().getCallingAccount();
         if (account != null) {
             return account.getId();
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/systemvm/DestroySystemVmCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/systemvm/DestroySystemVmCmd.java b/api/src/org/apache/cloudstack/api/command/admin/systemvm/DestroySystemVmCmd.java
index 87c6696..b539df1 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/systemvm/DestroySystemVmCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/systemvm/DestroySystemVmCmd.java
@@ -24,11 +24,12 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.SystemVmResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "destroySystemVm", responseObject=SystemVmResponse.class, description="Destroyes a system virtual machine.")
@@ -56,7 +57,7 @@ public class DestroySystemVmCmd extends BaseAsyncCmd {
 
     @Override
     public long getEntityOwnerId() {
-        Account account = UserContext.current().getCaller();
+        Account account = CallContext.current().getCallingAccount();
         if (account != null) {
             return account.getId();
         }
@@ -92,7 +93,7 @@ public class DestroySystemVmCmd extends BaseAsyncCmd {
 
     @Override
     public void execute(){
-        UserContext.current().setEventDetails("Vm Id: "+getId());
+        CallContext.current().setEventDetails("Vm Id: "+getId());
         VirtualMachine instance = _mgr.destroySystemVM(this);
         if (instance != null) {
             SystemVmResponse response = _responseGenerator.createSystemVmResponse(instance);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/systemvm/MigrateSystemVMCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/systemvm/MigrateSystemVMCmd.java b/api/src/org/apache/cloudstack/api/command/admin/systemvm/MigrateSystemVMCmd.java
index 31871b9..7b3436d 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/systemvm/MigrateSystemVMCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/systemvm/MigrateSystemVMCmd.java
@@ -25,6 +25,8 @@ import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.HostResponse;
 import org.apache.cloudstack.api.response.SystemVmInstanceResponse;
 import org.apache.cloudstack.api.response.SystemVmResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
@@ -35,7 +37,6 @@ import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.exception.VirtualMachineMigrationException;
 import com.cloud.host.Host;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "migrateSystemVm", description="Attempts Migration of a system virtual machine to the host specified.", responseObject=SystemVmInstanceResponse.class)
@@ -81,7 +82,7 @@ public class MigrateSystemVMCmd extends BaseAsyncCmd {
 
     @Override
     public long getEntityOwnerId() {
-        Account account = UserContext.current().getCaller();
+        Account account = CallContext.current().getCallingAccount();
         if (account != null) {
             return account.getId();
         }
@@ -107,7 +108,7 @@ public class MigrateSystemVMCmd extends BaseAsyncCmd {
             throw new InvalidParameterValueException("Unable to find the host to migrate the VM, host id=" + getHostId());
         }
         try{
-            UserContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to host Id: "+ getHostId());
+            CallContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to host Id: "+ getHostId());
             //FIXME : Should not be calling UserVmService to migrate all types of VMs - need a generic VM layer
             VirtualMachine migratedVm = _userVmService.migrateVirtualMachine(getVirtualMachineId(), destinationHost);
             if (migratedVm != null) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/systemvm/RebootSystemVmCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/systemvm/RebootSystemVmCmd.java b/api/src/org/apache/cloudstack/api/command/admin/systemvm/RebootSystemVmCmd.java
index 8cb0718..904faab 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/systemvm/RebootSystemVmCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/systemvm/RebootSystemVmCmd.java
@@ -24,11 +24,12 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.SystemVmResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "rebootSystemVm", description="Reboots a system VM.", responseObject=SystemVmResponse.class)
@@ -64,7 +65,7 @@ public class RebootSystemVmCmd extends BaseAsyncCmd {
 
     @Override
     public long getEntityOwnerId() {
-        Account account = UserContext.current().getCaller();
+        Account account = CallContext.current().getCallingAccount();
         if (account != null) {
             return account.getId();
         }
@@ -98,7 +99,7 @@ public class RebootSystemVmCmd extends BaseAsyncCmd {
 
     @Override
     public void execute(){
-        UserContext.current().setEventDetails("Vm Id: "+getId());
+        CallContext.current().setEventDetails("Vm Id: "+getId());
         VirtualMachine result = _mgr.rebootSystemVM(this);
         if (result != null) {
             SystemVmResponse response = _responseGenerator.createSystemVmResponse(result);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/systemvm/ScaleSystemVMCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/systemvm/ScaleSystemVMCmd.java b/api/src/org/apache/cloudstack/api/command/admin/systemvm/ScaleSystemVMCmd.java
index a077e24..61b457f 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/systemvm/ScaleSystemVMCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/systemvm/ScaleSystemVMCmd.java
@@ -18,15 +18,17 @@ package org.apache.cloudstack.api.command.admin.systemvm;
 
 import com.cloud.event.EventTypes;
 import com.cloud.exception.*;
+
 import org.apache.cloudstack.api.*;
 import org.apache.cloudstack.api.command.user.vm.UpgradeVMCmd;
 import org.apache.cloudstack.api.response.ServiceOfferingResponse;
 import org.apache.cloudstack.api.response.SystemVmResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.offering.ServiceOffering;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "scaleSystemVm", responseObject=SystemVmResponse.class, description="Scale the service offering for a system vm (console proxy or secondary storage). " +
@@ -71,7 +73,7 @@ public class ScaleSystemVMCmd extends BaseAsyncCmd {
 
     @Override
     public long getEntityOwnerId() {
-        Account account = UserContext.current().getCaller();
+        Account account = CallContext.current().getCallingAccount();
         if (account != null) {
             return account.getId();
         }
@@ -81,7 +83,7 @@ public class ScaleSystemVMCmd extends BaseAsyncCmd {
 
     @Override
     public void execute(){
-        UserContext.current().setEventDetails("SystemVm Id: "+getId());
+        CallContext.current().setEventDetails("SystemVm Id: "+getId());
 
         ServiceOffering serviceOffering = _configService.getServiceOffering(serviceOfferingId);
         if (serviceOffering == null) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/systemvm/StartSystemVMCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/systemvm/StartSystemVMCmd.java b/api/src/org/apache/cloudstack/api/command/admin/systemvm/StartSystemVMCmd.java
index 1283d98..1062ae4 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/systemvm/StartSystemVMCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/systemvm/StartSystemVMCmd.java
@@ -24,11 +24,12 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.SystemVmResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "startSystemVm", responseObject=SystemVmResponse.class, description="Starts a system virtual machine.")
@@ -68,7 +69,7 @@ public class StartSystemVMCmd extends BaseAsyncCmd {
 
     @Override
     public long getEntityOwnerId() {
-        Account account = UserContext.current().getCaller();
+        Account account = CallContext.current().getCallingAccount();
         if (account != null) {
             return account.getId();
         }
@@ -102,7 +103,7 @@ public class StartSystemVMCmd extends BaseAsyncCmd {
 
     @Override
     public void execute(){
-        UserContext.current().setEventDetails("Vm Id: "+getId());
+        CallContext.current().setEventDetails("Vm Id: "+getId());
         VirtualMachine instance = _mgr.startSystemVM(getId());
         if (instance != null) {
             SystemVmResponse response = _responseGenerator.createSystemVmResponse(instance);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/api/src/org/apache/cloudstack/api/command/admin/systemvm/StopSystemVmCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/systemvm/StopSystemVmCmd.java b/api/src/org/apache/cloudstack/api/command/admin/systemvm/StopSystemVmCmd.java
index 9954330..c147540 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/systemvm/StopSystemVmCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/systemvm/StopSystemVmCmd.java
@@ -24,13 +24,14 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.SystemVmResponse;
+import org.apache.cloudstack.context.CallContext;
+
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.user.Account;
-import com.cloud.user.UserContext;
 import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "stopSystemVm", description="Stops a system VM.", responseObject=SystemVmResponse.class)
@@ -69,7 +70,7 @@ public class StopSystemVmCmd extends BaseAsyncCmd {
 
     @Override
     public long getEntityOwnerId() {
-        Account account = UserContext.current().getCaller();
+        Account account = CallContext.current().getCallingAccount();
         if (account != null) {
             return account.getId();
         }
@@ -109,7 +110,7 @@ public class StopSystemVmCmd extends BaseAsyncCmd {
 
     @Override
     public void execute() throws ResourceUnavailableException, ConcurrentOperationException {
-        UserContext.current().setEventDetails("Vm Id: "+getId());
+        CallContext.current().setEventDetails("Vm Id: "+getId());
         VirtualMachine result = _mgr.stopSystemVM(this);
         if (result != null) {
             SystemVmResponse response = _responseGenerator.createSystemVmResponse(result);


Mime
View raw message