diff --git a/api/src/com/cloud/user/UserContext.java b/api/src/com/cloud/user/UserContext.java index f14e6cdaf9d..ee519d275d0 100644 --- a/api/src/com/cloud/user/UserContext.java +++ b/api/src/com/cloud/user/UserContext.java @@ -16,103 +16,150 @@ // under the License. package com.cloud.user; -import javax.inject.Inject; +import java.util.HashMap; +import java.util.Map; -import com.cloud.utils.component.ComponentContext; +import org.apache.log4j.Logger; +import org.apache.log4j.NDC; +import com.cloud.dao.EntityManager; +import com.cloud.exception.CloudAuthenticationException; +import com.cloud.utils.exception.CloudRuntimeException; + +/** + * Calling Context records information about who is making this call. This + * class must be always be available in all CloudStack code. Every thread + * entry point must set the context and remove it when the thread finishes. + */ public class UserContext { + private static final Logger s_logger = Logger.getLogger(UserContext.class); private static ThreadLocal s_currentContext = new ThreadLocal(); - private long userId; private String sessionId; private Account account; private long startEventId = 0; - private long accountId; private String eventDetails; - private boolean apiServer; + private User user; + private final Map context = new HashMap(); - @Inject private AccountService _accountMgr = null; + private static EntityManager s_entityMgr; + + public static void init(EntityManager entityMgr) { + s_entityMgr = entityMgr; + } public UserContext() { } - public UserContext(long userId, Account accountObject, String sessionId, boolean apiServer) { - this.userId = userId; - this.account = accountObject; + protected UserContext(User user, Account account, String sessionId) { + this.user = user; + this.account = account; this.sessionId = sessionId; - this.apiServer = apiServer; + } + + public void putContextParameter(String key, Object value) { + context.put(key, value); } - public long getCallerUserId() { - return userId; + public Object getContextParameter(String key) { + return context.get(key); } - public User getCallerUser() { - if (_accountMgr == null) { - _accountMgr = ComponentContext.getComponent(AccountService.class); - } - return _accountMgr.getActiveUser(userId); + public long getCallingUserId() { + return user.getId(); } - public void setCallerUserId(long userId) { - this.userId = userId; + public User getCallingUser() { + return user; } public String getSessionId() { return sessionId; } - public Account getCaller() { + public Account getCallingAccount() { 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() { + return s_currentContext.get(); + } + + public static UserContext register(User callingUser, Account callingAccount, String sessionId) { + assert s_currentContext.get() == null : "There's a context already so what does this new register context mean? " + s_currentContext.get().toString(); + if (s_currentContext.get() != null) { // FIXME: This should be removed soon. I added this check only to surface all the places that have this problem. + throw new CloudRuntimeException("There's a context already so what does this new register context mean? " + s_currentContext.get().toString()); + } + UserContext callingContext = new UserContext(callingUser, callingAccount, sessionId); + s_currentContext.set(callingContext); + if (sessionId != null) { + NDC.push(sessionId); + } + s_logger.debug("Setting calling context: " + s_currentContext.get()); + return callingContext; + } + + public static UserContext registerOnceOnly() { 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 register(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, null); } + + assert context.getCallingUserId() == User.UID_SYSTEM : "You are calling a very specific method that registers a one time system context. This method is meant for background threads that does processing."; 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 UserContext register(String callingUserUuid, String callingAccountUuid, String sessionId) { + Account account = s_entityMgr.findByUuid(Account.class, callingAccountUuid); + if (account == null) { + throw new CloudAuthenticationException("The account is no longer current.").add(Account.class, callingAccountUuid); + } + + User user = s_entityMgr.findByUuid(User.class, callingUserUuid); + if (user == null) { + throw new CloudAuthenticationException("The user is no longer current.").add(User.class, callingUserUuid); + } + return register(user, account, sessionId); } - public static void registerContext(long userId, Account accountObject, String sessionId, boolean apiServer) { - s_currentContext.set(new UserContext(userId, accountObject, sessionId, apiServer)); + public static UserContext register(long callingUserId, long callingAccountId, String sessionId) throws CloudAuthenticationException { + Account account = s_entityMgr.findById(Account.class, callingAccountId); + if (account == null) { + throw new CloudAuthenticationException("The account is no longer current.").add(Account.class, Long.toString(callingAccountId)); + } + User user = s_entityMgr.findById(User.class, callingUserId); + if (user == null) { + throw new CloudAuthenticationException("The user is no longer current.").add(User.class, Long.toString(callingUserId)); + } + return register(user, account, sessionId); } - public static void unregisterContext() { - s_currentContext.set(null); + public static UserContext register(long callingUserId, Account callingAccount, String sessionId, boolean apiServer) { + User user = s_entityMgr.findById(User.class, callingUserId); + if (user == null) { + throw new CloudAuthenticationException("The user is no longer current.").add(User.class, Long.toString(callingUserId)); + } + return register(user, callingAccount, sessionId); + } + + public static UserContext unregister() { + assert s_currentContext.get() != null : "Removing the context when we don't need to " + s_currentContext.get().toString(); + UserContext context = s_currentContext.get(); + if (context == null) { + s_logger.trace("No context to remove"); + return null; + } + s_currentContext.remove(); + s_logger.debug("Context removed " + context); + String sessionId = context.getSessionId(); + if (sessionId != null) { + while ((sessionId = NDC.pop()) != null) { + if (context.getSessionId().equals(sessionId)) { + break; + } + } + } + return context; } public void setStartEventId(long startEventId) { @@ -123,12 +170,16 @@ public class UserContext { return startEventId; } - public long getAccountId() { - return accountId; + public long getCallingAccountId() { + return account.getId(); } - public void setAccountId(long accountId) { - this.accountId = accountId; + public String getCallingAccountUuid() { + return account.getUuid(); + } + + public String getCallingUserUuid() { + return user.getUuid(); } public void setEventDetails(String eventDetails) { @@ -138,4 +189,12 @@ public class UserContext { public String getEventDetails() { return eventDetails; } + + @Override + public String toString() { + return new StringBuffer("CallContext[acct=").append(account.getId()) + .append("; user=").append(user.getId()) + .append("; session=").append(sessionId) + .append("]").toString(); + } } diff --git a/api/src/com/cloud/user/UserContextInitializer.java b/api/src/com/cloud/user/UserContextInitializer.java deleted file mode 100644 index a54596373eb..00000000000 --- 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); - } -} diff --git a/api/src/org/apache/cloudstack/api/BaseAsyncCmd.java b/api/src/org/apache/cloudstack/api/BaseAsyncCmd.java index 56e2ba1858c..b73a8bff8dd 100644 --- a/api/src/org/apache/cloudstack/api/BaseAsyncCmd.java +++ b/api/src/org/apache/cloudstack/api/BaseAsyncCmd.java @@ -98,7 +98,7 @@ public abstract class BaseAsyncCmd extends BaseCmd { protected long saveStartedEvent(String eventType, String description, Long startEventId) { UserContext ctx = UserContext.current(); - Long userId = ctx.getCallerUserId(); + Long userId = ctx.getCallingUserId(); userId = (userId == null) ? User.UID_SYSTEM : userId; Long startEvent = startEventId; if (startEvent == null) { @@ -113,7 +113,7 @@ 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(); + Long userId = ctx.getCallingUserId(); userId = (userId == null) ? User.UID_SYSTEM : userId; Long startEvent = startEventId; if (startEvent == null) { diff --git a/api/src/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java b/api/src/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java index 1c94e10dd5d..2da3a5e8305 100644 --- a/api/src/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java +++ b/api/src/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java @@ -80,7 +80,7 @@ public class BaseListTemplateOrIsoPermissionsCmd extends BaseCmd { public void execute(){ List accountNames = _templateService.listTemplatePermissions(this); - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); boolean isAdmin = (isAdmin(account.getType())); TemplatePermissionsResponse response = _responseGenerator.createTemplatePermissionsResponse(accountNames, id, isAdmin); 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 a2833650adf..024e69ced33 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 @@ -75,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 = UserContext.current().getCallingAccount();// Let's give the caller here for event logging. if (account != null) { return account.getAccountId(); } 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 b4023d95e19..2e725f1cd8a 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 @@ -69,7 +69,7 @@ public class CancelMaintenanceCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } 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 e55680a1e23..1534c7955eb 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 @@ -69,7 +69,7 @@ public class PrepareForMaintenanceCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } 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 f96d9b16fa3..ca25b64c289 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 @@ -69,7 +69,7 @@ public class ReconnectHostCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } 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 5ace7661330..fe5a11e2eed 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 @@ -65,7 +65,7 @@ public class ReleaseHostReservationCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } 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 5ca4f4f5053..7db6e6f8229 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 @@ -109,7 +109,7 @@ public class StartInternalLBVMCmd extends BaseAsyncCmd { 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(), UserContext.current().getCallingAccount(), UserContext.current().getCallingUserId()); } if (result != null){ 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 be1887ea3a7..67bce1d1f15 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 @@ -110,7 +110,7 @@ public class StopInternalLBVMCmd extends BaseAsyncCmd { 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(), UserContext.current().getCallingAccount(), UserContext.current().getCallingUserId()); } if (result != null) { 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 932becb34a3..2407c4f0190 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 @@ -99,7 +99,7 @@ public class DestroyRouterCmd extends BaseAsyncCmd { UserContext ctx = UserContext.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()); 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 c0433115d00..fd194e37bae 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 @@ -82,7 +82,7 @@ public class CancelPrimaryStorageMaintenanceCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } 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 269b0ab8263..d84f641e49f 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 @@ -80,7 +80,7 @@ public class PreparePrimaryStorageForMaintenanceCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } 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 392d13fa650..8816d5a77d7 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 @@ -57,7 +57,7 @@ public class DestroySystemVmCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } 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 923e6fde049..ec44e7a9118 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 @@ -82,7 +82,7 @@ public class MigrateSystemVMCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } 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 dba34e100a6..b70e34b7fb0 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 @@ -65,7 +65,7 @@ public class RebootSystemVmCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } 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 a077e246a46..df863801b69 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 @@ -71,7 +71,7 @@ public class ScaleSystemVMCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } 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 991774793b4..2cc69567d86 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 @@ -69,7 +69,7 @@ public class StartSystemVMCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } 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 396360fccd5..d891ca93c52 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 @@ -70,7 +70,7 @@ public class StopSystemVmCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } diff --git a/api/src/org/apache/cloudstack/api/command/admin/systemvm/UpgradeSystemVMCmd.java b/api/src/org/apache/cloudstack/api/command/admin/systemvm/UpgradeSystemVMCmd.java index 4b5feb8eb6b..70e0dcb9839 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/systemvm/UpgradeSystemVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/systemvm/UpgradeSystemVMCmd.java @@ -76,7 +76,7 @@ public class UpgradeSystemVMCmd extends BaseCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } diff --git a/api/src/org/apache/cloudstack/api/command/admin/user/CreateUserCmd.java b/api/src/org/apache/cloudstack/api/command/admin/user/CreateUserCmd.java index f9fc1ab690d..85a3ee2baac 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/user/CreateUserCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/user/CreateUserCmd.java @@ -120,7 +120,7 @@ public class CreateUserCmd extends BaseCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if ((account == null) || isAdmin(account.getType())) { if ((domainId != null) && (accountName != null)) { Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId); diff --git a/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java b/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java index 21f8177e55e..42215a74c56 100644 --- a/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java @@ -103,14 +103,14 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd { if (accountName != null) { return accountName; } - return UserContext.current().getCaller().getAccountName(); + return UserContext.current().getCallingAccount().getAccountName(); } public long getDomainId() { if (domainId != null) { return domainId; } - return UserContext.current().getCaller().getDomainId(); + return UserContext.current().getCallingAccount().getDomainId(); } private long getZoneId() { @@ -191,7 +191,7 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd { @Override public long getEntityOwnerId() { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); if (accountName != null && domainId != null) { Account account = _accountService.finalizeOwner(caller, accountName, domainId, projectId); return account.getId(); diff --git a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java index a160892bdc9..3955da87505 100644 --- a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java @@ -95,7 +95,7 @@ public class CreateAffinityGroupCmd extends BaseAsyncCreateCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if ((account == null) || isAdmin(account.getType())) { if ((domainId != null) && (accountName != null)) { Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId); diff --git a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java index 0eb6a4cb2fd..4fa7f2436f2 100644 --- a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java @@ -102,7 +102,7 @@ public class DeleteAffinityGroupCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if ((account == null) || isAdmin(account.getType())) { if ((domainId != null) && (accountName != null)) { Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId); diff --git a/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java b/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java index 84a6182e99d..485fc64ae84 100644 --- a/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java @@ -120,7 +120,7 @@ public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd { if (autoscaleUserId != null) { return autoscaleUserId; } else { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } } @@ -137,7 +137,7 @@ public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd { User user = _entityMgr.findById(User.class, autoscaleUserId); account = _entityMgr.findById(Account.class, user.getAccountId()); } else { - account = UserContext.current().getCaller(); + account = UserContext.current().getCallingAccount(); } accountId = account.getAccountId(); domainId = account.getDomainId(); diff --git a/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateConditionCmd.java b/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateConditionCmd.java index 293a054f9cd..9c0763173f8 100644 --- a/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateConditionCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/autoscale/CreateConditionCmd.java @@ -106,7 +106,7 @@ public class CreateConditionCmd extends BaseAsyncCreateCmd { public String getAccountName() { if (accountName == null) { - return UserContext.current().getCaller().getAccountName(); + return UserContext.current().getCallingAccount().getAccountName(); } return accountName; @@ -114,7 +114,7 @@ public class CreateConditionCmd extends BaseAsyncCreateCmd { public Long getDomainId() { if (domainId == null) { - return UserContext.current().getCaller().getDomainId(); + return UserContext.current().getCallingAccount().getDomainId(); } return domainId; } @@ -142,7 +142,7 @@ public class CreateConditionCmd extends BaseAsyncCreateCmd { public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, null, true); if (accountId == null) { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } return accountId; diff --git a/api/src/org/apache/cloudstack/api/command/user/event/ArchiveEventsCmd.java b/api/src/org/apache/cloudstack/api/command/user/event/ArchiveEventsCmd.java index cfff73b53bf..1c641e81dbb 100644 --- a/api/src/org/apache/cloudstack/api/command/user/event/ArchiveEventsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/event/ArchiveEventsCmd.java @@ -82,7 +82,7 @@ public class ArchiveEventsCmd extends BaseCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } diff --git a/api/src/org/apache/cloudstack/api/command/user/event/DeleteEventsCmd.java b/api/src/org/apache/cloudstack/api/command/user/event/DeleteEventsCmd.java index 324c7b2c530..4500b54d8ea 100644 --- a/api/src/org/apache/cloudstack/api/command/user/event/DeleteEventsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/event/DeleteEventsCmd.java @@ -82,7 +82,7 @@ public class DeleteEventsCmd extends BaseCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } diff --git a/api/src/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java index a1279a99e45..cece2d0eb88 100644 --- a/api/src/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java @@ -133,7 +133,7 @@ public class CreateEgressFirewallRuleCmd extends BaseAsyncCreateCmd implements F FirewallRule rule = _entityMgr.findById(FirewallRule.class, getEntityId()); try { UserContext.current().setEventDetails("Rule Id: " + getEntityId()); - success = _firewallService.applyEgressFirewallRules (rule, callerContext.getCaller()); + success = _firewallService.applyEgressFirewallRules (rule, callerContext.getCallingAccount()); // State is different after the rule is applied, so get new object here rule = _entityMgr.findById(FirewallRule.class, getEntityId()); FirewallResponse fwResponse = new FirewallResponse(); @@ -204,7 +204,7 @@ public class CreateEgressFirewallRuleCmd extends BaseAsyncCreateCmd implements F @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); diff --git a/api/src/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java index c6cbe09598a..0388a481ac6 100644 --- a/api/src/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java @@ -122,7 +122,7 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal FirewallRule rule = _entityMgr.findById(FirewallRule.class, getEntityId()); try { UserContext.current().setEventDetails("Rule Id: " + getEntityId()); - success = _firewallService.applyIngressFirewallRules(rule.getSourceIpAddressId(), callerContext.getCaller()); + success = _firewallService.applyIngressFirewallRules(rule.getSourceIpAddressId(), callerContext.getCallingAccount()); // State is different after the rule is applied, so get new object here rule = _entityMgr.findById(FirewallRule.class, getEntityId()); @@ -212,7 +212,7 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); diff --git a/api/src/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java index 43d7b8cf540..0e5a9521d33 100644 --- a/api/src/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java @@ -179,10 +179,10 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P UserContext.current().setEventDetails("Rule Id: " + getEntityId()); if (getOpenFirewall()) { - success = success && _firewallService.applyIngressFirewallRules(ipAddressId, callerContext.getCaller()); + success = success && _firewallService.applyIngressFirewallRules(ipAddressId, callerContext.getCallingAccount()); } - success = success && _rulesService.applyPortForwardingRules(ipAddressId, callerContext.getCaller()); + success = success && _rulesService.applyPortForwardingRules(ipAddressId, callerContext.getCallingAccount()); // State is different after the rule is applied, so get new object here rule = _entityMgr.findById(PortForwardingRule.class, getEntityId()); @@ -272,7 +272,7 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); diff --git a/api/src/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java b/api/src/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java index d70375aa57a..04d40bd61a9 100644 --- a/api/src/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java @@ -124,7 +124,7 @@ public class ListIsosCmd extends BaseListTaggedResourcesCmd { } public boolean listInReadyState() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); // It is account specific if account is admin type and domainId and accountName are not null boolean isAccountSpecific = (account == null || isAdmin(account.getType())) && (getAccountName() != null) && (getDomainId() != null); // Show only those that are downloaded. diff --git a/api/src/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java b/api/src/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java index ec08db0c9db..719779d47a6 100644 --- a/api/src/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java @@ -163,7 +163,7 @@ public class RegisterIsoCmd extends BaseCmd { public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, projectId, true); if (accountId == null) { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } return accountId; diff --git a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBHealthCheckPolicyCmd.java b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBHealthCheckPolicyCmd.java index 4a87652ba78..c329781e913 100644 --- a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBHealthCheckPolicyCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBHealthCheckPolicyCmd.java @@ -98,7 +98,7 @@ public class CreateLBHealthCheckPolicyCmd extends BaseAsyncCreateCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } diff --git a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBStickinessPolicyCmd.java b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBStickinessPolicyCmd.java index 648983b2a58..6bd3d8361fe 100644 --- a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBStickinessPolicyCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBStickinessPolicyCmd.java @@ -104,7 +104,7 @@ public class CreateLBStickinessPolicyCmd extends BaseAsyncCreateCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } diff --git a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLoadBalancerRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLoadBalancerRuleCmd.java index 46dd9b77288..d50a7972316 100644 --- a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLoadBalancerRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLoadBalancerRuleCmd.java @@ -245,7 +245,7 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements UserContext.current().setEventDetails("Rule Id: " + getEntityId()); if (getOpenFirewall()) { - success = success && _firewallService.applyIngressFirewallRules(getSourceIpAddressId(), callerContext.getCaller()); + success = success && _firewallService.applyIngressFirewallRules(getSourceIpAddressId(), callerContext.getCallingAccount()); } // State might be different after the rule is applied, so get new object here @@ -328,7 +328,7 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements if (domainId != null) { return domainId; } - return UserContext.current().getCaller().getDomainId(); + return UserContext.current().getCallingAccount().getDomainId(); } public int getDefaultPortStart() { diff --git a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBHealthCheckPolicyCmd.java b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBHealthCheckPolicyCmd.java index 968dee9ad8d..4897a65e76b 100644 --- a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBHealthCheckPolicyCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBHealthCheckPolicyCmd.java @@ -65,7 +65,7 @@ public class DeleteLBHealthCheckPolicyCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } diff --git a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBStickinessPolicyCmd.java b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBStickinessPolicyCmd.java index 32b164912a2..ecb9350ab77 100644 --- a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBStickinessPolicyCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBStickinessPolicyCmd.java @@ -65,7 +65,7 @@ public class DeleteLBStickinessPolicyCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } diff --git a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/ListLBStickinessPoliciesCmd.java b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/ListLBStickinessPoliciesCmd.java index 19ac4475e79..544328609c6 100644 --- a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/ListLBStickinessPoliciesCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/ListLBStickinessPoliciesCmd.java @@ -72,7 +72,7 @@ public class ListLBStickinessPoliciesCmd extends BaseListCmd { if (lb != null) { //check permissions - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); _accountService.checkAccess(caller, null, true, lb); List stickinessPolicies = _lbService.searchForLBStickinessPolicies(this); LBStickinessResponse spResponse = _responseGenerator.createLBStickinessPolicyResponse(stickinessPolicies, lb); diff --git a/api/src/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java index cb9df7e61d2..e1657848a50 100644 --- a/api/src/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java @@ -115,10 +115,10 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Sta UserContext.current().setEventDetails("Rule Id: "+ getEntityId()); if (getOpenFirewall()) { - result = result && _firewallService.applyIngressFirewallRules(ipAddressId, UserContext.current().getCaller()); + result = result && _firewallService.applyIngressFirewallRules(ipAddressId, UserContext.current().getCallingAccount()); } - result = result && _rulesService.applyStaticNatRules(ipAddressId, UserContext.current().getCaller()); + result = result && _rulesService.applyStaticNatRules(ipAddressId, UserContext.current().getCallingAccount()); rule = _entityMgr.findById(FirewallRule.class, getEntityId()); StaticNatRule staticNatRule = _rulesService.buildStaticNatRule(rule, false); IpForwardingRuleResponse fwResponse = _responseGenerator.createIpForwardingRuleResponse(staticNatRule); @@ -158,7 +158,7 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Sta @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); diff --git a/api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkACLCmd.java b/api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkACLCmd.java index 113e89cb465..60339e475e4 100644 --- a/api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkACLCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkACLCmd.java @@ -166,7 +166,7 @@ public class CreateNetworkACLCmd extends BaseAsyncCreateCmd { @Override public long getEntityOwnerId() { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); return caller.getAccountId(); } diff --git a/api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java b/api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java index 9ec436e0628..fd720c27223 100644 --- a/api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java @@ -282,7 +282,7 @@ public class CreateNetworkCmd extends BaseCmd { public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, projectId, true); if (accountId == null) { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } return accountId; diff --git a/api/src/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLCmd.java b/api/src/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLCmd.java index 051e5867529..7ac90bd3cef 100644 --- a/api/src/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLCmd.java @@ -73,7 +73,7 @@ public class DeleteNetworkACLCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); return caller.getAccountId(); } diff --git a/api/src/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLListCmd.java b/api/src/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLListCmd.java index 22f7b3caea3..82bbab74c8f 100644 --- a/api/src/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLListCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLListCmd.java @@ -74,7 +74,7 @@ public class DeleteNetworkACLListCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); return caller.getAccountId(); } diff --git a/api/src/org/apache/cloudstack/api/command/user/network/ReplaceNetworkACLListCmd.java b/api/src/org/apache/cloudstack/api/command/user/network/ReplaceNetworkACLListCmd.java index 67f40d1a942..e6ec5172283 100644 --- a/api/src/org/apache/cloudstack/api/command/user/network/ReplaceNetworkACLListCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/network/ReplaceNetworkACLListCmd.java @@ -87,7 +87,7 @@ public class ReplaceNetworkACLListCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); return caller.getAccountId(); } diff --git a/api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLItemCmd.java b/api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLItemCmd.java index 1ea815ab1fb..83bdc5b0e0e 100644 --- a/api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLItemCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLItemCmd.java @@ -134,7 +134,7 @@ public class UpdateNetworkACLItemCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); return caller.getAccountId(); } diff --git a/api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java b/api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java index 63b5bb31d56..6fc99dace95 100644 --- a/api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java @@ -130,7 +130,7 @@ public class UpdateNetworkCmd extends BaseAsyncCmd { @Override public void execute() throws InsufficientCapacityException, ConcurrentOperationException{ - User callerUser = _accountService.getActiveUser(UserContext.current().getCallerUserId()); + User callerUser = _accountService.getActiveUser(UserContext.current().getCallingUserId()); Account callerAccount = _accountService.getActiveAccountById(callerUser.getAccountId()); Network network = _networkService.getNetwork(id); if (network == null) { diff --git a/api/src/org/apache/cloudstack/api/command/user/project/CreateProjectCmd.java b/api/src/org/apache/cloudstack/api/command/user/project/CreateProjectCmd.java index 789c0fe943c..7d779807d1d 100644 --- a/api/src/org/apache/cloudstack/api/command/user/project/CreateProjectCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/project/CreateProjectCmd.java @@ -66,7 +66,7 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd { if (accountName != null) { return accountName; } else { - return UserContext.current().getCaller().getAccountName(); + return UserContext.current().getCallingAccount().getAccountName(); } } @@ -74,7 +74,7 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd { if (domainId != null) { return domainId; } else { - return UserContext.current().getCaller().getDomainId(); + return UserContext.current().getCallingAccount().getDomainId(); } } @@ -94,7 +94,7 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd { @Override public long getEntityOwnerId() { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); if ((accountName != null && domainId == null) || (domainId != null && accountName == null)) { throw new InvalidParameterValueException("Account name and domain id must be specified together"); diff --git a/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java index e04bb336b79..595f4d9d6ed 100644 --- a/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java @@ -182,7 +182,7 @@ public class CreateGlobalLoadBalancerRuleCmd extends BaseAsyncCreateCmd { public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, null, true); if (accountId == null) { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } return accountId; } diff --git a/api/src/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmd.java b/api/src/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmd.java index 791243acfaf..b3255c4ad39 100644 --- a/api/src/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmd.java @@ -100,7 +100,7 @@ public class UpdateResourceCountCmd extends BaseCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if ((account == null) || isAdmin(account.getType())) { if ((domainId != null) && (accountName != null)) { Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId); diff --git a/api/src/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmd.java b/api/src/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmd.java index 038d06d82c1..9e5aa156e1c 100644 --- a/api/src/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmd.java @@ -97,7 +97,7 @@ public class UpdateResourceLimitCmd extends BaseCmd { public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, projectId, true); if (accountId == null) { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } return accountId; diff --git a/api/src/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupEgressCmd.java b/api/src/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupEgressCmd.java index bfbd97ceaf2..4f75724c6bd 100644 --- a/api/src/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupEgressCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupEgressCmd.java @@ -165,7 +165,7 @@ public class AuthorizeSecurityGroupEgressCmd extends BaseAsyncCmd { public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, projectId, true); if (accountId == null) { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } return accountId; diff --git a/api/src/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupIngressCmd.java b/api/src/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupIngressCmd.java index 40e6620419c..50686993c61 100644 --- a/api/src/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupIngressCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupIngressCmd.java @@ -166,7 +166,7 @@ public class AuthorizeSecurityGroupIngressCmd extends BaseAsyncCmd { public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, projectId, true); if (accountId == null) { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } return accountId; diff --git a/api/src/org/apache/cloudstack/api/command/user/securitygroup/CreateSecurityGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/securitygroup/CreateSecurityGroupCmd.java index fb7c2ccf43f..1f970e479a1 100644 --- a/api/src/org/apache/cloudstack/api/command/user/securitygroup/CreateSecurityGroupCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/securitygroup/CreateSecurityGroupCmd.java @@ -92,7 +92,7 @@ public class CreateSecurityGroupCmd extends BaseCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if ((account == null) || isAdmin(account.getType())) { if ((domainId != null) && (accountName != null)) { Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId); diff --git a/api/src/org/apache/cloudstack/api/command/user/securitygroup/DeleteSecurityGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/securitygroup/DeleteSecurityGroupCmd.java index bc30b7646cb..2a4c4a90459 100644 --- a/api/src/org/apache/cloudstack/api/command/user/securitygroup/DeleteSecurityGroupCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/securitygroup/DeleteSecurityGroupCmd.java @@ -108,7 +108,7 @@ public class DeleteSecurityGroupCmd extends BaseCmd { public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, projectId, true); if (accountId == null) { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } return accountId; diff --git a/api/src/org/apache/cloudstack/api/command/user/ssh/CreateSSHKeyPairCmd.java b/api/src/org/apache/cloudstack/api/command/user/ssh/CreateSSHKeyPairCmd.java index d87cf9efa59..1b948c2664e 100644 --- a/api/src/org/apache/cloudstack/api/command/user/ssh/CreateSSHKeyPairCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/ssh/CreateSSHKeyPairCmd.java @@ -82,7 +82,7 @@ public class CreateSSHKeyPairCmd extends BaseCmd { public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, projectId, true); if (accountId == null) { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } return accountId; diff --git a/api/src/org/apache/cloudstack/api/command/user/ssh/DeleteSSHKeyPairCmd.java b/api/src/org/apache/cloudstack/api/command/user/ssh/DeleteSSHKeyPairCmd.java index f40fa73011d..91f2f687f39 100644 --- a/api/src/org/apache/cloudstack/api/command/user/ssh/DeleteSSHKeyPairCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/ssh/DeleteSSHKeyPairCmd.java @@ -91,7 +91,7 @@ public class DeleteSSHKeyPairCmd extends BaseCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if ((account == null) || isAdmin(account.getType())) { if ((domainId != null) && (accountName != null)) { Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId); diff --git a/api/src/org/apache/cloudstack/api/command/user/ssh/RegisterSSHKeyPairCmd.java b/api/src/org/apache/cloudstack/api/command/user/ssh/RegisterSSHKeyPairCmd.java index feffda5e79e..efc4e14faad 100644 --- a/api/src/org/apache/cloudstack/api/command/user/ssh/RegisterSSHKeyPairCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/ssh/RegisterSSHKeyPairCmd.java @@ -88,7 +88,7 @@ public class RegisterSSHKeyPairCmd extends BaseCmd { public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, projectId, true); if (accountId == null) { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } return accountId; diff --git a/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java index 2da3bf4ede3..07f5d56102a 100644 --- a/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java @@ -103,7 +103,7 @@ public class ListTemplatesCmd extends BaseListTaggedResourcesCmd { public boolean listInReadyState() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); // It is account specific if account is admin type and domainId and accountName are not null boolean isAccountSpecific = (account == null || isAdmin(account.getType())) && (getAccountName() != null) && (getDomainId() != null); // Show only those that are downloaded. diff --git a/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java index a66acde51ac..e3cc319f623 100644 --- a/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java @@ -226,7 +226,7 @@ public class RegisterTemplateCmd extends BaseCmd { public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, projectId, true); if (accountId == null) { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } return accountId; diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java index 9c95a9e3bb7..f252d300d56 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java @@ -69,11 +69,11 @@ public class AddIpToVmNicCmd extends BaseAsyncCmd { } public String getAccountName() { - return UserContext.current().getCaller().getAccountName(); + return UserContext.current().getCallingAccount().getAccountName(); } public long getDomainId() { - return UserContext.current().getCaller().getDomainId(); + return UserContext.current().getCallingAccount().getDomainId(); } private long getZoneId() { @@ -113,7 +113,7 @@ public class AddIpToVmNicCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); return caller.getAccountId(); } diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java index 6dfc576b187..1d780aee873 100755 --- a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java @@ -195,7 +195,7 @@ public class DeployVMCmd extends BaseAsyncCreateCmd { public String getAccountName() { if (accountName == null) { - return UserContext.current().getCaller().getAccountName(); + return UserContext.current().getCallingAccount().getAccountName(); } return accountName; } @@ -210,7 +210,7 @@ public class DeployVMCmd extends BaseAsyncCreateCmd { public Long getDomainId() { if (domainId == null) { - return UserContext.current().getCaller().getDomainId(); + return UserContext.current().getCallingAccount().getDomainId(); } return domainId; } @@ -380,7 +380,7 @@ public class DeployVMCmd extends BaseAsyncCreateCmd { public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, projectId, true); if (accountId == null) { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } return accountId; diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/ListNicsCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/ListNicsCmd.java index 189136566cb..8d4181dac18 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vm/ListNicsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/ListNicsCmd.java @@ -66,11 +66,11 @@ public class ListNicsCmd extends BaseListCmd { } public String getAccountName() { - return UserContext.current().getCaller().getAccountName(); + return UserContext.current().getCallingAccount().getAccountName(); } public long getDomainId() { - return UserContext.current().getCaller().getDomainId(); + return UserContext.current().getCallingAccount().getDomainId(); } public Long getNicId() { @@ -83,7 +83,7 @@ public class ListNicsCmd extends BaseListCmd { @Override public long getEntityOwnerId() { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); return caller.getAccountId(); } diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java index 1a78f481c58..b1115172886 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java @@ -67,16 +67,16 @@ public class RemoveIpFromVmNicCmd extends BaseAsyncCmd { } public String getAccountName() { - return UserContext.current().getCaller().getAccountName(); + return UserContext.current().getCallingAccount().getAccountName(); } public long getDomainId() { - return UserContext.current().getCaller().getDomainId(); + return UserContext.current().getCallingAccount().getDomainId(); } @Override public long getEntityOwnerId() { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); return caller.getAccountId(); } diff --git a/api/src/org/apache/cloudstack/api/command/user/vmgroup/CreateVMGroupCmd.java b/api/src/org/apache/cloudstack/api/command/user/vmgroup/CreateVMGroupCmd.java index 24aad77d984..d4e699eab05 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vmgroup/CreateVMGroupCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vmgroup/CreateVMGroupCmd.java @@ -89,7 +89,7 @@ public class CreateVMGroupCmd extends BaseCmd { public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, projectId, true); if (accountId == null) { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } return accountId; diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java index 85629d19952..3966c424a6e 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java @@ -141,7 +141,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCmd { public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, projectId, true); if (accountId == null) { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } return accountId; diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/DeleteVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/DeleteVolumeCmd.java index ead687ee03d..6a92dd5f884 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/DeleteVolumeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/DeleteVolumeCmd.java @@ -81,7 +81,7 @@ public class DeleteVolumeCmd extends BaseCmd { @Override public void execute() throws ConcurrentOperationException { UserContext.current().setEventDetails("Volume Id: "+getId()); - boolean result = this._volumeService.deleteVolume(id, UserContext.current().getCaller()); + boolean result = this._volumeService.deleteVolume(id, UserContext.current().getCallingAccount()); if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java index a74763c198a..70441cae4c3 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java @@ -144,7 +144,7 @@ public class UploadVolumeCmd extends BaseAsyncCmd { public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, projectId, true); if (accountId == null) { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } return accountId; diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java index 20a29d4d91b..5cc62473baa 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java @@ -180,7 +180,7 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{ public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, projectId, true); if (accountId == null) { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } return accountId; diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/AddVpnUserCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/AddVpnUserCmd.java index 2f30091a403..56834930447 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/AddVpnUserCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/AddVpnUserCmd.java @@ -98,7 +98,7 @@ public class AddVpnUserCmd extends BaseAsyncCreateCmd { public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, projectId, true); if (accountId == null) { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } return accountId; diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java index 3546267664a..510f894df8a 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java @@ -138,7 +138,7 @@ public class CreateVpnCustomerGatewayCmd extends BaseAsyncCmd { public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, null, true); if (accountId == null) { - accountId = UserContext.current().getCaller().getId(); + accountId = UserContext.current().getCallingAccount().getId(); } return accountId; } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteRemoteAccessVpnCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteRemoteAccessVpnCmd.java index fa1fd7deda5..4c9a0b5e6cd 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteRemoteAccessVpnCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteRemoteAccessVpnCmd.java @@ -85,7 +85,7 @@ public class DeleteRemoteAccessVpnCmd extends BaseAsyncCmd { @Override public void execute() throws ResourceUnavailableException { - _ravService.destroyRemoteAccessVpnForIp(publicIpId, UserContext.current().getCaller()); + _ravService.destroyRemoteAccessVpnForIp(publicIpId, UserContext.current().getCallingAccount()); } @Override diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/RemoveVpnUserCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/RemoveVpnUserCmd.java index 12ef712533b..fa576043220 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/RemoveVpnUserCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/RemoveVpnUserCmd.java @@ -90,7 +90,7 @@ public class RemoveVpnUserCmd extends BaseAsyncCmd { public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, projectId, true); if (accountId == null) { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } return accountId; @@ -109,7 +109,7 @@ public class RemoveVpnUserCmd extends BaseAsyncCmd { @Override public void execute(){ Account owner = _accountService.getAccount(getEntityOwnerId()); - boolean result = _ravService.removeVpnUser(owner.getId(), userName, UserContext.current().getCaller()); + boolean result = _ravService.removeVpnUser(owner.getId(), userName, UserContext.current().getCallingAccount()); if (!result) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove vpn user"); } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/ResetVpnConnectionCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/ResetVpnConnectionCmd.java index 5043ff315cc..d65241df3ae 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/ResetVpnConnectionCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/ResetVpnConnectionCmd.java @@ -85,7 +85,7 @@ public class ResetVpnConnectionCmd extends BaseAsyncCmd { public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, null, true); if (accountId == null) { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } return Account.ACCOUNT_ID_SYSTEM; } diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnCustomerGatewayCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnCustomerGatewayCmd.java index 12ed65b334c..977651e8f94 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnCustomerGatewayCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpn/UpdateVpnCustomerGatewayCmd.java @@ -137,7 +137,7 @@ public class UpdateVpnCustomerGatewayCmd extends BaseAsyncCmd { public long getEntityOwnerId() { Long accountId = finalyzeAccountId(accountName, domainId, null, true); if (accountId == null) { - accountId = UserContext.current().getCaller().getId(); + accountId = UserContext.current().getCallingAccount().getId(); } return accountId; } diff --git a/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJob.java b/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJob.java index 19eff1c9cd2..35f4f3e90db 100644 --- a/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJob.java +++ b/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJob.java @@ -95,6 +95,8 @@ public interface AsyncJob extends Job { @Override Long getInstanceId(); + String getShortUuid(); + SyncQueueItem getSyncSource(); void setSyncSource(SyncQueueItem item); } diff --git a/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJobVO.java b/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJobVO.java index b5f883cf07b..9c9001ab552 100644 --- a/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJobVO.java +++ b/framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJobVO.java @@ -35,6 +35,7 @@ import javax.persistence.Transient; import org.apache.cloudstack.jobs.Job; +import com.cloud.utils.UuidUtils; import com.cloud.utils.db.GenericDao; @Entity @@ -142,6 +143,11 @@ public class AsyncJobVO implements AsyncJob, Job { this.id = id; } + @Override + public String getShortUuid() { + return UuidUtils.first(uuid); + } + @Override public String getType() { return type; diff --git a/plugins/api/discovery/src/org/apache/cloudstack/api/command/user/discovery/ListApisCmd.java b/plugins/api/discovery/src/org/apache/cloudstack/api/command/user/discovery/ListApisCmd.java index 5de04f01e11..3bb04fd834a 100644 --- a/plugins/api/discovery/src/org/apache/cloudstack/api/command/user/discovery/ListApisCmd.java +++ b/plugins/api/discovery/src/org/apache/cloudstack/api/command/user/discovery/ListApisCmd.java @@ -47,7 +47,7 @@ public class ListApisCmd extends BaseCmd { @Override public void execute() throws ServerApiException { if (_apiDiscoveryService != null) { - User user = UserContext.current().getCallerUser(); + User user = UserContext.current().getCallingUser(); ListResponse response = (ListResponse) _apiDiscoveryService.listApis(user, name); if (response == null) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Api Discovery plugin was unable to find an api by that name or process any apis"); diff --git a/plugins/api/rate-limit/src/org/apache/cloudstack/api/command/admin/ratelimit/ResetApiLimitCmd.java b/plugins/api/rate-limit/src/org/apache/cloudstack/api/command/admin/ratelimit/ResetApiLimitCmd.java index 7ec53163c91..bf4e91c889b 100644 --- a/plugins/api/rate-limit/src/org/apache/cloudstack/api/command/admin/ratelimit/ResetApiLimitCmd.java +++ b/plugins/api/rate-limit/src/org/apache/cloudstack/api/command/admin/ratelimit/ResetApiLimitCmd.java @@ -84,7 +84,7 @@ public class ResetApiLimitCmd extends BaseCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } diff --git a/plugins/api/rate-limit/src/org/apache/cloudstack/api/command/user/ratelimit/GetApiLimitCmd.java b/plugins/api/rate-limit/src/org/apache/cloudstack/api/command/user/ratelimit/GetApiLimitCmd.java index ba92e8b60c8..319daec7017 100644 --- a/plugins/api/rate-limit/src/org/apache/cloudstack/api/command/user/ratelimit/GetApiLimitCmd.java +++ b/plugins/api/rate-limit/src/org/apache/cloudstack/api/command/user/ratelimit/GetApiLimitCmd.java @@ -73,7 +73,7 @@ public class GetApiLimitCmd extends BaseCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account != null) { return account.getId(); } @@ -87,7 +87,7 @@ public class GetApiLimitCmd extends BaseCmd { if ( !apiLimitEnabled ){ throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "This api is only available when api.throttling.enabled = true."); } - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); ApiLimitResponse response = _apiLimitService.searchApiLimit(caller); response.setResponseName(getCommandName()); response.setObjectName("apilimit"); diff --git a/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java b/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java index 83cc12370f1..32ff9983cc9 100644 --- a/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java +++ b/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java @@ -165,7 +165,7 @@ public class ImplicitPlannerTest { acct.setDomainId(domainId); acct.setId(accountId); - UserContext.registerContext(1, acct, null, true); + UserContext.register(1, acct, null, true); } @Test diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/AddBaremetalDhcpCmd.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/AddBaremetalDhcpCmd.java index c74983222f2..9c3398c6898 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/AddBaremetalDhcpCmd.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/AddBaremetalDhcpCmd.java @@ -100,7 +100,7 @@ public class AddBaremetalDhcpCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } public Long getPodId() { diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/AddBaremetalPxeCmd.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/AddBaremetalPxeCmd.java index 63e11478e4c..e64e0707d28 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/AddBaremetalPxeCmd.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/AddBaremetalPxeCmd.java @@ -94,7 +94,7 @@ public class AddBaremetalPxeCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } public Long getPhysicalNetworkId() { diff --git a/plugins/network-elements/bigswitch-vns/src/com/cloud/api/commands/AddBigSwitchVnsDeviceCmd.java b/plugins/network-elements/bigswitch-vns/src/com/cloud/api/commands/AddBigSwitchVnsDeviceCmd.java index 30f631dd5d6..f82ee127136 100644 --- a/plugins/network-elements/bigswitch-vns/src/com/cloud/api/commands/AddBigSwitchVnsDeviceCmd.java +++ b/plugins/network-elements/bigswitch-vns/src/com/cloud/api/commands/AddBigSwitchVnsDeviceCmd.java @@ -96,7 +96,7 @@ public class AddBigSwitchVnsDeviceCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } @Override diff --git a/plugins/network-elements/bigswitch-vns/src/com/cloud/api/commands/DeleteBigSwitchVnsDeviceCmd.java b/plugins/network-elements/bigswitch-vns/src/com/cloud/api/commands/DeleteBigSwitchVnsDeviceCmd.java index 9a7dc480968..514d312d6d1 100644 --- a/plugins/network-elements/bigswitch-vns/src/com/cloud/api/commands/DeleteBigSwitchVnsDeviceCmd.java +++ b/plugins/network-elements/bigswitch-vns/src/com/cloud/api/commands/DeleteBigSwitchVnsDeviceCmd.java @@ -86,7 +86,7 @@ public class DeleteBigSwitchVnsDeviceCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } @Override diff --git a/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/AddCiscoAsa1000vResourceCmd.java b/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/AddCiscoAsa1000vResourceCmd.java index c880199f5c4..11ea00ff894 100755 --- a/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/AddCiscoAsa1000vResourceCmd.java +++ b/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/AddCiscoAsa1000vResourceCmd.java @@ -111,6 +111,6 @@ public class AddCiscoAsa1000vResourceCmd extends BaseCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } } diff --git a/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/AddCiscoVnmcResourceCmd.java b/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/AddCiscoVnmcResourceCmd.java index bfd6db95434..900e4ac9cff 100644 --- a/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/AddCiscoVnmcResourceCmd.java +++ b/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/AddCiscoVnmcResourceCmd.java @@ -110,6 +110,6 @@ public class AddCiscoVnmcResourceCmd extends BaseCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } } diff --git a/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/DeleteCiscoAsa1000vResourceCmd.java b/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/DeleteCiscoAsa1000vResourceCmd.java index d4f86fa527a..0894f2f1db3 100755 --- a/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/DeleteCiscoAsa1000vResourceCmd.java +++ b/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/DeleteCiscoAsa1000vResourceCmd.java @@ -87,7 +87,7 @@ public class DeleteCiscoAsa1000vResourceCmd extends BaseCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } } diff --git a/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/DeleteCiscoVnmcResourceCmd.java b/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/DeleteCiscoVnmcResourceCmd.java index d2a37202f0a..bdc00e87d42 100644 --- a/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/DeleteCiscoVnmcResourceCmd.java +++ b/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/DeleteCiscoVnmcResourceCmd.java @@ -87,7 +87,7 @@ public class DeleteCiscoVnmcResourceCmd extends BaseCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } } diff --git a/plugins/network-elements/cisco-vnmc/src/com/cloud/network/element/CiscoVnmcElement.java b/plugins/network-elements/cisco-vnmc/src/com/cloud/network/element/CiscoVnmcElement.java index 799e4493652..75e1d34ba63 100644 --- a/plugins/network-elements/cisco-vnmc/src/com/cloud/network/element/CiscoVnmcElement.java +++ b/plugins/network-elements/cisco-vnmc/src/com/cloud/network/element/CiscoVnmcElement.java @@ -359,8 +359,8 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro } if (outsideIp == null) { // none available, acquire one try { - Account caller = UserContext.current().getCaller(); - long callerUserId = UserContext.current().getCallerUserId(); + Account caller = UserContext.current().getCallingAccount(); + long callerUserId = UserContext.current().getCallingUserId(); outsideIp = _networkMgr.allocateIp(owner, false, caller, callerUserId, zone); } catch (ResourceAllocationException e) { s_logger.error("Unable to allocate additional public Ip address. Exception details " + e); diff --git a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java index 51567a82781..dc3e134a968 100644 --- a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java +++ b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java @@ -667,7 +667,7 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements } catch (NetworkRuleConflictException e) { s_logger.warn("Failed to create LB rule, not continuing with ELB deployment"); if (newIp) { - releaseIp(ipId, UserContext.current().getCallerUserId(), account); + releaseIp(ipId, UserContext.current().getCallingUserId(), account); } throw e; } @@ -681,7 +681,7 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements if (elbVm == null) { s_logger.warn("Failed to deploy a new ELB vm for ip " + ipAddr + " in network " + network + "lb name=" + lb.getName()); if (newIp) - releaseIp(ipId, UserContext.current().getCallerUserId(), account); + releaseIp(ipId, UserContext.current().getCallingUserId(), account); } } diff --git a/plugins/network-elements/f5/src/com/cloud/api/commands/AddF5LoadBalancerCmd.java b/plugins/network-elements/f5/src/com/cloud/api/commands/AddF5LoadBalancerCmd.java index 1670351c55d..2ec641f561c 100644 --- a/plugins/network-elements/f5/src/com/cloud/api/commands/AddF5LoadBalancerCmd.java +++ b/plugins/network-elements/f5/src/com/cloud/api/commands/AddF5LoadBalancerCmd.java @@ -127,6 +127,6 @@ public class AddF5LoadBalancerCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } } diff --git a/plugins/network-elements/f5/src/com/cloud/api/commands/ConfigureF5LoadBalancerCmd.java b/plugins/network-elements/f5/src/com/cloud/api/commands/ConfigureF5LoadBalancerCmd.java index 209a25845cb..ec4c809e104 100644 --- a/plugins/network-elements/f5/src/com/cloud/api/commands/ConfigureF5LoadBalancerCmd.java +++ b/plugins/network-elements/f5/src/com/cloud/api/commands/ConfigureF5LoadBalancerCmd.java @@ -105,6 +105,6 @@ public class ConfigureF5LoadBalancerCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } } diff --git a/plugins/network-elements/f5/src/com/cloud/api/commands/DeleteF5LoadBalancerCmd.java b/plugins/network-elements/f5/src/com/cloud/api/commands/DeleteF5LoadBalancerCmd.java index 691643d1370..d43e24f796b 100644 --- a/plugins/network-elements/f5/src/com/cloud/api/commands/DeleteF5LoadBalancerCmd.java +++ b/plugins/network-elements/f5/src/com/cloud/api/commands/DeleteF5LoadBalancerCmd.java @@ -102,6 +102,6 @@ public class DeleteF5LoadBalancerCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } } diff --git a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java index 1afb00822b6..d3fd686bad9 100644 --- a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java +++ b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java @@ -91,7 +91,7 @@ public class InternalLBVMServiceTest extends TestCase { Mockito.when(_accountMgr.getSystemUser()).thenReturn(new UserVO(1)); Mockito.when(_accountMgr.getSystemAccount()).thenReturn(new AccountVO(2)); Mockito.when(_accountDao.findByIdIncludingRemoved(Mockito.anyLong())).thenReturn(new AccountVO(2)); - UserContext.registerContext(_accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount(), null, false); + UserContext.register(_accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount(), null, false); DomainRouterVO validVm = new DomainRouterVO(validVmId,off.getId(),1,"alena",1,HypervisorType.XenServer,1,1,1, diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddSrxFirewallCmd.java b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddSrxFirewallCmd.java index f5bb037ca00..ff01899c7e3 100644 --- a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddSrxFirewallCmd.java +++ b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddSrxFirewallCmd.java @@ -130,6 +130,6 @@ public class AddSrxFirewallCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } } diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java index 9bffee1f85c..f61c3e8911b 100644 --- a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java +++ b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java @@ -109,6 +109,6 @@ public class ConfigureSrxFirewallCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } } diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteSrxFirewallCmd.java b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteSrxFirewallCmd.java index ce804a71cd5..51347308126 100644 --- a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteSrxFirewallCmd.java +++ b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteSrxFirewallCmd.java @@ -100,6 +100,6 @@ public class DeleteSrxFirewallCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } } diff --git a/plugins/network-elements/netscaler/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java b/plugins/network-elements/netscaler/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java index e4327b4348c..8f1da5a23cd 100644 --- a/plugins/network-elements/netscaler/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java +++ b/plugins/network-elements/netscaler/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java @@ -143,6 +143,6 @@ public class AddNetscalerLoadBalancerCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } } diff --git a/plugins/network-elements/netscaler/src/com/cloud/api/commands/ConfigureNetscalerLoadBalancerCmd.java b/plugins/network-elements/netscaler/src/com/cloud/api/commands/ConfigureNetscalerLoadBalancerCmd.java index a04a48ded95..3f36ec8440e 100644 --- a/plugins/network-elements/netscaler/src/com/cloud/api/commands/ConfigureNetscalerLoadBalancerCmd.java +++ b/plugins/network-elements/netscaler/src/com/cloud/api/commands/ConfigureNetscalerLoadBalancerCmd.java @@ -129,6 +129,6 @@ public class ConfigureNetscalerLoadBalancerCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } } diff --git a/plugins/network-elements/netscaler/src/com/cloud/api/commands/DeleteNetscalerLoadBalancerCmd.java b/plugins/network-elements/netscaler/src/com/cloud/api/commands/DeleteNetscalerLoadBalancerCmd.java index 76f0273aecc..51b8f66a3e9 100644 --- a/plugins/network-elements/netscaler/src/com/cloud/api/commands/DeleteNetscalerLoadBalancerCmd.java +++ b/plugins/network-elements/netscaler/src/com/cloud/api/commands/DeleteNetscalerLoadBalancerCmd.java @@ -100,6 +100,6 @@ public class DeleteNetscalerLoadBalancerCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } } diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/AddNiciraNvpDeviceCmd.java b/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/AddNiciraNvpDeviceCmd.java index 5b2dacfe00f..bb8e1e18edc 100644 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/AddNiciraNvpDeviceCmd.java +++ b/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/AddNiciraNvpDeviceCmd.java @@ -122,7 +122,7 @@ public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } @Override diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/DeleteNiciraNvpDeviceCmd.java b/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/DeleteNiciraNvpDeviceCmd.java index 9ba1c836a98..bc20d8e8901 100755 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/DeleteNiciraNvpDeviceCmd.java +++ b/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/DeleteNiciraNvpDeviceCmd.java @@ -90,7 +90,7 @@ public class DeleteNiciraNvpDeviceCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - return UserContext.current().getCaller().getId(); + return UserContext.current().getCallingAccount().getId(); } @Override diff --git a/plugins/network-elements/ovs/src/com/cloud/network/guru/OvsGuestNetworkGuru.java b/plugins/network-elements/ovs/src/com/cloud/network/guru/OvsGuestNetworkGuru.java index 781b4b9b2f2..8df8cd27831 100644 --- a/plugins/network-elements/ovs/src/com/cloud/network/guru/OvsGuestNetworkGuru.java +++ b/plugins/network-elements/ovs/src/com/cloud/network/guru/OvsGuestNetworkGuru.java @@ -99,7 +99,7 @@ public class OvsGuestNetworkGuru extends GuestNetworkGuru { throw new InsufficientVirtualNetworkCapcityException("Unable to allocate vnet as a part of network " + network + " implement ", DataCenter.class, dcId); } implemented.setBroadcastUri(BroadcastDomainType.Vswitch.toUri(vnet)); - ActionEventUtils.onCompletedActionEvent(UserContext.current().getCallerUserId(), network.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_ASSIGN, "Assigned Zone Vlan: " + vnet + " Network Id: " + network.getId(), 0); + ActionEventUtils.onCompletedActionEvent(UserContext.current().getCallingUserId(), network.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_ASSIGN, "Assigned Zone Vlan: " + vnet + " Network Id: " + network.getId(), 0); } else { implemented.setBroadcastUri(network.getBroadcastUri()); } diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/server/src/com/cloud/agent/manager/AgentManagerImpl.java index 71ca88d3229..ddaf1b3f401 100755 --- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java @@ -105,6 +105,7 @@ import com.cloud.storage.dao.VolumeDao; import com.cloud.storage.resource.DummySecondaryStorageResource; import com.cloud.storage.secondary.SecondaryStorageVmManager; import com.cloud.user.AccountManager; +import com.cloud.user.UserContext; import com.cloud.utils.ActionDelegate; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; @@ -1175,10 +1176,16 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl @Override public void run() { + try { + UserContext.registerOnceOnly(); + } catch (Exception e) { + s_logger.error("Unable to register context", e); + return; + } _request.logD("Processing the first command "); StartupCommand[] startups = new StartupCommand[_cmds.length]; for (int i = 0; i < _cmds.length; i++) { - startups[i] = (StartupCommand) _cmds[i]; + startups[i] = (StartupCommand)_cmds[i]; } AgentAttache attache = handleConnectedAgent(_link, startups, _request); diff --git a/server/src/com/cloud/api/ApiAsyncJobDispatcher.java b/server/src/com/cloud/api/ApiAsyncJobDispatcher.java index 15f245c5bea..1705e8606d0 100644 --- a/server/src/com/cloud/api/ApiAsyncJobDispatcher.java +++ b/server/src/com/cloud/api/ApiAsyncJobDispatcher.java @@ -87,7 +87,7 @@ public class ApiAsyncJobDispatcher extends AdapterBase implements AsyncJobDispat accountObject = _accountDao.findById(Long.parseLong(acctIdStr)); } - UserContext.registerContext(userId, accountObject, null, false); + UserContext.register(userId, accountObject, "job-" + job.getShortUuid(), false); try { // dispatch could ultimately queue the job _dispatcher.dispatch(cmdObj, params); @@ -95,7 +95,7 @@ public class ApiAsyncJobDispatcher extends AdapterBase implements AsyncJobDispat // serialize this to the async job table _asyncJobMgr.completeAsyncJob(job.getId(), AsyncJobConstants.STATUS_SUCCEEDED, 0, cmdObj.getResponseObject()); } finally { - UserContext.unregisterContext(); + UserContext.unregister(); } } catch(Throwable e) { String errorMsg = null; diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java index 68a7481c562..7df17d32e11 100755 --- a/server/src/com/cloud/api/ApiDispatcher.java +++ b/server/src/com/cloud/api/ApiDispatcher.java @@ -96,15 +96,11 @@ public class ApiDispatcher { public void dispatchCreateCmd(BaseAsyncCreateCmd cmd, Map params) throws Exception { processParameters(cmd, params); - - UserContext ctx = UserContext.current(); - ctx.setAccountId(cmd.getEntityOwnerId()); - cmd.create(); - + cmd.create(); } private void doAccessChecks(BaseCmd cmd, Map entitiesToAccess) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Account owner = _accountMgr.getActiveAccountById(cmd.getEntityOwnerId()); if(cmd instanceof BaseAsyncCreateCmd) { @@ -129,7 +125,6 @@ public class ApiDispatcher { public void dispatch(BaseCmd cmd, Map params) throws Exception { processParameters(cmd, params); UserContext ctx = UserContext.current(); - ctx.setAccountId(cmd.getEntityOwnerId()); if (cmd instanceof BaseAsyncCmd) { diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index b83b343cb62..5d594d43deb 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -711,7 +711,7 @@ public class ApiResponseHelper implements ResponseGenerator { } // show this info to admin only - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (account.getType() == Account.ACCOUNT_TYPE_ADMIN) { VlanVO vl = ApiDBUtils.findVlanById(ipAddr.getVlanId()); if (vl != null) { @@ -1287,7 +1287,7 @@ public class ApiResponseHelper implements ResponseGenerator { response.setOsTypeName(os.getDisplayName()); } response.setDetails(result.getDetails()); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); if (result.getFormat() == ImageFormat.ISO) { // Templates are always bootable response.setBootable(result.isBootable()); @@ -1380,7 +1380,7 @@ public class ApiResponseHelper implements ResponseGenerator { populateAccount(templateResponse, account.getId()); populateDomain(templateResponse, account.getDomainId()); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); boolean isAdmin = false; if (BaseCmd.isAdmin(caller.getType())) { isAdmin = true; @@ -1472,7 +1472,7 @@ public class ApiResponseHelper implements ResponseGenerator { } boolean isAdmin = false; - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); if ((caller == null) || BaseCmd.isAdmin(caller.getType())) { isAdmin = true; } @@ -1747,7 +1747,7 @@ public class ApiResponseHelper implements ResponseGenerator { populateAccount(isoResponse, account.getId()); populateDomain(isoResponse, account.getDomainId()); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); boolean isAdmin = false; if ((caller == null) || BaseCmd.isAdmin(caller.getType())) { isAdmin = true; @@ -2360,7 +2360,7 @@ public class ApiResponseHelper implements ResponseGenerator { response.setReservedIpRange(reservation); //return vlan information only to Root admin - if (network.getBroadcastUri() != null && UserContext.current().getCaller().getType() == Account.ACCOUNT_TYPE_ADMIN) { + if (network.getBroadcastUri() != null && UserContext.current().getCallingAccount().getType() == Account.ACCOUNT_TYPE_ADMIN) { String broadcastUri = network.getBroadcastUri().toString(); response.setBroadcastUri(broadcastUri); String vlan="N/A"; diff --git a/server/src/com/cloud/api/ApiSerializerHelper.java b/server/src/com/cloud/api/ApiSerializerHelper.java index 97faa19accb..e65d5e7e8da 100644 --- a/server/src/com/cloud/api/ApiSerializerHelper.java +++ b/server/src/com/cloud/api/ApiSerializerHelper.java @@ -16,11 +16,12 @@ // under the License. package com.cloud.api; -import org.apache.cloudstack.api.ResponseObject; import org.apache.log4j.Logger; import com.google.gson.Gson; +import org.apache.cloudstack.api.ResponseObject; + public class ApiSerializerHelper { public static final Logger s_logger = Logger.getLogger(ApiSerializerHelper.class.getName()); public static String token = "/"; diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java index 28d79f0cfba..b4adf746794 100755 --- a/server/src/com/cloud/api/ApiServer.java +++ b/server/src/com/cloud/api/ApiServer.java @@ -176,7 +176,6 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer @Inject private final RegionManager _regionMgr = null; private static int _workerCount = 0; - private static ApiServer s_instance = null; private static final DateFormat _dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); private static Map> _apiNameCmdClassMap = new HashMap>(); @@ -187,16 +186,11 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer @PostConstruct void initComponent() { - s_instance = this; - } - - public static ApiServer getInstance() { - return s_instance; + UserContext.init(_entityMgr); } @Override - public boolean configure(String name, Map params) - throws ConfigurationException { + public boolean configure(String name, Map params) throws ConfigurationException { init(); return true; } @@ -302,7 +296,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer try { // always trust commands from API port, user context will always be UID_SYSTEM/ACCOUNT_ID_SYSTEM - UserContext.registerContext(_accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount(), null, true); + UserContext.register(_accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount(), null, true); sb.insert(0, "(userId=" + User.UID_SYSTEM + " accountId=" + Account.ACCOUNT_ID_SYSTEM + " sessionId=" + null + ") "); String responseText = handleRequest(parameterMap, responseType, sb); sb.append(" 200 " + ((responseText == null) ? 0 : responseText.length())); @@ -319,7 +313,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer } } finally { s_accessLogger.info(sb.toString()); - UserContext.unregisterContext(); + UserContext.unregister(); } } @@ -416,7 +410,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer catch (InsufficientCapacityException ex){ s_logger.info(ex.getMessage()); String errorMsg = ex.getMessage(); - if (UserContext.current().getCaller().getType() != Account.ACCOUNT_TYPE_ADMIN){ + if (UserContext.current().getCallingAccount().getType() != Account.ACCOUNT_TYPE_ADMIN){ // hide internal details to non-admin user for security reason errorMsg = BaseCmd.USER_ERROR_MESSAGE; @@ -426,7 +420,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer catch (ResourceAllocationException ex){ s_logger.info(ex.getMessage()); String errorMsg = ex.getMessage(); - if (UserContext.current().getCaller().getType() != Account.ACCOUNT_TYPE_ADMIN){ + if (UserContext.current().getCallingAccount().getType() != Account.ACCOUNT_TYPE_ADMIN){ // hide internal details to non-admin user for security reason errorMsg = BaseCmd.USER_ERROR_MESSAGE; } @@ -435,7 +429,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer catch (ResourceUnavailableException ex){ s_logger.info(ex.getMessage()); String errorMsg = ex.getMessage(); - if (UserContext.current().getCaller().getType() != Account.ACCOUNT_TYPE_ADMIN){ + if (UserContext.current().getCallingAccount().getType() != Account.ACCOUNT_TYPE_ADMIN){ // hide internal details to non-admin user for security reason errorMsg = BaseCmd.USER_ERROR_MESSAGE; } @@ -448,7 +442,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer catch (Exception ex){ s_logger.error("unhandled exception executing api command: " + ((command == null) ? "null" : command[0]), ex); String errorMsg = ex.getMessage(); - if (UserContext.current().getCaller().getType() != Account.ACCOUNT_TYPE_ADMIN){ + if (UserContext.current().getCallingAccount().getType() != Account.ACCOUNT_TYPE_ADMIN){ // hide internal details to non-admin user for security reason errorMsg = BaseCmd.USER_ERROR_MESSAGE; } @@ -478,8 +472,8 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer private String queueCommand(BaseCmd cmdObj, Map params) throws Exception { UserContext ctx = UserContext.current(); - Long callerUserId = ctx.getCallerUserId(); - Account caller = ctx.getCaller(); + Long callerUserId = ctx.getCallingUserId(); + Account caller = ctx.getCallingAccount(); // Queue command based on Cmd super class: @@ -522,8 +516,6 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer params.put("ctxStartEventId", String.valueOf(startEventId)); - ctx.setAccountId(asyncCmd.getEntityOwnerId()); - Long instanceId = (objectId == null) ? asyncCmd.getInstanceId() : objectId; AsyncJobVO job = new AsyncJobVO(callerUserId, caller.getId(), cmdObj.getClass().getName(), ApiGsonHelper.getBuilder().create().toJson(params), instanceId, @@ -747,8 +739,6 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer return false; } - UserContext.updateContext(user.getId(), account, null); - try{ checkCommandAvailable(user, commandName); } diff --git a/server/src/com/cloud/api/ApiServlet.java b/server/src/com/cloud/api/ApiServlet.java index 7525b61e84a..038a0a1744b 100755 --- a/server/src/com/cloud/api/ApiServlet.java +++ b/server/src/com/cloud/api/ApiServlet.java @@ -31,13 +31,14 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import org.apache.cloudstack.api.ApiErrorCode; -import org.apache.cloudstack.api.BaseCmd; -import org.apache.cloudstack.api.ServerApiException; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.springframework.web.context.support.SpringBeanAutowiringSupport; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.ServerApiException; + import com.cloud.exception.CloudAuthenticationException; import com.cloud.user.Account; import com.cloud.user.AccountService; @@ -58,7 +59,7 @@ public class ApiServlet extends HttpServlet { @Override public void init(ServletConfig config) throws ServletException { - SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext()); + SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext()); } @Override @@ -235,7 +236,6 @@ public class ApiServlet extends HttpServlet { // Initialize an empty context and we will update it after we have verified the request below, // we no longer rely on web-session here, verifyRequest will populate user/account information // if a API key exists - UserContext.registerContext(_accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount(), null, false); Long userId = null; if (!isNew) { @@ -266,7 +266,7 @@ public class ApiServlet extends HttpServlet { writeResponse(resp, serializedResponse, HttpServletResponse.SC_BAD_REQUEST, responseType); return; } - UserContext.updateContext(userId, (Account) accountObj, session.getId()); + UserContext.register(userId, ((Account)accountObj).getId(), session.getId()); } else { // Invalidate the session to ensure we won't allow a request across management server // restarts if the userId was serialized to the stored session @@ -296,8 +296,8 @@ public class ApiServlet extends HttpServlet { * key mechanism updateUserContext(params, session != null ? session.getId() : null); */ - auditTrailSb.insert(0, "(userId=" + UserContext.current().getCallerUserId() + " accountId=" - + UserContext.current().getCaller().getId() + " sessionId=" + (session != null ? session.getId() : null) + ")"); + auditTrailSb.insert(0, "(userId=" + UserContext.current().getCallingUserId() + " accountId=" + + UserContext.current().getCallingAccount().getId() + " sessionId=" + (session != null ? session.getId() : null) + ")"); // Add the HTTP method (GET/POST/PUT/DELETE) as well into the params map. params.put("httpmethod", new String[] { req.getMethod() }); @@ -330,7 +330,7 @@ public class ApiServlet extends HttpServlet { s_logger.debug("===END=== " + StringUtils.cleanString(reqStr)); } // cleanup user context to prevent from being peeked in other request context - UserContext.unregisterContext(); + UserContext.unregister(); } } diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java index 5a25732bca0..6d65ec0cb01 100644 --- a/server/src/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/com/cloud/api/query/QueryManagerImpl.java @@ -268,7 +268,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } private Pair, Integer> searchForUsersInternal(ListUsersCmd cmd) throws PermissionDeniedException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); //TODO: Integrate with ACL checkAccess refactoring Long domainId = cmd.getDomainId(); @@ -372,7 +372,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } private Pair, Integer> searchForEventsInternal(ListEventsCmd cmd) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); Long id = cmd.getId(); @@ -482,7 +482,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } private Pair, Integer> listTagsInternal(ListTagsCmd cmd) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); String key = cmd.getKey(); String value = cmd.getValue(); @@ -561,7 +561,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { String name = cmd.getGroupName(); String keyword = cmd.getKeyword(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); Ternary domainIdRecursiveListProject = new Ternary( @@ -613,7 +613,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } private Pair, Integer> searchForUserVMsInternal(ListVMsCmd cmd) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); String hypervisor = cmd.getHypervisor(); boolean listAll = cmd.listAll(); @@ -877,7 +877,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } private Pair, Integer> searchForSecurityGroupsInternal(ListSecurityGroupsCmd cmd) throws PermissionDeniedException, InvalidParameterValueException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long instanceId = cmd.getVirtualMachineId(); String securityGroup = cmd.getSecurityGroupName(); Long id = cmd.getId(); @@ -1010,7 +1010,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { String name, String state, Long zoneId, Long podId, Long hostId, String keyword, Long networkId, Long vpcId, Boolean forVpc, String role, String zoneType) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); Ternary domainIdRecursiveListProject = new Ternary( @@ -1149,7 +1149,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { boolean isRecursive = cmd.isRecursive(); Map tags = cmd.getTags(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long accountId = null; String path = null; @@ -1302,7 +1302,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { boolean isRecursive = cmd.isRecursive(); boolean listAll = cmd.listAll(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); Ternary domainIdRecursiveListProject = new Ternary(domainId, isRecursive, null); @@ -1364,7 +1364,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { Long pageSizeVal = cmd.getPageSizeVal(); //long projectId, String accountName, String role, Long startIndex, Long pageSizeVal) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); //check that the project exists Project project = _projectDao.findById(projectId); @@ -1418,7 +1418,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { public Pair, Integer> searchForServersInternal(ListHostsCmd cmd) { - Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), cmd.getZoneId()); + Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCallingAccount(), cmd.getZoneId()); String zoneType = cmd.getZoneType(); Object name = cmd.getHostName(); Object type = cmd.getType(); @@ -1535,7 +1535,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { private Pair, Integer> searchForVolumesInternal(ListVolumesCmd cmd) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); Long id = cmd.getId(); @@ -1675,7 +1675,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { private Pair, Integer> searchForAccountsInternal(ListAccountsCmd cmd) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long domainId = cmd.getDomainId(); Long accountId = cmd.getId(); String accountName = cmd.getSearchName(); @@ -1803,7 +1803,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { private Pair, Integer> searchForAsyncJobsInternal(ListAsyncJobsCmd cmd) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); @@ -1882,7 +1882,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { private Pair, Integer> searchForStoragePoolsInternal(ListStoragePoolsCmd cmd) { - Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), cmd.getZoneId()); + Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCallingAccount(), cmd.getZoneId()); String zoneType = cmd.getZoneType(); Object id = cmd.getId(); Object name = cmd.getStoragePoolName(); @@ -1991,7 +1991,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { SearchCriteria sc = _diskOfferingJoinDao.createSearchCriteria(); - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); Object name = cmd.getDiskOfferingName(); Object id = cmd.getId(); Object keyword = cmd.getKeyword(); @@ -2105,7 +2105,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { Filter searchFilter = new Filter(ServiceOfferingJoinVO.class, "sortKey", isAscending, cmd.getStartIndex(), cmd.getPageSizeVal()); SearchCriteria sc = _srvOfferingJoinDao.createSearchCriteria(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Object name = cmd.getServiceOfferingName(); Object id = cmd.getId(); Object keyword = cmd.getKeyword(); @@ -2227,7 +2227,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { private Pair, Integer> listDataCentersInternal(ListZonesByCmd cmd) { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); Long domainId = cmd.getDomainId(); Long id = cmd.getId(); String keyword = cmd.getKeyword(); @@ -2385,7 +2385,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { public Pair, Integer> listAffinityGroupsInternal(Long affinityGroupId, String affinityGroupName, String affinityGroupType, Long vmId, Long startIndex, Long pageSize) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long accountId = caller.getAccountId(); Long domainId = caller.getDomainId(); diff --git a/server/src/com/cloud/api/query/ViewResponseHelper.java b/server/src/com/cloud/api/query/ViewResponseHelper.java index 827ae7b7a66..b94dccf2f82 100644 --- a/server/src/com/cloud/api/query/ViewResponseHelper.java +++ b/server/src/com/cloud/api/query/ViewResponseHelper.java @@ -115,7 +115,7 @@ public class ViewResponseHelper { } public static List createUserVmResponse(String objectName, EnumSet details, UserVmJoinVO... userVms) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Hashtable vmDataList = new Hashtable(); // Initialise the vmdatalist with the input data @@ -136,7 +136,7 @@ public class ViewResponseHelper { } public static List createDomainRouterResponse(DomainRouterJoinVO... routers) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Hashtable vrDataList = new Hashtable(); // Initialise the vrdatalist with the input data for (DomainRouterJoinVO vr : routers) { @@ -156,7 +156,7 @@ public class ViewResponseHelper { public static List createSecurityGroupResponses(List securityGroups) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Hashtable vrDataList = new Hashtable(); // Initialise the vrdatalist with the input data for (SecurityGroupJoinVO vr : securityGroups) { diff --git a/server/src/com/cloud/api/query/dao/DataCenterJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/DataCenterJoinDaoImpl.java index 4c8b545f343..5256c2a9ac3 100644 --- a/server/src/com/cloud/api/query/dao/DataCenterJoinDaoImpl.java +++ b/server/src/com/cloud/api/query/dao/DataCenterJoinDaoImpl.java @@ -56,7 +56,7 @@ public class DataCenterJoinDaoImpl extends GenericDaoBase implem @Override public VolumeResponse newVolumeResponse(VolumeJoinVO volume) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); VolumeResponse volResponse = new VolumeResponse(); volResponse.setId(volume.getUuid()); diff --git a/server/src/com/cloud/async/AsyncJobManagerImpl.java b/server/src/com/cloud/async/AsyncJobManagerImpl.java index cf5cc70431d..f17df5db262 100644 --- a/server/src/com/cloud/async/AsyncJobManagerImpl.java +++ b/server/src/com/cloud/async/AsyncJobManagerImpl.java @@ -400,7 +400,7 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, @Override public AsyncJob queryAsyncJobResult(QueryAsyncJobResultCmd cmd) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); AsyncJobVO job = _jobDao.findById(cmd.getId()); if (job == null) { diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 779ef4812c9..07c43de389d 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -564,7 +564,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati @Override @ActionEvent(eventType = EventTypes.EVENT_CONFIGURATION_VALUE_EDIT, eventDescription = "updating configuration") public Configuration updateConfiguration(UpdateCfgCmd cmd) throws InvalidParameterValueException { - Long userId = UserContext.current().getCallerUserId(); + Long userId = UserContext.current().getCallingUserId(); String name = cmd.getCfgName(); String value = cmd.getValue(); Long zoneId = cmd.getZoneId(); @@ -1112,7 +1112,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati @Override public Pod createPod(long zoneId, String name, String startIp, String endIp, String gateway, String netmask, String allocationState) { String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask); - Long userId = UserContext.current().getCallerUserId(); + Long userId = UserContext.current().getCallingUserId(); if (allocationState == null) { allocationState = Grouping.AllocationState.Enabled.toString(); @@ -1131,7 +1131,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // Check if zone is disabled DataCenterVO zone = _zoneDao.findById(zoneId); - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) { throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId); } @@ -1387,7 +1387,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati Transaction txn = Transaction.currentTxn(); boolean success = false; - Long userId = UserContext.current().getCallerUserId(); + Long userId = UserContext.current().getCallingUserId(); Long zoneId = cmd.getId(); if (userId == null) { @@ -1874,7 +1874,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati @ActionEvent(eventType = EventTypes.EVENT_ZONE_CREATE, eventDescription = "creating zone", async = false) public DataCenter createZone(CreateZoneCmd cmd) { // grab parameters from the command - Long userId = UserContext.current().getCallerUserId(); + Long userId = UserContext.current().getCallingUserId(); String zoneName = cmd.getZoneName(); String dns1 = cmd.getDns1(); String dns2 = cmd.getDns2(); @@ -1928,7 +1928,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati @Override public ServiceOffering createServiceOffering(CreateServiceOfferingCmd cmd) { - Long userId = UserContext.current().getCallerUserId(); + Long userId = UserContext.current().getCallingUserId(); String name = cmd.getServiceOfferingName(); if ((name == null) || (name.length() == 0)) { @@ -2046,7 +2046,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati Long id = cmd.getId(); String name = cmd.getServiceOfferingName(); Integer sortKey = cmd.getSortKey(); - Long userId = UserContext.current().getCallerUserId(); + Long userId = UserContext.current().getCallingUserId(); if (userId == null) { userId = Long.valueOf(User.UID_SYSTEM); @@ -2267,7 +2267,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati public boolean deleteServiceOffering(DeleteServiceOfferingCmd cmd) { Long offeringId = cmd.getId(); - Long userId = UserContext.current().getCallerUserId(); + Long userId = UserContext.current().getCallingUserId(); if (userId == null) { userId = Long.valueOf(User.UID_SYSTEM); @@ -2421,7 +2421,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // Check if zone is enabled - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) { throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId); } @@ -2610,7 +2610,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } // ACL check - checkZoneAccess(UserContext.current().getCaller(), zone); + checkZoneAccess(UserContext.current().getCallingAccount(), zone); //Validate the physical network if (_physicalNetworkDao.findById(physicalNetworkId) == null) { @@ -3136,7 +3136,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati throw new InvalidParameterValueException("Please specify a valid IP range id."); } - return releasePublicIpRange(vlanDbId, UserContext.current().getCallerUserId(), UserContext.current().getCaller()); + return releasePublicIpRange(vlanDbId, UserContext.current().getCallingUserId(), UserContext.current().getCallingAccount()); } @@ -3475,7 +3475,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati throw new InvalidParameterValueException("Please specify a valid IP range id."); } - return deleteVlanAndPublicIpRange(UserContext.current().getCallerUserId(), vlanDbId, UserContext.current().getCaller()); + return deleteVlanAndPublicIpRange(UserContext.current().getCallingUserId(), vlanDbId, UserContext.current().getCallingAccount()); } @Override @@ -4049,7 +4049,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm")); isAscending = (isAscending == null ? true : isAscending); Filter searchFilter = new Filter(NetworkOfferingVO.class, "sortKey", isAscending, cmd.getStartIndex(), cmd.getPageSizeVal()); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); SearchCriteria sc = _networkOfferingDao.createSearchCriteria(); Long id = cmd.getId(); diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index e05780eb1a3..6bd13045632 100755 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -1513,7 +1513,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy if (ip != null && ip.getSystem()) { UserContext ctx = UserContext.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); } diff --git a/server/src/com/cloud/event/ActionEventInterceptor.java b/server/src/com/cloud/event/ActionEventInterceptor.java index 01eefcd72b7..24f704a0770 100644 --- a/server/src/com/cloud/event/ActionEventInterceptor.java +++ b/server/src/com/cloud/event/ActionEventInterceptor.java @@ -37,8 +37,8 @@ public class ActionEventInterceptor implements ComponentMethodInterceptor { boolean async = actionEvent.async(); if(async){ UserContext ctx = UserContext.current(); - long userId = ctx.getCallerUserId(); - long accountId = ctx.getAccountId(); + long userId = ctx.getCallingUserId(); + long accountId = ctx.getCallingAccountId(); long startEventId = ctx.getStartEventId(); String eventDescription = actionEvent.eventDescription(); if(ctx.getEventDetails() != null){ @@ -55,8 +55,8 @@ public class ActionEventInterceptor implements ComponentMethodInterceptor { ActionEvent actionEvent = method.getAnnotation(ActionEvent.class); if (actionEvent != null) { UserContext ctx = UserContext.current(); - long userId = ctx.getCallerUserId(); - long accountId = ctx.getAccountId(); + long userId = ctx.getCallingUserId(); + long accountId = ctx.getCallingAccountId(); long startEventId = ctx.getStartEventId(); String eventDescription = actionEvent.eventDescription(); if(ctx.getEventDetails() != null){ @@ -77,8 +77,8 @@ public class ActionEventInterceptor implements ComponentMethodInterceptor { ActionEvent actionEvent = method.getAnnotation(ActionEvent.class); if (actionEvent != null) { UserContext ctx = UserContext.current(); - long userId = ctx.getCallerUserId(); - long accountId = ctx.getAccountId(); + long userId = ctx.getCallingUserId(); + long accountId = ctx.getCallingAccountId(); long startEventId = ctx.getStartEventId(); String eventDescription = actionEvent.eventDescription(); if(ctx.getEventDetails() != null){ diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 13a93f0a655..32d2e9ca0cc 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -715,8 +715,8 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L private IpAddress allocateIP(Account ipOwner, boolean isSystem, long zoneId) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { - Account caller = UserContext.current().getCaller(); - long callerUserId = UserContext.current().getCallerUserId(); + Account caller = UserContext.current().getCallingAccount(); + long callerUserId = UserContext.current().getCallingUserId(); // check permissions _accountMgr.checkAccess(caller, null, false, ipOwner); @@ -873,7 +873,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L public IPAddressVO associateIPToGuestNetwork(long ipId, long networkId, boolean releaseOnFailure) throws ResourceAllocationException, ResourceUnavailableException, InsufficientAddressCapacityException, ConcurrentOperationException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Account owner = null; IPAddressVO ipToAssoc = _ipAddressDao.findById(ipId); @@ -887,7 +887,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L if (zone.getNetworkType() == NetworkType.Advanced) { if (network.getGuestType() == Network.GuestType.Shared) { if (isSharedNetworkOfferingWithServices(network.getNetworkOfferingId())) { - _accountMgr.checkAccess(UserContext.current().getCaller(), AccessType.UseNetwork, false, network); + _accountMgr.checkAccess(UserContext.current().getCallingAccount(), AccessType.UseNetwork, false, network); } else { throw new InvalidParameterValueException("IP can be associated with guest network of 'shared' type only if " + "network services Source Nat, Static Nat, Port Forwarding, Load balancing, firewall are enabled in the network"); @@ -1001,7 +1001,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L throws ResourceAllocationException, ResourceUnavailableException, InsufficientAddressCapacityException, ConcurrentOperationException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Account owner = null; Network network = _networksDao.findById(networkId); @@ -1024,7 +1024,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L if (zone.getNetworkType() == NetworkType.Advanced) { if (network.getGuestType() == Network.GuestType.Shared) { assert (isSharedNetworkOfferingWithServices(network.getNetworkOfferingId())); - _accountMgr.checkAccess(UserContext.current().getCaller(), AccessType.UseNetwork, false, network); + _accountMgr.checkAccess(UserContext.current().getCallingAccount(), AccessType.UseNetwork, false, network); } } else { _accountMgr.checkAccess(caller, null, true, ipToAssoc); @@ -1941,7 +1941,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L // reapply all the firewall/staticNat/lb rules s_logger.debug("Reprogramming network " + network + " as a part of network implement"); - if (!reprogramNetworkRules(network.getId(), UserContext.current().getCaller(), network)) { + if (!reprogramNetworkRules(network.getId(), UserContext.current().getCallingAccount(), network)) { s_logger.warn("Failed to re-program the network as a part of network " + network + " implement"); // see DataCenterVO.java ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId()); @@ -3225,8 +3225,8 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L if ( createNetwork && requiredOfferings.get(0).getIsPersistent() ) { DataCenter zone = _dcDao.findById(zoneId); DeployDestination dest = new DeployDestination(zone, null, null, null); - Account callerAccount = UserContext.current().getCaller(); - UserVO callerUser = _userDao.findById(UserContext.current().getCallerUserId()); + Account callerAccount = UserContext.current().getCallingAccount(); + UserVO callerUser = _userDao.findById(UserContext.current().getCallingUserId()); Journal journal = new Journal.LogJournal("Implementing " + guestNetwork, s_logger); ReservationContext context = new ReservationContextImpl(UUID.randomUUID().toString(), journal, callerUser, callerAccount); s_logger.debug("Implementing network " + guestNetwork + " as a part of network provision for persistent network"); @@ -3428,7 +3428,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L public String allocateGuestIP(Account ipOwner, boolean isSystem, long zoneId, Long networkId, String requestedIp) throws InsufficientAddressCapacityException { String ipaddr = null; - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); // check permissions Network network = _networksDao.findById(networkId); @@ -4017,7 +4017,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L if (networkId != null) { if (ip.getSystem()) { UserContext ctx = UserContext.current(); - if (!disassociatePublicIpAddress(ip.getId(), ctx.getCallerUserId(), ctx.getCaller())) { + if (!disassociatePublicIpAddress(ip.getId(), ctx.getCallingUserId(), ctx.getCallingAccount())) { s_logger.warn("Unable to release system ip address id=" + ip.getId()); success = false; } else { diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java index 98992846c4e..910f66fa93f 100755 --- a/server/src/com/cloud/network/NetworkServiceImpl.java +++ b/server/src/com/cloud/network/NetworkServiceImpl.java @@ -18,8 +18,6 @@ package com.cloud.network; import java.net.Inet6Address; import java.net.InetAddress; -import java.net.InetAddress; -import java.net.Inet6Address; import java.net.UnknownHostException; import java.security.InvalidParameterException; import java.sql.PreparedStatement; @@ -39,31 +37,19 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; -import com.cloud.network.vpc.dao.VpcDao; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + import org.apache.cloudstack.acl.ControlledEntity.ACLType; -import org.apache.cloudstack.acl.SecurityChecker; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd; import org.apache.cloudstack.api.command.admin.network.ListDedicatedGuestVlanRangesCmd; import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd; -import org.apache.cloudstack.api.command.user.network.*; -import com.cloud.network.vpc.NetworkACL; -import com.cloud.network.vpc.dao.NetworkACLDao; -import org.apache.cloudstack.acl.ControlledEntity.ACLType; -import org.apache.cloudstack.acl.SecurityChecker.AccessType; -import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd; import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd; import org.apache.cloudstack.api.command.user.network.ListNetworksCmd; import org.apache.cloudstack.api.command.user.network.RestartNetworkCmd; import org.apache.cloudstack.api.command.user.vm.ListNicsCmd; import org.apache.cloudstack.network.element.InternalLoadBalancerElementService; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; -import org.apache.cloudstack.api.command.user.vm.ListNicsCmd; -import org.bouncycastle.util.IPAddress; import com.cloud.api.ApiDBUtils; import com.cloud.configuration.Config; @@ -134,10 +120,13 @@ import com.cloud.network.rules.FirewallRuleVO; import com.cloud.network.rules.PortForwardingRuleVO; import com.cloud.network.rules.RulesManager; import com.cloud.network.rules.dao.PortForwardingRulesDao; +import com.cloud.network.vpc.NetworkACL; import com.cloud.network.vpc.PrivateIpVO; import com.cloud.network.vpc.Vpc; import com.cloud.network.vpc.VpcManager; +import com.cloud.network.vpc.dao.NetworkACLDao; import com.cloud.network.vpc.dao.PrivateIpDao; +import com.cloud.network.vpc.dao.VpcDao; import com.cloud.offering.NetworkOffering; import com.cloud.offerings.NetworkOfferingVO; import com.cloud.offerings.dao.NetworkOfferingDao; @@ -158,7 +147,6 @@ import com.cloud.user.UserContext; import com.cloud.user.UserVO; import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.UserDao; -import com.cloud.utils.AnnotationHelper; import com.cloud.utils.Journal; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; @@ -510,8 +498,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { public IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { - Account caller = UserContext.current().getCaller(); - long callerUserId = UserContext.current().getCallerUserId(); + Account caller = UserContext.current().getCallingAccount(); + long callerUserId = UserContext.current().getCallingUserId(); DataCenter zone = _configMgr.getZone(zoneId); if (networkId != null) { @@ -549,8 +537,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { @ActionEvent(eventType = EventTypes.EVENT_PORTABLE_IP_ASSIGN, eventDescription = "allocating portable public Ip", create = true) public IpAddress allocatePortableIP(Account ipOwner, int regionId, Long zoneId, Long networkId, Long vpcId) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { - Account caller = UserContext.current().getCaller(); - long callerUserId = UserContext.current().getCallerUserId(); + Account caller = UserContext.current().getCallingAccount(); + long callerUserId = UserContext.current().getCallingUserId(); DataCenter zone = _configMgr.getZone(zoneId); if ((networkId == null && vpcId == null) && (networkId != null && vpcId != null)) { @@ -645,7 +633,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { throw new InvalidParameterValueException("Invalid network id is given"); } - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); //check whether the nic belongs to user vm. NicVO nicVO = _nicDao.findById(nicId); @@ -745,7 +733,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { @Override @DB public boolean releaseSecondaryIpFromNic (long ipAddressId) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); boolean success = false; // Verify input parameters @@ -852,8 +840,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { @DB private boolean releaseIpAddressInternal(long ipAddressId) throws InsufficientAddressCapacityException { - Long userId = UserContext.current().getCallerUserId(); - Account caller = UserContext.current().getCaller(); + Long userId = UserContext.current().getCallingUserId(); + Account caller = UserContext.current().getCallingAccount(); // Verify input parameters IPAddressVO ipVO = _ipAddressDao.findById(ipAddressId); @@ -979,7 +967,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { String vlanId = cmd.getVlan(); String name = cmd.getNetworkName(); String displayText = cmd.getDisplayText(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long physicalNetworkId = cmd.getPhysicalNetworkId(); Long zoneId = cmd.getZoneId(); String aclTypeStr = cmd.getAclType(); @@ -1108,8 +1096,6 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { owner = caller; } - UserContext.current().setAccountId(owner.getAccountId()); - boolean ipv4 = true, ipv6 = false; if (startIP != null) { ipv4 = true; @@ -1329,7 +1315,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { return network; } DeployDestination dest = new DeployDestination(zone, null, null, null); - UserVO callerUser = _userDao.findById(UserContext.current().getCallerUserId()); + UserVO callerUser = _userDao.findById(UserContext.current().getCallingUserId()); Journal journal = new Journal.LogJournal("Implementing " + network, s_logger); ReservationContext context = new ReservationContextImpl(UUID.randomUUID().toString(), journal, callerUser, caller); s_logger.debug("Implementing network " + network + " as a part of network provision for persistent network"); @@ -1354,7 +1340,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { String keyword = cmd.getKeyword(); Long zoneId = cmd.getZoneId(); String zoneType = cmd.getZoneType(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long domainId = cmd.getDomainId(); String accountName = cmd.getAccountName(); String guestIpType = cmd.getGuestIpType(); @@ -1744,7 +1730,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { @ActionEvent(eventType = EventTypes.EVENT_NETWORK_DELETE, eventDescription = "deleting network", async = true) public boolean deleteNetwork(long networkId) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); // Verify network id NetworkVO network = _networksDao.findById(networkId); @@ -1768,7 +1754,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { // Perform permission check _accountMgr.checkAccess(caller, null, true, network); - User callerUser = _accountMgr.getActiveUser(UserContext.current().getCallerUserId()); + User callerUser = _accountMgr.getActiveUser(UserContext.current().getCallingUserId()); ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner); return _networkMgr.destroyNetwork(networkId, context); @@ -1781,7 +1767,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { // This method restarts all network elements belonging to the network and re-applies all the rules Long networkId = cmd.getNetworkId(); - User callerUser = _accountMgr.getActiveUser(UserContext.current().getCallerUserId()); + User callerUser = _accountMgr.getActiveUser(UserContext.current().getCallingUserId()); Account callerAccount = _accountMgr.getActiveAccountById(callerUser.getAccountId()); // Check if network exists @@ -3412,7 +3398,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { throw new CloudRuntimeException("Provider is not deletable because there are active networks using this provider, please upgrade these networks to new network offerings"); } - User callerUser = _accountMgr.getActiveUser(UserContext.current().getCallerUserId()); + User callerUser = _accountMgr.getActiveUser(UserContext.current().getCallingUserId()); Account callerAccount = _accountMgr.getActiveAccountById(callerUser.getAccountId()); // shutdown the provider instances ReservationContext context = new ReservationContextImpl(null, null, callerUser, callerAccount); @@ -3904,7 +3890,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { @Override public List listNics(ListNicsCmd cmd) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long nicId = cmd.getNicId(); Long vmId = cmd.getVmId(); diff --git a/server/src/com/cloud/network/NetworkUsageManagerImpl.java b/server/src/com/cloud/network/NetworkUsageManagerImpl.java index 80f898b0d7a..437bdf51111 100755 --- a/server/src/com/cloud/network/NetworkUsageManagerImpl.java +++ b/server/src/com/cloud/network/NetworkUsageManagerImpl.java @@ -188,7 +188,7 @@ public class NetworkUsageManagerImpl extends ManagerBase implements NetworkUsage @Override public boolean deleteTrafficMonitor(DeleteTrafficMonitorCmd cmd) { long hostId = cmd.getId(); - User caller = _accountMgr.getActiveUser(UserContext.current().getCallerUserId()); + User caller = _accountMgr.getActiveUser(UserContext.current().getCallingUserId()); HostVO trafficMonitor = _hostDao.findById(hostId); if (trafficMonitor == null) { throw new InvalidParameterValueException("Could not find an traffic monitor with ID: " + hostId); diff --git a/server/src/com/cloud/network/as/AutoScaleManagerImpl.java b/server/src/com/cloud/network/as/AutoScaleManagerImpl.java index 247441e19cc..5dfbc45725e 100644 --- a/server/src/com/cloud/network/as/AutoScaleManagerImpl.java +++ b/server/src/com/cloud/network/as/AutoScaleManagerImpl.java @@ -306,7 +306,7 @@ public class AutoScaleManagerImpl extends ManagerBase implements AutoScale public AutoScaleVmProfile createAutoScaleVmProfile(CreateAutoScaleVmProfileCmd cmd) { Account owner = _accountDao.findById(cmd.getAccountId()); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); _accountMgr.checkAccess(caller, null, true, owner); long zoneId = cmd.getZoneId(); @@ -337,7 +337,7 @@ public class AutoScaleManagerImpl extends ManagerBase implements AutoScale ApiDispatcher.processParameters(new DeployVMCmd(), deployParams); if (autoscaleUserId == null) { - autoscaleUserId = UserContext.current().getCallerUserId(); + autoscaleUserId = UserContext.current().getCallingUserId(); } AutoScaleVmProfileVO profileVO = new AutoScaleVmProfileVO(cmd.getZoneId(), cmd.getDomainId(), cmd.getAccountId(), cmd.getServiceOfferingId(), cmd.getTemplateId(), cmd.getOtherDeployParams(), @@ -358,7 +358,7 @@ public class AutoScaleManagerImpl extends ManagerBase implements AutoScale Integer destroyVmGraceperiod = cmd.getDestroyVmGraceperiod(); - AutoScaleVmProfileVO vmProfile = getEntityInDatabase(UserContext.current().getCaller(), "Auto Scale Vm Profile", profileId, _autoScaleVmProfileDao); + AutoScaleVmProfileVO vmProfile = getEntityInDatabase(UserContext.current().getCallingAccount(), "Auto Scale Vm Profile", profileId, _autoScaleVmProfileDao); if (templateId != null) { vmProfile.setTemplateId(templateId); @@ -393,7 +393,7 @@ public class AutoScaleManagerImpl extends ManagerBase implements AutoScale @ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMPROFILE_DELETE, eventDescription = "deleting autoscale vm profile") public boolean deleteAutoScaleVmProfile(long id) { /* Check if entity is in database */ - getEntityInDatabase(UserContext.current().getCaller(), "AutoScale Vm Profile", id, _autoScaleVmProfileDao); + getEntityInDatabase(UserContext.current().getCallingAccount(), "AutoScale Vm Profile", id, _autoScaleVmProfileDao); if (_autoScaleVmGroupDao.isProfileInUse(id)) { throw new InvalidParameterValueException("Cannot delete AutoScale Vm Profile when it is in use by one more vm groups"); } @@ -459,7 +459,7 @@ public class AutoScaleManagerImpl extends ManagerBase implements AutoScale ControlledEntity[] sameOwnerEntities = conditions.toArray(new ControlledEntity[conditions.size() + 1]); sameOwnerEntities[sameOwnerEntities.length - 1] = autoScalePolicyVO; - _accountMgr.checkAccess(UserContext.current().getCaller(), null, true, sameOwnerEntities); + _accountMgr.checkAccess(UserContext.current().getCallingAccount(), null, true, sameOwnerEntities); if (conditionIds.size() != conditions.size()) { // TODO report the condition id which could not be found @@ -516,7 +516,7 @@ public class AutoScaleManagerImpl extends ManagerBase implements AutoScale @ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEPOLICY_DELETE, eventDescription = "deleting autoscale policy") public boolean deleteAutoScalePolicy(long id) { /* Check if entity is in database */ - getEntityInDatabase(UserContext.current().getCaller(), "AutoScale Policy", id, _autoScalePolicyDao); + getEntityInDatabase(UserContext.current().getCallingAccount(), "AutoScale Policy", id, _autoScalePolicyDao); if (_autoScaleVmGroupPolicyMapDao.isAutoScalePolicyInUse(id)) { throw new InvalidParameterValueException("Cannot delete AutoScale Policy when it is in use by one or more AutoScale Vm Groups"); @@ -543,7 +543,7 @@ public class AutoScaleManagerImpl extends ManagerBase implements AutoScale public void checkCallerAccess(String accountName, Long domainId) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Account owner = _accountDao.findActiveAccount(accountName, domainId); if (owner == null) { List idList = new ArrayList(); @@ -573,7 +573,7 @@ public class AutoScaleManagerImpl extends ManagerBase implements AutoScale boolean listAll = cmd.listAll(); long startIndex = cmd.getStartIndex(); long pageSizeVal = cmd.getPageSizeVal(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Ternary domainIdRecursiveListProject = new Ternary(domainId, isRecursive, null); @@ -654,7 +654,7 @@ public class AutoScaleManagerImpl extends ManagerBase implements AutoScale Integer duration = cmd.getDuration(); Integer quietTime = cmd.getQuietTime(); List conditionIds = cmd.getConditionIds(); - AutoScalePolicyVO policy = getEntityInDatabase(UserContext.current().getCaller(), "Auto Scale Policy", policyId, _autoScalePolicyDao); + AutoScalePolicyVO policy = getEntityInDatabase(UserContext.current().getCallingAccount(), "Auto Scale Policy", policyId, _autoScalePolicyDao); if (duration != null) { policy.setDuration(duration); @@ -697,7 +697,7 @@ public class AutoScaleManagerImpl extends ManagerBase implements AutoScale interval = NetUtils.DEFAULT_AUTOSCALE_POLICY_INTERVAL_TIME; } - LoadBalancerVO loadBalancer = getEntityInDatabase(UserContext.current().getCaller(), ApiConstants.LBID, cmd.getLbRuleId(), _lbDao); + LoadBalancerVO loadBalancer = getEntityInDatabase(UserContext.current().getCallingAccount(), ApiConstants.LBID, cmd.getLbRuleId(), _lbDao); Long zoneId = _ipAddressDao.findById(loadBalancer.getSourceIpAddressId()).getDataCenterId(); @@ -749,7 +749,7 @@ public class AutoScaleManagerImpl extends ManagerBase implements AutoScale @DB @ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMGROUP_DELETE, eventDescription = "deleting autoscale vm group") public boolean deleteAutoScaleVmGroup(long id) { - AutoScaleVmGroupVO autoScaleVmGroupVO = getEntityInDatabase(UserContext.current().getCaller(), "AutoScale Vm Group", id, _autoScaleVmGroupDao); + AutoScaleVmGroupVO autoScaleVmGroupVO = getEntityInDatabase(UserContext.current().getCallingAccount(), "AutoScale Vm Group", id, _autoScaleVmGroupDao); if (autoScaleVmGroupVO.getState().equals(AutoScaleVmGroup.State_New)) { /* This condition is for handling failures during creation command */ @@ -880,15 +880,15 @@ public class AutoScaleManagerImpl extends ManagerBase implements AutoScale getAutoScalePolicies("scaledownpolicyid", currentScaleDownPolicyIds, counters, interval, false); policyIds.addAll(currentScaleDownPolicyIds); } - AutoScaleVmProfileVO profileVO = getEntityInDatabase(UserContext.current().getCaller(), ApiConstants.VMPROFILE_ID, vmGroup.getProfileId(), _autoScaleVmProfileDao); + AutoScaleVmProfileVO profileVO = getEntityInDatabase(UserContext.current().getCallingAccount(), ApiConstants.VMPROFILE_ID, vmGroup.getProfileId(), _autoScaleVmProfileDao); - LoadBalancerVO loadBalancer = getEntityInDatabase(UserContext.current().getCaller(), ApiConstants.LBID, vmGroup.getLoadBalancerId(), _lbDao); + LoadBalancerVO loadBalancer = getEntityInDatabase(UserContext.current().getCallingAccount(), ApiConstants.LBID, vmGroup.getLoadBalancerId(), _lbDao); validateAutoScaleCounters(loadBalancer.getNetworkId(), counters, profileVO.getCounterParams()); ControlledEntity[] sameOwnerEntities = policies.toArray(new ControlledEntity[policies.size() + 2]); sameOwnerEntities[sameOwnerEntities.length - 2] = loadBalancer; sameOwnerEntities[sameOwnerEntities.length - 1] = profileVO; - _accountMgr.checkAccess(UserContext.current().getCaller(), null, true, sameOwnerEntities); + _accountMgr.checkAccess(UserContext.current().getCallingAccount(), null, true, sameOwnerEntities); final Transaction txn = Transaction.currentTxn(); txn.start(); @@ -917,7 +917,7 @@ public class AutoScaleManagerImpl extends ManagerBase implements AutoScale List scaleUpPolicyIds = cmd.getScaleUpPolicyIds(); List scaleDownPolicyIds = cmd.getScaleDownPolicyIds(); - AutoScaleVmGroupVO vmGroupVO = getEntityInDatabase(UserContext.current().getCaller(), "AutoScale Vm Group", vmGroupId, _autoScaleVmGroupDao); + AutoScaleVmGroupVO vmGroupVO = getEntityInDatabase(UserContext.current().getCallingAccount(), "AutoScale Vm Group", vmGroupId, _autoScaleVmGroupDao); if (!vmGroupVO.getState().equals(AutoScaleVmGroup.State_Disabled)) { throw new InvalidParameterValueException("An AutoScale Vm Group can be updated only when it is in disabled state"); @@ -947,7 +947,7 @@ public class AutoScaleManagerImpl extends ManagerBase implements AutoScale @DB @ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMGROUP_ENABLE, eventDescription = "enabling autoscale vm group") public AutoScaleVmGroup enableAutoScaleVmGroup(Long id) { - AutoScaleVmGroupVO vmGroup = getEntityInDatabase(UserContext.current().getCaller(), "AutoScale Vm Group", id, _autoScaleVmGroupDao); + AutoScaleVmGroupVO vmGroup = getEntityInDatabase(UserContext.current().getCallingAccount(), "AutoScale Vm Group", id, _autoScaleVmGroupDao); boolean success = false; if (!vmGroup.getState().equals(AutoScaleVmGroup.State_Disabled)) { throw new InvalidParameterValueException("Only a AutoScale Vm Group which is in Disabled state can be enabled."); @@ -974,7 +974,7 @@ public class AutoScaleManagerImpl extends ManagerBase implements AutoScale @ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMGROUP_DISABLE, eventDescription = "disabling autoscale vm group") @DB public AutoScaleVmGroup disableAutoScaleVmGroup(Long id) { - AutoScaleVmGroupVO vmGroup = getEntityInDatabase(UserContext.current().getCaller(), "AutoScale Vm Group", id, _autoScaleVmGroupDao); + AutoScaleVmGroupVO vmGroup = getEntityInDatabase(UserContext.current().getCallingAccount(), "AutoScale Vm Group", id, _autoScaleVmGroupDao); boolean success = false; if (!vmGroup.getState().equals(AutoScaleVmGroup.State_Enabled)) { throw new InvalidParameterValueException("Only a AutoScale Vm Group which is in Enabled state can be disabled."); @@ -1128,7 +1128,7 @@ public class AutoScaleManagerImpl extends ManagerBase implements AutoScale @ActionEvent(eventType = EventTypes.EVENT_CONDITION_DELETE, eventDescription = "condition") public boolean deleteCondition(long conditionId) throws ResourceInUseException { /* Check if entity is in database */ - ConditionVO condition = getEntityInDatabase(UserContext.current().getCaller(), "Condition", conditionId, _conditionDao); + ConditionVO condition = getEntityInDatabase(UserContext.current().getCallingAccount(), "Condition", conditionId, _conditionDao); if (condition == null) { throw new InvalidParameterValueException("Unable to find Condition"); } diff --git a/server/src/com/cloud/network/firewall/FirewallManagerImpl.java b/server/src/com/cloud/network/firewall/FirewallManagerImpl.java index 334a5a108e6..c0595729c44 100644 --- a/server/src/com/cloud/network/firewall/FirewallManagerImpl.java +++ b/server/src/com/cloud/network/firewall/FirewallManagerImpl.java @@ -147,7 +147,7 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService, @Override public FirewallRule createEgressFirewallRule(FirewallRule rule) throws NetworkRuleConflictException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Network network = _networkDao.findById(rule.getNetworkId()); if (network.getGuestType() == Network.GuestType.Shared) { @@ -160,7 +160,7 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService, } public FirewallRule createIngressFirewallRule(FirewallRule rule) throws NetworkRuleConflictException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long sourceIpAddressId = rule.getSourceIpAddressId(); return createFirewallRule(sourceIpAddressId, caller, rule.getXid(), rule.getSourcePortStart(), @@ -241,7 +241,7 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService, Map tags = cmd.getTags(); FirewallRule.TrafficType trafficType = cmd.getTrafficType(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); if (ipId != null) { @@ -687,8 +687,8 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService, @Override public boolean revokeFirewallRule(long ruleId, boolean apply) { - Account caller = UserContext.current().getCaller(); - long userId = UserContext.current().getCallerUserId(); + Account caller = UserContext.current().getCallingAccount(); + long userId = UserContext.current().getCallingUserId(); return revokeFirewallRule(ruleId, apply, caller, userId); } diff --git a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java index 79f85a63c10..862bcc81a8b 100644 --- a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java +++ b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java @@ -139,7 +139,7 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru { } implemented.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vlanTag)); - ActionEventUtils.onCompletedActionEvent(UserContext.current().getCallerUserId(), config.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_ASSIGN, "Assigned Zone Vlan: " + vnet + " Network Id: " + config.getId(), 0); + ActionEventUtils.onCompletedActionEvent(UserContext.current().getCallingUserId(), config.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_ASSIGN, "Assigned Zone Vlan: " + vnet + " Network Id: " + config.getId(), 0); } else { vlanTag = Integer.parseInt(config.getBroadcastUri().getHost()); implemented.setBroadcastUri(config.getBroadcastUri()); diff --git a/server/src/com/cloud/network/guru/GuestNetworkGuru.java b/server/src/com/cloud/network/guru/GuestNetworkGuru.java index dde562e0a36..7fca152923d 100755 --- a/server/src/com/cloud/network/guru/GuestNetworkGuru.java +++ b/server/src/com/cloud/network/guru/GuestNetworkGuru.java @@ -266,7 +266,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur "part of network " + network + " implement ", DataCenter.class, dcId); } implemented.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vnet)); - ActionEventUtils.onCompletedActionEvent(UserContext.current().getCallerUserId(), network.getAccountId(), + ActionEventUtils.onCompletedActionEvent(UserContext.current().getCallingUserId(), network.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_ASSIGN, "Assigned Zone Vlan: " + vnet + " Network Id: " + network.getId(), 0); } else { implemented.setBroadcastUri(network.getBroadcastUri()); @@ -406,7 +406,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur s_logger.debug("Releasing vnet for the network id=" + profile.getId()); _dcDao.releaseVnet(profile.getBroadcastUri().getHost(), profile.getDataCenterId(), profile.getPhysicalNetworkId(), profile.getAccountId(), profile.getReservationId()); - ActionEventUtils.onCompletedActionEvent(UserContext.current().getCallerUserId(), profile.getAccountId(), + ActionEventUtils.onCompletedActionEvent(UserContext.current().getCallingUserId(), profile.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_RELEASE, "Released Zone Vlan: " + profile.getBroadcastUri().getHost() + " for Network: " + profile.getId(), 0); } diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java index f9bbf1f25bb..a091a9eb9ea 100755 --- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java +++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java @@ -526,7 +526,7 @@ public class LoadBalancingRulesManagerImpl extends ManagerBase implements throw new InvalidParameterValueException("Failed: LB rule id: " + cmd.getLbRuleId() + " not present "); } - _accountMgr.checkAccess(caller.getCaller(), null, true, loadBalancer); + _accountMgr.checkAccess(caller.getCallingAccount(), null, true, loadBalancer); if (loadBalancer.getState() == FirewallRule.State.Revoke) { throw new InvalidParameterValueException("Failed: LB rule id: " + cmd.getLbRuleId() + " is in deleting state: "); @@ -586,7 +586,7 @@ public class LoadBalancingRulesManagerImpl extends ManagerBase implements throw new InvalidParameterValueException("Failed: LB rule id: " + cmd.getLbRuleId() + " not present "); } - _accountMgr.checkAccess(caller.getCaller(), null, true, loadBalancer); + _accountMgr.checkAccess(caller.getCallingAccount(), null, true, loadBalancer); if (loadBalancer.getState() == FirewallRule.State.Revoke) { throw new InvalidParameterValueException("Failed: LB rule id: " + cmd.getLbRuleId() @@ -727,7 +727,7 @@ public class LoadBalancingRulesManagerImpl extends ManagerBase implements } long loadBalancerId = loadBalancer.getId(); FirewallRule.State backupState = loadBalancer.getState(); - _accountMgr.checkAccess(caller.getCaller(), null, true, loadBalancer); + _accountMgr.checkAccess(caller.getCallingAccount(), null, true, loadBalancer); if (apply) { if (loadBalancer.getState() == FirewallRule.State.Active) { @@ -785,7 +785,7 @@ public class LoadBalancingRulesManagerImpl extends ManagerBase implements } long loadBalancerId = loadBalancer.getId(); FirewallRule.State backupState = loadBalancer.getState(); - _accountMgr.checkAccess(caller.getCaller(), null, true, loadBalancer); + _accountMgr.checkAccess(caller.getCallingAccount(), null, true, loadBalancer); if (apply) { if (loadBalancer.getState() == FirewallRule.State.Active) { @@ -925,7 +925,7 @@ public class LoadBalancingRulesManagerImpl extends ManagerBase implements @ActionEvent(eventType = EventTypes.EVENT_ASSIGN_TO_LOAD_BALANCER_RULE, eventDescription = "assigning to load balancer", async = true) public boolean assignToLoadBalancer(long loadBalancerId, List instanceIds) { UserContext ctx = UserContext.current(); - Account caller = ctx.getCaller(); + Account caller = ctx.getCallingAccount(); LoadBalancerVO loadBalancer = _lbDao.findById(loadBalancerId); if (loadBalancer == null) { @@ -1053,7 +1053,7 @@ public class LoadBalancingRulesManagerImpl extends ManagerBase implements throw new InvalidParameterException("Invalid load balancer value: " + loadBalancerId); } - _accountMgr.checkAccess(caller.getCaller(), null, true, loadBalancer); + _accountMgr.checkAccess(caller.getCallingAccount(), null, true, loadBalancer); boolean success = false; FirewallRule.State backupState = loadBalancer.getState(); @@ -1151,7 +1151,7 @@ public class LoadBalancingRulesManagerImpl extends ManagerBase implements @ActionEvent(eventType = EventTypes.EVENT_LOAD_BALANCER_DELETE, eventDescription = "deleting load balancer", async = true) public boolean deleteLoadBalancerRule(long loadBalancerId, boolean apply) { UserContext ctx = UserContext.current(); - Account caller = ctx.getCaller(); + Account caller = ctx.getCallingAccount(); LoadBalancerVO rule = _lbDao.findById(loadBalancerId); @@ -1160,7 +1160,7 @@ public class LoadBalancingRulesManagerImpl extends ManagerBase implements } _accountMgr.checkAccess(caller, null, true, rule); - boolean result = deleteLoadBalancerRule(loadBalancerId, apply, caller, ctx.getCallerUserId(), true); + boolean result = deleteLoadBalancerRule(loadBalancerId, apply, caller, ctx.getCallingUserId(), true); if (!result) { throw new CloudRuntimeException("Unable to remove load balancer rule " + loadBalancerId); } @@ -1388,7 +1388,7 @@ public class LoadBalancingRulesManagerImpl extends ManagerBase implements throw ex; } - _accountMgr.checkAccess(caller.getCaller(), null, true, ipAddr); + _accountMgr.checkAccess(caller.getCallingAccount(), null, true, ipAddr); Long networkId = ipAddr.getAssociatedWithNetworkId(); @@ -1402,7 +1402,7 @@ public class LoadBalancingRulesManagerImpl extends ManagerBase implements // verify that lb service is supported by the network isLbServiceSupportedInNetwork(networkId, Scheme.Public); - _firewallMgr.validateFirewallRule(caller.getCaller(), ipAddr, srcPort, srcPort, protocol, + _firewallMgr.validateFirewallRule(caller.getCallingAccount(), ipAddr, srcPort, srcPort, protocol, Purpose.LoadBalancing, FirewallRuleType.User, networkId, null); LoadBalancerVO newRule = new LoadBalancerVO(xId, name, description, @@ -1424,7 +1424,7 @@ public class LoadBalancingRulesManagerImpl extends ManagerBase implements //create rule for all CIDRs if (openFirewall) { - _firewallMgr.createRuleForAllCidrs(sourceIpId, caller.getCaller(), srcPort, + _firewallMgr.createRuleForAllCidrs(sourceIpId, caller.getCallingAccount(), srcPort, srcPort, protocol, null, null, newRule.getId(), networkId); } @@ -1646,7 +1646,7 @@ public class LoadBalancingRulesManagerImpl extends ManagerBase implements if (ip.getSystem()) { s_logger.debug("Releasing system ip address " + lb.getSourceIpAddressId() + " as a part of delete lb rule"); if (!_networkMgr.disassociatePublicIpAddress(lb.getSourceIpAddressId(), UserContext.current() - .getCallerUserId(), UserContext.current().getCaller())) { + .getCallingUserId(), UserContext.current().getCallingAccount())) { s_logger.warn("Unable to release system ip address id=" + lb.getSourceIpAddressId() + " as a part of delete lb rule"); success = false; @@ -1738,7 +1738,7 @@ public class LoadBalancingRulesManagerImpl extends ManagerBase implements @Override @ActionEvent(eventType = EventTypes.EVENT_LOAD_BALANCER_UPDATE, eventDescription = "updating load balancer", async = true) public LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long lbRuleId = cmd.getId(); String name = cmd.getLoadBalancerName(); String description = cmd.getDescription(); @@ -1810,7 +1810,7 @@ public class LoadBalancingRulesManagerImpl extends ManagerBase implements @Override public List listLoadBalancerInstances(ListLoadBalancerRuleInstancesCmd cmd) throws PermissionDeniedException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long loadBalancerId = cmd.getId(); Boolean applied = cmd.isApplied(); @@ -1876,7 +1876,7 @@ public class LoadBalancingRulesManagerImpl extends ManagerBase implements @Override public List searchForLBStickinessPolicies(ListLBStickinessPoliciesCmd cmd) throws PermissionDeniedException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long loadBalancerId = cmd.getLbRuleId(); LoadBalancerVO loadBalancer = _lbDao.findById(loadBalancerId); if (loadBalancer == null) { @@ -1893,7 +1893,7 @@ public class LoadBalancingRulesManagerImpl extends ManagerBase implements @Override public List searchForLBHealthCheckPolicies(ListLBHealthCheckPoliciesCmd cmd) throws PermissionDeniedException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long loadBalancerId = cmd.getLbRuleId(); LoadBalancerVO loadBalancer = _lbDao.findById(loadBalancerId); if (loadBalancer == null) { @@ -1915,7 +1915,7 @@ public class LoadBalancingRulesManagerImpl extends ManagerBase implements Long networkId = cmd.getNetworkId(); Map tags = cmd.getTags(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); Ternary domainIdRecursiveListProject = new Ternary( diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index fd11e8066fe..0f5eff57972 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -432,7 +432,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V public VirtualRouter upgradeRouter(UpgradeRouterCmd cmd) { Long routerId = cmd.getId(); Long serviceOfferingId = cmd.getServiceOfferingId(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); DomainRouterVO router = _routerDao.findById(routerId); if (router == null) { @@ -542,7 +542,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V @ActionEvent(eventType = EventTypes.EVENT_ROUTER_STOP, eventDescription = "stopping router Vm", async = true) public VirtualRouter stopRouter(long routerId, boolean forced) throws ResourceUnavailableException, ConcurrentOperationException { UserContext context = UserContext.current(); - Account account = context.getCaller(); + Account account = context.getCallingAccount(); // verify parameters DomainRouterVO router = _routerDao.findById(routerId); @@ -552,7 +552,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V _accountMgr.checkAccess(account, null, true, router); - UserVO user = _userDao.findById(UserContext.current().getCallerUserId()); + UserVO user = _userDao.findById(UserContext.current().getCallingUserId()); VirtualRouter virtualRouter = stop(router, forced, user, account); if (virtualRouter == null) { @@ -605,7 +605,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V @ActionEvent(eventType = EventTypes.EVENT_ROUTER_REBOOT, eventDescription = "rebooting router Vm", async = true) public VirtualRouter rebootRouter(long routerId, boolean reprogramNetwork) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); // verify parameters DomainRouterVO router = _routerDao.findById(routerId); @@ -622,7 +622,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V DataCenter.class, router.getDataCenterId()); } - UserVO user = _userDao.findById(UserContext.current().getCallerUserId()); + UserVO user = _userDao.findById(UserContext.current().getCallingUserId()); s_logger.debug("Stopping and starting router " + router + " as a part of router reboot"); if (stop(router, false, user, caller) != null) { @@ -1170,8 +1170,6 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V //Ensure router status is update to date before execute this function. The function would try best to recover all routers except MASTER protected void recoverRedundantNetwork(DomainRouterVO masterRouter, DomainRouterVO backupRouter) { - UserContext context = UserContext.current(); - context.setAccountId(1); if (masterRouter.getState() == State.Running && backupRouter.getState() == State.Running) { HostVO masterHost = _hostDao.findById(masterRouter.getHostId()); HostVO backupHost = _hostDao.findById(backupRouter.getHostId()); @@ -1283,42 +1281,49 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V @Override public void run() { - while (true) { - try { - Long networkId = _vrUpdateQueue.take(); - List routers = _routerDao.listByNetworkAndRole(networkId, Role.VIRTUAL_ROUTER); + try { + UserContext.register(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, null); + while (true) { + try { + Long networkId = _vrUpdateQueue.take(); + List routers = _routerDao.listByNetworkAndRole(networkId, Role.VIRTUAL_ROUTER); - if (routers.size() != 2) { - continue; + if (routers.size() != 2) { + continue; + } + /* + * We update the router pair which the lower id router owned by this mgmt server, in order + * to prevent duplicate update of router status from cluster mgmt servers + */ + DomainRouterVO router0 = routers.get(0); + DomainRouterVO router1 = routers.get(1); + DomainRouterVO router = router0; + if ((router0.getId() < router1.getId()) && router0.getHostId() != null) { + router = router0; + } else { + router = router1; + } + if (router.getHostId() == null) { + s_logger.debug("Skip router pair (" + router0.getInstanceName() + "," + router1.getInstanceName() + ") due to can't find host"); + continue; + } + HostVO host = _hostDao.findById(router.getHostId()); + if (host == null || host.getManagementServerId() == null || + host.getManagementServerId() != ManagementServerNode.getManagementServerId()) { + s_logger.debug("Skip router pair (" + router0.getInstanceName() + "," + router1.getInstanceName() + ") due to not belong to this mgmt server"); + continue; + } + updateRoutersRedundantState(routers); + checkDuplicateMaster(routers); + checkSanity(routers); + } catch (Exception ex) { + s_logger.error("Fail to complete the RvRStatusUpdateTask! ", ex); } - /* - * We update the router pair which the lower id router owned by this mgmt server, in order - * to prevent duplicate update of router status from cluster mgmt servers - */ - DomainRouterVO router0 = routers.get(0); - DomainRouterVO router1 = routers.get(1); - DomainRouterVO router = router0; - if ((router0.getId() < router1.getId()) && router0.getHostId() != null) { - router = router0; - } else { - router = router1; - } - if (router.getHostId() == null) { - s_logger.debug("Skip router pair (" + router0.getInstanceName() + "," + router1.getInstanceName() + ") due to can't find host"); - continue; - } - HostVO host = _hostDao.findById(router.getHostId()); - if (host == null || host.getManagementServerId() == null || - host.getManagementServerId() != ManagementServerNode.getManagementServerId()) { - s_logger.debug("Skip router pair (" + router0.getInstanceName() + "," + router1.getInstanceName() + ") due to not belong to this mgmt server"); - continue; - } - updateRoutersRedundantState(routers); - checkDuplicateMaster(routers); - checkSanity(routers); - } catch (Exception ex) { - s_logger.error("Fail to complete the RvRStatusUpdateTask! ", ex); } + } catch (Exception e) { + s_logger.error("Unable to setup the calling context", e); + } finally { + UserContext.unregister(); } } @@ -2778,7 +2783,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V try { if (network.getTrafficType() == TrafficType.Guest && network.getGuestType() == GuestType.Shared) { Pod pod = _podDao.findById(vm.getPodIdToDeployIn()); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List vlanList = _vlanDao.listVlansByNetworkIdAndGateway(network.getId(), nic.getGateway()); List vlanDbIdList = new ArrayList(); for (VlanVO vlan : vlanList) { @@ -2794,7 +2799,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V return false; } //this means we did not create a ip alis on the router. - NicIpAliasVO alias = new NicIpAliasVO(domr_guest_nic.getId(), routerAliasIp, router.getId(), UserContext.current().getAccountId(), network.getDomainId(), nic.getNetworkId(),nic.getGateway(), nic.getNetmask()); + NicIpAliasVO alias = new NicIpAliasVO(domr_guest_nic.getId(), routerAliasIp, router.getId(), UserContext.current().getCallingAccountId(), network.getDomainId(), nic.getNetworkId(),nic.getGateway(), nic.getNetmask()); alias.setAliasCount((routerPublicIP.getIpMacAddress())); _nicIpAliasDao.persist(alias); List ipaliasTo = new ArrayList(); @@ -3053,8 +3058,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V @Override public VirtualRouter startRouter(long routerId, boolean reprogramNetwork) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException { - Account caller = UserContext.current().getCaller(); - User callerUser = _accountMgr.getActiveUser(UserContext.current().getCallerUserId()); + Account caller = UserContext.current().getCallingAccount(); + User callerUser = _accountMgr.getActiveUser(UserContext.current().getCallingUserId()); // verify parameters DomainRouterVO router = _routerDao.findById(routerId); @@ -3090,7 +3095,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V return router; } - UserVO user = _userDao.findById(UserContext.current().getCallerUserId()); + UserVO user = _userDao.findById(UserContext.current().getCallingUserId()); Map params = new HashMap(); if (reprogramNetwork) { params.put(Param.ReProgramGuestNetworks, true); @@ -3832,8 +3837,6 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V @Override public void processConnect(HostVO host, StartupCommand cmd, boolean forRebalance) throws ConnectionException { - UserContext context = UserContext.current(); - context.setAccountId(1); List routers = _routerDao.listIsolatedByHostId(host.getId()); for (DomainRouterVO router : routers) { if (router.isStopPending()) { diff --git a/server/src/com/cloud/network/rules/RulesManagerImpl.java b/server/src/com/cloud/network/rules/RulesManagerImpl.java index dd5f99ba574..3455e9c91c0 100755 --- a/server/src/com/cloud/network/rules/RulesManagerImpl.java +++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java @@ -190,7 +190,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules public PortForwardingRule createPortForwardingRule(PortForwardingRule rule, Long vmId, Ip vmIp, boolean openFirewall) throws NetworkRuleConflictException { UserContext ctx = UserContext.current(); - Account caller = ctx.getCaller(); + Account caller = ctx.getCallingAccount(); Long ipAddrId = rule.getSourceIpAddressId(); @@ -352,7 +352,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules @DB @ActionEvent(eventType = EventTypes.EVENT_NET_RULE_ADD, eventDescription = "creating static nat rule", create = true) public StaticNatRule createStaticNatRule(StaticNatRule rule, boolean openFirewall) throws NetworkRuleConflictException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long ipAddrId = rule.getSourceIpAddressId(); @@ -434,7 +434,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules private boolean enableStaticNat(long ipId, long vmId, long networkId, boolean isSystemVm, String vmGuestIp) throws NetworkRuleConflictException, ResourceUnavailableException { UserContext ctx = UserContext.current(); - Account caller = ctx.getCaller(); + Account caller = ctx.getCallingAccount(); UserContext.current().setEventDetails("Ip Id: " + ipId); // Verify input parameters @@ -569,7 +569,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules // Verify ip address parameter // checking vm id is not sufficient, check for the vm ip - isIpReadyForStaticNat(vmId, ipAddress, dstIp, caller, ctx.getCallerUserId()); + isIpReadyForStaticNat(vmId, ipAddress, dstIp, caller, ctx.getCallingUserId()); } ipAddress.setOneToOneNat(true); @@ -656,7 +656,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules @ActionEvent(eventType = EventTypes.EVENT_NET_RULE_DELETE, eventDescription = "revoking forwarding rule", async = true) public boolean revokePortForwardingRule(long ruleId, boolean apply) { UserContext ctx = UserContext.current(); - Account caller = ctx.getCaller(); + Account caller = ctx.getCallingAccount(); PortForwardingRuleVO rule = _portForwardingDao.findById(ruleId); if (rule == null) { @@ -665,7 +665,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules _accountMgr.checkAccess(caller, null, true, rule); - if (!revokePortForwardingRuleInternal(ruleId, caller, ctx.getCallerUserId(), apply)) { + if (!revokePortForwardingRuleInternal(ruleId, caller, ctx.getCallingUserId(), apply)) { throw new CloudRuntimeException("Failed to delete port forwarding rule"); } return true; @@ -691,7 +691,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules @ActionEvent(eventType = EventTypes.EVENT_NET_RULE_DELETE, eventDescription = "revoking forwarding rule", async = true) public boolean revokeStaticNatRule(long ruleId, boolean apply) { UserContext ctx = UserContext.current(); - Account caller = ctx.getCaller(); + Account caller = ctx.getCallingAccount(); FirewallRuleVO rule = _firewallDao.findById(ruleId); if (rule == null) { @@ -700,7 +700,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules _accountMgr.checkAccess(caller, null, true, rule); - if (!revokeStaticNatRuleInternal(ruleId, caller, ctx.getCallerUserId(), apply)) { + if (!revokeStaticNatRuleInternal(ruleId, caller, ctx.getCallingUserId(), apply)) { throw new CloudRuntimeException("Failed to revoke forwarding rule"); } return true; @@ -802,7 +802,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules Long id = cmd.getId(); Map tags = cmd.getTags(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); if (ipId != null) { @@ -1015,7 +1015,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules @Override public Pair, Integer> searchStaticNatRules(Long ipId, Long id, Long vmId, Long start, Long size, String accountName, Long domainId, Long projectId, boolean isRecursive, boolean listAll) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); if (ipId != null) { @@ -1251,7 +1251,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules @ActionEvent(eventType = EventTypes.EVENT_DISABLE_STATIC_NAT, eventDescription = "disabling static nat", async=true) public boolean disableStaticNat(long ipId) throws ResourceUnavailableException, NetworkRuleConflictException, InsufficientAddressCapacityException { UserContext ctx = UserContext.current(); - Account caller = ctx.getCaller(); + Account caller = ctx.getCallingAccount(); IPAddressVO ipAddress = _ipAddressDao.findById(ipId); checkIpAndUserVm(ipAddress, null, caller); @@ -1279,7 +1279,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules } } - return disableStaticNat(ipId, caller, ctx.getCallerUserId(), false); + return disableStaticNat(ipId, caller, ctx.getCallingUserId(), false); } @Override diff --git a/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java b/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java index 1c189c44688..1cc6f8d4593 100755 --- a/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java +++ b/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java @@ -585,7 +585,7 @@ public class SecurityGroupManagerImpl extends ManagerBase implements SecurityGro throw new InvalidParameterValueException("At least one cidr or at least one security group needs to be specified"); } - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Account owner = _accountMgr.getAccount(securityGroup.getAccountId()); if (owner == null) { @@ -762,7 +762,7 @@ public class SecurityGroupManagerImpl extends ManagerBase implements SecurityGro private boolean revokeSecurityGroupRule(Long id, SecurityRuleType type) { // input validation - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); SecurityGroupRuleVO rule = _securityGroupRuleDao.findById(id); if (rule == null) { @@ -816,7 +816,7 @@ public class SecurityGroupManagerImpl extends ManagerBase implements SecurityGro @ActionEvent(eventType = EventTypes.EVENT_SECURITY_GROUP_CREATE, eventDescription = "creating security group") public SecurityGroupVO createSecurityGroup(CreateSecurityGroupCmd cmd) throws PermissionDeniedException, InvalidParameterValueException { String name = cmd.getSecurityGroupName(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Account owner = _accountMgr.finalizeOwner(caller, cmd.getAccountName(), cmd.getDomainId(), cmd.getProjectId()); if (_securityGroupDao.isNameInUse(owner.getId(), owner.getDomainId(), cmd.getSecurityGroupName())) { @@ -1055,7 +1055,7 @@ public class SecurityGroupManagerImpl extends ManagerBase implements SecurityGro @ActionEvent(eventType = EventTypes.EVENT_SECURITY_GROUP_DELETE, eventDescription = "deleting security group") public boolean deleteSecurityGroup(DeleteSecurityGroupCmd cmd) throws ResourceInUseException { Long groupId = cmd.getId(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); SecurityGroupVO group = _securityGroupDao.findById(groupId); if (group == null) { @@ -1307,7 +1307,7 @@ public class SecurityGroupManagerImpl extends ManagerBase implements SecurityGro return true; } - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); for (SecurityGroupVO securityGroup: vmSgGrps) { Account owner = _accountMgr.getAccount(securityGroup.getAccountId()); diff --git a/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java b/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java index 2b02a888de9..c2283261248 100644 --- a/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java +++ b/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java @@ -84,7 +84,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ @Override public NetworkACL createNetworkACL(String name, String description, long vpcId) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Vpc vpc = _vpcMgr.getVpc(vpcId); if(vpc == null){ throw new InvalidParameterValueException("Unable to find VPC"); @@ -135,7 +135,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ @Override public boolean deleteNetworkACL(long id) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); NetworkACL acl = _networkACLDao.findById(id); if(acl == null) { throw new InvalidParameterValueException("Unable to find specified ACL"); @@ -155,7 +155,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ } @Override public boolean replaceNetworkACLonPrivateGw(long aclId, long privateGatewayId) throws ResourceUnavailableException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); VpcGateway gateway = _vpcGatewayDao.findById(privateGatewayId); if (gateway == null) { throw new InvalidParameterValueException("Unable to find specified private gateway"); @@ -196,7 +196,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ @Override public boolean replaceNetworkACL(long aclId, long networkId) throws ResourceUnavailableException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); NetworkVO network = _networkDao.findById(networkId); if(network == null){ @@ -235,7 +235,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ @Override public NetworkACLItem createNetworkACLItem(CreateNetworkACLCmd aclItemCmd){ - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long aclId = aclItemCmd.getACLId(); if(aclId == null){ //ACL id is not specified. Get the ACL details from network @@ -368,7 +368,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ String action = cmd.getAction(); Map tags = cmd.getTags(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); Ternary domainIdRecursiveListProject = @@ -471,7 +471,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ Vpc vpc = _vpcMgr.getVpc(acl.getVpcId()); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); _accountMgr.checkAccess(caller, null, true, vpc); diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index 380a95e1882..379980e03d8 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -573,7 +573,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @ActionEvent(eventType = EventTypes.EVENT_VPC_CREATE, eventDescription = "creating vpc", create=true) public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr, String networkDomain) throws ResourceAllocationException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Account owner = _accountMgr.getAccount(vpcOwnerId); //Verify that caller can perform actions in behalf of vpc owner @@ -705,9 +705,9 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } //verify permissions - _accountMgr.checkAccess(ctx.getCaller(), null, false, vpc); + _accountMgr.checkAccess(ctx.getCallingAccount(), null, false, vpc); - return destroyVpc(vpc, ctx.getCaller(), ctx.getCallerUserId()); + return destroyVpc(vpc, ctx.getCallingAccount(), ctx.getCallingUserId()); } @Override @@ -763,7 +763,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @ActionEvent(eventType = EventTypes.EVENT_VPC_UPDATE, eventDescription = "updating vpc") public Vpc updateVpc(long vpcId, String vpcName, String displayText) { UserContext.current().setEventDetails(" Id: " + vpcId); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); // Verify input parameters VpcVO vpcToUpdate = _vpcDao.findById(vpcId); @@ -796,7 +796,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis public List listVpcs(Long id, String vpcName, String displayText, List supportedServicesStr, String cidr, Long vpcOffId, String state, String accountName, Long domainId, String keyword, Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll, Boolean restartRequired, Map tags, Long projectId) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); Ternary domainIdRecursiveListProject = new Ternary providersToImplement = getVpcProviders(vpc.getId()); - ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(ctx.getCallerUserId()), caller); + ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(ctx.getCallingUserId()), caller); for (VpcProvider element: getVpcElements()){ if(providersToImplement.contains(element.getProvider())){ if (element.shutdownVpc(vpc, context)) { @@ -1273,7 +1273,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @ActionEvent(eventType = EventTypes.EVENT_VPC_RESTART, eventDescription = "restarting vpc") public boolean restartVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); // Verify input parameters Vpc vpc = getActiveVpc(vpcId); @@ -1508,7 +1508,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } if (deleteNetwork) { - User callerUser = _accountMgr.getActiveUser(UserContext.current().getCallerUserId()); + User callerUser = _accountMgr.getActiveUser(UserContext.current().getCallingUserId()); Account owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM); ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner); _ntwkMgr.destroyNetwork(networkId, context); @@ -1532,7 +1532,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis Boolean listAll = cmd.listAll(); Long domainId = cmd.getDomainId(); String accountName = cmd.getAccountName(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); String state = cmd.getState(); Long projectId = cmd.getProjectId(); @@ -1594,7 +1594,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @Override public boolean applyStaticRoutes(long vpcId) throws ResourceUnavailableException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List routes = _staticRouteDao.listByVpcId(vpcId); return applyStaticRoutes(routes, caller, true); } @@ -1662,7 +1662,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @Override @ActionEvent(eventType = EventTypes.EVENT_STATIC_ROUTE_DELETE, eventDescription = "deleting static route") public boolean revokeStaticRoute(long routeId) throws ResourceUnavailableException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); StaticRouteVO route = _staticRouteDao.findById(routeId); if (route == null) { @@ -1699,7 +1699,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @DB @ActionEvent(eventType = EventTypes.EVENT_STATIC_ROUTE_CREATE, eventDescription = "creating static route", create=true) public StaticRoute createStaticRoute(long gatewayId, String cidr) throws NetworkRuleConflictException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); //parameters validation VpcGateway gateway = _vpcGatewayDao.findById(gatewayId); @@ -1782,7 +1782,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis Boolean isRecursive = cmd.isRecursive(); Boolean listAll = cmd.listAll(); String accountName = cmd.getAccountName(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); Map tags = cmd.getTags(); Long projectId = cmd.getProjectId(); @@ -1924,7 +1924,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @ActionEvent(eventType = EventTypes.EVENT_NET_IP_ASSIGN, eventDescription = "associating Ip", async = true) public IpAddress associateIPToVpc(long ipId, long vpcId) throws ResourceAllocationException, ResourceUnavailableException, InsufficientAddressCapacityException, ConcurrentOperationException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Account owner = null; IpAddress ipToAssoc = _ntwkModel.getIp(ipId); diff --git a/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java b/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java index 9e7bb13b867..472281bd2dd 100755 --- a/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java +++ b/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java @@ -114,7 +114,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc public RemoteAccessVpn createRemoteAccessVpn(long publicIpId, String ipRange, boolean openFirewall, long networkId) throws NetworkRuleConflictException { UserContext ctx = UserContext.current(); - Account caller = ctx.getCaller(); + Account caller = ctx.getCallingAccount(); // make sure ip address exists PublicIpAddress ipAddr = _networkMgr.getPublicIpAddress(publicIpId); @@ -312,7 +312,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc @Override @DB public VpnUser addVpnUser(long vpnOwnerId, String username, String password) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); if (!username.matches("^[a-zA-Z0-9][a-zA-Z0-9@._-]{2,63}$")) { throw new InvalidParameterValueException( @@ -366,7 +366,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc @Override public List listVpnUsers(long vpnOwnerId, String userName) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Account owner = _accountDao.findById(vpnOwnerId); _accountMgr.checkAccess(caller, null, true, owner); return _vpnUsersDao.listByAccount(vpnOwnerId); @@ -374,7 +374,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc @Override @DB public RemoteAccessVpnVO startRemoteAccessVpn(long ipAddressId, boolean openFirewall) throws ResourceUnavailableException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); RemoteAccessVpnVO vpn = _remoteAccessVpnDao.findByPublicIpAddress(ipAddressId); if (vpn == null) { @@ -425,7 +425,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc @DB @Override public boolean applyVpnUsers(long vpnOwnerId, String userName) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Account owner = _accountDao.findById(vpnOwnerId); _accountMgr.checkAccess(caller, null, true, owner); @@ -504,7 +504,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc public Pair, Integer> searchForVpnUsers(ListVpnUsersCmd cmd) { String username = cmd.getUsername(); Long id = cmd.getId(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); Ternary domainIdRecursiveListProject = new Ternary(cmd.getDomainId(), cmd.isRecursive(), null); @@ -542,7 +542,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc @Override public Pair, Integer> searchForRemoteAccessVpns(ListRemoteAccessVpnsCmd cmd) { // do some parameter validation - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long ipAddressId = cmd.getPublicIpId(); List permittedAccounts = new ArrayList(); diff --git a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java index a24300e02bf..360b46dfae5 100644 --- a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java +++ b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java @@ -112,7 +112,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 = UserContext.current().getCallingAccount(); Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId()); //Verify that caller can perform actions in behalf of vpc owner @@ -157,7 +157,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 = UserContext.current().getCallingAccount(); Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId()); //Verify that caller can perform actions in behalf of vpc owner @@ -225,7 +225,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 = UserContext.current().getCallingAccount(); Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId()); //Verify that caller can perform actions in behalf of vpc owner @@ -338,7 +338,7 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn @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(); + Account caller = UserContext.current().getCallingAccount(); Long id = cmd.getId(); Site2SiteCustomerGateway customerGateway = _customerGatewayDao.findById(id); @@ -372,7 +372,7 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn @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(); + Account caller = UserContext.current().getCallingAccount(); Long id = cmd.getId(); Site2SiteVpnGateway vpnGateway = _vpnGatewayDao.findById(id); @@ -390,7 +390,7 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn @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(); + Account caller = UserContext.current().getCallingAccount(); Long id = cmd.getId(); Site2SiteCustomerGatewayVO gw = _customerGatewayDao.findById(id); @@ -479,7 +479,7 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn @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(); + Account caller = UserContext.current().getCallingAccount(); Long id = cmd.getId(); Site2SiteVpnConnectionVO conn = _vpnConnectionDao.findById(id); @@ -529,7 +529,7 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn @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(); + Account caller = UserContext.current().getCallingAccount(); Long id = cmd.getId(); Site2SiteVpnConnectionVO conn = _vpnConnectionDao.findById(id); @@ -559,7 +559,7 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn long startIndex = cmd.getStartIndex(); long pageSizeVal = cmd.getPageSizeVal(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); Ternary domainIdRecursiveListProject = new Ternary permittedAccounts = new ArrayList(); Ternary domainIdRecursiveListProject = new Ternary permittedAccounts = new ArrayList(); Ternary domainIdRecursiveListProject = new Ternary hostTags = cmd.getHostTags(); dcId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current() - .getCaller(), dcId); + .getCallingAccount(), dcId); // this is for standalone option if (clusterName == null && clusterId == null) { @@ -704,7 +704,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, + dcId); } - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) { PermissionDeniedException ex = new PermissionDeniedException( @@ -927,7 +927,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, protected boolean doDeleteHost(long hostId, boolean isForced, boolean isForceDeleteStorage) { User caller = _accountMgr.getActiveUser(UserContext.current() - .getCallerUserId()); + .getCallingUserId()); // Verify that host exists HostVO host = _hostDao.findById(hostId); if (host == null) { @@ -935,7 +935,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, + " doesn't exist"); } _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current() - .getCaller(), host.getDataCenterId()); + .getCallingAccount(), host.getDataCenterId()); /* * TODO: check current agent status and updateAgentStatus to removed. If @@ -2296,7 +2296,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, } User caller = _accountMgr.getActiveUser(UserContext.current() - .getCallerUserId()); + .getCallingUserId()); if (forceDestroyStorage) { // put local storage into mainenance mode, will set all the VMs on diff --git a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java index 6d929c6438b..9b65b8a585d 100755 --- a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java +++ b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java @@ -421,7 +421,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim @Override public List searchForLimits(Long id, Long accountId, Long domainId, Integer type, Long startIndex, Long pageSizeVal) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List limits = new ArrayList(); boolean isAccount = true; @@ -565,7 +565,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 = UserContext.current().getCallingAccount(); if (max == null) { max = new Long(Resource.RESOURCE_UNLIMITED); @@ -663,7 +663,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim @Override public List recalculateResourceCount(Long accountId, Long domainId, Integer typeId) throws InvalidParameterValueException, CloudRuntimeException, PermissionDeniedException { - Account callerAccount = UserContext.current().getCaller(); + Account callerAccount = UserContext.current().getCallingAccount(); long count = 0; List counts = new ArrayList(); List resourceTypes = new ArrayList(); diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 227b20c0c5d..6c076759f78 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -983,7 +983,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe @Override public boolean archiveEvents(ArchiveEventsCmd cmd) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List ids = cmd.getIds(); boolean result =true; List permittedAccountIds = new ArrayList(); @@ -998,7 +998,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe List events = _eventDao.listToArchiveOrDeleteEvents(ids, cmd.getType(), cmd.getOlderThan(), permittedAccountIds); ControlledEntity[] sameOwnerEvents = events.toArray(new ControlledEntity[events.size()]); - _accountMgr.checkAccess(UserContext.current().getCaller(), null, true, sameOwnerEvents); + _accountMgr.checkAccess(UserContext.current().getCallingAccount(), null, true, sameOwnerEvents); if (ids != null && events.size() < ids.size()) { result = false; @@ -1010,7 +1010,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe @Override public boolean deleteEvents(DeleteEventsCmd cmd) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List ids = cmd.getIds(); boolean result =true; List permittedAccountIds = new ArrayList(); @@ -1025,7 +1025,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe List events = _eventDao.listToArchiveOrDeleteEvents(ids, cmd.getType(), cmd.getOlderThan(), permittedAccountIds); ControlledEntity[] sameOwnerEvents = events.toArray(new ControlledEntity[events.size()]); - _accountMgr.checkAccess(UserContext.current().getCaller(), null, true, sameOwnerEvents); + _accountMgr.checkAccess(UserContext.current().getCallingAccount(), null, true, sameOwnerEvents); if (ids != null && events.size() < ids.size()) { result = false; @@ -1052,7 +1052,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe Filter searchFilter = new Filter(ClusterVO.class, "id", true, startIndex, pageSizeVal); SearchCriteria sc = _clusterDao.createSearchCriteria(); - zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId); + zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCallingAccount(), zoneId); sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId); sc.addAnd("hypervisorType", SearchCriteria.Op.EQ, hypervisorType); @@ -1071,7 +1071,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe Object allocationState = cmd.getAllocationState(); String zoneType = cmd.getZoneType(); String keyword = cmd.getKeyword(); - zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId); + zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCallingAccount(), zoneId); Filter searchFilter = new Filter(ClusterVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal()); @@ -1139,7 +1139,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe @Override public Pair, Integer> searchForServers(ListHostsCmd cmd) { - Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), cmd.getZoneId()); + Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCallingAccount(), cmd.getZoneId()); Object name = cmd.getHostName(); Object type = cmd.getType(); Object state = cmd.getState(); @@ -1159,7 +1159,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe public Ternary, Integer>, List, Map> listHostsForMigrationOfVM(Long vmId, Long startIndex, Long pageSize) { // access check - only root admin can migrate VM - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.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"); @@ -1345,7 +1345,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe @Override public Pair, List> listStoragePoolsForMigrationOfVolume(Long volumeId) { // Access check - only root administrator can migrate volumes. - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.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"); @@ -1540,7 +1540,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe Object keyword = cmd.getKeyword(); Object allocationState = cmd.getAllocationState(); String zoneType = cmd.getZoneType(); - zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId); + zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCallingAccount(), zoneId); Filter searchFilter = new Filter(HostPodVO.class, "dataCenterId", true, cmd.getStartIndex(), cmd.getPageSizeVal()); @@ -1796,7 +1796,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe @Override public Set> listIsos(ListIsosCmd cmd) throws IllegalArgumentException, InvalidParameterValueException { TemplateFilter isoFilter = TemplateFilter.valueOf(cmd.getIsoFilter()); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Map tags = cmd.getTags(); boolean listAll = false; @@ -1829,7 +1829,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe TemplateFilter templateFilter = TemplateFilter.valueOf(cmd.getTemplateFilter()); Long id = cmd.getId(); Map tags = cmd.getTags(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); boolean listAll = false; if (templateFilter != null && templateFilter == TemplateFilter.all) { @@ -1975,7 +1975,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe Boolean passwordEnabled = cmd.isPasswordEnabled(); Boolean bootable = cmd.isBootable(); Integer sortKey = cmd.getSortKey(); - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); // verify that template exists VMTemplateVO template = _templateDao.findById(id); @@ -2078,7 +2078,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe List permittedAccounts = new ArrayList(); ListProjectResourcesCriteria listProjectResourcesCriteria = null; if (isAllocated) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Ternary domainIdRecursiveListProject = new Ternary( cmd.getDomainId(), cmd.isRecursive(), null); @@ -2269,9 +2269,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(UserContext.current().getCallingUserId()); - _itMgr.advanceStop(systemVm.getUuid(), isForced, caller, UserContext.current().getCaller()); + _itMgr.advanceStop(systemVm.getUuid(), isForced, caller, UserContext.current().getCallingAccount()); return _consoleProxyDao.findById(systemVm.getId()); } @@ -2343,7 +2343,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe } // check permissions - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); _accountMgr.checkAccess(caller, domain); // domain name is unique under the parent domain @@ -2427,7 +2427,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(UserContext.current().getCallingAccount(), null); if (id != null) { sc.addAnd("id", SearchCriteria.Op.EQ, id); } @@ -2453,14 +2453,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(UserContext.current().getCallingAccount(), null); boolean result = _alertDao.archiveAlert(cmd.getIds(), cmd.getType(), cmd.getOlderThan(), zoneId); return result; } @Override public boolean deleteAlerts(DeleteAlertsCmd cmd) { - Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), null); + Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCallingAccount(), null); boolean result = _alertDao.deleteAlert(cmd.getIds(), cmd.getType(), cmd.getOlderThan(), zoneId); return result; } @@ -2476,7 +2476,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(UserContext.current().getCallingAccount(), zoneId); List summedCapacities = new ArrayList(); if (zoneId == null && podId == null) {// Group by Zone, capacity type @@ -2585,7 +2585,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(UserContext.current().getCallingAccount(), zoneId); if (fetchLatest != null && fetchLatest) { _alertMgr.recalculateCapacity(); } @@ -3151,9 +3151,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(UserContext.current().getCallingUserId()); - _itMgr.advanceStop(systemVm.getUuid(), isForced, caller, UserContext.current().getCaller()); + _itMgr.advanceStop(systemVm.getUuid(), isForced, caller, UserContext.current().getCallingAccount()); return _secStorageVmDao.findById(systemVm.getId()); } @@ -3175,7 +3175,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe @Override public Pair, Integer> searchForSystemVm(ListSystemVMsCmd cmd) { String type = cmd.getSystemVmType(); - Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), cmd.getZoneId()); + Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCallingAccount(), cmd.getZoneId()); String zoneType = cmd.getZoneType(); Long id = cmd.getId(); String name = cmd.getSystemVmName(); @@ -3368,7 +3368,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe @Override public ArrayList getCloudIdentifierResponse(long userId) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); // verify that user exists User user = _accountMgr.getUserIncludingRemoved(userId); @@ -3461,7 +3461,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe Long zoneId = cmd.getZoneId(); AsyncJob job = null; // FIXME: cmd.getJob(); String mode = cmd.getMode(); - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (!_accountMgr.isRootAdmin(account.getType()) && ApiDBUtils.isExtractionDisabled()) { throw new PermissionDeniedException("Extraction has been disabled by admin"); @@ -3657,7 +3657,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe @Override public InstanceGroupVO updateVmGroup(UpdateVMGroupCmd cmd) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long groupId = cmd.getId(); String groupName = cmd.getGroupName(); @@ -3836,7 +3836,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe @Override public SSHKeyPair createSSHKeyPair(CreateSSHKeyPairCmd cmd) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); String accountName = cmd.getAccountName(); Long domainId = cmd.getDomainId(); Long projectId = cmd.getProjectId(); @@ -3860,7 +3860,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe @Override public boolean deleteSSHKeyPair(DeleteSSHKeyPairCmd cmd) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); String accountName = cmd.getAccountName(); Long domainId = cmd.getDomainId(); Long projectId = cmd.getProjectId(); @@ -3888,7 +3888,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe String name = cmd.getName(); String fingerPrint = cmd.getFingerprint(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); Ternary domainIdRecursiveListProject = new Ternary( @@ -3920,7 +3920,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 = UserContext.current().getCallingAccount(); Account owner = _accountMgr.finalizeOwner(caller, cmd.getAccountName(), cmd.getDomainId(), cmd.getProjectId()); @@ -3958,7 +3958,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe @Override public String getVMPassword(GetVMPasswordCmd cmd) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); UserVmVO vm = _userVmDao.findById(cmd.getId()); if (vm == null) { @@ -4134,7 +4134,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe } private VirtualMachine upgradeStoppedSystemVm(Long systemVmId, Long serviceOfferingId){ - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(systemVmId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm); if (systemVm == null) { diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 83f54f200ae..a807a906fde 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -785,7 +785,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C "unable to find zone by id " + zoneId); } // Check if zone is disabled - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) { throw new PermissionDeniedException( @@ -1372,9 +1372,9 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C public PrimaryDataStoreInfo preparePrimaryStorageForMaintenance( Long primaryStorageId) throws ResourceUnavailableException, InsufficientCapacityException { - Long userId = UserContext.current().getCallerUserId(); + Long userId = UserContext.current().getCallingUserId(); User user = _userDao.findById(userId); - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); boolean restart = true; StoragePoolVO primaryStorage = null; @@ -1425,9 +1425,9 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C CancelPrimaryStorageMaintenanceCmd cmd) throws ResourceUnavailableException { Long primaryStorageId = cmd.getId(); - Long userId = UserContext.current().getCallerUserId(); + Long userId = UserContext.current().getCallingUserId(); User user = _userDao.findById(userId); - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); StoragePoolVO primaryStorage = null; primaryStorage = _storagePoolDao.findById(primaryStorageId); diff --git a/server/src/com/cloud/storage/StoragePoolAutomationImpl.java b/server/src/com/cloud/storage/StoragePoolAutomationImpl.java index af5e9131931..8b2362862ac 100644 --- a/server/src/com/cloud/storage/StoragePoolAutomationImpl.java +++ b/server/src/com/cloud/storage/StoragePoolAutomationImpl.java @@ -101,9 +101,9 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation { @Override public boolean maintain(DataStore store) { - Long userId = UserContext.current().getCallerUserId(); + Long userId = UserContext.current().getCallingUserId(); User user = _userDao.findById(userId); - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); StoragePoolVO pool = primaryDataStoreDao.findById(store.getId()); try { StoragePool storagePool = (StoragePool) store; @@ -257,9 +257,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 = UserContext.current().getCallingUserId(); User user = _userDao.findById(userId); - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); StoragePoolVO poolVO = primaryDataStoreDao.findById(store.getId()); StoragePool pool = (StoragePool)store; diff --git a/server/src/com/cloud/storage/VolumeManagerImpl.java b/server/src/com/cloud/storage/VolumeManagerImpl.java index f91c9718832..b9cb4537903 100644 --- a/server/src/com/cloud/storage/VolumeManagerImpl.java +++ b/server/src/com/cloud/storage/VolumeManagerImpl.java @@ -374,7 +374,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 = UserContext.current().getCallingAccount(); long ownerId = cmd.getEntityOwnerId(); Account owner = _accountDao.findById(ownerId); Long zoneId = cmd.getZoneId(); @@ -816,7 +816,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 = UserContext.current().getCallingAccount(); long ownerId = cmd.getEntityOwnerId(); Boolean displayVolumeEnabled = cmd.getDisplayVolume(); @@ -1135,7 +1135,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { // do nothing as offering is public } else { _configMgr.checkDiskOfferingAccess(UserContext.current() - .getCaller(), newDiskOffering); + .getCallingAccount(), newDiskOffering); } if (newDiskOffering.isCustomized()) { @@ -1163,7 +1163,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(UserContext.current().getCallingAccount(), null, true, volume); UserVmVO userVm = _userVmDao.findById(volume.getInstanceId()); @@ -1616,7 +1616,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 = UserContext.current().getCallingAccount(); // Check that the volume ID is valid VolumeInfo volume = volFactory.getVolume(volumeId); @@ -1813,7 +1813,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 = UserContext.current().getCallingAccount(); if ((cmmd.getId() == null && cmmd.getDeviceId() == null && cmmd .getVirtualMachineId() == null) || (cmmd.getId() != null && (cmmd.getDeviceId() != null || cmmd diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index 10264d670d0..3f7c19028f2 100755 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -1211,7 +1211,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar if (ip != null && ip.getSystem()) { UserContext ctx = UserContext.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); } diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java index 92d80ee6cc8..0237769ecba 100755 --- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -272,7 +272,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(UserContext.current().getCallingAccount(), null, true, volume); SnapshotInfo snap = this.snapshotFactory.getSnapshot(snapshotId); @@ -459,7 +459,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, } private Long getSnapshotUserId() { - Long userId = UserContext.current().getCallerUserId(); + Long userId = UserContext.current().getCallingUserId(); if (userId == null) { return User.UID_SYSTEM; } @@ -508,7 +508,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 = UserContext.current().getCallingAccount(); // Verify parameters SnapshotInfo snapshotCheck = this.snapshotFactory.getSnapshot(snapshotId); @@ -575,14 +575,14 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, String zoneType = cmd.getZoneType(); Map tags = cmd.getTags(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); // Verify parameters if (volumeId != null) { VolumeVO volume = _volsDao.findById(volumeId); if (volume != null) { - _accountMgr.checkAccess(UserContext.current().getCaller(), null, true, volume); + _accountMgr.checkAccess(UserContext.current().getCallingAccount(), null, true, volume); } } @@ -777,7 +777,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(UserContext.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."); @@ -875,7 +875,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(UserContext.current().getCallingAccount(), null, true, volume); Pair, Integer> result = _snapshotPolicyDao.listAndCountByVolumeId(volumeId); return new Pair, Integer>(result.first(), result.second()); } @@ -912,7 +912,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, public List findRecurringSnapshotSchedule(ListRecurringSnapshotScheduleCmd cmd) { Long volumeId = cmd.getVolumeId(); Long policyId = cmd.getSnapshotPolicyId(); - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); // Verify parameters VolumeVO volume = _volsDao.findById(volumeId); @@ -971,7 +971,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, @Override public SnapshotVO allocSnapshot(Long volumeId, Long policyId) throws ResourceAllocationException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); VolumeVO volume = _volsDao.findById(volumeId); if (volume == null) { @@ -1111,7 +1111,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(UserContext.current().getCallingAccount(), null, true, volume); } boolean success = true; diff --git a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java index 851ec86c880..8efa0d60152 100644 --- a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java @@ -27,12 +27,11 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; -import com.cloud.event.ActionEventUtils; -import org.apache.cloudstack.api.command.user.snapshot.CreateSnapshotCmd; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.command.user.snapshot.CreateSnapshotCmd; import org.apache.cloudstack.framework.jobs.AsyncJobConstants; import org.apache.cloudstack.framework.jobs.AsyncJobManager; import org.apache.cloudstack.framework.jobs.AsyncJobVO; @@ -40,9 +39,8 @@ import org.apache.cloudstack.framework.jobs.dao.AsyncJobDao; import com.cloud.api.ApiDispatcher; import com.cloud.api.ApiGsonHelper; -import com.cloud.user.Account; -import com.cloud.async.AsyncJobResult; import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.event.ActionEventUtils; import com.cloud.event.EventTypes; import com.cloud.storage.Snapshot; import com.cloud.storage.SnapshotPolicyVO; @@ -53,11 +51,12 @@ import com.cloud.storage.dao.SnapshotDao; import com.cloud.storage.dao.SnapshotPolicyDao; import com.cloud.storage.dao.SnapshotScheduleDao; import com.cloud.storage.dao.VolumeDao; +import com.cloud.user.Account; import com.cloud.user.User; +import com.cloud.user.UserContext; import com.cloud.utils.DateUtil; import com.cloud.utils.DateUtil.IntervalType; import com.cloud.utils.NumbersUtil; - import com.cloud.utils.component.ManagerBase; import com.cloud.utils.concurrency.TestClock; import com.cloud.utils.db.DB; @@ -209,10 +208,6 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu List snapshotsToBeExecuted = _snapshotScheduleDao.getSchedulesToExecute(_currentTimestamp); s_logger.debug("Got " + snapshotsToBeExecuted.size() + " snapshots to be executed at " + displayTime); - // This is done for recurring snapshots, which are executed by the system automatically - // Hence set user id to that of system - long userId = 1; - for (SnapshotScheduleVO snapshotToBeExecuted : snapshotsToBeExecuted) { SnapshotScheduleVO tmpSnapshotScheduleVO = null; long snapshotScheId = snapshotToBeExecuted.getId(); @@ -377,11 +372,17 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu TimerTask timerTask = new TimerTask() { @Override public void run() { + try { + UserContext.registerOnceOnly(); + } catch (Exception e) { + s_logger.error("Unable to register context", e); + return; + } try { Date currentTimestamp = new Date(); poll(currentTimestamp); } catch (Throwable t) { - s_logger.warn("Catch throwable in snapshot scheduler " + t.toString(), t); + s_logger.warn("Catch throwable in snapshot scheduler ", t); } } }; diff --git a/server/src/com/cloud/tags/TaggedResourceManagerImpl.java b/server/src/com/cloud/tags/TaggedResourceManagerImpl.java index f58c5d70d7b..d4c1f560532 100644 --- a/server/src/com/cloud/tags/TaggedResourceManagerImpl.java +++ b/server/src/com/cloud/tags/TaggedResourceManagerImpl.java @@ -248,7 +248,7 @@ public class TaggedResourceManagerImpl extends ManagerBase implements TaggedReso @ActionEvent(eventType = EventTypes.EVENT_TAGS_CREATE, eventDescription = "creating resource tags") public List createTags(List resourceIds, TaggedResourceType resourceType, Map tags, String customer) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List resourceTags = new ArrayList(tags.size()); @@ -332,7 +332,7 @@ public class TaggedResourceManagerImpl extends ManagerBase implements TaggedReso @DB @ActionEvent(eventType = EventTypes.EVENT_TAGS_DELETE, eventDescription = "deleting resource tags") public boolean deleteTags(List resourceIds, TaggedResourceType resourceType, Map tags) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); SearchBuilder sb = _resourceTagDao.createSearchBuilder(); sb.and().op("resourceId", sb.entity().getResourceId(), SearchCriteria.Op.IN); diff --git a/server/src/com/cloud/template/TemplateAdapterBase.java b/server/src/com/cloud/template/TemplateAdapterBase.java index 0940d3e2af1..ea6590422fe 100755 --- a/server/src/com/cloud/template/TemplateAdapterBase.java +++ b/server/src/com/cloud/template/TemplateAdapterBase.java @@ -204,7 +204,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 = UserContext.current().getCallingAccount(); if(Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())){ throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: "+ zoneId ); } @@ -232,13 +232,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 = UserContext.current().getCallingAccount(); Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId()); _accountMgr.checkAccess(caller, null, true, owner); - return prepare(false, UserContext.current().getCallerUserId(), cmd.getTemplateName(), cmd.getDisplayText(), + return prepare(false, UserContext.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(), cmd.getImageStoreUuid()); @@ -246,11 +246,11 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat public TemplateProfile prepare(RegisterIsoCmd cmd) throws ResourceAllocationException { //check if the caller can operate with the template owner - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.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, UserContext.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()); } @@ -318,8 +318,8 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat public TemplateProfile prepareDelete(DeleteTemplateCmd cmd) { Long templateId = cmd.getId(); - Long userId = UserContext.current().getCallerUserId(); - Account account = UserContext.current().getCaller(); + Long userId = UserContext.current().getCallingUserId(); + Account account = UserContext.current().getCallingAccount(); Long zoneId = cmd.getZoneId(); VMTemplateVO template = _tmpltDao.findById(templateId.longValue()); @@ -343,7 +343,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 = UserContext.current().getCallingUserId(); Long zoneId = cmd.getZoneId(); VMTemplateVO template = _tmpltDao.findById(templateId.longValue()); @@ -355,8 +355,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 = UserContext.current().getCallingUserId(); + Account account = UserContext.current().getCallingAccount(); Long zoneId = cmd.getZoneId(); VMTemplateVO template = _tmpltDao.findById(templateId.longValue()); diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index daaa6bac06e..32b275d96c7 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -305,7 +305,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, @ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_CREATE, eventDescription = "creating template") public VirtualMachineTemplate registerTemplate(RegisterTemplateCmd cmd) throws URISyntaxException, ResourceAllocationException{ if(cmd.getTemplateTag() != null){ - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if(!_accountService.isRootAdmin(account.getType())){ throw new PermissionDeniedException("Parameter templatetag can only be specified by a Root Admin, permission denied"); } @@ -341,7 +341,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, @Override @ActionEvent(eventType = EventTypes.EVENT_ISO_EXTRACT, eventDescription = "extracting ISO", async = true) public Long extract(ExtractIsoCmd cmd) { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); Long templateId = cmd.getId(); Long zoneId = cmd.getZoneId(); String url = cmd.getUrl(); @@ -360,7 +360,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, @Override @ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_EXTRACT, eventDescription = "extracting template", async = true) public Long extract(ExtractTemplateCmd cmd) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long templateId = cmd.getId(); Long zoneId = cmd.getZoneId(); String url = cmd.getUrl(); @@ -390,7 +390,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, if(vmTemplate == null) throw new InvalidParameterValueException("Unable to find template id=" + templateId); - _accountMgr.checkAccess(UserContext.current().getCaller(), AccessType.ModifyEntry, true, vmTemplate); + _accountMgr.checkAccess(UserContext.current().getCallingAccount(), AccessType.ModifyEntry, true, vmTemplate); prepareTemplateInAllStoragePools(vmTemplate, zoneId); return vmTemplate; @@ -978,10 +978,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 = UserContext.current().getCallingUserId(); Long sourceZoneId = cmd.getSourceZoneId(); Long destZoneId = cmd.getDestinationZoneId(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); if (_swiftMgr.isSwiftEnabled()) { throw new CloudRuntimeException("copytemplate API is disabled in Swift setup, templates in Swift can be accessed by all Zones"); @@ -1274,8 +1274,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 = UserContext.current().getCallingAccount(); + Long userId = UserContext.current().getCallingUserId(); // Verify input parameters UserVmVO vmInstanceCheck = _userVmDao.findById(vmId); @@ -1312,8 +1312,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 = UserContext.current().getCallingAccount(); + Long userId = UserContext.current().getCallingUserId(); // Verify input parameters UserVmVO vm = _userVmDao.findById(vmId); @@ -1420,7 +1420,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 = UserContext.current().getCallingAccount(); VirtualMachineTemplate template = getTemplate(templateId); if (template == null) { @@ -1464,7 +1464,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 = UserContext.current().getCallingAccount(); Long zoneId = cmd.getZoneId(); VirtualMachineTemplate template = getTemplate(templateId);; @@ -1519,7 +1519,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, @Override public List listTemplatePermissions(BaseListTemplateOrIsoPermissionsCmd cmd) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long id = cmd.getId(); if (id.equals(Long.valueOf(1))) { @@ -1570,7 +1570,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, // Input validation Long id = cmd.getId(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List accountNames = cmd.getAccountNames(); List projectIds = cmd.getProjectIds(); Boolean isFeatured = cmd.isFeatured(); @@ -1720,7 +1720,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, @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 = UserContext.current().getCallingUserId(); if (userId == null) { userId = User.UID_SYSTEM; } @@ -1826,9 +1826,9 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, @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 = UserContext.current().getCallingUserId(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); boolean isAdmin = (isAdmin(caller.getType())); _accountMgr.checkAccess(caller, null, true, templateOwner); diff --git a/server/src/com/cloud/usage/UsageServiceImpl.java b/server/src/com/cloud/usage/UsageServiceImpl.java index ae0a585e906..b6828d61061 100755 --- a/server/src/com/cloud/usage/UsageServiceImpl.java +++ b/server/src/com/cloud/usage/UsageServiceImpl.java @@ -115,7 +115,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)UserContext.current().getCallingAccount(); Long usageType = cmd.getUsageType(); Long projectId = cmd.getProjectId(); diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index 89882742053..a69411937c3 100755 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -55,9 +55,9 @@ import com.cloud.api.query.dao.UserAccountJoinDao; import com.cloud.api.query.vo.ControlledViewEntity; import com.cloud.configuration.Config; import com.cloud.configuration.ConfigurationManager; +import com.cloud.configuration.Resource.ResourceOwnerType; import com.cloud.configuration.ResourceCountVO; import com.cloud.configuration.ResourceLimit; -import com.cloud.configuration.Resource.ResourceOwnerType; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.configuration.dao.ResourceCountDao; import com.cloud.configuration.dao.ResourceLimitDao; @@ -842,7 +842,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M } // Check permissions - checkAccess(UserContext.current().getCaller(), domain); + checkAccess(UserContext.current().getCallingAccount(), domain); if (!_userAccountDao.validateUsernameInDomain(userName, domainId)) { throw new InvalidParameterValueException("The user " + userName + " already exists in domain " + domainId); @@ -896,7 +896,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M throw new CloudRuntimeException("The user cannot be created as domain " + domain.getName() + " is being deleted"); } - checkAccess(UserContext.current().getCaller(), domain); + checkAccess(UserContext.current().getCallingAccount(), domain); Account account = _accountDao.findEnabledAccount(accountName, domainId); if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) { @@ -952,7 +952,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M throw new PermissionDeniedException("user id : " + id + " is system account, update is not allowed"); } - checkAccess(UserContext.current().getCaller(), null, true, account); + checkAccess(UserContext.current().getCallingAccount(), null, true, account); if (firstName != null) { if (firstName.isEmpty()) { @@ -1043,7 +1043,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M @Override @ActionEvent(eventType = EventTypes.EVENT_USER_DISABLE, eventDescription = "disabling User", async = true) public UserAccount disableUser(long userId) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); // Check if user exists in the system User user = _userDao.findById(userId); @@ -1079,7 +1079,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M @ActionEvent(eventType = EventTypes.EVENT_USER_ENABLE, eventDescription = "enabling User") public UserAccount enableUser(long userId) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); // Check if user exists in the system User user = _userDao.findById(userId); @@ -1122,7 +1122,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M @Override @ActionEvent(eventType = EventTypes.EVENT_USER_LOCK, eventDescription = "locking User") public UserAccount lockUser(long userId) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); // Check if user with id exists in the system User user = _userDao.findById(userId); @@ -1186,8 +1186,8 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M public boolean deleteUserAccount(long accountId) { UserContext ctx = UserContext.current(); - long callerUserId = ctx.getCallerUserId(); - Account caller = ctx.getCaller(); + long callerUserId = ctx.getCallingUserId(); + Account caller = ctx.getCallingAccount(); // If the user is a System user, return an error. We do not allow this AccountVO account = _accountDao.findById(accountId); @@ -1243,7 +1243,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M } // Check if user performing the action is allowed to modify this account - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); checkAccess(caller, null, true, account); boolean success = enableAccount(account.getId()); @@ -1257,7 +1257,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M @Override @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_DISABLE, eventDescription = "locking account", async = true) public AccountVO lockAccount(String accountName, Long domainId, Long accountId) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Account account = null; if (accountId != null) { @@ -1286,7 +1286,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M @Override @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_DISABLE, eventDescription = "disabling account", async = true) public AccountVO disableAccount(String accountName, Long domainId, Long accountId) throws ConcurrentOperationException, ResourceUnavailableException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Account account = null; if (accountId != null) { @@ -1343,7 +1343,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M } // Check if user performing the action is allowed to modify this account - checkAccess(UserContext.current().getCaller(), _domainMgr.getDomain(account.getDomainId())); + checkAccess(UserContext.current().getCallingAccount(), _domainMgr.getDomain(account.getDomainId())); // check if the given account name is unique in this domain for updating Account duplicateAcccount = _accountDao.findActiveAccount(newAccountName, domainId); @@ -1417,7 +1417,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M throw new InvalidParameterValueException("The user is default and can't be removed"); } - checkAccess(UserContext.current().getCaller(), null, true, account); + checkAccess(UserContext.current().getCallingAccount(), null, true, account); return _userDao.remove(id); } @@ -1431,6 +1431,12 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M protected class AccountCleanupTask implements Runnable { @Override public void run() { + try { + UserContext.registerOnceOnly(); + } catch (Exception e) { + s_logger.error("Unable to register the system user context", e); + return; + } try { GlobalLock lock = GlobalLock.getInternLock("AccountCleanup"); if (lock == null) { @@ -1493,7 +1499,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M Account projectAccount = getAccount(project.getProjectAccountId()); if (projectAccount == null) { s_logger.debug("Removing inactive project id=" + project.getId()); - _projectMgr.deleteProject(UserContext.current().getCaller(), UserContext.current().getCallerUserId(), project); + _projectMgr.deleteProject(UserContext.current().getCallingAccount(), UserContext.current().getCallingUserId(), project); } else { s_logger.debug("Can't remove disabled project " + project + " as it has non removed account id=" + project.getId()); } diff --git a/server/src/com/cloud/user/DomainManagerImpl.java b/server/src/com/cloud/user/DomainManagerImpl.java index 00a779e2ff9..6a76eccdbec 100644 --- a/server/src/com/cloud/user/DomainManagerImpl.java +++ b/server/src/com/cloud/user/DomainManagerImpl.java @@ -121,7 +121,7 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom @Override @ActionEvent(eventType = EventTypes.EVENT_DOMAIN_CREATE, eventDescription = "creating Domain") public Domain createDomain(String name, Long parentId, String networkDomain, String domainUUID) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); if (parentId == null) { parentId = Long.valueOf(DomainVO.ROOT_DOMAIN); @@ -198,7 +198,7 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom @Override @ActionEvent(eventType = EventTypes.EVENT_DOMAIN_DELETE, eventDescription = "deleting Domain", async = true) public boolean deleteDomain(long domainId, Boolean cleanup) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); DomainVO domain = _domainDao.findById(domainId); @@ -315,14 +315,14 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom for (AccountVO account : accounts) { if (account.getType() != Account.ACCOUNT_TYPE_PROJECT) { s_logger.debug("Deleting account " + account + " as a part of domain id=" + domainId + " cleanup"); - success = (success && _accountMgr.deleteAccount(account, UserContext.current().getCallerUserId(), UserContext.current().getCaller())); + success = (success && _accountMgr.deleteAccount(account, UserContext.current().getCallingUserId(), UserContext.current().getCallingAccount())); if (!success) { s_logger.warn("Failed to cleanup account id=" + account.getId() + " as a part of domain cleanup"); } } else { ProjectVO project = _projectDao.findByProjectAccountId(account.getId()); s_logger.debug("Deleting project " + project + " as a part of domain id=" + domainId + " cleanup"); - success = (success && _projectMgr.deleteProject(UserContext.current().getCaller(), UserContext.current().getCallerUserId(), project)); + success = (success && _projectMgr.deleteProject(UserContext.current().getCallingAccount(), UserContext.current().getCallingUserId(), project)); if (!success) { s_logger.warn("Failed to cleanup project " + project + " as a part of domain cleanup"); } @@ -347,7 +347,7 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom @Override public Pair, Integer> searchForDomains(ListDomainsCmd cmd) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long domainId = cmd.getId(); boolean listAll = cmd.listAll(); boolean isRecursive = false; @@ -419,7 +419,7 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom boolean listAll = cmd.listAll(); String path = null; - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); if (domainId != null) { _accountMgr.checkAccess(caller, getDomain(domainId)); } else { @@ -488,7 +488,7 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom } // check permissions - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); _accountMgr.checkAccess(caller, domain); // domain name is unique in the cloud diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 06c1d5d8f33..e7b9c81a409 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -454,7 +454,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use @ActionEvent(eventType = EventTypes.EVENT_VM_RESETPASSWORD, eventDescription = "resetting Vm password", async = true) public UserVm resetVMPassword(ResetVMPasswordCmd cmd, String password) throws ResourceUnavailableException, InsufficientCapacityException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long vmId = cmd.getId(); UserVmVO userVm = _vmDao.findById(cmd.getId()); _vmDao.loadDetails(userVm); @@ -511,7 +511,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use private boolean resetVMPasswordInternal(Long vmId, String password) throws ResourceUnavailableException, InsufficientCapacityException { - Long userId = UserContext.current().getCallerUserId(); + Long userId = UserContext.current().getCallingUserId(); VMInstanceVO vmInstance = _vmDao.findById(vmId); if (password == null || password.equals("")) { @@ -580,7 +580,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use public UserVm resetVMSSHKey(ResetVMSSHKeyCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Account owner = _accountMgr.finalizeOwner(caller, cmd.getAccountName(), cmd.getDomainId(), cmd.getProjectId()); Long vmId = cmd.getId(); @@ -638,7 +638,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use } private boolean resetVMSSHKeyInternal(Long vmId, String SSHPublicKey, String password) throws ResourceUnavailableException, InsufficientCapacityException { - Long userId = UserContext.current().getCallerUserId(); + Long userId = UserContext.current().getCallingUserId(); VMInstanceVO vmInstance = _vmDao.findById(vmId); VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vmInstance.getTemplateId()); @@ -755,7 +755,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use private UserVm upgradeStoppedVirtualMachine(Long vmId, Long svcOffId) throws ResourceAllocationException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); // Verify input parameters UserVmVO vmInstance = _vmDao.findById(vmId); @@ -824,7 +824,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use Long vmId = cmd.getVmId(); Long networkId = cmd.getNetworkId(); String ipAddress = cmd.getIpAddress(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); UserVmVO vmInstance = _vmDao.findById(vmId); if(vmInstance == null) { @@ -902,7 +902,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use public UserVm removeNicFromVirtualMachine(RemoveNicFromVMCmd cmd) throws InvalidParameterValueException, PermissionDeniedException, CloudRuntimeException { Long vmId = cmd.getVmId(); Long nicId = cmd.getNicId(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); UserVmVO vmInstance = _vmDao.findById(vmId); if(vmInstance == null) { @@ -965,7 +965,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use public UserVm updateDefaultNicForVirtualMachine(UpdateDefaultNicForVMCmd cmd) throws InvalidParameterValueException, CloudRuntimeException { Long vmId = cmd.getVmId(); Long nicId = cmd.getNicId(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); UserVmVO vmInstance = _vmDao.findById(vmId); if (vmInstance == null){ @@ -1092,7 +1092,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use @Override public boolean upgradeVirtualMachine(Long vmId, Long newServiceOfferingId) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException{ - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); // Verify input parameters VirtualMachine vmInstance = _vmInstanceDao.findById(vmId); @@ -1244,7 +1244,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use throws ResourceAllocationException, CloudRuntimeException { Long vmId = cmd.getId(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); // Verify input parameters UserVmVO vm = _vmDao.findById(vmId.longValue()); @@ -1443,9 +1443,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use @Override public boolean expunge(UserVmVO vm, long callerUserId, Account caller) { - UserContext ctx = UserContext.current(); - ctx.setAccountId(vm.getAccountId()); - try { List rootVol = _volsDao.findByInstanceAndType(vm.getId(), Volume.Type.ROOT); // expunge the vm @@ -1601,7 +1598,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use @Override public void run() { - UserContext.registerContext(_accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount(), null, false); + UserContext.register(_accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount(), null, false); GlobalLock scanLock = GlobalLock.getInternLock("UserVMExpunge"); try { if (scanLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION)) { @@ -1635,7 +1632,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use } } finally { scanLock.releaseRef(); - UserContext.unregisterContext(); + UserContext.unregister(); } } } @@ -1657,7 +1654,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use Long id = cmd.getId(); Long osTypeId = cmd.getOsTypeId(); String userData = cmd.getUserData(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); // Input validation UserVmVO vmInstance = null; @@ -1677,7 +1674,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use "Can't enable ha for the vm as it's created from the Service offering having HA disabled"); } - _accountMgr.checkAccess(UserContext.current().getCaller(), null, true, + _accountMgr.checkAccess(UserContext.current().getCallingAccount(), null, true, vmInstance); if (displayName == null) { @@ -1795,7 +1792,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use @ActionEvent(eventType = EventTypes.EVENT_VM_REBOOT, eventDescription = "rebooting Vm", async = true) public UserVm rebootVirtualMachine(RebootVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long vmId = cmd.getId(); // Verify input parameters @@ -1818,7 +1815,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId + " corresponding to the vm"); } - return rebootVirtualMachine(UserContext.current().getCallerUserId(), + return rebootVirtualMachine(UserContext.current().getCallingUserId(), vmId); } @@ -1832,7 +1829,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use @Override @DB public InstanceGroupVO createVmGroup(CreateVMGroupCmd cmd) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long domainId = cmd.getDomainId(); String accountName = cmd.getAccountName(); String groupName = cmd.getGroupName(); @@ -1887,7 +1884,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use @Override public boolean deleteVmGroup(DeleteVMGroupCmd cmd) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long groupId = cmd.getId(); // Verify input parameters @@ -2040,7 +2037,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use List affinityGroupIdList) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List networkList = new ArrayList(); // Verify that caller can perform actions in behalf of vm owner @@ -2100,7 +2097,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use List affinityGroupIdList) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List networkList = new ArrayList(); boolean isSecurityGroupEnabledNetworkUsed = false; boolean isVmWare = (template.getHypervisorType() == HypervisorType.VMware || (hypervisor != null && hypervisor == HypervisorType.VMware)); @@ -2215,7 +2212,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use IpAddresses defaultIps, Boolean displayvm, String keyboard, List affinityGroupIdList) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List networkList = new ArrayList(); // Verify that caller can perform actions in behalf of vm owner @@ -3031,8 +3028,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use public UserVm stopVirtualMachine(long vmId, boolean forced) throws ConcurrentOperationException { // Input validation - Account caller = UserContext.current().getCaller(); - Long userId = UserContext.current().getCallerUserId(); + Account caller = UserContext.current().getCallingAccount(); + Long userId = UserContext.current().getCallingUserId(); // if account is removed, return error if (caller != null && caller.getRemoved() != null) { @@ -3079,7 +3076,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use Network guestNetwork = _networkDao.findById(networkId); NetworkOffering offering = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId()); assert (offering.getAssociatePublicIP() == true) : "User VM should not have system owned public IP associated with it when offering configured not to associate public IP."; - _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 " @@ -3113,9 +3110,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { // Input validation - Account callerAccount = UserContext.current().getCaller(); + Account callerAccount = UserContext.current().getCallingAccount(); UserVO callerUser = _userDao.findById(UserContext.current() - .getCallerUserId()); + .getCallingUserId()); // if account is removed, return error if (callerAccount != null && callerAccount.getRemoved() != null) { @@ -3145,7 +3142,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use Host destinationHost = null; if (hostId != null) { - Account account = UserContext.current().getCaller(); + Account account = UserContext.current().getCallingAccount(); if (!_accountService.isRootAdmin(account.getType())) { throw new PermissionDeniedException( "Parameter hostid can only be specified by a Root Admin, permission denied"); @@ -3258,8 +3255,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use @Override public UserVm destroyVm(long vmId) throws ResourceUnavailableException, ConcurrentOperationException { - Account caller = UserContext.current().getCaller(); - Long userId = UserContext.current().getCallerUserId(); + Account caller = UserContext.current().getCallingAccount(); + Long userId = UserContext.current().getCallingUserId(); // Verify input parameters UserVmVO vm = _vmDao.findById(vmId); @@ -3531,7 +3528,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use @Override public VirtualMachine vmStorageMigration(Long vmId, StoragePool destPool) { // access check - only root admin can migrate VM - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.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"); @@ -3604,7 +3601,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException { // access check - only root admin can migrate VM - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.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"); @@ -3698,7 +3695,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use Map volumeToPool) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException { // Access check - only root administrator can migrate VM. - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.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"); @@ -3821,7 +3818,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use // VERIFICATIONS and VALIDATIONS // VV 1: verify the two users - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && caller.getType() != Account.ACCOUNT_TYPE_DOMAIN_ADMIN) { // only // root @@ -4158,7 +4155,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use // if the network offering has persistent set to true, implement the network if (requiredOfferings.get(0).getIsPersistent()) { DeployDestination dest = new DeployDestination(zone, null, null, null); - UserVO callerUser = _userDao.findById(UserContext.current().getCallerUserId()); + UserVO callerUser = _userDao.findById(UserContext.current().getCallingUserId()); Journal journal = new Journal.LogJournal("Implementing " + newNetwork, s_logger); ReservationContext context = new ReservationContextImpl(UUID.randomUUID().toString(), journal, callerUser, caller); @@ -4226,7 +4223,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use @Override public UserVm restoreVM(RestoreVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException { // Input validation - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); long vmId = cmd.getVmId(); Long newTemplateId = cmd.getTemplateId(); diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 037cbf3a2bf..2d744c8dcda 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -3664,4 +3664,5 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac return false; } + } diff --git a/server/src/com/cloud/vm/VmWorkJobDispatcher.java b/server/src/com/cloud/vm/VmWorkJobDispatcher.java index 40ab0df153a..0292db9b5f1 100644 --- a/server/src/com/cloud/vm/VmWorkJobDispatcher.java +++ b/server/src/com/cloud/vm/VmWorkJobDispatcher.java @@ -16,10 +16,6 @@ // under the License. package com.cloud.vm; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; - import javax.inject.Inject; import org.apache.log4j.Logger; @@ -30,9 +26,10 @@ import org.apache.cloudstack.framework.jobs.AsyncJobDispatcher; import org.apache.cloudstack.framework.jobs.AsyncJobManager; import com.cloud.api.ApiSerializerHelper; -import com.cloud.user.AccountVO; +import com.cloud.dao.EntityManager; import com.cloud.user.UserContext; import com.cloud.user.dao.AccountDao; +import com.cloud.utils.UuidUtils; import com.cloud.utils.component.AdapterBase; import com.cloud.vm.dao.VMInstanceDao; @@ -43,8 +40,11 @@ public class VmWorkJobDispatcher extends AdapterBase implements AsyncJobDispatch @Inject private AsyncJobManager _asyncJobMgr; @Inject private AccountDao _accountDao; @Inject private VMInstanceDao _instanceDao; + @Inject + private EntityManager _entityMgr; - private final Map _handlerMap = new HashMap(); + public final static String Start = "start"; + public final static String Stop = "stop"; @Override public void runJob(AsyncJob job) { @@ -55,69 +55,21 @@ public class VmWorkJobDispatcher extends AdapterBase implements AsyncJobDispatch VmWork work = (VmWork)ApiSerializerHelper.fromSerializedString(job.getCmdInfo()); assert(work != null); - AccountVO account = _accountDao.findById(work.getAccountId()); - assert(account != null); - VMInstanceVO vm = _instanceDao.findById(work.getVmId()); assert(vm != null); - // - // Due to legcy massive generic usage in VirtualMachineManagerImpl, we can't dispatch job handling - // directly to VirtualMachineManagerImpl, since most handling method are generic method. - // - // to solve the problem, we have to go through an instantiated VirtualMachineGuru so that it can carry - // down correct type back to VirtualMachineManagerImpl. It is sad that we have to write code like this - // - VirtualMachineGuru guru = _vmMgr.getVmGuru(vm); - assert(guru != null); - if(guru == null) { - s_logger.error("Unable to find virtual Guru for VM type: " + vm.getType()); - } - - UserContext.registerContext(work.getUserId(), account, null, false); - try { - Method handler = getHandler(guru, cmd); - if(handler != null) { - handler.invoke(guru, work); - _asyncJobMgr.completeAsyncJob(job.getId(), AsyncJobConstants.STATUS_SUCCEEDED, 0, null); - } else { - s_logger.error("Unable to find VM work handler. " + cmd); - - _asyncJobMgr.completeAsyncJob(job.getId(), AsyncJobConstants.STATUS_FAILED, 0, null); - } - } finally { - UserContext.unregisterContext(); + UserContext context = UserContext.register(work.getUserId(), work.getAccountId(), UuidUtils.first(job.getUuid())); + if (cmd.equals(Start)) { + _vmMgr.start(vm.getUuid(), null, context.getCallingUser(), context.getCallingAccount()); + } else if (cmd.equals(Stop)) { + _vmMgr.stop(vm.getUuid(), context.getCallingUser(), context.getCallingAccount()); } + _asyncJobMgr.completeAsyncJob(job.getId(), AsyncJobConstants.STATUS_SUCCEEDED, 0, null); } catch(Throwable e) { s_logger.error("Unexpected exception", e); - _asyncJobMgr.completeAsyncJob(job.getId(), AsyncJobConstants.STATUS_FAILED, 0, null); + _asyncJobMgr.completeAsyncJob(job.getId(), AsyncJobConstants.STATUS_FAILED, 0, e); + } finally { + UserContext.unregister(); } } - - private Method getHandler(VirtualMachineGuru guru, String cmd) { - - synchronized(_handlerMap) { - Class clz = guru.getClass(); - String key = clz.getCanonicalName() + cmd; - Method method = _handlerMap.get(key); - if(method != null) - return method; - - try { - method = clz.getMethod(cmd, VmWork.class); - method.setAccessible(true); - } catch (SecurityException e) { - assert(false); - s_logger.error("Unexpected exception", e); - return null; - } catch (NoSuchMethodException e) { - assert(false); - s_logger.error("Unexpected exception", e); - return null; - } - - _handlerMap.put(key, method); - return method; - } - } } diff --git a/server/src/com/cloud/vm/VmWorkJobWakeupDispatcher.java b/server/src/com/cloud/vm/VmWorkJobWakeupDispatcher.java index 17963f7135c..82d48c80852 100644 --- a/server/src/com/cloud/vm/VmWorkJobWakeupDispatcher.java +++ b/server/src/com/cloud/vm/VmWorkJobWakeupDispatcher.java @@ -77,7 +77,7 @@ public class VmWorkJobWakeupDispatcher extends AdapterBase implements AsyncJobDi VMInstanceVO vm = _instanceDao.findById(work.getVmId()); assert(vm != null); - UserContext.registerContext(work.getUserId(), account, null, false); + UserContext.register(work.getUserId(), account, null, false); try { Method handler = getHandler(joinRecord.getWakeupHandler()); if(handler != null) { @@ -88,7 +88,7 @@ public class VmWorkJobWakeupDispatcher extends AdapterBase implements AsyncJobDi " when waking up job-" + job.getId()); } } finally { - UserContext.unregisterContext(); + UserContext.unregister(); } } catch(Throwable e) { s_logger.warn("Unexpected exception in waking up job-" + job.getId()); diff --git a/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java b/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java index 3454c94962c..187835d4cfd 100644 --- a/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java +++ b/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java @@ -233,7 +233,7 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana } protected Account getCaller(){ - return UserContext.current().getCaller(); + return UserContext.current().getCallingAccount(); } @Override @@ -664,7 +664,7 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana "VM Snapshot reverting failed due to vm snapshot is not in the state of Created."); } - UserVO callerUser = _userDao.findById(UserContext.current().getCallerUserId()); + UserVO callerUser = _userDao.findById(UserContext.current().getCallingUserId()); UserVmVO vm = null; Long hostId = null; diff --git a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java index efe18c3b375..c2d6b971369 100644 --- a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java +++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java @@ -85,7 +85,7 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro public AffinityGroup createAffinityGroup(String account, Long domainId, String affinityGroupName, String affinityGroupType, String description) { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Account owner = _accountMgr.finalizeOwner(caller, account, domainId, null); if (_affinityGroupDao.isNameInUse(owner.getAccountId(), owner.getDomainId(), affinityGroupName)) { @@ -128,7 +128,7 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro public boolean deleteAffinityGroup(Long affinityGroupId, String account, Long domainId, String affinityGroupName) throws ResourceInUseException { - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Account owner = _accountMgr.finalizeOwner(caller, account, domainId, null); AffinityGroupVO group = null; @@ -180,7 +180,7 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro public Pair, Integer> listAffinityGroups(Long affinityGroupId, String affinityGroupName, String affinityGroupType, Long vmId, Long startIndex, Long pageSize) { Filter searchFilter = new Filter(AffinityGroupVO.class, "id", Boolean.TRUE, startIndex, pageSize); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Long accountId = caller.getAccountId(); Long domainId = caller.getDomainId(); @@ -322,7 +322,7 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro + "; make sure the virtual machine is stopped and not in an error state before updating."); } - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); Account owner = _accountMgr.getAccount(vmInstance.getAccountId()); // check that the affinity groups exist diff --git a/server/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerManagerImpl.java b/server/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerManagerImpl.java index ac3b8f56e61..ffbbcdbcffc 100644 --- a/server/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerManagerImpl.java +++ b/server/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerManagerImpl.java @@ -99,7 +99,7 @@ public class ApplicationLoadBalancerManagerImpl extends ManagerBase implements A throw new InvalidParameterValueException("Can't find guest network by id"); } - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); _accountMgr.checkAccess(caller, AccessType.UseNetwork, false, guestNtwk); Network sourceIpNtwk = _networkModel.getNetwork(sourceIpNetworkId); @@ -373,7 +373,7 @@ public class ApplicationLoadBalancerManagerImpl extends ManagerBase implements A Map tags = cmd.getTags(); - Account caller = UserContext.current().getCaller(); + Account caller = UserContext.current().getCallingAccount(); List permittedAccounts = new ArrayList(); Ternary domainIdRecursiveListProject = new Ternary( diff --git a/server/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImpl.java b/server/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImpl.java index 96ac76e3eae..d437c719a3d 100644 --- a/server/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImpl.java +++ b/server/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImpl.java @@ -151,7 +151,7 @@ public class GlobalLoadBalancingRulesServiceImpl implements GlobalLoadBalancingR public boolean assignToGlobalLoadBalancerRule(AssignToGlobalLoadBalancerRuleCmd assignToGslbCmd) { UserContext ctx = UserContext.current(); - Account caller = ctx.getCaller(); + Account caller = ctx.getCallingAccount(); long gslbRuleId = assignToGslbCmd.getGlobalLoadBalancerRuleId(); GlobalLoadBalancerRuleVO gslbRule = _gslbRuleDao.findById(gslbRuleId); @@ -282,7 +282,7 @@ public class GlobalLoadBalancingRulesServiceImpl implements GlobalLoadBalancingR public boolean removeFromGlobalLoadBalancerRule(RemoveFromGlobalLoadBalancerRuleCmd removeFromGslbCmd) { UserContext ctx = UserContext.current(); - Account caller = ctx.getCaller(); + Account caller = ctx.getCallingAccount(); long gslbRuleId = removeFromGslbCmd.getGlobalLoadBalancerRuleId(); GlobalLoadBalancerRuleVO gslbRule = _gslbRuleDao.findById(gslbRuleId); @@ -379,7 +379,7 @@ public class GlobalLoadBalancingRulesServiceImpl implements GlobalLoadBalancingR public boolean deleteGlobalLoadBalancerRule(DeleteGlobalLoadBalancerRuleCmd deleteGslbCmd) { UserContext ctx = UserContext.current(); - Account caller = ctx.getCaller(); + Account caller = ctx.getCallingAccount(); long gslbRuleId = deleteGslbCmd.getGlobalLoadBalancerId(); GlobalLoadBalancerRuleVO gslbRule = _gslbRuleDao.findById(gslbRuleId); @@ -448,7 +448,7 @@ public class GlobalLoadBalancingRulesServiceImpl implements GlobalLoadBalancingR } UserContext ctx = UserContext.current(); - Account caller = ctx.getCaller(); + Account caller = ctx.getCallingAccount(); _accountMgr.checkAccess(caller, SecurityChecker.AccessType.ModifyEntry, true, gslbRule); diff --git a/server/test/com/cloud/configuration/ConfigurationManagerTest.java b/server/test/com/cloud/configuration/ConfigurationManagerTest.java index 5c1cabfe774..75b5bc26f51 100755 --- a/server/test/com/cloud/configuration/ConfigurationManagerTest.java +++ b/server/test/com/cloud/configuration/ConfigurationManagerTest.java @@ -112,7 +112,7 @@ public class ConfigurationManagerTest { when(configurationMgr._vlanDao.acquireInLockTable(anyLong(), anyInt())).thenReturn(vlan); - UserContext.registerContext(1, account, null, true); + UserContext.register(1, account, null, true); Field dedicateIdField = _dedicatePublicIpRangeClass.getDeclaredField("id"); dedicateIdField.setAccessible(true); diff --git a/server/test/com/cloud/network/DedicateGuestVlanRangesTest.java b/server/test/com/cloud/network/DedicateGuestVlanRangesTest.java index e81d7222a60..82ebd544a08 100644 --- a/server/test/com/cloud/network/DedicateGuestVlanRangesTest.java +++ b/server/test/com/cloud/network/DedicateGuestVlanRangesTest.java @@ -90,7 +90,7 @@ public class DedicateGuestVlanRangesTest { when(networkService._accountMgr.getAccount(anyLong())).thenReturn(account); when(networkService._accountDao.findActiveAccount(anyString(), anyLong())).thenReturn(account); - UserContext.registerContext(1, account, null, true); + UserContext.register(1, account, null, true); Field accountNameField = _dedicateGuestVlanRangeClass.getDeclaredField("accountName"); accountNameField.setAccessible(true); diff --git a/server/test/com/cloud/vm/UserVmManagerTest.java b/server/test/com/cloud/vm/UserVmManagerTest.java index 88529a40db7..2c70ee7410d 100755 --- a/server/test/com/cloud/vm/UserVmManagerTest.java +++ b/server/test/com/cloud/vm/UserVmManagerTest.java @@ -277,7 +277,7 @@ public class UserVmManagerTest { // UserContext.current().setEventDetails("Vm Id: "+getId()); Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid"); //AccountVO(String accountName, long domainId, String networkDomain, short type, int regionId) - UserContext.registerContext(1, account, null, true); + UserContext.register(1, account, null, true); when(_vmInstanceDao.findById(anyLong())).thenReturn(_vmInstance); @@ -442,7 +442,7 @@ public class UserVmManagerTest { // caller is of type 0 Account caller = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString()); - UserContext.registerContext(1, caller, null, true); + UserContext.register(1, caller, null, true); _userVmMgr.moveVMToUser(cmd); } @@ -469,7 +469,7 @@ public class UserVmManagerTest { // caller is of type 0 Account caller = new AccountVO("testaccount", 1, "networkdomain", (short) 1, UUID.randomUUID().toString()); - UserContext.registerContext(1, caller, null, true); + UserContext.register(1, caller, null, true); Account oldAccount = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString()); diff --git a/server/test/com/cloud/vpc/NetworkACLManagerTest.java b/server/test/com/cloud/vpc/NetworkACLManagerTest.java index 76b811f8685..197be27d8de 100644 --- a/server/test/com/cloud/vpc/NetworkACLManagerTest.java +++ b/server/test/com/cloud/vpc/NetworkACLManagerTest.java @@ -91,7 +91,7 @@ public class NetworkACLManagerTest extends TestCase{ public void setUp() { ComponentContext.initComponentsLifeCycle(); Account account = new AccountVO("testaccount", 1, "testdomain", (short) 0, UUID.randomUUID().toString()); - UserContext.registerContext(1, account, null, true); + UserContext.register(1, account, null, true); acl = Mockito.mock(NetworkACLVO.class); aclItem = Mockito.mock(NetworkACLItemVO.class); } diff --git a/server/test/com/cloud/vpc/NetworkACLServiceTest.java b/server/test/com/cloud/vpc/NetworkACLServiceTest.java index e71fabfef2d..e34c52c94e9 100644 --- a/server/test/com/cloud/vpc/NetworkACLServiceTest.java +++ b/server/test/com/cloud/vpc/NetworkACLServiceTest.java @@ -78,7 +78,7 @@ public class NetworkACLServiceTest extends TestCase{ public void setUp() { ComponentContext.initComponentsLifeCycle(); Account account = new AccountVO("testaccount", 1, "testdomain", (short) 0, UUID.randomUUID().toString()); - UserContext.registerContext(1, account, null, true); + UserContext.register(1, account, null, true); createACLItemCmd = new CreateNetworkACLCmd(){ @Override diff --git a/server/test/com/cloud/vpc/VpcTest.java b/server/test/com/cloud/vpc/VpcTest.java index 52e837ec5ca..e490606e63a 100644 --- a/server/test/com/cloud/vpc/VpcTest.java +++ b/server/test/com/cloud/vpc/VpcTest.java @@ -97,7 +97,7 @@ public class VpcTest extends TestCase { public void setUp() { ComponentContext.initComponentsLifeCycle(); Account account = new AccountVO("testaccount", 1, "testdomain", (short) 0, UUID.randomUUID().toString()); - UserContext.registerContext(1, account, null, true); + UserContext.register(1, account, null, true); vpc = new VpcVO(1, "myvpc", "myvpc", 2, 1, 1, "10.0.1.0/16", "mydomain"); } diff --git a/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java b/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java index 484b044e28e..99b168a77df 100644 --- a/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java +++ b/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java @@ -117,7 +117,7 @@ public class AffinityApiUnitTest { acct.setAccountName("user"); acct.setDomainId(domainId); - UserContext.registerContext(1, acct, null, true); + UserContext.register(1, acct, null, true); when(_acctMgr.finalizeOwner((Account) anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct); when(_processor.getType()).thenReturn("mock"); diff --git a/server/test/org/apache/cloudstack/lb/ApplicationLoadBalancerTest.java b/server/test/org/apache/cloudstack/lb/ApplicationLoadBalancerTest.java index 461cbbdf012..6e92a8433b0 100644 --- a/server/test/org/apache/cloudstack/lb/ApplicationLoadBalancerTest.java +++ b/server/test/org/apache/cloudstack/lb/ApplicationLoadBalancerTest.java @@ -133,7 +133,7 @@ public class ApplicationLoadBalancerTest extends TestCase{ Mockito.when(_accountMgr.getSystemUser()).thenReturn(new UserVO(1)); Mockito.when(_accountMgr.getSystemAccount()).thenReturn(new AccountVO(2)); - UserContext.registerContext(_accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount(), null, false); + UserContext.register(_accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount(), null, false); Mockito.when(_ntwkModel.areServicesSupportedInNetwork(Mockito.anyLong(), Mockito.any(Network.Service.class))).thenReturn(true); diff --git a/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java b/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java index f862a2a4760..0d3c7afd3c4 100644 --- a/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java +++ b/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java @@ -19,12 +19,6 @@ package org.apache.cloudstack.networkoffering; import java.io.IOException; -import org.apache.cloudstack.acl.SecurityChecker; -import org.apache.cloudstack.region.PortableIpDaoImpl; -import org.apache.cloudstack.region.dao.RegionDaoImpl; -import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; -import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl; -import org.apache.cloudstack.test.utils.SpringUtils; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -35,6 +29,13 @@ import org.springframework.core.type.classreading.MetadataReader; import org.springframework.core.type.classreading.MetadataReaderFactory; import org.springframework.core.type.filter.TypeFilter; +import org.apache.cloudstack.acl.SecurityChecker; +import org.apache.cloudstack.region.PortableIpDaoImpl; +import org.apache.cloudstack.region.PortableIpRangeDaoImpl; +import org.apache.cloudstack.region.dao.RegionDaoImpl; +import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl; +import org.apache.cloudstack.test.utils.SpringUtils; + import com.cloud.agent.AgentManager; import com.cloud.alert.AlertManager; import com.cloud.api.query.dao.UserAccountJoinDaoImpl; @@ -108,7 +109,6 @@ import com.cloud.user.AccountDetailsDao; import com.cloud.user.AccountManager; import com.cloud.user.ResourceLimitService; import com.cloud.user.UserContext; -import com.cloud.user.UserContextInitializer; import com.cloud.user.dao.AccountDaoImpl; import com.cloud.user.dao.UserDaoImpl; import com.cloud.vm.dao.InstanceGroupDaoImpl; @@ -116,7 +116,6 @@ import com.cloud.vm.dao.NicDaoImpl; import com.cloud.vm.dao.NicSecondaryIpDaoImpl; import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.VMInstanceDaoImpl; -import org.apache.cloudstack.region.PortableIpRangeDaoImpl; @Configuration @ComponentScan(basePackageClasses={ @@ -312,11 +311,6 @@ public class ChildTestConfiguration { return Mockito.mock(UserContext.class); } - @Bean - public UserContextInitializer userContextInitializer() { - return Mockito.mock(UserContextInitializer.class); - } - @Bean public NetworkManager networkManager() { return Mockito.mock(NetworkManager.class); diff --git a/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java b/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java index 4a2c867be6a..a23822bfc1e 100644 --- a/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java +++ b/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java @@ -86,7 +86,7 @@ public class CreateNetworkOfferingTest extends TestCase{ Mockito.when(accountMgr.getSystemUser()).thenReturn(new UserVO(1)); Mockito.when(accountMgr.getSystemAccount()).thenReturn(new AccountVO(2)); - UserContext.registerContext(accountMgr.getSystemUser().getId(), accountMgr.getSystemAccount(), null, false); + UserContext.register(accountMgr.getSystemUser().getId(), accountMgr.getSystemAccount(), null, false); } //Test Shared network offerings diff --git a/server/test/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImplTest.java b/server/test/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImplTest.java index ab545342cfa..44802e0ff37 100644 --- a/server/test/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImplTest.java +++ b/server/test/org/apache/cloudstack/region/gslb/GlobalLoadBalancingRulesServiceImplTest.java @@ -499,7 +499,7 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase { Account account = (Account) new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString()); when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account); - UserContext.registerContext(1, account, null, true); + UserContext.register(1, account, null, true); Field gslbRuleId = _class.getDeclaredField("id"); gslbRuleId.setAccessible(true); @@ -564,7 +564,7 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase { Account account = (Account) new AccountVO("testaccount", 3, "networkdomain", (short) 0, UUID.randomUUID().toString()); when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account); - UserContext.registerContext(1, account, null, true); + UserContext.register(1, account, null, true); Field gslbRuleId = _class.getDeclaredField("id"); gslbRuleId.setAccessible(true); @@ -651,7 +651,7 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase { Account account = (Account) new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString()); when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account); - UserContext.registerContext(1, account, null, true); + UserContext.register(1, account, null, true); Field gslbRuleId = _class.getDeclaredField("id"); gslbRuleId.setAccessible(true); @@ -710,7 +710,7 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase { Account account = (Account) new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString()); when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account); - UserContext.registerContext(1, account, null, true); + UserContext.register(1, account, null, true); Field gslbRuleId = _class.getDeclaredField("id"); gslbRuleId.setAccessible(true); @@ -783,7 +783,7 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase { Account account = (Account) new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString()); when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account); - UserContext.registerContext(1, account, null, true); + UserContext.register(1, account, null, true); Field gslbRuleId = _class.getDeclaredField("id"); gslbRuleId.setAccessible(true); @@ -845,7 +845,7 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase { Account account = (Account) new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString()); when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account); - UserContext.registerContext(1, account, null, true); + UserContext.register(1, account, null, true); Field gslbRuleId = _class.getDeclaredField("id"); gslbRuleId.setAccessible(true); @@ -891,7 +891,7 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase { Account account = (Account) new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString()); when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account); - UserContext.registerContext(1, account, null, true); + UserContext.register(1, account, null, true); Field gslbRuleId = _class.getDeclaredField("id"); gslbRuleId.setAccessible(true); @@ -939,7 +939,7 @@ public class GlobalLoadBalancingRulesServiceImplTest extends TestCase { Account account = (Account) new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString()); when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account); - UserContext.registerContext(1, account, null, true); + UserContext.register(1, account, null, true); Field gslbRuleId = _class.getDeclaredField("id"); gslbRuleId.setAccessible(true);