Bug 11522 - New agent manager

move updatePassword to ResourceManager
This commit is contained in:
frank 2011-09-23 15:48:06 -07:00
parent 98900717dd
commit 95dbf2ac73
5 changed files with 53 additions and 72 deletions

View File

@ -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);

View File

@ -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<HostVO> 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;
}

View File

@ -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<HostVO> 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) };

View File

@ -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<? extends Cluster> discoverCluster(AddClusterCmd cmd) throws IllegalArgumentException, DiscoveryException {
Long dcId = cmd.getZoneId();
@ -1694,4 +1694,52 @@ 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<HostVO> 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;
}
}
}

View File

@ -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