use of com.cloud.storage.DiskOfferingVO in project cloudstack by apache.
the class RouterDeploymentDefinition method verifyServiceOfferingByUuid.
private void verifyServiceOfferingByUuid(String offeringUuid) {
logger.debug("Verifying router service offering with uuid : " + offeringUuid);
ServiceOfferingVO serviceOffering = serviceOfferingDao.findByUuid(offeringUuid);
if (serviceOffering != null && serviceOffering.isSystemUse()) {
DiskOfferingVO diskOffering = diskOfferingDao.findById(serviceOffering.getDiskOfferingId());
boolean isLocalStorage = ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dest.getDataCenter().getId());
if (isLocalStorage == diskOffering.isUseLocalStorage()) {
logger.debug(String.format("Service offering %s (uuid: %s) will be used on virtual router", serviceOffering.getName(), serviceOffering.getUuid()));
serviceOfferingId = serviceOffering.getId();
}
}
}
use of com.cloud.storage.DiskOfferingVO in project cloudstack by apache.
the class DiskOfferingDaoImpl method listAllBySizeAndProvisioningType.
@Override
public List<DiskOfferingVO> listAllBySizeAndProvisioningType(long size, Storage.ProvisioningType provisioningType) {
StringBuilder sql = new StringBuilder(SizeDiskOfferingSearch);
TransactionLegacy txn = TransactionLegacy.currentTxn();
List<DiskOfferingVO> offerings = new ArrayList<>();
try (PreparedStatement pstmt = txn.prepareStatement(sql.toString())) {
if (pstmt != null) {
pstmt.setLong(1, size);
pstmt.setString(2, provisioningType.toString());
try (ResultSet rs = pstmt.executeQuery()) {
while (rs.next()) {
offerings.add(toEntityBean(rs, false));
}
} catch (SQLException e) {
throw new CloudRuntimeException("Exception while listing disk offerings by size: " + e.getMessage(), e);
}
}
return offerings;
} catch (SQLException e) {
throw new CloudRuntimeException("Exception while listing disk offerings by size: " + e.getMessage(), e);
}
}
use of com.cloud.storage.DiskOfferingVO in project cloudstack by apache.
the class StorageAllocatorTest method testClusterAllocatorWithWrongTag.
@Test
public void testClusterAllocatorWithWrongTag() {
try {
createDb();
StoragePoolDetailVO detailVO = new StoragePoolDetailVO(this.storagePoolId, "high", "true", true);
poolDetailsDao.persist(detailVO);
DiskOfferingVO diskOff = this.diskOfferingDao.findById(diskOffering.getId());
List<String> tags = new ArrayList<String>();
tags.add("low");
diskOff.setTagsArray(tags);
diskOfferingDao.update(diskOff.getId(), diskOff);
DiskProfile profile = new DiskProfile(volume, diskOff, HypervisorType.XenServer);
VirtualMachineProfile vmProfile = Mockito.mock(VirtualMachineProfile.class);
Mockito.when(storageMgr.storagePoolHasEnoughSpace(Matchers.anyListOf(Volume.class), Matchers.any(StoragePool.class))).thenReturn(true);
DeploymentPlan plan = new DataCenterDeployment(dcId, podId, clusterId, null, null, null);
int foundAcct = 0;
for (StoragePoolAllocator allocator : allocators) {
List<StoragePool> pools = allocator.allocateToPool(profile, vmProfile, plan, new ExcludeList(), 1);
if (!pools.isEmpty()) {
foundAcct++;
}
}
if (foundAcct != 0) {
Assert.fail();
}
} catch (Exception e) {
cleanDb();
Assert.fail();
}
}
use of com.cloud.storage.DiskOfferingVO in project cloudstack by apache.
the class StorageSystemDataMotionStrategy method handleCreateManagedVolumeFromNonManagedSnapshot.
/**
* Creates a managed volume on the storage from a snapshot that resides on the secondary storage (archived snapshot).
* @param snapshotInfo snapshot on secondary
* @param volumeInfo volume to be created on the storage
* @param callback for async
*/
private void handleCreateManagedVolumeFromNonManagedSnapshot(SnapshotInfo snapshotInfo, VolumeInfo volumeInfo, AsyncCompletionCallback<CopyCommandResult> callback) {
String errMsg = null;
CopyCmdAnswer copyCmdAnswer = null;
try {
// at this point, the snapshotInfo and volumeInfo should have the same disk offering ID (so either one should be OK to get a DiskOfferingVO instance)
DiskOfferingVO diskOffering = _diskOfferingDao.findByIdIncludingRemoved(volumeInfo.getDiskOfferingId());
SnapshotVO snapshot = _snapshotDao.findById(snapshotInfo.getId());
// update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
_volumeService.updateHypervisorSnapshotReserveForVolume(diskOffering, volumeInfo.getId(), snapshot.getHypervisorType());
HostVO hostVO;
// create a volume on the storage
AsyncCallFuture<VolumeApiResult> future = _volumeService.createVolumeAsync(volumeInfo, volumeInfo.getDataStore());
VolumeApiResult result = future.get();
if (result.isFailed()) {
LOGGER.error("Failed to create a volume: " + result.getResult());
throw new CloudRuntimeException(result.getResult());
}
volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
volumeInfo.processEvent(Event.MigrationRequested);
volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
handleQualityOfServiceForVolumeMigration(volumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.MIGRATION);
hostVO = getHost(snapshotInfo.getDataCenterId(), snapshotInfo.getHypervisorType(), false);
// copy the volume from secondary via the hypervisor
if (HypervisorType.XenServer.equals(snapshotInfo.getHypervisorType())) {
copyCmdAnswer = performCopyOfVdi(volumeInfo, snapshotInfo, hostVO);
} else {
copyCmdAnswer = copyImageToVolume(snapshotInfo, volumeInfo, hostVO);
}
if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
if (copyCmdAnswer != null && StringUtils.isNotEmpty(copyCmdAnswer.getDetails())) {
throw new CloudRuntimeException(copyCmdAnswer.getDetails());
} else {
throw new CloudRuntimeException("Unable to create volume from snapshot");
}
}
} catch (Exception ex) {
errMsg = "Copy operation failed in 'StorageSystemDataMotionStrategy.handleCreateManagedVolumeFromNonManagedSnapshot': " + ex.getMessage();
throw new CloudRuntimeException(errMsg);
} finally {
handleQualityOfServiceForVolumeMigration(volumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.NO_MIGRATION);
if (copyCmdAnswer == null) {
copyCmdAnswer = new CopyCmdAnswer(errMsg);
}
CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
result.setResult(errMsg);
callback.complete(result);
}
}
use of com.cloud.storage.DiskOfferingVO in project cloudstack by apache.
the class ScaleIOVMSnapshotStrategy method publishUsageEvent.
private void publishUsageEvent(String type, VMSnapshot vmSnapshot, UserVm userVm, VolumeObjectTO volumeTo) {
VolumeVO volume = volumeDao.findById(volumeTo.getId());
Long diskOfferingId = volume.getDiskOfferingId();
Long offeringId = null;
if (diskOfferingId != null) {
DiskOfferingVO offering = diskOfferingDao.findById(diskOfferingId);
if (offering != null && !offering.isComputeOnly()) {
offeringId = offering.getId();
}
}
Map<String, String> details = new HashMap<>();
if (vmSnapshot != null) {
details.put(UsageEventVO.DynamicParameters.vmSnapshotId.name(), String.valueOf(vmSnapshot.getId()));
}
// save volume's id into templateId field
UsageEventUtils.publishUsageEvent(// save volume's id into templateId field
type, // save volume's id into templateId field
vmSnapshot.getAccountId(), // save volume's id into templateId field
userVm.getDataCenterId(), // save volume's id into templateId field
userVm.getId(), // save volume's id into templateId field
vmSnapshot.getName(), // save volume's id into templateId field
offeringId, // save volume's id into templateId field
volume.getId(), volumeTo.getSize(), VMSnapshot.class.getName(), vmSnapshot.getUuid(), details);
}
Aggregations