Skip to content

Commit 95dbf2a

Browse files
committed
Bug 11522 - New agent manager
move updatePassword to ResourceManager
1 parent 9890071 commit 95dbf2a

5 files changed

Lines changed: 53 additions & 72 deletions

File tree

‎server/src/com/cloud/agent/AgentManager.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,6 @@ public enum TapAgentsAction {
197197

198198
void notifyAnswersToMonitors(long agentId, long seq, Answer[] answers);
199199

200-
boolean updateHostPassword(UpdateHostPasswordCmd upasscmd);
201-
202200
long sendToSecStorage(HostVO ssHost, Command cmd, Listener listener);
203201

204202
Answer sendToSecStorage(HostVO ssHost, Command cmd);

‎server/src/com/cloud/agent/manager/AgentManagerImpl.java‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -567,32 +567,6 @@ public Answer sendTo(Long dcId, HypervisorType type, Command cmd) {
567567
return null;
568568
}
569569

570-
@Override
571-
public boolean updateHostPassword(UpdateHostPasswordCmd upasscmd) {
572-
if (upasscmd.getClusterId() == null) {
573-
//update agent attache password
574-
AgentAttache agent = this.findAttache(upasscmd.getHostId());
575-
if (!(agent instanceof DirectAgentAttache)) {
576-
return false;
577-
}
578-
UpdateHostPasswordCommand cmd = new UpdateHostPasswordCommand(upasscmd.getUsername(), upasscmd.getPassword());
579-
agent.updatePassword(cmd);
580-
}
581-
else {
582-
// get agents for the cluster
583-
List<HostVO> hosts = _hostDao.listByCluster(upasscmd.getClusterId());
584-
for (HostVO h : hosts) {
585-
AgentAttache agent = this.findAttache(h.getId());
586-
if (!(agent instanceof DirectAgentAttache)) {
587-
continue;
588-
}
589-
UpdateHostPasswordCommand cmd = new UpdateHostPasswordCommand(upasscmd.getUsername(), upasscmd.getPassword());
590-
agent.updatePassword(cmd);
591-
}
592-
}
593-
return true;
594-
}
595-
596570
protected int getPingInterval() {
597571
return _pingInterval;
598572
}

‎server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java‎

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -311,33 +311,6 @@ public boolean reconnect(final long hostId) throws AgentUnavailableException {
311311
return super.reconnect(hostId);
312312
}
313313

314-
@Override
315-
public boolean updateHostPassword(UpdateHostPasswordCmd upasscmd) {
316-
if (upasscmd.getClusterId() == null) {
317-
// update agent attache password
318-
try {
319-
Boolean result = _clusterMgr.propagateAgentEvent(upasscmd.getHostId(), Event.UpdatePassword);
320-
if (result != null) {
321-
return result;
322-
}
323-
} catch (AgentUnavailableException e) {
324-
}
325-
} else {
326-
// get agents for the cluster
327-
List<HostVO> hosts = _hostDao.listByCluster(upasscmd.getClusterId());
328-
for (HostVO h : hosts) {
329-
try {
330-
Boolean result = _clusterMgr.propagateAgentEvent(h.getId(), Event.UpdatePassword);
331-
if (result != null) {
332-
return result;
333-
}
334-
} catch (AgentUnavailableException e) {
335-
}
336-
}
337-
}
338-
return super.updateHostPassword(upasscmd);
339-
}
340-
341314
public void notifyNodesInCluster(AgentAttache attache) {
342315
s_logger.debug("Notifying other nodes of to disconnect");
343316
Command[] cmds = new Command[] { new ChangeAgentCommand(attache.getId(), Event.AgentDisconnected) };

‎server/src/com/cloud/resource/ResourceManagerImpl.java‎

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
import com.cloud.agent.api.MaintainCommand;
3939
import com.cloud.agent.api.StartupCommand;
4040
import com.cloud.agent.api.StartupRoutingCommand;
41+
import com.cloud.agent.api.UpdateHostPasswordCommand;
4142
import com.cloud.agent.manager.AgentAttache;
4243
import com.cloud.agent.transport.Request;
44+
import com.cloud.api.ApiConstants;
4345
import com.cloud.api.commands.AddClusterCmd;
4446
import com.cloud.api.commands.AddHostCmd;
4547
import com.cloud.api.commands.AddSecondaryStorageCmd;
@@ -69,6 +71,7 @@
6971
import com.cloud.exception.PermissionDeniedException;
7072
import com.cloud.ha.HighAvailabilityManager;
7173
import com.cloud.ha.HighAvailabilityManager.WorkType;
74+
import com.cloud.host.DetailVO;
7275
import com.cloud.host.Host;
7376
import com.cloud.host.Host.HostAllocationState;
7477
import com.cloud.host.Host.Type;
@@ -171,6 +174,8 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
171174
protected StoragePoolDao _storagePoolDao;
172175
@Inject
173176
protected CapacityDao _capacityDao;
177+
@Inject
178+
protected HostDetailsDao _detailsDao;
174179

175180
protected long _nodeId = ManagementServerNode.getManagementServerId();
176181

@@ -275,11 +280,6 @@ protected void processResourceEvent(Integer event, Object...params) {
275280

276281
}
277282

278-
@Override
279-
public boolean updateHostPassword(UpdateHostPasswordCmd cmd) {
280-
return _agentMgr.updateHostPassword(cmd);
281-
}
282-
283283
@Override
284284
public List<? extends Cluster> discoverCluster(AddClusterCmd cmd) throws IllegalArgumentException, DiscoveryException {
285285
Long dcId = cmd.getZoneId();
@@ -1693,5 +1693,53 @@ public boolean umanageHost(long hostId) {
16931693

16941694
return doUmanageHost(hostId);
16951695
}
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+
}
16961744

16971745
}

‎server/test/com/cloud/agent/MockAgentManagerImpl.java‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,6 @@ public void notifyAnswersToMonitors(long agentId, long seq, Answer[] answers) {
189189

190190
}
191191

192-
@Override
193-
public boolean updateHostPassword(UpdateHostPasswordCmd upasscmd) {
194-
// TODO Auto-generated method stub
195-
return false;
196-
}
197-
198192
@Override
199193
public long sendToSecStorage(HostVO ssHost, Command cmd, Listener listener) {
200194
// TODO Auto-generated method stub
@@ -219,12 +213,6 @@ public void updateStatus(HostVO host, Event event) {
219213

220214
}
221215

222-
@Override
223-
public boolean disconnect(long hostId) {
224-
// TODO Auto-generated method stub
225-
return false;
226-
}
227-
228216
@Override
229217
public boolean tapLoadingAgents(Long hostId, TapAgentsAction action) {
230218
// TODO Auto-generated method stub

0 commit comments

Comments
 (0)