Stop ConsoleProxy/SecondaryStorage vms: use the same code path as for user vms.

This commit is contained in:
alena 2011-01-14 17:53:48 -08:00
parent 0d2be33b2d
commit 50540b2bba
13 changed files with 89 additions and 142 deletions

View File

@ -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;
}
/**

View File

@ -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;
}

View File

@ -52,4 +52,5 @@ public interface ConsoleProxyManager extends Manager {
public void onAgentConnect(HostVO host, StartupCommand cmd);
public void onAgentDisconnect(long agentId, Status state);
}

View File

@ -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();
}

View File

@ -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());

View File

@ -416,6 +416,8 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
@Override
public boolean removeAllLoadBalanacers(Ip ip) {
List<FirewallRuleVO> 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);

View File

@ -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;
}

View File

@ -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

View File

@ -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();

View File

@ -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();
}

View File

@ -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);
}

View File

@ -109,9 +109,9 @@ public interface VirtualMachineGuru<T extends VirtualMachine> {
*
* @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

View File

@ -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<DeploymentPlanner> _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<T> vmProfile = new VirtualMachineProfileImpl<T>(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<T> vmProfile = new VirtualMachineProfileImpl<T>(vm, template, offering, null, params);
Journal journal = start.second().getJournal();
ExcludeList avoids = new ExcludeList();