mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
initial HA work
This commit is contained in:
parent
23c9b5d9d2
commit
0105c03a27
@ -21,9 +21,7 @@ import com.cloud.vm.VirtualMachine;
|
||||
|
||||
public class StopCommand extends RebootCommand {
|
||||
String vnet;
|
||||
boolean mirroredVolumes=false;
|
||||
private boolean isProxy=false;
|
||||
private String vncPort=null;
|
||||
private String urlPort=null;
|
||||
private String publicConsoleProxyIpAddress=null;
|
||||
private String privateRouterIpAddress=null;
|
||||
@ -31,10 +29,9 @@ public class StopCommand extends RebootCommand {
|
||||
protected StopCommand() {
|
||||
}
|
||||
|
||||
public StopCommand(VirtualMachine vm, boolean isProxy, String vncPort, String urlPort, String publicConsoleProxyIpAddress) {
|
||||
public StopCommand(VirtualMachine vm, boolean isProxy, String urlPort, String publicConsoleProxyIpAddress) {
|
||||
super(vm);
|
||||
this.isProxy = isProxy;
|
||||
this.vncPort = vncPort;
|
||||
this.urlPort = urlPort;
|
||||
this.publicConsoleProxyIpAddress = publicConsoleProxyIpAddress;
|
||||
}
|
||||
@ -55,6 +52,10 @@ public class StopCommand extends RebootCommand {
|
||||
this.privateRouterIpAddress = privateRouterIpAddress;
|
||||
}
|
||||
|
||||
public StopCommand(String vmName) {
|
||||
super(vmName);
|
||||
}
|
||||
|
||||
public String getVnet() {
|
||||
return vnet;
|
||||
}
|
||||
@ -64,22 +65,10 @@ public class StopCommand extends RebootCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isMirroredVolumes() {
|
||||
return mirroredVolumes;
|
||||
}
|
||||
|
||||
public void setMirroredVolumes(boolean mirroredVolumes) {
|
||||
this.mirroredVolumes = mirroredVolumes;
|
||||
}
|
||||
|
||||
public boolean isProxy() {
|
||||
return this.isProxy;
|
||||
}
|
||||
|
||||
public String getVNCPort() {
|
||||
return this.vncPort;
|
||||
}
|
||||
|
||||
public String getURLPort() {
|
||||
return this.urlPort;
|
||||
}
|
||||
@ -91,5 +80,4 @@ public class StopCommand extends RebootCommand {
|
||||
public String getPrivateRouterIpAddress() {
|
||||
return privateRouterIpAddress;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -38,11 +38,13 @@ public class VirtualMachineTO {
|
||||
String bootArgs;
|
||||
String[] bootupScripts;
|
||||
boolean rebootOnCrash;
|
||||
boolean enableHA;
|
||||
Map<String, String> params;
|
||||
|
||||
VolumeTO[] disks;
|
||||
NicTO[] nics;
|
||||
|
||||
public VirtualMachineTO(long id, String instanceName, VirtualMachine.Type type, int cpus, Integer speed, long minRam, long maxRam, BootloaderType bootloader, String os) {
|
||||
public VirtualMachineTO(long id, String instanceName, VirtualMachine.Type type, int cpus, Integer speed, long minRam, long maxRam, BootloaderType bootloader, String os, boolean enableHA) {
|
||||
this.id = id;
|
||||
this.name = instanceName;
|
||||
this.type = type;
|
||||
@ -52,6 +54,7 @@ public class VirtualMachineTO {
|
||||
this.maxRam = maxRam;
|
||||
this.bootloader = bootloader;
|
||||
this.os = os;
|
||||
this.enableHA = enableHA;
|
||||
}
|
||||
|
||||
protected VirtualMachineTO() {
|
||||
@ -135,11 +138,6 @@ public class VirtualMachineTO {
|
||||
}
|
||||
|
||||
public String getBootArgs() {
|
||||
StringBuilder buf = new StringBuilder(bootArgs != null ? bootArgs : "");
|
||||
buf.append(" ");
|
||||
for (NicTO nic : nics) {
|
||||
buf.append("");
|
||||
}
|
||||
return bootArgs;
|
||||
}
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@ import com.cloud.user.Account;
|
||||
* set in this object is transitional. It does not get persisted
|
||||
* back to the database. This allows the adapters to process
|
||||
* the information in the virtual machine and make determinations
|
||||
* on what the virtual machin profile should look like before it is
|
||||
* on what the virtual machine profile should look like before it is
|
||||
* actually started on the hypervisor.
|
||||
*
|
||||
* @param <T> a VirtualMachine
|
||||
|
||||
@ -279,21 +279,27 @@ public abstract class CitrixResourceBase implements ServerResource {
|
||||
}
|
||||
|
||||
|
||||
protected void cleanupHaltedVms(Connection conn) throws XenAPIException, XmlRpcException {
|
||||
protected boolean cleanupHaltedVms(Connection conn) throws XenAPIException, XmlRpcException {
|
||||
Host host = Host.getByUuid(conn, _host.uuid);
|
||||
Set<VM> vms = host.getResidentVMs(conn);
|
||||
Set<VM> vms = VM.getAll(conn);
|
||||
|
||||
boolean success = true;
|
||||
for (VM vm : vms) {
|
||||
try {
|
||||
if (VmPowerState.HALTED.equals(vm.getPowerState(conn))) {
|
||||
VM.Record vmr = vm.getRecord(conn);
|
||||
if (VmPowerState.HALTED.equals(vmr.powerState) && vmr.affinity.equals(host)) {
|
||||
vm.destroy(conn);
|
||||
}
|
||||
} catch (XenAPIException e) {
|
||||
s_logger.warn("Unable to cleanup " + vm);
|
||||
success = false;
|
||||
} catch (XmlRpcException e) {
|
||||
s_logger.warn("Unable to cleanup " + vm);
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
protected boolean isRefNull(XenAPIObject object) {
|
||||
@ -2424,6 +2430,20 @@ public abstract class CitrixResourceBase implements ServerResource {
|
||||
s_logger.warn(msg);
|
||||
return new ReadyAnswer(cmd, msg);
|
||||
}
|
||||
|
||||
try {
|
||||
boolean result = cleanupHaltedVms(conn);
|
||||
if (!result) {
|
||||
return new ReadyAnswer(cmd, "Unable to cleanup halted vms");
|
||||
}
|
||||
} catch (XenAPIException e) {
|
||||
s_logger.warn("Unable to cleanup halted vms", e);
|
||||
return new ReadyAnswer(cmd, "Unable to cleanup halted vms");
|
||||
} catch (XmlRpcException e) {
|
||||
s_logger.warn("Unable to cleanup halted vms", e);
|
||||
return new ReadyAnswer(cmd, "Unable to cleanup halted vms");
|
||||
}
|
||||
|
||||
return new ReadyAnswer(cmd);
|
||||
}
|
||||
|
||||
@ -3673,16 +3693,6 @@ public abstract class CitrixResourceBase implements ServerResource {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
cleanupHaltedVms(conn);
|
||||
} catch (XenAPIException e) {
|
||||
s_logger.warn("Unable to cleanup halted vms", e);
|
||||
return null;
|
||||
} catch (XmlRpcException e) {
|
||||
s_logger.warn("Unable to cleanup halted vms", e);
|
||||
return null;
|
||||
}
|
||||
|
||||
StartupRoutingCommand cmd = new StartupRoutingCommand();
|
||||
fillHostInfo(conn, cmd);
|
||||
|
||||
|
||||
@ -32,10 +32,10 @@ import com.cloud.exception.DiscoveryException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.Host.Type;
|
||||
import com.cloud.host.HostStats;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.host.Host.Type;
|
||||
import com.cloud.host.Status.Event;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.resource.ServerResource;
|
||||
@ -47,7 +47,6 @@ import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
/**
|
||||
* AgentManager manages hosts. It directly coordinates between the
|
||||
@ -190,8 +189,6 @@ public interface AgentManager extends Manager {
|
||||
*/
|
||||
Pair<HostPodVO, Long> findPod(VirtualMachineTemplate template, ServiceOfferingVO offering, DataCenterVO dc, long userId, Set<Long> avoids);
|
||||
|
||||
Host findHost(VirtualMachineProfile vm, Set<? extends Host> avoids);
|
||||
|
||||
/**
|
||||
* Put the agent in maintenance mode.
|
||||
*
|
||||
@ -227,4 +224,6 @@ public interface AgentManager extends Manager {
|
||||
|
||||
Answer easySend(Long hostId, Command cmd, int timeout);
|
||||
|
||||
boolean isHostNativeHAEnabled(long hostId);
|
||||
|
||||
}
|
||||
|
||||
@ -86,6 +86,7 @@ import com.cloud.capacity.CapacityVO;
|
||||
import com.cloud.capacity.dao.CapacityDao;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.ClusterDetailsDao;
|
||||
import com.cloud.dc.ClusterDetailsVO;
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.dc.DataCenterIpAddressVO;
|
||||
@ -388,6 +389,16 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory,
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHostNativeHAEnabled(long hostId) {
|
||||
HostVO host = _hostDao.findById(hostId);
|
||||
if (host.getClusterId() != null) {
|
||||
ClusterDetailsVO detail = _clusterDetailsDao.findDetail(host.getClusterId(), "NativeHA");
|
||||
return detail == null ? false : Boolean.parseBoolean(detail.getValue());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task create(Task.Type type, Link link, byte[] data) {
|
||||
return new AgentHandler(type, link, data);
|
||||
@ -2703,11 +2714,6 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory,
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Host findHost(VirtualMachineProfile vm, Set<? extends Host> avoids) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// create capacity entries if none exist for this server
|
||||
private void createCapacityEntry(final StartupCommand startup, HostVO server) {
|
||||
SearchCriteria<CapacityVO> capacitySC = _capacityDao
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
package com.cloud.agent.manager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.agent.AgentManager.OnError;
|
||||
@ -25,7 +26,7 @@ import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public class Commands {
|
||||
public class Commands implements Iterable<Command> {
|
||||
OnError _handler;
|
||||
private ArrayList<String> _ids = new ArrayList<String>();
|
||||
private ArrayList<Command> _cmds = new ArrayList<Command>();
|
||||
@ -150,4 +151,9 @@ public class Commands {
|
||||
|
||||
return _handler != OnError.Continue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Command> iterator() {
|
||||
return _cmds.iterator();
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,11 +40,6 @@ 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.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;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
@ -56,10 +51,11 @@ import com.cloud.vm.ConsoleProxyVO;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineGuru;
|
||||
import com.cloud.vm.VirtualMachineManager;
|
||||
import com.cloud.vm.VirtualMachineName;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.VirtualMachine.Type;
|
||||
import com.cloud.vm.dao.ConsoleProxyDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
@ -84,6 +80,8 @@ public class AgentBasedConsoleProxyManager implements ConsoleProxyManager, Virtu
|
||||
@Inject
|
||||
AgentManager _agentMgr;
|
||||
@Inject
|
||||
VirtualMachineManager _itMgr;
|
||||
@Inject
|
||||
protected ConsoleProxyDao _cpDao;
|
||||
public int getVncPort(VMInstanceVO vm) {
|
||||
if (vm.getHostId() == null) {
|
||||
@ -130,9 +128,8 @@ public class AgentBasedConsoleProxyManager implements ConsoleProxyManager, Virtu
|
||||
|
||||
_listener = new ConsoleProxyListener(this);
|
||||
_agentMgr.registerForHostEvents(_listener, true, true, false);
|
||||
|
||||
HighAvailabilityManager haMgr = locator.getManager(HighAvailabilityManager.class);
|
||||
haMgr.registerHandler(Type.ConsoleProxy, this);
|
||||
|
||||
_itMgr.registerGuru(VirtualMachine.Type.ConsoleProxy, this);
|
||||
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("AgentBasedConsoleProxyManager has been configured. SSL enabled: " + _sslEnabled);
|
||||
@ -290,17 +287,6 @@ public class AgentBasedConsoleProxyManager implements ConsoleProxyManager, Virtu
|
||||
return VirtualMachineName.getConsoleProxyId(vmName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConsoleProxyVO start(long vmId) throws InsufficientCapacityException, StorageUnavailableException,
|
||||
ConcurrentOperationException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop(ConsoleProxyVO vm) throws ResourceUnavailableException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyCustomCertToNewProxy(StartupProxyCommand cmd) {
|
||||
// TODO Auto-generated method stub
|
||||
@ -346,7 +332,6 @@ public class AgentBasedConsoleProxyManager implements ConsoleProxyManager, Virtu
|
||||
@Override
|
||||
public void finalizeStop(VirtualMachineProfile<ConsoleProxyVO> profile, StopAnswer answer) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -55,19 +55,15 @@ import com.cloud.agent.manager.Commands;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.commands.DestroyConsoleProxyCmd;
|
||||
import com.cloud.async.AsyncJobExecutor;
|
||||
import com.cloud.async.AsyncJobManager;
|
||||
import com.cloud.async.AsyncJobVO;
|
||||
import com.cloud.async.BaseAsyncJobExecutor;
|
||||
import com.cloud.certificate.CertificateVO;
|
||||
import com.cloud.certificate.dao.CertificateDao;
|
||||
import com.cloud.cluster.ClusterManager;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.dc.DataCenter.NetworkType;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.HostPodVO;
|
||||
import com.cloud.dc.DataCenter.NetworkType;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.dc.dao.HostPodDao;
|
||||
import com.cloud.deploy.DataCenterDeployment;
|
||||
@ -78,9 +74,8 @@ import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.exception.StorageUnavailableException;
|
||||
import com.cloud.ha.HighAvailabilityManager;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Host.Type;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.info.ConsoleProxyConnectionInfo;
|
||||
import com.cloud.info.ConsoleProxyInfo;
|
||||
@ -90,12 +85,10 @@ import com.cloud.info.RunningHostCountInfo;
|
||||
import com.cloud.info.RunningHostInfoAgregator;
|
||||
import com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo;
|
||||
import com.cloud.maid.StackMaid;
|
||||
import com.cloud.network.IpAddrAllocator;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.NetworkVO;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.offerings.NetworkOfferingVO;
|
||||
import com.cloud.offerings.dao.NetworkOfferingDao;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
@ -103,9 +96,8 @@ import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.servlet.ConsoleProxyServlet;
|
||||
import com.cloud.storage.StorageManager;
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.storage.dao.GuestOSDao;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.storage.dao.VMTemplateHostDao;
|
||||
import com.cloud.user.Account;
|
||||
@ -125,17 +117,15 @@ import com.cloud.utils.events.SubscriptionMgr;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.ConsoleProxyVO;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachineGuru;
|
||||
import com.cloud.vm.VirtualMachineManager;
|
||||
import com.cloud.vm.VirtualMachineName;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.dao.ConsoleProxyDao;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
@ -186,14 +176,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
@Inject private StorageManager _storageMgr;
|
||||
@Inject NetworkManager _networkMgr;
|
||||
@Inject AccountManager _accountMgr;
|
||||
@Inject GuestOSDao _guestOSDao = null;
|
||||
@Inject ServiceOfferingDao _offeringDao;
|
||||
@Inject NetworkOfferingDao _networkOfferingDao;
|
||||
@Inject NicDao _nicDao;
|
||||
@Inject NetworkDao _networkDao;
|
||||
|
||||
private IpAddrAllocator _IpAllocator;
|
||||
|
||||
private ConsoleProxyListener _listener;
|
||||
|
||||
private ServiceOfferingVO _serviceOffering;
|
||||
@ -202,7 +187,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
NetworkOfferingVO _managementNetworkOffering;
|
||||
NetworkOfferingVO _linkLocalNetworkOffering;
|
||||
|
||||
@Inject private AsyncJobManager _asyncMgr;
|
||||
@Inject private VirtualMachineManager _itMgr;
|
||||
|
||||
private final ScheduledExecutorService _capacityScanScheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory("CP-Scan"));
|
||||
@ -216,7 +200,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
private boolean _use_lvm;
|
||||
private boolean _use_storage_vm;
|
||||
private boolean _disable_rp_filter = false;
|
||||
private String _domain;
|
||||
private String _instance;
|
||||
|
||||
private int _proxySessionTimeoutValue = DEFAULT_PROXY_SESSION_TIMEOUT;
|
||||
@ -450,7 +433,21 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
@Override
|
||||
public ConsoleProxyVO startProxy(long proxyVmId) {
|
||||
try {
|
||||
return start(proxyVmId);
|
||||
ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyVmId);
|
||||
Account systemAcct = _accountMgr.getSystemAccount();
|
||||
User systemUser = _accountMgr.getSystemUser();
|
||||
if (proxy.getState() == VirtualMachine.State.Running) {
|
||||
return proxy;
|
||||
}
|
||||
|
||||
if(proxy.getState() == VirtualMachine.State.Stopped) {
|
||||
return _itMgr.start(proxy, null, systemUser, systemAcct);
|
||||
}
|
||||
|
||||
// For VMs that are in Stopping, Starting, Migrating state, let client to wait by returning null
|
||||
// as sooner or later, Starting/Migrating state will be transited to Running and Stopping will be transited to Stopped to allow
|
||||
// Starting of it
|
||||
return null;
|
||||
} catch (StorageUnavailableException e) {
|
||||
s_logger.warn("Exception while trying to start console proxy", e);
|
||||
return null;
|
||||
@ -466,24 +463,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConsoleProxyVO start(long proxyVmId) throws ResourceUnavailableException, InsufficientCapacityException {
|
||||
ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyVmId);
|
||||
Account systemAcct = _accountMgr.getSystemAccount();
|
||||
User systemUser = _accountMgr.getSystemUser();
|
||||
if (proxy.getState() == VirtualMachine.State.Running) {
|
||||
return proxy;
|
||||
}
|
||||
|
||||
if(proxy.getState() == VirtualMachine.State.Stopped)
|
||||
return _itMgr.start(proxy, null, systemUser, systemAcct);
|
||||
|
||||
// For VMs that are in Stopping, Starting, Migrating state, let client to wait by returning null
|
||||
// as sooner or later, Starting/Migrating state will be transited to Running and Stopping will be transited to Stopped to allow
|
||||
// Starting of it
|
||||
return null;
|
||||
}
|
||||
|
||||
public ConsoleProxyVO assignProxyFromRunningPool(long dataCenterId) {
|
||||
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
@ -712,12 +691,14 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
return new ConsoleAccessAuthenticationAnswer(cmd, false);
|
||||
}
|
||||
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("Console authentication. Ticket in url for " + cmd.getHost() + ":" + cmd.getPort() + "-" + cmd.getVmId() + " is " + ticketInUrl);
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Console authentication. Ticket in url for " + cmd.getHost() + ":" + cmd.getPort() + "-" + cmd.getVmId() + " is " + ticketInUrl);
|
||||
}
|
||||
|
||||
String ticket = ConsoleProxyServlet.genAccessTicket(cmd.getHost(), cmd.getPort(), cmd.getSid(), cmd.getVmId());
|
||||
if(s_logger.isDebugEnabled())
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Console authentication. Ticket in 1 minute boundary for " + cmd.getHost() + ":" + cmd.getPort() + "-" + cmd.getVmId() + " is " + ticket);
|
||||
}
|
||||
|
||||
if(!ticket.equals(ticketInUrl)) {
|
||||
Date now = new Date();
|
||||
@ -725,8 +706,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
String minuteEarlyTicket = ConsoleProxyServlet.genAccessTicket(cmd.getHost(), cmd.getPort(), cmd.getSid(), cmd.getVmId(),
|
||||
new Date(now.getTime() - 60*1000));
|
||||
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("Console authentication. Ticket in 2-minute boundary for " + cmd.getHost() + ":" + cmd.getPort() + "-" + cmd.getVmId() + " is " + minuteEarlyTicket);
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Console authentication. Ticket in 2-minute boundary for " + cmd.getHost() + ":" + cmd.getPort() + "-" + cmd.getVmId() + " is " + minuteEarlyTicket);
|
||||
}
|
||||
|
||||
if(!minuteEarlyTicket.equals(ticketInUrl)) {
|
||||
s_logger.error("Access ticket expired or has been modified. vmId: " + cmd.getVmId() + "ticket in URL: " + ticketInUrl + ", tickets to check against: " + ticket + "," + minuteEarlyTicket);
|
||||
@ -777,46 +759,34 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
return new ConsoleAccessAuthenticationAnswer(cmd, true);
|
||||
}
|
||||
|
||||
private ConsoleProxyVO findConsoleProxyByHost(HostVO host) throws NumberFormatException {
|
||||
String name = host.getName();
|
||||
long proxyVmId = 0;
|
||||
ConsoleProxyVO proxy = null;
|
||||
if (name != null && name.startsWith("v-")) {
|
||||
String[] tokens = name.split("-");
|
||||
proxyVmId = Long.parseLong(tokens[1]);
|
||||
proxy = this._consoleProxyDao.findById(proxyVmId);
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAgentConnect(HostVO host, StartupCommand cmd) {
|
||||
if (host.getType() == Type.ConsoleProxy) {
|
||||
// TODO we can use this event to mark the proxy is up and
|
||||
// functioning instead of
|
||||
// pinging the console proxy VM command port
|
||||
//
|
||||
// for now, just log a message
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Console proxy agent is connected. proxy: " + host.getName());
|
||||
}
|
||||
|
||||
/* update public/private ip address */
|
||||
if (_IpAllocator != null && _IpAllocator.exteralIpAddressAllocatorEnabled()) {
|
||||
try {
|
||||
ConsoleProxyVO console = findConsoleProxyByHost(host);
|
||||
if (console == null) {
|
||||
s_logger.debug("Can't find console proxy ");
|
||||
return;
|
||||
}
|
||||
console.setPrivateIpAddress(cmd.getPrivateIpAddress());
|
||||
console.setPublicIpAddress(cmd.getPublicIpAddress());
|
||||
console.setPublicNetmask(cmd.getPublicNetmask());
|
||||
_consoleProxyDao.persist(console);
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (host.getType() == Type.ConsoleProxy) {
|
||||
// // TODO we can use this event to mark the proxy is up and
|
||||
// // functioning instead of
|
||||
// // pinging the console proxy VM command port
|
||||
// //
|
||||
// // for now, just log a message
|
||||
// if (s_logger.isInfoEnabled()) {
|
||||
// s_logger.info("Console proxy agent is connected. proxy: " + host.getName());
|
||||
// }
|
||||
//
|
||||
// /* update public/private ip address */
|
||||
// if (_IpAllocator != null && _IpAllocator.exteralIpAddressAllocatorEnabled()) {
|
||||
// try {
|
||||
// ConsoleProxyVO console = findConsoleProxyByHost(host);
|
||||
// if (console == null) {
|
||||
// s_logger.debug("Can't find console proxy ");
|
||||
// return;
|
||||
// }
|
||||
// console.setPrivateIpAddress(cmd.getPrivateIpAddress());
|
||||
// console.setPublicIpAddress(cmd.getPublicIpAddress());
|
||||
// console.setPublicNetmask(cmd.getPublicNetmask());
|
||||
// _consoleProxyDao.persist(console);
|
||||
// } catch (NumberFormatException e) {
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -844,7 +814,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
|
||||
final ConsoleProxyVO proxy = this._consoleProxyDao.findById(proxyVmId);
|
||||
if (proxy != null) {
|
||||
Long hostId = proxy.getHostId();
|
||||
|
||||
// Disable this feature for now, as it conflicts with
|
||||
// the case of allowing user to reboot console proxy
|
||||
@ -877,8 +846,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
|
||||
private boolean reserveStandbyCapacity() {
|
||||
String value = _configDao.getValue(Config.SystemVMAutoReserveCapacity.key());
|
||||
if(value != null && value.equalsIgnoreCase("true"))
|
||||
if(value != null && value.equalsIgnoreCase("true")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -915,8 +885,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
}
|
||||
|
||||
if(!reserveStandbyCapacity()) {
|
||||
if(s_logger.isDebugEnabled())
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Reserving standby capacity is disable, skip capacity scan");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1058,8 +1029,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
_allocProxyLock.unlock();
|
||||
}
|
||||
} else {
|
||||
if(s_logger.isInfoEnabled())
|
||||
if(s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Unable to acquire proxy allocation lock, skip for next time");
|
||||
}
|
||||
}
|
||||
|
||||
if (proxy != null) {
|
||||
@ -1196,15 +1168,15 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
@Override
|
||||
public boolean stopProxy(long proxyVmId) {
|
||||
|
||||
AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor();
|
||||
if (asyncExecutor != null) {
|
||||
AsyncJobVO job = asyncExecutor.getJob();
|
||||
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Stop console proxy " + proxyVmId + ", update async job-" + job.getId());
|
||||
}
|
||||
_asyncMgr.updateAsyncJobAttachment(job.getId(), "console_proxy", proxyVmId);
|
||||
}
|
||||
// AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor();
|
||||
// if (asyncExecutor != null) {
|
||||
// AsyncJobVO job = asyncExecutor.getJob();
|
||||
//
|
||||
// if (s_logger.isInfoEnabled()) {
|
||||
// s_logger.info("Stop console proxy " + proxyVmId + ", update async job-" + job.getId());
|
||||
// }
|
||||
// _asyncMgr.updateAsyncJobAttachment(job.getId(), "console_proxy", proxyVmId);
|
||||
// }
|
||||
|
||||
ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyVmId);
|
||||
if (proxy == null) {
|
||||
@ -1219,7 +1191,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
* proxyVmId, startEventId);
|
||||
*/
|
||||
try {
|
||||
return stop(proxy);
|
||||
return _itMgr.stop(proxy, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
|
||||
} catch (ResourceUnavailableException e) {
|
||||
s_logger.warn("Stopping console proxy " + proxy.getName() + " failed : exception " + e.toString());
|
||||
return false;
|
||||
@ -1228,15 +1200,15 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
|
||||
@Override
|
||||
public boolean rebootProxy(long proxyVmId) {
|
||||
AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor();
|
||||
if (asyncExecutor != null) {
|
||||
AsyncJobVO job = asyncExecutor.getJob();
|
||||
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Reboot console proxy " + proxyVmId + ", update async job-" + job.getId());
|
||||
}
|
||||
_asyncMgr.updateAsyncJobAttachment(job.getId(), "console_proxy", proxyVmId);
|
||||
}
|
||||
// AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor();
|
||||
// if (asyncExecutor != null) {
|
||||
// AsyncJobVO job = asyncExecutor.getJob();
|
||||
//
|
||||
// if (s_logger.isInfoEnabled()) {
|
||||
// s_logger.info("Reboot console proxy " + proxyVmId + ", update async job-" + job.getId());
|
||||
// }
|
||||
// _asyncMgr.updateAsyncJobAttachment(job.getId(), "console_proxy", proxyVmId);
|
||||
// }
|
||||
|
||||
final ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyVmId);
|
||||
|
||||
@ -1283,11 +1255,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop(ConsoleProxyVO proxy) throws ResourceUnavailableException {
|
||||
return _itMgr.stop(proxy, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
|
||||
}
|
||||
|
||||
private String getCapacityScanLockName() {
|
||||
return "consoleproxy.capacity.scan";
|
||||
}
|
||||
@ -1352,11 +1319,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
s_logger.info("Console proxy standby capacity : " + _standbyCapacity);
|
||||
}
|
||||
|
||||
_domain = configs.get("domain");
|
||||
if (_domain == null) {
|
||||
_domain = "foo.com";
|
||||
}
|
||||
|
||||
_instance = configs.get("instance.name");
|
||||
if (_instance == null) {
|
||||
_instance = "DEFAULT";
|
||||
@ -1379,10 +1341,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
_listener = new ConsoleProxyListener(this);
|
||||
_agentMgr.registerForHostEvents(_listener, true, true, false);
|
||||
|
||||
HighAvailabilityManager haMgr = locator.getManager(HighAvailabilityManager.class);
|
||||
if (haMgr != null) {
|
||||
haMgr.registerHandler(VirtualMachine.Type.ConsoleProxy, this);
|
||||
}
|
||||
_itMgr.registerGuru(VirtualMachine.Type.ConsoleProxy, this);
|
||||
|
||||
boolean useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key()));
|
||||
@ -1497,14 +1455,13 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
|
||||
ConsoleProxyVO proxy = profile.getVirtualMachine();
|
||||
DataCenter dc = dest.getDataCenter();
|
||||
List<NicVO> nics = _nicDao.listBy(proxy.getId());
|
||||
for (NicVO nic : nics) {
|
||||
NetworkVO network = _networkDao.findById(nic.getNetworkId());
|
||||
if ((network.getTrafficType() == TrafficType.Public && dc.getNetworkType() == NetworkType.Advanced) || (network.getTrafficType() == TrafficType.Guest && dc.getNetworkType() == NetworkType.Basic)) {
|
||||
List<NicProfile> nics = profile.getNics();
|
||||
for (NicProfile nic : nics) {
|
||||
if ((nic.getTrafficType() == TrafficType.Public && dc.getNetworkType() == NetworkType.Advanced) || (nic.getTrafficType() == TrafficType.Guest && dc.getNetworkType() == NetworkType.Basic)) {
|
||||
proxy.setPublicIpAddress(nic.getIp4Address());
|
||||
proxy.setPublicNetmask(nic.getNetmask());
|
||||
proxy.setPublicMacAddress(nic.getMacAddress());
|
||||
} else if (network.getTrafficType() == TrafficType.Management) {
|
||||
} else if (nic.getTrafficType() == TrafficType.Management) {
|
||||
proxy.setPrivateIpAddress(nic.getIp4Address());
|
||||
proxy.setPrivateMacAddress(nic.getMacAddress());
|
||||
}
|
||||
@ -1517,10 +1474,11 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
public boolean finalizeStart(VirtualMachineProfile<ConsoleProxyVO> profile, long hostId, Commands cmds, ReservationContext context) {
|
||||
CheckSshAnswer answer = (CheckSshAnswer)cmds.getAnswer("checkSsh");
|
||||
if (answer == null || !answer.getResult()) {
|
||||
if(answer != null)
|
||||
if(answer != null) {
|
||||
s_logger.warn("Unable to ssh to the VM: " + answer.getDetails());
|
||||
else
|
||||
} else {
|
||||
s_logger.warn("Unable to ssh to the VM: null answer");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -23,8 +23,6 @@ import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineGuru;
|
||||
|
||||
/**
|
||||
* HighAvailabilityManager checks to make sure the VMs are running fine.
|
||||
@ -77,21 +75,6 @@ public interface HighAvailabilityManager extends Manager {
|
||||
*/
|
||||
void scheduleRestartForVmsOnHost(final HostVO host);
|
||||
|
||||
/**
|
||||
* Register a handler to take care of a VM. If a handler for a certain
|
||||
* type of VM is not handled, then it is not part of the HA process.
|
||||
*
|
||||
* @param type virtual machine type.
|
||||
* @param handler handler that can handle starting and stopping the machine.
|
||||
*/
|
||||
void registerHandler(final VirtualMachine.Type type, final VirtualMachineGuru<? extends VMInstanceVO> handler);
|
||||
|
||||
/**
|
||||
* Unregisters a handler. Not likely called but here for completeness.
|
||||
* @param type virtual machine type to unregister.
|
||||
*/
|
||||
void unregisterHandler(final VirtualMachine.Type type);
|
||||
|
||||
/**
|
||||
* Schedule the vm for migration.
|
||||
*
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
package com.cloud.ha;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
@ -36,11 +35,9 @@ import org.apache.log4j.Logger;
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.StopAnswer;
|
||||
import com.cloud.alert.AlertManager;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.ClusterDetailsDao;
|
||||
import com.cloud.dc.ClusterDetailsVO;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.HostPodVO;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
@ -68,20 +65,18 @@ import com.cloud.utils.component.Adapters;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
import com.cloud.utils.db.GlobalLock;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.Event;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachineGuru;
|
||||
import com.cloud.vm.VirtualMachineManager;
|
||||
import com.cloud.vm.VirtualMachineProfileImpl;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
||||
/**
|
||||
* HighAvailabilityManagerImpl coordinates the HA process. VMs are registered with
|
||||
* the HA Coordinator for HA. The request is stored within a database backed
|
||||
* work queue. HACoordinator then also has a number of workers that pick up
|
||||
* the HA Manager for HA. The request is stored within a database backed
|
||||
* work queue. HAManager has a number of workers that pick up
|
||||
* these work items to perform HA on the VMs.
|
||||
*
|
||||
* The HA process goes as follows:
|
||||
@ -143,21 +138,17 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
|
||||
|
||||
String _instance;
|
||||
ScheduledExecutorService _executor;
|
||||
int _operationTimeout;
|
||||
int _stopRetryInterval;
|
||||
int _investigateRetryInterval;
|
||||
int _migrateRetryInterval;
|
||||
int _restartRetryInterval;
|
||||
|
||||
HashMap<VirtualMachine.Type, VirtualMachineGuru<VMInstanceVO>> _handlers;
|
||||
|
||||
int _maxRetries;
|
||||
long _timeBetweenFailures;
|
||||
long _timeBetweenCleanups;
|
||||
boolean _forceHA;
|
||||
|
||||
protected HighAvailabilityManagerImpl() {
|
||||
_handlers = new HashMap<VirtualMachine.Type, VirtualMachineGuru<VMInstanceVO>>(11);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -247,17 +238,6 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
|
||||
wakeupWorkers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void registerHandler(final VirtualMachine.Type type, final VirtualMachineGuru<? extends VMInstanceVO> handler) {
|
||||
s_logger.info("Registering " + handler.getClass().getSimpleName() + " as the handler for " + type);
|
||||
_handlers.put(type, (VirtualMachineGuru<VMInstanceVO>)handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void unregisterHandler(final VirtualMachine.Type type) {
|
||||
_handlers.remove(type);
|
||||
}
|
||||
|
||||
protected void wakeupWorkers() {
|
||||
for (WorkerThread worker : _workers) {
|
||||
worker.wakup();
|
||||
@ -279,8 +259,6 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
|
||||
_itMgr.stateTransitTo(vm, Event.OperationFailed, null);
|
||||
return;
|
||||
}
|
||||
VirtualMachineGuru<VMInstanceVO> mgr = findManager(vm.getType());
|
||||
vm = mgr.findById(vm.getId());
|
||||
if (!investigate) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("VM does not require investigation so I'm marking it as Stopped: " + vm.toString());
|
||||
@ -306,8 +284,15 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
|
||||
}
|
||||
}
|
||||
|
||||
_itMgr.stateTransitTo(vm, Event.AgentReportStopped, null);
|
||||
mgr.finalizeStop(new VirtualMachineProfileImpl<VMInstanceVO>(vm), null);
|
||||
try {
|
||||
_itMgr.advanceStop(vm, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
|
||||
} catch (ResourceUnavailableException e) {
|
||||
// FIXME
|
||||
} catch (OperationTimedoutException e) {
|
||||
// FIXME
|
||||
} catch (ConcurrentOperationException e) {
|
||||
// FIXME
|
||||
}
|
||||
}
|
||||
|
||||
final List<HaWorkVO> items = _haDao.findPreviousHA(vm.getId());
|
||||
@ -330,20 +315,10 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
|
||||
wakeupWorkers();
|
||||
}
|
||||
|
||||
protected VirtualMachineGuru<VMInstanceVO> findManager(final VirtualMachine.Type type) {
|
||||
return _handlers.get(type);
|
||||
}
|
||||
|
||||
protected Long restart(final HaWorkVO work) {
|
||||
final long vmId = work.getInstanceId();
|
||||
|
||||
final VirtualMachineGuru<VMInstanceVO> mgr = findManager(work.getType());
|
||||
if (mgr == null) {
|
||||
s_logger.warn("Unable to find a handler for " + work.getType().toString() + ", throwing out " + vmId);
|
||||
return null;
|
||||
}
|
||||
|
||||
VMInstanceVO vm = mgr.findById(vmId);
|
||||
VMInstanceVO vm = _itMgr.findById(work.getType(), work.getInstanceId());
|
||||
if (vm == null) {
|
||||
s_logger.info("Unable to find vm: " + vmId);
|
||||
return null;
|
||||
@ -356,7 +331,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
|
||||
}
|
||||
|
||||
final HostVO host = _hostDao.findById(work.getHostId());
|
||||
boolean nativeHA = isHostClusterNativeHAEnabled(work.getHostId());
|
||||
boolean nativeHA = _agentMgr.isHostNativeHAEnabled(work.getHostId());
|
||||
|
||||
DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
|
||||
HostPodVO podVO = _podDao.findById(host.getPodId());
|
||||
@ -392,7 +367,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
|
||||
if (alive != null && alive) {
|
||||
s_logger.debug("VM " + vm.getName() + " is found to be alive by " + investigator.getName());
|
||||
if (host.getStatus() == Status.Up) {
|
||||
compareState(vm, new AgentVmInfo(vm.getInstanceName(), mgr, State.Running), false, nativeHA);
|
||||
//FIXME compareState(vm, new AgentVmInfo(vm.getInstanceName(), null, State.Running), false, nativeHA);
|
||||
return null;
|
||||
} else {
|
||||
s_logger.debug("Rescheduling because the host is not up but the vm is alive");
|
||||
@ -420,8 +395,15 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
|
||||
return (System.currentTimeMillis() >> 10) + _restartRetryInterval;
|
||||
}
|
||||
|
||||
_itMgr.stateTransitTo(vm, Event.AgentReportStopped, null);
|
||||
mgr.finalizeStop(new VirtualMachineProfileImpl<VMInstanceVO>(vm), null);
|
||||
try {
|
||||
_itMgr.advanceStop(vm, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
|
||||
} catch (ResourceUnavailableException e) {
|
||||
// FIXME
|
||||
} catch (OperationTimedoutException e) {
|
||||
// FIXME
|
||||
} catch (ConcurrentOperationException e) {
|
||||
// FIXME
|
||||
}
|
||||
|
||||
work.setStep(Step.Scheduled);
|
||||
_haDao.update(work.getId(), work);
|
||||
@ -433,7 +415,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
|
||||
+ hostDesc, "Virtual Machine " + vm.getName() + " (id: "
|
||||
+ vm.getId() + ") running on host [" + hostDesc + "] stopped unexpectedly.");
|
||||
|
||||
vm = mgr.findById(vm.getId());
|
||||
vm = _itMgr.findById(vm.getType(), vm.getId());
|
||||
|
||||
if (!_forceHA && !vm.isHaEnabled()) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
@ -455,7 +437,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
|
||||
}
|
||||
|
||||
try {
|
||||
VMInstanceVO started = mgr.start(vm.getId());
|
||||
VMInstanceVO started = _itMgr.advanceStart(vm, new HashMap<VirtualMachineProfile.Param, Object>(), _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
|
||||
if (started != null) {
|
||||
s_logger.info("VM is now restarted: " + vmId + " on " + started.getHostId());
|
||||
return null;
|
||||
@ -464,7 +446,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Rescheduling VM " + vm.toString() + " to try again in " + _restartRetryInterval);
|
||||
}
|
||||
vm = mgr.findById(vm.getId());
|
||||
vm = _itMgr.findById(vm.getType(), vm.getId());
|
||||
work.setUpdateTime(vm.getUpdated());
|
||||
work.setPreviousState(vm.getState());
|
||||
return (System.currentTimeMillis() >> 10) + _restartRetryInterval;
|
||||
@ -480,250 +462,12 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
|
||||
s_logger.warn("Unable to restart " + vm.toString() + " due to " + e.getMessage());
|
||||
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to restart " + vm.getName() + " which was running on host " + hostDesc, "The Storage is unavailable for trying to restart VM, name: " + vm.getName() + ", id: " + vmId + " which was running on host " + hostDesc);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* compareState does as its name suggests and compares the states between
|
||||
* management server and agent. It returns whether something should be
|
||||
* cleaned up
|
||||
*
|
||||
*/
|
||||
protected Command compareState(VMInstanceVO vm, final AgentVmInfo info, final boolean fullSync, boolean nativeHA) {
|
||||
State agentState = info.state;
|
||||
final String agentName = info.name;
|
||||
final State serverState = vm.getState();
|
||||
final String serverName = vm.getName();
|
||||
|
||||
|
||||
Command command = null;
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("VM " + serverName + ": server state = " + serverState.toString() + " and agent state = " + agentState.toString());
|
||||
}
|
||||
|
||||
if (agentState == State.Error) {
|
||||
agentState = State.Stopped;
|
||||
|
||||
short alertType = AlertManager.ALERT_TYPE_USERVM;
|
||||
if (VirtualMachine.Type.DomainRouter.equals(vm.getType())) {
|
||||
alertType = AlertManager.ALERT_TYPE_DOMAIN_ROUTER;
|
||||
} else if (VirtualMachine.Type.ConsoleProxy.equals(vm.getType())) {
|
||||
alertType = AlertManager.ALERT_TYPE_CONSOLE_PROXY;
|
||||
}
|
||||
|
||||
HostPodVO podVO = _podDao.findById(vm.getPodId());
|
||||
DataCenterVO dcVO = _dcDao.findById(vm.getDataCenterId());
|
||||
HostVO hostVO = _hostDao.findById(vm.getHostId());
|
||||
|
||||
String hostDesc = "name: " + hostVO.getName() + " (id:" + hostVO.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
|
||||
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "VM (name: " + vm.getName() + ", id: " + vm.getId() + ") stopped on host " + hostDesc + " due to storage failure", "Virtual Machine " + vm.getName() + " (id: " + vm.getId() + ") running on host [" + vm.getHostId() + "] stopped due to storage failure.");
|
||||
}
|
||||
|
||||
if (serverState == State.Migrating) {
|
||||
s_logger.debug("Skipping vm in migrating state: " + vm.toString());
|
||||
return null;
|
||||
}
|
||||
|
||||
if (agentState == serverState) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Both states are " + agentState.toString() + " for " + serverName);
|
||||
}
|
||||
assert (agentState == State.Stopped || agentState == State.Running) : "If the states we send up is changed, this must be changed.";
|
||||
_itMgr.stateTransitTo(vm, agentState == State.Stopped ? VirtualMachine.Event.AgentReportStopped : VirtualMachine.Event.AgentReportRunning, vm.getHostId());
|
||||
if (agentState == State.Stopped) {
|
||||
s_logger.debug("State matches but the agent said stopped so let's send a cleanup anyways.");
|
||||
return info.mgr.cleanup(vm, agentName);
|
||||
}
|
||||
} catch (OperationTimedoutException e) {
|
||||
// FIXME
|
||||
return null;
|
||||
}
|
||||
if (agentState == State.Shutdowned ) {
|
||||
if ( serverState == State.Running || serverState == State.Starting || serverState == State.Stopping ) {
|
||||
_itMgr.stateTransitTo(vm, VirtualMachine.Event.AgentReportShutdowned, null);
|
||||
}
|
||||
s_logger.debug("Sending cleanup to a shutdowned vm: " + agentName);
|
||||
command = info.mgr.cleanup(vm, agentName);
|
||||
} else if (agentState == State.Stopped) {
|
||||
// This state means the VM on the agent was detected previously
|
||||
// and now is gone. This is slightly different than if the VM
|
||||
// was never completed but we still send down a Stop Command
|
||||
// to ensure there's cleanup.
|
||||
if (serverState == State.Running ) {
|
||||
if(!nativeHA) {
|
||||
// Our records showed that it should be running so let's restart it.
|
||||
vm = info.mgr.findById(vm.getId());
|
||||
scheduleRestart(vm, false);
|
||||
command = info.mgr.cleanup(vm, agentName);
|
||||
} else {
|
||||
s_logger.info("VM is in runnting state, agent reported as stopped and native HA is enabled => skip sync action");
|
||||
}
|
||||
} else if (serverState == State.Stopping) {
|
||||
if (fullSync) {
|
||||
s_logger.debug("VM is in stopping state on full sync. Updating the status to stopped");
|
||||
vm = info.mgr.findById(vm.getId());
|
||||
_itMgr.stateTransitTo(vm, Event.AgentReportStopped, null);
|
||||
info.mgr.finalizeStop(new VirtualMachineProfileImpl<VMInstanceVO>(vm), null);
|
||||
command = info.mgr.cleanup(vm, agentName);
|
||||
} else {
|
||||
s_logger.debug("Ignoring VM in stopping mode: " + vm.getName());
|
||||
}
|
||||
} else if (serverState == State.Starting) {
|
||||
s_logger.debug("Ignoring VM in starting mode: " + vm.getName());
|
||||
_itMgr.stateTransitTo(vm, VirtualMachine.Event.AgentReportStopped, null);
|
||||
} else {
|
||||
s_logger.debug("Sending cleanup to a stopped vm: " + agentName);
|
||||
_itMgr.stateTransitTo(vm, VirtualMachine.Event.AgentReportStopped, null);
|
||||
command = info.mgr.cleanup(vm, agentName);
|
||||
}
|
||||
} else if (agentState == State.Running) {
|
||||
if (serverState == State.Starting) {
|
||||
if (fullSync) {
|
||||
s_logger.debug("VM state is starting on full sync so updating it to running");
|
||||
vm = info.mgr.findById(vm.getId());
|
||||
_itMgr.stateTransitTo(vm, Event.AgentReportRunning, vm.getHostId());
|
||||
info.mgr.finalizeStart(new VirtualMachineProfileImpl<VMInstanceVO>(vm), vm.getHostId(), null, null);
|
||||
}
|
||||
} else if (serverState == State.Stopping) {
|
||||
if (fullSync) {
|
||||
s_logger.debug("VM state is in stopping on fullsync so resend stop.");
|
||||
vm = info.mgr.findById(vm.getId());
|
||||
_itMgr.stateTransitTo(vm, Event.AgentReportStopped, null);
|
||||
info.mgr.finalizeStop(new VirtualMachineProfileImpl<VMInstanceVO>(vm), null);
|
||||
command = info.mgr.cleanup(vm, agentName);
|
||||
} else {
|
||||
s_logger.debug("VM is in stopping state so no action.");
|
||||
}
|
||||
} else if (serverState == State.Destroyed || serverState == State.Stopped || serverState == State.Expunging) {
|
||||
s_logger.debug("VM state is in stopped so stopping it on the agent");
|
||||
vm = info.mgr.findById(vm.getId());
|
||||
command = info.mgr.cleanup(vm, agentName);
|
||||
} else {
|
||||
_itMgr.stateTransitTo(vm, VirtualMachine.Event.AgentReportRunning, vm.getHostId());
|
||||
}
|
||||
} /*else if (agentState == State.Unknown) {
|
||||
if (serverState == State.Running) {
|
||||
if (fullSync) {
|
||||
vm = info.handler.get(vm.getId());
|
||||
}
|
||||
scheduleRestart(vm, false);
|
||||
} else if (serverState == State.Starting) {
|
||||
if (fullSync) {
|
||||
vm = info.handler.get(vm.getId());
|
||||
}
|
||||
scheduleRestart(vm, false);
|
||||
} else if (serverState == State.Stopping) {
|
||||
if (fullSync) {
|
||||
s_logger.debug("VM state is stopping in full sync. Resending stop");
|
||||
command = info.handler.cleanup(vm, agentName);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return command;
|
||||
}
|
||||
|
||||
public List<Command> fullSync(final long hostId, final Map<String, State> newStates) {
|
||||
final List<? extends VMInstanceVO> vms = _instanceDao.listByHostId(hostId);
|
||||
s_logger.debug("Found " + vms.size() + " VMs for host " + hostId);
|
||||
|
||||
final Map<Long, AgentVmInfo> states = convertToIds(newStates);
|
||||
final ArrayList<Command> commands = new ArrayList<Command>();
|
||||
|
||||
boolean nativeHA = isHostClusterNativeHAEnabled(hostId);
|
||||
|
||||
for (final VMInstanceVO vm : vms) {
|
||||
AgentVmInfo info = states.remove(vm.getId());
|
||||
|
||||
if (info == null) {
|
||||
info = new AgentVmInfo(null, findManager(vm.getType()), State.Stopped);
|
||||
}
|
||||
|
||||
assert info.mgr != null : "How can the manager be null for " + vm.getType();
|
||||
|
||||
VMInstanceVO vmCasted = info.mgr.findById(vm.getId());
|
||||
final Command command = compareState(vmCasted, info, true, nativeHA);
|
||||
if (command != null) {
|
||||
commands.add(command);
|
||||
}
|
||||
}
|
||||
|
||||
for (final AgentVmInfo left : states.values()) {
|
||||
s_logger.warn("Stopping a VM that we have no record of: " + left.name);
|
||||
commands.add(left.mgr.cleanup(null, left.name));
|
||||
}
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
protected Map<Long, AgentVmInfo> convertToIds(final Map<String, State> states) {
|
||||
final HashMap<Long, AgentVmInfo> map = new HashMap<Long, AgentVmInfo>();
|
||||
|
||||
if (states == null) {
|
||||
return map;
|
||||
}
|
||||
|
||||
final Collection<VirtualMachineGuru<VMInstanceVO>> handlers = _handlers.values();
|
||||
|
||||
for (final Map.Entry<String, State> entry : states.entrySet()) {
|
||||
for (final VirtualMachineGuru<VMInstanceVO> handler : handlers) {
|
||||
final String name = entry.getKey();
|
||||
|
||||
final Long id = handler.convertToId(name);
|
||||
|
||||
if (id != null) {
|
||||
map.put(id, new AgentVmInfo(entry.getKey(), handler, entry.getValue()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public List<Command> deltaSync(final long hostId, final Map<String, State> newStates) {
|
||||
final Map<Long, AgentVmInfo> states = convertToIds(newStates);
|
||||
final ArrayList<Command> commands = new ArrayList<Command>();
|
||||
|
||||
boolean nativeHA = isHostClusterNativeHAEnabled(hostId);
|
||||
|
||||
for (final Map.Entry<Long, AgentVmInfo> entry : states.entrySet()) {
|
||||
final AgentVmInfo info = entry.getValue();
|
||||
|
||||
final VMInstanceVO vm = info.mgr.findById(entry.getKey());
|
||||
|
||||
Command command = null;
|
||||
if (vm != null && vm.getHostId() != null && vm.getHostId() == hostId) {
|
||||
command = compareState(vm, info, false, nativeHA);
|
||||
} else {
|
||||
if(nativeHA) {
|
||||
if(vm.getHostId() != null && vm.getHostId() != hostId && info.state == VirtualMachine.State.Running) {
|
||||
vm.setHostId(hostId);
|
||||
_instanceDao.update(vm.getId(), vm);
|
||||
|
||||
s_logger.info("Native is enabled and we found VM has been switched from host " + vm.getHostId() + " to " + hostId);
|
||||
command = compareState(vm, info, false, nativeHA);
|
||||
}
|
||||
} else {
|
||||
s_logger.debug("VM is not found. Stopping " + info.name);
|
||||
command = info.mgr.cleanup(null, info.name);
|
||||
}
|
||||
}
|
||||
|
||||
if (command != null) {
|
||||
commands.add(command);
|
||||
}
|
||||
}
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
private boolean isHostClusterNativeHAEnabled(long hostId) {
|
||||
HostVO host = _hostDao.findById(hostId);
|
||||
ClusterDetailsVO detail = _clusterDetailsDao.findDetail(host.getClusterId(), "NativeHA");
|
||||
if(detail != null && detail.getValue() != null && detail.getValue().equalsIgnoreCase("true"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public Long migrate(final HaWorkVO work) {
|
||||
long vmId = work.getInstanceId();
|
||||
@ -740,137 +484,6 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
|
||||
return (System.currentTimeMillis() >> 10) + _migrateRetryInterval;
|
||||
}
|
||||
}
|
||||
// public Long migrate(final HaWorkVO work) {
|
||||
// final long vmId = work.getInstanceId();
|
||||
//
|
||||
// final VirtualMachineGuru<VMInstanceVO> mgr = findManager(work.getType());
|
||||
//
|
||||
// VMInstanceVO vm = mgr.findById(vmId);
|
||||
// if (vm == null || vm.getRemoved() != null) {
|
||||
// s_logger.debug("Unable to find the vm " + vmId);
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// s_logger.info("Migrating vm: " + vm.toString());
|
||||
// if (vm.getHostId() == null || vm.getHostId() != work.getHostId()) {
|
||||
// s_logger.info("VM is not longer running on the current hostId");
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// short alertType = AlertManager.ALERT_TYPE_USERVM_MIGRATE;
|
||||
// if (VirtualMachine.Type.DomainRouter.equals(vm.getType())) {
|
||||
// alertType = AlertManager.ALERT_TYPE_DOMAIN_ROUTER_MIGRATE;
|
||||
// } else if (VirtualMachine.Type.ConsoleProxy.equals(vm.getType())) {
|
||||
// alertType = AlertManager.ALERT_TYPE_CONSOLE_PROXY_MIGRATE;
|
||||
// }
|
||||
//
|
||||
// HostVO fromHost = _hostDao.findById(vm.getHostId());
|
||||
// String fromHostName = ((fromHost == null) ? "unknown" : fromHost.getName());
|
||||
// HostVO toHost = null;
|
||||
// if (work.getStep() == Step.Scheduled) {
|
||||
// if (vm.getState() != State.Running) {
|
||||
// s_logger.info("VM's state is not ready for migration. " + vm.toString() + " State is " + vm.getState().toString());
|
||||
// return (System.currentTimeMillis() >> 10) + _migrateRetryInterval;
|
||||
// }
|
||||
//
|
||||
// DataCenterVO dcVO = _dcDao.findById(fromHost.getDataCenterId());
|
||||
// HostPodVO podVO = _podDao.findById(fromHost.getPodId());
|
||||
//
|
||||
// try {
|
||||
// toHost = mgr.prepareForMigration(vm);
|
||||
// if (toHost == null) {
|
||||
// if (s_logger.isDebugEnabled()) {
|
||||
// s_logger.debug("Unable to find a host for migrating vm " + vmId);
|
||||
// }
|
||||
// _alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to migrate vm " + vm.getName() + " from host " + fromHostName + " in zone " + dcVO.getName() + " and pod " + podVO.getName(), "Unable to find a suitable host");
|
||||
// }
|
||||
// } catch(final InsufficientCapacityException e) {
|
||||
// s_logger.warn("Unable to mgirate due to insufficient capacity " + vm.toString());
|
||||
// _alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to migrate vm " + vm.getName() + " from host " + fromHostName + " in zone " + dcVO.getName() + " and pod " + podVO.getName(), "Insufficient capacity");
|
||||
// } catch(final StorageUnavailableException e) {
|
||||
// s_logger.warn("Storage is unavailable: " + vm.toString());
|
||||
// _alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to migrate vm " + vm.getName() + " from host " + fromHostName + " in zone " + dcVO.getName() + " and pod " + podVO.getName(), "Storage is gone.");
|
||||
// }
|
||||
//
|
||||
// if (toHost == null) {
|
||||
// _agentMgr.maintenanceFailed(vm.getHostId());
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// if (s_logger.isDebugEnabled()) {
|
||||
// s_logger.debug("Migrating from " + work.getHostId() + " to " + toHost.getId());
|
||||
// }
|
||||
// work.setStep(Step.Migrating);
|
||||
// work.setHostId(toHost.getId());
|
||||
// _haDao.update(work.getId(), work);
|
||||
// }
|
||||
//
|
||||
// if (work.getStep() == Step.Migrating) {
|
||||
// vm = mgr.findById(vmId); // let's see if anything has changed.
|
||||
// boolean migrated = false;
|
||||
// if (vm == null || vm.getRemoved() != null || vm.getHostId() == null || !_itMgr.stateTransitTo(vm, Event.MigrationRequested, vm.getHostId())) {
|
||||
// s_logger.info("Migration cancelled because state has changed: " + vm.toString());
|
||||
// } else {
|
||||
// try {
|
||||
// boolean isWindows = _guestOSCategoryDao.findById(_guestOSDao.findById(vm.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows");
|
||||
// MigrateCommand cmd = new MigrateCommand(vm.getInstanceName(), toHost.getPrivateIpAddress(), isWindows);
|
||||
// Answer answer = _agentMgr.send(fromHost.getId(), cmd);
|
||||
// if (answer != null && answer.getResult()) {
|
||||
// migrated = true;
|
||||
// _storageMgr.unshare(vm, fromHost);
|
||||
// work.setStep(Step.Investigating);
|
||||
// _haDao.update(work.getId(), work);
|
||||
// }
|
||||
// } catch (final AgentUnavailableException e) {
|
||||
// s_logger.debug("host became unavailable");
|
||||
// } catch (final OperationTimedoutException e) {
|
||||
// s_logger.debug("operation timed out");
|
||||
// if (e.isActive()) {
|
||||
// scheduleRestart(vm, true);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (!migrated) {
|
||||
// s_logger.info("Migration was unsuccessful. Cleaning up: " + vm.toString());
|
||||
//
|
||||
// DataCenterVO dcVO = _dcDao.findById(vm.getDataCenterId());
|
||||
// HostPodVO podVO = _podDao.findById(vm.getPodId());
|
||||
// _alertMgr.sendAlert(alertType, fromHost.getDataCenterId(), fromHost.getPodId(), "Unable to migrate vm " + vm.getName() + " from host " + fromHost.getName() + " in zone " + dcVO.getName() + " and pod " + podVO.getName(), "Migrate Command failed. Please check logs.");
|
||||
//
|
||||
// _itMgr.stateTransitTo(vm, Event.MigrationFailedOnSource, toHost.getId());
|
||||
// _agentMgr.maintenanceFailed(vm.getHostId());
|
||||
//
|
||||
// Command cleanup = mgr.cleanup(vm, null);
|
||||
// _agentMgr.easySend(toHost.getId(), cleanup);
|
||||
// _storageMgr.unshare(vm, toHost);
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (toHost == null) {
|
||||
// toHost = _hostDao.findById(work.getHostId());
|
||||
// }
|
||||
// DataCenterVO dcVO = _dcDao.findById(toHost.getDataCenterId());
|
||||
// HostPodVO podVO = _podDao.findById(toHost.getPodId());
|
||||
//
|
||||
// try {
|
||||
// if (!mgr.completeMigration(vm, toHost)) {
|
||||
// _alertMgr.sendAlert(alertType, toHost.getDataCenterId(), toHost.getPodId(), "Unable to migrate " + vmId + " to host " + toHost.getName() + " in zone " + dcVO.getName() + " and pod " + podVO.getName(), "Migration not completed");
|
||||
// s_logger.warn("Unable to complete migration: " + vm.toString());
|
||||
// } else {
|
||||
// s_logger.info("Migration is complete: " + vm.toString());
|
||||
// }
|
||||
// return null;
|
||||
// } catch (final AgentUnavailableException e) {
|
||||
// s_logger.warn("Agent is unavailable for " + vm.toString());
|
||||
// } catch (final OperationTimedoutException e) {
|
||||
// s_logger.warn("Operation timed outfor " + vm.toString());
|
||||
// }
|
||||
// _itMgr.stateTransitTo(vm, Event.MigrationFailedOnDest, toHost.getId());
|
||||
// return (System.currentTimeMillis() >> 10) + _migrateRetryInterval;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void scheduleDestroy(VMInstanceVO vm, long hostId) {
|
||||
@ -888,8 +501,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
|
||||
}
|
||||
|
||||
protected Long destroyVM(HaWorkVO work) {
|
||||
final VirtualMachineGuru<VMInstanceVO> mgr = findManager(work.getType());
|
||||
final VMInstanceVO vm = mgr.findById(work.getInstanceId());
|
||||
final VMInstanceVO vm = _itMgr.findById(work.getType(), work.getInstanceId());
|
||||
s_logger.info("Destroying " + vm.toString());
|
||||
try {
|
||||
if (vm.getState() != State.Destroyed) {
|
||||
@ -922,16 +534,15 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
|
||||
}
|
||||
|
||||
protected Long stopVM(final HaWorkVO work) {
|
||||
final VirtualMachineGuru<VMInstanceVO> mgr = findManager(work.getType());
|
||||
final VMInstanceVO vm = mgr.findById(work.getInstanceId());
|
||||
final VMInstanceVO vm = _itMgr.findById(work.getType(), work.getInstanceId());
|
||||
s_logger.info("Stopping " + vm.toString());
|
||||
try {
|
||||
if (work.getWorkType() == WorkType.Stop) {
|
||||
if (vm.getHostId() != null) {
|
||||
if (mgr.stop(vm)) {
|
||||
s_logger.info("Successfully stopped " + vm.toString());
|
||||
return null;
|
||||
}
|
||||
// FIXME if (_itMgr.advanceStop(vm, false, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount())) {
|
||||
// s_logger.info("Successfully stopped " + vm.toString());
|
||||
// return null;
|
||||
// }
|
||||
} else {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug(vm.toString() + " has already been stopped");
|
||||
@ -945,11 +556,12 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
|
||||
}
|
||||
return null;
|
||||
} else {
|
||||
Command cmd = mgr.cleanup(vm, null);
|
||||
Command cmd = null;
|
||||
//FIXME Command cmd = _itMgr.cleanup(vm.getInstanceName());
|
||||
Answer ans = _agentMgr.send(work.getHostId(), cmd);
|
||||
if (ans.getResult()) {
|
||||
_itMgr.stateTransitTo(vm, Event.AgentReportStopped, null);
|
||||
mgr.finalizeStop(new VirtualMachineProfileImpl<VMInstanceVO>(vm), (StopAnswer)ans);
|
||||
//FIXME mgr.finalizeStop(new VirtualMachineProfileImpl<VMInstanceVO>(vm), (StopAnswer)ans);
|
||||
s_logger.info("Successfully stopped " + vm.toString());
|
||||
return null;
|
||||
}
|
||||
@ -1023,9 +635,6 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
|
||||
value = params.get("time.between.cleanup");
|
||||
_timeBetweenCleanups = NumbersUtil.parseLong(value, 3600 * 24);
|
||||
|
||||
value = params.get("wait");
|
||||
_operationTimeout = NumbersUtil.parseInt(value, 1800) * 2;
|
||||
|
||||
value = params.get("stop.retry.interval");
|
||||
_stopRetryInterval = NumbersUtil.parseInt(value, 10 * 60);
|
||||
|
||||
@ -1047,8 +656,6 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
|
||||
|
||||
_executor = Executors.newScheduledThreadPool(count, new NamedThreadFactory("HA"));
|
||||
|
||||
_agentMgr.registerForHostEvents(new VmSyncListener(this, _agentMgr), true, true, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1066,7 +673,6 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
|
||||
}
|
||||
|
||||
_executor.scheduleAtFixedRate(new CleanupTask(), _timeBetweenCleanups, _timeBetweenCleanups, TimeUnit.SECONDS);
|
||||
_executor.scheduleAtFixedRate(new TransitionTask(), 0, _operationTimeout, TimeUnit.SECONDS);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1171,49 +777,4 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager {
|
||||
}
|
||||
}
|
||||
|
||||
protected class TransitionTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
GlobalLock lock = GlobalLock.getInternLock("TransitionChecking");
|
||||
if (lock == null) {
|
||||
s_logger.debug("Couldn't get the global lock");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!lock.lock(30)) {
|
||||
s_logger.debug("Couldn't lock the db");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
lock.addRef();
|
||||
List<VMInstanceVO> instances = _instanceDao.findVMInTransition(new Date(new Date().getTime() - (_operationTimeout * 1000)), State.Starting, State.Stopping);
|
||||
for (VMInstanceVO instance : instances) {
|
||||
State state = instance.getState();
|
||||
if (state == State.Stopping) {
|
||||
scheduleStop(instance, instance.getHostId(), true);
|
||||
} else if (state == State.Starting) {
|
||||
scheduleRestart(instance, true);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Caught the following exception on transition checking", e);
|
||||
} finally {
|
||||
StackMaid.current().exitCleanup();
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected class AgentVmInfo {
|
||||
public String name;
|
||||
public VirtualMachineGuru<VMInstanceVO> mgr;
|
||||
public State state;
|
||||
public State action;
|
||||
|
||||
public AgentVmInfo(final String name, final VirtualMachineGuru<VMInstanceVO> handler, final State state) {
|
||||
this.name = name;
|
||||
this.mgr = handler;
|
||||
this.state = state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,149 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.cloud.ha;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.AgentManager.OnError;
|
||||
import com.cloud.agent.Listener;
|
||||
import com.cloud.agent.api.AgentControlAnswer;
|
||||
import com.cloud.agent.api.AgentControlCommand;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.PingRoutingCommand;
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.agent.api.StartupRoutingCommand;
|
||||
import com.cloud.agent.manager.Commands;
|
||||
import com.cloud.exception.AgentUnavailableException;
|
||||
import com.cloud.exception.ConnectionException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
|
||||
public class VmSyncListener implements Listener {
|
||||
private static final Logger s_logger = Logger.getLogger(VmSyncListener.class);
|
||||
|
||||
long _hostId;
|
||||
HostDao _dao;
|
||||
HighAvailabilityManagerImpl _haMgr;
|
||||
AgentManager _agentMgr;
|
||||
|
||||
public VmSyncListener(HighAvailabilityManagerImpl mgr, AgentManager agentMgr) {
|
||||
_haMgr = mgr;
|
||||
_agentMgr = agentMgr;
|
||||
|
||||
}
|
||||
public VmSyncListener(HostDao dao, long hostId) {
|
||||
_dao = dao;
|
||||
_hostId = hostId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRecurring() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processAnswers(long agentId, long seq, Answer[] answers) {
|
||||
for (final Answer answer : answers) {
|
||||
if (!answer.getResult()) {
|
||||
s_logger.warn("Cleanup failed due to " + answer.getDetails());
|
||||
} else {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Cleanup succeeded. Details " + answer.getDetails());
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processTimeout(long agentId, long seq) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTimeout() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processCommands(long agentId, long seq, Command[] req) {
|
||||
boolean processed = false;
|
||||
for (Command cmd : req) {
|
||||
if (cmd instanceof PingRoutingCommand) {
|
||||
PingRoutingCommand ping = (PingRoutingCommand)cmd;
|
||||
if (ping.getNewStates().size() > 0) {
|
||||
List<Command> commands = _haMgr.deltaSync(agentId, ping.getNewStates());
|
||||
if (commands.size() > 0) {
|
||||
try {
|
||||
Commands cmds = new Commands(OnError.Continue);
|
||||
cmds.addCommands(commands);
|
||||
_agentMgr.send(agentId, cmds, this);
|
||||
} catch (final AgentUnavailableException e) {
|
||||
s_logger.warn("Agent is now unavailable", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
processed = true;
|
||||
}
|
||||
}
|
||||
return processed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AgentControlAnswer processControlCommand(long agentId, AgentControlCommand cmd) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processDisconnect(long agentId, Status state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processConnect(HostVO agent, StartupCommand cmd) throws ConnectionException {
|
||||
if (!(cmd instanceof StartupRoutingCommand)) {
|
||||
return;
|
||||
}
|
||||
|
||||
long agentId = agent.getId();
|
||||
|
||||
StartupRoutingCommand startup = (StartupRoutingCommand)cmd;
|
||||
|
||||
List<Command> commands = _haMgr.fullSync(agentId, startup.getVmStates());
|
||||
s_logger.debug("Sending clean commands to the agent");
|
||||
|
||||
if (commands.size() > 0) {
|
||||
Commands cmds = new Commands(OnError.Continue);
|
||||
cmds.addCommands(commands);
|
||||
try {
|
||||
Answer[] answers = _agentMgr.send(agentId, cmds);
|
||||
} catch (final AgentUnavailableException e) {
|
||||
s_logger.warn("Agent is unavailable now", e);
|
||||
throw new ConnectionException(true, "Unable to sync", e);
|
||||
} catch (final OperationTimedoutException e) {
|
||||
throw new ConnectionException(true, "Unable to sync", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -57,7 +57,7 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis
|
||||
ServiceOffering offering = vmProfile.getServiceOffering();
|
||||
VirtualMachine vm = vmProfile.getVirtualMachine();
|
||||
|
||||
VirtualMachineTO to = new VirtualMachineTO(vm.getId(), vm.getInstanceName(), vm.getType(), offering.getCpu(), offering.getSpeed(), offering.getRamSize() * 1024l * 1024l, offering.getRamSize() * 1024l * 1024l, null, null);
|
||||
VirtualMachineTO to = new VirtualMachineTO(vm.getId(), vm.getInstanceName(), vm.getType(), offering.getCpu(), offering.getSpeed(), offering.getRamSize() * 1024l * 1024l, offering.getRamSize() * 1024l * 1024l, null, null, vm.isHaEnabled());
|
||||
to.setBootArgs(vmProfile.getBootArgs());
|
||||
|
||||
List<NicProfile> nicProfiles = vmProfile.getNics();
|
||||
@ -70,10 +70,11 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis
|
||||
to.setNics(nics);
|
||||
to.setDisks(vmProfile.getDisks().toArray(new VolumeTO[vmProfile.getDisks().size()]));
|
||||
|
||||
if(vmProfile.getTemplate().getBits() == 32)
|
||||
to.setArch("i686");
|
||||
else
|
||||
to.setArch("x86_64");
|
||||
if(vmProfile.getTemplate().getBits() == 32) {
|
||||
to.setArch("i686");
|
||||
} else {
|
||||
to.setArch("x86_64");
|
||||
}
|
||||
|
||||
return to;
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru {
|
||||
public <T extends VirtualMachine> VirtualMachineTO implement(VirtualMachineProfile<T> vm) {
|
||||
VirtualMachineTO to = toVirtualMachineTO(vm);
|
||||
to.setBootloader(BootloaderType.HVM);
|
||||
|
||||
|
||||
// Determine the VM's OS description
|
||||
GuestOSVO guestOS = _guestOsDao.findById(vm.getVirtualMachine().getGuestOSId());
|
||||
to.setOs(guestOS.getDisplayName());
|
||||
|
||||
@ -83,7 +83,6 @@ import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.exception.StorageUnavailableException;
|
||||
import com.cloud.ha.HighAvailabilityManager;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.IPAddressVO;
|
||||
@ -129,7 +128,6 @@ import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.storage.StorageManager;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.dao.GuestOSDao;
|
||||
import com.cloud.storage.dao.StoragePoolDao;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.storage.dao.VMTemplateHostDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
@ -227,8 +225,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
@Inject
|
||||
StorageManager _storageMgr;
|
||||
@Inject
|
||||
HighAvailabilityManager _haMgr;
|
||||
@Inject
|
||||
AlertManager _alertMgr;
|
||||
@Inject
|
||||
AccountManager _accountMgr;
|
||||
@ -239,8 +235,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
@Inject
|
||||
AsyncJobManager _asyncMgr;
|
||||
@Inject
|
||||
StoragePoolDao _storagePoolDao = null;
|
||||
@Inject
|
||||
ServiceOfferingDao _serviceOfferingDao = null;
|
||||
@Inject
|
||||
UserVmDao _userVmDao;
|
||||
@ -257,8 +251,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
@Inject
|
||||
NetworkDao _networksDao = null;
|
||||
@Inject
|
||||
NicDao _nicDao;
|
||||
@Inject
|
||||
GuestOSDao _guestOSDao = null;
|
||||
@Inject
|
||||
NetworkManager _networkMgr;
|
||||
@ -280,6 +272,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
RemoteAccessVpnDao _vpnDao;
|
||||
@Inject
|
||||
VMInstanceDao _instanceDao;
|
||||
@Inject
|
||||
NicDao _nicDao;
|
||||
|
||||
int _routerRamSize;
|
||||
int _retry = 2;
|
||||
@ -589,7 +583,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
}
|
||||
|
||||
_agentMgr.registerForHostEvents(new SshKeysDistriMonitor(this, _hostDao, _configDao), true, false, false);
|
||||
_haMgr.registerHandler(VirtualMachine.Type.DomainRouter, this);
|
||||
_itMgr.registerGuru(VirtualMachine.Type.DomainRouter, this);
|
||||
|
||||
boolean useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key()));
|
||||
@ -911,7 +904,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
buf.append(" template=domP type=" + type);
|
||||
buf.append(" name=").append(profile.getHostName());
|
||||
NicProfile controlNic = null;
|
||||
NicProfile managementNic = null;
|
||||
|
||||
for (NicProfile nic : profile.getNics()) {
|
||||
int deviceId = nic.getDeviceId();
|
||||
@ -933,7 +925,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
}
|
||||
if (nic.getTrafficType() == TrafficType.Management) {
|
||||
buf.append(" localgw=").append(dest.getPod().getGateway());
|
||||
managementNic = nic;
|
||||
} else if (nic.getTrafficType() == TrafficType.Control) {
|
||||
|
||||
// DOMR control command is sent over management server in VMware
|
||||
@ -995,17 +986,16 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
|
||||
DomainRouterVO router = profile.getVirtualMachine();
|
||||
|
||||
List<NicVO> nics = _nicDao.listBy(router.getId());
|
||||
for (NicVO nic : nics) {
|
||||
NetworkVO network = _networkDao.findById(nic.getNetworkId());
|
||||
if (network.getTrafficType() == TrafficType.Public) {
|
||||
List<NicProfile> nics = profile.getNics();
|
||||
for (NicProfile nic : nics) {
|
||||
if (nic.getTrafficType() == TrafficType.Public) {
|
||||
router.setPublicIpAddress(nic.getIp4Address());
|
||||
router.setPublicNetmask(nic.getNetmask());
|
||||
router.setPublicMacAddress(nic.getMacAddress());
|
||||
} else if (network.getTrafficType() == TrafficType.Guest) {
|
||||
} else if (nic.getTrafficType() == TrafficType.Guest) {
|
||||
router.setGuestIpAddress(nic.getIp4Address());
|
||||
router.setGuestMacAddress(nic.getMacAddress());
|
||||
} else if (network.getTrafficType() == TrafficType.Control) {
|
||||
} else if (nic.getTrafficType() == TrafficType.Control) {
|
||||
router.setPrivateIpAddress(nic.getIp4Address());
|
||||
router.setPrivateMacAddress(nic.getMacAddress());
|
||||
}
|
||||
@ -1587,20 +1577,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
return sendCommandsToRouter(router, cmds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DomainRouterVO start(long vmId) throws InsufficientCapacityException, StorageUnavailableException,
|
||||
ConcurrentOperationException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop(DomainRouterVO router) throws ResourceUnavailableException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private List<Long> findLonelyRouters() {
|
||||
List<Long> routersToStop = new ArrayList<Long>();
|
||||
List<VMInstanceVO> runningRouters = _instanceDao.listByTypeAndState(State.Running, VirtualMachine.Type.DomainRouter);
|
||||
|
||||
@ -44,16 +44,12 @@ import com.cloud.agent.api.StopCommand;
|
||||
import com.cloud.agent.api.check.CheckSshAnswer;
|
||||
import com.cloud.agent.api.check.CheckSshCommand;
|
||||
import com.cloud.agent.manager.Commands;
|
||||
import com.cloud.async.AsyncJobExecutor;
|
||||
import com.cloud.async.AsyncJobManager;
|
||||
import com.cloud.async.AsyncJobVO;
|
||||
import com.cloud.async.BaseAsyncJobExecutor;
|
||||
import com.cloud.cluster.ClusterManager;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.DataCenter.NetworkType;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.deploy.DataCenterDeployment;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
@ -61,25 +57,22 @@ 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.Host;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.info.RunningHostCountInfo;
|
||||
import com.cloud.info.RunningHostInfoAgregator;
|
||||
import com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo;
|
||||
import com.cloud.network.IpAddrAllocator;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.NetworkVO;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.offerings.NetworkOfferingVO;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.dao.StoragePoolHostDao;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.storage.dao.VMTemplateHostDao;
|
||||
@ -102,16 +95,14 @@ import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.utils.net.NfsUtils;
|
||||
import com.cloud.vm.Nic;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.SecondaryStorageVmVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachineGuru;
|
||||
import com.cloud.vm.VirtualMachineManager;
|
||||
import com.cloud.vm.VirtualMachineName;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
import com.cloud.vm.dao.SecondaryStorageVmDao;
|
||||
|
||||
//
|
||||
@ -188,14 +179,6 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
|
||||
private AccountService _accountMgr;
|
||||
@Inject
|
||||
private VirtualMachineManager _itMgr;
|
||||
@Inject
|
||||
private NicDao _nicDao;
|
||||
@Inject
|
||||
private NetworkDao _networkDao;
|
||||
|
||||
private IpAddrAllocator _IpAllocator;
|
||||
|
||||
private AsyncJobManager _asyncMgr;
|
||||
|
||||
private final ScheduledExecutorService _capacityScanScheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory("SS-Scan"));
|
||||
|
||||
@ -203,7 +186,6 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
|
||||
|
||||
private int _secStorageVmRamSize;
|
||||
|
||||
private String _domain;
|
||||
private String _instance;
|
||||
private boolean _useLocalStorage;
|
||||
private boolean _useSSlCopy;
|
||||
@ -215,17 +197,16 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
|
||||
@Override
|
||||
public SecondaryStorageVmVO startSecStorageVm(long secStorageVmId) {
|
||||
try {
|
||||
SecondaryStorageVmVO ssvm = start(secStorageVmId);
|
||||
return ssvm;
|
||||
SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
|
||||
Account systemAcct = _accountMgr.getSystemAccount();
|
||||
User systemUser = _accountMgr.getSystemUser();
|
||||
return _itMgr.start(secStorageVm, null, systemUser, systemAcct);
|
||||
} catch (StorageUnavailableException e) {
|
||||
s_logger.warn("Exception while trying to start secondary storage vm", e);
|
||||
return null;
|
||||
} catch (InsufficientCapacityException e) {
|
||||
s_logger.warn("Exception while trying to start secondary storage vm", e);
|
||||
return null;
|
||||
} catch (ConcurrentOperationException e) {
|
||||
s_logger.warn("Exception while trying to start secondary storage vm", e);
|
||||
return null;
|
||||
} catch (ResourceUnavailableException e) {
|
||||
s_logger.warn("Exception while trying to start secondary storage vm", e);
|
||||
return null;
|
||||
@ -235,15 +216,6 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SecondaryStorageVmVO start(long secStorageVmId) throws ResourceUnavailableException, InsufficientCapacityException,
|
||||
ConcurrentOperationException {
|
||||
SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
|
||||
Account systemAcct = _accountMgr.getSystemAccount();
|
||||
User systemUser = _accountMgr.getSystemUser();
|
||||
return _itMgr.start(secStorageVm, null, systemUser, systemAcct);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generateFirewallConfiguration(Long hostId) {
|
||||
if (hostId == null) {
|
||||
@ -788,11 +760,6 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
|
||||
String value = configs.get("secstorage.capacityscan.interval");
|
||||
_capacityScanInterval = NumbersUtil.parseLong(value, DEFAULT_CAPACITY_SCAN_INTERVAL);
|
||||
|
||||
_domain = configs.get("domain");
|
||||
if (_domain == null) {
|
||||
_domain = "foo.com";
|
||||
}
|
||||
|
||||
_instance = configs.get("instance.name");
|
||||
if (_instance == null) {
|
||||
_instance = "DEFAULT";
|
||||
@ -810,11 +777,6 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
|
||||
_listener = new SecondaryStorageListener(this);
|
||||
_agentMgr.registerForHostEvents(_listener, true, true, false);
|
||||
|
||||
HighAvailabilityManager haMgr = locator.getManager(HighAvailabilityManager.class);
|
||||
if (haMgr != null) {
|
||||
haMgr.registerHandler(VirtualMachine.Type.SecondaryStorageVm, this);
|
||||
}
|
||||
|
||||
_itMgr.registerGuru(VirtualMachine.Type.SecondaryStorageVm, this);
|
||||
|
||||
_useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key()));
|
||||
@ -858,15 +820,15 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
|
||||
@Override
|
||||
public boolean stopSecStorageVm(long secStorageVmId) {
|
||||
|
||||
AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor();
|
||||
if (asyncExecutor != null) {
|
||||
AsyncJobVO job = asyncExecutor.getJob();
|
||||
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Stop secondary storage vm " + secStorageVmId + ", update async job-" + job.getId());
|
||||
}
|
||||
_asyncMgr.updateAsyncJobAttachment(job.getId(), "secStorageVm", secStorageVmId);
|
||||
}
|
||||
// AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor();
|
||||
// if (asyncExecutor != null) {
|
||||
// AsyncJobVO job = asyncExecutor.getJob();
|
||||
//
|
||||
// if (s_logger.isInfoEnabled()) {
|
||||
// s_logger.info("Stop secondary storage vm " + secStorageVmId + ", update async job-" + job.getId());
|
||||
// }
|
||||
// _asyncMgr.updateAsyncJobAttachment(job.getId(), "secStorageVm", secStorageVmId);
|
||||
// }
|
||||
|
||||
SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
|
||||
if (secStorageVm == null) {
|
||||
@ -877,7 +839,31 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return stop(secStorageVm);
|
||||
if (secStorageVm.getHostId() != null) {
|
||||
GlobalLock secStorageVmLock = GlobalLock.getInternLock(getSecStorageVmLockName(secStorageVm.getId()));
|
||||
try {
|
||||
if (secStorageVmLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
|
||||
try {
|
||||
boolean result = _itMgr.stop(secStorageVm, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
|
||||
if (result) {
|
||||
}
|
||||
|
||||
return result;
|
||||
} finally {
|
||||
secStorageVmLock.unlock();
|
||||
}
|
||||
} else {
|
||||
String msg = "Unable to acquire secondary storage vm lock : " + secStorageVm.toString();
|
||||
s_logger.debug(msg);
|
||||
return false;
|
||||
}
|
||||
} finally {
|
||||
secStorageVmLock.releaseRef();
|
||||
}
|
||||
}
|
||||
|
||||
// vm was already stopped, return true
|
||||
return true;
|
||||
} catch (ResourceUnavailableException e) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Stopping secondary storage vm " + secStorageVm.getName() + " faled : exception " + e.toString());
|
||||
@ -888,15 +874,15 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
|
||||
|
||||
@Override
|
||||
public boolean rebootSecStorageVm(long secStorageVmId) {
|
||||
AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor();
|
||||
if (asyncExecutor != null) {
|
||||
AsyncJobVO job = asyncExecutor.getJob();
|
||||
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Reboot secondary storage vm " + secStorageVmId + ", update async job-" + job.getId());
|
||||
}
|
||||
_asyncMgr.updateAsyncJobAttachment(job.getId(), "secstorage_vm", secStorageVmId);
|
||||
}
|
||||
// AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor();
|
||||
// if (asyncExecutor != null) {
|
||||
// AsyncJobVO job = asyncExecutor.getJob();
|
||||
//
|
||||
// if (s_logger.isInfoEnabled()) {
|
||||
// s_logger.info("Reboot secondary storage vm " + secStorageVmId + ", update async job-" + job.getId());
|
||||
// }
|
||||
// _asyncMgr.updateAsyncJobAttachment(job.getId(), "secstorage_vm", secStorageVmId);
|
||||
// }
|
||||
|
||||
final SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
|
||||
|
||||
@ -944,60 +930,8 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop(SecondaryStorageVmVO secStorageVm) throws ResourceUnavailableException {
|
||||
if (secStorageVm.getHostId() != null) {
|
||||
GlobalLock secStorageVmLock = GlobalLock.getInternLock(getSecStorageVmLockName(secStorageVm.getId()));
|
||||
try {
|
||||
if (secStorageVmLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
|
||||
try {
|
||||
boolean result = _itMgr.stop(secStorageVm, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
|
||||
if (result) {
|
||||
}
|
||||
|
||||
return result;
|
||||
} finally {
|
||||
secStorageVmLock.unlock();
|
||||
}
|
||||
} else {
|
||||
String msg = "Unable to acquire secondary storage vm lock : " + secStorageVm.toString();
|
||||
s_logger.debug(msg);
|
||||
return false;
|
||||
}
|
||||
} finally {
|
||||
secStorageVmLock.releaseRef();
|
||||
}
|
||||
}
|
||||
|
||||
// vm was already stopped, return true
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAgentConnect(Long dcId, StartupCommand cmd) {
|
||||
if (_IpAllocator != null && _IpAllocator.exteralIpAddressAllocatorEnabled()) {
|
||||
List<SecondaryStorageVmVO> zoneSsvms = _secStorageVmDao.listByZoneId(dcId);
|
||||
if (zoneSsvms.size() == 0) {
|
||||
return;
|
||||
}
|
||||
SecondaryStorageVmVO secStorageVm = zoneSsvms.get(0);// FIXME:
|
||||
// assumes one
|
||||
// vm per zone.
|
||||
secStorageVm.setPrivateIpAddress(cmd.getStorageIpAddress()); /*
|
||||
* FIXME:
|
||||
* privateipaddress
|
||||
* is
|
||||
* overwrited
|
||||
* with
|
||||
* address
|
||||
* of
|
||||
* secondary
|
||||
* storage
|
||||
*/
|
||||
secStorageVm.setPublicIpAddress(cmd.getPublicIpAddress());
|
||||
secStorageVm.setPublicNetmask(cmd.getPublicNetmask());
|
||||
_secStorageVmDao.persist(secStorageVm);
|
||||
}
|
||||
}
|
||||
|
||||
private String getCapacityScanLockName() {
|
||||
@ -1132,15 +1066,14 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
|
||||
|
||||
SecondaryStorageVmVO secVm = profile.getVirtualMachine();
|
||||
DataCenter dc = dest.getDataCenter();
|
||||
List<NicVO> nics = _nicDao.listBy(secVm.getId());
|
||||
for (NicVO nic : nics) {
|
||||
NetworkVO network = _networkDao.findById(nic.getNetworkId());
|
||||
if ((network.getTrafficType() == TrafficType.Public && dc.getNetworkType() == NetworkType.Advanced)
|
||||
|| (network.getTrafficType() == TrafficType.Guest && dc.getNetworkType() == NetworkType.Basic)) {
|
||||
List<NicProfile> nics = profile.getNics();
|
||||
for (NicProfile nic : nics) {
|
||||
if ((nic.getTrafficType() == TrafficType.Public && dc.getNetworkType() == NetworkType.Advanced)
|
||||
|| (nic.getTrafficType() == TrafficType.Guest && dc.getNetworkType() == NetworkType.Basic)) {
|
||||
secVm.setPublicIpAddress(nic.getIp4Address());
|
||||
secVm.setPublicNetmask(nic.getNetmask());
|
||||
secVm.setPublicMacAddress(nic.getMacAddress());
|
||||
} else if (network.getTrafficType() == TrafficType.Management) {
|
||||
} else if (nic.getTrafficType() == TrafficType.Management) {
|
||||
secVm.setPrivateIpAddress(nic.getIp4Address());
|
||||
secVm.setPrivateMacAddress(nic.getMacAddress());
|
||||
}
|
||||
|
||||
@ -66,7 +66,6 @@ import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.NetworkVO;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.router.VirtualNetworkApplianceManager;
|
||||
import com.cloud.network.security.SecurityGroupManager;
|
||||
import com.cloud.network.security.dao.SecurityGroupDao;
|
||||
import com.cloud.server.Criteria;
|
||||
@ -95,13 +94,14 @@ import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.InstanceGroupVO;
|
||||
import com.cloud.vm.UserVmManager;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachineManager;
|
||||
import com.cloud.vm.dao.InstanceGroupDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
||||
@Local(value={AccountManager.class, AccountService.class})
|
||||
public class AccountManagerImpl implements AccountManager, AccountService, Manager {
|
||||
@ -117,10 +117,10 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
@Inject private UserAccountDao _userAccountDao;
|
||||
@Inject private VolumeDao _volumeDao;
|
||||
@Inject private UserVmDao _userVmDao;
|
||||
@Inject private DomainRouterDao _routerDao;
|
||||
@Inject private VMTemplateDao _templateDao;
|
||||
@Inject private NetworkDao _networkDao;
|
||||
@Inject private SecurityGroupDao _securityGroupDao;
|
||||
@Inject private VMInstanceDao _vmDao;
|
||||
|
||||
|
||||
@Inject private SecurityGroupManager _networkGroupMgr;
|
||||
@ -129,8 +129,8 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
@Inject private UserVmManager _vmMgr;
|
||||
@Inject private StorageManager _storageMgr;
|
||||
@Inject private TemplateManager _tmpltMgr;
|
||||
@Inject private VirtualNetworkApplianceManager _routerMgr;
|
||||
@Inject private ConfigurationManager _configMgr;
|
||||
@Inject private VirtualMachineManager _itMgr;
|
||||
|
||||
private final ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("AccountChecker"));
|
||||
|
||||
@ -848,8 +848,9 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
// Mark the account's volumes as destroyed
|
||||
List<VolumeVO> volumes = _volumeDao.findDetachedByAccount(accountId);
|
||||
for (VolumeVO volume : volumes) {
|
||||
if(!volume.getState().equals(Volume.State.Destroy))//This check if for account with vm in error state; when a vm is in error state the vols are already destroyed on that account
|
||||
if(!volume.getState().equals(Volume.State.Destroy)) {
|
||||
_storageMgr.destroyVolume(volume);
|
||||
}
|
||||
}
|
||||
|
||||
//Cleanup security groups
|
||||
@ -913,22 +914,17 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
|
||||
private boolean doDisableAccount(long accountId) throws ConcurrentOperationException, ResourceUnavailableException{
|
||||
List<UserVmVO> vms = _userVmDao.listByAccountId(accountId);
|
||||
List<VMInstanceVO> vms = _vmDao.listByAccountId(accountId);
|
||||
boolean success = true;
|
||||
for (UserVmVO vm : vms) {
|
||||
for (VMInstanceVO vm : vms) {
|
||||
try {
|
||||
success = (success && _vmMgr.stop(vm));
|
||||
success = (success && _itMgr.stop(vm, getSystemUser(), getSystemAccount()));
|
||||
} catch (AgentUnavailableException aue) {
|
||||
s_logger.warn("Agent running on host " + vm.getHostId() + " is unavailable, unable to stop vm " + vm.getName());
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
List<DomainRouterVO> routers = _routerDao.listBy(accountId);
|
||||
for (DomainRouterVO router : routers) {
|
||||
success = (success && (_routerMgr.stopRouter(router.getId()) != null));
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@ -949,7 +945,6 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
String timezone = cmd.getTimezone();
|
||||
String accountName = cmd.getAccountName();
|
||||
short userType = cmd.getAccountType().shortValue();
|
||||
Long userId = UserContext.current().getCallerUserId();
|
||||
|
||||
try {
|
||||
if (accountName == null) {
|
||||
@ -1039,7 +1034,6 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
String email = cmd.getEmail();
|
||||
String timeZone = cmd.getTimezone();
|
||||
Long accountId = null;
|
||||
Long userId = UserContext.current().getCallerUserId();
|
||||
|
||||
Account account = _accountDao.findActiveAccount(accountName, domainId);
|
||||
|
||||
@ -1136,7 +1130,6 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("updating user with id: " + id);
|
||||
}
|
||||
UserAccount userAccount = _userAccountDao.findById(id);
|
||||
try {
|
||||
//check if the apiKey and secretKey are globally unique
|
||||
if (apiKey != null && secretKey != null) {
|
||||
@ -1498,6 +1491,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account finalizeOwner(Account caller, String accountName, Long domainId) {
|
||||
//don't default the owner to the system account
|
||||
if (caller.getId() == Account.ACCOUNT_ID_SYSTEM && (accountName == null || domainId == null)) {
|
||||
|
||||
@ -119,8 +119,6 @@ import com.cloud.network.dao.LoadBalancerDao;
|
||||
import com.cloud.network.dao.LoadBalancerVMMapDao;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.lb.LoadBalancingRulesManager;
|
||||
import com.cloud.network.ovs.OvsNetworkManager;
|
||||
import com.cloud.network.ovs.OvsTunnelManager;
|
||||
import com.cloud.network.router.VirtualNetworkApplianceManager;
|
||||
import com.cloud.network.rules.RulesManager;
|
||||
import com.cloud.network.security.SecurityGroupManager;
|
||||
@ -400,12 +398,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop(UserVmVO vm) {
|
||||
return stopVirtualMachine(_accountMgr.getSystemUser().getId(), vm.getId());
|
||||
}
|
||||
|
||||
|
||||
@Override @ActionEvent(eventType = EventTypes.EVENT_VOLUME_ATTACH, eventDescription = "attaching volume", async=true)
|
||||
public Volume attachVolumeToVM(AttachVolumeCmd command) {
|
||||
Long vmId = command.getVirtualMachineId();
|
||||
@ -1084,7 +1076,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
||||
|
||||
_executor = Executors.newScheduledThreadPool(wrks, new NamedThreadFactory("UserVm-Scavenger"));
|
||||
|
||||
_haMgr.registerHandler(Type.User, this);
|
||||
_itMgr.registerGuru(Type.User, this);
|
||||
|
||||
s_logger.info("User VM Manager is configured.");
|
||||
@ -1135,11 +1126,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
||||
return VirtualMachineName.getVmId(vmName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVmVO start(long vmId) throws StorageUnavailableException, ConcurrentOperationException {
|
||||
return null; // FIXME start(1L, vmId, null, null, startEventId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVm startUserVm(long vmId) throws ConcurrentOperationException, ExecutionException, ResourceUnavailableException, InsufficientCapacityException {
|
||||
return startVirtualMachine(vmId);
|
||||
|
||||
@ -21,11 +21,7 @@ import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.StopAnswer;
|
||||
import com.cloud.agent.manager.Commands;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.exception.StorageUnavailableException;
|
||||
import com.cloud.utils.exception.ExecutionException;
|
||||
|
||||
/**
|
||||
* A VirtualMachineGuru knows how to process a certain type of virtual machine.
|
||||
@ -77,28 +73,6 @@ public interface VirtualMachineGuru<T extends VirtualMachine> {
|
||||
*/
|
||||
Long convertToId(String vmName);
|
||||
|
||||
/**
|
||||
* start the vm
|
||||
*
|
||||
* @param vm to start.
|
||||
* @return true if started. false if not.
|
||||
* @throws InsufficientCapacityException if there's not enough capacity to start the vm.
|
||||
* @throws StorageUnavailableException if the storage is unavailable.
|
||||
* @throws ConcurrentOperationException there's multiple threads working on this vm.
|
||||
* @throws ExecutionException
|
||||
* @throws ResourceUnavailableException
|
||||
*/
|
||||
T start(long vmId) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException;
|
||||
|
||||
/**
|
||||
* stop the vm
|
||||
*
|
||||
* @param vm vm to Stop.
|
||||
* @return true if stopped and false if not.
|
||||
* @throws ResourceUnavailableException TODO
|
||||
*/
|
||||
boolean stop(T vm) throws ResourceUnavailableException;
|
||||
|
||||
/**
|
||||
* Produce a cleanup command to be sent to the agent to cleanup anything
|
||||
* out of the ordinary.
|
||||
|
||||
@ -99,4 +99,8 @@ public interface VirtualMachineManager extends Manager {
|
||||
<T extends VMInstanceVO> T reboot(T vm, Map<VirtualMachineProfile.Param, Object> params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException;
|
||||
|
||||
<T extends VMInstanceVO> T advanceReboot(T vm, Map<VirtualMachineProfile.Param, Object> params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, OperationTimedoutException;
|
||||
|
||||
VMInstanceVO findById(VirtualMachine.Type type, long vmId);
|
||||
|
||||
VirtualMachine start(VirtualMachine.Type type, long vmId, Map<VirtualMachineProfile.Param, Object> params);
|
||||
}
|
||||
|
||||
@ -18,6 +18,8 @@
|
||||
package com.cloud.vm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -33,18 +35,24 @@ import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.AgentManager.OnError;
|
||||
import com.cloud.agent.Listener;
|
||||
import com.cloud.agent.api.AgentControlAnswer;
|
||||
import com.cloud.agent.api.AgentControlCommand;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.CheckVirtualMachineAnswer;
|
||||
import com.cloud.agent.api.CheckVirtualMachineCommand;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.MigrateAnswer;
|
||||
import com.cloud.agent.api.MigrateCommand;
|
||||
import com.cloud.agent.api.PingRoutingCommand;
|
||||
import com.cloud.agent.api.PrepareForMigrationAnswer;
|
||||
import com.cloud.agent.api.PrepareForMigrationCommand;
|
||||
import com.cloud.agent.api.RebootAnswer;
|
||||
import com.cloud.agent.api.RebootCommand;
|
||||
import com.cloud.agent.api.StartAnswer;
|
||||
import com.cloud.agent.api.StartCommand;
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.agent.api.StartupRoutingCommand;
|
||||
import com.cloud.agent.api.StopAnswer;
|
||||
import com.cloud.agent.api.StopCommand;
|
||||
import com.cloud.agent.api.to.VirtualMachineTO;
|
||||
@ -57,7 +65,10 @@ import com.cloud.configuration.ConfigurationManager;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.consoleproxy.ConsoleProxyManager;
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.HostPodVO;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.dc.dao.HostPodDao;
|
||||
import com.cloud.deploy.DataCenterDeployment;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.deploy.DeploymentPlan;
|
||||
@ -69,14 +80,19 @@ import com.cloud.event.UsageEventVO;
|
||||
import com.cloud.event.dao.UsageEventDao;
|
||||
import com.cloud.exception.AgentUnavailableException;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.ConnectionException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientServerCapacityException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.ha.HighAvailabilityManager;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.hypervisor.HypervisorGuru;
|
||||
import com.cloud.maid.StackMaid;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.NetworkVO;
|
||||
import com.cloud.org.Cluster;
|
||||
@ -106,6 +122,7 @@ import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GlobalLock;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.fsm.StateListener;
|
||||
@ -121,7 +138,7 @@ import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
||||
@Local(value=VirtualMachineManager.class)
|
||||
public class VirtualMachineManagerImpl implements VirtualMachineManager, StateListener<State, VirtualMachine.Event, VirtualMachine> {
|
||||
public class VirtualMachineManagerImpl implements VirtualMachineManager, StateListener<State, VirtualMachine.Event, VirtualMachine>, Listener {
|
||||
private static final Logger s_logger = Logger.getLogger(VirtualMachineManagerImpl.class);
|
||||
|
||||
String _name;
|
||||
@ -151,15 +168,19 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, StateLi
|
||||
@Inject protected ConsoleProxyManager _consoleProxyMgr;
|
||||
@Inject protected ConfigurationManager _configMgr;
|
||||
@Inject protected CapacityManager _capacityMgr;
|
||||
@Inject protected HighAvailabilityManager _haMgr;
|
||||
@Inject protected HostPodDao _podDao;
|
||||
@Inject protected DataCenterDao _dcDao;
|
||||
|
||||
@Inject(adapter=DeploymentPlanner.class)
|
||||
protected Adapters<DeploymentPlanner> _planners;
|
||||
|
||||
|
||||
Map<VirtualMachine.Type, VirtualMachineGuru<? extends VMInstanceVO>> _vmGurus = new HashMap<VirtualMachine.Type, VirtualMachineGuru<? extends VMInstanceVO>>();
|
||||
Map<HypervisorType, HypervisorGuru> _hvGurus = new HashMap<HypervisorType, HypervisorGuru>();
|
||||
protected StateMachine2<State, VirtualMachine.Event, VirtualMachine> _stateMachine;
|
||||
|
||||
ScheduledExecutorService _executor = null;
|
||||
protected int _operationTimeout;
|
||||
|
||||
protected int _retry;
|
||||
protected long _nodeId;
|
||||
@ -423,11 +444,13 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, StateLi
|
||||
_cleanupInterval = NumbersUtil.parseLong(params.get(Config.VmOpCleanupInterval.key()), 86400) * 1000;
|
||||
_opWaitInterval = NumbersUtil.parseLong(params.get(Config.VmOpWaitInterval.key()), 120) * 1000;
|
||||
_lockStateRetry = NumbersUtil.parseInt(params.get(Config.VmOpLockStateRetry.key()), 5);
|
||||
_operationTimeout = NumbersUtil.parseInt(params.get(Config.Wait.key()), 1800) * 2;
|
||||
|
||||
_executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("Vm-Operations-Cleanup"));
|
||||
_nodeId = _clusterMgr.getId();
|
||||
|
||||
_stateMachine.registerListener(this);
|
||||
_agentMgr.registerForHostEvents(this, true, true, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1196,4 +1219,404 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, StateLi
|
||||
public boolean postStateTransitionEvent(State oldState, Event event, State newState, VirtualMachine vo, boolean status) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualMachine start(VirtualMachine.Type type, long vmId, Map<VirtualMachineProfile.Param, Object> params) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VMInstanceVO findById(VirtualMachine.Type type, long vmId) {
|
||||
VirtualMachineGuru<? extends VMInstanceVO> guru = _vmGurus.get(type);
|
||||
return guru.findById(vmId);
|
||||
}
|
||||
|
||||
public Command cleanup(String vmName) {
|
||||
return new StopCommand(vmName);
|
||||
}
|
||||
|
||||
public Commands deltaSync(long hostId, Map<String, State> newStates) {
|
||||
Map<Long, AgentVmInfo> states = convertToIds(newStates);
|
||||
Commands commands = new Commands(OnError.Continue);
|
||||
|
||||
boolean nativeHA = _agentMgr.isHostNativeHAEnabled(hostId);
|
||||
|
||||
for (final Map.Entry<Long, AgentVmInfo> entry : states.entrySet()) {
|
||||
AgentVmInfo info = entry.getValue();
|
||||
|
||||
VMInstanceVO vm = info.vm;
|
||||
|
||||
Command command = null;
|
||||
if (vm != null) {
|
||||
command = compareState(vm, info, false, nativeHA);
|
||||
} else {
|
||||
command = cleanup(info.name);
|
||||
}
|
||||
|
||||
if (command != null) {
|
||||
commands.addCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
protected Map<Long, AgentVmInfo> convertToIds(final Map<String, State> states) {
|
||||
final HashMap<Long, AgentVmInfo> map = new HashMap<Long, AgentVmInfo>();
|
||||
|
||||
if (states == null) {
|
||||
return map;
|
||||
}
|
||||
|
||||
Collection<VirtualMachineGuru<? extends VMInstanceVO>> vmGurus = _vmGurus.values();
|
||||
|
||||
for (Map.Entry<String, State> entry : states.entrySet()) {
|
||||
for (VirtualMachineGuru<? extends VMInstanceVO> vmGuru : vmGurus) {
|
||||
String name = entry.getKey();
|
||||
|
||||
VMInstanceVO vm = vmGuru.findByName(name);
|
||||
|
||||
if (vm != null) {
|
||||
map.put(vm.getId(), new AgentVmInfo(entry.getKey(), vm, entry.getValue()));
|
||||
break;
|
||||
}
|
||||
|
||||
Long id = vmGuru.convertToId(name);
|
||||
if (id != null) {
|
||||
map.put(id, new AgentVmInfo(entry.getKey(), null, entry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* compareState does as its name suggests and compares the states between
|
||||
* management server and agent. It returns whether something should be
|
||||
* cleaned up
|
||||
*
|
||||
*/
|
||||
protected Command compareState(VMInstanceVO vm, final AgentVmInfo info, final boolean fullSync, boolean nativeHA) {
|
||||
State agentState = info.state;
|
||||
final String agentName = info.name;
|
||||
final State serverState = vm.getState();
|
||||
final String serverName = vm.getName();
|
||||
|
||||
Command command = null;
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("VM " + serverName + ": server state = " + serverState.toString() + " and agent state = " + agentState.toString());
|
||||
}
|
||||
|
||||
if (agentState == State.Error) {
|
||||
agentState = State.Stopped;
|
||||
|
||||
short alertType = AlertManager.ALERT_TYPE_USERVM;
|
||||
if (VirtualMachine.Type.DomainRouter.equals(vm.getType())) {
|
||||
alertType = AlertManager.ALERT_TYPE_DOMAIN_ROUTER;
|
||||
} else if (VirtualMachine.Type.ConsoleProxy.equals(vm.getType())) {
|
||||
alertType = AlertManager.ALERT_TYPE_CONSOLE_PROXY;
|
||||
}
|
||||
|
||||
HostPodVO podVO = _podDao.findById(vm.getPodId());
|
||||
DataCenterVO dcVO = _dcDao.findById(vm.getDataCenterId());
|
||||
HostVO hostVO = _hostDao.findById(vm.getHostId());
|
||||
|
||||
String hostDesc = "name: " + hostVO.getName() + " (id:" + hostVO.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
|
||||
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "VM (name: " + vm.getName() + ", id: " + vm.getId() + ") stopped on host " + hostDesc + " due to storage failure", "Virtual Machine " + vm.getName() + " (id: " + vm.getId() + ") running on host [" + vm.getHostId() + "] stopped due to storage failure.");
|
||||
}
|
||||
|
||||
if (serverState == State.Migrating) {
|
||||
s_logger.debug("Skipping vm in migrating state: " + vm.toString());
|
||||
return null;
|
||||
}
|
||||
|
||||
if (agentState == serverState) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Both states are " + agentState.toString() + " for " + serverName);
|
||||
}
|
||||
assert (agentState == State.Stopped || agentState == State.Running) : "If the states we send up is changed, this must be changed.";
|
||||
stateTransitTo(vm, agentState == State.Stopped ? VirtualMachine.Event.AgentReportStopped : VirtualMachine.Event.AgentReportRunning, vm.getHostId());
|
||||
if (agentState == State.Stopped) {
|
||||
s_logger.debug("State matches but the agent said stopped so let's send a cleanup anyways.");
|
||||
return cleanup(agentName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (agentState == State.Shutdowned ) {
|
||||
if ( serverState == State.Running || serverState == State.Starting || serverState == State.Stopping ) {
|
||||
stateTransitTo(vm, VirtualMachine.Event.AgentReportShutdowned, null);
|
||||
}
|
||||
s_logger.debug("Sending cleanup to a shutdowned vm: " + agentName);
|
||||
command = cleanup(agentName);
|
||||
} else if (agentState == State.Stopped) {
|
||||
// This state means the VM on the agent was detected previously
|
||||
// and now is gone. This is slightly different than if the VM
|
||||
// was never completed but we still send down a Stop Command
|
||||
// to ensure there's cleanup.
|
||||
if (serverState == State.Running ) {
|
||||
if(!nativeHA) {
|
||||
// Our records showed that it should be running so let's restart it.
|
||||
vm = findById(vm.getType(), vm.getId());
|
||||
_haMgr.scheduleRestart(vm, false);
|
||||
command = cleanup(agentName);
|
||||
} else {
|
||||
s_logger.info("VM is in runnting state, agent reported as stopped and native HA is enabled => skip sync action");
|
||||
stateTransitTo(vm, Event.AgentReportStopped, null);
|
||||
}
|
||||
} else if (serverState == State.Stopping) {
|
||||
if (fullSync) {
|
||||
s_logger.debug("VM is in stopping state on full sync. Updating the status to stopped");
|
||||
vm = findById(vm.getType(), vm.getId());
|
||||
// advanceStop(vm, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
|
||||
command = cleanup(agentName);
|
||||
} else {
|
||||
s_logger.debug("Ignoring VM in stopping mode: " + vm.getName());
|
||||
}
|
||||
} else if (serverState == State.Starting) {
|
||||
s_logger.debug("Ignoring VM in starting mode: " + vm.getName());
|
||||
stateTransitTo(vm, VirtualMachine.Event.AgentReportStopped, null);
|
||||
} else {
|
||||
s_logger.debug("Sending cleanup to a stopped vm: " + agentName);
|
||||
stateTransitTo(vm, VirtualMachine.Event.AgentReportStopped, null);
|
||||
command = cleanup(agentName);
|
||||
}
|
||||
} else if (agentState == State.Running) {
|
||||
if (serverState == State.Starting) {
|
||||
if (fullSync) {
|
||||
s_logger.debug("VM state is starting on full sync so updating it to running");
|
||||
vm = findById(vm.getType(), vm.getId());
|
||||
stateTransitTo(vm, Event.AgentReportRunning, vm.getHostId());
|
||||
//finalizeStart(new VirtualMachineProfileImpl<VMInstanceVO>(vm), vm.getHostId(), null, null);
|
||||
}
|
||||
} else if (serverState == State.Stopping) {
|
||||
if (fullSync) {
|
||||
s_logger.debug("VM state is in stopping on fullsync so resend stop.");
|
||||
vm = findById(vm.getType(), vm.getId());
|
||||
stateTransitTo(vm, Event.AgentReportStopped, null);
|
||||
//finalizeStop(new VirtualMachineProfileImpl<VMInstanceVO>(vm), null);
|
||||
command = cleanup(agentName);
|
||||
} else {
|
||||
s_logger.debug("VM is in stopping state so no action.");
|
||||
}
|
||||
} else if (serverState == State.Destroyed || serverState == State.Stopped || serverState == State.Expunging) {
|
||||
s_logger.debug("VM state is in stopped so stopping it on the agent");
|
||||
command = cleanup(agentName);
|
||||
} else {
|
||||
stateTransitTo(vm, VirtualMachine.Event.AgentReportRunning, vm.getHostId());
|
||||
}
|
||||
} /*else if (agentState == State.Unknown) {
|
||||
if (serverState == State.Running) {
|
||||
if (fullSync) {
|
||||
vm = info.vmGuru.get(vm.getId());
|
||||
}
|
||||
scheduleRestart(vm, false);
|
||||
} else if (serverState == State.Starting) {
|
||||
if (fullSync) {
|
||||
vm = info.vmGuru.get(vm.getId());
|
||||
}
|
||||
scheduleRestart(vm, false);
|
||||
} else if (serverState == State.Stopping) {
|
||||
if (fullSync) {
|
||||
s_logger.debug("VM state is stopping in full sync. Resending stop");
|
||||
command = info.vmGuru.getCleanupCommand(vm, agentName);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return command;
|
||||
}
|
||||
|
||||
public Commands fullSync(final long hostId, final Map<String, State> newStates) {
|
||||
Commands commands = new Commands(OnError.Continue);
|
||||
final List<? extends VMInstanceVO> vms = _vmDao.listByHostId(hostId);
|
||||
s_logger.debug("Found " + vms.size() + " VMs for host " + hostId);
|
||||
|
||||
Map<Long, AgentVmInfo> states = convertToIds(newStates);
|
||||
|
||||
boolean nativeHA = _agentMgr.isHostNativeHAEnabled(hostId);
|
||||
|
||||
for (final VMInstanceVO vm : vms) {
|
||||
AgentVmInfo info = states.remove(vm.getId());
|
||||
|
||||
if (info == null) {
|
||||
info = new AgentVmInfo(vm.getInstanceName(), null, State.Stopped);
|
||||
}
|
||||
|
||||
VirtualMachineGuru<? extends VMInstanceVO> vmGuru = getVmGuru(vm);
|
||||
VMInstanceVO castedVm = vmGuru.findById(vm.getId());
|
||||
final Command command = compareState(castedVm, info, true, nativeHA);
|
||||
if (command != null) {
|
||||
commands.addCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
for (final AgentVmInfo left : states.values()) {
|
||||
if (nativeHA) {
|
||||
for (VirtualMachineGuru<? extends VMInstanceVO> vmGuru : _vmGurus.values()) {
|
||||
VMInstanceVO vm = vmGuru.findByName(left.name);
|
||||
if (vm == null) {
|
||||
s_logger.warn("Stopping a VM that we have no record of: " + left.name);
|
||||
commands.addCommand(cleanup(left.name));
|
||||
} else {
|
||||
Command command = compareState(vm, left, true, nativeHA);
|
||||
if (command != null) {
|
||||
commands.addCommand(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
s_logger.warn("Stopping a VM that we have no record of: " + left.name);
|
||||
commands.addCommand(cleanup(left.name));
|
||||
}
|
||||
}
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isRecurring() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processAnswers(long agentId, long seq, Answer[] answers) {
|
||||
for (final Answer answer : answers) {
|
||||
if (!answer.getResult()) {
|
||||
s_logger.warn("Cleanup failed due to " + answer.getDetails());
|
||||
} else {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Cleanup succeeded. Details " + answer.getDetails());
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processTimeout(long agentId, long seq) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTimeout() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processCommands(long agentId, long seq, Command[] cmds) {
|
||||
boolean processed = false;
|
||||
for (Command cmd : cmds) {
|
||||
if (cmd instanceof PingRoutingCommand) {
|
||||
PingRoutingCommand ping = (PingRoutingCommand)cmd;
|
||||
if (ping.getNewStates().size() > 0) {
|
||||
Commands commands = deltaSync(agentId, ping.getNewStates());
|
||||
if (commands.size() > 0) {
|
||||
try {
|
||||
_agentMgr.send(agentId, commands, this);
|
||||
} catch (final AgentUnavailableException e) {
|
||||
s_logger.warn("Agent is now unavailable", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
processed = true;
|
||||
}
|
||||
}
|
||||
return processed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AgentControlAnswer processControlCommand(long agentId, AgentControlCommand cmd) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processDisconnect(long agentId, Status state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processConnect(HostVO agent, StartupCommand cmd) throws ConnectionException {
|
||||
if (!(cmd instanceof StartupRoutingCommand)) {
|
||||
return;
|
||||
}
|
||||
|
||||
long agentId = agent.getId();
|
||||
|
||||
StartupRoutingCommand startup = (StartupRoutingCommand)cmd;
|
||||
|
||||
Commands commands = fullSync(agentId, startup.getVmStates());
|
||||
|
||||
if (commands.size() > 0) {
|
||||
s_logger.debug("Sending clean commands to the agent");
|
||||
|
||||
try {
|
||||
boolean error = false;
|
||||
Answer[] answers = _agentMgr.send(agentId, commands);
|
||||
for (Answer answer : answers) {
|
||||
if (!answer.getResult()) {
|
||||
s_logger.warn("Unable to stop a VM due to " + answer.getDetails());
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
if (error) {
|
||||
throw new ConnectionException(true, "Unable to stop VMs");
|
||||
}
|
||||
} catch (final AgentUnavailableException e) {
|
||||
s_logger.warn("Agent is unavailable now", e);
|
||||
throw new ConnectionException(true, "Unable to sync", e);
|
||||
} catch (final OperationTimedoutException e) {
|
||||
s_logger.warn("Agent is unavailable now", e);
|
||||
throw new ConnectionException(true, "Unable to sync", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected class TransitionTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
GlobalLock lock = GlobalLock.getInternLock("TransitionChecking");
|
||||
if (lock == null) {
|
||||
s_logger.debug("Couldn't get the global lock");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!lock.lock(30)) {
|
||||
s_logger.debug("Couldn't lock the db");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
lock.addRef();
|
||||
List<VMInstanceVO> instances = _vmDao.findVMInTransition(new Date(new Date().getTime() - (_operationTimeout * 1000)), State.Starting, State.Stopping);
|
||||
for (VMInstanceVO instance : instances) {
|
||||
State state = instance.getState();
|
||||
if (state == State.Stopping) {
|
||||
_haMgr.scheduleStop(instance, instance.getHostId(), true);
|
||||
} else if (state == State.Starting) {
|
||||
_haMgr.scheduleRestart(instance, true);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Caught the following exception on transition checking", e);
|
||||
} finally {
|
||||
StackMaid.current().exitCleanup();
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected class AgentVmInfo {
|
||||
public String name;
|
||||
public State state;
|
||||
public State action;
|
||||
public VMInstanceVO vm;
|
||||
|
||||
public AgentVmInfo(String name, VMInstanceVO vm, State state) {
|
||||
this.name = name;
|
||||
this.state = state;
|
||||
this.vm = vm;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,13 +63,6 @@ public interface VMInstanceDao extends GenericDao<VMInstanceVO, Long>, StateDao<
|
||||
|
||||
List<VMInstanceVO> findVMInTransition(Date time, State... states);
|
||||
|
||||
/**
|
||||
* return the counts of domain routers and console proxies running on the host
|
||||
* @param hostId
|
||||
* @return
|
||||
*/
|
||||
Integer[] countRoutersAndProxies(Long hostId);
|
||||
|
||||
List<VMInstanceVO> listByTypes(VirtualMachine.Type... types);
|
||||
|
||||
VMInstanceVO findByIdTypes(long id, VirtualMachine.Type... types);
|
||||
@ -84,4 +77,6 @@ public interface VMInstanceDao extends GenericDao<VMInstanceVO, Long>, StateDao<
|
||||
List<VMInstanceVO> listByLastHostId(Long hostId);
|
||||
|
||||
List<VMInstanceVO> listByTypeAndState(State state, VirtualMachine.Type type);
|
||||
|
||||
List<VMInstanceVO> listByAccountId(long accountId);
|
||||
}
|
||||
|
||||
@ -19,8 +19,6 @@
|
||||
package com.cloud.vm.dao;
|
||||
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@ -32,7 +30,7 @@ import com.cloud.utils.db.Attribute;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.UpdateBuilder;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
@ -43,16 +41,10 @@ import com.cloud.vm.VirtualMachine.Type;
|
||||
@Local(value = { VMInstanceDao.class })
|
||||
public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implements VMInstanceDao {
|
||||
|
||||
public static final Logger s_logger = Logger.getLogger(VMInstanceDaoImpl.class.getName());
|
||||
|
||||
private static final String COUNT_ROUTERS_AND_PROXIES = "SELECT count(*) from `cloud`.`vm_instance` where host_id = ? AND type = 'DomainRouter'" + " UNION ALL"
|
||||
+ " SELECT count(*) from `cloud`.`vm_instance` where host_id = ? AND type = 'ConsoleProxy'";
|
||||
public static final Logger s_logger = Logger.getLogger(VMInstanceDaoImpl.class);
|
||||
|
||||
protected final SearchBuilder<VMInstanceVO> IdStatesSearch;
|
||||
protected final SearchBuilder<VMInstanceVO> HostSearch;
|
||||
protected final SearchBuilder<VMInstanceVO> LastHostSearch;
|
||||
protected final SearchBuilder<VMInstanceVO> ZoneSearch;
|
||||
protected final SearchBuilder<VMInstanceVO> ZoneVmTypeSearch;
|
||||
protected final SearchBuilder<VMInstanceVO> AllFieldsSearch;
|
||||
protected final SearchBuilder<VMInstanceVO> ZoneTemplateNonExpungedSearch;
|
||||
protected final SearchBuilder<VMInstanceVO> NameLikeSearch;
|
||||
protected final SearchBuilder<VMInstanceVO> StateChangeSearch;
|
||||
@ -62,90 +54,83 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
||||
protected final SearchBuilder<VMInstanceVO> HostIdTypesSearch;
|
||||
protected final SearchBuilder<VMInstanceVO> HostIdUpTypesSearch;
|
||||
protected final SearchBuilder<VMInstanceVO> HostUpSearch;
|
||||
protected final SearchBuilder<VMInstanceVO> TypeStateSearch;
|
||||
|
||||
protected final Attribute _updateTimeAttr;
|
||||
|
||||
protected VMInstanceDaoImpl() {
|
||||
IdStatesSearch = createSearchBuilder();
|
||||
IdStatesSearch.and("id", IdStatesSearch.entity().getId(), SearchCriteria.Op.EQ);
|
||||
IdStatesSearch.and("states", IdStatesSearch.entity().getState(), SearchCriteria.Op.IN);
|
||||
IdStatesSearch.and("id", IdStatesSearch.entity().getId(), Op.EQ);
|
||||
IdStatesSearch.and("states", IdStatesSearch.entity().getState(), Op.IN);
|
||||
IdStatesSearch.done();
|
||||
|
||||
HostSearch = createSearchBuilder();
|
||||
HostSearch.and("host", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ);
|
||||
HostSearch.done();
|
||||
|
||||
LastHostSearch = createSearchBuilder();
|
||||
LastHostSearch.and("lastHost", LastHostSearch.entity().getLastHostId(), SearchCriteria.Op.EQ);
|
||||
LastHostSearch.and("state", LastHostSearch.entity().getState(), SearchCriteria.Op.EQ);
|
||||
LastHostSearch.done();
|
||||
|
||||
ZoneSearch = createSearchBuilder();
|
||||
ZoneSearch.and("zone", ZoneSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
||||
ZoneSearch.done();
|
||||
|
||||
ZoneVmTypeSearch = createSearchBuilder();
|
||||
ZoneVmTypeSearch.and("zone", ZoneVmTypeSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
||||
ZoneVmTypeSearch.and("type", ZoneVmTypeSearch.entity().getType(), SearchCriteria.Op.EQ);
|
||||
ZoneVmTypeSearch.done();
|
||||
AllFieldsSearch = createSearchBuilder();
|
||||
AllFieldsSearch.and("host", AllFieldsSearch.entity().getHostId(), Op.EQ);
|
||||
AllFieldsSearch.and("lastHost", AllFieldsSearch.entity().getLastHostId(), Op.EQ);
|
||||
AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ);
|
||||
AllFieldsSearch.and("zone", AllFieldsSearch.entity().getDataCenterId(), Op.EQ);
|
||||
AllFieldsSearch.and("type", AllFieldsSearch.entity().getType(), Op.EQ);
|
||||
AllFieldsSearch.and("account", AllFieldsSearch.entity().getAccountId(), Op.EQ);
|
||||
AllFieldsSearch.done();
|
||||
|
||||
ZoneTemplateNonExpungedSearch = createSearchBuilder();
|
||||
ZoneTemplateNonExpungedSearch.and("zone", ZoneTemplateNonExpungedSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
||||
ZoneTemplateNonExpungedSearch.and("template", ZoneTemplateNonExpungedSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
|
||||
ZoneTemplateNonExpungedSearch.and("state", ZoneTemplateNonExpungedSearch.entity().getState(), SearchCriteria.Op.NEQ);
|
||||
ZoneTemplateNonExpungedSearch.and("zone", ZoneTemplateNonExpungedSearch.entity().getDataCenterId(), Op.EQ);
|
||||
ZoneTemplateNonExpungedSearch.and("template", ZoneTemplateNonExpungedSearch.entity().getTemplateId(), Op.EQ);
|
||||
ZoneTemplateNonExpungedSearch.and("state", ZoneTemplateNonExpungedSearch.entity().getState(), Op.NEQ);
|
||||
ZoneTemplateNonExpungedSearch.done();
|
||||
|
||||
NameLikeSearch = createSearchBuilder();
|
||||
NameLikeSearch.and("name", NameLikeSearch.entity().getName(), SearchCriteria.Op.LIKE);
|
||||
NameLikeSearch.and("name", NameLikeSearch.entity().getName(), Op.LIKE);
|
||||
NameLikeSearch.done();
|
||||
|
||||
StateChangeSearch = createSearchBuilder();
|
||||
StateChangeSearch.and("id", StateChangeSearch.entity().getId(), SearchCriteria.Op.EQ);
|
||||
StateChangeSearch.and("states", StateChangeSearch.entity().getState(), SearchCriteria.Op.EQ);
|
||||
StateChangeSearch.and("host", StateChangeSearch.entity().getHostId(), SearchCriteria.Op.EQ);
|
||||
StateChangeSearch.and("update", StateChangeSearch.entity().getUpdated(), SearchCriteria.Op.EQ);
|
||||
StateChangeSearch.and("id", StateChangeSearch.entity().getId(), Op.EQ);
|
||||
StateChangeSearch.and("states", StateChangeSearch.entity().getState(), Op.EQ);
|
||||
StateChangeSearch.and("host", StateChangeSearch.entity().getHostId(), Op.EQ);
|
||||
StateChangeSearch.and("update", StateChangeSearch.entity().getUpdated(), Op.EQ);
|
||||
StateChangeSearch.done();
|
||||
|
||||
TransitionSearch = createSearchBuilder();
|
||||
TransitionSearch.and("updateTime", TransitionSearch.entity().getUpdateTime(), SearchCriteria.Op.LT);
|
||||
TransitionSearch.and("states", TransitionSearch.entity().getState(), SearchCriteria.Op.IN);
|
||||
TransitionSearch.and("updateTime", TransitionSearch.entity().getUpdateTime(), Op.LT);
|
||||
TransitionSearch.and("states", TransitionSearch.entity().getState(), Op.IN);
|
||||
TransitionSearch.done();
|
||||
|
||||
TypesSearch = createSearchBuilder();
|
||||
TypesSearch.and("types", TypesSearch.entity().getType(), SearchCriteria.Op.IN);
|
||||
TypesSearch.and("types", TypesSearch.entity().getType(), Op.IN);
|
||||
TypesSearch.done();
|
||||
|
||||
IdTypesSearch = createSearchBuilder();
|
||||
IdTypesSearch.and("id", IdTypesSearch.entity().getId(), SearchCriteria.Op.EQ);
|
||||
IdTypesSearch.and("types", IdTypesSearch.entity().getType(), SearchCriteria.Op.IN);
|
||||
IdTypesSearch.and("id", IdTypesSearch.entity().getId(), Op.EQ);
|
||||
IdTypesSearch.and("types", IdTypesSearch.entity().getType(), Op.IN);
|
||||
IdTypesSearch.done();
|
||||
|
||||
HostIdTypesSearch = createSearchBuilder();
|
||||
HostIdTypesSearch.and("hostid", HostIdTypesSearch.entity().getHostId(), SearchCriteria.Op.EQ);
|
||||
HostIdTypesSearch.and("types", HostIdTypesSearch.entity().getType(), SearchCriteria.Op.IN);
|
||||
HostIdTypesSearch.and("hostid", HostIdTypesSearch.entity().getHostId(), Op.EQ);
|
||||
HostIdTypesSearch.and("types", HostIdTypesSearch.entity().getType(), Op.IN);
|
||||
HostIdTypesSearch.done();
|
||||
|
||||
HostIdUpTypesSearch = createSearchBuilder();
|
||||
HostIdUpTypesSearch.and("hostid", HostIdUpTypesSearch.entity().getHostId(), SearchCriteria.Op.EQ);
|
||||
HostIdUpTypesSearch.and("types", HostIdUpTypesSearch.entity().getType(), SearchCriteria.Op.IN);
|
||||
HostIdUpTypesSearch.and("states", HostIdUpTypesSearch.entity().getState(), SearchCriteria.Op.NIN);
|
||||
HostIdUpTypesSearch.and("hostid", HostIdUpTypesSearch.entity().getHostId(), Op.EQ);
|
||||
HostIdUpTypesSearch.and("types", HostIdUpTypesSearch.entity().getType(), Op.IN);
|
||||
HostIdUpTypesSearch.and("states", HostIdUpTypesSearch.entity().getState(), Op.NIN);
|
||||
HostIdUpTypesSearch.done();
|
||||
|
||||
HostUpSearch = createSearchBuilder();
|
||||
HostUpSearch.and("host", HostUpSearch.entity().getHostId(), SearchCriteria.Op.EQ);
|
||||
HostUpSearch.and("states", HostUpSearch.entity().getState(), SearchCriteria.Op.IN);
|
||||
HostUpSearch.and("host", HostUpSearch.entity().getHostId(), Op.EQ);
|
||||
HostUpSearch.and("states", HostUpSearch.entity().getState(), Op.IN);
|
||||
HostUpSearch.done();
|
||||
|
||||
TypeStateSearch = createSearchBuilder();
|
||||
TypeStateSearch.and("type", TypeStateSearch.entity().getType(), SearchCriteria.Op.EQ);
|
||||
TypeStateSearch.and("state", TypeStateSearch.entity().getState(), SearchCriteria.Op.EQ);
|
||||
TypeStateSearch.done();
|
||||
|
||||
_updateTimeAttr = _allAttributes.get("updateTime");
|
||||
assert _updateTimeAttr != null : "Couldn't get this updateTime attribute";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VMInstanceVO> listByAccountId(long accountId) {
|
||||
SearchCriteria<VMInstanceVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("account", accountId);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VMInstanceVO> findVMInstancesLike(String name) {
|
||||
SearchCriteria<VMInstanceVO> sc = NameLikeSearch.create();
|
||||
@ -155,7 +140,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
||||
|
||||
@Override
|
||||
public List<VMInstanceVO> listByHostId(long hostid) {
|
||||
SearchCriteria<VMInstanceVO> sc = HostSearch.create();
|
||||
SearchCriteria<VMInstanceVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("host", hostid);
|
||||
|
||||
return listBy(sc);
|
||||
@ -163,7 +148,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
||||
|
||||
@Override
|
||||
public List<VMInstanceVO> listByZoneId(long zoneId) {
|
||||
SearchCriteria<VMInstanceVO> sc = ZoneSearch.create();
|
||||
SearchCriteria<VMInstanceVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("zone", zoneId);
|
||||
|
||||
return listBy(sc);
|
||||
@ -171,7 +156,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
||||
|
||||
@Override
|
||||
public List<VMInstanceVO> listByZoneIdAndType(long zoneId, VirtualMachine.Type type) {
|
||||
SearchCriteria<VMInstanceVO> sc = ZoneVmTypeSearch.create();
|
||||
SearchCriteria<VMInstanceVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("zone", zoneId);
|
||||
sc.setParameters("type", type.toString());
|
||||
return listBy(sc);
|
||||
@ -199,28 +184,6 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
||||
return search(sc, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer[] countRoutersAndProxies(Long hostId) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
PreparedStatement pstmt = null;
|
||||
Integer[] routerAndProxyCount = new Integer[] { null, null };
|
||||
try {
|
||||
String sql = COUNT_ROUTERS_AND_PROXIES;
|
||||
pstmt = txn.prepareAutoCloseStatement(sql);
|
||||
pstmt.setLong(1, hostId);
|
||||
pstmt.setLong(2, hostId);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
int i = 0;
|
||||
while (rs.next()) {
|
||||
routerAndProxyCount[i++] = rs.getInt(1);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Exception searching for routers and proxies", e);
|
||||
}
|
||||
return routerAndProxyCount;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<VMInstanceVO> listByHostIdTypes(long hostid, Type... types) {
|
||||
SearchCriteria<VMInstanceVO> sc = HostIdTypesSearch.create();
|
||||
@ -255,7 +218,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
||||
|
||||
@Override
|
||||
public List<VMInstanceVO> listByTypeAndState(State state, VirtualMachine.Type type) {
|
||||
SearchCriteria<VMInstanceVO> sc = TypeStateSearch.create();
|
||||
SearchCriteria<VMInstanceVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("type", type);
|
||||
sc.setParameters("state", state);
|
||||
return listBy(sc);
|
||||
@ -314,7 +277,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
||||
|
||||
@Override
|
||||
public List<VMInstanceVO> listByLastHostId(Long hostId) {
|
||||
SearchCriteria<VMInstanceVO> sc = LastHostSearch.create();
|
||||
SearchCriteria<VMInstanceVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("lastHost", hostId);
|
||||
sc.setParameters("state", State.Stopped);
|
||||
return listBy(sc);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user