You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ch...@apache.org on 2013/07/17 19:35:05 UTC
[06/50] [abbrv] UserContext switched to CallContext. Added generic
storage mechanism for other code to carry information throughout a call. Made
the calling User and Account a must have. Added an interface to carry
entities in error. Fixed up the cod
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index 7bd2864..0a67cff 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -5,7 +5,7 @@
// 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,
@@ -44,6 +44,8 @@ import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.apache.cloudstack.api.command.admin.router.UpgradeRouterCmd;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.context.ServerContexts;
import com.cloud.agent.AgentManager;
import com.cloud.agent.AgentManager.OnError;
@@ -205,7 +207,6 @@ import com.cloud.storage.dao.VolumeDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.User;
-import com.cloud.user.UserContext;
import com.cloud.user.UserStatisticsVO;
import com.cloud.user.UserStatsLogVO;
import com.cloud.user.UserVO;
@@ -253,13 +254,12 @@ import com.cloud.vm.dao.NicIpAliasVO;
import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.dao.UserVmDetailsDao;
import com.cloud.vm.dao.VMInstanceDao;
-
/**
* VirtualNetworkApplianceManagerImpl manages the different types of virtual network appliances available in the Cloud Stack.
*/
@Component
@Local(value = { VirtualNetworkApplianceManager.class, VirtualNetworkApplianceService.class })
-public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements VirtualNetworkApplianceManager, VirtualNetworkApplianceService,
+public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements VirtualNetworkApplianceManager, VirtualNetworkApplianceService,
VirtualMachineGuru<DomainRouterVO>, Listener {
private static final Logger s_logger = Logger.getLogger(VirtualNetworkApplianceManagerImpl.class);
@@ -431,7 +431,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 = CallContext.current().getCallingAccount();
DomainRouterVO router = _routerDao.findById(routerId);
if (router == null) {
@@ -467,7 +467,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
// Check that the service offering being upgraded to has the same storage pool preference as the VM's current service
// offering
if (currentServiceOffering.getUseLocalStorage() != newServiceOffering.getUseLocalStorage()) {
- throw new InvalidParameterValueException("Can't upgrade, due to new local storage status : " +
+ throw new InvalidParameterValueException("Can't upgrade, due to new local storage status : " +
newServiceOffering.getUseLocalStorage() + " is different from "
+ "curruent local storage status: " + currentServiceOffering.getUseLocalStorage());
}
@@ -541,8 +541,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
@Override @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();
+ CallContext context = CallContext.current();
+ 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(CallContext.current().getCallingUserId());
VirtualRouter virtualRouter = stop(router, forced, user, account);
if(virtualRouter == null){
@@ -602,9 +602,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
@Override @ActionEvent(eventType = EventTypes.EVENT_ROUTER_REBOOT, eventDescription = "rebooting router Vm", async = true)
- public VirtualRouter rebootRouter(long routerId, boolean reprogramNetwork) throws ConcurrentOperationException,
+ public VirtualRouter rebootRouter(long routerId, boolean reprogramNetwork) throws ConcurrentOperationException,
ResourceUnavailableException, InsufficientCapacityException {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
// verify parameters
DomainRouterVO router = _routerDao.findById(routerId);
@@ -621,7 +621,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
DataCenter.class, router.getDataCenterId());
}
- UserVO user = _userDao.findById(UserContext.current().getCallerUserId());
+ UserVO user = _userDao.findById(CallContext.current().getCallingUserId());
s_logger.debug("Stopping and starting router " + router + " as a part of router reboot");
if (stop(router, false, user, caller) != null) {
@@ -666,11 +666,11 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
value = configs.get("router.check.poolsize");
_rvrStatusUpdatePoolSize = NumbersUtil.parseInt(value, 10);
- /*
+ /*
* We assume that one thread can handle 20 requests in 1 minute in normal situation, so here we give the queue size up to 50 minutes.
* It's mostly for buffer, since each time CheckRouterTask running, it would add all the redundant networks in the queue immediately
*/
- _vrUpdateQueue = new LinkedBlockingQueue<Long>(_rvrStatusUpdatePoolSize * 1000);
+ _vrUpdateQueue = new LinkedBlockingQueue<Long>(_rvrStatusUpdatePoolSize * 1000);
_rvrStatusUpdateExecutor = Executors.newFixedThreadPool(_rvrStatusUpdatePoolSize, new NamedThreadFactory("RedundantRouterStatusMonitor"));
@@ -796,7 +796,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
return VirtualMachineName.getRouterId(vmName);
}
- private VmDataCommand generateVmDataCommand(VirtualRouter router, String vmPrivateIpAddress, String userData,
+ private VmDataCommand generateVmDataCommand(VirtualRouter router, String vmPrivateIpAddress, String userData,
String serviceOffering, String zoneName, String guestIpAddress, String vmName,
String vmInstanceName, long vmId, String vmUuid, String publicKey, long guestNetworkId) {
VmDataCommand cmd = new VmDataCommand(vmPrivateIpAddress, vmName, _networkModel.getExecuteInSeqNtwkElmtCmd());
@@ -860,6 +860,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
@Override
public void run() {
+ ServerContexts.registerSystemContext();
try{
final List<DomainRouterVO> routers = _routerDao.listByStateAndNetworkType(State.Running, GuestType.Isolated, mgmtSrvrId);
s_logger.debug("Found " + routers.size() + " running routers. ");
@@ -873,7 +874,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
for (Nic routerNic : routerNics) {
Network network = _networkModel.getNetwork(routerNic.getNetworkId());
//Send network usage command for public nic in VPC VR
- //Send network usage command for isolated guest nic of non VPC VR
+ //Send network usage command for isolated guest nic of non VPC VR
if ((forVpc && network.getTrafficType() == TrafficType.Public) || (!forVpc && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Isolated)) {
final NetworkUsageCommand usageCmd = new NetworkUsageCommand(privateIP, router.getHostName(),
forVpc, routerNic.getIp4Address());
@@ -957,6 +958,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
} catch (Exception e) {
s_logger.warn("Error while collecting network stats", e);
+ } finally {
+ ServerContexts.unregisterSystemContext();
}
}
}
@@ -986,12 +989,12 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
List<UserStatisticsVO> updatedStats = _userStatsDao.listUpdatedStats();
Date updatedTime = new Date();
for(UserStatisticsVO stat : updatedStats){
- //update agg bytes
+ //update agg bytes
stat.setAggBytesReceived(stat.getCurrentBytesReceived() + stat.getNetBytesReceived());
stat.setAggBytesSent(stat.getCurrentBytesSent() + stat.getNetBytesSent());
_userStatsDao.update(stat.getId(), stat);
//insert into op_user_stats_log
- UserStatsLogVO statsLog = new UserStatsLogVO(stat.getId(), stat.getNetBytesReceived(), stat.getNetBytesSent(), stat.getCurrentBytesReceived(),
+ UserStatsLogVO statsLog = new UserStatsLogVO(stat.getId(), stat.getNetBytesReceived(), stat.getNetBytesSent(), stat.getCurrentBytesReceived(),
stat.getCurrentBytesSent(), stat.getAggBytesReceived(), stat.getAggBytesSent(), updatedTime);
_userStatsLogDao.persist(statsLog);
}
@@ -1083,7 +1086,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
if (oldState != conn.getState()) {
String title = "Site-to-site Vpn Connection to " + gw.getName() +
" just switch from " + oldState + " to " + conn.getState();
- String context = "Site-to-site Vpn Connection to " + gw.getName() + " on router " + router.getHostName() +
+ String context = "Site-to-site Vpn Connection to " + gw.getName() + " on router " + router.getHostName() +
"(id: " + router.getId() + ") " + " just switch from " + oldState + " to " + conn.getState();
s_logger.info(context);
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_DOMAIN_ROUTER,
@@ -1168,8 +1171,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());
@@ -1281,45 +1282,49 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
@Override
public void run() {
- while (true) {
+ ServerContexts.registerSystemContext();
try {
- Long networkId = _vrUpdateQueue.take();
- List <DomainRouterVO> routers = _routerDao.listByNetworkAndRole(networkId, Role.VIRTUAL_ROUTER);
-
- 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;
+ while (true) {
+ try {
+ Long networkId = _vrUpdateQueue.take(); // This is a blocking call so this thread won't run all the time if no work item in queue.
+ List <DomainRouterVO> routers = _routerDao.listByNetworkAndRole(networkId, Role.VIRTUAL_ROUTER);
+
+ 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);
}
- updateRoutersRedundantState(routers);
- checkDuplicateMaster(routers);
- checkSanity(routers);
- } catch (Exception ex) {
- s_logger.error("Fail to complete the RvRStatusUpdateTask! ", ex);
}
+ } finally {
+ ServerContexts.unregisterSystemContext();
}
}
-
}
protected class CheckRouterTask implements Runnable {
@@ -1329,6 +1334,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
@Override
public void run() {
+ ServerContexts.registerSystemContext();
try {
final List<DomainRouterVO> routers = _routerDao.listIsolatedByHostId(null);
s_logger.debug("Found " + routers.size() + " routers to update status. ");
@@ -1345,6 +1351,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
} catch (Exception ex) {
s_logger.error("Fail to complete the CheckRouterTask! ", ex);
+ } finally {
+ ServerContexts.unregisterSystemContext();
}
}
}
@@ -1402,7 +1410,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
for (HostVO h : hosts) {
if (h.getStatus() == Status.Up) {
- s_logger.debug("Pick up host that has hypervisor type " + h.getHypervisorType() + " in cluster " +
+ s_logger.debug("Pick up host that has hypervisor type " + h.getHypervisorType() + " in cluster " +
cv.getId() + " to start domain router for OVM");
return h.getHypervisorType();
}
@@ -1419,7 +1427,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
@DB
protected List<DomainRouterVO> findOrDeployVirtualRouterInGuestNetwork(Network guestNetwork, DeployDestination dest, Account owner,
- boolean isRedundant, Map<Param, Object> params) throws ConcurrentOperationException,
+ boolean isRedundant, Map<Param, Object> params) throws ConcurrentOperationException,
InsufficientCapacityException, ResourceUnavailableException {
List<DomainRouterVO> routers = new ArrayList<DomainRouterVO>();
@@ -1642,9 +1650,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
offerHA = false;
}
- router = new DomainRouterVO(id, routerOffering.getId(), vrProvider.getId(),
+ router = new DomainRouterVO(id, routerOffering.getId(), vrProvider.getId(),
VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(),
- template.getGuestOSId(), owner.getDomainId(), owner.getId(), isRedundant, 0, false,
+ template.getGuestOSId(), owner.getDomainId(), owner.getId(), isRedundant, 0, false,
RedundantState.UNKNOWN, offerHA, false, vpcId);
router.setRole(Role.VIRTUAL_ROUTER);
router = _itMgr.allocate(router, template, routerOffering, networks, plan, null, owner);
@@ -1687,7 +1695,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
- protected List<HypervisorType> getHypervisors(DeployDestination dest, DeploymentPlan plan,
+ protected List<HypervisorType> getHypervisors(DeployDestination dest, DeploymentPlan plan,
List<HypervisorType> supportedHypervisors) throws InsufficientServerCapacityException {
List<HypervisorType> hypervisors = new ArrayList<HypervisorType>();
@@ -1758,7 +1766,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) {
defaultNetworkStartIp = startIp;
} else if (s_logger.isDebugEnabled()){
- s_logger.debug("First ipv4 " + startIp + " in network id=" + guestNetwork.getId() +
+ s_logger.debug("First ipv4 " + startIp + " in network id=" + guestNetwork.getId() +
" is already allocated, can't use it for domain router; will get random ip address from the range");
}
}
@@ -1767,13 +1775,13 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
if (guestNetwork.getIp6Cidr() != null) {
if (placeholder != null && placeholder.getIp6Address() != null) {
s_logger.debug("Requesting ipv6 address " + placeholder.getIp6Address() + " stored in placeholder nic for the network " + guestNetwork);
- defaultNetworkStartIpv6 = placeholder.getIp6Address();
+ defaultNetworkStartIpv6 = placeholder.getIp6Address();
} else {
String startIpv6 = _networkModel.getStartIpv6Address(guestNetwork.getId());
if (startIpv6 != null && _ipv6Dao.findByNetworkIdAndIp(guestNetwork.getId(), startIpv6) == null) {
defaultNetworkStartIpv6 = startIpv6;
} else if (s_logger.isDebugEnabled()){
- s_logger.debug("First ipv6 " + startIpv6 + " in network id=" + guestNetwork.getId() +
+ s_logger.debug("First ipv6 " + startIpv6 + " in network id=" + guestNetwork.getId() +
" is already allocated, can't use it for domain router; will get random ipv6 address from the range");
}
}
@@ -1842,7 +1850,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
- protected Pair<DeploymentPlan, List<DomainRouterVO>> getDeploymentPlanAndRouters(boolean isPodBased,
+ protected Pair<DeploymentPlan, List<DomainRouterVO>> getDeploymentPlanAndRouters(boolean isPodBased,
DeployDestination dest, long guestNetworkId) {
long dcId = dest.getDataCenter().getId();
List<DomainRouterVO> routers = null;
@@ -1865,7 +1873,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
- private DomainRouterVO startVirtualRouter(DomainRouterVO router, User user, Account caller, Map<Param, Object> params)
+ private DomainRouterVO startVirtualRouter(DomainRouterVO router, User user, Account caller, Map<Param, Object> params)
throws StorageUnavailableException, InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException {
@@ -1908,7 +1916,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
}
if (routerToBeAvoid == null) {
- return this.start(router, user, caller, params, null);
+ return this.start(router, user, caller, params, null);
}
// We would try best to deploy the router to another place
int retryIndex = 5;
@@ -1945,7 +1953,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
@Override
- public List<DomainRouterVO> deployVirtualRouterInGuestNetwork(Network guestNetwork, DeployDestination dest, Account owner,
+ public List<DomainRouterVO> deployVirtualRouterInGuestNetwork(Network guestNetwork, DeployDestination dest, Account owner,
Map<Param, Object> params, boolean isRedundant) throws InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException {
@@ -1985,7 +1993,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
@Override
- public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<DomainRouterVO> profile, DeployDestination dest,
+ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<DomainRouterVO> profile, DeployDestination dest,
ReservationContext context) {
boolean dnsProvided = true;
@@ -2048,7 +2056,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
// DOMR control command is sent over management server in VMware
if (dest.getHost().getHypervisorType() == HypervisorType.VMware) {
if (s_logger.isInfoEnabled()) {
- s_logger.info("Check if we need to add management server explicit route to DomR. pod cidr: "
+ s_logger.info("Check if we need to add management server explicit route to DomR. pod cidr: "
+ dest.getPod().getCidrAddress() + "/" + dest.getPod().getCidrSize()
+ ", pod gateway: " + dest.getPod().getGateway() + ", management host: " + _mgmt_host);
}
@@ -2106,7 +2114,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
type = "router";
if (_disable_rp_filter) {
rpFilter=" disable_rp_filter=true";
- }
+ }
}
if (_disable_rp_filter) {
@@ -2124,8 +2132,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
buf.append(" extra_pubnics=" + _routerExtraPublicNics);
}
- /* If virtual router didn't provide DNS service but provide DHCP service, we need to override the DHCP response
- * to return DNS server rather than
+ /* If virtual router didn't provide DNS service but provide DHCP service, we need to override the DHCP response
+ * to return DNS server rather than
* virtual router itself. */
if (dnsProvided || dhcpProvided) {
if (defaultDns1 != null) {
@@ -2161,7 +2169,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
- protected StringBuilder createGuestBootLoadArgs(NicProfile guestNic, String defaultDns1,
+ protected StringBuilder createGuestBootLoadArgs(NicProfile guestNic, String defaultDns1,
String defaultDns2, DomainRouterVO router) {
long guestNetworkId = guestNic.getNetworkId();
NetworkVO guestNetwork = _networkDao.findById(guestNetworkId);
@@ -2203,7 +2211,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
if (cidr != null) {
dhcpRange = NetUtils.getIpRangeStartIpFromCidr(cidr, cidrSize);
}
- }
+ }
} else if (dc.getNetworkType() == NetworkType.Advanced) {
String cidr = guestNetwork.getCidr();
if (cidr != null) {
@@ -2268,7 +2276,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
@Override
- public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile<DomainRouterVO> profile,
+ public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile<DomainRouterVO> profile,
DeployDestination dest, ReservationContext context) throws ResourceUnavailableException {
DomainRouterVO router = profile.getVirtualMachine();
@@ -2303,7 +2311,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
// restart network if restartNetwork = false is not specified in profile parameters
boolean reprogramGuestNtwks = true;
- if (profile.getParameter(Param.ReProgramGuestNetworks) != null
+ if (profile.getParameter(Param.ReProgramGuestNetworks) != null
&& (Boolean) profile.getParameter(Param.ReProgramGuestNetworks) == false) {
reprogramGuestNtwks = false;
}
@@ -2509,7 +2517,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
}
- protected void finalizeIpAssocForNetwork(Commands cmds, VirtualRouter router, Provider provider,
+ protected void finalizeIpAssocForNetwork(Commands cmds, VirtualRouter router, Provider provider,
Long guestNetworkId, Map<String, String> vlanMacAddress) {
ArrayList<? extends PublicIpAddress> publicIps = getPublicIpsToApply(router, provider, guestNetworkId);
@@ -2523,7 +2531,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
}
- protected ArrayList<? extends PublicIpAddress> getPublicIpsToApply(VirtualRouter router, Provider provider,
+ protected ArrayList<? extends PublicIpAddress> getPublicIpsToApply(VirtualRouter router, Provider provider,
Long guestNetworkId, com.cloud.network.IpAddress.State... skipInStates) {
long ownerId = router.getAccountId();
final List<? extends IpAddress> userIps = _networkModel.listPublicIpsAssignedToGuestNtwk(ownerId, guestNetworkId, null);
@@ -2642,7 +2650,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
@Override
- public boolean startRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List<? extends VirtualRouter> routers)
+ public boolean startRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List<? extends VirtualRouter> routers)
throws ResourceUnavailableException {
if (routers == null || routers.isEmpty()) {
s_logger.warn("Failed to start remote access VPN: no router found for account and zone");
@@ -2653,7 +2661,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
for (VirtualRouter router : routers) {
if (router.getState() != State.Running) {
s_logger.warn("Failed to start remote access VPN: router not in right state " + router.getState());
- throw new ResourceUnavailableException("Failed to start remote access VPN: router not in right state "
+ throw new ResourceUnavailableException("Failed to start remote access VPN: router not in right state "
+ router.getState(), DataCenter.class, network.getDataCenterId());
}
@@ -2668,16 +2676,16 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
Answer answer = cmds.getAnswer("users");
if (!answer.getResult()) {
- s_logger.error("Unable to start vpn: unable add users to vpn in zone " + router.getDataCenterId()
+ s_logger.error("Unable to start vpn: unable add users to vpn in zone " + router.getDataCenterId()
+ " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName()
+ " due to " + answer.getDetails());
- throw new ResourceUnavailableException("Unable to start vpn: Unable to add users to vpn in zone " +
+ throw new ResourceUnavailableException("Unable to start vpn: Unable to add users to vpn in zone " +
router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: "
+ router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
}
answer = cmds.getAnswer("startVpn");
if (!answer.getResult()) {
- s_logger.error("Unable to start vpn in zone " + router.getDataCenterId() + " for account " +
+ s_logger.error("Unable to start vpn in zone " + router.getDataCenterId() + " for account " +
vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to "
+ answer.getDetails());
throw new ResourceUnavailableException("Unable to start vpn in zone " + router.getDataCenterId()
@@ -2691,7 +2699,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
@Override
- public boolean deleteRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List<? extends VirtualRouter> routers)
+ public boolean deleteRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List<? extends VirtualRouter> routers)
throws ResourceUnavailableException {
if (routers == null || routers.isEmpty()) {
s_logger.warn("Failed to delete remote access VPN: no router found for account and zone");
@@ -2704,7 +2712,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
Commands cmds = new Commands(OnError.Continue);
IpAddress ip = _networkModel.getIp(vpn.getServerAddressId());
- RemoteAccessVpnCfgCommand removeVpnCmd = new RemoteAccessVpnCfgCommand(false, ip.getAddress().addr(),
+ RemoteAccessVpnCfgCommand removeVpnCmd = new RemoteAccessVpnCfgCommand(false, ip.getAddress().addr(),
vpn.getLocalIp(), vpn.getIpRange(), vpn.getIpsecPresharedKey());
removeVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
removeVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(network.getId(), router.getId()));
@@ -2721,7 +2729,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
continue;
} else {
s_logger.warn("Failed to delete remote access VPN: domR " + router + " is not in right state " + router.getState());
- throw new ResourceUnavailableException("Failed to delete remote access VPN: domR is not in right state " +
+ throw new ResourceUnavailableException("Failed to delete remote access VPN: domR is not in right state " +
router.getState(), DataCenter.class, network.getDataCenterId());
}
}
@@ -2730,7 +2738,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
- private DomainRouterVO start(DomainRouterVO router, User user, Account caller, Map<Param, Object> params, DeploymentPlan planToDeploy)
+ private DomainRouterVO start(DomainRouterVO router, User user, Account caller, Map<Param, Object> params, DeploymentPlan planToDeploy)
throws StorageUnavailableException, InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException {
s_logger.debug("Starting router " + router);
@@ -2807,7 +2815,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 = CallContext.current().getCallingAccount();
List<VlanVO> vlanList = _vlanDao.listVlansByNetworkIdAndGateway(network.getId(), nic.getGateway());
List<Long> vlanDbIdList = new ArrayList<Long>();
for (VlanVO vlan : vlanList) {
@@ -2829,7 +2837,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(), CallContext.current().getCallingAccountId(), network.getDomainId(), nic.getNetworkId(),nic.getGateway(), nic.getNetmask());
alias.setAliasCount((routerPublicIP.getIpMacAddress()));
_nicIpAliasDao.persist(alias);
List<IpAliasTO> ipaliasTo = new ArrayList<IpAliasTO>();
@@ -2894,7 +2902,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
@Override
- public boolean applyDhcpEntry(Network network, final NicProfile nic, VirtualMachineProfile<UserVm> profile,
+ public boolean applyDhcpEntry(Network network, final NicProfile nic, VirtualMachineProfile<UserVm> profile,
DeployDestination dest, List<DomainRouterVO> routers)
throws ResourceUnavailableException {
if(s_logger.isTraceEnabled()) {
@@ -2908,7 +2916,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
boolean podLevelException = false;
//for user vm in Basic zone we should try to re-deploy vm in a diff pod if it fails to deploy in original pod; so throwing exception with Pod scope
- if (isZoneBasic && podId != null && updatedProfile.getVirtualMachine().getType() == VirtualMachine.Type.User
+ if (isZoneBasic && podId != null && updatedProfile.getVirtualMachine().getType() == VirtualMachine.Type.User
&& network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Shared) {
podLevelException = true;
}
@@ -2982,7 +2990,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
boolean podLevelException = false;
//for user vm in Basic zone we should try to re-deploy vm in a diff pod if it fails to deploy in original pod; so throwing exception with Pod scope
- if (isZoneBasic && podId != null && updatedProfile.getVirtualMachine().getType() == VirtualMachine.Type.User
+ if (isZoneBasic && podId != null && updatedProfile.getVirtualMachine().getType() == VirtualMachine.Type.User
&& network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Shared) {
podLevelException = true;
}
@@ -3014,7 +3022,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
public String[] applyVpnUsers(Network network, List<? extends VpnUser> users, List<DomainRouterVO> routers) throws ResourceUnavailableException {
if (routers == null || routers.isEmpty()) {
s_logger.warn("Failed to add/remove VPN users: no router found for account and zone");
- throw new ResourceUnavailableException("Unable to assign ip addresses, domR doesn't exist for network " +
+ throw new ResourceUnavailableException("Unable to assign ip addresses, domR doesn't exist for network " +
network.getId(), DataCenter.class, network.getDataCenterId());
}
@@ -3023,7 +3031,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
for (DomainRouterVO router : routers) {
if (router.getState() != State.Running) {
s_logger.warn("Failed to add/remove VPN users: router not in running state");
- throw new ResourceUnavailableException("Unable to assign ip addresses, domR is not in right state " +
+ throw new ResourceUnavailableException("Unable to assign ip addresses, domR is not in right state " +
router.getState(), DataCenter.class, network.getDataCenterId());
}
@@ -3088,10 +3096,10 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
@Override
- public VirtualRouter startRouter(long routerId, boolean reprogramNetwork) throws ResourceUnavailableException,
+ 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 = CallContext.current().getCallingAccount();
+ User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
// verify parameters
DomainRouterVO router = _routerDao.findById(routerId);
@@ -3127,7 +3135,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
return router;
}
- UserVO user = _userDao.findById(UserContext.current().getCallerUserId());
+ UserVO user = _userDao.findById(CallContext.current().getCallingUserId());
Map<Param, Object> params = new HashMap<Param, Object>();
if (reprogramNetwork) {
params.put(Param.ReProgramGuestNetworks, true);
@@ -3209,7 +3217,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
vifMacAddress = ipAddr.getMacAddress();
}
- IpAddressTO ip = new IpAddressTO(ipAddr.getAccountId(), ipAddr.getAddress().addr(), add, firstIP,
+ IpAddressTO ip = new IpAddressTO(ipAddr.getAccountId(), ipAddr.getAddress().addr(), add, firstIP,
sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress, networkRate, ipAddr.isOneToOneNat());
ip.setTrafficType(network.getTrafficType());
@@ -3307,13 +3315,13 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
Network guestNetwork = _networkModel.getNetwork(guestNetworkId);
Nic nic = _nicDao.findByNtwkIdAndInstanceId(guestNetwork.getId(), router.getId());
- NicProfile nicProfile = new NicProfile(nic, guestNetwork, nic.getBroadcastUri(), nic.getIsolationUri(),
- _networkModel.getNetworkRate(guestNetwork.getId(), router.getId()),
- _networkModel.isSecurityGroupSupportedInNetwork(guestNetwork),
+ NicProfile nicProfile = new NicProfile(nic, guestNetwork, nic.getBroadcastUri(), nic.getIsolationUri(),
+ _networkModel.getNetworkRate(guestNetwork.getId(), router.getId()),
+ _networkModel.isSecurityGroupSupportedInNetwork(guestNetwork),
_networkModel.getNetworkTag(router.getHypervisorType(), guestNetwork));
- LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lbs,routerPublicIp,
- getRouterIpInNetwork(guestNetworkId, router.getId()),router.getPrivateIpAddress(),
+ LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lbs,routerPublicIp,
+ getRouterIpInNetwork(guestNetworkId, router.getId()),router.getPrivateIpAddress(),
_itMgr.toNicTO(nicProfile, router.getHypervisorType()), router.getVpcId());
cmd.lbStatsVisibility = _configDao.getValue(Config.NetworkLBHaproxyStatsVisbility.key());
@@ -3350,7 +3358,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
IpAddress ip = _networkModel.getIp(vpn.getServerAddressId());
- RemoteAccessVpnCfgCommand startVpnCmd = new RemoteAccessVpnCfgCommand(true, ip.getAddress().addr(),
+ RemoteAccessVpnCfgCommand startVpnCmd = new RemoteAccessVpnCfgCommand(true, ip.getAddress().addr(),
vpn.getLocalIp(), vpn.getIpRange(), vpn.getIpsecPresharedKey());
startVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
startVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(vpn.getNetworkId(), router.getId()));
@@ -3369,7 +3377,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
// password should be set only on default network element
if (password != null && nic.isDefaultNic()) {
String encodedPassword = PasswordGenerator.rot13(password);
- // We would unset password for BACKUP router in the RvR, to prevent user from accidently reset the
+ // We would unset password for BACKUP router in the RvR, to prevent user from accidently reset the
// password again after BACKUP become MASTER
if (router.getIsRedundantRouter() && router.getRedundantState() != RedundantState.MASTER) {
encodedPassword = PasswordGenerator.rot13("saved_password");
@@ -3663,7 +3671,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList, sourceIp);
lbRules.add(loadBalancing);
}
- return sendLBRules(router, lbRules, network.getId());
+ return sendLBRules(router, lbRules, network.getId());
}
});
}
@@ -3756,7 +3764,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
boolean execute(Network network, VirtualRouter router) throws ResourceUnavailableException;
}
- protected boolean applyRules(Network network, List<? extends VirtualRouter> routers, String typeString,
+ protected boolean applyRules(Network network, List<? extends VirtualRouter> routers, String typeString,
boolean isPodLevelException, Long podId, boolean failWhenDisconnect, RuleApplier applier) throws ResourceUnavailableException {
if (routers == null || routers.isEmpty()) {
s_logger.warn("Unable to apply " + typeString + ", virtual router doesn't exist in the network " + network.getId());
@@ -3779,11 +3787,11 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
if (router.isStopPending()) {
if (_hostDao.findById(router.getHostId()).getStatus() == Status.Up) {
- throw new ResourceUnavailableException("Unable to process due to the stop pending router " +
+ throw new ResourceUnavailableException("Unable to process due to the stop pending router " +
router.getInstanceName() + " haven't been stopped after it's host coming back!",
DataCenter.class, router.getDataCenterId());
}
- s_logger.debug("Router " + router.getInstanceName() + " is stop pending, so not sending apply " +
+ s_logger.debug("Router " + router.getInstanceName() + " is stop pending, so not sending apply " +
typeString + " commands to the backend");
continue;
}
@@ -3805,15 +3813,15 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
} else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
- s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() +
+ s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() +
", so not sending apply " + typeString + " commands to the backend");
} else {
s_logger.warn("Unable to apply " + typeString +", virtual router is not in the right state " + router.getState());
if (isZoneBasic && isPodLevelException) {
- throw new ResourceUnavailableException("Unable to apply " + typeString +
+ throw new ResourceUnavailableException("Unable to apply " + typeString +
", virtual router is not in the right state", Pod.class, podId);
}
- throw new ResourceUnavailableException("Unable to apply " + typeString +
+ throw new ResourceUnavailableException("Unable to apply " + typeString +
", virtual router is not in the right state", DataCenter.class, router.getDataCenterId());
}
}
@@ -3870,7 +3878,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
rulesTO = new ArrayList<StaticNatRuleTO>();
for (StaticNat rule : rules) {
IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
- StaticNatRuleTO ruleTO = new StaticNatRuleTO(0, sourceIp.getAddress().addr(), null,
+ StaticNatRuleTO ruleTO = new StaticNatRuleTO(0, sourceIp.getAddress().addr(), null,
null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false);
rulesTO.add(ruleTO);
}
@@ -3907,8 +3915,6 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
@Override
public void processConnect(Host host, StartupCommand cmd, boolean forRebalance) throws ConnectionException {
- UserContext context = UserContext.current();
- context.setAccountId(1);
List<DomainRouterVO> routers = _routerDao.listIsolatedByHostId(host.getId());
for (DomainRouterVO router : routers) {
if (router.isStopPending()) {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/src/com/cloud/network/rules/RulesManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/rules/RulesManagerImpl.java b/server/src/com/cloud/network/rules/RulesManagerImpl.java
index 397ece8..4c1fa37 100755
--- a/server/src/com/cloud/network/rules/RulesManagerImpl.java
+++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java
@@ -26,6 +26,8 @@ import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.cloudstack.api.command.user.firewall.ListPortForwardingRulesCmd;
+import org.apache.cloudstack.context.CallContext;
+
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@@ -63,7 +65,6 @@ import com.cloud.tags.dao.ResourceTagDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.DomainManager;
-import com.cloud.user.UserContext;
import com.cloud.uservm.UserVm;
import com.cloud.utils.Pair;
import com.cloud.utils.Ternary;
@@ -189,8 +190,8 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
@ActionEvent(eventType = EventTypes.EVENT_NET_RULE_ADD, eventDescription = "creating forwarding rule", create = true)
public PortForwardingRule createPortForwardingRule(PortForwardingRule rule, Long vmId, Ip vmIp, boolean openFirewall)
throws NetworkRuleConflictException {
- UserContext ctx = UserContext.current();
- Account caller = ctx.getCaller();
+ CallContext ctx = CallContext.current();
+ Account caller = ctx.getCallingAccount();
Long ipAddrId = rule.getSourceIpAddressId();
@@ -317,7 +318,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
if (!_firewallDao.setStateToAdd(newRule)) {
throw new CloudRuntimeException("Unable to update the state to add for " + newRule);
}
- UserContext.current().setEventDetails("Rule Id: " + newRule.getId());
+ CallContext.current().setEventDetails("Rule Id: " + newRule.getId());
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_RULE_ADD, newRule.getAccountId(),
ipAddress.getDataCenterId(), newRule.getId(), null, PortForwardingRule.class.getName(),
newRule.getUuid());
@@ -352,7 +353,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 = CallContext.current().getCallingAccount();
Long ipAddrId = rule.getSourceIpAddressId();
@@ -399,7 +400,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
if (!_firewallDao.setStateToAdd(newRule)) {
throw new CloudRuntimeException("Unable to update the state to add for " + newRule);
}
- UserContext.current().setEventDetails("Rule Id: " + newRule.getId());
+ CallContext.current().setEventDetails("Rule Id: " + newRule.getId());
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_RULE_ADD, newRule.getAccountId(), 0, newRule.getId(),
null, FirewallRule.class.getName(), newRule.getUuid());
@@ -433,9 +434,9 @@ 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();
- UserContext.current().setEventDetails("Ip Id: " + ipId);
+ CallContext ctx = CallContext.current();
+ Account caller = ctx.getCallingAccount();
+ CallContext.current().setEventDetails("Ip Id: " + ipId);
// Verify input parameters
IPAddressVO ipAddress = _ipAddressDao.findById(ipId);
@@ -569,7 +570,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);
@@ -655,8 +656,8 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
@Override
@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();
+ CallContext ctx = CallContext.current();
+ Account caller = ctx.getCallingAccount();
PortForwardingRuleVO rule = _portForwardingDao.findById(ruleId);
if (rule == null) {
@@ -665,7 +666,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;
@@ -690,8 +691,8 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
@Override
@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();
+ CallContext ctx = CallContext.current();
+ Account caller = ctx.getCallingAccount();
FirewallRuleVO rule = _firewallDao.findById(ruleId);
if (rule == null) {
@@ -700,7 +701,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;
@@ -764,7 +765,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
Long id = cmd.getId();
Map<String, String> tags = cmd.getTags();
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
List<Long> permittedAccounts = new ArrayList<Long>();
if (ipId != null) {
@@ -977,7 +978,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
@Override
public Pair<List<? extends FirewallRule>, 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 = CallContext.current().getCallingAccount();
List<Long> permittedAccounts = new ArrayList<Long>();
if (ipId != null) {
@@ -1182,8 +1183,8 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
@Override
@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();
+ CallContext ctx = CallContext.current();
+ Account caller = ctx.getCallingAccount();
IPAddressVO ipAddress = _ipAddressDao.findById(ipId);
checkIpAndUserVm(ipAddress, null, caller);
@@ -1211,7 +1212,7 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
}
}
- return disableStaticNat(ipId, caller, ctx.getCallerUserId(), false);
+ return disableStaticNat(ipId, caller, ctx.getCallingUserId(), false);
}
@Override
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java b/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java
index ce6f8ac..d4460f1 100755
--- a/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java
+++ b/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java
@@ -43,10 +43,12 @@ import org.apache.cloudstack.api.command.user.securitygroup.CreateSecurityGroupC
import org.apache.cloudstack.api.command.user.securitygroup.DeleteSecurityGroupCmd;
import org.apache.cloudstack.api.command.user.securitygroup.RevokeSecurityGroupEgressCmd;
import org.apache.cloudstack.api.command.user.securitygroup.RevokeSecurityGroupIngressCmd;
+
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.log4j.Logger;
import com.amazonaws.services.identitymanagement.model.User;
+
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.NetworkRulesSystemVmCommand;
import com.cloud.agent.api.NetworkRulesVmSecondaryIpCommand;
@@ -75,7 +77,6 @@ import com.cloud.tags.dao.ResourceTagDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.DomainManager;
-import com.cloud.user.UserContext;
import com.cloud.user.dao.AccountDao;
import com.cloud.uservm.UserVm;
import com.cloud.utils.NumbersUtil;
@@ -97,8 +98,12 @@ import com.cloud.vm.dao.NicDao;
import com.cloud.vm.dao.NicSecondaryIpDao;
import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.dao.VMInstanceDao;
+
import edu.emory.mathcs.backport.java.util.Collections;
+
import org.apache.cloudstack.api.command.user.securitygroup.*;
+import org.apache.cloudstack.context.CallContext;
+
import java.util.*;
@Local(value = { SecurityGroupManager.class, SecurityGroupService.class })
@@ -596,7 +601,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 = CallContext.current().getCallingAccount();
Account owner = _accountMgr.getAccount(securityGroup.getAccountId());
if (owner == null) {
@@ -773,7 +778,7 @@ public class SecurityGroupManagerImpl extends ManagerBase implements SecurityGro
private boolean revokeSecurityGroupRule(Long id, SecurityRuleType type) {
// input validation
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
SecurityGroupRuleVO rule = _securityGroupRuleDao.findById(id);
if (rule == null) {
@@ -827,7 +832,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 = CallContext.current().getCallingAccount();
Account owner = _accountMgr.finalizeOwner(caller, cmd.getAccountName(), cmd.getDomainId(), cmd.getProjectId());
if (_securityGroupDao.isNameInUse(owner.getId(), owner.getDomainId(), cmd.getSecurityGroupName())) {
@@ -1066,7 +1071,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 = CallContext.current().getCallingAccount();
SecurityGroupVO group = _securityGroupDao.findById(groupId);
if (group == null) {
@@ -1318,7 +1323,7 @@ public class SecurityGroupManagerImpl extends ManagerBase implements SecurityGro
return true;
}
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
for (SecurityGroupVO securityGroup: vmSgGrps) {
Account owner = _accountMgr.getAccount(securityGroup.getAccountId());
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java b/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java
index 5c45a86..1028d74 100644
--- a/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java
+++ b/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java
@@ -35,16 +35,19 @@ import com.cloud.offering.NetworkOffering;
import com.cloud.tags.dao.ResourceTagDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
-import com.cloud.user.UserContext;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
+
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
+import org.apache.cloudstack.context.CallContext;
+
import javax.ejb.Local;
import javax.inject.Inject;
+
import java.util.ArrayList;
import java.util.List;
@@ -232,7 +235,7 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana
if (!_networkACLItemDao.setStateToAdd(newRule)) {
throw new CloudRuntimeException("Unable to update the state to add for " + newRule);
}
- UserContext.current().setEventDetails("ACL Item Id: " + newRule.getId());
+ CallContext.current().setEventDetails("ACL Item Id: " + newRule.getId());
txn.commit();
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java b/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java
index 4c97869..274ca44 100644
--- a/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java
+++ b/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java
@@ -31,7 +31,6 @@ import com.cloud.tags.ResourceTagVO;
import com.cloud.tags.dao.ResourceTagDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
-import com.cloud.user.UserContext;
import com.cloud.utils.Pair;
import com.cloud.utils.Ternary;
import com.cloud.utils.component.ManagerBase;
@@ -42,16 +41,20 @@ import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils;
+
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.command.user.network.CreateNetworkACLCmd;
import org.apache.cloudstack.api.command.user.network.ListNetworkACLsCmd;
+import org.apache.cloudstack.context.CallContext;
+
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import javax.ejb.Local;
import javax.inject.Inject;
+
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -85,7 +88,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 = CallContext.current().getCallingAccount();
Vpc vpc = _vpcMgr.getVpc(vpcId);
if(vpc == null){
throw new InvalidParameterValueException("Unable to find VPC");
@@ -137,7 +140,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ
@Override
public boolean deleteNetworkACL(long id) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
NetworkACL acl = _networkACLDao.findById(id);
if(acl == null) {
throw new InvalidParameterValueException("Unable to find specified ACL");
@@ -157,7 +160,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 = CallContext.current().getCallingAccount();
VpcGateway gateway = _vpcGatewayDao.findById(privateGatewayId);
if (gateway == null) {
throw new InvalidParameterValueException("Unable to find specified private gateway");
@@ -198,7 +201,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 = CallContext.current().getCallingAccount();
NetworkVO network = _networkDao.findById(networkId);
if(network == null){
@@ -237,7 +240,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ
@Override
public NetworkACLItem createNetworkACLItem(CreateNetworkACLCmd aclItemCmd){
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
Long aclId = aclItemCmd.getACLId();
if(aclId == null){
//ACL id is not specified. Get the ACL details from network
@@ -415,7 +418,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ
String action = cmd.getAction();
Map<String, String> tags = cmd.getTags();
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
List<Long> permittedAccounts = new ArrayList<Long>();
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject =
@@ -518,7 +521,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ
Vpc vpc = _vpcMgr.getVpc(acl.getVpcId());
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
_accountMgr.checkAccess(caller, null, true, vpc);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/src/com/cloud/network/vpc/VpcManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
index 2555ef6..f74e770 100644
--- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java
+++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
@@ -81,7 +81,6 @@ import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.ResourceLimitService;
import com.cloud.user.User;
-import com.cloud.user.UserContext;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.Ternary;
@@ -100,15 +99,19 @@ import com.cloud.utils.net.NetUtils;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.ReservationContextImpl;
import com.cloud.vm.dao.DomainRouterDao;
+
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.api.command.user.vpc.ListPrivateGatewaysCmd;
import org.apache.cloudstack.api.command.user.vpc.ListStaticRoutesCmd;
+import org.apache.cloudstack.context.CallContext;
+
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -350,7 +353,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
}
VpcOffering offering = createVpcOffering(name, displayText, svcProviderMap, false, null);
- UserContext.current().setEventDetails(" Id: " + offering.getId() + " Name: " + name);
+ CallContext.current().setEventDetails(" Id: " + offering.getId() + " Name: " + name);
return offering;
}
@@ -498,7 +501,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_DELETE, eventDescription = "deleting vpc offering")
public boolean deleteVpcOffering(long offId) {
- UserContext.current().setEventDetails(" Id: " + offId);
+ CallContext.current().setEventDetails(" Id: " + offId);
// Verify vpc offering id
VpcOfferingVO offering = _vpcOffDao.findById(offId);
@@ -528,7 +531,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_UPDATE, eventDescription = "updating vpc offering")
public VpcOffering updateVpcOffering(long vpcOffId, String vpcOfferingName, String displayText, String state) {
- UserContext.current().setEventDetails(" Id: " + vpcOffId);
+ CallContext.current().setEventDetails(" Id: " + vpcOffId);
// Verify input parameters
VpcOfferingVO offeringToUpdate = _vpcOffDao.findById(vpcOffId);
@@ -571,7 +574,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 = CallContext.current().getCallingAccount();
Account owner = _accountMgr.getAccount(vpcOwnerId);
//Verify that caller can perform actions in behalf of vpc owner
@@ -697,8 +700,8 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_DELETE, eventDescription = "deleting VPC")
public boolean deleteVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException {
- UserContext.current().setEventDetails(" Id: " + vpcId);
- UserContext ctx = UserContext.current();
+ CallContext.current().setEventDetails(" Id: " + vpcId);
+ CallContext ctx = CallContext.current();
// Verify vpc id
Vpc vpc = getVpc(vpcId);
@@ -707,9 +710,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
@@ -764,8 +767,8 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
@Override
@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();
+ CallContext.current().setEventDetails(" Id: " + vpcId);
+ Account caller = CallContext.current().getCallingAccount();
// Verify input parameters
VpcVO vpcToUpdate = _vpcDao.findById(vpcId);
@@ -798,7 +801,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
public List<? extends Vpc> listVpcs(Long id, String vpcName, String displayText, List<String> 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<String, String> tags, Long projectId) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
List<Long> permittedAccounts = new ArrayList<Long>();
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean,
@@ -941,9 +944,9 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
@Override
public boolean startVpc(long vpcId, boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
- UserContext ctx = UserContext.current();
- Account caller = ctx.getCaller();
- User callerUser = _accountMgr.getActiveUser(ctx.getCallerUserId());
+ CallContext ctx = CallContext.current();
+ Account caller = ctx.getCallingAccount();
+ User callerUser = _accountMgr.getActiveUser(ctx.getCallingUserId());
//check if vpc exists
Vpc vpc = getActiveVpc(vpcId);
@@ -1005,8 +1008,8 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
@Override
public boolean shutdownVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException {
- UserContext ctx = UserContext.current();
- Account caller = ctx.getCaller();
+ CallContext ctx = CallContext.current();
+ Account caller = ctx.getCallingAccount();
//check if vpc exists
Vpc vpc = getVpc(vpcId);
@@ -1023,7 +1026,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
boolean success = true;
List<Provider> 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)) {
@@ -1281,7 +1284,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 = CallContext.current().getCallingAccount();
// Verify input parameters
Vpc vpc = getActiveVpc(vpcId);
@@ -1521,7 +1524,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
}
if (deleteNetwork) {
- User callerUser = _accountMgr.getActiveUser(UserContext.current().getCallerUserId());
+ User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
Account owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
_ntwkMgr.destroyNetwork(networkId, context);
@@ -1545,7 +1548,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 = CallContext.current().getCallingAccount();
List<Long> permittedAccounts = new ArrayList<Long>();
String state = cmd.getState();
Long projectId = cmd.getProjectId();
@@ -1607,7 +1610,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
@Override
public boolean applyStaticRoutes(long vpcId) throws ResourceUnavailableException {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
List<? extends StaticRoute> routes = _staticRouteDao.listByVpcId(vpcId);
return applyStaticRoutes(routes, caller, true);
}
@@ -1675,7 +1678,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 = CallContext.current().getCallingAccount();
StaticRouteVO route = _staticRouteDao.findById(routeId);
if (route == null) {
@@ -1712,7 +1715,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 = CallContext.current().getCallingAccount();
//parameters validation
VpcGateway gateway = _vpcGatewayDao.findById(gatewayId);
@@ -1762,7 +1765,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
if (!_staticRouteDao.setStateToAdd(newRoute)) {
throw new CloudRuntimeException("Unable to update the state to add for " + newRoute);
}
- UserContext.current().setEventDetails("Static route Id: " + newRoute.getId());
+ CallContext.current().setEventDetails("Static route Id: " + newRoute.getId());
txn.commit();
@@ -1795,7 +1798,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 = CallContext.current().getCallingAccount();
List<Long> permittedAccounts = new ArrayList<Long>();
Map<String, String> tags = cmd.getTags();
Long projectId = cmd.getProjectId();
@@ -1939,7 +1942,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 = CallContext.current().getCallingAccount();
Account owner = null;
IpAddress ipToAssoc = _ntwkModel.getIp(ipId);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11e1e585/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java b/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java
index 9e7bb13..401b9f4 100755
--- a/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java
+++ b/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java
@@ -27,6 +27,8 @@ import javax.naming.ConfigurationException;
import org.apache.cloudstack.api.command.user.vpn.ListRemoteAccessVpnsCmd;
import org.apache.cloudstack.api.command.user.vpn.ListVpnUsersCmd;
+import org.apache.cloudstack.context.CallContext;
+
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@@ -43,10 +45,6 @@ import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.Network.Service;
-import com.cloud.network.NetworkModel;
-import com.cloud.network.PublicIpAddress;
-import com.cloud.network.RemoteAccessVpn;
-import com.cloud.network.VpnUser;
import com.cloud.network.*;
import com.cloud.network.VpnUser.State;
import com.cloud.network.dao.FirewallRulesDao;
@@ -66,18 +64,12 @@ import com.cloud.server.ConfigurationServer;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.DomainManager;
-import com.cloud.user.UserContext;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.PasswordGenerator;
import com.cloud.utils.Ternary;
import com.cloud.utils.component.ManagerBase;
-import com.cloud.utils.db.DB;
-import com.cloud.utils.db.Filter;
-import com.cloud.utils.db.JoinBuilder;
-import com.cloud.utils.db.SearchBuilder;
-import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.*;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.net.NetUtils;
@@ -113,8 +105,8 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc
@DB
public RemoteAccessVpn createRemoteAccessVpn(long publicIpId, String ipRange, boolean openFirewall, long networkId)
throws NetworkRuleConflictException {
- UserContext ctx = UserContext.current();
- Account caller = ctx.getCaller();
+ CallContext ctx = CallContext.current();
+ Account caller = ctx.getCallingAccount();
// make sure ip address exists
PublicIpAddress ipAddr = _networkMgr.getPublicIpAddress(publicIpId);
@@ -312,7 +304,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 = CallContext.current().getCallingAccount();
if (!username.matches("^[a-zA-Z0-9][a-zA-Z0-9@._-]{2,63}$")) {
throw new InvalidParameterValueException(
@@ -366,7 +358,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc
@Override
public List<? extends VpnUser> listVpnUsers(long vpnOwnerId, String userName) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
Account owner = _accountDao.findById(vpnOwnerId);
_accountMgr.checkAccess(caller, null, true, owner);
return _vpnUsersDao.listByAccount(vpnOwnerId);
@@ -374,7 +366,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 = CallContext.current().getCallingAccount();
RemoteAccessVpnVO vpn = _remoteAccessVpnDao.findByPublicIpAddress(ipAddressId);
if (vpn == null) {
@@ -425,7 +417,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc
@DB
@Override
public boolean applyVpnUsers(long vpnOwnerId, String userName) {
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
Account owner = _accountDao.findById(vpnOwnerId);
_accountMgr.checkAccess(caller, null, true, owner);
@@ -504,7 +496,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc
public Pair<List<? extends VpnUser>, Integer> searchForVpnUsers(ListVpnUsersCmd cmd) {
String username = cmd.getUsername();
Long id = cmd.getId();
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
List<Long> permittedAccounts = new ArrayList<Long>();
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(cmd.getDomainId(), cmd.isRecursive(), null);
@@ -542,7 +534,7 @@ public class RemoteAccessVpnManagerImpl extends ManagerBase implements RemoteAcc
@Override
public Pair<List<? extends RemoteAccessVpn>, Integer> searchForRemoteAccessVpns(ListRemoteAccessVpnsCmd cmd) {
// do some parameter validation
- Account caller = UserContext.current().getCaller();
+ Account caller = CallContext.current().getCallingAccount();
Long ipAddressId = cmd.getPublicIpId();
List<Long> permittedAccounts = new ArrayList<Long>();