mirror of https://github.com/apache/cloudstack.git
fixes bug with two agents connecting to the same host
This commit is contained in:
parent
0008dfc3a9
commit
aa25cfa676
|
|
@ -153,7 +153,8 @@ public class HostVO implements Host {
|
|||
this.storageIpAddressDeux = deuxStorageIpAddress;
|
||||
}
|
||||
|
||||
public String getStorageNetmaskDeux() {
|
||||
@Override
|
||||
public String getStorageNetmaskDeux() {
|
||||
return storageNetmaskDeux;
|
||||
}
|
||||
|
||||
|
|
@ -170,7 +171,8 @@ public class HostVO implements Host {
|
|||
this.storageNetmaskDeux = deuxStorageNetmask;
|
||||
}
|
||||
|
||||
public String getStorageMacAddressDeux() {
|
||||
@Override
|
||||
public String getStorageMacAddressDeux() {
|
||||
return storageMacAddressDeux;
|
||||
}
|
||||
|
||||
|
|
@ -178,7 +180,8 @@ public class HostVO implements Host {
|
|||
this.storageMacAddressDeux = duexStorageMacAddress;
|
||||
}
|
||||
|
||||
public String getPrivateMacAddress() {
|
||||
@Override
|
||||
public String getPrivateMacAddress() {
|
||||
return privateMacAddress;
|
||||
}
|
||||
|
||||
|
|
@ -194,6 +197,7 @@ public class HostVO implements Host {
|
|||
this.available = available;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrivateNetmask() {
|
||||
return privateNetmask;
|
||||
}
|
||||
|
|
@ -202,6 +206,7 @@ public class HostVO implements Host {
|
|||
this.privateNetmask = privateNetmask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPublicNetmask() {
|
||||
return publicNetmask;
|
||||
}
|
||||
|
|
@ -210,6 +215,7 @@ public class HostVO implements Host {
|
|||
this.publicNetmask = publicNetmask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPublicIpAddress() {
|
||||
return publicIpAddress;
|
||||
}
|
||||
|
|
@ -218,6 +224,7 @@ public class HostVO implements Host {
|
|||
this.publicIpAddress = publicIpAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPublicMacAddress() {
|
||||
return publicMacAddress;
|
||||
}
|
||||
|
|
@ -235,6 +242,7 @@ public class HostVO implements Host {
|
|||
this.storageIpAddress = storageIpAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStorageNetmask() {
|
||||
return storageNetmask;
|
||||
}
|
||||
|
|
@ -243,6 +251,7 @@ public class HostVO implements Host {
|
|||
this.storageNetmask = storageNetmask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStorageMacAddress() {
|
||||
return storageMacAddress;
|
||||
}
|
||||
|
|
@ -647,7 +656,7 @@ public class HostVO implements Host {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder(type.toString()).append("-").append(id).append("-").append(name).toString();
|
||||
return new StringBuilder("Host[").append("-").append(id).append("-").append(type).append("]").toString();
|
||||
}
|
||||
|
||||
public void setHypervisorType(HypervisorType hypervisorType) {
|
||||
|
|
|
|||
|
|
@ -447,7 +447,11 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
|
|||
}
|
||||
|
||||
public AgentAttache findAttache(long hostId) {
|
||||
return _agents.get(hostId);
|
||||
AgentAttache attache = null;
|
||||
synchronized (_agents) {
|
||||
attache = _agents.get(hostId);
|
||||
}
|
||||
return attache;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -681,7 +685,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
|
|||
if (resources != null) {
|
||||
for (Map.Entry<? extends ServerResource, Map<String, String>> entry : resources.entrySet()) {
|
||||
ServerResource resource = entry.getKey();
|
||||
AgentAttache attache = simulateStart(resource, entry.getValue(), true, null, null);
|
||||
AgentAttache attache = simulateStart(null, resource, entry.getValue(), true, null, null);
|
||||
if (attache != null) {
|
||||
hosts.add(_hostDao.findById(attache.getId()));
|
||||
}
|
||||
|
|
@ -913,7 +917,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
|
|||
}
|
||||
return null;
|
||||
}
|
||||
AgentAttache attache = simulateStart(resource, entry.getValue(), true, hostTags, allocationState);
|
||||
AgentAttache attache = simulateStart(null, resource, entry.getValue(), true, hostTags, allocationState);
|
||||
if (attache != null) {
|
||||
hosts.add(_hostDao.findById(attache.getId()));
|
||||
}
|
||||
|
|
@ -1532,11 +1536,9 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
|
|||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Deregistering link for " + hostId + " with state " + nextState);
|
||||
}
|
||||
|
||||
_hostDao.disconnect(host, event, _nodeId);
|
||||
|
||||
removeAgent(attache, nextState);
|
||||
|
||||
_hostDao.disconnect(host, event, _nodeId);
|
||||
|
||||
host = _hostDao.findById(host.getId());
|
||||
if (host.getStatus() == Status.Alert || host.getStatus() == Status.Down) {
|
||||
_haMgr.scheduleRestartForVmsOnHost(host);
|
||||
|
|
@ -1695,11 +1697,19 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
|
|||
_executor.execute(new SimulateStartTask(host.getId(), resource, host.getDetails(), null));
|
||||
}
|
||||
|
||||
protected AgentAttache simulateStart(ServerResource resource, Map<String, String> details, boolean old, List<String> hostTags, String allocationState) throws IllegalArgumentException {
|
||||
protected AgentAttache simulateStart(Long id, ServerResource resource, Map<String, String> details, boolean old, List<String> hostTags, String allocationState) throws IllegalArgumentException {
|
||||
StartupCommand[] cmds = resource.initialize();
|
||||
if (cmds == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (id != null) {
|
||||
HostVO host = _hostDao.findById(id);
|
||||
if (!_hostDao.directConnect(host, _nodeId)) {
|
||||
s_logger.info("Someone else is loading " + host);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
AgentAttache attache = null;
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
|
|
@ -2199,7 +2209,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
|
|||
}
|
||||
}
|
||||
|
||||
AgentAttache attache = simulateStart(resource, hostDetails, true, null, null);
|
||||
AgentAttache attache = simulateStart(null, resource, hostDetails, true, null, null);
|
||||
return _hostDao.findById(attache.getId());
|
||||
}
|
||||
|
||||
|
|
@ -2360,8 +2370,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
|
|||
link.attach(attache);
|
||||
AgentAttache old = null;
|
||||
synchronized (_agents) {
|
||||
old = _agents.get(id);
|
||||
_agents.put(id, attache);
|
||||
old = _agents.put(id, attache);
|
||||
}
|
||||
if (old != null) {
|
||||
old.disconnect(Status.Removed);
|
||||
|
|
@ -2378,8 +2387,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
|
|||
|| server.getStatus() == Status.PrepareForMaintenance, this);
|
||||
AgentAttache old = null;
|
||||
synchronized (_agents) {
|
||||
old = _agents.get(id);
|
||||
_agents.put(id, attache);
|
||||
old = _agents.put(id, attache);
|
||||
}
|
||||
if (old != null) {
|
||||
old.disconnect(Status.Removed);
|
||||
|
|
@ -2759,23 +2767,17 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
AgentAttache at = null;
|
||||
try {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Simulating start for resource " + resource.getName() + " id " + id);
|
||||
}
|
||||
simulateStart(resource, details, false, null, null);
|
||||
simulateStart(id, resource, details, false, null, null);
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to simulate start on resource " + id + " name " + resource.getName(), e);
|
||||
} finally {
|
||||
if (actionDelegate != null) {
|
||||
actionDelegate.action(new Long(id));
|
||||
}
|
||||
if (at == null) {
|
||||
HostVO host = _hostDao.findById(id);
|
||||
host.setManagementServerId(null);
|
||||
_hostDao.update(id, host);
|
||||
}
|
||||
StackMaid.current().exitCleanup();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
|
|||
// already loaded, skip
|
||||
if(agentattache.forForward()) {
|
||||
if(s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Host " + host.getName() + " is detected down, but we have a forward attache running, disconnect this one before launching the host");
|
||||
s_logger.info(host + " is detected down, but we have a forward attache running, disconnect this one before launching the host");
|
||||
}
|
||||
removeAgent(agentattache, Status.Disconnected);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -158,5 +158,7 @@ public interface HostDao extends GenericDao<HostVO, Long> {
|
|||
void loadHostTags(HostVO host);
|
||||
|
||||
List<HostVO> listByHostTag(Host.Type type, Long clusterId, Long podId, long dcId, String hostTag);
|
||||
|
||||
boolean directConnect(HostVO host, long msId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,6 +85,8 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
protected final SearchBuilder<HostVO> ConsoleProxyHostSearch;
|
||||
protected final SearchBuilder<HostVO> AvailHypevisorInZone;
|
||||
|
||||
protected final SearchBuilder<HostVO> DirectConnectSearch;
|
||||
|
||||
protected final GenericSearchBuilder<HostVO, Long> HostsInStatusSearch;
|
||||
|
||||
protected final Attribute _statusAttr;
|
||||
|
|
@ -197,7 +199,6 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
UnmanagedDirectConnectSearch.and("resource", UnmanagedDirectConnectSearch.entity().getResource(), SearchCriteria.Op.NNULL);
|
||||
UnmanagedDirectConnectSearch.and("server", UnmanagedDirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.NULL);
|
||||
UnmanagedDirectConnectSearch.and("lastPinged", UnmanagedDirectConnectSearch.entity().getLastPinged(), SearchCriteria.Op.LTEQ);
|
||||
|
||||
/*
|
||||
UnmanagedDirectConnectSearch.op(SearchCriteria.Op.OR, "managementServerId", UnmanagedDirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ);
|
||||
UnmanagedDirectConnectSearch.and("lastPinged", UnmanagedDirectConnectSearch.entity().getLastPinged(), SearchCriteria.Op.LTEQ);
|
||||
|
|
@ -206,6 +207,12 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
*/
|
||||
UnmanagedDirectConnectSearch.done();
|
||||
|
||||
DirectConnectSearch = createSearchBuilder();
|
||||
DirectConnectSearch.and("server", DirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.NULL);
|
||||
DirectConnectSearch.and("resource", DirectConnectSearch.entity().getResource(), SearchCriteria.Op.NNULL);
|
||||
DirectConnectSearch.and("id", DirectConnectSearch.entity().getId(), SearchCriteria.Op.EQ);
|
||||
DirectConnectSearch.done();
|
||||
|
||||
UnmanagedExternalNetworkApplianceSearch = createSearchBuilder();
|
||||
UnmanagedExternalNetworkApplianceSearch.and("resource", UnmanagedExternalNetworkApplianceSearch.entity().getResource(), SearchCriteria.Op.NNULL);
|
||||
UnmanagedExternalNetworkApplianceSearch.and("server", UnmanagedExternalNetworkApplianceSearch.entity().getManagementServerId(), SearchCriteria.Op.NULL);
|
||||
|
|
@ -419,7 +426,20 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
public void loadHostTags(HostVO host){
|
||||
List<String> hostTags = _hostTagsDao.gethostTags(host.getId());
|
||||
host.setHostTags(hostTags);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean directConnect(HostVO host, long msId) {
|
||||
SearchCriteria<HostVO> sc = DirectConnectSearch.create();
|
||||
sc.setParameters("id", host.getId());
|
||||
|
||||
host.setManagementServerId(msId);
|
||||
host.setLastPinged(System.currentTimeMillis() >> 10);
|
||||
UpdateBuilder ub = getUpdateBuilder(host);
|
||||
ub.set(host, _statusAttr, Status.Connecting);
|
||||
|
||||
return update(host, sc) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateStatus(HostVO host, Event event, long msId) {
|
||||
|
|
@ -519,8 +539,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
public List<HostVO> findLostHosts(long timeout) {
|
||||
SearchCriteria<HostVO> sc = LastPingedSearch.create();
|
||||
sc.setParameters("ping", timeout);
|
||||
sc.setParameters("state", Status.Up.toString(), Status.Updating.toString(),
|
||||
Status.Disconnected.toString(), Status.Down.toString());
|
||||
sc.setParameters("state", Status.Up, Status.Updating, Status.Disconnected, Status.Down, Status.Connecting);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue