From 542e3d6f536b4e2a9f6173015fa935a70798c2be Mon Sep 17 00:00:00 2001 From: Abhinandan Prateek Date: Mon, 16 May 2011 15:57:35 +0530 Subject: [PATCH] bug 6451: host username/password should be changable through API Propogate update password to other managment server nodes in a cluster. --- api/src/com/cloud/host/Status.java | 3 ++- .../cloud/agent/manager/AgentManagerImpl.java | 16 ++++++++++++- .../manager/ClusteredAgentManagerImpl.java | 24 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/api/src/com/cloud/host/Status.java b/api/src/com/cloud/host/Status.java index e33ddad3532..9c68eb5f731 100644 --- a/api/src/com/cloud/host/Status.java +++ b/api/src/com/cloud/host/Status.java @@ -72,7 +72,8 @@ public enum Status { 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"); + Ready(false, "Host is ready for commands"), + UpdatePassword(false, "Update host password from db"); private final boolean isUserRequest; private final String comment; diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/server/src/com/cloud/agent/manager/AgentManagerImpl.java index 46bf16166d6..11bc29358a8 100755 --- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java @@ -77,6 +77,7 @@ import com.cloud.agent.manager.allocator.PodAllocator; import com.cloud.agent.transport.Request; import com.cloud.agent.transport.Response; import com.cloud.alert.AlertManager; +import com.cloud.api.ApiConstants; import com.cloud.api.commands.AddClusterCmd; import com.cloud.api.commands.AddHostCmd; import com.cloud.api.commands.AddSecondaryStorageCmd; @@ -208,6 +209,8 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS @Inject protected HostDao _hostDao = null; @Inject + protected DetailsDao _detailsDao = null; + @Inject protected DataCenterDao _dcDao = null; @Inject protected DataCenterIpAddressDao _privateIPAddressDao = null; @@ -1227,7 +1230,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS agent.updatePassword(cmd); } } - return false; + return true; } @DB @@ -2096,6 +2099,17 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS } else if (event == Event.ShutdownRequested) { return reconnect(hostId); } + else if (event == Event.UpdatePassword) { + AgentAttache attache = findAttache(hostId); + 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); + if (attache != null) { + attache.updatePassword(cmd); + } + } return false; } diff --git a/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java b/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java index 1ac5df77977..5402bfc5431 100644 --- a/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java @@ -26,9 +26,11 @@ import com.cloud.agent.AgentManager; import com.cloud.agent.api.CancelCommand; import com.cloud.agent.api.ChangeAgentCommand; import com.cloud.agent.api.Command; +import com.cloud.agent.api.UpdateHostPasswordCommand; import com.cloud.agent.transport.Request; import com.cloud.agent.transport.Request.Version; import com.cloud.agent.transport.Response; +import com.cloud.api.commands.UpdateHostPasswordCmd; import com.cloud.cluster.ClusterManager; import com.cloud.cluster.ClusterManagerListener; import com.cloud.cluster.ManagementServerHostVO; @@ -318,6 +320,28 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust return super.deleteHost(hostId, isForced, caller); } + + @Override + public boolean updateHostPassword(UpdateHostPasswordCmd upasscmd) { + if (upasscmd.getClusterId() == null) { + //update agent attache password + try { + Boolean result = _clusterMgr.propagateAgentEvent(upasscmd.getHostId(), Event.UpdatePassword); + } 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); + } catch (AgentUnavailableException e) { + } + } + } + return super.updateHostPassword(upasscmd); + } public void notifyNodesInCluster(AgentAttache attache) { s_logger.debug("Notifying other nodes of to disconnect");