mirror of https://github.com/apache/cloudstack.git
Bug 11522 - New agent manager
clean up events, status of agent
This commit is contained in:
parent
66c347bec5
commit
caa8aaf6fe
|
|
@ -30,9 +30,6 @@ public enum Status {
|
|||
Down(true, true, true),
|
||||
Disconnected(true, true, true),
|
||||
Updating(true, true, false),
|
||||
PrepareForMaintenance(false, false, false),
|
||||
ErrorInMaintenance(false, false, false),
|
||||
Maintenance(false, false, false),
|
||||
Alert(true, true, true),
|
||||
Removed(true, false, true),
|
||||
Rebalancing(false, false, false);
|
||||
|
|
@ -67,20 +64,15 @@ public enum Status {
|
|||
AgentDisconnected(false, "Agent disconnected"),
|
||||
ResetRequested(true, "Reset is requested by the user"),
|
||||
HostDown(false, "Host is found to be down by the investigator"),
|
||||
PreparationComplete(false, "Preparation for PrepareForMaintenance is completed"),
|
||||
UnableToMigrate(false, "Migration for at least one VM didn't work"),
|
||||
Ping(false, "Ping is received from the host"),
|
||||
MaintenanceRequested(true, "PrepareForMaintenance requested by user"),
|
||||
ManagementServerDown(false, "Management Server that the agent is connected is going down"),
|
||||
WaitedTooLong(false, "Waited too long from the agent to reconnect on its own. Time to do HA"),
|
||||
Remove(true, "Host is removed"),
|
||||
Ready(false, "Host is ready for commands"),
|
||||
UpdatePassword(false, "Update host password from db"),
|
||||
RequestAgentRebalance(false, "Request rebalance for the certain host"),
|
||||
StartAgentRebalance(false, "Start rebalance for the certain host"),
|
||||
RebalanceCompleted(false, "Host is rebalanced successfully"),
|
||||
RebalanceFailed(false, "Failed to rebalance the host"),
|
||||
PrepareUnmanaged(true, "prepare for cluster entering unmanaged status"),
|
||||
HypervisorVersionChanged(false, " hypervisor version changed when host is reconnected");
|
||||
|
||||
private final boolean isUserRequest;
|
||||
|
|
@ -131,7 +123,6 @@ public enum Status {
|
|||
s_fsm.addTransition(Status.Connecting, Event.Ready, Status.Up);
|
||||
s_fsm.addTransition(Status.Connecting, Event.PingTimeout, Status.Alert);
|
||||
s_fsm.addTransition(Status.Connecting, Event.UpdateNeeded, Status.Updating);
|
||||
s_fsm.addTransition(Status.Connecting, Event.MaintenanceRequested, Status.PrepareForMaintenance);
|
||||
s_fsm.addTransition(Status.Connecting, Event.ShutdownRequested, Status.Disconnected);
|
||||
s_fsm.addTransition(Status.Connecting, Event.HostDown, Status.Alert);
|
||||
s_fsm.addTransition(Status.Connecting, Event.Ping, Status.Connecting);
|
||||
|
|
@ -139,7 +130,6 @@ public enum Status {
|
|||
s_fsm.addTransition(Status.Connecting, Event.AgentDisconnected, Status.Alert);
|
||||
s_fsm.addTransition(Status.Connecting, Event.HypervisorVersionChanged, Status.Disconnected);
|
||||
s_fsm.addTransition(Status.Up, Event.PingTimeout, Status.Alert);
|
||||
s_fsm.addTransition(Status.Up, Event.MaintenanceRequested, Status.PrepareForMaintenance);
|
||||
s_fsm.addTransition(Status.Up, Event.AgentDisconnected, Status.Alert);
|
||||
s_fsm.addTransition(Status.Up, Event.ShutdownRequested, Status.Disconnected);
|
||||
s_fsm.addTransition(Status.Up, Event.HostDown, Status.Down);
|
||||
|
|
@ -147,38 +137,12 @@ public enum Status {
|
|||
s_fsm.addTransition(Status.Up, Event.AgentConnected, Status.Connecting);
|
||||
s_fsm.addTransition(Status.Up, Event.ManagementServerDown, Status.Disconnected);
|
||||
s_fsm.addTransition(Status.Up, Event.StartAgentRebalance, Status.Rebalancing);
|
||||
s_fsm.addTransition(Status.Up, Event.PrepareUnmanaged, Status.Disconnected);
|
||||
s_fsm.addTransition(Status.Up, Event.HypervisorVersionChanged, Status.Disconnected);
|
||||
s_fsm.addTransition(Status.Updating, Event.PingTimeout, Status.Alert);
|
||||
s_fsm.addTransition(Status.Updating, Event.Ping, Status.Updating);
|
||||
s_fsm.addTransition(Status.Updating, Event.AgentConnected, Status.Connecting);
|
||||
s_fsm.addTransition(Status.Updating, Event.ManagementServerDown, Status.Disconnected);
|
||||
s_fsm.addTransition(Status.Updating, Event.WaitedTooLong, Status.Alert);
|
||||
s_fsm.addTransition(Status.PrepareForMaintenance, Event.ResetRequested, Status.Disconnected);
|
||||
s_fsm.addTransition(Status.PrepareForMaintenance, Event.PreparationComplete, Status.Maintenance);
|
||||
s_fsm.addTransition(Status.PrepareForMaintenance, Event.AgentDisconnected, Status.PrepareForMaintenance);
|
||||
s_fsm.addTransition(Status.PrepareForMaintenance, Event.AgentConnected, Status.PrepareForMaintenance);
|
||||
s_fsm.addTransition(Status.PrepareForMaintenance, Event.HostDown, Status.PrepareForMaintenance);
|
||||
s_fsm.addTransition(Status.PrepareForMaintenance, Event.UnableToMigrate, Status.ErrorInMaintenance);
|
||||
s_fsm.addTransition(Status.PrepareForMaintenance, Event.Ping, Status.PrepareForMaintenance);
|
||||
s_fsm.addTransition(Status.PrepareForMaintenance, Event.ManagementServerDown, Status.PrepareForMaintenance);
|
||||
s_fsm.addTransition(Status.ErrorInMaintenance, Event.MaintenanceRequested, Status.PrepareForMaintenance);
|
||||
s_fsm.addTransition(Status.ErrorInMaintenance, Event.ResetRequested, Status.Disconnected);
|
||||
s_fsm.addTransition(Status.ErrorInMaintenance, Event.HostDown, Status.ErrorInMaintenance);
|
||||
s_fsm.addTransition(Status.ErrorInMaintenance, Event.AgentDisconnected, Status.ErrorInMaintenance);
|
||||
s_fsm.addTransition(Status.ErrorInMaintenance, Event.AgentConnected, Status.ErrorInMaintenance);
|
||||
s_fsm.addTransition(Status.ErrorInMaintenance, Event.Remove, Status.Removed);
|
||||
s_fsm.addTransition(Status.ErrorInMaintenance, Event.UnableToMigrate, Status.ErrorInMaintenance);
|
||||
s_fsm.addTransition(Status.ErrorInMaintenance, Event.PreparationComplete, Status.Maintenance);
|
||||
s_fsm.addTransition(Status.ErrorInMaintenance, Event.Ping, Status.ErrorInMaintenance);
|
||||
s_fsm.addTransition(Status.ErrorInMaintenance, Event.ManagementServerDown, Status.ErrorInMaintenance);
|
||||
s_fsm.addTransition(Status.Maintenance, Event.ResetRequested, Status.Disconnected);
|
||||
s_fsm.addTransition(Status.Maintenance, Event.AgentDisconnected, Status.Maintenance);
|
||||
s_fsm.addTransition(Status.Maintenance, Event.HostDown, Status.Maintenance);
|
||||
s_fsm.addTransition(Status.Maintenance, Event.Remove, Status.Removed);
|
||||
s_fsm.addTransition(Status.Maintenance, Event.AgentConnected, Status.Maintenance);
|
||||
s_fsm.addTransition(Status.Maintenance, Event.Ping, Status.Maintenance);
|
||||
s_fsm.addTransition(Status.Maintenance, Event.ManagementServerDown, Status.Maintenance);
|
||||
s_fsm.addTransition(Status.Disconnected, Event.PingTimeout, Status.Alert);
|
||||
s_fsm.addTransition(Status.Disconnected, Event.AgentConnected, Status.Connecting);
|
||||
s_fsm.addTransition(Status.Disconnected, Event.Ping, Status.Up);
|
||||
|
|
@ -187,12 +151,10 @@ public enum Status {
|
|||
s_fsm.addTransition(Status.Disconnected, Event.Remove, Status.Removed);
|
||||
s_fsm.addTransition(Status.Disconnected, Event.HypervisorVersionChanged, Status.Disconnected);
|
||||
s_fsm.addTransition(Status.Disconnected, Event.AgentDisconnected, Status.Disconnected);
|
||||
s_fsm.addTransition(Status.Down, Event.MaintenanceRequested, Status.PrepareForMaintenance);
|
||||
s_fsm.addTransition(Status.Down, Event.AgentConnected, Status.Connecting);
|
||||
s_fsm.addTransition(Status.Down, Event.Remove, Status.Removed);
|
||||
s_fsm.addTransition(Status.Down, Event.ManagementServerDown, Status.Down);
|
||||
s_fsm.addTransition(Status.Down, Event.AgentDisconnected, Status.Down);
|
||||
s_fsm.addTransition(Status.Alert, Event.MaintenanceRequested, Status.PrepareForMaintenance);
|
||||
s_fsm.addTransition(Status.Alert, Event.AgentConnected, Status.Connecting);
|
||||
s_fsm.addTransition(Status.Alert, Event.Ping, Status.Up);
|
||||
s_fsm.addTransition(Status.Alert, Event.Remove, Status.Removed);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ public enum ResourceState {
|
|||
Enabled,
|
||||
Disabled,
|
||||
Unmanaged,
|
||||
PrepareForMaintenace,
|
||||
PrepareForMaintenance,
|
||||
ErrorInMaintenance,
|
||||
Maintenance;
|
||||
|
||||
|
|
|
|||
|
|
@ -210,7 +210,9 @@ public interface AgentManager extends Manager {
|
|||
|
||||
public AgentAttache findAttache(long hostId);
|
||||
|
||||
void disconnect(long hostId, Status.Event event);
|
||||
void disconnectWithoutInvestigation(long hostId, Status.Event event);
|
||||
|
||||
void disconnectWithInvestigation(long hostId, Status.Event event);
|
||||
|
||||
public boolean disconnectAgent(HostVO host, Status.Event e, long msId);
|
||||
|
||||
|
|
|
|||
|
|
@ -714,11 +714,6 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStatus(HostVO host, Status.Event event) {
|
||||
_hostDao.updateStatus(host, event, _nodeId);
|
||||
}
|
||||
|
||||
protected AgentAttache notifyMonitorsOfConnection(AgentAttache attache, final StartupCommand[] cmd, boolean forRebalance) throws ConnectionException {
|
||||
long hostId = attache.getId();
|
||||
HostVO host = _hostDao.findById(hostId);
|
||||
|
|
@ -763,7 +758,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
|
|||
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected);
|
||||
}
|
||||
|
||||
_hostDao.updateStatus(host, Event.Ready, _nodeId);
|
||||
agentStatusTransitTo(host, Event.Ready, _nodeId);
|
||||
attache.ready();
|
||||
return attache;
|
||||
}
|
||||
|
|
@ -882,7 +877,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
|
|||
} finally {
|
||||
if(!initialized) {
|
||||
if (host != null) {
|
||||
_hostDao.updateStatus(host, Event.AgentDisconnected, _nodeId);
|
||||
agentStatusTransitTo(host, Event.AgentDisconnected, _nodeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -934,7 +929,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
|
|||
s_logger.debug("Cant not find host " + agent.getId());
|
||||
}
|
||||
} else {
|
||||
_hostDao.updateStatus(host, Event.ManagementServerDown, _nodeId);
|
||||
agentStatusTransitTo(host, Event.ManagementServerDown, _nodeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1736,11 +1731,11 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
|
|||
return agentStatusTransitTo(host, e, msId);
|
||||
}
|
||||
|
||||
public void disconnectWithoutInvestigation(AgentAttache attache, final Status.Event event) {
|
||||
protected void disconnectWithoutInvestigation(AgentAttache attache, final Status.Event event) {
|
||||
_executor.submit(new DisconnectTask(attache, event, false));
|
||||
}
|
||||
|
||||
public void disconnectWithInvestigation(AgentAttache attache, final Status.Event event) {
|
||||
protected void disconnectWithInvestigation(AgentAttache attache, final Status.Event event) {
|
||||
_executor.submit(new DisconnectTask(attache, event, true));
|
||||
}
|
||||
|
||||
|
|
@ -1768,7 +1763,12 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(final long hostId, final Status.Event event) {
|
||||
public void disconnectWithInvestigation(final long hostId, final Status.Event event) {
|
||||
disconnectInternal(hostId, event, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnectWithoutInvestigation(final long hostId, final Status.Event event) {
|
||||
disconnectInternal(hostId, event, false);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ import com.cloud.host.HostVO;
|
|||
import com.cloud.host.Status;
|
||||
import com.cloud.host.Status.Event;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.resource.ResourceManager;
|
||||
import com.cloud.resource.ResourceState;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.db.ConnectionConcierge;
|
||||
import com.cloud.utils.db.DB;
|
||||
|
|
@ -63,6 +65,9 @@ public class AgentMonitor extends Thread implements Listener {
|
|||
private ConnectionConcierge _concierge;
|
||||
@Inject
|
||||
ClusterDao _clusterDao;
|
||||
@Inject
|
||||
ResourceManager _resourceMgr;
|
||||
|
||||
// private ConnectionConcierge _concierge;
|
||||
private Map<Long, Long> _pingMap;
|
||||
|
||||
|
|
@ -133,10 +138,10 @@ public class AgentMonitor extends Thread implements Listener {
|
|||
|
||||
List<Long> behindAgents = findAgentsBehindOnPing();
|
||||
for (Long agentId : behindAgents) {
|
||||
_agentMgr.disconnect(agentId, Event.PingTimeout, true);
|
||||
_agentMgr.disconnectWithInvestigation(agentId, Event.PingTimeout);
|
||||
}
|
||||
|
||||
List<HostVO> hosts = _hostDao.listByStatus(Status.PrepareForMaintenance, Status.ErrorInMaintenance);
|
||||
List<HostVO> hosts = _hostDao.listByResourceState(ResourceState.PrepareForMaintenace, ResourceState.ErrorInMaintenance);
|
||||
for (HostVO host : hosts) {
|
||||
long hostId = host.getId();
|
||||
DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
|
||||
|
|
@ -148,7 +153,7 @@ public class AgentMonitor extends Thread implements Listener {
|
|||
List<VMInstanceVO> vosMigrating = _vmDao.listVmsMigratingFromHost(hostId);
|
||||
if (vos.isEmpty() && vosMigrating.isEmpty()) {
|
||||
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Migration Complete for host " + hostDesc, "Host [" + hostDesc + "] is ready for maintenance");
|
||||
_hostDao.updateStatus(host, Event.PreparationComplete, _msId);
|
||||
_resourceMgr.updateResourceState(host, ResourceState.Event.InternalEnterMaintenance, _msId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -227,7 +232,7 @@ public class AgentMonitor extends Thread implements Listener {
|
|||
s_logger.info("Asking agent mgr to investgate why host " + host.getId() +
|
||||
" is behind on ping. last ping time: " + host.getLastPinged());
|
||||
}
|
||||
_agentMgr.disconnect(host.getId(), Event.PingTimeout, true);
|
||||
_agentMgr.disconnectWithInvestigation(host.getId(), Event.PingTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -102,6 +102,9 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
|
|||
|
||||
@Inject(adapter = AgentLoadBalancerPlanner.class)
|
||||
protected Adapters<AgentLoadBalancerPlanner> _lbPlanners;
|
||||
|
||||
@Inject
|
||||
protected AgentManager _agentMgr;
|
||||
|
||||
protected ClusteredAgentManagerImpl() {
|
||||
super();
|
||||
|
|
@ -1018,7 +1021,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
|
|||
|
||||
s_logger.debug("Updating host id=" + hostId + " with the status " + Status.Rebalancing);
|
||||
host.setManagementServerId(null);
|
||||
_hostDao.updateStatus(host, Event.StartAgentRebalance, _nodeId);
|
||||
_agentMgr.agentStatusTransitTo(host, Event.StartAgentRebalance, _nodeId);
|
||||
_hostTransferDao.startAgentTransfer(hostId);
|
||||
txn.commit();
|
||||
|
||||
|
|
|
|||
|
|
@ -38,11 +38,12 @@ import com.cloud.utils.fsm.StateDao;
|
|||
public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Status.Event, Host> {
|
||||
List<HostVO> listBy(Host.Type type, Long clusterId, Long podId, long dcId);
|
||||
|
||||
long countBy(long clusterId, Status... statuses);
|
||||
long countBy(long clusterId, ResourceState... states);
|
||||
|
||||
List<HostVO> listByDataCenter(long dcId);
|
||||
List<HostVO> listByHostPod(long podId);
|
||||
List<HostVO> listByStatus(Status... status);
|
||||
List<HostVO> listByStatus(Status... status);
|
||||
List<HostVO> listByResourceState(ResourceState...states);
|
||||
List<HostVO> listBy(Host.Type type, long dcId);
|
||||
List<HostVO> listAllBy(Host.Type type, long dcId);
|
||||
HostVO findSecondaryStorageHost(long dcId);
|
||||
|
|
@ -71,21 +72,6 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat
|
|||
List<HostVO> findDirectlyConnectedHosts();
|
||||
|
||||
List<HostVO> findAndUpdateDirectAgentToLoad(long lastPingSecondsAfter, Long limit, long managementServerId);
|
||||
/**
|
||||
* Mark the host as disconnected if it is in one of these states.
|
||||
* The management server id is set to null.
|
||||
* The lastPinged timestamp is set to current.
|
||||
* The state is set to the state passed in.
|
||||
* The disconnectedOn timestamp is set to current.
|
||||
*
|
||||
* @param host host to be marked
|
||||
* @param state state to be set to.
|
||||
* @param ifStates only if it is one of these states.
|
||||
* @return true if it's updated; false if not.
|
||||
*/
|
||||
boolean disconnect(HostVO host, Event event, long msId);
|
||||
|
||||
boolean connect(HostVO host, long msId);
|
||||
|
||||
HostVO findByStorageIpAddressInDataCenter(long dcId, String privateIpAddress);
|
||||
HostVO findByPrivateIpAddressInDataCenter(long dcId, String privateIpAddress);
|
||||
|
|
@ -111,16 +97,6 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat
|
|||
*/
|
||||
List<HostVO> listByType(Type type);
|
||||
|
||||
/**
|
||||
* update the host and changes the status depending on the Event and
|
||||
* the current status. If the status changed between
|
||||
* @param host host object to change
|
||||
* @param event event that happened.
|
||||
* @param management server who's making this update
|
||||
* @return true if updated; false if not.
|
||||
*/
|
||||
boolean updateStatus(HostVO host, Event event, long msId);
|
||||
|
||||
List<RunningHostCountInfo> getRunningHostCounts(Date cutTime);
|
||||
|
||||
long getNextSequence(long hostId);
|
||||
|
|
@ -152,9 +128,7 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat
|
|||
|
||||
long countRoutingHostsByDataCenter(long dcId);
|
||||
|
||||
List<HostVO> listSecondaryStorageHosts(long dataCenterId);
|
||||
|
||||
boolean directConnect(HostVO host, long msId);
|
||||
List<HostVO> listSecondaryStorageHosts(long dataCenterId);
|
||||
|
||||
List<HostVO> listDirectHostsBy(long msId, Status status);
|
||||
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
protected final SearchBuilder<HostVO> PodSearch;
|
||||
protected final SearchBuilder<HostVO> TypeSearch;
|
||||
protected final SearchBuilder<HostVO> StatusSearch;
|
||||
protected final SearchBuilder<HostVO> ResourceStateSearch;
|
||||
protected final SearchBuilder<HostVO> NameLikeSearch;
|
||||
protected final SearchBuilder<HostVO> NameSearch;
|
||||
protected final SearchBuilder<HostVO> SequenceSearch;
|
||||
|
|
@ -120,7 +121,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
|
||||
MaintenanceCountSearch = createSearchBuilder();
|
||||
MaintenanceCountSearch.and("cluster", MaintenanceCountSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
|
||||
MaintenanceCountSearch.and("status", MaintenanceCountSearch.entity().getStatus(), SearchCriteria.Op.IN);
|
||||
MaintenanceCountSearch.and("resourceState", MaintenanceCountSearch.entity().getResourceState(), SearchCriteria.Op.IN);
|
||||
MaintenanceCountSearch.done();
|
||||
|
||||
TypePodDcStatusSearch = createSearchBuilder();
|
||||
|
|
@ -135,7 +136,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
MsStatusSearch = createSearchBuilder();
|
||||
MsStatusSearch.and("ms", MsStatusSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ);
|
||||
MsStatusSearch.and("type", MsStatusSearch.entity().getType(), SearchCriteria.Op.EQ);
|
||||
MsStatusSearch.and("statuses", MsStatusSearch.entity().getStatus(), SearchCriteria.Op.NIN);
|
||||
MsStatusSearch.and("resourceState", MsStatusSearch.entity().getResourceState(), SearchCriteria.Op.NIN);
|
||||
MsStatusSearch.done();
|
||||
|
||||
TypeDcSearch = createSearchBuilder();
|
||||
|
|
@ -199,6 +200,10 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
StatusSearch = createSearchBuilder();
|
||||
StatusSearch.and("status", StatusSearch.entity().getStatus(), SearchCriteria.Op.IN);
|
||||
StatusSearch.done();
|
||||
|
||||
ResourceStateSearch = createSearchBuilder();
|
||||
ResourceStateSearch.and("resourceState", ResourceStateSearch.entity().getResourceState(), SearchCriteria.Op.IN);
|
||||
ResourceStateSearch.done();
|
||||
|
||||
NameLikeSearch = createSearchBuilder();
|
||||
NameLikeSearch.and("name", NameLikeSearch.entity().getName(), SearchCriteria.Op.LIKE);
|
||||
|
|
@ -223,7 +228,7 @@ 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.and("statuses", UnmanagedDirectConnectSearch.entity().getStatus(), SearchCriteria.Op.NIN);
|
||||
UnmanagedDirectConnectSearch.and("resourceStates", UnmanagedDirectConnectSearch.entity().getResourceState(), SearchCriteria.Op.NIN);
|
||||
/*
|
||||
* UnmanagedDirectConnectSearch.op(SearchCriteria.Op.OR, "managementServerId",
|
||||
* UnmanagedDirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ);
|
||||
|
|
@ -301,10 +306,10 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
}
|
||||
|
||||
@Override
|
||||
public long countBy(long clusterId, Status... statuses) {
|
||||
public long countBy(long clusterId, ResourceState... states) {
|
||||
SearchCriteria<HostVO> sc = MaintenanceCountSearch.create();
|
||||
|
||||
sc.setParameters("status", (Object[]) statuses);
|
||||
sc.setParameters("resourceState", (Object[]) states);
|
||||
sc.setParameters("cluster", clusterId);
|
||||
|
||||
List<HostVO> hosts = listBy(sc);
|
||||
|
|
@ -377,7 +382,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
txn.start();
|
||||
SearchCriteria<HostVO> sc = UnmanagedDirectConnectSearch.create();
|
||||
sc.setParameters("lastPinged", lastPingSecondsAfter);
|
||||
sc.setParameters("statuses", Status.ErrorInMaintenance, Status.Maintenance, Status.PrepareForMaintenance);
|
||||
sc.setParameters("resourceStates", ResourceState.ErrorInMaintenance, ResourceState.Maintenance, ResourceState.PrepareForMaintenance);
|
||||
sc.setJoinParameters("ClusterManagedSearch", "managed", Managed.ManagedState.Managed);
|
||||
List<HostVO> hosts = lockRows(sc, new Filter(HostVO.class, "clusterId", true, 0L, limit), true);
|
||||
|
||||
|
|
@ -415,7 +420,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
public void markHostsAsDisconnected(long msId, long lastPing) {
|
||||
SearchCriteria<HostVO> sc = MsStatusSearch.create();
|
||||
sc.setParameters("ms", msId);
|
||||
sc.setParameters("statuses", Status.ErrorInMaintenance, Status.Maintenance, Status.PrepareForMaintenance);
|
||||
sc.setParameters("resourceState", ResourceState.ErrorInMaintenance, ResourceState.Maintenance, ResourceState.PrepareForMaintenance);
|
||||
|
||||
HostVO host = createForUpdate();
|
||||
host.setLastPinged(lastPing);
|
||||
|
|
@ -585,120 +590,6 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
host.setHostTags(hostTags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean directConnect(HostVO host, long msId) {
|
||||
SearchCriteria<HostVO> sc = DirectConnectSearch.create();
|
||||
sc.setParameters("id", host.getId());
|
||||
sc.setParameters("server", msId);
|
||||
|
||||
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) {
|
||||
if (host == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Status oldStatus = host.getStatus();
|
||||
long oldPingTime = host.getLastPinged();
|
||||
Status newStatus = oldStatus.getNextStatus(event);
|
||||
|
||||
if (newStatus == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SearchBuilder<HostVO> sb = createSearchBuilder();
|
||||
sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ);
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
if (newStatus.checkManagementServer()) {
|
||||
sb.and("ping", sb.entity().getLastPinged(), SearchCriteria.Op.EQ);
|
||||
sb.and().op("nullmsid", sb.entity().getManagementServerId(), SearchCriteria.Op.NULL);
|
||||
sb.or("msid", sb.entity().getManagementServerId(), SearchCriteria.Op.EQ);
|
||||
sb.closeParen();
|
||||
}
|
||||
sb.done();
|
||||
|
||||
SearchCriteria<HostVO> sc = sb.create();
|
||||
|
||||
sc.setParameters("status", oldStatus);
|
||||
sc.setParameters("id", host.getId());
|
||||
if (newStatus.checkManagementServer()) {
|
||||
sc.setParameters("ping", oldPingTime);
|
||||
sc.setParameters("msid", msId);
|
||||
}
|
||||
|
||||
UpdateBuilder ub = getUpdateBuilder(host);
|
||||
ub.set(host, _statusAttr, newStatus);
|
||||
if (newStatus.updateManagementServer()) {
|
||||
if (newStatus.lostConnection()) {
|
||||
ub.set(host, _msIdAttr, null);
|
||||
} else {
|
||||
ub.set(host, _msIdAttr, msId);
|
||||
}
|
||||
if (event.equals(Event.Ping) || event.equals(Event.AgentConnected)) {
|
||||
ub.set(host, _pingTimeAttr, System.currentTimeMillis() >> 10);
|
||||
}
|
||||
}
|
||||
if (event.equals(Event.ManagementServerDown)) {
|
||||
ub.set(host, _pingTimeAttr, ((System.currentTimeMillis() >> 10) - (10 * 60)));
|
||||
}
|
||||
int result = update(ub, sc, null);
|
||||
|
||||
assert result <= 1 : "How can this update " + result + " rows? ";
|
||||
if (result < 1) {
|
||||
s_logger.warn("Unable to update db record for host id=" + host.getId() + "; it's possible that the host is removed");
|
||||
}
|
||||
|
||||
if (s_logger.isDebugEnabled() && result == 0) {
|
||||
HostVO vo = findById(host.getId());
|
||||
|
||||
if (vo != null) {
|
||||
StringBuilder str = new StringBuilder("Unable to update host for event:").append(event.toString());
|
||||
str.append(". New=[status=").append(newStatus.toString()).append(":msid=").append(newStatus.lostConnection() ? "null" : msId).append(":lastpinged=").append(host.getLastPinged())
|
||||
.append("]");
|
||||
str.append("; Old=[status=").append(oldStatus.toString()).append(":msid=").append(msId).append(":lastpinged=").append(oldPingTime).append("]");
|
||||
str.append("; DB=[status=").append(vo.getStatus().toString()).append(":msid=").append(vo.getManagementServerId()).append(":lastpinged=").append(vo.getLastPinged()).append("]");
|
||||
s_logger.debug(str.toString());
|
||||
} else {
|
||||
s_logger.warn("Can't find host db record by id=" + host.getId() + "; host might be already marked as removed");
|
||||
}
|
||||
|
||||
}
|
||||
return result > 0;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disconnect(HostVO host, Event event, long msId) {
|
||||
host.setDisconnectedOn(new Date());
|
||||
if (event != null && event.equals(Event.Remove)) {
|
||||
host.setGuid(null);
|
||||
host.setClusterId(null);
|
||||
}
|
||||
return updateStatus(host, event, msId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public boolean connect(HostVO host, long msId) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
long id = host.getId();
|
||||
txn.start();
|
||||
|
||||
if (!updateStatus(host, Event.AgentConnected, msId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
txn.commit();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HostVO findByGuid(String guid) {
|
||||
SearchCriteria<HostVO> sc = GuidSearch.create("guid", guid);
|
||||
|
|
@ -784,6 +675,14 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
sc.setParameters("status", (Object[]) status);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HostVO> listByResourceState(ResourceState... states) {
|
||||
SearchCriteria<HostVO> sc = ResourceStateSearch.create();
|
||||
sc.setParameters("resourceState", (Object[]) states);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<HostVO> listByTypeDataCenter(Type type, long dcId) {
|
||||
|
|
|
|||
|
|
@ -696,7 +696,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
|
|||
txn.start();
|
||||
|
||||
_dcDao.releasePrivateIpAddress(host.getPrivateIpAddress(), host.getDataCenterId(), null);
|
||||
_agentMgr.disconnect(hostId, Status.Event.Remove);
|
||||
_agentMgr.disconnectWithoutInvestigation(hostId, Status.Event.Remove);
|
||||
|
||||
// delete host details
|
||||
_hostDetailsDao.deleteDetails(hostId);
|
||||
|
|
@ -1038,7 +1038,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
|
|||
throw new InvalidParameterValueException("Unable to find host with ID: " + hostId + ". Please specify a valid host ID.");
|
||||
}
|
||||
|
||||
if (_hostDao.countBy(host.getClusterId(), Status.PrepareForMaintenance, Status.ErrorInMaintenance) > 0) {
|
||||
if (_hostDao.countBy(host.getClusterId(), ResourceState.PrepareForMaintenance, ResourceState.ErrorInMaintenance) > 0) {
|
||||
throw new InvalidParameterValueException("There are other servers in PrepareForMaintenance OR ErrorInMaintenance STATUS in cluster " + host.getClusterId());
|
||||
}
|
||||
|
||||
|
|
@ -1631,7 +1631,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
|
|||
}
|
||||
}
|
||||
|
||||
_agentMgr.disconnect(hostId, Status.Event.ResetRequested);
|
||||
_agentMgr.disconnectWithoutInvestigation(hostId, Status.Event.ResetRequested);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1668,7 +1668,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
|
|||
}
|
||||
|
||||
private boolean doUmanageHost(long hostId) {
|
||||
_agentMgr.disconnect(hostId, Status.Event.AgentDisconnected);
|
||||
_agentMgr.disconnectWithoutInvestigation(hostId, Status.Event.AgentDisconnected);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -357,7 +357,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
|||
List<StoragePoolVO> pools = _storagePoolDao.listAll();
|
||||
|
||||
// if no pools or 1 pool which is in maintenance
|
||||
if (pools == null || pools.size() == 0 || (pools.size() == 1 && pools.get(0).getStatus().equals(Status.Maintenance))) {
|
||||
if (pools == null || pools.size() == 0 || (pools.size() == 1 && pools.get(0).getStatus().equals(StoragePoolStatus.Maintenance))) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import javax.naming.ConfigurationException;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status.Event;
|
||||
|
|
@ -78,6 +79,8 @@ public class SecondaryStorageDiscoverer extends DiscovererBase implements Discov
|
|||
protected VMTemplateDao _vmTemplateDao = null;
|
||||
@Inject
|
||||
protected ConfigurationDao _configDao = null;
|
||||
@Inject
|
||||
protected AgentManager _agentMgr = null;
|
||||
|
||||
protected SecondaryStorageDiscoverer() {
|
||||
}
|
||||
|
|
@ -290,7 +293,7 @@ public class SecondaryStorageDiscoverer extends DiscovererBase implements Discov
|
|||
public void postDiscovery(List<HostVO> hosts, long msId) {
|
||||
if (_useServiceVM) {
|
||||
for (HostVO h: hosts) {
|
||||
_hostDao.disconnect(h, Event.AgentDisconnected, msId);
|
||||
_agentMgr.agentStatusTransitTo(h, Event.AgentDisconnected, msId);
|
||||
}
|
||||
}
|
||||
for (HostVO h: hosts) {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import com.cloud.agent.api.Command;
|
|||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.agent.api.StartupSecondaryStorageCommand;
|
||||
import com.cloud.agent.api.StartupStorageCommand;
|
||||
import com.cloud.cluster.ManagementServerNode;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.host.Status.Event;
|
||||
|
|
@ -82,7 +83,7 @@ public class SecondaryStorageListener implements Listener {
|
|||
if(s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Received a host startup notification " + cmd);
|
||||
}
|
||||
_agentMgr.updateStatus(agent, Event.Ready);
|
||||
_agentMgr.agentStatusTransitTo(agent, Event.Ready, ManagementServerNode.getManagementServerId());
|
||||
_ssVmMgr.onAgentConnect(agent.getDataCenterId(), cmd);
|
||||
_ssVmMgr.generateSetupCommand(agent.getId());
|
||||
_ssVmMgr.generateFirewallConfiguration(agent.getId());
|
||||
|
|
|
|||
Loading…
Reference in New Issue