Search in sources :

Example 1 with GetStorageStatsAnswer

use of com.cloud.agent.api.GetStorageStatsAnswer in project CloudStack-archive by CloudStack-extras.

the class MockStorageManagerImpl method GetStorageStats.

@Override
public GetStorageStatsAnswer GetStorageStats(GetStorageStatsCommand cmd) {
    String uuid = cmd.getStorageId();
    if (uuid == null) {
        String secUrl = cmd.getSecUrl();
        MockSecStorageVO secondary = _mockSecStorageDao.findByUrl(secUrl);
        if (secondary == null) {
            return new GetStorageStatsAnswer(cmd, "Can't find the secondary storage:" + secUrl);
        }
        Long totalUsed = _mockVolumeDao.findTotalStorageId(secondary.getId());
        return new GetStorageStatsAnswer(cmd, secondary.getCapacity(), totalUsed);
    } else {
        MockStoragePoolVO pool = _mockStoragePoolDao.findByUuid(uuid);
        if (pool == null) {
            return new GetStorageStatsAnswer(cmd, "Can't find the pool");
        }
        Long totalUsed = _mockVolumeDao.findTotalStorageId(pool.getId());
        if (totalUsed == null) {
            totalUsed = 0L;
        }
        return new GetStorageStatsAnswer(cmd, pool.getCapacity(), totalUsed);
    }
}
Also used : GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO)

Example 2 with GetStorageStatsAnswer

use of com.cloud.agent.api.GetStorageStatsAnswer in project cosmic by MissionCriticalCloud.

the class NfsSecondaryStorageResource method execute.

protected GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) {
    final DataStoreTO store = cmd.getStore();
    final String rootDir = getRootDir(((NfsTO) store).getUrl());
    final long usedSize = getUsedSize(rootDir);
    final long totalSize = getTotalSize(rootDir);
    if ((usedSize == 0 && totalSize == 0) || usedSize < 0 || totalSize < 0) {
        return new GetStorageStatsAnswer(cmd, "Unable to get storage stats");
    } else {
        return new GetStorageStatsAnswer(cmd, totalSize, usedSize);
    }
}
Also used : DataStoreTO(com.cloud.agent.api.to.DataStoreTO) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer)

Example 3 with GetStorageStatsAnswer

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

the class Ovm3StoragePool method execute.

/**
 * Gets statistics for storage.
 *
 * @param cmd
 * @return
 */
public GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) {
    LOGGER.debug("Getting stats for: " + cmd.getStorageId());
    try {
        Linux host = new Linux(c);
        Linux.FileSystem fs = host.getFileSystemByUuid(cmd.getStorageId(), "nfs");
        StoragePlugin store = new StoragePlugin(c);
        String propUuid = store.deDash(cmd.getStorageId());
        String mntUuid = cmd.getStorageId();
        if (store == null || propUuid == null || mntUuid == null || fs == null) {
            String msg = "Null returned when retrieving stats for " + cmd.getStorageId();
            LOGGER.error(msg);
            return new GetStorageStatsAnswer(cmd, msg);
        }
        /* or is it mntUuid ish ? */
        StorageDetails sd = store.storagePluginGetFileSystemInfo(propUuid, mntUuid, fs.getHost(), fs.getDevice());
        /*
             * FIXME: cure me or kill me, this needs to trigger a reinit of
             * primary storage, actually the problem is more deeprooted, as when
             * the hypervisor reboots it looses partial context and needs to be
             * reinitiated.... actually a full configure round... how to trigger
             * that ?
             */
        if ("".equals(sd.getSize())) {
            String msg = "No size when retrieving stats for " + cmd.getStorageId();
            LOGGER.debug(msg);
            return new GetStorageStatsAnswer(cmd, msg);
        }
        long total = Long.parseLong(sd.getSize());
        long used = total - Long.parseLong(sd.getFreeSize());
        return new GetStorageStatsAnswer(cmd, total, used);
    } catch (Ovm3ResourceException e) {
        LOGGER.debug("GetStorageStatsCommand for " + cmd.getStorageId() + " failed", e);
        return new GetStorageStatsAnswer(cmd, e.getMessage());
    }
}
Also used : GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) Linux(com.cloud.hypervisor.ovm3.objects.Linux) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) StorageDetails(com.cloud.hypervisor.ovm3.objects.StoragePlugin.StorageDetails) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin)

Example 4 with GetStorageStatsAnswer

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

the class LibvirtGetStorageStatsCommandWrapper method execute.

@Override
public Answer execute(final GetStorageStatsCommand command, final LibvirtComputingResource libvirtComputingResource) {
    try {
        final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
        final KVMStoragePool sp = storagePoolMgr.getStoragePool(command.getPooltype(), command.getStorageId(), true);
        if (sp == null) {
            return new GetStorageStatsAnswer(command, "no storage pool to get statistics from");
        }
        return new GetStorageStatsAnswer(command, sp.getCapacity(), sp.getUsed());
    } catch (final CloudRuntimeException e) {
        return new GetStorageStatsAnswer(command, e.toString());
    }
}
Also used : KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 5 with GetStorageStatsAnswer

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

the class MockStorageManagerImpl method GetStorageStats.

@Override
public GetStorageStatsAnswer GetStorageStats(GetStorageStatsCommand cmd) {
    String uuid = cmd.getStorageId();
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        if (uuid == null) {
            String secUrl = cmd.getSecUrl();
            MockSecStorageVO secondary = _mockSecStorageDao.findByUrl(secUrl);
            if (secondary == null) {
                return new GetStorageStatsAnswer(cmd, "Can't find the secondary storage:" + secUrl);
            }
            Long totalUsed = _mockVolumeDao.findTotalStorageId(secondary.getId());
            txn.commit();
            return new GetStorageStatsAnswer(cmd, secondary.getCapacity(), totalUsed);
        } else {
            MockStoragePoolVO pool = _mockStoragePoolDao.findByUuid(uuid);
            if (pool == null) {
                return new GetStorageStatsAnswer(cmd, "Can't find the pool");
            }
            Long totalUsed = _mockVolumeDao.findTotalStorageId(pool.getId());
            if (totalUsed == null) {
                totalUsed = 0L;
            }
            txn.commit();
            return new GetStorageStatsAnswer(cmd, pool.getCapacity(), totalUsed);
        }
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("DBException during storage stats collection for pool " + uuid, ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

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