diff --git a/server/src/com/cloud/agent/AgentManager.java b/server/src/com/cloud/agent/AgentManager.java index a7ed31cdaf7..b48382e352e 100755 --- a/server/src/com/cloud/agent/AgentManager.java +++ b/server/src/com/cloud/agent/AgentManager.java @@ -197,8 +197,6 @@ public interface AgentManager extends Manager { void notifyAnswersToMonitors(long agentId, long seq, Answer[] answers); - boolean updateHostPassword(UpdateHostPasswordCmd upasscmd); - long sendToSecStorage(HostVO ssHost, Command cmd, Listener listener); Answer sendToSecStorage(HostVO ssHost, Command cmd); diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/server/src/com/cloud/agent/manager/AgentManagerImpl.java index eb78679c0f7..c5e098ec70f 100755 --- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java @@ -567,32 +567,6 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager { return null; } - @Override - public boolean updateHostPassword(UpdateHostPasswordCmd upasscmd) { - if (upasscmd.getClusterId() == null) { - //update agent attache password - AgentAttache agent = this.findAttache(upasscmd.getHostId()); - if (!(agent instanceof DirectAgentAttache)) { - return false; - } - UpdateHostPasswordCommand cmd = new UpdateHostPasswordCommand(upasscmd.getUsername(), upasscmd.getPassword()); - agent.updatePassword(cmd); - } - else { - // get agents for the cluster - List hosts = _hostDao.listByCluster(upasscmd.getClusterId()); - for (HostVO h : hosts) { - AgentAttache agent = this.findAttache(h.getId()); - if (!(agent instanceof DirectAgentAttache)) { - continue; - } - UpdateHostPasswordCommand cmd = new UpdateHostPasswordCommand(upasscmd.getUsername(), upasscmd.getPassword()); - agent.updatePassword(cmd); - } - } - return true; - } - protected int getPingInterval() { return _pingInterval; } diff --git a/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java b/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java index c0c8cfe67d8..59b45f95c1e 100755 --- a/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java @@ -311,33 +311,6 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust return super.reconnect(hostId); } - @Override - public boolean updateHostPassword(UpdateHostPasswordCmd upasscmd) { - if (upasscmd.getClusterId() == null) { - // update agent attache password - try { - Boolean result = _clusterMgr.propagateAgentEvent(upasscmd.getHostId(), Event.UpdatePassword); - if (result != null) { - return result; - } - } catch (AgentUnavailableException e) { - } - } else { - // get agents for the cluster - List hosts = _hostDao.listByCluster(upasscmd.getClusterId()); - for (HostVO h : hosts) { - try { - Boolean result = _clusterMgr.propagateAgentEvent(h.getId(), Event.UpdatePassword); - if (result != null) { - return result; - } - } catch (AgentUnavailableException e) { - } - } - } - return super.updateHostPassword(upasscmd); - } - public void notifyNodesInCluster(AgentAttache attache) { s_logger.debug("Notifying other nodes of to disconnect"); Command[] cmds = new Command[] { new ChangeAgentCommand(attache.getId(), Event.AgentDisconnected) }; diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index 77f87474690..696a1f8d235 100755 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -38,8 +38,10 @@ import com.cloud.agent.api.MaintainAnswer; import com.cloud.agent.api.MaintainCommand; import com.cloud.agent.api.StartupCommand; import com.cloud.agent.api.StartupRoutingCommand; +import com.cloud.agent.api.UpdateHostPasswordCommand; import com.cloud.agent.manager.AgentAttache; import com.cloud.agent.transport.Request; +import com.cloud.api.ApiConstants; import com.cloud.api.commands.AddClusterCmd; import com.cloud.api.commands.AddHostCmd; import com.cloud.api.commands.AddSecondaryStorageCmd; @@ -69,6 +71,7 @@ import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.PermissionDeniedException; import com.cloud.ha.HighAvailabilityManager; import com.cloud.ha.HighAvailabilityManager.WorkType; +import com.cloud.host.DetailVO; import com.cloud.host.Host; import com.cloud.host.Host.HostAllocationState; import com.cloud.host.Host.Type; @@ -171,6 +174,8 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma protected StoragePoolDao _storagePoolDao; @Inject protected CapacityDao _capacityDao; + @Inject + protected HostDetailsDao _detailsDao; protected long _nodeId = ManagementServerNode.getManagementServerId(); @@ -275,11 +280,6 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma } - @Override - public boolean updateHostPassword(UpdateHostPasswordCmd cmd) { - return _agentMgr.updateHostPassword(cmd); - } - @Override public List discoverCluster(AddClusterCmd cmd) throws IllegalArgumentException, DiscoveryException { Long dcId = cmd.getZoneId(); @@ -1693,5 +1693,53 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma return doUmanageHost(hostId); } + + private boolean doUpdateHostPassword(long hostId) { + AgentAttache attache = _agentMgr.findAttache(hostId); + if (attache == null) { + return false; + } + + DetailVO nv = _detailsDao.findDetail(hostId, ApiConstants.USERNAME); + String username = nv.getValue(); + nv = _detailsDao.findDetail(hostId, ApiConstants.PASSWORD); + String password = nv.getValue(); + UpdateHostPasswordCommand cmd = new UpdateHostPasswordCommand(username, password); + attache.updatePassword(cmd); + return true; + } + + @Override + public boolean updateHostPassword(UpdateHostPasswordCmd cmd) { + if (cmd.getClusterId() == null) { + // update agent attache password + try { + Boolean result = _clusterMgr.propagateResourceEvent(cmd.getHostId(), ResourceState.Event.UpdatePassword); + if (result != null) { + return result; + } + } catch (AgentUnavailableException e) { + } + + return doUpdateHostPassword(cmd.getHostId()); + } else { + // get agents for the cluster + List hosts = _hostDao.listByCluster(cmd.getClusterId()); + for (HostVO h : hosts) { + try { + /*FIXME: this is a buggy logic, check with alex. Shouldn't return if propagation return non null*/ + Boolean result = _clusterMgr.propagateResourceEvent(h.getId(), ResourceState.Event.UpdatePassword); + if (result != null) { + return result; + } + + doUpdateHostPassword(cmd.getHostId()); + } catch (AgentUnavailableException e) { + } + } + + return true; + } + } } diff --git a/server/test/com/cloud/agent/MockAgentManagerImpl.java b/server/test/com/cloud/agent/MockAgentManagerImpl.java index 4d908ca74e5..877e39cae03 100755 --- a/server/test/com/cloud/agent/MockAgentManagerImpl.java +++ b/server/test/com/cloud/agent/MockAgentManagerImpl.java @@ -189,12 +189,6 @@ public class MockAgentManagerImpl implements AgentManager { } - @Override - public boolean updateHostPassword(UpdateHostPasswordCmd upasscmd) { - // TODO Auto-generated method stub - return false; - } - @Override public long sendToSecStorage(HostVO ssHost, Command cmd, Listener listener) { // TODO Auto-generated method stub @@ -219,12 +213,6 @@ public class MockAgentManagerImpl implements AgentManager { } - @Override - public boolean disconnect(long hostId) { - // TODO Auto-generated method stub - return false; - } - @Override public boolean tapLoadingAgents(Long hostId, TapAgentsAction action) { // TODO Auto-generated method stub