use of com.cloud.agent.api.GetStorageStatsAnswer in project cloudstack by apache.
the class NfsSecondaryStorageResource method execute.
protected GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) {
DataStoreTO store = cmd.getStore();
if (store instanceof S3TO || store instanceof SwiftTO) {
long infinity = Integer.MAX_VALUE;
return new GetStorageStatsAnswer(cmd, infinity, 0L);
}
String rootDir = getRootDir(((NfsTO) store).getUrl(), cmd.getNfsVersion());
final long usedSize = getUsedSize(rootDir);
final long totalSize = getTotalSize(rootDir);
if (usedSize == -1 || totalSize == -1) {
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 StorageManagerImpl method getStoragePoolStats.
private GetStorageStatsAnswer getStoragePoolStats(StoragePool pool, GetStorageStatsCommand cmd) {
GetStorageStatsAnswer answer = null;
DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(pool.getStorageProviderName());
DataStoreDriver storeDriver = storeProvider.getDataStoreDriver();
PrimaryDataStoreDriver primaryStoreDriver = (PrimaryDataStoreDriver) storeDriver;
Pair<Long, Long> storageStats = primaryStoreDriver.getStorageStats(pool);
if (storageStats == null) {
answer = new GetStorageStatsAnswer((GetStorageStatsCommand) cmd, "Failed to get storage stats for pool: " + pool.getId());
} else {
answer = new GetStorageStatsAnswer((GetStorageStatsCommand) cmd, storageStats.first(), storageStats.second());
}
return answer;
}
use of com.cloud.agent.api.GetStorageStatsAnswer in project cosmic by MissionCriticalCloud.
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);
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 cosmic by MissionCriticalCloud.
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);
}
}
use of com.cloud.agent.api.GetStorageStatsAnswer in project cloudstack by apache.
the class VmwareResource method execute.
protected Answer execute(GetStorageStatsCommand cmd) {
try {
VmwareContext context = getServiceContext();
VmwareHypervisorHost hyperHost = getHyperHost(context);
ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getStorageId());
if (morDs != null) {
long capacity = 0;
long free = 0;
if (cmd.getPooltype() == StoragePoolType.DatastoreCluster) {
StoragepodMO datastoreClusterMo = new StoragepodMO(getServiceContext(), morDs);
StoragePodSummary summary = datastoreClusterMo.getDatastoreClusterSummary();
capacity = summary.getCapacity();
free = summary.getFreeSpace();
} else {
DatastoreMO datastoreMo = new DatastoreMO(context, morDs);
DatastoreSummary summary = datastoreMo.getDatastoreSummary();
capacity = summary.getCapacity();
free = summary.getFreeSpace();
}
long used = capacity - free;
s_logger.debug(String.format("Datastore summary info: [storageId: %s, ], localPath: %s, poolType: %s, capacity: %s, free: %s, used: %s].", cmd.getStorageId(), cmd.getLocalPath(), cmd.getPooltype(), toHumanReadableSize(capacity), toHumanReadableSize(free), toHumanReadableSize(used)));
if (capacity <= 0) {
s_logger.warn("Something is wrong with vSphere NFS datastore, rebooting ESX(ESXi) host should help");
}
return new GetStorageStatsAnswer(cmd, capacity, used);
} else {
String msg = String.format("Could not find datastore for GetStorageStatsCommand: [storageId: %s, localPath: %s, poolType: %s].", cmd.getStorageId(), cmd.getLocalPath(), cmd.getPooltype());
s_logger.error(msg);
return new GetStorageStatsAnswer(cmd, msg);
}
} catch (Throwable e) {
if (e instanceof RemoteException) {
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
invalidateServiceContext();
}
String msg = String.format("Unable to execute GetStorageStatsCommand(storageId : [%s], localPath: [%s], poolType: [%s]) due to [%s]", cmd.getStorageId(), cmd.getLocalPath(), cmd.getPooltype(), VmwareHelper.getExceptionMessage(e));
s_logger.error(msg, e);
return new GetStorageStatsAnswer(cmd, msg);
}
}
Aggregations