Skip to content

Commit 2759eef

Browse files
author
Kelven Yang
committed
Add weight to command to help future load management, fix issues found in system vm pooling
1 parent 1e180de commit 2759eef

11 files changed

Lines changed: 44 additions & 25 deletions

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,6 @@ public List<HostVO> discoverHosts(Long dcId, Long podId, Long clusterId, String
230230
boolean isHostNativeHAEnabled(long hostId);
231231

232232
Answer sendTo(Long dcId, HypervisorType type, Command cmd);
233+
234+
void notifyAnswersFromAttache(long agentId, long seq, Answer[] answers);
233235
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import org.apache.log4j.Logger;
3333

34+
import com.cloud.agent.AgentManager;
3435
import com.cloud.agent.Listener;
3536
import com.cloud.agent.api.Answer;
3637
import com.cloud.agent.api.CheckHealthCommand;
@@ -98,6 +99,8 @@ public int compare(Object o1, Object o2) {
9899
protected Status _status = Status.Connecting;
99100
protected boolean _maintenance;
100101

102+
protected AgentManager _agentMgr;
103+
101104
public final static String[] s_commandsAllowedInMaintenanceMode =
102105
new String[] { MaintainCommand.class.toString(), MigrateCommand.class.toString(), StopCommand.class.toString(), CheckVirtualMachineCommand.class.toString(), PingTestCommand.class.toString(), CheckHealthCommand.class.toString(), ReadyCommand.class.toString(), ShutdownCommand.class.toString() };
103106
protected final static String[] s_commandsNotAllowedInConnectingMode =
@@ -108,12 +111,13 @@ public int compare(Object o1, Object o2) {
108111
}
109112

110113

111-
protected AgentAttache(final long id, boolean maintenance) {
114+
protected AgentAttache(AgentManager agentMgr, final long id, boolean maintenance) {
112115
_id = id;
113116
_waitForList = new ConcurrentHashMap<Long, Listener>();
114117
_currentSequence = null;
115118
_maintenance = maintenance;
116119
_requests = new LinkedList<Request>();
120+
_agentMgr = agentMgr;
117121
}
118122

119123
public synchronized void setMaintenanceMode(final boolean value) {
@@ -263,6 +267,8 @@ public boolean processAnswers(final long seq, final Response resp) {
263267
if (resp.executeInSequence()) {
264268
sendNext(seq);
265269
}
270+
271+
_agentMgr.notifyAnswersFromAttache(_id, seq, answers);
266272
return processed;
267273
}
268274

@@ -384,6 +390,8 @@ public Answer[] send(Request req, final int wait) throws AgentUnavailableExcepti
384390
new Response(req, answers).log(_id, "Received after timeout: ");
385391
// s_logger.debug(log(seq, "Received after timeout: " + new Response(req, answers).toString()));
386392
}
393+
394+
_agentMgr.notifyAnswersFromAttache(_id, seq, answers);
387395
return answers;
388396
}
389397

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,12 @@ public void handleCommands(AgentAttache attache, final long sequence,
484484
}
485485
}
486486
}
487+
488+
public void notifyAnswersFromAttache(long agentId, long seq, Answer[] answers) {
489+
for (Pair<Integer, Listener> listener : _cmdMonitors) {
490+
listener.second().processCommands(agentId, seq, answers);
491+
}
492+
}
487493

488494
public AgentAttache findAttache(long hostId) {
489495
return _agents.get(hostId);
@@ -2656,7 +2662,7 @@ public AgentAttache findAgent(long hostId) {
26562662

26572663
protected AgentAttache createAttache(long id, HostVO server, Link link) {
26582664
s_logger.debug("create ConnectedAgentAttache for " + id);
2659-
final AgentAttache attache = new ConnectedAgentAttache(id, link,
2665+
final AgentAttache attache = new ConnectedAgentAttache(this, id, link,
26602666
server.getStatus() == Status.Maintenance
26612667
|| server.getStatus() == Status.ErrorInMaintenance
26622668
|| server.getStatus() == Status.PrepareForMaintenance);
@@ -2676,10 +2682,10 @@ protected AgentAttache createAttache(long id, HostVO server,
26762682
ServerResource resource) {
26772683
if (resource instanceof DummySecondaryStorageResource
26782684
|| resource instanceof KvmDummyResourceBase) {
2679-
return new DummyAttache(id, false);
2685+
return new DummyAttache(this, id, false);
26802686
}
26812687
s_logger.debug("create DirectAgentAttache for " + id);
2682-
final DirectAgentAttache attache = new DirectAgentAttache(id, resource,
2688+
final DirectAgentAttache attache = new DirectAgentAttache(this, id, resource,
26832689
server.getStatus() == Status.Maintenance
26842690
|| server.getStatus() == Status.ErrorInMaintenance
26852691
|| server.getStatus() == Status.PrepareForMaintenance,

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import org.apache.log4j.Logger;
1414

15+
import com.cloud.agent.AgentManager;
1516
import com.cloud.agent.Listener;
1617
import com.cloud.agent.transport.Request;
1718
import com.cloud.exception.AgentUnavailableException;
@@ -28,13 +29,13 @@ static public void initialize(ClusteredAgentManagerImpl agentMgr) {
2829
s_clusteredAgentMgr = agentMgr;
2930
}
3031

31-
public ClusteredAgentAttache(long id) {
32-
super(id, null, false);
32+
public ClusteredAgentAttache(AgentManager agentMgr, long id) {
33+
super(agentMgr, id, null, false);
3334
_forward = true;
3435
}
3536

36-
public ClusteredAgentAttache(long id, Link link, boolean maintenance) {
37-
super(id, link, maintenance);
37+
public ClusteredAgentAttache(AgentManager agentMgr, long id, Link link, boolean maintenance) {
38+
super(agentMgr, id, link, maintenance);
3839
_forward = link == null;
3940
}
4041

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public boolean cancelMaintenance(final long hostId) {
186186

187187
protected AgentAttache createAttache(long id) {
188188
s_logger.debug("create forwarding ClusteredAgentAttache for " + id);
189-
final AgentAttache attache = new ClusteredAgentAttache(id);
189+
final AgentAttache attache = new ClusteredAgentAttache(this, id);
190190
AgentAttache old = null;
191191
synchronized(_agents) {
192192
old = _agents.get(id);
@@ -201,7 +201,7 @@ protected AgentAttache createAttache(long id) {
201201
@Override
202202
protected AgentAttache createAttache(long id, HostVO server, Link link) {
203203
s_logger.debug("create ClusteredAgentAttache for " + id);
204-
final AgentAttache attache = new ClusteredAgentAttache(id, link, server.getStatus() == Status.Maintenance || server.getStatus() == Status.ErrorInMaintenance || server.getStatus() == Status.PrepareForMaintenance);
204+
final AgentAttache attache = new ClusteredAgentAttache(this, id, link, server.getStatus() == Status.Maintenance || server.getStatus() == Status.ErrorInMaintenance || server.getStatus() == Status.PrepareForMaintenance);
205205
link.attach(attache);
206206
AgentAttache old = null;
207207
synchronized(_agents) {
@@ -217,10 +217,10 @@ protected AgentAttache createAttache(long id, HostVO server, Link link) {
217217
@Override
218218
protected AgentAttache createAttache(long id, HostVO server, ServerResource resource) {
219219
if (resource instanceof DummySecondaryStorageResource) {
220-
return new DummyAttache(id, false);
220+
return new DummyAttache(this, id, false);
221221
}
222222
s_logger.debug("create ClusteredDirectAgentAttache for " + id);
223-
final DirectAgentAttache attache = new ClusteredDirectAgentAttache(id, _nodeId, resource, server.getStatus() == Status.Maintenance
223+
final DirectAgentAttache attache = new ClusteredDirectAgentAttache(this, id, _nodeId, resource, server.getStatus() == Status.Maintenance
224224
|| server.getStatus() == Status.ErrorInMaintenance || server.getStatus() == Status.PrepareForMaintenance, this);
225225
AgentAttache old = null;
226226
synchronized (_agents) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
package com.cloud.agent.manager;
1919

20-
import com.cloud.agent.manager.DirectAgentAttache;
20+
import com.cloud.agent.AgentManager;
2121
import com.cloud.agent.transport.Request;
2222
import com.cloud.agent.transport.Response;
2323
import com.cloud.exception.AgentUnavailableException;
@@ -29,8 +29,8 @@ public class ClusteredDirectAgentAttache extends DirectAgentAttache implements R
2929
private final ClusteredAgentManagerImpl _mgr;
3030
private final long _nodeId;
3131

32-
public ClusteredDirectAgentAttache(long id, long mgmtId, ServerResource resource, boolean maintenance, ClusteredAgentManagerImpl mgr) {
33-
super(id, resource, maintenance, mgr);
32+
public ClusteredDirectAgentAttache(AgentManager agentMgr, long id, long mgmtId, ServerResource resource, boolean maintenance, ClusteredAgentManagerImpl mgr) {
33+
super(agentMgr, id, resource, maintenance, mgr);
3434
_mgr = mgr;
3535
_nodeId = mgmtId;
3636
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.apache.log4j.Logger;
2424

25+
import com.cloud.agent.AgentManager;
2526
import com.cloud.agent.transport.Request;
2627
import com.cloud.exception.AgentUnavailableException;
2728
import com.cloud.host.Status;
@@ -35,8 +36,8 @@ public class ConnectedAgentAttache extends AgentAttache {
3536

3637
protected Link _link;
3738

38-
public ConnectedAgentAttache(final long id, final Link link, boolean maintenance) {
39-
super(id, maintenance);
39+
public ConnectedAgentAttache(AgentManager agentMgr, final long id, final Link link, boolean maintenance) {
40+
super(agentMgr, id, maintenance);
4041
_link = link;
4142
}
4243

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import org.apache.log4j.Logger;
2828

29+
import com.cloud.agent.AgentManager;
2930
import com.cloud.agent.api.Answer;
3031
import com.cloud.agent.api.Command;
3132
import com.cloud.agent.api.CronCommand;
@@ -48,8 +49,8 @@ public class DirectAgentAttache extends AgentAttache {
4849
AgentManagerImpl _mgr;
4950
long _seq = 0;
5051

51-
public DirectAgentAttache(long id, ServerResource resource, boolean maintenance, AgentManagerImpl mgr) {
52-
super(id, maintenance);
52+
public DirectAgentAttache(AgentManager agentMgr, long id, ServerResource resource, boolean maintenance, AgentManagerImpl mgr) {
53+
super(agentMgr, id, maintenance);
5354
_resource = resource;
5455
_mgr = mgr;
5556
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717
*/
1818
package com.cloud.agent.manager;
1919

20+
import com.cloud.agent.AgentManager;
2021
import com.cloud.agent.transport.Request;
2122
import com.cloud.exception.AgentUnavailableException;
2223
import com.cloud.host.Status;
2324

2425

2526
public class DummyAttache extends AgentAttache {
2627

27-
public DummyAttache(long id, boolean maintenance) {
28-
super(id, maintenance);
28+
public DummyAttache(AgentManager agentMgr, long id, boolean maintenance) {
29+
super(agentMgr, id, maintenance);
2930
}
3031

3132

‎server/src/com/cloud/vm/dao/SecondaryStorageVmDaoImpl.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,9 @@ public List<Long> listRunningSecStorageOrderByLoad(SecondaryStorageVm.Role role,
216216
try {
217217
String sql;
218218
if(role == null)
219-
sql = "SELECT s.id, count(l.id) as count FROM secondary_storage_vm s, vm_instance v, cmd_exec_log l " +
220-
"WHERE s.id=v.id AND v.state='Running' AND v.data_center_id=? AND v.id=l.instance_id GROUP BY s.id ORDER BY count";
219+
sql = "SELECT s.id, count(l.id) as count FROM secondary_storage_vm s INNER JOIN vm_instance v ON s.id=v.id LEFT JOIN cmd_exec_log l ON s.id=l.instance_id WHERE v.state='Running' AND v.data_center_id=? GROUP BY s.id ORDER BY count";
221220
else
222-
sql = "SELECT s.id, count(l.id) as count FROM secondary_storage_vm s, vm_instance v, cmd_exec_log l " +
223-
"WHERE s.id=v.id AND v.state='Running' AND v.data_center_id=? AND s.role=? AND v.id=l.instance_id GROUP BY s.id ORDER BY count";
221+
sql = "SELECT s.id, count(l.id) as count FROM secondary_storage_vm s INNER JOIN vm_instance v ON s.id=v.id LEFT JOIN cmd_exec_log l ON s.id=l.instance_id WHERE v.state='Running' AND v.data_center_id=? AND s.role=? GROUP BY s.id ORDER BY count";
224222

225223
pstmt = txn.prepareAutoCloseStatement(sql);
226224

0 commit comments

Comments
 (0)