From a0ce3da1913e580d767a0942de347b8cedf7a3f4 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Sun, 5 Jun 2011 13:51:22 -0700 Subject: [PATCH] fixed problem with header --- .../com/cloud/agent/transport/Request.java | 15 +++++--- .../cloud/agent/transport/RequestTest.java | 13 ++++--- .../agent/manager/DirectAgentAttache.java | 2 +- .../src/com/cloud/server/StatsCollector.java | 38 +++++++++++-------- 4 files changed, 41 insertions(+), 27 deletions(-) diff --git a/core/src/com/cloud/agent/transport/Request.java b/core/src/com/cloud/agent/transport/Request.java index 455f32db19d..afbb8b44b9d 100755 --- a/core/src/com/cloud/agent/transport/Request.java +++ b/core/src/com/cloud/agent/transport/Request.java @@ -324,7 +324,7 @@ public class Request { assert false : "More gson errors on " + buff.toString(); return ""; } - if (content.length() <= 4) { + if (content.length() <= (1 + _cmds.length * 3)) { return null; } } else { @@ -368,7 +368,7 @@ public class Request { final ByteBuffer buff = ByteBuffer.wrap(bytes); final byte ver = buff.get(); final Version version = Version.get(ver); - if (version.ordinal() != Version.v1.ordinal()) { + if (version.ordinal() != Version.v1.ordinal() && version.ordinal() != Version.v3.ordinal()) { throw new UnsupportedVersionException("This version is no longer supported: " + version.toString(), UnsupportedVersionException.IncompatibleVersion); } final byte reserved = buff.get(); // tossed away for now. @@ -379,7 +379,12 @@ public class Request { final int size = buff.getInt(); final long mgmtId = buff.getLong(); final long agentId = buff.getLong(); - final long via = buff.getLong(); + long via; + if (version.ordinal() == Version.v1.ordinal()) { + via = buff.getLong(); + } else { + via = agentId; + } byte[] command = null; int offset = 0; @@ -426,11 +431,11 @@ public class Request { } public static long getAgentId(final byte[] bytes) { - return NumbersUtil.bytesToLong(bytes, 28); + return NumbersUtil.bytesToLong(bytes, 24); } public static long getViaAgentId(final byte[] bytes) { - return NumbersUtil.bytesToLong(bytes, 24); + return NumbersUtil.bytesToLong(bytes, 32); } public static boolean fromServer(final byte[] bytes) { diff --git a/core/test/com/cloud/agent/transport/RequestTest.java b/core/test/com/cloud/agent/transport/RequestTest.java index 0198444fbff..683b2b506be 100644 --- a/core/test/com/cloud/agent/transport/RequestTest.java +++ b/core/test/com/cloud/agent/transport/RequestTest.java @@ -75,16 +75,17 @@ public class RequestTest extends TestCase { assert (!log.contains("password")); logger.setLevel(Level.INFO); - sreq.log("Info", true, Level.INFO); - assert (log.contains(UpdateHostPasswordCommand.class.getSimpleName())); - assert (log.contains(SecStorageFirewallCfgCommand.class.getSimpleName())); - assert (!log.contains(GetHostStatsCommand.class.getSimpleName())); - assert (!log.contains("username")); - assert (!log.contains("password")); + log = sreq.log("Info", true, Level.INFO); + assert (log == null); logger.setLevel(level); byte[] bytes = sreq.getBytes(); + + assert Request.getSequence(bytes) == 1; + assert Request.getManagementServerId(bytes) == 3; + assert Request.getAgentId(bytes) == 2; + assert Request.getViaAgentId(bytes) == 2; Request creq = null; try { creq = Request.parse(bytes); diff --git a/server/src/com/cloud/agent/manager/DirectAgentAttache.java b/server/src/com/cloud/agent/manager/DirectAgentAttache.java index c36a3c77942..bfc02f9bbf6 100644 --- a/server/src/com/cloud/agent/manager/DirectAgentAttache.java +++ b/server/src/com/cloud/agent/manager/DirectAgentAttache.java @@ -44,7 +44,7 @@ public class DirectAgentAttache extends AgentAttache { private final static Logger s_logger = Logger.getLogger(DirectAgentAttache.class); ServerResource _resource; - static ScheduledExecutorService s_executor = new ScheduledThreadPoolExecutor(100, new NamedThreadFactory("DirectAgent")); + static ScheduledExecutorService s_executor = new ScheduledThreadPoolExecutor(500, new NamedThreadFactory("DirectAgent")); List> _futures = new ArrayList>(); AgentManagerImpl _mgr; long _seq = 0; diff --git a/server/src/com/cloud/server/StatsCollector.java b/server/src/com/cloud/server/StatsCollector.java index e52205867f3..c0d4bca5f54 100755 --- a/server/src/com/cloud/server/StatsCollector.java +++ b/server/src/com/cloud/server/StatsCollector.java @@ -128,10 +128,18 @@ public class StatsCollector { hostAndVmStatsInterval = NumbersUtil.parseLong(configs.get("vm.stats.interval"), 60000L); storageStatsInterval = NumbersUtil.parseLong(configs.get("storage.stats.interval"), 60000L); volumeStatsInterval = NumbersUtil.parseLong(configs.get("volume.stats.interval"), -1L); - - _executor.scheduleWithFixedDelay(new HostCollector(), 15000L, hostStatsInterval, TimeUnit.MILLISECONDS); - _executor.scheduleWithFixedDelay(new VmStatsCollector(), 15000L, hostAndVmStatsInterval, TimeUnit.MILLISECONDS); - _executor.scheduleWithFixedDelay(new StorageCollector(), 15000L, storageStatsInterval, TimeUnit.MILLISECONDS); + + if (hostStatsInterval > 0) { + _executor.scheduleWithFixedDelay(new HostCollector(), 15000L, hostStatsInterval, TimeUnit.MILLISECONDS); + } + + if (hostAndVmStatsInterval > 0) { + _executor.scheduleWithFixedDelay(new VmStatsCollector(), 15000L, hostAndVmStatsInterval, TimeUnit.MILLISECONDS); + } + + if (storageStatsInterval > 0) { + _executor.scheduleWithFixedDelay(new StorageCollector(), 15000L, storageStatsInterval, TimeUnit.MILLISECONDS); + } // -1 means we don't even start this thread to pick up any data. if (volumeStatsInterval > 0) { @@ -199,7 +207,7 @@ public class StatsCollector { vmIds.add(vm.getId()); } - try + try { HashMap vmStatsById = _userVmMgr.getVirtualMachineStatistics(host.getId(), host.getName(), vmIds); @@ -250,7 +258,7 @@ public class StatsCollector { class StorageCollector implements Runnable { @Override public void run() { - try { + try { List hosts = _hostDao.listSecondaryStorageHosts(); ConcurrentHashMap storageStats = new ConcurrentHashMap(); for (HostVO host : hosts) { @@ -260,13 +268,13 @@ public class StatsCollector { if (answer != null && answer.getResult()) { storageStats.put(hostId, (StorageStats)answer); //Seems like we have dynamically updated the sec. storage as prev. size and the current do not match - if (_storageStats.get(hostId)!=null && - _storageStats.get(hostId).getCapacityBytes() != ((StorageStats)answer).getCapacityBytes()){ + if (_storageStats.get(hostId)!=null && + _storageStats.get(hostId).getCapacityBytes() != ((StorageStats)answer).getCapacityBytes()){ host.setTotalSize(((StorageStats)answer).getCapacityBytes()); _hostDao.update(hostId, host); - } + } } - } + } _storageStats = storageStats; ConcurrentHashMap storagePoolStats = new ConcurrentHashMap(); @@ -279,11 +287,11 @@ public class StatsCollector { if (answer != null && answer.getResult()) { storagePoolStats.put(pool.getId(), (StorageStats)answer); - // Seems like we have dynamically updated the pool size since the prev. size and the current do not match + // Seems like we have dynamically updated the pool size since the prev. size and the current do not match if (_storagePoolStats.get(poolId)!= null && - _storagePoolStats.get(poolId).getCapacityBytes() != ((StorageStats)answer).getCapacityBytes()){ - pool.setCapacityBytes(((StorageStats)answer).getCapacityBytes()); - _storagePoolDao.update(pool.getId(), pool); + _storagePoolStats.get(poolId).getCapacityBytes() != ((StorageStats)answer).getCapacityBytes()){ + pool.setCapacityBytes(((StorageStats)answer).getCapacityBytes()); + _storagePoolDao.update(pool.getId(), pool); } } } catch (StorageUnavailableException e) { @@ -291,7 +299,7 @@ public class StatsCollector { } catch (Exception e) { s_logger.warn("Unable to get stats for " + pool); } - } + } _storagePoolStats = storagePoolStats; } catch (Throwable t) { s_logger.error("Error trying to retrieve storage stats", t);