use of com.cloud.agent.api.GetVolumeStatsAnswer in project cloudstack by apache.
the class LibvirtGetVolumeStatsCommandWrapper method execute.
@Override
public Answer execute(final GetVolumeStatsCommand cmd, final LibvirtComputingResource libvirtComputingResource) {
try {
Connect conn = LibvirtConnection.getConnection();
String storeUuid = cmd.getPoolUuid();
StoragePoolType poolType = cmd.getPoolType();
HashMap<String, VolumeStatsEntry> statEntry = new HashMap<String, VolumeStatsEntry>();
for (String volumeUuid : cmd.getVolumeUuids()) {
VolumeStatsEntry volumeStatsEntry = getVolumeStat(libvirtComputingResource, conn, volumeUuid, storeUuid, poolType);
if (volumeStatsEntry == null) {
String msg = "Can't get disk stats as pool or disk details unavailable for volume: " + volumeUuid + " on the storage pool: " + storeUuid;
return new GetVolumeStatsAnswer(cmd, msg, null);
}
statEntry.put(volumeUuid, volumeStatsEntry);
}
return new GetVolumeStatsAnswer(cmd, "", statEntry);
} catch (LibvirtException | CloudRuntimeException e) {
return new GetVolumeStatsAnswer(cmd, "Can't get vm disk stats: " + e.getMessage(), null);
}
}
use of com.cloud.agent.api.GetVolumeStatsAnswer in project cloudstack by apache.
the class StorageManagerImpl method getVolumeStats.
@Override
public Answer getVolumeStats(StoragePool pool, Command cmd) {
DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(pool.getStorageProviderName());
DataStoreDriver storeDriver = storeProvider.getDataStoreDriver();
PrimaryDataStoreDriver primaryStoreDriver = (PrimaryDataStoreDriver) storeDriver;
HashMap<String, VolumeStatsEntry> statEntry = new HashMap<String, VolumeStatsEntry>();
GetVolumeStatsCommand getVolumeStatsCommand = (GetVolumeStatsCommand) cmd;
for (String volumeUuid : getVolumeStatsCommand.getVolumeUuids()) {
Pair<Long, Long> volumeStats = primaryStoreDriver.getVolumeStats(pool, volumeUuid);
if (volumeStats == null) {
return new GetVolumeStatsAnswer(getVolumeStatsCommand, "Failed to get stats for volume: " + volumeUuid, null);
} else {
VolumeStatsEntry volumeStatsEntry = new VolumeStatsEntry(volumeUuid, volumeStats.first(), volumeStats.second());
statEntry.put(volumeUuid, volumeStatsEntry);
}
}
return new GetVolumeStatsAnswer(getVolumeStatsCommand, "", statEntry);
}
use of com.cloud.agent.api.GetVolumeStatsAnswer in project cloudstack by apache.
the class UserVmManagerImpl method getVolumeStatistics.
@Override
public HashMap<String, VolumeStatsEntry> getVolumeStatistics(long clusterId, String poolUuid, StoragePoolType poolType, int timeout) {
List<HostVO> neighbors = _resourceMgr.listHostsInClusterByStatus(clusterId, Status.Up);
StoragePoolVO storagePool = _storagePoolDao.findPoolByUUID(poolUuid);
HashMap<String, VolumeStatsEntry> volumeStatsByUuid = new HashMap<>();
for (HostVO neighbor : neighbors) {
// - zone wide storage for specific hypervisortypes
if ((ScopeType.ZONE.equals(storagePool.getScope()) && storagePool.getHypervisor() != neighbor.getHypervisorType())) {
// skip this neighbour if their hypervisor type is not the same as that of the store
continue;
}
List<String> volumeLocators = getVolumesByHost(neighbor, storagePool);
if (!CollectionUtils.isEmpty(volumeLocators)) {
GetVolumeStatsCommand cmd = new GetVolumeStatsCommand(poolType, poolUuid, volumeLocators);
Answer answer = null;
DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(storagePool.getStorageProviderName());
DataStoreDriver storeDriver = storeProvider.getDataStoreDriver();
if (storeDriver instanceof PrimaryDataStoreDriver && ((PrimaryDataStoreDriver) storeDriver).canProvideVolumeStats()) {
// Get volume stats from the pool directly instead of sending cmd to host
answer = storageManager.getVolumeStats(storagePool, cmd);
} else {
if (timeout > 0) {
cmd.setWait(timeout / 1000);
}
answer = _agentMgr.easySend(neighbor.getId(), cmd);
}
if (answer != null && answer instanceof GetVolumeStatsAnswer) {
GetVolumeStatsAnswer volstats = (GetVolumeStatsAnswer) answer;
if (volstats.getVolumeStats() != null) {
volumeStatsByUuid.putAll(volstats.getVolumeStats());
}
}
}
}
return volumeStatsByUuid.size() > 0 ? volumeStatsByUuid : null;
}
use of com.cloud.agent.api.GetVolumeStatsAnswer in project cloudstack by apache.
the class VmwareResource method execute.
protected GetVolumeStatsAnswer execute(GetVolumeStatsCommand cmd) {
try {
VmwareHypervisorHost srcHyperHost = getHyperHost(getServiceContext());
ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(srcHyperHost, cmd.getPoolUuid());
assert (morDs != null);
DatastoreMO primaryStorageDatastoreMo = new DatastoreMO(getServiceContext(), morDs);
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter();
DatacenterMO dcMo = new DatacenterMO(getServiceContext(), dcMor);
HashMap<String, VolumeStatsEntry> statEntry = new HashMap<String, VolumeStatsEntry>();
for (String chainInfo : cmd.getVolumeUuids()) {
if (chainInfo != null) {
VirtualMachineDiskInfo infoInChain = _gson.fromJson(chainInfo, VirtualMachineDiskInfo.class);
if (infoInChain != null) {
String[] disks = infoInChain.getDiskChain();
if (disks.length > 0) {
for (String diskPath : disks) {
DatastoreFile file = new DatastoreFile(diskPath);
VirtualMachineMO vmMo = dcMo.findVm(file.getDir());
Pair<VirtualDisk, String> vds = vmMo.getDiskDevice(file.getFileName(), true);
long virtualsize = vds.first().getCapacityInKB() * 1024;
long physicalsize = primaryStorageDatastoreMo.fileDiskSize(file.getPath());
if (statEntry.containsKey(chainInfo)) {
VolumeStatsEntry vse = statEntry.get(chainInfo);
if (vse != null) {
vse.setPhysicalSize(vse.getPhysicalSize() + physicalsize);
}
} else {
VolumeStatsEntry vse = new VolumeStatsEntry(chainInfo, physicalsize, virtualsize);
statEntry.put(chainInfo, vse);
}
}
}
}
}
}
s_logger.debug(String.format("Volume Stats Entry is: [%s].", _gson.toJson(statEntry)));
return new GetVolumeStatsAnswer(cmd, "", statEntry);
} catch (Exception e) {
s_logger.error(String.format("VOLSTAT GetVolumeStatsCommand failed due to [%s].", VmwareHelper.getExceptionMessage(e)), e);
}
return new GetVolumeStatsAnswer(cmd, "", null);
}
use of com.cloud.agent.api.GetVolumeStatsAnswer in project cloudstack by apache.
the class CitrixGetVolumeStatsCommandWrapper method execute.
@Override
public Answer execute(final GetVolumeStatsCommand cmd, final CitrixResourceBase citrixResourceBase) {
Connection conn = citrixResourceBase.getConnection();
HashMap<String, VolumeStatsEntry> statEntry = new HashMap<String, VolumeStatsEntry>();
for (String volumeUuid : cmd.getVolumeUuids()) {
VDI vdi = citrixResourceBase.getVDIbyUuid(conn, volumeUuid, false);
if (vdi != null) {
try {
VolumeStatsEntry vse = new VolumeStatsEntry(volumeUuid, vdi.getPhysicalUtilisation(conn), vdi.getVirtualSize(conn));
statEntry.put(volumeUuid, vse);
} catch (Exception e) {
s_logger.warn("Unable to get volume stats", e);
statEntry.put(volumeUuid, new VolumeStatsEntry(volumeUuid, -1, -1));
}
} else {
s_logger.warn("VDI not found for path " + volumeUuid);
statEntry.put(volumeUuid, new VolumeStatsEntry(volumeUuid, -1L, -1L));
}
}
return new GetVolumeStatsAnswer(cmd, "", statEntry);
}
Aggregations