HandleDisconnect - don't update the DB when the disconnect event is happening as a part of MS Cluster notification

Reviewed-by: Frank Zhang
This commit is contained in:
Alena Prokharchyk 2012-08-31 14:22:38 -07:00
parent 7e99fca844
commit f1bb87ce80
2 changed files with 18 additions and 15 deletions

View File

@ -604,19 +604,19 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
ConnectionException ce = (ConnectionException)e;
if (ce.isSetupError()) {
s_logger.warn("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage());
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected);
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true);
throw ce;
} else {
s_logger.info("Monitor " + monitor.second().getClass().getSimpleName() + " says not to continue the connect process for " + hostId + " due to " + e.getMessage());
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested);
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true);
return attache;
}
} else if (e instanceof HypervisorVersionChangedException) {
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested);
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true);
throw new CloudRuntimeException("Unable to connect " + attache.getId(), e);
} else {
s_logger.error("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage(), e);
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected);
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true);
throw new CloudRuntimeException("Unable to connect " + attache.getId(), e);
}
}
@ -630,7 +630,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
// this is tricky part for secondary storage
// make it as disconnected, wait for secondary storage VM to be up
// return the attache instead of null, even it is disconnectede
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected);
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true);
}
agentStatusTransitTo(host, Event.Ready, _nodeId);
@ -834,7 +834,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
return _name;
}
protected boolean handleDisconnectWithoutInvestigation(AgentAttache attache, Status.Event event) {
protected boolean handleDisconnectWithoutInvestigation(AgentAttache attache, Status.Event event, boolean transitState) {
long hostId = attache.getId();
s_logger.info("Host " + hostId + " is disconnecting with event " + event);
@ -869,8 +869,11 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
s_logger.debug("Deregistering link for " + hostId + " with state " + nextStatus);
}
//remove the attache
removeAgent(attache, nextStatus);
if (host != null) {
//update the DB
if (host != null && transitState) {
disconnectAgent(host, event, _nodeId);
}
@ -940,7 +943,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
}
}
handleDisconnectWithoutInvestigation(attache, event);
handleDisconnectWithoutInvestigation(attache, event, true);
host = _hostDao.findById(host.getId());
if (host.getStatus() == Status.Alert || host.getStatus() == Status.Down) {
_haMgr.scheduleRestartForVmsOnHost(host, true);
@ -966,7 +969,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
if (_investigate == true) {
handleDisconnectWithInvestigation(_attache, _event);
} else {
handleDisconnectWithoutInvestigation(_attache, _event);
handleDisconnectWithoutInvestigation(_attache, _event, true);
}
} catch (final Exception e) {
s_logger.error("Exception caught while handling disconnect: ", e);
@ -1058,7 +1061,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
AgentAttache attache = null;
attache = findAttache(hostId);
if (attache != null) {
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected);
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true);
}
return true;
} else if (event == Event.ShutdownRequested) {

View File

@ -266,7 +266,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
}
@Override
protected boolean handleDisconnectWithoutInvestigation(AgentAttache attache, Status.Event event) {
protected boolean handleDisconnectWithoutInvestigation(AgentAttache attache, Status.Event event, boolean transitState) {
return handleDisconnect(attache, event, false, true);
}
@ -278,7 +278,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
protected boolean handleDisconnect(AgentAttache agent, Status.Event event, boolean investigate, boolean broadcast) {
boolean res;
if (!investigate) {
res = super.handleDisconnectWithoutInvestigation(agent, event);
res = super.handleDisconnectWithoutInvestigation(agent, event, true);
} else {
res = super.handleDisconnectWithInvestigation(agent, event);
}
@ -311,7 +311,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
}
}
}
handleDisconnect(attache, Event.AgentDisconnected, false, false);
return super.handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, false);
}
return true;
@ -1023,7 +1023,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
try {
s_logger.debug("Management server " + _nodeId + " failed to rebalance agent " + hostId);
_hostTransferDao.completeAgentTransfer(hostId);
handleDisconnectWithoutInvestigation(findAttache(hostId), Event.RebalanceFailed);
handleDisconnectWithoutInvestigation(findAttache(hostId), Event.RebalanceFailed, true);
} catch (Exception ex) {
s_logger.warn("Failed to reconnect host id=" + hostId + " as a part of failed rebalance task cleanup");
}
@ -1040,7 +1040,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
synchronized (_agents) {
ClusteredDirectAgentAttache attache = (ClusteredDirectAgentAttache)_agents.get(hostId);
if (attache != null && attache.getQueueSize() == 0 && attache.getNonRecurringListenersSize() == 0) {
handleDisconnectWithoutInvestigation(attache, Event.StartAgentRebalance);
handleDisconnectWithoutInvestigation(attache, Event.StartAgentRebalance, true);
ClusteredAgentAttache forwardAttache = (ClusteredAgentAttache)createAttache(hostId);
if (forwardAttache == null) {
s_logger.warn("Unable to create a forward attache for the host " + hostId + " as a part of rebalance process");