mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Store agent hostname in attache, print it in logs wherever possible. This
was discussed on the mailing list as a useful debugging tool, currently the log prints the DB id of the agent, which makes admins have to look it up to know where the Command was run.
This commit is contained in:
parent
29d9228140
commit
4e0e7410e9
@ -108,6 +108,7 @@ public class Request {
|
||||
protected long _agentId;
|
||||
protected Command[] _cmds;
|
||||
protected String _content;
|
||||
protected String _agentName;
|
||||
|
||||
protected Request() {
|
||||
}
|
||||
@ -142,6 +143,11 @@ public class Request {
|
||||
setFromServer(fromServer);
|
||||
}
|
||||
|
||||
public Request(long agentId, String agentName, long mgmtId, Command[] cmds, boolean stopOnError, boolean fromServer) {
|
||||
this(agentId, mgmtId, cmds, stopOnError, fromServer);
|
||||
setAgentName(agentName);
|
||||
}
|
||||
|
||||
public void setSequence(long seq) {
|
||||
_seq = seq;
|
||||
}
|
||||
@ -174,6 +180,10 @@ public class Request {
|
||||
_flags |= (stopOnError ? FLAG_STOP_ON_ERROR : 0);
|
||||
}
|
||||
|
||||
private final void setAgentName(String agentName) {
|
||||
_agentName = agentName;
|
||||
}
|
||||
|
||||
private final void setInSequence(boolean inSequence) {
|
||||
_flags |= (inSequence ? FLAG_IN_SEQUENCE : 0);
|
||||
}
|
||||
@ -422,7 +432,11 @@ public class Request {
|
||||
|
||||
buf.append(msg);
|
||||
buf.append(" { ").append(getType());
|
||||
buf.append(", MgmtId: ").append(_mgmtId).append(", via: ").append(_via);
|
||||
if (_agentName != null) {
|
||||
buf.append(", MgmtId: ").append(_mgmtId).append(", via: ").append(_via).append("(" + _agentName + ")");
|
||||
} else {
|
||||
buf.append(", MgmtId: ").append(_mgmtId).append(", via: ").append(_via);
|
||||
}
|
||||
buf.append(", Ver: ").append(_ver.toString());
|
||||
buf.append(", Flags: ").append(Integer.toBinaryString(getFlags())).append(", ");
|
||||
buf.append(content);
|
||||
|
||||
@ -101,6 +101,7 @@ public abstract class AgentAttache {
|
||||
};
|
||||
|
||||
protected final long _id;
|
||||
protected String _name = null;
|
||||
protected final ConcurrentHashMap<Long, Listener> _waitForList;
|
||||
protected final LinkedList<Request> _requests;
|
||||
protected Long _currentSequence;
|
||||
@ -121,9 +122,9 @@ public abstract class AgentAttache {
|
||||
Arrays.sort(s_commandsNotAllowedInConnectingMode);
|
||||
}
|
||||
|
||||
|
||||
protected AgentAttache(AgentManagerImpl agentMgr, final long id, boolean maintenance) {
|
||||
protected AgentAttache(AgentManagerImpl agentMgr, final long id, final String name, boolean maintenance) {
|
||||
_id = id;
|
||||
_name = name;
|
||||
_waitForList = new ConcurrentHashMap<Long, Listener>();
|
||||
_currentSequence = null;
|
||||
_maintenance = maintenance;
|
||||
@ -164,7 +165,7 @@ public abstract class AgentAttache {
|
||||
if (_maintenance) {
|
||||
for (final Command cmd : cmds) {
|
||||
if (Arrays.binarySearch(s_commandsAllowedInMaintenanceMode, cmd.getClass().toString()) < 0) {
|
||||
throw new AgentUnavailableException("Unable to send " + cmd.getClass().toString() + " because agent is in maintenance mode", _id);
|
||||
throw new AgentUnavailableException("Unable to send " + cmd.getClass().toString() + " because agent " + _name + " is in maintenance mode", _id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -172,7 +173,7 @@ public abstract class AgentAttache {
|
||||
if (_status == Status.Connecting) {
|
||||
for (final Command cmd : cmds) {
|
||||
if (Arrays.binarySearch(s_commandsNotAllowedInConnectingMode, cmd.getClass().toString()) >= 0) {
|
||||
throw new AgentUnavailableException("Unable to send " + cmd.getClass().toString() + " because agent is in connecting mode", _id);
|
||||
throw new AgentUnavailableException("Unable to send " + cmd.getClass().toString() + " because agent " + _name + " is in connecting mode", _id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -242,6 +243,10 @@ public abstract class AgentAttache {
|
||||
return _id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return _name;
|
||||
}
|
||||
|
||||
public int getQueueSize() {
|
||||
return _requests.size();
|
||||
}
|
||||
@ -350,7 +355,7 @@ public abstract class AgentAttache {
|
||||
synchronized(this) {
|
||||
try {
|
||||
if (isClosed()) {
|
||||
throw new AgentUnavailableException("The link to the agent has been closed", _id);
|
||||
throw new AgentUnavailableException("The link to the agent " + _name + " has been closed", _id);
|
||||
}
|
||||
|
||||
if (req.executeInSequence() && _currentSequence != null) {
|
||||
|
||||
@ -384,7 +384,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
|
||||
throw new AgentUnavailableException("agent not logged into this management server", hostId);
|
||||
}
|
||||
|
||||
Request req = new Request(hostId, _nodeId, cmds, commands.stopOnError(), true);
|
||||
Request req = new Request(hostId, agent.getName(), _nodeId, cmds, commands.stopOnError(), true);
|
||||
req.setSequence(agent.getNextSequence());
|
||||
Answer[] answers = agent.send(req, timeout);
|
||||
notifyAnswersToMonitors(hostId, req.getSequence(), answers);
|
||||
@ -437,7 +437,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
|
||||
if (cmds.length == 0) {
|
||||
throw new AgentUnavailableException("Empty command set for agent " + agent.getId(), agent.getId());
|
||||
}
|
||||
Request req = new Request(hostId, _nodeId, cmds, commands.stopOnError(), true);
|
||||
Request req = new Request(hostId, agent.getName(), _nodeId, cmds, commands.stopOnError(), true);
|
||||
req.setSequence(agent.getNextSequence());
|
||||
|
||||
agent.send(req, listener);
|
||||
@ -679,7 +679,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
|
||||
// }
|
||||
|
||||
s_logger.debug("create DirectAgentAttache for " + host.getId());
|
||||
DirectAgentAttache attache = new DirectAgentAttache(this, host.getId(), resource, host.isInMaintenanceStates(), this);
|
||||
DirectAgentAttache attache = new DirectAgentAttache(this, host.getId(), host.getName(), resource, host.isInMaintenanceStates(), this);
|
||||
|
||||
AgentAttache old = null;
|
||||
synchronized (_agents) {
|
||||
@ -969,7 +969,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
|
||||
|
||||
protected AgentAttache createAttacheForConnect(HostVO host, Link link) throws ConnectionException {
|
||||
s_logger.debug("create ConnectedAgentAttache for " + host.getId());
|
||||
AgentAttache attache = new ConnectedAgentAttache(this, host.getId(), link, host.isInMaintenanceStates());
|
||||
AgentAttache attache = new ConnectedAgentAttache(this, host.getId(), host.getName(), link, host.isInMaintenanceStates());
|
||||
link.attach(attache);
|
||||
|
||||
AgentAttache old = null;
|
||||
|
||||
@ -50,14 +50,14 @@ public class ClusteredAgentAttache extends ConnectedAgentAttache implements Rout
|
||||
s_clusteredAgentMgr = agentMgr;
|
||||
}
|
||||
|
||||
public ClusteredAgentAttache(AgentManagerImpl agentMgr, long id) {
|
||||
super(agentMgr, id, null, false);
|
||||
public ClusteredAgentAttache(AgentManagerImpl agentMgr, long id, String name) {
|
||||
super(agentMgr, id, name, null, false);
|
||||
_forward = true;
|
||||
_transferRequests = new LinkedList<Request>();
|
||||
}
|
||||
|
||||
public ClusteredAgentAttache(AgentManagerImpl agentMgr, long id, Link link, boolean maintenance) {
|
||||
super(agentMgr, id, link, maintenance);
|
||||
public ClusteredAgentAttache(AgentManagerImpl agentMgr, long id, String name, Link link, boolean maintenance) {
|
||||
super(agentMgr, id, name, link, maintenance);
|
||||
_forward = link == null;
|
||||
_transferRequests = new LinkedList<Request>();
|
||||
}
|
||||
|
||||
@ -246,7 +246,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
|
||||
|
||||
protected AgentAttache createAttache(long id) {
|
||||
s_logger.debug("create forwarding ClusteredAgentAttache for " + id);
|
||||
final AgentAttache attache = new ClusteredAgentAttache(this, id);
|
||||
HostVO host = _hostDao.findById(id);
|
||||
final AgentAttache attache = new ClusteredAgentAttache(this, id, host.getName());
|
||||
AgentAttache old = null;
|
||||
synchronized (_agents) {
|
||||
old = _agents.get(id);
|
||||
@ -261,7 +262,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
|
||||
@Override
|
||||
protected AgentAttache createAttacheForConnect(HostVO host, Link link) {
|
||||
s_logger.debug("create ClusteredAgentAttache for " + host.getId());
|
||||
final AgentAttache attache = new ClusteredAgentAttache(this, host.getId(), link, host.isInMaintenanceStates());
|
||||
final AgentAttache attache = new ClusteredAgentAttache(this, host.getId(), host.getName(), link, host.isInMaintenanceStates());
|
||||
link.attach(attache);
|
||||
AgentAttache old = null;
|
||||
synchronized (_agents) {
|
||||
@ -280,7 +281,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
|
||||
// return new DummyAttache(this, host.getId(), false);
|
||||
// }
|
||||
s_logger.debug("create ClusteredDirectAgentAttache for " + host.getId());
|
||||
final DirectAgentAttache attache = new ClusteredDirectAgentAttache(this, host.getId(), _nodeId, resource, host.isInMaintenanceStates(), this);
|
||||
final DirectAgentAttache attache = new ClusteredDirectAgentAttache(this, host.getId(), host.getName(), _nodeId, resource, host.isInMaintenanceStates(), this);
|
||||
AgentAttache old = null;
|
||||
synchronized (_agents) {
|
||||
old = _agents.get(host.getId());
|
||||
|
||||
@ -28,8 +28,8 @@ public class ClusteredDirectAgentAttache extends DirectAgentAttache implements R
|
||||
private final ClusteredAgentManagerImpl _mgr;
|
||||
private final long _nodeId;
|
||||
|
||||
public ClusteredDirectAgentAttache(AgentManagerImpl agentMgr, long id, long mgmtId, ServerResource resource, boolean maintenance, ClusteredAgentManagerImpl mgr) {
|
||||
super(agentMgr, id, resource, maintenance, mgr);
|
||||
public ClusteredDirectAgentAttache(AgentManagerImpl agentMgr, long id, String name, long mgmtId, ServerResource resource, boolean maintenance, ClusteredAgentManagerImpl mgr) {
|
||||
super(agentMgr, id, name, resource, maintenance, mgr);
|
||||
_mgr = mgr;
|
||||
_nodeId = mgmtId;
|
||||
}
|
||||
|
||||
@ -33,8 +33,8 @@ public class ConnectedAgentAttache extends AgentAttache {
|
||||
|
||||
protected Link _link;
|
||||
|
||||
public ConnectedAgentAttache(AgentManagerImpl agentMgr, final long id, final Link link, boolean maintenance) {
|
||||
super(agentMgr, id, maintenance);
|
||||
public ConnectedAgentAttache(AgentManagerImpl agentMgr, final long id, final String name, final Link link, boolean maintenance) {
|
||||
super(agentMgr, id, name, maintenance);
|
||||
_link = link;
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ public class ConnectedAgentAttache extends AgentAttache {
|
||||
assert _link == null : "Duh...Says you....Forgot to call disconnect()!";
|
||||
synchronized (this) {
|
||||
if (_link != null) {
|
||||
s_logger.warn("Lost attache " + _id);
|
||||
s_logger.warn("Lost attache " + _id + "(" + _name + ")");
|
||||
disconnect(Status.Alert);
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,8 +44,8 @@ public class DirectAgentAttache extends AgentAttache {
|
||||
AgentManagerImpl _mgr;
|
||||
long _seq = 0;
|
||||
|
||||
public DirectAgentAttache(AgentManagerImpl agentMgr, long id, ServerResource resource, boolean maintenance, AgentManagerImpl mgr) {
|
||||
super(agentMgr, id, maintenance);
|
||||
public DirectAgentAttache(AgentManagerImpl agentMgr, long id, String name, ServerResource resource, boolean maintenance, AgentManagerImpl mgr) {
|
||||
super(agentMgr, id, name, maintenance);
|
||||
_resource = resource;
|
||||
_mgr = mgr;
|
||||
}
|
||||
@ -53,7 +53,7 @@ public class DirectAgentAttache extends AgentAttache {
|
||||
@Override
|
||||
public void disconnect(Status state) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Processing disconnect " + _id);
|
||||
s_logger.debug("Processing disconnect " + _id + "(" + _name + ")");
|
||||
}
|
||||
|
||||
for (ScheduledFuture<?> future : _futures) {
|
||||
@ -119,7 +119,7 @@ public class DirectAgentAttache extends AgentAttache {
|
||||
assert _resource == null : "Come on now....If you're going to dabble in agent code, you better know how to close out our resources. Ever considered why there's a method called disconnect()?";
|
||||
synchronized (this) {
|
||||
if (_resource != null) {
|
||||
s_logger.warn("Lost attache for " + _id);
|
||||
s_logger.warn("Lost attache for " + _id + "(" + _name + ")");
|
||||
disconnect(Status.Alert);
|
||||
}
|
||||
}
|
||||
@ -137,12 +137,12 @@ public class DirectAgentAttache extends AgentAttache {
|
||||
if (resource != null) {
|
||||
PingCommand cmd = resource.getCurrentStatus(_id);
|
||||
if (cmd == null) {
|
||||
s_logger.warn("Unable to get current status on " + _id);
|
||||
s_logger.warn("Unable to get current status on " + _id + "(" + _name + ")");
|
||||
_mgr.disconnectWithInvestigation(DirectAgentAttache.this, Event.AgentDisconnected);
|
||||
return;
|
||||
}
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Ping from " + _id);
|
||||
s_logger.debug("Ping from " + _id + "(" + _name + ")");
|
||||
}
|
||||
long seq = _seq++;
|
||||
|
||||
@ -152,7 +152,7 @@ public class DirectAgentAttache extends AgentAttache {
|
||||
|
||||
_mgr.handleCommands(DirectAgentAttache.this, seq, new Command[]{cmd});
|
||||
} else {
|
||||
s_logger.debug("Unable to send ping because agent is disconnected " + _id);
|
||||
s_logger.debug("Unable to send ping because agent is disconnected " + _id + "(" + _name + ")");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to complete the ping task", e);
|
||||
|
||||
@ -23,8 +23,8 @@ import com.cloud.host.Status;
|
||||
|
||||
public class DummyAttache extends AgentAttache {
|
||||
|
||||
public DummyAttache(AgentManagerImpl agentMgr, long id, boolean maintenance) {
|
||||
super(agentMgr, id, maintenance);
|
||||
public DummyAttache(AgentManagerImpl agentMgr, long id, String name, boolean maintenance) {
|
||||
super(agentMgr, id, name, maintenance);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user