Search in sources :

Example 11 with GetStorageStatsAnswer

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

the class CitrixGetStorageStatsCommandWrapper method execute.

@Override
public Answer execute(final GetStorageStatsCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    try {
        final Set<SR> srs = SR.getByNameLabel(conn, command.getStorageId());
        if (srs.size() != 1) {
            final String msg = "There are " + srs.size() + " storageid: " + command.getStorageId();
            s_logger.warn(msg);
            return new GetStorageStatsAnswer(command, msg);
        }
        final SR sr = srs.iterator().next();
        sr.scan(conn);
        final long capacity = sr.getPhysicalSize(conn);
        final long used = sr.getPhysicalUtilisation(conn);
        return new GetStorageStatsAnswer(command, capacity, used);
    } catch (final XenAPIException e) {
        final String msg = "GetStorageStats Exception:" + e.toString() + "host:" + citrixResourceBase.getHost().getUuid() + "storageid: " + command.getStorageId();
        s_logger.warn(msg);
        return new GetStorageStatsAnswer(command, msg);
    } catch (final XmlRpcException e) {
        final String msg = "GetStorageStats Exception:" + e.getMessage() + "host:" + citrixResourceBase.getHost().getUuid() + "storageid: " + command.getStorageId();
        s_logger.warn(msg);
        return new GetStorageStatsAnswer(command, msg);
    } catch (final Exception e) {
        final String msg = "GetStorageStats Exception:" + e.getMessage() + "host:" + citrixResourceBase.getHost().getUuid() + "storageid: " + command.getStorageId();
        s_logger.warn(msg);
        return new GetStorageStatsAnswer(command, msg);
    }
}
Also used : GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) SR(com.xensource.xenapi.SR)

Example 12 with GetStorageStatsAnswer

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

the class HypervDirectConnectResourceTest method testGetStorageStatsCommand.

@Test
public final void testGetStorageStatsCommand() {
    // TODO: Update sample data to unsure it is using correct info.
    String sample = "{\"id\":\"" + s_testLocalStoreUUID + "\",\"localPath\":" + s_testLocalStorePathJSON + "," + "\"pooltype\":\"Filesystem\"," + "\"contextMap\":{},\"wait\":0}";
    s_logger.info("Sample JSON: " + sample);
    GetStorageStatsCommand cmd = s_gson.fromJson(sample, GetStorageStatsCommand.class);
    s_hypervresource.executeRequest(cmd);
    GetStorageStatsAnswer ans = (GetStorageStatsAnswer) s_hypervresource.executeRequest(cmd);
    Assert.assertTrue(ans.getDetails(), ans.getResult());
    Assert.assertTrue(ans.getByteUsed() != ans.getCapacityBytes());
}
Also used : GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) GetStorageStatsCommand(com.cloud.agent.api.GetStorageStatsCommand) Test(org.junit.Test)

Aggregations

GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)12 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 GetStorageStatsCommand (com.cloud.agent.api.GetStorageStatsCommand)2 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)2 MockSecStorageVO (com.cloud.simulator.MockSecStorageVO)2 MockStoragePoolVO (com.cloud.simulator.MockStoragePoolVO)2 Connection (com.xensource.xenapi.Connection)2 SR (com.xensource.xenapi.SR)2 XenAPIException (com.xensource.xenapi.Types.XenAPIException)2 XmlRpcException (org.apache.xmlrpc.XmlRpcException)2 S3TO (com.cloud.agent.api.to.S3TO)1 SwiftTO (com.cloud.agent.api.to.SwiftTO)1 KVMStoragePool (com.cloud.hypervisor.kvm.storage.KVMStoragePool)1 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)1 KvmStoragePool (com.cloud.hypervisor.kvm.storage.KvmStoragePool)1 KvmStoragePoolManager (com.cloud.hypervisor.kvm.storage.KvmStoragePoolManager)1 Linux (com.cloud.hypervisor.ovm3.objects.Linux)1 Ovm3ResourceException (com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)1 StoragePlugin (com.cloud.hypervisor.ovm3.objects.StoragePlugin)1 StorageDetails (com.cloud.hypervisor.ovm3.objects.StoragePlugin.StorageDetails)1