use of com.cloud.exception.StorageUnavailableException in project cloudstack by apache.
the class DeploymentPlanningManagerImpl method findPotentialDeploymentResources.
protected Pair<Host, Map<Volume, StoragePool>> findPotentialDeploymentResources(List<Host> suitableHosts, Map<Volume, List<StoragePool>> suitableVolumeStoragePools, ExcludeList avoid, PlannerResourceUsage resourceUsageRequired, List<Volume> readyAndReusedVolumes, List<Long> preferredHosts, VirtualMachine vm) {
s_logger.debug("Trying to find a potenial host and associated storage pools from the suitable host/pool lists for this VM");
boolean hostCanAccessPool = false;
boolean haveEnoughSpace = false;
boolean hostAffinityCheck = false;
if (readyAndReusedVolumes == null) {
readyAndReusedVolumes = new ArrayList<Volume>();
}
Map<Volume, StoragePool> storage = new HashMap<Volume, StoragePool>();
TreeSet<Volume> volumesOrderBySizeDesc = new TreeSet<Volume>(new Comparator<Volume>() {
@Override
public int compare(Volume v1, Volume v2) {
if (v1.getSize() < v2.getSize())
return 1;
else
return -1;
}
});
volumesOrderBySizeDesc.addAll(suitableVolumeStoragePools.keySet());
boolean multipleVolume = volumesOrderBySizeDesc.size() > 1;
boolean deployAsIs = isDeployAsIs(vm);
for (Host potentialHost : suitableHosts) {
Map<StoragePool, List<Volume>> volumeAllocationMap = new HashMap<StoragePool, List<Volume>>();
if (deployAsIs) {
storage = new HashMap<>();
// Find the common suitable pools
s_logger.debug("Trying to allocate all the VM volumes to a single storage pool");
Set<StoragePool> suitablePools = new HashSet<>();
List<StoragePool> notAllowedPools = new ArrayList<>();
for (List<StoragePool> pools : suitableVolumeStoragePools.values()) {
if (CollectionUtils.isEmpty(suitablePools)) {
// All the suitable pools of the first volume
suitablePools.addAll(pools);
} else {
for (StoragePool pool : pools) {
if (!suitablePools.contains(pool)) {
s_logger.debug("Storage pool " + pool.getUuid() + " not allowed for this VM");
notAllowedPools.add(pool);
}
}
}
}
suitablePools.removeAll(notAllowedPools);
if (CollectionUtils.isEmpty(suitablePools)) {
s_logger.debug("Could not find a storage pool to fit all the VM volumes on this host");
continue;
}
List<Volume> allVolumes = new ArrayList<>();
allVolumes.addAll(volumesOrderBySizeDesc);
List<Pair<Volume, DiskProfile>> volumeDiskProfilePair = getVolumeDiskProfilePairs(allVolumes);
for (StoragePool storagePool : suitablePools) {
haveEnoughSpace = false;
hostCanAccessPool = false;
hostAffinityCheck = checkAffinity(potentialHost, preferredHosts);
if (hostCanAccessSPool(potentialHost, storagePool)) {
hostCanAccessPool = true;
if (potentialHost.getHypervisorType() == HypervisorType.VMware) {
try {
boolean isStoragePoolStoragepolicyComplaince = _storageMgr.isStoragePoolCompliantWithStoragePolicy(volumeDiskProfilePair, storagePool);
if (!isStoragePoolStoragepolicyComplaince) {
continue;
}
} catch (StorageUnavailableException e) {
s_logger.warn(String.format("Could not verify storage policy complaince against storage pool %s due to exception %s", storagePool.getUuid(), e.getMessage()));
continue;
}
haveEnoughSpace = true;
}
}
if (hostCanAccessPool && haveEnoughSpace && hostAffinityCheck) {
for (Volume vol : volumesOrderBySizeDesc) {
s_logger.debug("Found a suitable storage pool for all the VM volumes: " + storagePool.getUuid());
storage.put(vol, storagePool);
}
break;
}
}
} else {
for (Volume vol : volumesOrderBySizeDesc) {
haveEnoughSpace = false;
s_logger.debug("Checking if host: " + potentialHost.getId() + " can access any suitable storage pool for volume: " + vol.getVolumeType());
List<StoragePool> volumePoolList = suitableVolumeStoragePools.get(vol);
hostCanAccessPool = false;
hostAffinityCheck = checkAffinity(potentialHost, preferredHosts);
for (StoragePool potentialSPool : volumePoolList) {
if (hostCanAccessSPool(potentialHost, potentialSPool)) {
hostCanAccessPool = true;
if (multipleVolume && !readyAndReusedVolumes.contains(vol)) {
List<Volume> requestVolumes = null;
if (volumeAllocationMap.containsKey(potentialSPool))
requestVolumes = volumeAllocationMap.get(potentialSPool);
else
requestVolumes = new ArrayList<Volume>();
requestVolumes.add(vol);
List<Pair<Volume, DiskProfile>> volumeDiskProfilePair = getVolumeDiskProfilePairs(requestVolumes);
if (potentialHost.getHypervisorType() == HypervisorType.VMware) {
try {
boolean isStoragePoolStoragepolicyComplaince = _storageMgr.isStoragePoolCompliantWithStoragePolicy(volumeDiskProfilePair, potentialSPool);
if (!isStoragePoolStoragepolicyComplaince) {
continue;
}
} catch (StorageUnavailableException e) {
s_logger.warn(String.format("Could not verify storage policy complaince against storage pool %s due to exception %s", potentialSPool.getUuid(), e.getMessage()));
continue;
}
}
if (!_storageMgr.storagePoolHasEnoughIops(volumeDiskProfilePair, potentialSPool) || !_storageMgr.storagePoolHasEnoughSpace(volumeDiskProfilePair, potentialSPool, potentialHost.getClusterId()))
continue;
volumeAllocationMap.put(potentialSPool, requestVolumes);
}
storage.put(vol, potentialSPool);
haveEnoughSpace = true;
break;
}
}
if (!hostCanAccessPool) {
break;
}
if (!haveEnoughSpace) {
s_logger.warn("insufficient capacity to allocate all volumes");
break;
}
if (!hostAffinityCheck) {
s_logger.debug("Host affinity check failed");
break;
}
}
}
if (hostCanAccessPool && haveEnoughSpace && hostAffinityCheck && checkIfHostFitsPlannerUsage(potentialHost.getId(), resourceUsageRequired)) {
s_logger.debug("Found a potential host " + "id: " + potentialHost.getId() + " name: " + potentialHost.getName() + " and associated storage pools for this VM");
volumeAllocationMap.clear();
return new Pair<Host, Map<Volume, StoragePool>>(potentialHost, storage);
} else {
avoid.addHost(potentialHost.getId());
}
}
s_logger.debug("Could not find a potential host that has associated storage pools from the suitable host/pool lists for this VM");
return null;
}
use of com.cloud.exception.StorageUnavailableException in project cloudstack by apache.
the class KVMHostActivityChecker method verifyActivityOfStorageOnHost.
protected boolean verifyActivityOfStorageOnHost(HashMap<StoragePool, List<Volume>> poolVolMap, StoragePool pool, Host agent, DateTime suspectTime, boolean activityStatus) throws HACheckerException, IllegalStateException {
List<Volume> volume_list = poolVolMap.get(pool);
final CheckVMActivityOnStoragePoolCommand cmd = new CheckVMActivityOnStoragePoolCommand(agent, pool, volume_list, suspectTime);
LOG.debug(String.format("Checking VM activity for %s on storage pool [%s].", agent.toString(), pool.getId()));
try {
Answer answer = storageManager.sendToPool(pool, getNeighbors(agent), cmd);
if (answer != null) {
activityStatus = !answer.getResult();
LOG.debug(String.format("%s %s activity on storage pool [%s]", agent.toString(), activityStatus ? "has" : "does not have", pool.getId()));
} else {
String message = String.format("Did not get a valid response for VM activity check for %s on storage pool [%s].", agent.toString(), pool.getId());
LOG.debug(message);
throw new IllegalStateException(message);
}
} catch (StorageUnavailableException e) {
String message = String.format("Storage [%s] is unavailable to do the check, probably the %s is not reachable.", pool.getId(), agent.toString());
LOG.warn(message, e);
throw new HACheckerException(message, e);
}
return activityStatus;
}
use of com.cloud.exception.StorageUnavailableException in project cloudstack by apache.
the class TemplateManagerImpl method evictTemplateFromStoragePool.
@Override
@DB
public void evictTemplateFromStoragePool(VMTemplateStoragePoolVO templatePoolVO) {
// Need to hold the lock; otherwise, another thread may create a volume from the template at the same time.
// Assumption here is that we will hold the same lock during create volume from template.
VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolVO.getId());
if (templatePoolRef == null) {
s_logger.debug("Can't aquire the lock for template pool ref: " + templatePoolVO.getId());
return;
}
PrimaryDataStore pool = (PrimaryDataStore) _dataStoreMgr.getPrimaryDataStore(templatePoolVO.getPoolId());
TemplateInfo template = _tmplFactory.getTemplateOnPrimaryStorage(templatePoolRef.getTemplateId(), pool, templatePoolRef.getDeploymentOption());
try {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Evicting " + templatePoolVO);
}
if (pool.isManaged()) {
// For managed store, just delete the template volume.
AsyncCallFuture<TemplateApiResult> future = _tmpltSvr.deleteTemplateOnPrimary(template, pool);
TemplateApiResult result = future.get();
if (result.isFailed()) {
s_logger.debug("Failed to delete template " + template.getId() + " from storage pool " + pool.getId());
} else {
// Remove the templatePoolVO.
if (_tmpltPoolDao.remove(templatePoolVO.getId())) {
s_logger.debug("Successfully evicted template " + template.getName() + " from storage pool " + pool.getName());
}
}
} else {
DestroyCommand cmd = new DestroyCommand(pool, templatePoolVO);
Answer answer = _storageMgr.sendToPool(pool, cmd);
if (answer != null && answer.getResult()) {
// Remove the templatePoolVO.
if (_tmpltPoolDao.remove(templatePoolVO.getId())) {
s_logger.debug("Successfully evicted template " + template.getName() + " from storage pool " + pool.getName());
}
} else {
s_logger.info("Will retry evict template " + template.getName() + " from storage pool " + pool.getName());
}
}
} catch (StorageUnavailableException | InterruptedException | ExecutionException e) {
s_logger.info("Storage is unavailable currently. Will retry evicte template " + template.getName() + " from storage pool " + pool.getName());
} finally {
_tmpltPoolDao.releaseFromLockTable(templatePoolRef.getId());
}
}
use of com.cloud.exception.StorageUnavailableException in project cloudstack by apache.
the class StorageManagerImpl method cancelPrimaryStorageForMaintenance.
@Override
@DB
public PrimaryDataStoreInfo cancelPrimaryStorageForMaintenance(CancelPrimaryStorageMaintenanceCmd cmd) throws ResourceUnavailableException {
Long primaryStorageId = cmd.getId();
StoragePoolVO primaryStorage = null;
primaryStorage = _storagePoolDao.findById(primaryStorageId);
if (primaryStorage == null) {
String msg = "Unable to obtain lock on the storage pool in cancelPrimaryStorageForMaintenance()";
s_logger.error(msg);
throw new InvalidParameterValueException(msg);
}
if (primaryStorage.getStatus().equals(StoragePoolStatus.Up) || primaryStorage.getStatus().equals(StoragePoolStatus.PrepareForMaintenance)) {
throw new StorageUnavailableException("Primary storage with id " + primaryStorageId + " is not ready to complete migration, as the status is:" + primaryStorage.getStatus().toString(), primaryStorageId);
}
DataStoreProvider provider = _dataStoreProviderMgr.getDataStoreProvider(primaryStorage.getStorageProviderName());
DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
DataStore store = _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
if (primaryStorage.getPoolType() == StoragePoolType.DatastoreCluster) {
primaryStorage.setStatus(StoragePoolStatus.Up);
_storagePoolDao.update(primaryStorage.getId(), primaryStorage);
// FR41 need to handle when one of the primary stores is unable to cancel the maintenance mode
List<StoragePoolVO> childDatastores = _storagePoolDao.listChildStoragePoolsInDatastoreCluster(primaryStorageId);
for (StoragePoolVO childDatastore : childDatastores) {
DataStore childStore = _dataStoreMgr.getDataStore(childDatastore.getId(), DataStoreRole.Primary);
lifeCycle.cancelMaintain(childStore);
}
}
lifeCycle.cancelMaintain(store);
return (PrimaryDataStoreInfo) _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
}
use of com.cloud.exception.StorageUnavailableException in project cloudstack by apache.
the class UserVmManagerImpl method getVolumePoolMappingForMigrateVmWithStorage.
private Map<Long, Long> getVolumePoolMappingForMigrateVmWithStorage(VMInstanceVO vm, Map<String, String> volumeToPool) {
Map<Long, Long> volToPoolObjectMap = new HashMap<Long, Long>();
List<VolumeVO> vmVolumes = getVmVolumesForMigrateVmWithStorage(vm);
if (MapUtils.isNotEmpty(volumeToPool)) {
// Check if all the volumes and pools passed as parameters are valid.
for (Map.Entry<String, String> entry : volumeToPool.entrySet()) {
VolumeVO volume = _volsDao.findByUuid(entry.getKey());
StoragePoolVO pool = _storagePoolDao.findByUuid(entry.getValue());
if (volume == null) {
throw new InvalidParameterValueException("There is no volume present with the given id " + entry.getKey());
} else if (pool == null) {
throw new InvalidParameterValueException("There is no storage pool present with the given id " + entry.getValue());
} else if (pool.isInMaintenance()) {
throw new InvalidParameterValueException("Cannot migrate volume " + volume + "to the destination storage pool " + pool.getName() + " as the storage pool is in maintenance mode.");
} else {
// Verify the volume given belongs to the vm.
if (!vmVolumes.contains(volume)) {
throw new InvalidParameterValueException(String.format("Volume " + volume + " doesn't belong to the VM %s (ID: %s) that has to be migrated", vm.getInstanceName(), vm.getUuid()));
}
volToPoolObjectMap.put(volume.getId(), pool.getId());
}
HypervisorType hypervisorType = _volsDao.getHypervisorType(volume.getId());
if (hypervisorType.equals(HypervisorType.VMware)) {
try {
DiskOffering diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
DiskProfile diskProfile = new DiskProfile(volume, diskOffering, _volsDao.getHypervisorType(volume.getId()));
Pair<Volume, DiskProfile> volumeDiskProfilePair = new Pair<>(volume, diskProfile);
boolean isStoragePoolStoragepolicyCompliance = storageManager.isStoragePoolCompliantWithStoragePolicy(Arrays.asList(volumeDiskProfilePair), pool);
if (!isStoragePoolStoragepolicyCompliance) {
throw new CloudRuntimeException(String.format("Storage pool %s is not storage policy compliance with the volume %s", pool.getUuid(), volume.getUuid()));
}
} catch (StorageUnavailableException e) {
throw new CloudRuntimeException(String.format("Could not verify storage policy compliance against storage pool %s due to exception %s", pool.getUuid(), e.getMessage()));
}
}
}
}
return volToPoolObjectMap;
}
Aggregations