add a timeout (5 minutes) to wait for KVM agent host connecting to mgt svr, during adding host->discover

This commit is contained in:
edison 2010-10-29 19:16:59 -07:00
parent 67bd893de0
commit d0c68cd4a7
7 changed files with 46 additions and 70 deletions

View File

@ -32,7 +32,6 @@ import com.cloud.resource.ServerResource;
@Local(value={ServerResource.class})
public class DummyResource implements ServerResource {
private boolean _isRemoteAgent = false;
String _name;
Host.Type _type;
boolean _negative;
@ -102,12 +101,4 @@ public class DummyResource implements ServerResource {
public void setAgentControl(IAgentControl agentControl) {
_agentControl = agentControl;
}
public boolean IsRemoteAgent() {
return _isRemoteAgent;
}
public void setRemoteAgent(boolean remote) {
_isRemoteAgent = remote;
}
}

View File

@ -232,7 +232,6 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
protected String _guestNetworkName;
protected int _wait;
protected IAgentControl _agentControl;
protected boolean _isRemoteAgent = false;
int _userVMCap = 0;
final int _maxWeight = 256;
@ -6045,17 +6044,6 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
_agentControl = agentControl;
}
@Override
public boolean IsRemoteAgent() {
return _isRemoteAgent;
}
@Override
public void setRemoteAgent(boolean remote) {
_isRemoteAgent = remote;
}
protected Answer execute(PoolEjectCommand cmd) {
Connection conn = getConnection();
String hostuuid = cmd.getHostuuid();

View File

@ -71,8 +71,4 @@ public interface ServerResource extends Manager {
public IAgentControl getAgentControl();
public void setAgentControl(IAgentControl agentControl);
public boolean IsRemoteAgent();
public void setRemoteAgent(boolean remote);
}

View File

@ -48,7 +48,6 @@ public abstract class ServerResourceBase implements ServerResource {
protected NetworkInterface _storageNic;
protected NetworkInterface _storageNic2;
protected IAgentControl _agentControl;
protected boolean _isRemoteAgent = false;
@Override
public String getName() {
@ -302,12 +301,4 @@ public abstract class ServerResourceBase implements ServerResource {
public boolean stop() {
return true;
}
public boolean IsRemoteAgent() {
return _isRemoteAgent;
}
public void setRemoteAgent(boolean remote) {
_isRemoteAgent = remote;
}
}

View File

@ -496,11 +496,9 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory {
long id = server.getId();
AgentAttache attache = createAttache(id, server, resource);
if (!resource.IsRemoteAgent())
attache = notifyMonitorsOfConnection(attache, startup);
else {
_hostDao.updateStatus(server, Event.AgentConnected, _nodeId);
}
return attache;
}
@ -609,7 +607,19 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory {
if (resources != null) {
for (Map.Entry<? extends ServerResource, Map<String, String>> entry : resources.entrySet()) {
ServerResource resource = entry.getKey();
/*For KVM, if we go to here, that means kvm agent is already connected to mgt svr.*/
if (resource instanceof KvmDummyResourceBase) {
Map<String, String> details = entry.getValue();
String guid = details.get("guid");
List<HostVO> kvmHosts = _hostDao.listBy(Host.Type.Routing, clusterId, podId, dcId);
for (HostVO host: kvmHosts) {
if (host.getGuid() == guid) {
hosts.add(host);
return hosts;
}
}
return null;
}
AgentAttache attache = simulateStart(resource, entry.getValue(), true);
if (attache != null) {
hosts.add(_hostDao.findById(attache.getId()));

View File

@ -126,10 +126,6 @@ public class DirectAgentAttache extends AgentAttache {
ServerResource resource = _resource;
if (resource != null) {
if (resource.IsRemoteAgent()) {
return;
}
PingCommand cmd = resource.getCurrentStatus(_id);
if (cmd == null) {
s_logger.warn("Unable to get current status on " + _id);

View File

@ -24,6 +24,7 @@ import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.ClusterVO;
import com.cloud.dc.dao.ClusterDao;
import com.cloud.exception.DiscoveryException;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.host.Status.Event;
@ -47,7 +48,7 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer,
private String _setupAgentPath;
private ConfigurationDao _configDao;
private String _hostIp;
private int _waitTime = 3; /*wait for 3 minutes*/
private int _waitTime = 5; /*wait for 5 minutes*/
@Inject HostDao _hostDao = null;
@Inject ClusterDao _clusterDao;
@ -218,15 +219,20 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer,
KvmDummyResourceBase kvmResource = new KvmDummyResourceBase();
Map<String, Object> params = new HashMap<String, Object>();
guid = guid + "-LibvirtComputingResource";/*tail added by agent.java*/
params.put("zone", Long.toString(dcId));
params.put("pod", Long.toString(podId));
params.put("cluster", Long.toString(clusterId));
params.put("guid", guid + "-LibvirtComputingResource"); /*tail added by agent.java*/
params.put("guid", guid);
params.put("agentIp", agentIp);
kvmResource.configure("kvm agent", params);
kvmResource.setRemoteAgent(true);
resources.put(kvmResource, details);
HostVO connectedHost = waitForHostConnect(dcId, podId, clusterId, guid);
if (connectedHost == null)
return null;
details.put("guid", guid);
/*set cluster hypervisor type to xenserver*/
ClusterVO clu = _clusterDao.findById(clusterId);
clu.setHypervisorType(HypervisorType.KVM.toString());
@ -243,31 +249,22 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer,
return null;
}
@Override
public void postDiscovery(List<HostVO> hosts, long msId) throws DiscoveryException {
/*Wait for agent coming back*/
if (hosts.isEmpty()) {
return;
}
HostVO host = hosts.get(0);
private HostVO waitForHostConnect(long dcId, long podId, long clusterId, String guid) {
for (int i = 0; i < _waitTime; i++) {
if (host.getStatus() != Status.Up) {
s_logger.debug("Wait host comes back, try: " + i);
List<HostVO> hosts = _hostDao.listBy(Host.Type.Routing, clusterId, podId, dcId);
for (HostVO host : hosts) {
if (host.getGuid() == guid) {
return host;
}
}
try {
Thread.sleep(60000);
} catch (InterruptedException e) {
s_logger.debug("Failed to sleep: " + e.toString());
}
} else {
return;
}
}
_hostDao.updateStatus(host, Event.AgentDisconnected, msId);
/*Timeout, throw warning msg to user*/
throw new DiscoveryException("Host " + host.getId() + ":" + host.getPrivateIpAddress() + " does not come back, It may connect to server later, if not, please check the agent log on this host");
s_logger.debug("Timeout, to wait for the host connecting to mgt svr, assuming it is failed");
return null;
}
@Override
@ -289,4 +286,11 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer,
protected String getPatchPath() {
return "scripts/vm/hypervisor/kvm/";
}
@Override
public void postDiscovery(List<HostVO> hosts, long msId)
throws DiscoveryException {
// TODO Auto-generated method stub
}
}