|
38 | 38 | import com.cloud.agent.api.MaintainCommand; |
39 | 39 | import com.cloud.agent.api.StartupCommand; |
40 | 40 | import com.cloud.agent.api.StartupRoutingCommand; |
| 41 | +import com.cloud.agent.api.UpdateHostPasswordCommand; |
41 | 42 | import com.cloud.agent.manager.AgentAttache; |
42 | 43 | import com.cloud.agent.transport.Request; |
| 44 | +import com.cloud.api.ApiConstants; |
43 | 45 | import com.cloud.api.commands.AddClusterCmd; |
44 | 46 | import com.cloud.api.commands.AddHostCmd; |
45 | 47 | import com.cloud.api.commands.AddSecondaryStorageCmd; |
|
69 | 71 | import com.cloud.exception.PermissionDeniedException; |
70 | 72 | import com.cloud.ha.HighAvailabilityManager; |
71 | 73 | import com.cloud.ha.HighAvailabilityManager.WorkType; |
| 74 | +import com.cloud.host.DetailVO; |
72 | 75 | import com.cloud.host.Host; |
73 | 76 | import com.cloud.host.Host.HostAllocationState; |
74 | 77 | import com.cloud.host.Host.Type; |
@@ -171,6 +174,8 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma |
171 | 174 | protected StoragePoolDao _storagePoolDao; |
172 | 175 | @Inject |
173 | 176 | protected CapacityDao _capacityDao; |
| 177 | + @Inject |
| 178 | + protected HostDetailsDao _detailsDao; |
174 | 179 |
|
175 | 180 | protected long _nodeId = ManagementServerNode.getManagementServerId(); |
176 | 181 |
|
@@ -275,11 +280,6 @@ protected void processResourceEvent(Integer event, Object...params) { |
275 | 280 |
|
276 | 281 | } |
277 | 282 |
|
278 | | - @Override |
279 | | - public boolean updateHostPassword(UpdateHostPasswordCmd cmd) { |
280 | | - return _agentMgr.updateHostPassword(cmd); |
281 | | - } |
282 | | - |
283 | 283 | @Override |
284 | 284 | public List<? extends Cluster> discoverCluster(AddClusterCmd cmd) throws IllegalArgumentException, DiscoveryException { |
285 | 285 | Long dcId = cmd.getZoneId(); |
@@ -1693,5 +1693,53 @@ public boolean umanageHost(long hostId) { |
1693 | 1693 |
|
1694 | 1694 | return doUmanageHost(hostId); |
1695 | 1695 | } |
| 1696 | + |
| 1697 | + private boolean doUpdateHostPassword(long hostId) { |
| 1698 | + AgentAttache attache = _agentMgr.findAttache(hostId); |
| 1699 | + if (attache == null) { |
| 1700 | + return false; |
| 1701 | + } |
| 1702 | + |
| 1703 | + DetailVO nv = _detailsDao.findDetail(hostId, ApiConstants.USERNAME); |
| 1704 | + String username = nv.getValue(); |
| 1705 | + nv = _detailsDao.findDetail(hostId, ApiConstants.PASSWORD); |
| 1706 | + String password = nv.getValue(); |
| 1707 | + UpdateHostPasswordCommand cmd = new UpdateHostPasswordCommand(username, password); |
| 1708 | + attache.updatePassword(cmd); |
| 1709 | + return true; |
| 1710 | + } |
| 1711 | + |
| 1712 | + @Override |
| 1713 | + public boolean updateHostPassword(UpdateHostPasswordCmd cmd) { |
| 1714 | + if (cmd.getClusterId() == null) { |
| 1715 | + // update agent attache password |
| 1716 | + try { |
| 1717 | + Boolean result = _clusterMgr.propagateResourceEvent(cmd.getHostId(), ResourceState.Event.UpdatePassword); |
| 1718 | + if (result != null) { |
| 1719 | + return result; |
| 1720 | + } |
| 1721 | + } catch (AgentUnavailableException e) { |
| 1722 | + } |
| 1723 | + |
| 1724 | + return doUpdateHostPassword(cmd.getHostId()); |
| 1725 | + } else { |
| 1726 | + // get agents for the cluster |
| 1727 | + List<HostVO> hosts = _hostDao.listByCluster(cmd.getClusterId()); |
| 1728 | + for (HostVO h : hosts) { |
| 1729 | + try { |
| 1730 | + /*FIXME: this is a buggy logic, check with alex. Shouldn't return if propagation return non null*/ |
| 1731 | + Boolean result = _clusterMgr.propagateResourceEvent(h.getId(), ResourceState.Event.UpdatePassword); |
| 1732 | + if (result != null) { |
| 1733 | + return result; |
| 1734 | + } |
| 1735 | + |
| 1736 | + doUpdateHostPassword(cmd.getHostId()); |
| 1737 | + } catch (AgentUnavailableException e) { |
| 1738 | + } |
| 1739 | + } |
| 1740 | + |
| 1741 | + return true; |
| 1742 | + } |
| 1743 | + } |
1696 | 1744 |
|
1697 | 1745 | } |
0 commit comments