From b92fc074aae56a0ac440cb32d4747d55721fd333 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Tue, 8 Feb 2011 15:20:05 -0800 Subject: [PATCH] added forced paramter to stop apis --- api/src/com/cloud/api/ApiConstants.java | 1 + .../com/cloud/api/commands/StopRouterCmd.java | 13 +++- .../cloud/api/commands/StopSystemVmCmd.java | 13 +++- api/src/com/cloud/api/commands/StopVMCmd.java | 11 +++- .../VirtualNetworkApplianceService.java | 5 +- .../network/vpn/RemoteAccessVpnElement.java | 4 +- .../com/cloud/server/ManagementService.java | 4 +- api/src/com/cloud/vm/UserVmService.java | 5 +- .../cloud/network/element/DhcpElement.java | 2 +- .../network/element/VirtualRouterElement.java | 8 +-- .../VirtualNetworkApplianceManager.java | 2 + .../VirtualNetworkApplianceManagerImpl.java | 66 +++++++++---------- .../vpn/RemoteAccessVpnManagerImpl.java | 4 +- .../cloud/server/ManagementServerImpl.java | 37 ++++++----- .../src/com/cloud/vm/UserVmManagerImpl.java | 14 ++-- .../cloud/vm/VirtualMachineManagerImpl.java | 4 +- 16 files changed, 108 insertions(+), 85 deletions(-) diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index 10ef70a28f8..62dd6cfaa51 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -61,6 +61,7 @@ public class ApiConstants { public static final String END_PORT = "endport"; public static final String ENTRY_TIME = "entrytime"; public static final String FIRSTNAME = "firstname"; + public static final String FORCED = "forced"; public static final String FORMAT = "format"; public static final String FOR_VIRTUAL_NETWORK = "forvirtualnetwork"; public static final String GATEWAY = "gateway"; diff --git a/api/src/com/cloud/api/commands/StopRouterCmd.java b/api/src/com/cloud/api/commands/StopRouterCmd.java index 40a26f7ed61..71a619dc80c 100644 --- a/api/src/com/cloud/api/commands/StopRouterCmd.java +++ b/api/src/com/cloud/api/commands/StopRouterCmd.java @@ -47,6 +47,9 @@ public class StopRouterCmd extends BaseAsyncCmd { @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the router") private Long id; + + @Parameter(name=ApiConstants.FORCED, type=CommandType.BOOLEAN, required=false, description="Force stop the VM. The caller knows the VM is stopped.") + private Boolean forced; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -79,23 +82,29 @@ public class StopRouterCmd extends BaseAsyncCmd { public String getEventType() { return EventTypes.EVENT_ROUTER_STOP; } - + @Override public String getEventDescription() { return "stopping router: " + getId(); } + @Override public AsyncJob.Type getInstanceType() { return AsyncJob.Type.DomainRouter; } + @Override public Long getInstanceId() { return getId(); } + + public boolean isForced() { + return (forced != null) ? forced : false; + } @Override public void execute() throws ConcurrentOperationException, ResourceUnavailableException{ - VirtualRouter result = _routerService.stopRouter(this.getId()); + VirtualRouter result = _routerService.stopRouter(getId(), isForced()); if (result != null){ DomainRouterResponse response =_responseGenerator.createDomainRouterResponse(result); response.setResponseName(getCommandName()); diff --git a/api/src/com/cloud/api/commands/StopSystemVmCmd.java b/api/src/com/cloud/api/commands/StopSystemVmCmd.java index a190cad33ad..6367d2896d6 100644 --- a/api/src/com/cloud/api/commands/StopSystemVmCmd.java +++ b/api/src/com/cloud/api/commands/StopSystemVmCmd.java @@ -29,6 +29,8 @@ import com.cloud.api.ServerApiException; import com.cloud.api.response.SystemVmResponse; import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.ResourceUnavailableException; import com.cloud.user.Account; import com.cloud.user.UserContext; import com.cloud.vm.VirtualMachine; @@ -46,6 +48,9 @@ public class StopSystemVmCmd extends BaseAsyncCmd { @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the system virtual machine") private Long id; + @Parameter(name=ApiConstants.FORCED, type=CommandType.BOOLEAN, required=false, description="Force stop the VM. The caller knows the VM is stopped.") + private Boolean forced; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -83,16 +88,22 @@ public class StopSystemVmCmd extends BaseAsyncCmd { return "stopping system vm: " + getId(); } + @Override public AsyncJob.Type getInstanceType() { return AsyncJob.Type.SystemVm; } + @Override public Long getInstanceId() { return getId(); } + + public boolean isForced() { + return (forced != null) ? forced : false; + } @Override - public void execute(){ + public void execute() throws ResourceUnavailableException, ConcurrentOperationException { VirtualMachine result = _mgr.stopSystemVM(this); if (result != null) { SystemVmResponse response = _responseGenerator.createSystemVmResponse(result); diff --git a/api/src/com/cloud/api/commands/StopVMCmd.java b/api/src/com/cloud/api/commands/StopVMCmd.java index b55c4ceb912..4162bd91e66 100644 --- a/api/src/com/cloud/api/commands/StopVMCmd.java +++ b/api/src/com/cloud/api/commands/StopVMCmd.java @@ -45,6 +45,9 @@ public class StopVMCmd extends BaseAsyncCmd { @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the virtual machine") private Long id; + + @Parameter(name=ApiConstants.FORCED, type=CommandType.BOOLEAN, required=false, description="Force stop the VM. The caller knows the VM is stopped.") + private Boolean forced; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -87,18 +90,24 @@ public class StopVMCmd extends BaseAsyncCmd { return "stopping user vm: " + getId(); } + @Override public AsyncJob.Type getInstanceType() { return AsyncJob.Type.VirtualMachine; } + @Override public Long getInstanceId() { return getId(); } + + public boolean isForced() { + return (forced != null) ? forced : false; + } @Override public void execute() throws ServerApiException, ConcurrentOperationException{ UserContext.current().setEventDetails("Vm Id: "+getId()); - UserVm result = _userVmService.stopVirtualMachine(this); + UserVm result = _userVmService.stopVirtualMachine(getId(), isForced()); if (result != null) { UserVmResponse response = _responseGenerator.createUserVmResponse(result); response.setResponseName(getCommandName()); diff --git a/api/src/com/cloud/network/VirtualNetworkApplianceService.java b/api/src/com/cloud/network/VirtualNetworkApplianceService.java index ed820f15d6c..a194b06174a 100644 --- a/api/src/com/cloud/network/VirtualNetworkApplianceService.java +++ b/api/src/com/cloud/network/VirtualNetworkApplianceService.java @@ -46,12 +46,13 @@ public interface VirtualNetworkApplianceService{ /** * Stops domain router - * @param id of the router + * @param id of the router + * @param forced just do it. caller knows best. * @return router if successful, null otherwise * @throws ConcurrentOperationException * @throws ResourceUnavailableException * @throws InvalidParameterValueException, PermissionDeniedException */ - VirtualRouter stopRouter(long routerId) throws InvalidParameterValueException, PermissionDeniedException, ResourceUnavailableException, ConcurrentOperationException; + VirtualRouter stopRouter(long routerId, boolean forced) throws InvalidParameterValueException, PermissionDeniedException, ResourceUnavailableException, ConcurrentOperationException; } diff --git a/api/src/com/cloud/network/vpn/RemoteAccessVpnElement.java b/api/src/com/cloud/network/vpn/RemoteAccessVpnElement.java index 3ec802fb4a6..0a1dfbfd379 100644 --- a/api/src/com/cloud/network/vpn/RemoteAccessVpnElement.java +++ b/api/src/com/cloud/network/vpn/RemoteAccessVpnElement.java @@ -28,7 +28,7 @@ import com.cloud.utils.component.Adapter; public interface RemoteAccessVpnElement extends Adapter { String[] applyVpnUsers(RemoteAccessVpn vpn, List users) throws ResourceUnavailableException; - boolean start(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException; + boolean startVpn(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException; - boolean stop(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException; + boolean stopVpn(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException; } diff --git a/api/src/com/cloud/server/ManagementService.java b/api/src/com/cloud/server/ManagementService.java index 3ec7aff17ca..4bff921391c 100644 --- a/api/src/com/cloud/server/ManagementService.java +++ b/api/src/com/cloud/server/ManagementService.java @@ -83,9 +83,11 @@ import com.cloud.dc.Pod; import com.cloud.dc.Vlan; import com.cloud.domain.Domain; import com.cloud.event.Event; +import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InternalErrorException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.PermissionDeniedException; +import com.cloud.exception.ResourceUnavailableException; import com.cloud.host.Host; import com.cloud.network.IpAddress; import com.cloud.network.router.VirtualRouter; @@ -218,7 +220,7 @@ public interface ManagementService { */ List listGuestOSCategoriesByCriteria(ListGuestOsCategoriesCmd cmd); - VirtualMachine stopSystemVM(StopSystemVmCmd cmd); + VirtualMachine stopSystemVM(StopSystemVmCmd cmd) throws ResourceUnavailableException, ConcurrentOperationException; VirtualMachine startSystemVM(StartSystemVMCmd cmd); VirtualMachine rebootSystemVM(RebootSystemVmCmd cmd); VirtualMachine destroySystemVM(DestroySystemVmCmd cmd); diff --git a/api/src/com/cloud/vm/UserVmService.java b/api/src/com/cloud/vm/UserVmService.java index cef0373b581..28b5c436870 100755 --- a/api/src/com/cloud/vm/UserVmService.java +++ b/api/src/com/cloud/vm/UserVmService.java @@ -21,7 +21,6 @@ import java.util.List; import javax.naming.InsufficientResourcesException; -import com.cloud.api.ServerApiException; import com.cloud.api.commands.AttachVolumeCmd; import com.cloud.api.commands.CreateTemplateCmd; import com.cloud.api.commands.CreateVMGroupCmd; @@ -34,7 +33,6 @@ import com.cloud.api.commands.RebootVMCmd; import com.cloud.api.commands.RecoverVMCmd; import com.cloud.api.commands.ResetVMPasswordCmd; import com.cloud.api.commands.StartVMCmd; -import com.cloud.api.commands.StopVMCmd; import com.cloud.api.commands.UpdateVMCmd; import com.cloud.api.commands.UpgradeVMCmd; import com.cloud.exception.ConcurrentOperationException; @@ -92,7 +90,6 @@ public interface UserVmService { Volume detachVolumeFromVM(DetachVolumeCmd cmmd); UserVm startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, ExecutionException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException; - UserVm stopVirtualMachine(StopVMCmd cmd) throws ServerApiException, ConcurrentOperationException; UserVm rebootVirtualMachine(RebootVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException; UserVm updateVirtualMachine(UpdateVMCmd cmd); UserVm recoverVirtualMachine(RecoverVMCmd cmd) throws ResourceAllocationException; @@ -157,7 +154,7 @@ public interface UserVmService { */ UserVm upgradeVirtualMachine(UpgradeVMCmd cmd); - UserVm stopVirtualMachine(long vmId) throws ConcurrentOperationException; + UserVm stopVirtualMachine(long vmId, boolean forced) throws ConcurrentOperationException; UserVm startVirtualMachine(long vmId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; diff --git a/server/src/com/cloud/network/element/DhcpElement.java b/server/src/com/cloud/network/element/DhcpElement.java index 2ce6d8730c2..23fa6bf05b4 100644 --- a/server/src/com/cloud/network/element/DhcpElement.java +++ b/server/src/com/cloud/network/element/DhcpElement.java @@ -130,7 +130,7 @@ public class DhcpElement extends AdapterBase implements NetworkElement, Password if (router == null) { return true; } - return (_routerMgr.stopRouter(router.getId()) != null); + return (_routerMgr.stop(router, false, context.getCaller(), context.getAccount()) != null); } @Override diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java index f58e48fd40c..b7d0ed05666 100644 --- a/server/src/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VirtualRouterElement.java @@ -77,7 +77,7 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement, private static final Map> capabilities = setCapabilities(); - @Inject NetworkDao _networkConfigDao; + @Inject NetworkDao _networksDao; @Inject NetworkManager _networkMgr; @Inject LoadBalancingRulesManager _lbMgr; @Inject NetworkOfferingDao _networkOfferingDao; @@ -204,7 +204,7 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement, @Override public String[] applyVpnUsers(RemoteAccessVpn vpn, List users) throws ResourceUnavailableException{ - Network network = _networkConfigDao.findById(vpn.getNetworkId()); + Network network = _networksDao.findById(vpn.getNetworkId()); DataCenter dc = _configMgr.getZone(network.getDataCenterId()); if (canHandle(network.getGuestType(),dc)) { return _routerMgr.applyVpnUsers(network, users); @@ -215,7 +215,7 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement, } @Override - public boolean start(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException { + public boolean startVpn(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException { DataCenter dc = _configMgr.getZone(network.getDataCenterId()); if (canHandle(network.getGuestType(),dc)) { return _routerMgr.startRemoteAccessVpn(network, vpn); @@ -226,7 +226,7 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement, } @Override - public boolean stop(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException { + public boolean stopVpn(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException { DataCenter dc = _configMgr.getZone(network.getDataCenterId()); if (canHandle(network.getGuestType(),dc)) { return _routerMgr.deleteRemoteAccessVpn(network, vpn); diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java index cd628667df7..631fb6d0474 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java @@ -33,6 +33,7 @@ import com.cloud.network.VirtualNetworkApplianceService; import com.cloud.network.VpnUser; import com.cloud.network.lb.LoadBalancingRule; import com.cloud.user.Account; +import com.cloud.user.User; import com.cloud.uservm.UserVm; import com.cloud.utils.component.Manager; import com.cloud.vm.NicProfile; @@ -86,4 +87,5 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA VirtualRouter getRouterForNetwork(long networkId); + VirtualRouter stop(VirtualRouter router, boolean forced, User callingUser, Account callingAccount) throws ConcurrentOperationException, ResourceUnavailableException; } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 3e049eb7b30..78ca9bb8da2 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -273,14 +273,12 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian int _routerRamSize; int _retry = 2; - String _domain; String _instance; String _mgmt_host; int _routerCleanupInterval = 3600; int _routerStatsInterval = 300; private ServiceOfferingVO _offering; - String _networkDomain; ScheduledExecutorService _executor; @@ -414,7 +412,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Override - public VirtualRouter stopRouter(long routerId) throws ResourceUnavailableException, ConcurrentOperationException { + public VirtualRouter stopRouter(long routerId, boolean forced) throws ResourceUnavailableException, ConcurrentOperationException { UserContext context = UserContext.current(); Account account = context.getCaller(); @@ -428,7 +426,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian UserVO user = _userDao.findById(UserContext.current().getCallerUserId()); - return this.stop(router, user, account); + return stop(router, forced, user, account); } @DB @@ -505,7 +503,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Override public VirtualRouter rebootRouter(long routerId, boolean restartNetwork) throws InvalidParameterValueException, PermissionDeniedException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - Account account = UserContext.current().getCaller(); + Account caller = UserContext.current().getCaller(); // verify parameters DomainRouterVO router = _routerDao.findById(routerId); @@ -513,7 +511,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian throw new InvalidParameterValueException("Unable to find domain router with id " + routerId + "."); } - if ((account != null) && !_domainDao.isChildDomain(account.getDomainId(), router.getDomainId())) { + if ((caller != null) && !_domainDao.isChildDomain(caller.getDomainId(), router.getDomainId())) { throw new PermissionDeniedException("Unable to reboot domain router with id " + routerId + ". Permission denied"); } @@ -523,9 +521,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian throw new ResourceUnavailableException("Unable to reboot domR, it is not in right state " + router.getState(), DataCenter.class, router.getDataCenterId()); } + UserVO user = _userDao.findById(UserContext.current().getCallerUserId()); s_logger.debug("Stopping and starting router " + router + " as a part of router reboot"); - if (stopRouter(routerId) != null) { + if (stop(router, false, user, caller) != null) { return startRouter(routerId, restartNetwork); } else { throw new CloudRuntimeException("Failed to reboot router " + router); @@ -543,7 +542,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian final Map configs = _configDao.getConfiguration("AgentManager", params); _mgmt_host = configs.get("host"); - _routerRamSize = NumbersUtil.parseInt(configs.get("router.ram.size"), 128); + _routerRamSize = NumbersUtil.parseInt(configs.get(Config.RouterRamSize.key()), DEFAULT_ROUTER_VM_RAMSIZE); String value = configs.get("start.retry"); _retry = NumbersUtil.parseInt(value, 2); @@ -554,18 +553,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian value = configs.get("router.cleanup.interval"); _routerCleanupInterval = NumbersUtil.parseInt(value, 3600); - _domain = configs.get("domain"); - if (_domain == null) { - _domain = "foo.com"; - } - _instance = configs.get("instance.name"); if (_instance == null) { _instance = "DEFAULT"; } - _networkDomain = configs.get("guest.domain.suffix"); - s_logger.info("Router configurations: " + "ramsize=" + _routerRamSize); final UserStatisticsDao statsDao = locator.getDao(UserStatisticsDao.class); @@ -626,23 +618,22 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Override public void run() { try { - final List ids = findLonelyRouters(); - Long size; - if (ids == null || ids.isEmpty()) { - size = 0L; - } else { - size = Long.valueOf(ids.size()); + List ids = findLonelyRouters(); + + s_logger.trace("Found " + ids.size() + " routers to stop. "); + + for (Long id : ids) { + try { + DomainRouterVO router = _routerDao.findById(id); + if (stop(router, false, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()) != null) { + s_logger.info("Successfully stopped a rather lonely " + router); + } + } catch (Exception e) { + s_logger.warn("Unable to stop router " + id, e); + } } - s_logger.info("Found " + size + " routers to stop. "); - - if (ids != null) { - for (final Long id : ids) { - stopRouter(id); - } - } - - s_logger.info("Done my job. Time to rest."); + s_logger.trace("Done my job. Time to rest."); } catch (Exception e) { s_logger.warn("Unable to stop routers. Will retry. ", e); } @@ -1174,12 +1165,17 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } - private DomainRouterVO stop(DomainRouterVO router, User user, Account caller) throws ConcurrentOperationException, ResourceUnavailableException { + @Override + public DomainRouterVO stop(VirtualRouter router, boolean forced, User user, Account caller) throws ConcurrentOperationException, ResourceUnavailableException { s_logger.debug("Stopping router " + router); - if (_itMgr.stop(router, user, caller)) { - return _routerDao.findById(router.getId()); - } else { - return null; + try { + if (_itMgr.advanceStop((DomainRouterVO)router, forced, user, caller)) { + return _routerDao.findById(router.getId()); + } else { + return null; + } + } catch (OperationTimedoutException e) { + throw new CloudRuntimeException("Unable to stop " + router, e); } } diff --git a/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java b/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java index e8992b272ae..c42b364650b 100644 --- a/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java +++ b/server/src/com/cloud/network/vpn/RemoteAccessVpnManagerImpl.java @@ -213,7 +213,7 @@ public class RemoteAccessVpnManagerImpl implements RemoteAccessVpnService, Manag boolean success = false; try { for (RemoteAccessVpnElement element : elements) { - if (element.stop(network, vpn)) { + if (element.stopVpn(network, vpn)) { success = true; break; } @@ -312,7 +312,7 @@ public class RemoteAccessVpnManagerImpl implements RemoteAccessVpnService, Manag boolean started = false; try { for (RemoteAccessVpnElement element : elements) { - if (element.start(network, vpn)) { + if (element.startVpn(network, vpn)) { started = true; break; } diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 7c734287caf..1726d4ec806 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -269,6 +269,7 @@ import com.cloud.vm.UserVmVO; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.State; +import com.cloud.vm.VirtualMachineManager; import com.cloud.vm.dao.ConsoleProxyDao; import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.InstanceGroupDao; @@ -319,6 +320,7 @@ public class ManagementServerImpl implements ManagementServer { private final NicDao _nicDao; private final NetworkDao _networkDao; private final StorageManager _storageMgr; + private final VirtualMachineManager _itMgr; private final Adapters _userAuthenticators; private final HostPodDao _hostPodDao; @@ -342,8 +344,6 @@ public class ManagementServerImpl implements ManagementServer { private final Map _configs; - private String _domain; - private final int _routerRamSize; private final int _proxyRamSize; private final int _ssRamSize; @@ -407,20 +407,13 @@ public class ManagementServerImpl implements ManagementServer { _tmpltMgr = locator.getManager(TemplateManager.class); _uploadMonitor = locator.getManager(UploadMonitor.class); _sshKeyPairDao = locator.getDao(SSHKeyPairDao.class); + _itMgr = locator.getManager(VirtualMachineManager.class); _userAuthenticators = locator.getAdapters(UserAuthenticator.class); if (_userAuthenticators == null || !_userAuthenticators.isSet()) { s_logger.error("Unable to find an user authenticator."); } - _domain = _configs.get("domain"); - if (_domain == null) { - _domain = ".myvm.com"; - } - if (!_domain.startsWith(".")) { - _domain = "." + _domain; - } - String value = _configs.get("account.cleanup.interval"); int cleanup = NumbersUtil.parseInt(value, 60 * 60 * 24); // 1 hour. @@ -3996,21 +3989,29 @@ public class ManagementServerImpl implements ManagementServer { } @Override - public VMInstanceVO stopSystemVM(StopSystemVmCmd cmd) { + public VMInstanceVO stopSystemVM(StopSystemVmCmd cmd) throws ResourceUnavailableException, ConcurrentOperationException { Long id = cmd.getId(); // verify parameters VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(id, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm); if (systemVm == null) { - throw new ServerApiException (BaseCmd.PARAM_ERROR, "unable to find a system vm with id " + id); + throw new InvalidParameterValueException("unable to find a system vm with id " + id); } + + User caller = _userDao.findById(UserContext.current().getCallerUserId()); - // FIXME: We need to return the system VM from this method, so what do we do with the boolean response from stopConsoleProxy and stopSecondaryStorageVm? - if (systemVm.getType().equals(VirtualMachine.Type.ConsoleProxy)){ - return stopConsoleProxy(id); - } else { - return stopSecondaryStorageVm(id); - } + try { + if (_itMgr.advanceStop(systemVm, cmd.isForced(), caller, UserContext.current().getCaller())) { + if (systemVm.getType() == VirtualMachine.Type.ConsoleProxy) { + return _consoleProxyDao.findById(systemVm.getId()); + } else if (systemVm.getType() == VirtualMachine.Type.SecondaryStorageVm) { + return _secStorageVmDao.findById(systemVm.getId()); + } + } + return null; + } catch (OperationTimedoutException e) { + throw new CloudRuntimeException("Unable to stop " + systemVm, e); + } } @Override diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index b7be1c80eb7..b9cf3aa3e9e 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -64,7 +64,6 @@ import com.cloud.api.commands.RebootVMCmd; import com.cloud.api.commands.RecoverVMCmd; import com.cloud.api.commands.ResetVMPasswordCmd; import com.cloud.api.commands.StartVMCmd; -import com.cloud.api.commands.StopVMCmd; import com.cloud.api.commands.UpdateVMCmd; import com.cloud.api.commands.UpgradeVMCmd; import com.cloud.async.AsyncInstanceCreateStatus; @@ -1611,11 +1610,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager return _vmDao.findById(id); } - @Override @ActionEvent (eventType=EventTypes.EVENT_VM_STOP, eventDescription="stopping Vm", async=true) - public UserVm stopVirtualMachine(StopVMCmd cmd) throws ServerApiException, ConcurrentOperationException{ - return stopVirtualMachine(cmd.getId()); - } - @Override @ActionEvent (eventType=EventTypes.EVENT_VM_START, eventDescription="starting Vm", async=true) public UserVm startVirtualMachine(StartVMCmd cmd) throws ExecutionException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { return startVirtualMachine(cmd.getId()); @@ -2259,8 +2253,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager return findById(VirtualMachineName.getVmId(name)); } - @Override - public UserVm stopVirtualMachine(long vmId) throws ConcurrentOperationException { + @Override @ActionEvent (eventType=EventTypes.EVENT_VM_STOP, eventDescription="stopping Vm", async=true) + public UserVm stopVirtualMachine(long vmId, boolean forced) throws ConcurrentOperationException { //Input validation Account caller = UserContext.current().getCaller(); @@ -2280,9 +2274,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager UserVO user = _userDao.findById(userId); try { - _itMgr.stop(vm, user, caller); + _itMgr.advanceStop(vm, forced, user, caller); } catch (ResourceUnavailableException e) { throw new CloudRuntimeException("Unable to contact the agent to stop the virtual machine " + vm, e); + } catch (OperationTimedoutException e) { + throw new CloudRuntimeException("Unable to contact the agent to stop the virtual machine " + vm, e); } return _vmDao.findById(vmId); diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index d6d7913896b..735a280532f 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -76,8 +76,6 @@ import com.cloud.deploy.DeploymentPlan; import com.cloud.deploy.DeploymentPlanner; import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.domain.dao.DomainDao; -import com.cloud.event.EventTypes; -import com.cloud.event.UsageEventVO; import com.cloud.event.dao.UsageEventDao; import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.ConcurrentOperationException; @@ -1035,7 +1033,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, StateLi throw new AgentUnavailableException("Operation timed out: ", dstHostId); } finally { if (!migrated) { - s_logger.info("Migration was unsuccessful. Cleaning up: " + vm.toString()); + s_logger.info("Migration was unsuccessful. Cleaning up: " + vm); _alertMgr.sendAlert(alertType, fromHost.getDataCenterId(), fromHost.getPodId(), "Unable to migrate vm " + vm.getName() + " from host " + fromHost.getName() + " in zone " + dest.getDataCenter().getName() + " and pod " + dest.getPod().getName(), "Migrate Command failed. Please check logs.");