diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/server/src/com/cloud/agent/manager/AgentManagerImpl.java index 62a0103a9ef..7121c12fd21 100755 --- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java @@ -150,6 +150,8 @@ import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.VirtualMachineManager; import com.cloud.vm.dao.VMInstanceDao; +import edu.emory.mathcs.backport.java.util.Collections; + /** * Implementation of the Agent Manager. This class controls the connection to the agents. * @@ -488,16 +490,17 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager { @Override public HostVO getSSAgent(HostVO ssHost) { if( ssHost.getType() == Host.Type.LocalSecondaryStorage ) { - return ssHost; + if( ssHost.getStatus() == Status.Up ) { + return ssHost; + } } else if ( ssHost.getType() == Host.Type.SecondaryStorage) { Long dcId = ssHost.getDataCenterId(); List ssAHosts = _hostDao.listBy(Host.Type.SecondaryStorageVM, dcId); if (ssAHosts == null || ssAHosts.isEmpty() ) { return null; } - int size = ssAHosts.size(); - Random rn = new Random(System.currentTimeMillis()); - return ssAHosts.get(rn.nextInt(size)); + Collections.shuffle(ssAHosts); + return ssAHosts.get(0); } return null; } @@ -520,9 +523,8 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager { if (ssAHosts == null || ssAHosts.isEmpty() ) { return -1; } - int size = ssAHosts.size(); - Random rn = new Random(System.currentTimeMillis()); - HostVO ssAhost = ssAHosts.get(rn.nextInt(size)); + Collections.shuffle(ssAHosts); + HostVO ssAhost = ssAHosts.get(0); try { return send(ssAhost.getId(), new Commands(cmd), listener); } catch (final AgentUnavailableException e) { @@ -535,9 +537,8 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager { if (ssAHosts == null || ssAHosts.isEmpty() ) { return new Answer(cmd, false, "can not find secondary storage VM agent for data center " + dcId); } - int size = ssAHosts.size(); - Random rn = new Random(System.currentTimeMillis()); - HostVO ssAhost = ssAHosts.get(rn.nextInt(size)); + Collections.shuffle(ssAHosts); + HostVO ssAhost = ssAHosts.get(0); return easySend(ssAhost.getId(), cmd); } diff --git a/server/src/com/cloud/storage/download/DownloadListener.java b/server/src/com/cloud/storage/download/DownloadListener.java index f8f7769a7c4..4eef22bb663 100644 --- a/server/src/com/cloud/storage/download/DownloadListener.java +++ b/server/src/com/cloud/storage/download/DownloadListener.java @@ -280,7 +280,7 @@ public class DownloadListener implements Listener { @Override public void processConnect(HostVO agent, StartupCommand cmd) throws ConnectionException { if (cmd instanceof StartupRoutingCommand) { - //downloadMonitor.handleSysTemplateDownload(agent); + downloadMonitor.handleSysTemplateDownload(agent); } else if ( cmd instanceof StartupStorageCommand) { StartupStorageCommand storage = (StartupStorageCommand)cmd; if( storage.getResourceType() == Storage.StorageResourceType.SECONDARY_STORAGE ||