Skip to content

Commit a0ce3da

Browse files
author
Alex Huang
committed
fixed problem with header
1 parent 7cf3126 commit a0ce3da

4 files changed

Lines changed: 41 additions & 27 deletions

File tree

‎core/src/com/cloud/agent/transport/Request.java‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ protected String log(String msg, boolean logContent, Level level) {
324324
assert false : "More gson errors on " + buff.toString();
325325
return "";
326326
}
327-
if (content.length() <= 4) {
327+
if (content.length() <= (1 + _cmds.length * 3)) {
328328
return null;
329329
}
330330
} else {
@@ -368,7 +368,7 @@ public static Request parse(final byte[] bytes) throws ClassNotFoundException, U
368368
final ByteBuffer buff = ByteBuffer.wrap(bytes);
369369
final byte ver = buff.get();
370370
final Version version = Version.get(ver);
371-
if (version.ordinal() != Version.v1.ordinal()) {
371+
if (version.ordinal() != Version.v1.ordinal() && version.ordinal() != Version.v3.ordinal()) {
372372
throw new UnsupportedVersionException("This version is no longer supported: " + version.toString(), UnsupportedVersionException.IncompatibleVersion);
373373
}
374374
final byte reserved = buff.get(); // tossed away for now.
@@ -379,7 +379,12 @@ public static Request parse(final byte[] bytes) throws ClassNotFoundException, U
379379
final int size = buff.getInt();
380380
final long mgmtId = buff.getLong();
381381
final long agentId = buff.getLong();
382-
final long via = buff.getLong();
382+
long via;
383+
if (version.ordinal() == Version.v1.ordinal()) {
384+
via = buff.getLong();
385+
} else {
386+
via = agentId;
387+
}
383388

384389
byte[] command = null;
385390
int offset = 0;
@@ -426,11 +431,11 @@ public static long getManagementServerId(final byte[] bytes) {
426431
}
427432

428433
public static long getAgentId(final byte[] bytes) {
429-
return NumbersUtil.bytesToLong(bytes, 28);
434+
return NumbersUtil.bytesToLong(bytes, 24);
430435
}
431436

432437
public static long getViaAgentId(final byte[] bytes) {
433-
return NumbersUtil.bytesToLong(bytes, 24);
438+
return NumbersUtil.bytesToLong(bytes, 32);
434439
}
435440

436441
public static boolean fromServer(final byte[] bytes) {

‎core/test/com/cloud/agent/transport/RequestTest.java‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,17 @@ public void testSerDeser() {
7575
assert (!log.contains("password"));
7676

7777
logger.setLevel(Level.INFO);
78-
sreq.log("Info", true, Level.INFO);
79-
assert (log.contains(UpdateHostPasswordCommand.class.getSimpleName()));
80-
assert (log.contains(SecStorageFirewallCfgCommand.class.getSimpleName()));
81-
assert (!log.contains(GetHostStatsCommand.class.getSimpleName()));
82-
assert (!log.contains("username"));
83-
assert (!log.contains("password"));
78+
log = sreq.log("Info", true, Level.INFO);
79+
assert (log == null);
8480

8581
logger.setLevel(level);
8682

8783
byte[] bytes = sreq.getBytes();
84+
85+
assert Request.getSequence(bytes) == 1;
86+
assert Request.getManagementServerId(bytes) == 3;
87+
assert Request.getAgentId(bytes) == 2;
88+
assert Request.getViaAgentId(bytes) == 2;
8889
Request creq = null;
8990
try {
9091
creq = Request.parse(bytes);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class DirectAgentAttache extends AgentAttache {
4444
private final static Logger s_logger = Logger.getLogger(DirectAgentAttache.class);
4545

4646
ServerResource _resource;
47-
static ScheduledExecutorService s_executor = new ScheduledThreadPoolExecutor(100, new NamedThreadFactory("DirectAgent"));
47+
static ScheduledExecutorService s_executor = new ScheduledThreadPoolExecutor(500, new NamedThreadFactory("DirectAgent"));
4848
List<ScheduledFuture<?>> _futures = new ArrayList<ScheduledFuture<?>>();
4949
AgentManagerImpl _mgr;
5050
long _seq = 0;

‎server/src/com/cloud/server/StatsCollector.java‎

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,18 @@ private StatsCollector(Map<String, String> configs) {
128128
hostAndVmStatsInterval = NumbersUtil.parseLong(configs.get("vm.stats.interval"), 60000L);
129129
storageStatsInterval = NumbersUtil.parseLong(configs.get("storage.stats.interval"), 60000L);
130130
volumeStatsInterval = NumbersUtil.parseLong(configs.get("volume.stats.interval"), -1L);
131-
132-
_executor.scheduleWithFixedDelay(new HostCollector(), 15000L, hostStatsInterval, TimeUnit.MILLISECONDS);
133-
_executor.scheduleWithFixedDelay(new VmStatsCollector(), 15000L, hostAndVmStatsInterval, TimeUnit.MILLISECONDS);
134-
_executor.scheduleWithFixedDelay(new StorageCollector(), 15000L, storageStatsInterval, TimeUnit.MILLISECONDS);
131+
132+
if (hostStatsInterval > 0) {
133+
_executor.scheduleWithFixedDelay(new HostCollector(), 15000L, hostStatsInterval, TimeUnit.MILLISECONDS);
134+
}
135+
136+
if (hostAndVmStatsInterval > 0) {
137+
_executor.scheduleWithFixedDelay(new VmStatsCollector(), 15000L, hostAndVmStatsInterval, TimeUnit.MILLISECONDS);
138+
}
139+
140+
if (storageStatsInterval > 0) {
141+
_executor.scheduleWithFixedDelay(new StorageCollector(), 15000L, storageStatsInterval, TimeUnit.MILLISECONDS);
142+
}
135143

136144
// -1 means we don't even start this thread to pick up any data.
137145
if (volumeStatsInterval > 0) {
@@ -199,7 +207,7 @@ public void run() {
199207
vmIds.add(vm.getId());
200208
}
201209

202-
try
210+
try
203211
{
204212
HashMap<Long, VmStatsEntry> vmStatsById = _userVmMgr.getVirtualMachineStatistics(host.getId(), host.getName(), vmIds);
205213

@@ -250,7 +258,7 @@ public VmStats getVmStats(long id) {
250258
class StorageCollector implements Runnable {
251259
@Override
252260
public void run() {
253-
try {
261+
try {
254262
List<HostVO> hosts = _hostDao.listSecondaryStorageHosts();
255263
ConcurrentHashMap<Long, StorageStats> storageStats = new ConcurrentHashMap<Long, StorageStats>();
256264
for (HostVO host : hosts) {
@@ -260,13 +268,13 @@ public void run() {
260268
if (answer != null && answer.getResult()) {
261269
storageStats.put(hostId, (StorageStats)answer);
262270
//Seems like we have dynamically updated the sec. storage as prev. size and the current do not match
263-
if (_storageStats.get(hostId)!=null &&
264-
_storageStats.get(hostId).getCapacityBytes() != ((StorageStats)answer).getCapacityBytes()){
271+
if (_storageStats.get(hostId)!=null &&
272+
_storageStats.get(hostId).getCapacityBytes() != ((StorageStats)answer).getCapacityBytes()){
265273
host.setTotalSize(((StorageStats)answer).getCapacityBytes());
266274
_hostDao.update(hostId, host);
267-
}
275+
}
268276
}
269-
}
277+
}
270278
_storageStats = storageStats;
271279
ConcurrentHashMap<Long, StorageStats> storagePoolStats = new ConcurrentHashMap<Long, StorageStats>();
272280

@@ -279,19 +287,19 @@ public void run() {
279287
if (answer != null && answer.getResult()) {
280288
storagePoolStats.put(pool.getId(), (StorageStats)answer);
281289

282-
// Seems like we have dynamically updated the pool size since the prev. size and the current do not match
290+
// Seems like we have dynamically updated the pool size since the prev. size and the current do not match
283291
if (_storagePoolStats.get(poolId)!= null &&
284-
_storagePoolStats.get(poolId).getCapacityBytes() != ((StorageStats)answer).getCapacityBytes()){
285-
pool.setCapacityBytes(((StorageStats)answer).getCapacityBytes());
286-
_storagePoolDao.update(pool.getId(), pool);
292+
_storagePoolStats.get(poolId).getCapacityBytes() != ((StorageStats)answer).getCapacityBytes()){
293+
pool.setCapacityBytes(((StorageStats)answer).getCapacityBytes());
294+
_storagePoolDao.update(pool.getId(), pool);
287295
}
288296
}
289297
} catch (StorageUnavailableException e) {
290298
s_logger.info("Unable to reach " + pool);
291299
} catch (Exception e) {
292300
s_logger.warn("Unable to get stats for " + pool);
293301
}
294-
}
302+
}
295303
_storagePoolStats = storagePoolStats;
296304
} catch (Throwable t) {
297305
s_logger.error("Error trying to retrieve storage stats", t);

0 commit comments

Comments
 (0)