use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method getDataStoreRole.
public static DataStoreRole getDataStoreRole(final Snapshot snapshot, final SnapshotDataStoreDao snapshotStoreDao, final DataStoreManager dataStoreMgr) {
final SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Primary);
if (snapshotStore == null) {
return DataStoreRole.Image;
}
final long storagePoolId = snapshotStore.getDataStoreId();
final DataStore dataStore = dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary);
final Map<String, String> mapCapabilities = dataStore.getDriver().getCapabilities();
if (mapCapabilities != null) {
final String value = mapCapabilities.get(DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString());
final Boolean supportsStorageSystemSnapshots = new Boolean(value);
if (supportsStorageSystemSnapshots) {
return DataStoreRole.Primary;
}
}
return DataStoreRole.Image;
}
use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.
the class QueryManagerImpl method searchForStoragePools.
@Override
public ListResponse<StoragePoolResponse> searchForStoragePools(final ListStoragePoolsCmd cmd) {
final Pair<List<StoragePoolJoinVO>, Integer> result = searchForStoragePoolsInternal(cmd);
final ListResponse<StoragePoolResponse> response = new ListResponse<>();
final List<StoragePoolResponse> poolResponses = ViewResponseHelper.createStoragePoolResponse(result.first().toArray(new StoragePoolJoinVO[result.first().size()]));
for (final StoragePoolResponse poolResponse : poolResponses) {
final DataStore store = dataStoreManager.getPrimaryDataStore(poolResponse.getId());
if (store != null) {
final DataStoreDriver driver = store.getDriver();
if (driver != null && driver.getCapabilities() != null) {
poolResponse.setCaps(driver.getCapabilities());
}
}
}
response.setResponses(poolResponses, result.second());
return response;
}
use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.
the class QueryManagerImpl method searchForVolumes.
@Override
public ListResponse<VolumeResponse> searchForVolumes(final ListVolumesCmd cmd) {
final Pair<List<VolumeJoinVO>, Integer> result = searchForVolumesInternal(cmd);
final ListResponse<VolumeResponse> response = new ListResponse<>();
ResponseView respView = ResponseView.Restricted;
if (cmd instanceof ListVolumesCmdByAdmin) {
respView = ResponseView.Full;
}
final List<VolumeResponse> volumeResponses = ViewResponseHelper.createVolumeResponse(respView, result.first().toArray(new VolumeJoinVO[result.first().size()]));
for (final VolumeResponse vr : volumeResponses) {
final String poolId = vr.getStoragePoolId();
if (poolId == null) {
continue;
}
final DataStore store = dataStoreManager.getPrimaryDataStore(poolId);
if (store == null) {
continue;
}
final DataStoreDriver driver = store.getDriver();
if (driver == null) {
continue;
}
final Map<String, String> caps = driver.getCapabilities();
if (caps != null) {
final boolean quiescevm = Boolean.parseBoolean(caps.get(DataStoreCapabilities.VOLUME_SNAPSHOT_QUIESCEVM.toString()));
vr.setNeedQuiescevm(quiescevm);
}
}
response.setResponses(volumeResponses, result.second());
return response;
}
use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.
the class DeploymentPlanningManagerImpl method findSuitablePoolsForVolumes.
protected Pair<Map<Volume, List<StoragePool>>, List<Volume>> findSuitablePoolsForVolumes(final VirtualMachineProfile vmProfile, final DeploymentPlan plan, final ExcludeList avoid, final int returnUpTo) {
final List<VolumeVO> volumesTobeCreated = _volsDao.findUsableVolumesForInstance(vmProfile.getId());
final Map<Volume, List<StoragePool>> suitableVolumeStoragePools = new HashMap<>();
final List<Volume> readyAndReusedVolumes = new ArrayList<>();
// There should be atleast the ROOT volume of the VM in usable state
if (volumesTobeCreated.isEmpty()) {
throw new CloudRuntimeException("Unable to create deployment, no usable volumes found for the VM");
}
// don't allow to start vm that doesn't have a root volume
if (_volsDao.findByInstanceAndType(vmProfile.getId(), Volume.Type.ROOT).isEmpty()) {
throw new CloudRuntimeException("Unable to prepare volumes for vm as ROOT volume is missing");
}
// for each volume find list of suitable storage pools by calling the
// allocators
Set<Long> originalAvoidPoolSet = avoid.getPoolsToAvoid();
if (originalAvoidPoolSet == null) {
originalAvoidPoolSet = new HashSet<>();
}
final Set<Long> poolsToAvoidOutput = new HashSet<>(originalAvoidPoolSet);
for (final VolumeVO toBeCreated : volumesTobeCreated) {
s_logger.debug("Checking suitable pools for volume (Id, Type): (" + toBeCreated.getId() + "," + toBeCreated.getVolumeType().name() + ")");
// be reused.
if (plan.getPoolId() != null || (toBeCreated.getVolumeType() == Volume.Type.DATADISK && toBeCreated.getPoolId() != null && toBeCreated.getState() == Volume.State.Ready)) {
s_logger.debug("Volume has pool already allocated, checking if pool can be reused, poolId: " + toBeCreated.getPoolId());
final List<StoragePool> suitablePools = new ArrayList<>();
StoragePool pool = null;
if (toBeCreated.getPoolId() != null) {
pool = (StoragePool) dataStoreMgr.getPrimaryDataStore(toBeCreated.getPoolId());
} else {
pool = (StoragePool) dataStoreMgr.getPrimaryDataStore(plan.getPoolId());
}
if (!pool.isInMaintenance()) {
if (!avoid.shouldAvoid(pool)) {
final long exstPoolDcId = pool.getDataCenterId();
final long exstPoolPodId = pool.getPodId() != null ? pool.getPodId() : -1;
final long exstPoolClusterId = pool.getClusterId() != null ? pool.getClusterId() : -1;
boolean canReusePool = false;
if (plan.getDataCenterId() == exstPoolDcId && plan.getPodId() == exstPoolPodId && plan.getClusterId() == exstPoolClusterId) {
canReusePool = true;
} else if (plan.getDataCenterId() == exstPoolDcId) {
final DataStore dataStore = dataStoreMgr.getPrimaryDataStore(pool.getId());
if (dataStore != null && dataStore.getScope() != null && dataStore.getScope().getScopeType() == ScopeType.ZONE) {
canReusePool = true;
}
} else {
s_logger.debug("Pool of the volume does not fit the specified plan, need to reallocate a pool for this volume");
canReusePool = false;
}
if (canReusePool) {
s_logger.debug("Planner need not allocate a pool for this volume since its READY");
suitablePools.add(pool);
suitableVolumeStoragePools.put(toBeCreated, suitablePools);
if (!(toBeCreated.getState() == Volume.State.Allocated || toBeCreated.getState() == Volume.State.Creating)) {
readyAndReusedVolumes.add(toBeCreated);
}
continue;
}
} else {
s_logger.debug("Pool of the volume is in avoid set, need to reallocate a pool for this volume");
}
} else {
s_logger.debug("Pool of the volume is in maintenance, need to reallocate a pool for this volume");
}
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("We need to allocate new storagepool for this volume");
}
if (!isRootAdmin(vmProfile)) {
if (!isEnabledForAllocation(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId())) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Cannot allocate new storagepool for this volume in this cluster, allocation state is disabled");
s_logger.debug("Cannot deploy to this specified plan, allocation state is disabled, returning.");
}
// Cannot find suitable storage pools under this cluster for
// this volume since allocation_state is disabled.
// - remove any suitable pools found for other volumes.
// All volumes should get suitable pools under this cluster;
// else we cant use this cluster.
suitableVolumeStoragePools.clear();
break;
}
}
s_logger.debug("Calling StoragePoolAllocators to find suitable pools");
final DiskOfferingVO diskOffering = _diskOfferingDao.findById(toBeCreated.getDiskOfferingId());
if (vmProfile.getTemplate().getFormat() == Storage.ImageFormat.ISO && vmProfile.getServiceOffering().getTagsArray().length != 0) {
diskOffering.setTagsArray(Arrays.asList(vmProfile.getServiceOffering().getTagsArray()));
}
final DiskProfile diskProfile = new DiskProfile(toBeCreated, diskOffering, vmProfile.getHypervisorType());
boolean useLocalStorage = false;
if (vmProfile.getType() != VirtualMachine.Type.User) {
final Zone zone = zoneRepository.findOne(plan.getDataCenterId());
assert (zone != null) : "Invalid zone in deployment plan";
final Boolean useLocalStorageForSystemVM = ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(zone.getId());
if (useLocalStorageForSystemVM != null) {
useLocalStorage = useLocalStorageForSystemVM.booleanValue();
s_logger.debug("System VMs will use " + (useLocalStorage ? "local" : "shared") + " storage for zone id=" + plan.getDataCenterId());
}
} else {
useLocalStorage = diskOffering.getUseLocalStorage();
// offering when it is a ROOT disk
if (!useLocalStorage && vmProfile.getServiceOffering().getUseLocalStorage()) {
if (toBeCreated.getVolumeType() == Volume.Type.ROOT) {
useLocalStorage = true;
}
}
}
diskProfile.setUseLocalStorage(useLocalStorage);
boolean foundPotentialPools = false;
for (final StoragePoolAllocator allocator : _storagePoolAllocators) {
final List<StoragePool> suitablePools = allocator.allocateToPool(diskProfile, vmProfile, plan, avoid, returnUpTo);
if (suitablePools != null && !suitablePools.isEmpty()) {
suitableVolumeStoragePools.put(toBeCreated, suitablePools);
foundPotentialPools = true;
break;
}
}
if (avoid.getPoolsToAvoid() != null) {
poolsToAvoidOutput.addAll(avoid.getPoolsToAvoid());
avoid.getPoolsToAvoid().retainAll(originalAvoidPoolSet);
}
if (!foundPotentialPools) {
s_logger.debug("No suitable pools found for volume: " + toBeCreated + " under cluster: " + plan.getClusterId());
// No suitable storage pools found under this cluster for this
// volume. - remove any suitable pools found for other volumes.
// All volumes should get suitable pools under this cluster;
// else we cant use this cluster.
suitableVolumeStoragePools.clear();
break;
}
}
final HashSet<Long> toRemove = new HashSet<>();
for (final List<StoragePool> lsp : suitableVolumeStoragePools.values()) {
for (final StoragePool sp : lsp) {
toRemove.add(sp.getId());
}
}
poolsToAvoidOutput.removeAll(toRemove);
if (avoid.getPoolsToAvoid() != null) {
avoid.getPoolsToAvoid().addAll(poolsToAvoidOutput);
}
if (suitableVolumeStoragePools.isEmpty()) {
s_logger.debug("No suitable pools found");
}
return new Pair<>(suitableVolumeStoragePools, readyAndReusedVolumes);
}
use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.
the class StorageManagerImpl method cancelPrimaryStorageForMaintenance.
@Override
@DB
public PrimaryDataStoreInfo cancelPrimaryStorageForMaintenance(final CancelPrimaryStorageMaintenanceCmd cmd) throws ResourceUnavailableException {
final Long primaryStorageId = cmd.getId();
final StoragePoolVO primaryStorage;
primaryStorage = _storagePoolDao.findById(primaryStorageId);
if (primaryStorage == null) {
final 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);
}
final DataStoreProvider provider = _dataStoreProviderMgr.getDataStoreProvider(primaryStorage.getStorageProviderName());
final DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
final DataStore store = _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
lifeCycle.cancelMaintain(store);
return (PrimaryDataStoreInfo) _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
}
Aggregations