Search in sources :

Example 1 with GetHostStatsCommand

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();
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) CpuStat(com.cloud.utils.linux.CpuStat) MemStat(com.cloud.utils.linux.MemStat) GetHostStatsCommand(com.cloud.legacymodel.communication.command.GetHostStatsCommand) Test(org.junit.Test)

Example 2 with GetHostStatsCommand

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);
}
Also used : Logger(org.slf4j.Logger) GetHostStatsCommand(com.cloud.legacymodel.communication.command.GetHostStatsCommand) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with GetHostStatsCommand

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());
}
Also used : RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CreateAnswer(com.cloud.legacymodel.communication.answer.CreateAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) GetHostStatsCommand(com.cloud.legacymodel.communication.command.GetHostStatsCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with GetHostStatsCommand

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);
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) UpdateHostPasswordCommand(com.cloud.legacymodel.communication.command.UpdateHostPasswordCommand) SecStorageFirewallCfgCommand(com.cloud.legacymodel.communication.command.SecStorageFirewallCfgCommand) Logger(org.slf4j.Logger) GetHostStatsCommand(com.cloud.legacymodel.communication.command.GetHostStatsCommand) UnsupportedVersionException(com.cloud.legacymodel.exceptions.UnsupportedVersionException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with GetHostStatsCommand

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;
}
Also used : UnsupportedAnswer(com.cloud.legacymodel.communication.answer.UnsupportedAnswer) GetHostStatsAnswer(com.cloud.legacymodel.communication.answer.GetHostStatsAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) GetGPUStatsAnswer(com.cloud.legacymodel.communication.answer.GetGPUStatsAnswer) MaintainAnswer(com.cloud.legacymodel.communication.answer.MaintainAnswer) UnsupportedAnswer(com.cloud.legacymodel.communication.answer.UnsupportedAnswer) GetHostStatsAnswer(com.cloud.legacymodel.communication.answer.GetHostStatsAnswer) GetHostStatsCommand(com.cloud.legacymodel.communication.command.GetHostStatsCommand)

Aggregations

GetHostStatsCommand (com.cloud.legacymodel.communication.command.GetHostStatsCommand)5 Answer (com.cloud.legacymodel.communication.answer.Answer)4 Test (org.junit.Test)4 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)2 Ignore (org.junit.Ignore)2 Logger (org.slf4j.Logger)2 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)1 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)1 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)1 GetGPUStatsAnswer (com.cloud.legacymodel.communication.answer.GetGPUStatsAnswer)1 GetHostStatsAnswer (com.cloud.legacymodel.communication.answer.GetHostStatsAnswer)1 MaintainAnswer (com.cloud.legacymodel.communication.answer.MaintainAnswer)1 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)1 UnsupportedAnswer (com.cloud.legacymodel.communication.answer.UnsupportedAnswer)1 SecStorageFirewallCfgCommand (com.cloud.legacymodel.communication.command.SecStorageFirewallCfgCommand)1 UpdateHostPasswordCommand (com.cloud.legacymodel.communication.command.UpdateHostPasswordCommand)1 UnsupportedVersionException (com.cloud.legacymodel.exceptions.UnsupportedVersionException)1 CpuStat (com.cloud.utils.linux.CpuStat)1 MemStat (com.cloud.utils.linux.MemStat)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1