Skip to content

Commit 8068486

Browse files
committed
Bug 10197: do not check timeout against cluster which is not managed
1 parent d30fe74 commit 8068486

4 files changed

Lines changed: 38 additions & 44 deletions

File tree

‎server/src/com/cloud/agent/manager/AgentManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ protected boolean handleDisconnect(AgentAttache attache, Status.Event event, boo
10851085
_hostDao.disconnect(host, event, _nodeId);
10861086

10871087
host = _hostDao.findById(host.getId());
1088-
if (event.equals(Event.PrepareUnmanaged) && (host.getStatus() == Status.Alert || host.getStatus() == Status.Down)) {
1088+
if (!event.equals(Event.PrepareUnmanaged) && (host.getStatus() == Status.Alert || host.getStatus() == Status.Down)) {
10891089
_haMgr.scheduleRestartForVmsOnHost(host, investigate);
10901090
}
10911091

‎server/src/com/cloud/agent/manager/AgentMonitor.java‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@
3333
import com.cloud.alert.AlertManager;
3434
import com.cloud.dc.DataCenterVO;
3535
import com.cloud.dc.HostPodVO;
36+
import com.cloud.dc.dao.ClusterDao;
3637
import com.cloud.dc.dao.DataCenterDao;
3738
import com.cloud.dc.dao.HostPodDao;
3839
import com.cloud.host.Host;
3940
import com.cloud.host.HostVO;
4041
import com.cloud.host.Status;
4142
import com.cloud.host.Status.Event;
4243
import com.cloud.host.dao.HostDao;
44+
import com.cloud.utils.component.Inject;
4345
import com.cloud.utils.db.ConnectionConcierge;
4446
import com.cloud.utils.db.DB;
4547
import com.cloud.utils.db.GlobalLock;
@@ -60,6 +62,8 @@ public class AgentMonitor extends Thread implements Listener {
6062
private AlertManager _alertMgr;
6163
private long _msId;
6264
private ConnectionConcierge _concierge;
65+
@Inject
66+
ClusterDao _clusterDao;
6367

6468
protected AgentMonitor() {
6569
}
@@ -117,13 +121,6 @@ public void run() {
117121
}
118122

119123
for (HostVO host : hosts) {
120-
if (host.getType().equals(Host.Type.ExternalFirewall) ||
121-
host.getType().equals(Host.Type.ExternalLoadBalancer) ||
122-
host.getType().equals(Host.Type.TrafficMonitor) ||
123-
host.getType().equals(Host.Type.SecondaryStorage)) {
124-
continue;
125-
}
126-
127124
if (host.getManagementServerId() == null || host.getManagementServerId() == _msId) {
128125
if (s_logger.isInfoEnabled()) {
129126
s_logger.info("Asking agent mgr to investgate why host " + host.getId() + " is behind on ping. last ping time: " + host.getLastPinged());
@@ -137,10 +134,10 @@ public void run() {
137134
long hostId = host.getId();
138135
DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
139136
HostPodVO podVO = _podDao.findById(host.getPodId());
140-
String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
137+
String hostDesc = "name: " + host.getName() + " (id:" + hostId + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
141138

142139
if (host.getType() != Host.Type.Storage) {
143-
List<VMInstanceVO> vos = _vmDao.listByHostId(host.getId());
140+
List<VMInstanceVO> vos = _vmDao.listByHostId(hostId);
144141
if (vos.size() == 0) {
145142
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Migration Complete for host " + hostDesc, "Host [" + hostDesc + "] is ready for maintenance");
146143
_hostDao.updateStatus(host, Event.PreparationComplete, _msId);

‎server/src/com/cloud/host/dao/HostDao.java‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,6 @@ public interface HostDao extends GenericDao<HostVO, Long> {
109109
*/
110110
List<HostVO> listByType(Type type);
111111

112-
/**
113-
* Find hosts that have not responded to a ping regardless of state
114-
* @param timeout
115-
* @param type
116-
* @return
117-
*/
118-
List<HostVO> findLostHosts2(long timeout, Type type);
119-
120112
/**
121113
* update the host and changes the status depending on the Event and
122114
* the current status. If the status changed between

‎server/src/com/cloud/host/dao/HostDaoImpl.java‎

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
7373
protected final SearchBuilder<HostVO> IdStatusSearch;
7474
protected final SearchBuilder<HostVO> TypeDcSearch;
7575
protected final SearchBuilder<HostVO> TypeDcStatusSearch;
76-
protected final SearchBuilder<HostVO> LastPingedSearch;
77-
protected final SearchBuilder<HostVO> LastPingedSearch2;
7876
protected final SearchBuilder<HostVO> MsStatusSearch;
7977
protected final SearchBuilder<HostVO> DcPrivateIpAddressSearch;
8078
protected final SearchBuilder<HostVO> DcStorageIpAddressSearch;
@@ -104,7 +102,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
104102
protected final GenericSearchBuilder<HostVO, Long> HostsInStatusSearch;
105103
protected final GenericSearchBuilder<HostVO, Long> CountRoutingByDc;
106104
protected final SearchBuilder<HostTransferMapVO> HostTransferSearch;
107-
protected final SearchBuilder<ClusterVO> ClusterManagedSearch;
105+
protected SearchBuilder<ClusterVO> ClusterManagedSearch;
108106
protected final SearchBuilder<HostVO> RoutingSearch;
109107

110108
protected final Attribute _statusAttr;
@@ -133,16 +131,6 @@ public HostDaoImpl() {
133131
TypePodDcStatusSearch.and("status", entity.getStatus(), SearchCriteria.Op.EQ);
134132
TypePodDcStatusSearch.done();
135133

136-
LastPingedSearch = createSearchBuilder();
137-
LastPingedSearch.and("ping", LastPingedSearch.entity().getLastPinged(), SearchCriteria.Op.LT);
138-
LastPingedSearch.and("state", LastPingedSearch.entity().getStatus(), SearchCriteria.Op.IN);
139-
LastPingedSearch.done();
140-
141-
LastPingedSearch2 = createSearchBuilder();
142-
LastPingedSearch2.and("ping", LastPingedSearch2.entity().getLastPinged(), SearchCriteria.Op.LT);
143-
LastPingedSearch2.and("type", LastPingedSearch2.entity().getType(), SearchCriteria.Op.EQ);
144-
LastPingedSearch2.done();
145-
146134
MsStatusSearch = createSearchBuilder();
147135
MsStatusSearch.and("ms", MsStatusSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ);
148136
MsStatusSearch.and("statuses", MsStatusSearch.entity().getStatus(), SearchCriteria.Op.NIN);
@@ -382,8 +370,7 @@ public List<HostVO> findDirectlyConnectedHosts() {
382370
@Override @DB
383371
public List<HostVO> findAndUpdateDirectAgentToLoad(long lastPingSecondsAfter, Long limit, long managementServerId) {
384372
Transaction txn = Transaction.currentTxn();
385-
txn.start();
386-
373+
txn.start();
387374
SearchCriteria<HostVO> sc = UnmanagedDirectConnectSearch.create();
388375
sc.setParameters("lastPinged", lastPingSecondsAfter);
389376
sc.setParameters("statuses", Status.ErrorInMaintenance, Status.Maintenance, Status.PrepareForMaintenance);
@@ -682,12 +669,36 @@ public HostVO findByName(String name) {
682669
return findOneBy(sc);
683670
}
684671

672+
@DB
685673
@Override
686674
public List<HostVO> findLostHosts(long timeout) {
687-
SearchCriteria<HostVO> sc = LastPingedSearch.create();
688-
sc.setParameters("ping", timeout);
689-
sc.setParameters("state", Status.Up, Status.Updating, Status.Disconnected, Status.Connecting);
690-
return listBy(sc);
675+
Transaction txn = Transaction.currentTxn();
676+
PreparedStatement pstmt = null;
677+
List<HostVO> result = new ArrayList<HostVO>();
678+
ResultSet rs = null;
679+
try {
680+
String sql = "select h.id from host h left join cluster c on h.cluster_id=c.id where h.last_ping < ? and h.status in ('Up', 'Updating', 'Disconnected', 'Connecting') and h.type not in ('ExternalFirewall', 'ExternalLoadBalancer', 'TrafficMonitor', 'SecondaryStorage', 'LocalSecondaryStorage') and (h.cluster_id is null or c.managed_state = 'Managed') ;" ;
681+
pstmt = txn.prepareStatement(sql);
682+
pstmt.setLong(1, timeout);
683+
rs = pstmt.executeQuery();
684+
while (rs.next()) {
685+
long id = rs.getLong(1); //ID column
686+
result.add(findById(id));
687+
}
688+
} catch (Exception e) {
689+
s_logger.warn("Exception: ", e);
690+
} finally {
691+
try {
692+
if (rs != null) {
693+
rs.close();
694+
}
695+
if (pstmt != null) {
696+
pstmt.close();
697+
}
698+
} catch (SQLException e) {
699+
}
700+
}
701+
return result;
691702
}
692703

693704
@Override
@@ -697,13 +708,7 @@ public List<HostVO> findHostsLike(String hostName) {
697708
return listBy(sc);
698709
}
699710

700-
@Override
701-
public List<HostVO> findLostHosts2(long timeout, Type type) {
702-
SearchCriteria<HostVO> sc = LastPingedSearch2.create();
703-
sc.setParameters("ping", timeout);
704-
sc.setParameters("type", type.toString());
705-
return listBy(sc);
706-
}
711+
707712

708713
@Override
709714
public List<HostVO> listByDataCenter(long dcId) {

0 commit comments

Comments
 (0)