use of com.cloud.storage.StoragePool 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 com.cloud.storage.StoragePool in project cloudstack by apache.
the class VMwareGuru method finalizeMigrate.
@Override
public List<Command> finalizeMigrate(VirtualMachine vm, Map<Volume, StoragePool> volumeToPool) {
List<Command> commands = new ArrayList<Command>();
// OfflineVmwareMigration: specialised migration command
List<Pair<VolumeTO, StorageFilerTO>> volumeToFilerTo = new ArrayList<Pair<VolumeTO, StorageFilerTO>>();
Long poolClusterId = null;
for (Map.Entry<Volume, StoragePool> entry : volumeToPool.entrySet()) {
Volume volume = entry.getKey();
StoragePool pool = entry.getValue();
VolumeTO volumeTo = new VolumeTO(volume, _storagePoolDao.findById(pool.getId()));
StorageFilerTO filerTo = new StorageFilerTO(pool);
if (pool.getClusterId() != null) {
poolClusterId = pool.getClusterId();
}
volumeToFilerTo.add(new Pair<VolumeTO, StorageFilerTO>(volumeTo, filerTo));
}
final Long destClusterId = poolClusterId;
final Long srcClusterId = vmManager.findClusterAndHostIdForVm(vm.getId()).first();
final boolean isInterClusterMigration = isInterClusterMigration(destClusterId, srcClusterId);
MigrateVmToPoolCommand migrateVmToPoolCommand = new MigrateVmToPoolCommand(vm.getInstanceName(), volumeToFilerTo, getHostGuidInTargetCluster(isInterClusterMigration, destClusterId), true);
commands.add(migrateVmToPoolCommand);
// OfflineVmwareMigration: cleanup if needed
if (isInterClusterMigration) {
final String srcDcName = _clusterDetailsDao.getVmwareDcName(srcClusterId);
final String destDcName = _clusterDetailsDao.getVmwareDcName(destClusterId);
if (srcDcName != null && destDcName != null && !srcDcName.equals(destDcName)) {
final UnregisterVMCommand unregisterVMCommand = new UnregisterVMCommand(vm.getInstanceName(), true);
unregisterVMCommand.setCleanupVmFiles(true);
commands.add(unregisterVMCommand);
}
}
return commands;
}
use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class RandomStoragePoolAllocator method select.
@Override
public List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) {
List<StoragePool> suitablePools = new ArrayList<StoragePool>();
long dcId = plan.getDataCenterId();
Long podId = plan.getPodId();
Long clusterId = plan.getClusterId();
if (podId == null) {
return null;
}
s_logger.debug("Looking for pools in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId);
List<StoragePoolVO> pools = storagePoolDao.listBy(dcId, podId, clusterId, ScopeType.CLUSTER);
if (pools.size() == 0) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("No storage pools available for allocation, returning");
}
return suitablePools;
}
Collections.shuffle(pools);
if (s_logger.isDebugEnabled()) {
s_logger.debug("RandomStoragePoolAllocator has " + pools.size() + " pools to check for allocation");
}
for (StoragePoolVO pool : pools) {
if (suitablePools.size() == returnUpTo) {
break;
}
StoragePool pol = (StoragePool) this.dataStoreMgr.getPrimaryDataStore(pool.getId());
if (filter(avoid, pol, dskCh, plan)) {
suitablePools.add(pol);
}
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("RandomStoragePoolAllocator returning " + suitablePools.size() + " suitable storage pools");
}
return suitablePools;
}
use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class AncientDataMotionStrategy method addFullCloneAndDiskprovisiongStrictnessFlagOnVMwareDest.
/**
* Adds {@code 'vmware.create.full.clone'} value for a given primary storage, whose HV is VMware, on datastore's {@code fullCloneFlag} field
* @param dataTO Dest data store TO
* @return dataTO including fullCloneFlag, if provided
*/
protected DataTO addFullCloneAndDiskprovisiongStrictnessFlagOnVMwareDest(DataTO dataTO) {
if (dataTO != null && dataTO.getHypervisorType().equals(Hypervisor.HypervisorType.VMware)) {
DataStoreTO dataStoreTO = dataTO.getDataStore();
if (dataStoreTO != null && dataStoreTO instanceof PrimaryDataStoreTO) {
PrimaryDataStoreTO primaryDataStoreTO = (PrimaryDataStoreTO) dataStoreTO;
primaryDataStoreTO.setFullCloneFlag(CapacityManager.VmwareCreateCloneFull.valueIn(primaryDataStoreTO.getId()));
StoragePool pool = storageManager.getStoragePool(primaryDataStoreTO.getId());
primaryDataStoreTO.setDiskProvisioningStrictnessFlag(storageManager.DiskProvisioningStrictness.valueIn(pool.getDataCenterId()));
}
}
return dataTO;
}
use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class AncientDataMotionStrategy method copyVolumeFromSnapshot.
protected Answer copyVolumeFromSnapshot(DataObject snapObj, DataObject volObj) {
SnapshotInfo snapshot = (SnapshotInfo) snapObj;
StoragePool pool = (StoragePool) volObj.getDataStore();
String basicErrMsg = "Failed to create volume from " + snapshot.getName() + " on pool " + pool;
DataStore store = snapObj.getDataStore();
DataStoreTO storTO = store.getTO();
DataObject srcData = snapObj;
try {
if (!(storTO instanceof NfsTO)) {
// cache snapshot to zone-wide staging store for the volume to be created
srcData = cacheSnapshotChain(snapshot, new ZoneScope(pool.getDataCenterId()));
}
String value = configDao.getValue(Config.CreateVolumeFromSnapshotWait.toString());
int _createVolumeFromSnapshotWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CreateVolumeFromSnapshotWait.getDefaultValue()));
EndPoint ep = null;
if (srcData.getDataStore().getRole() == DataStoreRole.Primary) {
ep = selector.select(volObj);
} else {
ep = selector.select(srcData, volObj);
}
CopyCommand cmd = new CopyCommand(srcData.getTO(), addFullCloneAndDiskprovisiongStrictnessFlagOnVMwareDest(volObj.getTO()), _createVolumeFromSnapshotWait, VirtualMachineManager.ExecuteInSequence.value());
Answer answer = null;
if (ep == null) {
String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
s_logger.error(errMsg);
answer = new Answer(cmd, false, errMsg);
} else {
answer = ep.sendMessage(cmd);
}
return answer;
} catch (Exception e) {
s_logger.error(basicErrMsg, e);
throw new CloudRuntimeException(basicErrMsg);
} finally {
if (!(storTO instanceof NfsTO)) {
// still keep snapshot on cache which may be migrated from previous secondary storage
releaseSnapshotCacheChain((SnapshotInfo) srcData);
}
}
}
Aggregations