Search in sources :

Example 81 with DiskOfferingVO

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();
        }
    }
}
Also used : DiskOfferingVO(com.cloud.storage.DiskOfferingVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

Example 82 with DiskOfferingVO

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);
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 83 with DiskOfferingVO

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();
    }
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) StoragePool(com.cloud.storage.StoragePool) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) ArrayList(java.util.ArrayList) StoragePoolDetailVO(org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO) DiskProfile(com.cloud.vm.DiskProfile) Volume(com.cloud.storage.Volume) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DeploymentPlan(com.cloud.deploy.DeploymentPlan) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator) Test(org.junit.Test)

Example 84 with DiskOfferingVO

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);
    }
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeApiResult(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) HostVO(com.cloud.host.HostVO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 85 with DiskOfferingVO

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);
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) HashMap(java.util.HashMap) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) VMSnapshot(com.cloud.vm.snapshot.VMSnapshot)

Aggregations

DiskOfferingVO (com.cloud.storage.DiskOfferingVO)86 ArrayList (java.util.ArrayList)34 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)32 VolumeVO (com.cloud.storage.VolumeVO)25 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)24 Account (com.cloud.user.Account)23 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)22 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)18 List (java.util.List)16 StoragePool (com.cloud.storage.StoragePool)15 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)14 DiskProfile (com.cloud.vm.DiskProfile)14 VMInstanceVO (com.cloud.vm.VMInstanceVO)14 HostVO (com.cloud.host.HostVO)13 NetworkVO (com.cloud.network.dao.NetworkVO)13 Pair (com.cloud.utils.Pair)13 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)12 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)12 User (com.cloud.user.User)12 HashMap (java.util.HashMap)12