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);
}
}
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);
}
}
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());
}
}
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());
}
}
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();
}
}
Aggregations