diff --git a/api/src/com/cloud/resource/Resource.java b/api/src/com/cloud/resource/Resource.java index f4e8dd1d95a..cb76142513e 100644 --- a/api/src/com/cloud/resource/Resource.java +++ b/api/src/com/cloud/resource/Resource.java @@ -30,9 +30,7 @@ public interface Resource { Reserving("Resource is being reserved right now"), Reserved("Resource has been reserved."), Releasing("Resource is being released"), - Ready("Resource is ready which means it doesn't need to go through resservation"), - Deallocating("Resource is being deallocated"), - Free("Resource is now completely free"); + Deallocating("Resource is being deallocated"); String _description; @@ -78,10 +76,9 @@ public interface Resource { } enum ReservationStrategy { - UserSpecified, + PlaceHolder, Create, - Start, - PlaceHolder; + Start; } /** diff --git a/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java b/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java index 70ee22c8aeb..da268079e87 100644 --- a/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java +++ b/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java @@ -40,9 +40,9 @@ import com.cloud.agent.api.StopCommand; import com.cloud.agent.manager.Commands; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.deploy.DeployDestination; -import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.StorageUnavailableException; import com.cloud.ha.HighAvailabilityManager; import com.cloud.host.HostVO; @@ -305,7 +305,7 @@ public class AgentBasedConsoleProxyManager implements ConsoleProxyManager, Virtu } @Override - public boolean stop(ConsoleProxyVO vm) throws AgentUnavailableException { + public boolean stop(ConsoleProxyVO vm) throws ResourceUnavailableException { return false; } diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManager.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManager.java index cc123d9f480..8c0ea1666f0 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManager.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManager.java @@ -52,4 +52,5 @@ public interface ConsoleProxyManager extends Manager { public void onAgentConnect(HostVO host, StartupCommand cmd); public void onAgentDisconnect(long agentId, Status state); + } diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 858f9c6bf7c..3a02e8bfe53 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -48,7 +48,6 @@ import com.cloud.agent.api.ConsoleProxyLoadReportCommand; import com.cloud.agent.api.RebootCommand; import com.cloud.agent.api.StartupCommand; import com.cloud.agent.api.StartupProxyCommand; -import com.cloud.agent.api.StopAnswer; import com.cloud.agent.api.StopCommand; import com.cloud.agent.api.check.CheckSshAnswer; import com.cloud.agent.api.check.CheckSshCommand; @@ -118,7 +117,7 @@ import com.cloud.storage.dao.VMTemplateDao; import com.cloud.storage.dao.VMTemplateHostDao; import com.cloud.storage.dao.VolumeDao; import com.cloud.user.Account; -import com.cloud.user.AccountService; +import com.cloud.user.AccountManager; import com.cloud.user.AccountVO; import com.cloud.user.User; import com.cloud.user.dao.AccountDao; @@ -221,7 +220,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx @Inject private AgentManager _agentMgr; @Inject private StorageManager _storageMgr; @Inject NetworkManager _networkMgr; - @Inject AccountService _accountMgr; + @Inject AccountManager _accountMgr; @Inject private EventDao _eventDao; @Inject GuestOSDao _guestOSDao = null; @Inject ServiceOfferingDao _offeringDao; @@ -1429,32 +1428,54 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx @DB protected void completeStopCommand(ConsoleProxyVO proxy, VirtualMachine.Event ev) { - Transaction txn = Transaction.currentTxn(); - try { - txn.start(); - String privateIpAddress = proxy.getPrivateIpAddress(); - if (privateIpAddress != null) { - proxy.setPrivateIpAddress(null); -// freePrivateIpAddress(privateIpAddress, proxy.getDataCenterId(), proxy.getId()); - } - String guestIpAddress = proxy.getGuestIpAddress(); - if (guestIpAddress != null) { - proxy.setGuestIpAddress(null); - _dcDao.releaseLinkLocalIpAddress(guestIpAddress, proxy.getDataCenterId(), proxy.getId()); - } - - if (!_itMgr.stateTransitTo(proxy, ev, null)) { - s_logger.debug("Unable to update the console proxy"); - return; - } - txn.commit(); + + Transaction txn = Transaction.currentTxn(); + try { + txn.start(); + SubscriptionMgr.getInstance().notifySubscribers( + ConsoleProxyManager.ALERT_SUBJECT, + this, + new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_DOWN, proxy.getDataCenterId(), proxy.getId(), proxy, + null)); + + if (!_itMgr.stateTransitTo(proxy, ev, null)) { + s_logger.debug("Unable to update the console proxy"); + return; + } + txn.commit(); } catch (Exception e) { s_logger.error("Unable to complete stop command due to ", e); } - - if (_storageMgr.unshare(proxy, null) == null) { - s_logger.warn("Unable to set share to false for " + proxy.getId()); - } + + if (_storageMgr.unshare(proxy, null) == null) { + s_logger.warn("Unable to set share to false for " + proxy.getId()); + } +// Transaction txn = Transaction.currentTxn(); +// try { +// txn.start(); +// String privateIpAddress = proxy.getPrivateIpAddress(); +// if (privateIpAddress != null) { +// proxy.setPrivateIpAddress(null); +//// freePrivateIpAddress(privateIpAddress, proxy.getDataCenterId(), proxy.getId()); +// } +// String guestIpAddress = proxy.getGuestIpAddress(); +// if (guestIpAddress != null) { +// proxy.setGuestIpAddress(null); +// _dcDao.releaseLinkLocalIpAddress(guestIpAddress, proxy.getDataCenterId(), proxy.getId()); +// } +// +// if (!_itMgr.stateTransitTo(proxy, ev, null)) { +// s_logger.debug("Unable to update the console proxy"); +// return; +// } +// txn.commit(); +// } catch (Exception e) { +// s_logger.error("Unable to complete stop command due to ", e); +// } +// +// if (_storageMgr.unshare(proxy, null) == null) { +// s_logger.warn("Unable to set share to false for " + proxy.getId()); +// } } @Override @@ -1492,10 +1513,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx */ try { return stop(proxy); - } catch (AgentUnavailableException e) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Stopping console proxy " + proxy.getName() + " failed : exception " + e.toString()); - } + } catch (ResourceUnavailableException e) { + s_logger.warn("Stopping console proxy " + proxy.getName() + " failed : exception " + e.toString()); return false; } } @@ -1587,44 +1606,21 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } @Override - public boolean stop(ConsoleProxyVO proxy) throws AgentUnavailableException { + public boolean stop(ConsoleProxyVO proxy) throws ResourceUnavailableException { if (!_itMgr.stateTransitTo(proxy, VirtualMachine.Event.StopRequested, proxy.getHostId())) { s_logger.debug("Unable to stop console proxy: " + proxy.toString()); return false; } - // IPAddressVO ip = _ipAddressDao.findById(proxy.getPublicIpAddress()); - // VlanVO vlan = _vlanDao.findById(new Long(ip.getVlanDbId())); - GlobalLock proxyLock = GlobalLock.getInternLock(getProxyLockName(proxy.getId())); try { if (proxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) { try { - StopCommand cmd = new StopCommand(proxy, true, Integer.toString(_consoleProxyPort), Integer.toString(_consoleProxyUrlPort), - proxy.getPublicIpAddress()); - try { - Long proxyHostId = proxy.getHostId(); - if (proxyHostId == null) { - s_logger.debug("Unable to stop due to proxy " + proxy.getId() - + " as host is no longer available, proxy may already have been stopped"); - return false; - } - StopAnswer answer = (StopAnswer) _agentMgr.send(proxyHostId, cmd); - if (answer == null || !answer.getResult()) { - s_logger.debug("Unable to stop due to " + (answer == null ? "answer is null" : answer.getDetails())); - return false; - } + boolean result = _itMgr.stop(proxy, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); + if (result) { completeStopCommand(proxy, VirtualMachine.Event.OperationSucceeded); - - SubscriptionMgr.getInstance().notifySubscribers( - ConsoleProxyManager.ALERT_SUBJECT, - this, - new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_DOWN, proxy.getDataCenterId(), proxy.getId(), proxy, - null)); - return true; - } catch (OperationTimedoutException e) { - throw new AgentUnavailableException(proxy.getHostId()); } + return result; } finally { proxyLock.unlock(); } diff --git a/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java b/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java index ac4827aa967..ee7d8c0df79 100644 --- a/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java +++ b/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java @@ -915,7 +915,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager { } else { assert false : "Who decided there's other steps but didn't modify the guy who does the work?"; } - } catch (final AgentUnavailableException e) { + } catch (final ResourceUnavailableException e) { s_logger.debug("Agnet is not available" + e.getMessage()); } catch (OperationTimedoutException e) { s_logger.debug("operation timed out: " + e.getMessage()); diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java index 459f7710f07..2fe3da73b4c 100644 --- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java +++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java @@ -416,6 +416,8 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager, @Override public boolean removeAllLoadBalanacers(Ip ip) { List rules = _rulesDao.listByIpAndNotRevoked(ip); + if (rules != null) + s_logger.debug("Found " + rules.size() + " lb rules to cleanup"); for (FirewallRule rule : rules) { if (rule.getPurpose() == Purpose.LoadBalancing) { boolean result = deleteLoadBalancerRule(rule.getId(), true); diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 6657a8de302..8d2769b4c87 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1777,7 +1777,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } @Override - public boolean stop(DomainRouterVO router) throws AgentUnavailableException { + public boolean stop(DomainRouterVO router) throws ResourceUnavailableException { // TODO Auto-generated method stub return false; } diff --git a/server/src/com/cloud/server/ManagementServer.java b/server/src/com/cloud/server/ManagementServer.java index 5b7114db26d..558cc41a5f9 100755 --- a/server/src/com/cloud/server/ManagementServer.java +++ b/server/src/com/cloud/server/ManagementServer.java @@ -370,9 +370,7 @@ public interface ManagementServer extends ManagementService { String getConsoleAccessUrlRoot(long vmId); ConsoleProxyVO findConsoleProxyById(long instanceId); VMInstanceVO findSystemVMById(long instanceId); - VirtualMachine startSystemVm(long vmId); - VirtualMachine stopSystemVm(long vmId); /** * Returns a configuration value with the specified name diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 32ddef4fea4..102d48e084b 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -3957,23 +3957,6 @@ public class ManagementServerImpl implements ManagementServer { } } - @Override - public VirtualMachine stopSystemVm(long vmId) { - - // verify parameters - VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(vmId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm); - if (systemVm == null) { - throw new ServerApiException (BaseCmd.PARAM_ERROR, "unable to find a system vm with id " + vmId); - } - - // 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(vmId); - } else { - return stopSecondaryStorageVm(vmId); - } - } - @Override public VMInstanceVO stopSystemVM(StopSystemVmCmd cmd) { Long id = cmd.getId(); diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index 6bd2789e118..d6c9aae0a4f 100644 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -39,7 +39,6 @@ import com.cloud.agent.api.RebootCommand; import com.cloud.agent.api.SecStorageFirewallCfgCommand; import com.cloud.agent.api.SecStorageSetupCommand; import com.cloud.agent.api.StartupCommand; -import com.cloud.agent.api.StopAnswer; import com.cloud.agent.api.StopCommand; import com.cloud.agent.api.check.CheckSshAnswer; import com.cloud.agent.api.check.CheckSshCommand; @@ -978,7 +977,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V } @Override - public void completeStopCommand(SecondaryStorageVmVO vm) { + public void completeStopCommand(SecondaryStorageVmVO vm) { completeStopCommand(vm, VirtualMachine.Event.AgentReportStopped); } @@ -987,16 +986,14 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V Transaction txn = Transaction.currentTxn(); try { txn.start(); - String privateIpAddress = secStorageVm.getPrivateIpAddress(); - if (privateIpAddress != null) { - secStorageVm.setPrivateIpAddress(null); - // FIXME: freePrivateIpAddress(privateIpAddress, secStorageVm.getDataCenterId(), secStorageVm.getId()); - } - String guestIpAddress = secStorageVm.getGuestIpAddress(); - if (guestIpAddress != null) { - secStorageVm.setGuestIpAddress(null); - _dcDao.releaseLinkLocalIpAddress(guestIpAddress, secStorageVm.getDataCenterId(), secStorageVm.getId()); - } + + SubscriptionMgr.getInstance().notifySubscribers( + SecStorageVmAlertEventArgs.ALERT_SUBJECT, this, + new SecStorageVmAlertEventArgs( + SecStorageVmAlertEventArgs.SSVM_DOWN, + secStorageVm.getDataCenterId(), secStorageVm.getId(), secStorageVm, null) + ); + if (! _itMgr.stateTransitTo(secStorageVm, ev, null)) { s_logger.debug("Unable to update the secondary storage vm"); return; @@ -1042,7 +1039,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V } try { return stop(secStorageVm); - } catch (AgentUnavailableException e) { + } catch (ResourceUnavailableException e) { if (s_logger.isDebugEnabled()) { s_logger.debug("Stopping secondary storage vm " + secStorageVm.getName() + " faled : exception " + e.toString()); } @@ -1137,51 +1134,24 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V } @Override - public boolean stop(SecondaryStorageVmVO secStorageVm) throws AgentUnavailableException { + public boolean stop(SecondaryStorageVmVO secStorageVm) throws ResourceUnavailableException { if (! _itMgr.stateTransitTo(secStorageVm, VirtualMachine.Event.StopRequested, secStorageVm.getHostId())) { String msg = "Unable to stop secondary storage vm: " + secStorageVm.toString(); s_logger.debug(msg); return false; } - // IPAddressVO ip = _ipAddressDao.findById(secStorageVm.getPublicIpAddress()); - // VlanVO vlan = _vlanDao.findById(new Long(ip.getVlanDbId())); - if (secStorageVm.getHostId() != null) { GlobalLock secStorageVmLock = GlobalLock.getInternLock(getSecStorageVmLockName(secStorageVm.getId())); try { if (secStorageVmLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) { try { - StopCommand cmd = new StopCommand(secStorageVm, true, - Integer.toString(0), - Integer.toString(0), - secStorageVm.getPublicIpAddress()); - try { - StopAnswer answer = (StopAnswer) _agentMgr.send(secStorageVm.getHostId(), cmd); - if (answer == null || !answer.getResult()) { - String msg = "Unable to stop due to " + (answer == null ? "answer is null" : answer.getDetails()); - s_logger.debug(msg); - return false; - } + boolean result = _itMgr.stop(secStorageVm, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); + if (result) { completeStopCommand(secStorageVm, VirtualMachine.Event.OperationSucceeded); - - SubscriptionMgr.getInstance().notifySubscribers( - SecStorageVmAlertEventArgs.ALERT_SUBJECT, this, - new SecStorageVmAlertEventArgs( - SecStorageVmAlertEventArgs.SSVM_DOWN, - secStorageVm.getDataCenterId(), secStorageVm.getId(), secStorageVm, null) - ); - final EventVO event = new EventVO(); - event.setUserId(User.UID_SYSTEM); - event.setAccountId(Account.ACCOUNT_ID_SYSTEM); - event.setType(EventTypes.EVENT_SSVM_STOP); - event.setLevel(EventVO.LEVEL_INFO); - event.setDescription("Secondary Storage Vm stopped - " + secStorageVm.getName()); - _eventDao.persist(event); - return true; - } catch (OperationTimedoutException e) { - throw new AgentUnavailableException(secStorageVm.getHostId()); } + + return result; } finally { secStorageVmLock.unlock(); } diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 18aa5b63469..a911b25d2f4 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -1193,7 +1193,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } @Override - public boolean stop(UserVmVO vm) { + public boolean stop(UserVmVO vm) throws ResourceUnavailableException { return stop(1L, vm); } diff --git a/server/src/com/cloud/vm/VirtualMachineGuru.java b/server/src/com/cloud/vm/VirtualMachineGuru.java index b8ce7d5ab4d..46da9e4c985 100644 --- a/server/src/com/cloud/vm/VirtualMachineGuru.java +++ b/server/src/com/cloud/vm/VirtualMachineGuru.java @@ -109,9 +109,9 @@ public interface VirtualMachineGuru { * * @param vm vm to Stop. * @return true if stopped and false if not. - * @throws AgentUnavailableException if the agent is unavailable. + * @throws ResourceUnavailableException TODO */ - boolean stop(T vm) throws AgentUnavailableException; + boolean stop(T vm) throws ResourceUnavailableException; /** * Produce a cleanup command to be sent to the agent to cleanup anything diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 3e72a1c0104..d6d8aff61e7 100644 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -51,6 +51,7 @@ import com.cloud.alert.AlertManager; import com.cloud.cluster.ClusterManager; import com.cloud.configuration.Config; import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.consoleproxy.ConsoleProxyManager; import com.cloud.dc.DataCenter; import com.cloud.deploy.DataCenterDeployment; import com.cloud.deploy.DeployDestination; @@ -141,6 +142,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager { @Inject protected GuestOSCategoryDao _guestOsCategoryDao; @Inject protected GuestOSDao _guestOsDao; @Inject protected VolumeDao _volsDao; + @Inject protected ConsoleProxyManager _consoleProxyMgr; @Inject(adapter=DeploymentPlanner.class) protected Adapters _planners; @@ -552,16 +554,14 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager { ItWorkVO work = start.third(); T startedVm = null; + ServiceOfferingVO offering = _offeringDao.findById(vm.getServiceOfferingId()); + VMTemplateVO template = _templateDao.findById(vm.getTemplateId()); + DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vm.getPodId(), null, null); + HypervisorGuru hvGuru = _hvGurus.get(vm.getHypervisorType()); + VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm, template, offering, null, params); + try { - ServiceOfferingVO offering = _offeringDao.findById(vm.getServiceOfferingId()); - VMTemplateVO template = _templateDao.findById(vm.getTemplateId()); - - DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vm.getPodId(), null, null); - - HypervisorGuru hvGuru = _hvGurus.get(vm.getHypervisorType()); - VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm, template, offering, null, params); - Journal journal = start.second().getJournal(); ExcludeList avoids = new ExcludeList();