From 635a1075de96ca847ec78f260131d84bf5fb4b91 Mon Sep 17 00:00:00 2001 From: alena Date: Thu, 2 Jun 2011 21:33:34 -0700 Subject: [PATCH] bug 9127: intermediate checkin for agent load balancer --- api/src/com/cloud/host/Status.java | 8 +- client/tomcatconf/components.xml.in | 2 +- .../com/cloud/agent/manager/AgentAttache.java | 23 +++- .../manager/ClusteredAgentManagerImpl.java | 121 +++++++++--------- .../com/cloud/cluster/ClusterManagerImpl.java | 58 ++------- .../agentlb/AgentLoadBalancerPlanner.java | 2 +- .../ClusterBasedAgentLoadBalancerPlanner.java | 10 +- .../cluster/agentlb/HostTransferMapVO.java | 2 +- .../agentlb/dao/HostTransferMapDao.java | 8 +- .../agentlb/dao/HostTransferMapDaoImpl.java | 32 ++--- server/src/com/cloud/host/dao/HostDao.java | 2 +- .../src/com/cloud/host/dao/HostDaoImpl.java | 14 +- 12 files changed, 133 insertions(+), 149 deletions(-) diff --git a/api/src/com/cloud/host/Status.java b/api/src/com/cloud/host/Status.java index 87da0ef2bb7..cbcdb40776d 100644 --- a/api/src/com/cloud/host/Status.java +++ b/api/src/com/cloud/host/Status.java @@ -33,7 +33,7 @@ public enum Status { Maintenance(false, false, false), Alert(true, true, true), Removed(true, false, true), - Rebalance(false, false, false); + Rebalancing(false, false, false); private final boolean updateManagementServer; private final boolean checkManagementServer; @@ -137,7 +137,7 @@ public enum Status { s_fsm.addTransition(Status.Up, Event.Ping, Status.Up); 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.Rebalance); + s_fsm.addTransition(Status.Up, Event.StartAgentRebalance, Status.Rebalancing); 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); @@ -183,8 +183,8 @@ public enum Status { s_fsm.addTransition(Status.Alert, Event.Ping, Status.Up); s_fsm.addTransition(Status.Alert, Event.Remove, Status.Removed); s_fsm.addTransition(Status.Alert, Event.ManagementServerDown, Status.Alert); - s_fsm.addTransition(Status.Rebalance, Event.RebalanceFailed, Status.Alert); - s_fsm.addTransition(Status.Rebalance, Event.RebalanceCompleted, Status.Connecting); + s_fsm.addTransition(Status.Rebalancing, Event.RebalanceFailed, Status.Alert); + s_fsm.addTransition(Status.Rebalancing, Event.RebalanceCompleted, Status.Connecting); } public static void main(String[] args) { diff --git a/client/tomcatconf/components.xml.in b/client/tomcatconf/components.xml.in index a991e84fcde..c63aa0c047a 100755 --- a/client/tomcatconf/components.xml.in +++ b/client/tomcatconf/components.xml.in @@ -93,7 +93,7 @@ - + diff --git a/server/src/com/cloud/agent/manager/AgentAttache.java b/server/src/com/cloud/agent/manager/AgentAttache.java index 12934b18ece..470acb2c319 100644 --- a/server/src/com/cloud/agent/manager/AgentAttache.java +++ b/server/src/com/cloud/agent/manager/AgentAttache.java @@ -17,11 +17,13 @@ */ package com.cloud.agent.manager; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Random; import java.util.Set; @@ -238,8 +240,25 @@ public abstract class AgentAttache { return _requests.size(); } - public int getListenersSize() { - return _waitForList.size(); + public int getNonRecurringListenersSize() { + List nonRecurringListenersList = new ArrayList(); + if (_waitForList.isEmpty()) { + return 0; + } else { + final Set> entries = _waitForList.entrySet(); + final Iterator> it = entries.iterator(); + while (it.hasNext()) { + final Map.Entry entry = it.next(); + final Listener monitor = entry.getValue(); + if (!monitor.isRecurring()) { + //TODO - remove this debug statement later + s_logger.debug("Listener is " + entry.getValue() + " waiting on " + entry.getKey()); + nonRecurringListenersList.add(monitor); + } + } + } + + return nonRecurringListenersList.size(); } public boolean processAnswers(final long seq, final Response resp) { diff --git a/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java b/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java index 070a697be55..d916200e387 100644 --- a/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java @@ -129,7 +129,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust // schedule transfer scan executor - if agent LB is enabled if (_clusterMgr.isAgentRebalanceEnabled()) { - s_transferExecutor.scheduleAtFixedRate(getTransferScanTask(), ClusteredAgentRebalanceService.DEFAULT_TRANSFER_CHECK_INTERVAL, ClusteredAgentRebalanceService.DEFAULT_TRANSFER_CHECK_INTERVAL, + s_transferExecutor.scheduleAtFixedRate(getTransferScanTask(), 60000, ClusteredAgentRebalanceService.DEFAULT_TRANSFER_CHECK_INTERVAL, TimeUnit.MILLISECONDS); } @@ -524,7 +524,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust } } if (agent == null) { - throw new AgentUnavailableException("Host is not in the right state", hostId); + throw new AgentUnavailableException("Host is not in the right state: " + host.getStatus() , hostId); } return agent; @@ -698,23 +698,26 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust @Override public void startRebalanceAgents() { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Management server " + _nodeId + " was asked to do agent rebalancing; checking how many hosts can be taken from this server"); - } - List allMS = _mshostDao.listBy(ManagementServerHost.State.Up, ManagementServerHost.State.Starting); - List allManagedAgents = _hostDao.listManagedAgents(); + List allManagedAgents = _hostDao.listManagedRoutingAgents(); - long avLoad = 0L; + int avLoad = 0; if (!allManagedAgents.isEmpty() && !allMS.isEmpty()) { avLoad = allManagedAgents.size() / allMS.size(); } else { if (s_logger.isDebugEnabled()) { - s_logger.debug("Management server " + _nodeId + " found no hosts to rebalance. Current number of active management server nodes in the system is " + allMS.size() + "; number of managed agents is " + allMS.size()); + s_logger.debug("There are no hosts to rebalance in the system. Current number of active management server nodes in the system is " + allMS.size() + "; number of managed agents is " + allManagedAgents.size()); } return; } + + if (avLoad == 0L) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("As calculated average load is less than 1, rounding it to 1"); + } + avLoad = 1; + } for (ManagementServerHostVO node : allMS) { if (node.getMsid() != _nodeId) { @@ -722,21 +725,21 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust List hostsToRebalance = new ArrayList(); for (AgentLoadBalancerPlanner lbPlanner : _lbPlanners) { hostsToRebalance = lbPlanner.getHostsToRebalance(node.getMsid(), avLoad); - if (!hostsToRebalance.isEmpty()) { + if (hostsToRebalance != null && !hostsToRebalance.isEmpty()) { break; } else { - s_logger.debug("Agent load balancer planner " + lbPlanner.getName() + " found no hosts to be rebalanced from management server " + _nodeId); + s_logger.debug("Agent load balancer planner " + lbPlanner.getName() + " found no hosts to be rebalanced from management server " + node.getMsid()); } } - if (!hostsToRebalance.isEmpty()) { + if (hostsToRebalance != null && !hostsToRebalance.isEmpty()) { for (HostVO host : hostsToRebalance) { long hostId = host.getId(); s_logger.debug("Asking management server " + node.getMsid() + " to give away host id=" + hostId); boolean result = true; - HostTransferMapVO transfer = _hostTransferDao.startAgentTransfering(hostId, _nodeId, node.getMsid()); + HostTransferMapVO transfer = _hostTransferDao.startAgentTransfering(hostId, node.getMsid(), _nodeId); try { - Answer[] answer = sendRebalanceCommand(hostId, _nodeId, Event.RequestAgentRebalance); + Answer[] answer = sendRebalanceCommand(hostId, node.getMsid(), Event.RequestAgentRebalance); if (answer == null) { s_logger.warn("Failed to get host id=" + hostId + " from management server " + node.getMsid()); result = false; @@ -756,7 +759,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust } } } else { - s_logger.debug("Management server " + _nodeId + " found no hosts to rebalance."); + s_logger.debug("Found no hosts to rebalance from the management server " + node.getMsid()); } } } @@ -797,10 +800,11 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust s_logger.debug("Found " + _agentToTransferIds.size() + " agents to transfer"); for (Long hostId : _agentToTransferIds) { AgentAttache attache = findAttache(hostId); - if (attache.getQueueSize() == 0 && attache.getListenersSize() == 0) { - boolean result = true; + if (attache.getQueueSize() == 0 && attache.getNonRecurringListenersSize() == 0) { + boolean result = false; _agentToTransferIds.remove(hostId); try { + _hostTransferDao.startAgentTransfer(hostId); result = rebalanceHost(hostId); } finally { if (result) { @@ -810,16 +814,16 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust } } } else { - // if we timed out waiting for the host to reconnect, remove host from rebalance list and mark it as failed to rebalance + // if we timed out waiting for the host to reconnect, remove host from rebalance list and delete from op_host_transfer DB // no need to do anything with the real attache Date cutTime = DateUtil.currentGMTTime(); - if (!(_hostTransferDao.isActive(hostId, new Date(cutTime.getTime() - rebalanceTimeOut)))) { + if (_hostTransferDao.isNotActive(hostId, new Date(cutTime.getTime() - rebalanceTimeOut))) { s_logger.debug("Timed out waiting for the host id=" + hostId + " to be ready to transfer, failing rebalance for this host"); _agentToTransferIds.remove(hostId); - HostTransferMapVO transferMap = _hostTransferDao.findById(hostId); - transferMap.setState(HostTransferState.TransferFailed); - _hostTransferDao.update(hostId, transferMap); - } + _hostTransferDao.completeAgentTransfer(hostId); + } else { + s_logger.debug("Agent " + hostId + " can't be transfered yet as its request queue size is " + attache.getQueueSize() + " and listener queue size is " + attache.getNonRecurringListenersSize()); + } } } } else { @@ -859,7 +863,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust _agents.put(hostId, attache); if (host != null && host.getRemoved() == null) { host.setManagementServerId(null); - s_logger.debug("Updating host id=" + hostId + " with the status " + Status.Rebalance); + s_logger.debug("Updating host id=" + hostId + " with the status " + Status.Rebalancing); _hostDao.updateStatus(host, Event.StartAgentRebalance, _nodeId); } @@ -877,7 +881,10 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust s_logger.debug("Got host id=" + hostId + " from management server " + map.getFutureOwner()); } - } + } else { + s_logger.warn("Unable to find agent " + hostId + " on management server " + _nodeId); + result = false; + } } else if (map.getFutureOwner() == _nodeId) { try { if (s_logger.isDebugEnabled()) { @@ -887,61 +894,57 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust loadDirectlyConnectedHost(host); } catch (Exception ex) { s_logger.warn("Unable to load directly connected host " + host.getId() + " as a part of rebalance due to exception: ", ex); + result = false; } } return result; - } private boolean finishRebalance(final long hostId, Event event) { HostTransferMapVO map = _hostTransferDao.findById(hostId); - AgentAttache attache = findAttache(hostId); - - if (attache == null) { - s_logger.debug("Unable to find attache for the host id=" + hostId + ", assuming that the agent disconnected already"); - HostTransferState state = (event == Event.RebalanceCompleted) ? HostTransferState.TransferCompleted : HostTransferState.TransferFailed; - map.setState(state); - _hostTransferDao.update(hostId, map); - return true; - } if (map.getInitialOwner() != _nodeId) { s_logger.warn("Why finish rebalance called not by initial host owner???"); return false; - } - - if (s_logger.isDebugEnabled()) { - s_logger.debug("Finishing rebalancing for the host id=" + hostId); + } + + boolean success = (event == Event.RebalanceCompleted) ? true : false; + if (s_logger.isDebugEnabled()) { + s_logger.debug("Finishing rebalancing for the agent " + hostId + " with result " + success); } - if (event == Event.RebalanceFailed) { - ((ClusteredDirectAgentAttache) attache).setTransferMode(false); - s_logger.debug("Rebalance failed for the host id=" + hostId); - map.setState(HostTransferState.TransferFailed); - _hostTransferDao.update(hostId, map); - } else if (event == Event.RebalanceCompleted) { - - //1) Get all the requests remove transfer attache + AgentAttache attache = findAttache(hostId); + if (attache == null) { + s_logger.debug("Unable to find attache for the host id=" + hostId + ", assuming that the agent disconnected already"); + return true; + } else if (success) { + s_logger.debug("Management server " + _nodeId + " is completing agent " + hostId + " rebalance"); + //1) Get all the requests before removing transfer attache LinkedList requests = ((ClusteredDirectAgentAttache) attache).getRequests(); - removeAgent(attache, Status.Rebalance); + removeAgent(attache, Status.Rebalancing); //2) Create forward attache - createAttache(hostId); - - //3) forward all the requests to the management server which owns the host now - if (!requests.isEmpty()) { - for (Request request : requests) { - routeToPeer(Long.toString(map.getFutureOwner()), request.getBytes()); + try { + getAttache(hostId); + //3) forward all the requests to the management server which owns the host now + if (!requests.isEmpty()) { + s_logger.debug("Forwarding requests held in transfer attache " + hostId + " from the management server " + _nodeId + " to " + map.getFutureOwner()); + for (Request request : requests) { + routeToPeer(Long.toString(map.getFutureOwner()), request.getBytes()); + } } + } catch (AgentUnavailableException ex) { + s_logger.warn("Not creating forward attache as agent is not available", ex); + //TODO - - have to handle the case when requests can't be forwarded due to lack of forward attache } - map.setState(HostTransferState.TransferCompleted); - _hostTransferDao.update(hostId, map); - - return true; - + } else { + ((ClusteredDirectAgentAttache) attache).setTransferMode(false); + //TODO - have to handle the case when agent fails to rebalance 1) Either connect it back 2) Or disconnect it } + + _hostTransferDao.completeAgentTransfer(hostId); return true; } } diff --git a/server/src/com/cloud/cluster/ClusterManagerImpl.java b/server/src/com/cloud/cluster/ClusterManagerImpl.java index 747898755a9..0ee0f796230 100644 --- a/server/src/com/cloud/cluster/ClusterManagerImpl.java +++ b/server/src/com/cloud/cluster/ClusterManagerImpl.java @@ -574,14 +574,11 @@ public class ClusterManagerImpl implements ClusterManager { Connection conn = getHeartbeatConnection(); _mshostDao.update(conn, _mshostId, getCurrentRunId(), DateUtil.currentGMTTime()); - // for cluster in Starting state check if there are any agents being transfered if (_state == State.Starting) { synchronized (stateLock) { - if (isClusterReadyToStart()) { - _mshostDao.update(conn, _mshostId, getCurrentRunId(), State.Up, DateUtil.currentGMTTime()); - _state = State.Up; - stateLock.notifyAll(); - } + _mshostDao.update(conn, _mshostId, getCurrentRunId(), State.Up, DateUtil.currentGMTTime()); + _state = State.Up; + stateLock.notifyAll(); } } @@ -618,45 +615,6 @@ public class ClusterManagerImpl implements ClusterManager { s_logger.error("Problem with the cluster heartbeat!", e); } } - - private boolean isClusterReadyToStart() { - if (!_agentLBEnabled) { - return true; - } - boolean isReady = false; - int transferCount = _hostTransferDao.listHostsJoiningCluster(_msId).size(); - if (transferCount == 0) { - //Check how many servers got transfered successfully - List rebalancedHosts = _hostTransferDao.listBy(_msId, HostTransferState.TransferCompleted); - - if (!rebalancedHosts.isEmpty() && s_logger.isDebugEnabled()) { - s_logger.debug(rebalancedHosts.size() + " hosts joined the cluster " + _msId + " as a result of rebalance process"); - - } - - for (HostTransferMapVO host : rebalancedHosts) { - _hostTransferDao.remove(host.getId()); - } - - //Check how many servers failed to transfer - List failedToRebalanceHosts = _hostTransferDao.listBy(_msId, HostTransferState.TransferFailed); - if (!failedToRebalanceHosts.isEmpty() && s_logger.isDebugEnabled()) { - s_logger.debug(failedToRebalanceHosts.size() + " hosts failed to join the cluster " + _msId + " as a result of rebalance process"); - } - - for (HostTransferMapVO host : failedToRebalanceHosts) { - _hostTransferDao.remove(host.getId()); - } - - s_logger.debug("There are no hosts currently joining cluser msid=" + _msId + ", so management server is ready to start"); - isReady = true; - } else if (s_logger.isDebugEnabled()) { - //TODO : change to trace mode later - s_logger.debug("There are " + transferCount + " agents currently joinging the cluster " + _msId); - } - - return isReady; - } }; } @@ -952,15 +910,15 @@ public class ClusterManagerImpl implements ClusterManager { s_logger.info("Management server (host id : " + _mshostId + ") is being started at " + _clusterNodeIP + ":" + _currentServiceAdapter.getServicePort()); } - // use seperate thread for heartbeat updates - _heartbeatScheduler.scheduleAtFixedRate(getHeartbeatTask(), heartbeatInterval, heartbeatInterval, TimeUnit.MILLISECONDS); - _notificationExecutor.submit(getNotificationTask()); - - // Do agent rebalancing + // Initiate agent rebalancing if (_agentLBEnabled) { s_logger.debug("Management server " + _msId + " is asking other peers to rebalance their agents"); _rebalanceService.startRebalanceAgents(); } + + // use seperate thread for heartbeat updates + _heartbeatScheduler.scheduleAtFixedRate(getHeartbeatTask(), heartbeatInterval, heartbeatInterval, TimeUnit.MILLISECONDS); + _notificationExecutor.submit(getNotificationTask()); //wait here for heartbeat task to update the host state try { diff --git a/server/src/com/cloud/cluster/agentlb/AgentLoadBalancerPlanner.java b/server/src/com/cloud/cluster/agentlb/AgentLoadBalancerPlanner.java index 2a87724d253..b9d5b0fa936 100644 --- a/server/src/com/cloud/cluster/agentlb/AgentLoadBalancerPlanner.java +++ b/server/src/com/cloud/cluster/agentlb/AgentLoadBalancerPlanner.java @@ -26,6 +26,6 @@ import com.cloud.utils.component.Adapter; public interface AgentLoadBalancerPlanner extends Adapter{ - List getHostsToRebalance(long msId, long avLoad); + List getHostsToRebalance(long msId, int avLoad); } diff --git a/server/src/com/cloud/cluster/agentlb/ClusterBasedAgentLoadBalancerPlanner.java b/server/src/com/cloud/cluster/agentlb/ClusterBasedAgentLoadBalancerPlanner.java index 0f896d7f43c..1862ced8cbd 100644 --- a/server/src/com/cloud/cluster/agentlb/ClusterBasedAgentLoadBalancerPlanner.java +++ b/server/src/com/cloud/cluster/agentlb/ClusterBasedAgentLoadBalancerPlanner.java @@ -65,11 +65,11 @@ public class ClusterBasedAgentLoadBalancerPlanner implements AgentLoadBalancerPl } @Override - public List getHostsToRebalance(long msId, long avLoad) { + public List getHostsToRebalance(long msId, int avLoad) { List allHosts = _hostDao.listByManagementServer(msId); if (allHosts.size() <= avLoad) { - s_logger.debug("Agent load for management server " + msId + " doesn't exceed av load " + avLoad + "; so it doesn't participate in agent rebalancing process"); + s_logger.debug("Agent load = " + allHosts.size() + " for management server " + msId + " doesn't exceed average system agent load = " + avLoad + "; so it doesn't participate in agent rebalancing process"); return null; } @@ -96,9 +96,9 @@ public class ClusterBasedAgentLoadBalancerPlanner implements AgentLoadBalancerPl hostToClusterMap = sortByClusterSize(hostToClusterMap); - long hostsToGive = allHosts.size() - avLoad; - long hostsLeftToGive = hostsToGive; - long hostsLeft = directHosts.size(); + int hostsToGive = allHosts.size() - avLoad; + int hostsLeftToGive = hostsToGive; + int hostsLeft = directHosts.size(); List hostsToReturn = new ArrayList(); int count = 0; diff --git a/server/src/com/cloud/cluster/agentlb/HostTransferMapVO.java b/server/src/com/cloud/cluster/agentlb/HostTransferMapVO.java index a2bb428b084..d98d41b5345 100644 --- a/server/src/com/cloud/cluster/agentlb/HostTransferMapVO.java +++ b/server/src/com/cloud/cluster/agentlb/HostTransferMapVO.java @@ -35,7 +35,7 @@ import com.cloud.utils.db.GenericDao; public class HostTransferMapVO { public enum HostTransferState { - TransferRequested, TransferStarted, TransferCompleted, TransferFailed; + TransferRequested, TransferStarted; } @Id diff --git a/server/src/com/cloud/cluster/agentlb/dao/HostTransferMapDao.java b/server/src/com/cloud/cluster/agentlb/dao/HostTransferMapDao.java index 4bb0b172250..55e7802431f 100644 --- a/server/src/com/cloud/cluster/agentlb/dao/HostTransferMapDao.java +++ b/server/src/com/cloud/cluster/agentlb/dao/HostTransferMapDao.java @@ -29,13 +29,15 @@ public interface HostTransferMapDao extends GenericDao List listHostsLeavingCluster(long clusterId); - List listHostsJoiningCluster(long clusterId); + List listHostsJoiningCluster(long futureOwnerId); HostTransferMapVO startAgentTransfering(long hostId, long currentOwner, long futureOwner); - boolean completeAgentTransfering(long hostId, boolean success); + boolean completeAgentTransfer(long hostId); List listBy(long futureOwnerId, HostTransferState state); - boolean isActive(long hostId, Date cutTime); + boolean isNotActive(long hostId, Date cutTime); + + boolean startAgentTransfer(long hostId); } diff --git a/server/src/com/cloud/cluster/agentlb/dao/HostTransferMapDaoImpl.java b/server/src/com/cloud/cluster/agentlb/dao/HostTransferMapDaoImpl.java index 8491215e8cc..e600011e865 100644 --- a/server/src/com/cloud/cluster/agentlb/dao/HostTransferMapDaoImpl.java +++ b/server/src/com/cloud/cluster/agentlb/dao/HostTransferMapDaoImpl.java @@ -51,7 +51,7 @@ public class HostTransferMapDaoImpl extends GenericDaoBase listHostsJoiningCluster(long clusterId) { + public List listHostsJoiningCluster(long futureOwnerId) { SearchCriteria sc = IntermediateStateSearch.create(); - sc.setParameters("futureOwner", clusterId); - sc.setParameters("state", HostTransferState.TransferRequested, HostTransferState.TransferStarted); + sc.setParameters("futureOwner", futureOwnerId); + sc.setParameters("state", HostTransferState.TransferRequested); return listBy(sc); } @@ -88,14 +88,8 @@ public class HostTransferMapDaoImpl extends GenericDaoBase sc = InactiveSearch.create(); sc.setParameters("id", hostId); sc.setParameters("state", HostTransferState.TransferRequested); sc.setParameters("created", cutTime); - if (listBy(sc).isEmpty()) { - return true; - } else { return false; + } else { + return true; } } + @Override + public boolean startAgentTransfer(long hostId) { + HostTransferMapVO transfer = findById(hostId); + transfer.setState(HostTransferState.TransferStarted); + return update(hostId, transfer); + } + } diff --git a/server/src/com/cloud/host/dao/HostDao.java b/server/src/com/cloud/host/dao/HostDao.java index de035f20743..95607033b3d 100644 --- a/server/src/com/cloud/host/dao/HostDao.java +++ b/server/src/com/cloud/host/dao/HostDao.java @@ -171,7 +171,7 @@ public interface HostDao extends GenericDao { List listManagedDirectAgents(); - List listManagedAgents(); + List listManagedRoutingAgents(); HostVO findTrafficMonitorHost(); diff --git a/server/src/com/cloud/host/dao/HostDaoImpl.java b/server/src/com/cloud/host/dao/HostDaoImpl.java index ed74c108703..06717dbfd27 100644 --- a/server/src/com/cloud/host/dao/HostDaoImpl.java +++ b/server/src/com/cloud/host/dao/HostDaoImpl.java @@ -91,7 +91,7 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao protected final SearchBuilder DirectConnectSearch; protected final SearchBuilder ManagedDirectConnectSearch; - protected final SearchBuilder ManagedConnectSearch; + protected final SearchBuilder ManagedRoutingServersSearch; protected final GenericSearchBuilder HostsInStatusSearch; protected final GenericSearchBuilder CountRoutingByDc; @@ -264,9 +264,10 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao ManagedDirectConnectSearch.and("server", ManagedDirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.NULL); ManagedDirectConnectSearch.done(); - ManagedConnectSearch = createSearchBuilder(); - ManagedConnectSearch.and("server", ManagedConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.NNULL); - ManagedConnectSearch.done(); + ManagedRoutingServersSearch = createSearchBuilder(); + ManagedRoutingServersSearch.and("server", ManagedRoutingServersSearch.entity().getManagementServerId(), SearchCriteria.Op.NNULL); + ManagedRoutingServersSearch.and("type", ManagedRoutingServersSearch.entity().getType(), SearchCriteria.Op.EQ); + ManagedRoutingServersSearch.done(); _statusAttr = _allAttributes.get("status"); _msIdAttr = _allAttributes.get("managementServerId"); @@ -868,8 +869,9 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao } @Override - public List listManagedAgents() { - SearchCriteria sc = ManagedConnectSearch.create(); + public List listManagedRoutingAgents() { + SearchCriteria sc = ManagedRoutingServersSearch.create(); + sc.setParameters("type", Type.Routing); return listBy(sc); }