Search in sources :

Example 1 with GetGPUStatsCommand

use of com.cloud.agent.api.GetGPUStatsCommand in project cloudstack by apache.

the class ResourceManagerImpl method getGPUStatistics.

@Override
public HashMap<String, HashMap<String, VgpuTypesInfo>> getGPUStatistics(final HostVO host) {
    final Answer answer = _agentMgr.easySend(host.getId(), new GetGPUStatsCommand(host.getGuid(), host.getName()));
    if (answer != null && answer instanceof UnsupportedAnswer) {
        return null;
    }
    if (answer == null || !answer.getResult()) {
        final String msg = "Unable to obtain GPU stats for host " + host.getName();
        s_logger.warn(msg);
        return null;
    } else {
        // now construct the result object
        if (answer instanceof GetGPUStatsAnswer) {
            return ((GetGPUStatsAnswer) answer).getGroupDetails();
        }
    }
    return null;
}
Also used : GetGPUStatsCommand(com.cloud.agent.api.GetGPUStatsCommand) UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) GetGPUStatsAnswer(com.cloud.agent.api.GetGPUStatsAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) Answer(com.cloud.agent.api.Answer) UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) GetGPUStatsAnswer(com.cloud.agent.api.GetGPUStatsAnswer)

Example 2 with GetGPUStatsCommand

use of com.cloud.agent.api.GetGPUStatsCommand in project cloudstack by apache.

the class XenServer620SP1WrapperTest method testGetGPUStatsCommand.

@Test
public void testGetGPUStatsCommand() {
    final String guuid = "246a5b75-05ed-4bbc-a171-2d1fe94a1b0e";
    final Connection conn = Mockito.mock(Connection.class);
    final GetGPUStatsCommand gpuStats = new GetGPUStatsCommand(guuid, "xen");
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(xenServer620SP1Resource.getConnection()).thenReturn(conn);
    try {
        when(xenServer620SP1Resource.getGPUGroupDetails(conn)).thenReturn(new HashMap<String, HashMap<String, VgpuTypesInfo>>());
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    final Answer answer = wrapper.execute(gpuStats, xenServer620SP1Resource);
    verify(xenServer620SP1Resource, times(1)).getConnection();
    try {
        verify(xenServer620SP1Resource, times(1)).getGPUGroupDetails(conn);
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    assertTrue(answer.getResult());
}
Also used : GetGPUStatsCommand(com.cloud.agent.api.GetGPUStatsCommand) Answer(com.cloud.agent.api.Answer) HashMap(java.util.HashMap) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test)

Example 3 with GetGPUStatsCommand

use of com.cloud.agent.api.GetGPUStatsCommand in project cloudstack by apache.

the class XenServer620SP1WrapperTest method testGetGPUStatsCommandFailure.

@Test
public void testGetGPUStatsCommandFailure() {
    final String guuid = "246a5b75-05ed-4bbc-a171-2d1fe94a1b0e";
    final Connection conn = Mockito.mock(Connection.class);
    final GetGPUStatsCommand gpuStats = new GetGPUStatsCommand(guuid, "xen");
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(xenServer620SP1Resource.getConnection()).thenReturn(conn);
    try {
        when(xenServer620SP1Resource.getGPUGroupDetails(conn)).thenThrow(new CloudRuntimeException("Failed!"));
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    final Answer answer = wrapper.execute(gpuStats, xenServer620SP1Resource);
    verify(xenServer620SP1Resource, times(1)).getConnection();
    try {
        verify(xenServer620SP1Resource, times(1)).getGPUGroupDetails(conn);
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    assertFalse(answer.getResult());
}
Also used : GetGPUStatsCommand(com.cloud.agent.api.GetGPUStatsCommand) Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test)

Aggregations

Answer (com.cloud.agent.api.Answer)3 GetGPUStatsCommand (com.cloud.agent.api.GetGPUStatsCommand)3 Connection (com.xensource.xenapi.Connection)2 XenAPIException (com.xensource.xenapi.Types.XenAPIException)2 XmlRpcException (org.apache.xmlrpc.XmlRpcException)2 Test (org.junit.Test)2 GetGPUStatsAnswer (com.cloud.agent.api.GetGPUStatsAnswer)1 GetHostStatsAnswer (com.cloud.agent.api.GetHostStatsAnswer)1 MaintainAnswer (com.cloud.agent.api.MaintainAnswer)1 UnsupportedAnswer (com.cloud.agent.api.UnsupportedAnswer)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 HashMap (java.util.HashMap)1