use of org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand in project cloudstack by apache.
the class VmwareManagerImpl method listVsphereStoragePolicyCompatibleStoragePools.
@Override
public List<StoragePool> listVsphereStoragePolicyCompatibleStoragePools(ListVsphereStoragePolicyCompatiblePoolsCmd cmd) {
Long policyId = cmd.getPolicyId();
VsphereStoragePolicyVO storagePolicy = vsphereStoragePolicyDao.findById(policyId);
if (storagePolicy == null) {
throw new CloudRuntimeException("Storage policy with ID = " + policyId + " was not found");
}
long zoneId = storagePolicy.getZoneId();
List<StoragePoolVO> poolsInZone = primaryStorageDao.listByStatusInZone(zoneId, StoragePoolStatus.Up);
List<StoragePool> compatiblePools = new ArrayList<>();
for (StoragePoolVO pool : poolsInZone) {
StorageFilerTO storageFilerTO = new StorageFilerTO(pool);
List<Long> hostIds = storageManager.getUpHostsInPool(pool.getId());
if (CollectionUtils.isNullOrEmpty(hostIds)) {
s_logger.debug("Did not find a suitable host to verify compatibility of the pool " + pool.getName());
continue;
}
Collections.shuffle(hostIds);
CheckDataStoreStoragePolicyComplainceCommand command = new CheckDataStoreStoragePolicyComplainceCommand(storagePolicy.getPolicyId(), storageFilerTO);
long targetHostId = hypervisorGuruManager.getGuruProcessedCommandTargetHost(hostIds.get(0), command);
try {
Answer answer = _agentMgr.send(targetHostId, command);
boolean result = answer != null && answer.getResult();
if (result) {
compatiblePools.add(pool);
}
} catch (AgentUnavailableException | OperationTimedoutException e) {
s_logger.error("Could not verify if storage policy " + storagePolicy.getName() + " is compatible with storage pool " + pool.getName());
}
}
return compatiblePools;
}
use of org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand in project cloudstack by apache.
the class StorageManagerImpl method isStoragePoolCompliantWithStoragePolicy.
@Override
public boolean isStoragePoolCompliantWithStoragePolicy(List<Pair<Volume, DiskProfile>> volumes, StoragePool pool) throws StorageUnavailableException {
if (CollectionUtils.isEmpty(volumes)) {
return false;
}
List<Pair<Volume, Answer>> answers = new ArrayList<Pair<Volume, Answer>>();
for (Pair<Volume, DiskProfile> volumeDiskProfilePair : volumes) {
String storagePolicyId = null;
Volume volume = volumeDiskProfilePair.first();
DiskProfile diskProfile = volumeDiskProfilePair.second();
if (volume.getVolumeType() == Type.ROOT) {
Long vmId = volume.getInstanceId();
if (vmId != null) {
VMInstanceVO vm = _vmInstanceDao.findByIdIncludingRemoved(vmId);
storagePolicyId = _serviceOfferingDetailsDao.getDetail(vm.getServiceOfferingId(), ApiConstants.STORAGE_POLICY);
}
} else {
storagePolicyId = _diskOfferingDetailsDao.getDetail(diskProfile.getDiskOfferingId(), ApiConstants.STORAGE_POLICY);
}
if (StringUtils.isNotEmpty(storagePolicyId)) {
VsphereStoragePolicyVO storagePolicyVO = _vsphereStoragePolicyDao.findById(Long.parseLong(storagePolicyId));
List<Long> hostIds = getUpHostsInPool(pool.getId());
Collections.shuffle(hostIds);
if (hostIds == null || hostIds.isEmpty()) {
throw new StorageUnavailableException("Unable to send command to the pool " + pool.getName() + " due to there is no enabled hosts up in this cluster", pool.getId());
}
try {
StorageFilerTO storageFilerTO = new StorageFilerTO(pool);
CheckDataStoreStoragePolicyComplainceCommand cmd = new CheckDataStoreStoragePolicyComplainceCommand(storagePolicyVO.getPolicyId(), storageFilerTO);
long targetHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(hostIds.get(0), cmd);
Answer answer = _agentMgr.send(targetHostId, cmd);
answers.add(new Pair<>(volume, answer));
} catch (AgentUnavailableException e) {
s_logger.debug("Unable to send storage pool command to " + pool + " via " + hostIds.get(0), e);
throw new StorageUnavailableException("Unable to send command to the pool ", pool.getId());
} catch (OperationTimedoutException e) {
s_logger.debug("Failed to process storage pool command to " + pool + " via " + hostIds.get(0), e);
throw new StorageUnavailableException("Failed to process storage command to the pool ", pool.getId());
}
}
}
// check cummilative result for all volumes
for (Pair<Volume, Answer> answer : answers) {
if (!answer.second().getResult()) {
s_logger.debug(String.format("Storage pool %s is not compliance with storage policy for volume %s", pool.getUuid(), answer.first().getName()));
return false;
}
}
return true;
}
Aggregations