Bug 11522 - New agent manager

renamce updateResourceState to resourceStateTransitTo
This commit is contained in:
frank 2011-09-29 11:58:41 -07:00
parent b188a513ba
commit a1193149a0
6 changed files with 34 additions and 17 deletions

View File

@ -153,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");
_resourceMgr.updateResourceState(host, ResourceState.Event.InternalEnterMaintenance, _msId);
_resourceMgr.resourceStateTransitTo(host, ResourceState.Event.InternalEnterMaintenance, _msId);
}
}
}

View File

@ -132,6 +132,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
TypePodDcStatusSearch.and("dc", entity.getDataCenterId(), SearchCriteria.Op.EQ);
TypePodDcStatusSearch.and("cluster", entity.getClusterId(), SearchCriteria.Op.EQ);
TypePodDcStatusSearch.and("status", entity.getStatus(), SearchCriteria.Op.EQ);
TypePodDcStatusSearch.and("resourceState", entity.getResourceState(), SearchCriteria.Op.EQ);
TypePodDcStatusSearch.done();
MsStatusSearch = createSearchBuilder();
@ -155,6 +156,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
TypeDcStatusSearch.and("type", TypeDcStatusSearch.entity().getType(), SearchCriteria.Op.EQ);
TypeDcStatusSearch.and("dc", TypeDcStatusSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
TypeDcStatusSearch.and("status", TypeDcStatusSearch.entity().getStatus(), SearchCriteria.Op.EQ);
TypeDcStatusSearch.and("resourceState", TypeDcStatusSearch.entity().getState(), SearchCriteria.Op.EQ);
TypeDcStatusSearch.done();
IdStatusSearch = createSearchBuilder();
@ -223,6 +225,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
DirectlyConnectedSearch.and("resource", DirectlyConnectedSearch.entity().getResource(), SearchCriteria.Op.NNULL);
DirectlyConnectedSearch.and("ms", DirectlyConnectedSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ);
DirectlyConnectedSearch.and("statuses", DirectlyConnectedSearch.entity().getStatus(), SearchCriteria.Op.EQ);
DirectlyConnectedSearch.and("resourceState", DirectlyConnectedSearch.entity().getResource(), SearchCriteria.Op.NOTIN);
DirectlyConnectedSearch.done();
UnmanagedDirectConnectSearch = createSearchBuilder();
@ -374,7 +377,8 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
@Override
public List<HostVO> findDirectlyConnectedHosts() {
SearchCriteria<HostVO> sc = DirectlyConnectedSearch.create();
SearchCriteria<HostVO> sc = DirectlyConnectedSearch.create();
sc.setParameters("resourceState", ResourceState.Disabled);
return search(sc, null);
}
@ -384,7 +388,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
txn.start();
SearchCriteria<HostVO> sc = UnmanagedDirectConnectSearch.create();
sc.setParameters("lastPinged", lastPingSecondsAfter);
sc.setParameters("resourceStates", ResourceState.ErrorInMaintenance, ResourceState.Maintenance, ResourceState.PrepareForMaintenance);
sc.setParameters("resourceStates", ResourceState.ErrorInMaintenance, ResourceState.Maintenance, ResourceState.PrepareForMaintenance, ResourceState.Disabled);
sc.setJoinParameters("ClusterManagedSearch", "managed", Managed.ManagedState.Managed);
List<HostVO> hosts = lockRows(sc, new Filter(HostVO.class, "clusterId", true, 0L, limit), true);
@ -422,7 +426,6 @@ 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("resourceState", ResourceState.ErrorInMaintenance, ResourceState.Maintenance, ResourceState.PrepareForMaintenance);
HostVO host = createForUpdate();
host.setLastPinged(lastPing);
@ -457,6 +460,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
}
sc.setParameters("dc", dcId);
sc.setParameters("status", Status.Up.toString());
sc.setParameters("resourceState", ResourceState.Enabled.toString());
return listBy(sc);
}
@ -505,6 +509,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
hostSearch.and("dc", entity.getDataCenterId(), SearchCriteria.Op.EQ);
hostSearch.and("cluster", entity.getClusterId(), SearchCriteria.Op.EQ);
hostSearch.and("status", entity.getStatus(), SearchCriteria.Op.EQ);
hostSearch.and("resourceState", entity.getState(), SearchCriteria.Op.EQ);
hostSearch.join("hostTagSearch", hostTagSearch, entity.getId(), tagEntity.getHostId(), JoinBuilder.JoinType.INNER);
SearchCriteria<HostVO> sc = hostSearch.create();
@ -518,6 +523,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
}
sc.setParameters("dc", dcId);
sc.setParameters("status", Status.Up.toString());
sc.setParameters("resourceState", ResourceState.Enabled.toString());
return listBy(sc);
}
@ -549,6 +555,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
sc.setParameters("type", type.toString());
sc.setParameters("dc", dcId);
sc.setParameters("status", Status.Up.toString());
sc.setParameters("resourceState", ResourceState.Enabled.toString());
return listBy(sc);
}
@ -864,6 +871,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
return customSearch(sc, null);
}
/*TODO: this is used by mycloud, check if it needs resource state Enabled */
@Override
public long countRoutingHostsByDataCenter(long dcId) {
SearchCriteria<Long> sc = CountRoutingByDc.create();

View File

@ -74,7 +74,7 @@ public interface ResourceManager {
public boolean executeUserRequest(long hostId, ResourceState.Event event) throws AgentUnavailableException;
boolean updateResourceState(Host host, Event event, long msId) throws NoTransitionException;
boolean resourceStateTransitTo(Host host, Event event, long msId) throws NoTransitionException;
boolean umanageHost(long hostId);

View File

@ -718,7 +718,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
}
try {
updateResourceState(host, ResourceState.Event.DeleteHost, _nodeId);
resourceStateTransitTo(host, ResourceState.Event.DeleteHost, _nodeId);
} catch (NoTransitionException e) {
s_logger.debug("Cannot transmit host " + host.getId() + "to Enabled state", e);
}
@ -974,7 +974,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
}
@Override
public boolean updateResourceState(Host host, ResourceState.Event event, long msId) throws NoTransitionException {
public boolean resourceStateTransitTo(Host host, ResourceState.Event event, long msId) throws NoTransitionException {
ResourceState currentState = host.getResourceState();
ResourceState nextState = currentState.getNextState(event);
if (nextState == null) {
@ -993,7 +993,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
}
try {
updateResourceState(host, ResourceState.Event.AdminAskMaintenace, _nodeId);
resourceStateTransitTo(host, ResourceState.Event.AdminAskMaintenace, _nodeId);
} catch (NoTransitionException e) {
String err = "Cannot transimit resource state of host " + host.getId() + " to " + ResourceState.Maintenance;
s_logger.debug(err, e);
@ -1396,12 +1396,12 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
try {
/* Agent goes to Connecting status */
_agentMgr.agentStatusTransitTo(host, Status.Event.AgentConnected, _nodeId);
updateResourceState(host, ResourceState.Event.InternalCreated, _nodeId);
resourceStateTransitTo(host, ResourceState.Event.InternalCreated, _nodeId);
} catch (Exception e) {
s_logger.debug("Cannot transmit host " + host.getId() + " to Creating state", e);
_agentMgr.agentStatusTransitTo(host, Status.Event.Error, _nodeId);
try {
updateResourceState(host, ResourceState.Event.Error, _nodeId);
resourceStateTransitTo(host, ResourceState.Event.Error, _nodeId);
} catch (NoTransitionException e1) {
s_logger.debug("Cannot transmit host " + host.getId() + "to Error state", e);
}
@ -1457,7 +1457,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
/* Change agent status to Alert */
_agentMgr.agentStatusTransitTo(host, Status.Event.AgentDisconnected, _nodeId);
try {
updateResourceState(host, ResourceState.Event.Error, _nodeId);
resourceStateTransitTo(host, ResourceState.Event.Error, _nodeId);
} catch (NoTransitionException e) {
s_logger.debug("Cannot transmit host " + host.getId() + "to Disabled state", e);
}
@ -1671,7 +1671,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
}
try {
updateResourceState(host, ResourceState.Event.AdminCancelMaintenance, _nodeId);
resourceStateTransitTo(host, ResourceState.Event.AdminCancelMaintenance, _nodeId);
_agentMgr.disconnectWithoutInvestigation(hostId, Status.Event.ResetRequested);
return true;
} catch (NoTransitionException e) {
@ -1720,7 +1720,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
return true;
}
updateResourceState(host, ResourceState.Event.AdminCancelMaintenance, _nodeId);
resourceStateTransitTo(host, ResourceState.Event.AdminCancelMaintenance, _nodeId);
_agentMgr.disconnectWithoutInvestigation(hostId, Status.Event.AgentDisconnected);
return true;
} catch (NoTransitionException e) {
@ -1803,7 +1803,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
return false;
} else {
try {
return updateResourceState(host, ResourceState.Event.UnableToMigrate, _nodeId);
return resourceStateTransitTo(host, ResourceState.Event.UnableToMigrate, _nodeId);
} catch (NoTransitionException e) {
s_logger.debug("No next resource state for host " + host.getId() + " while current state is " + host.getResourceState() + " with event " + ResourceState.Event.UnableToMigrate, e);
return false;

View File

@ -72,7 +72,6 @@ public class SecondaryStorageListener implements Listener {
@Override
public void processConnect(HostVO agent, StartupCommand cmd, boolean forRebalance) {
if ((cmd instanceof StartupStorageCommand) ) {
StartupStorageCommand scmd = (StartupStorageCommand)cmd;
if (scmd.getResourceType() == Storage.StorageResourceType.SECONDARY_STORAGE ) {
@ -90,8 +89,6 @@ public class SecondaryStorageListener implements Listener {
return;
}
return;
}
@Override

View File

@ -379,6 +379,18 @@ public class CheckPointManagerTest extends TestCase {
@Override
public boolean isAgentRebalanceEnabled() {
return false;
}
@Override
public Boolean propagateResourceEvent(long agentId, com.cloud.resource.ResourceState.Event event) throws AgentUnavailableException {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean executeResourceUserRequest(long hostId, com.cloud.resource.ResourceState.Event event) throws AgentUnavailableException {
// TODO Auto-generated method stub
return false;
}
}