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}) @Local(value={ServerResource.class})
public class DummyResource implements ServerResource { public class DummyResource implements ServerResource {
private boolean _isRemoteAgent = false;
String _name; String _name;
Host.Type _type; Host.Type _type;
boolean _negative; boolean _negative;
@ -102,12 +101,4 @@ public class DummyResource implements ServerResource {
public void setAgentControl(IAgentControl agentControl) { public void setAgentControl(IAgentControl agentControl) {
_agentControl = 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 String _guestNetworkName;
protected int _wait; protected int _wait;
protected IAgentControl _agentControl; protected IAgentControl _agentControl;
protected boolean _isRemoteAgent = false;
int _userVMCap = 0; int _userVMCap = 0;
final int _maxWeight = 256; final int _maxWeight = 256;
@ -6045,17 +6044,6 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
_agentControl = agentControl; _agentControl = agentControl;
} }
@Override
public boolean IsRemoteAgent() {
return _isRemoteAgent;
}
@Override
public void setRemoteAgent(boolean remote) {
_isRemoteAgent = remote;
}
protected Answer execute(PoolEjectCommand cmd) { protected Answer execute(PoolEjectCommand cmd) {
Connection conn = getConnection(); Connection conn = getConnection();
String hostuuid = cmd.getHostuuid(); String hostuuid = cmd.getHostuuid();

View File

@ -71,8 +71,4 @@ public interface ServerResource extends Manager {
public IAgentControl getAgentControl(); public IAgentControl getAgentControl();
public void setAgentControl(IAgentControl agentControl); 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 _storageNic;
protected NetworkInterface _storageNic2; protected NetworkInterface _storageNic2;
protected IAgentControl _agentControl; protected IAgentControl _agentControl;
protected boolean _isRemoteAgent = false;
@Override @Override
public String getName() { public String getName() {
@ -302,12 +301,4 @@ public abstract class ServerResourceBase implements ServerResource {
public boolean stop() { public boolean stop() {
return true; 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(); long id = server.getId();
AgentAttache attache = createAttache(id, server, resource); AgentAttache attache = createAttache(id, server, resource);
if (!resource.IsRemoteAgent())
attache = notifyMonitorsOfConnection(attache, startup); attache = notifyMonitorsOfConnection(attache, startup);
else {
_hostDao.updateStatus(server, Event.AgentConnected, _nodeId);
}
return attache; return attache;
} }
@ -609,7 +607,19 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory {
if (resources != null) { if (resources != null) {
for (Map.Entry<? extends ServerResource, Map<String, String>> entry : resources.entrySet()) { for (Map.Entry<? extends ServerResource, Map<String, String>> entry : resources.entrySet()) {
ServerResource resource = entry.getKey(); 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); AgentAttache attache = simulateStart(resource, entry.getValue(), true);
if (attache != null) { if (attache != null) {
hosts.add(_hostDao.findById(attache.getId())); hosts.add(_hostDao.findById(attache.getId()));

View File

@ -126,10 +126,6 @@ public class DirectAgentAttache extends AgentAttache {
ServerResource resource = _resource; ServerResource resource = _resource;
if (resource != null) { if (resource != null) {
if (resource.IsRemoteAgent()) {
return;
}
PingCommand cmd = resource.getCurrentStatus(_id); PingCommand cmd = resource.getCurrentStatus(_id);
if (cmd == null) { if (cmd == null) {
s_logger.warn("Unable to get current status on " + _id); 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.ClusterVO;
import com.cloud.dc.dao.ClusterDao; import com.cloud.dc.dao.ClusterDao;
import com.cloud.exception.DiscoveryException; import com.cloud.exception.DiscoveryException;
import com.cloud.host.Host;
import com.cloud.host.HostVO; import com.cloud.host.HostVO;
import com.cloud.host.Status; import com.cloud.host.Status;
import com.cloud.host.Status.Event; import com.cloud.host.Status.Event;
@ -47,7 +48,7 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer,
private String _setupAgentPath; private String _setupAgentPath;
private ConfigurationDao _configDao; private ConfigurationDao _configDao;
private String _hostIp; private String _hostIp;
private int _waitTime = 3; /*wait for 3 minutes*/ private int _waitTime = 5; /*wait for 5 minutes*/
@Inject HostDao _hostDao = null; @Inject HostDao _hostDao = null;
@Inject ClusterDao _clusterDao; @Inject ClusterDao _clusterDao;
@ -218,15 +219,20 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer,
KvmDummyResourceBase kvmResource = new KvmDummyResourceBase(); KvmDummyResourceBase kvmResource = new KvmDummyResourceBase();
Map<String, Object> params = new HashMap<String, Object>(); Map<String, Object> params = new HashMap<String, Object>();
guid = guid + "-LibvirtComputingResource";/*tail added by agent.java*/
params.put("zone", Long.toString(dcId)); params.put("zone", Long.toString(dcId));
params.put("pod", Long.toString(podId)); params.put("pod", Long.toString(podId));
params.put("cluster", Long.toString(clusterId)); params.put("cluster", Long.toString(clusterId));
params.put("guid", guid + "-LibvirtComputingResource"); /*tail added by agent.java*/ params.put("guid", guid);
params.put("agentIp", agentIp); params.put("agentIp", agentIp);
kvmResource.configure("kvm agent", params); kvmResource.configure("kvm agent", params);
kvmResource.setRemoteAgent(true);
resources.put(kvmResource, details); 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*/ /*set cluster hypervisor type to xenserver*/
ClusterVO clu = _clusterDao.findById(clusterId); ClusterVO clu = _clusterDao.findById(clusterId);
clu.setHypervisorType(HypervisorType.KVM.toString()); clu.setHypervisorType(HypervisorType.KVM.toString());
@ -243,31 +249,22 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer,
return null; return null;
} }
@Override private HostVO waitForHostConnect(long dcId, long podId, long clusterId, String guid) {
public void postDiscovery(List<HostVO> hosts, long msId) throws DiscoveryException { for (int i = 0; i < _waitTime; i++) {
/*Wait for agent coming back*/ List<HostVO> hosts = _hostDao.listBy(Host.Type.Routing, clusterId, podId, dcId);
if (hosts.isEmpty()) { for (HostVO host : hosts) {
return; if (host.getGuid() == guid) {
return host;
}
} }
HostVO host = hosts.get(0);
for (int i = 0 ; i < _waitTime; i++) {
if (host.getStatus() != Status.Up) {
s_logger.debug("Wait host comes back, try: " + i);
try { try {
Thread.sleep(60000); Thread.sleep(60000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
s_logger.debug("Failed to sleep: " + e.toString()); s_logger.debug("Failed to sleep: " + e.toString());
} }
} else {
return;
} }
} s_logger.debug("Timeout, to wait for the host connecting to mgt svr, assuming it is failed");
return null;
_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");
} }
@Override @Override
@ -289,4 +286,11 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer,
protected String getPatchPath() { protected String getPatchPath() {
return "scripts/vm/hypervisor/kvm/"; return "scripts/vm/hypervisor/kvm/";
} }
@Override
public void postDiscovery(List<HostVO> hosts, long msId)
throws DiscoveryException {
// TODO Auto-generated method stub
}
} }