use of com.cloud.legacymodel.communication.command.GetHostStatsCommand in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testGetHostStatsCommand.
@Test
public void testGetHostStatsCommand() {
Mockito.mock(LibvirtUtilitiesHelper.class);
final CpuStat cpuStat = Mockito.mock(CpuStat.class);
final MemStat memStat = Mockito.mock(MemStat.class);
final String uuid = "e8d6b4d0-bc6d-4613-b8bb-cb9e0600f3c6";
final GetHostStatsCommand command = new GetHostStatsCommand(uuid, "summer", 1l);
when(this.libvirtComputingResource.getCpuStat()).thenReturn(cpuStat);
when(this.libvirtComputingResource.getMemStat()).thenReturn(memStat);
when(this.libvirtComputingResource.getNicStats(Matchers.anyString())).thenReturn(new Pair<>(1.0d, 1.0d));
when(cpuStat.getCpuUsedPercent()).thenReturn(0.5d);
when(memStat.getAvailable()).thenReturn(1500.5d);
when(memStat.getTotal()).thenReturn(15000d);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertTrue(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getCpuStat();
verify(this.libvirtComputingResource, times(1)).getMemStat();
verify(cpuStat, times(1)).getCpuUsedPercent();
verify(memStat, times(1)).getAvailable();
verify(memStat, times(1)).getTotal();
}
use of com.cloud.legacymodel.communication.command.GetHostStatsCommand in project cosmic by MissionCriticalCloud.
the class RequestTest method testLogging.
@Test
@Ignore
public void testLogging() {
s_logger.info("Testing Logging");
final GetHostStatsCommand cmd3 = new GetHostStatsCommand("hostguid", "hostname", 101);
final Request sreq = new Request(2, 3, new Command[] { cmd3 }, true, true);
sreq.setSequence(1);
final Logger logger = LoggerFactory.getLogger(GsonHelper.class);
// final Level level = logger.getLevel();
// logger.setLevel(Level.DEBUG);
String log = sreq.log("Debug", true);
assert (log == null);
log = sreq.log("Debug", false);
assert (log != null);
// logger.setLevel(Level.TRACE);
log = sreq.log("Trace", true);
assert (log.contains(GetHostStatsCommand.class.getSimpleName()));
s_logger.debug(log);
// logger.setLevel(level);
}
use of com.cloud.legacymodel.communication.command.GetHostStatsCommand in project cosmic by MissionCriticalCloud.
the class NotAValidCommand method testGetHostStatsCommand.
@Test
public void testGetHostStatsCommand() {
final GetHostStatsCommand statsCommand = new GetHostStatsCommand(null, null, 0);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(statsCommand, this.citrixResourceBase);
assertTrue(answer.getResult());
}
use of com.cloud.legacymodel.communication.command.GetHostStatsCommand in project cosmic by MissionCriticalCloud.
the class RequestTest method testSerDeser.
@Test
@Ignore
public void testSerDeser() {
s_logger.info("Testing serializing and deserializing works as expected");
s_logger.info("UpdateHostPasswordCommand should have two parameters that doesn't show in logging");
final UpdateHostPasswordCommand cmd1 = new UpdateHostPasswordCommand("abc", "def");
s_logger.info("SecStorageFirewallCfgCommand has a context map that shouldn't show up in debug level");
final SecStorageFirewallCfgCommand cmd2 = new SecStorageFirewallCfgCommand();
s_logger.info("GetHostStatsCommand should not show up at all in debug level");
final GetHostStatsCommand cmd3 = new GetHostStatsCommand("hostguid", "hostname", 101);
cmd2.addPortConfig("abc", "24", true, "eth0");
cmd2.addPortConfig("127.0.0.1", "44", false, "eth1");
final Request sreq = new Request(2, 3, new Command[] { cmd1, cmd2, cmd3 }, true, true);
sreq.setSequence(892403717);
final Logger logger = LoggerFactory.getLogger(GsonHelper.class);
// logger.setLevel(Level.DEBUG);
String log = sreq.log("Debug", true);
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"));
// logger.setLevel(Level.TRACE);
log = sreq.log("Trace", true);
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"));
// logger.setLevel(Level.INFO);
log = sreq.log("Info", true);
assert (log == null);
// logger.setLevel(level);
byte[] bytes = sreq.getBytes();
assert Request.getSequence(bytes) == 892403717;
assert Request.getManagementServerId(bytes) == 3;
assert Request.getAgentId(bytes) == 2;
assert Request.getViaAgentId(bytes) == 2;
Request creq = null;
try {
creq = Request.parse(bytes);
} catch (final ClassNotFoundException e) {
s_logger.error("Unable to parse bytes: ", e);
} catch (final UnsupportedVersionException e) {
s_logger.error("Unable to parse bytes: ", e);
}
assert creq != null : "Couldn't get the request back";
compareRequest(creq, sreq);
final Answer ans = new Answer(cmd1, true, "No Problem");
final Response cresp = new Response(creq, ans);
bytes = cresp.getBytes();
Response sresp = null;
try {
sresp = Response.parse(bytes);
} catch (final ClassNotFoundException e) {
s_logger.error("Unable to parse bytes: ", e);
} catch (final UnsupportedVersionException e) {
s_logger.error("Unable to parse bytes: ", e);
}
assert sresp != null : "Couldn't get the response back";
compareRequest(cresp, sresp);
}
use of com.cloud.legacymodel.communication.command.GetHostStatsCommand in project cosmic by MissionCriticalCloud.
the class ResourceManagerImpl method getHostStatistics.
@Override
public HostStats getHostStatistics(final long hostId) {
final Answer answer = this._agentMgr.easySend(hostId, new GetHostStatsCommand(this._hostDao.findById(hostId).getGuid(), this._hostDao.findById(hostId).getName(), hostId));
if (answer != null && answer instanceof UnsupportedAnswer) {
return null;
}
if (answer == null || !answer.getResult()) {
final String msg = "Unable to obtain host " + hostId + " statistics. ";
s_logger.warn(msg);
return null;
} else {
// now construct the result object
if (answer instanceof GetHostStatsAnswer) {
return ((GetHostStatsAnswer) answer).getHostStats();
}
}
return null;
}
Aggregations