Search in sources :

Example 16 with DiskOfferingVO

use of com.cloud.storage.DiskOfferingVO in project cloudstack by apache.

the class StorageAllocatorTest method testLocalStorageAllocator.

@Test
public void testLocalStorageAllocator() {
    try {
        createDb();
        StoragePoolVO pool = storagePoolDao.findById(storagePoolId);
        pool.setScope(ScopeType.HOST);
        storagePoolDao.update(pool.getId(), pool);
        DiskOfferingVO diskOff = diskOfferingDao.findById(diskOfferingId);
        diskOff.setUseLocalStorage(true);
        diskOfferingDao.update(diskOfferingId, 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()) {
                Assert.assertEquals(pools.get(0).getId(), storage.getId());
                foundAcct++;
            }
        }
        if (foundAcct > 1 || 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) DiskProfile(com.cloud.vm.DiskProfile) Volume(com.cloud.storage.Volume) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DeploymentPlan(com.cloud.deploy.DeploymentPlan) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator) Test(org.junit.Test)

Example 17 with DiskOfferingVO

use of com.cloud.storage.DiskOfferingVO in project cloudstack by apache.

the class StorageSystemDataMotionStrategy method handleCreateManagedVolumeFromManagedSnapshot.

private void handleCreateManagedVolumeFromManagedSnapshot(SnapshotInfo snapshotInfo, VolumeInfo volumeInfo, AsyncCompletionCallback<CopyCommandResult> callback) {
    String errMsg = null;
    CopyCmdAnswer copyCmdAnswer = null;
    boolean useCloning = true;
    try {
        verifyFormat(snapshotInfo);
        HostVO hostVO = getHost(snapshotInfo);
        boolean usingBackendSnapshot = usingBackendSnapshotFor(snapshotInfo);
        boolean computeClusterSupportsVolumeClone = true;
        if (HypervisorType.XenServer.equals(snapshotInfo.getHypervisorType())) {
            computeClusterSupportsVolumeClone = clusterDao.getSupportsResigning(hostVO.getClusterId());
            if (usingBackendSnapshot && !computeClusterSupportsVolumeClone) {
                String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + hostVO.getClusterId();
                LOGGER.warn(noSupportForResignErrMsg);
                throw new CloudRuntimeException(noSupportForResignErrMsg);
            }
        }
        boolean canStorageSystemCreateVolumeFromVolume = canStorageSystemCreateVolumeFromVolume(snapshotInfo.getDataStore().getId());
        useCloning = usingBackendSnapshot || (canStorageSystemCreateVolumeFromVolume && computeClusterSupportsVolumeClone);
        VolumeDetailVO volumeDetail = null;
        if (useCloning) {
            volumeDetail = new VolumeDetailVO(volumeInfo.getId(), "cloneOfSnapshot", String.valueOf(snapshotInfo.getId()), false);
            volumeDetail = volumeDetailsDao.persist(volumeDetail);
        }
        // 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());
        AsyncCallFuture<VolumeApiResult> future = _volumeService.createVolumeAsync(volumeInfo, volumeInfo.getDataStore());
        VolumeApiResult result = future.get();
        if (volumeDetail != null) {
            volumeDetailsDao.remove(volumeDetail.getId());
        }
        if (result.isFailed()) {
            LOGGER.warn("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());
        if (HypervisorType.XenServer.equals(snapshotInfo.getHypervisorType()) || HypervisorType.VMware.equals(snapshotInfo.getHypervisorType())) {
            if (useCloning) {
                Map<String, String> extraDetails = null;
                if (HypervisorType.VMware.equals(snapshotInfo.getHypervisorType())) {
                    extraDetails = new HashMap<>();
                    String extraDetailsVmdk = getSnapshotProperty(snapshotInfo.getId(), DiskTO.VMDK);
                    extraDetails.put(DiskTO.VMDK, extraDetailsVmdk);
                }
                copyCmdAnswer = performResignature(volumeInfo, hostVO, extraDetails);
                // If using VMware, have the host rescan its software HBA if dynamic discovery is in use.
                if (HypervisorType.VMware.equals(snapshotInfo.getHypervisorType())) {
                    disconnectHostFromVolume(hostVO, volumeInfo.getPoolId(), volumeInfo.get_iScsiName());
                }
            } else {
                // asking for a XenServer host here so we don't always prefer to use XenServer hosts that support resigning
                // even when we don't need those hosts to do this kind of copy work
                hostVO = getHost(snapshotInfo.getDataCenterId(), snapshotInfo.getHypervisorType(), false);
                handleQualityOfServiceForVolumeMigration(volumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.MIGRATION);
                copyCmdAnswer = performCopyOfVdi(volumeInfo, snapshotInfo, hostVO);
            }
            verifyCopyCmdAnswer(copyCmdAnswer, snapshotInfo);
        } else if (HypervisorType.KVM.equals(snapshotInfo.getHypervisorType())) {
            VolumeObjectTO newVolume = new VolumeObjectTO();
            newVolume.setSize(volumeInfo.getSize());
            newVolume.setPath(volumeInfo.get_iScsiName());
            newVolume.setFormat(volumeInfo.getFormat());
            copyCmdAnswer = new CopyCmdAnswer(newVolume);
        } else {
            throw new CloudRuntimeException("Unsupported hypervisor type");
        }
    } catch (Exception ex) {
        errMsg = "Copy operation failed in 'StorageSystemDataMotionStrategy.handleCreateManagedVolumeFromManagedSnapshot': " + ex.getMessage();
        throw new CloudRuntimeException(errMsg);
    } finally {
        if (useCloning) {
            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 : VolumeDetailVO(com.cloud.storage.VolumeDetailVO) VolumeApiResult(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult) HostVO(com.cloud.host.HostVO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SnapshotVO(com.cloud.storage.SnapshotVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 18 with DiskOfferingVO

use of com.cloud.storage.DiskOfferingVO in project cloudstack by apache.

the class CloudOrchestrator method createVirtualMachineFromScratch.

@Override
public VirtualMachineEntity createVirtualMachineFromScratch(String id, String owner, String isoId, String hostName, String displayName, String hypervisor, String os, int cpu, int speed, long memory, Long diskSize, List<String> computeTags, List<String> rootDiskTags, Map<String, List<NicProfile>> networkNicMap, DeploymentPlan plan, Map<String, Map<Integer, String>> extraDhcpOptionMap, Long diskOfferingId) throws InsufficientCapacityException {
    // VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks, vmEntityManager);
    VirtualMachineEntityImpl vmEntity = ComponentContext.inject(VirtualMachineEntityImpl.class);
    vmEntity.init(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, new ArrayList<String>(networkNicMap.keySet()));
    // load vm instance and offerings and call virtualMachineManagerImpl
    VMInstanceVO vm = _vmDao.findByUuid(id);
    ServiceOfferingVO computeOffering = _serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
    DiskOfferingInfo rootDiskOfferingInfo = new DiskOfferingInfo();
    if (diskOfferingId == null) {
        throw new InvalidParameterValueException("Installing from ISO requires a disk offering to be specified for the root disk.");
    }
    DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId);
    if (diskOffering == null) {
        throw new InvalidParameterValueException("Unable to find disk offering " + diskOfferingId);
    }
    rootDiskOfferingInfo.setDiskOffering(diskOffering);
    Long size = null;
    if (!diskOffering.isComputeOnly() && diskOffering.getDiskSize() == 0) {
        size = diskSize;
        if (size == null) {
            throw new InvalidParameterValueException("Disk offering " + diskOffering + " requires size parameter.");
        }
        _volumeMgr.validateVolumeSizeRange(size * 1024 * 1024 * 1024);
    }
    rootDiskOfferingInfo.setDiskOffering(diskOffering);
    rootDiskOfferingInfo.setSize(size);
    if (diskOffering.isCustomizedIops() != null && diskOffering.isCustomizedIops()) {
        Map<String, String> userVmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
        if (userVmDetails != null) {
            String minIops = userVmDetails.get("minIopsDo");
            String maxIops = userVmDetails.get("maxIopsDo");
            rootDiskOfferingInfo.setMinIops(minIops != null && minIops.trim().length() > 0 ? Long.parseLong(minIops) : null);
            rootDiskOfferingInfo.setMaxIops(maxIops != null && maxIops.trim().length() > 0 ? Long.parseLong(maxIops) : null);
        }
    }
    LinkedHashMap<Network, List<? extends NicProfile>> networkIpMap = new LinkedHashMap<Network, List<? extends NicProfile>>();
    for (String uuid : networkNicMap.keySet()) {
        NetworkVO network = _networkDao.findByUuid(uuid);
        if (network != null) {
            networkIpMap.put(network, networkNicMap.get(uuid));
        }
    }
    HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor);
    _itMgr.allocate(vm.getInstanceName(), _templateDao.findById(new Long(isoId)), computeOffering, rootDiskOfferingInfo, new ArrayList<DiskOfferingInfo>(), networkIpMap, plan, hypervisorType, extraDhcpOptionMap, null);
    return vmEntity;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) NicProfile(com.cloud.vm.NicProfile) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) VirtualMachineEntityImpl(org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl) LinkedHashMap(java.util.LinkedHashMap) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) List(java.util.List) DiskOfferingInfo(com.cloud.offering.DiskOfferingInfo)

Example 19 with DiskOfferingVO

use of com.cloud.storage.DiskOfferingVO in project cloudstack by apache.

the class ServiceOfferingJoinDaoImpl method newServiceOfferingResponse.

@Override
public ServiceOfferingResponse newServiceOfferingResponse(ServiceOfferingJoinVO offering) {
    ServiceOfferingResponse offeringResponse = new ServiceOfferingResponse();
    offeringResponse.setId(offering.getUuid());
    offeringResponse.setName(offering.getName());
    offeringResponse.setIsSystemOffering(offering.isSystemUse());
    offeringResponse.setDefaultUse(offering.isDefaultUse());
    offeringResponse.setSystemVmType(offering.getSystemVmType());
    offeringResponse.setDisplayText(offering.getDisplayText());
    offeringResponse.setProvisioningType(offering.getProvisioningType().toString());
    offeringResponse.setCpuNumber(offering.getCpu());
    offeringResponse.setCpuSpeed(offering.getSpeed());
    offeringResponse.setMemory(offering.getRamSize());
    offeringResponse.setCreated(offering.getCreated());
    offeringResponse.setStorageType(offering.isUseLocalStorage() ? ServiceOffering.StorageType.local.toString() : ServiceOffering.StorageType.shared.toString());
    offeringResponse.setOfferHa(offering.isOfferHA());
    offeringResponse.setLimitCpuUse(offering.isLimitCpuUse());
    offeringResponse.setVolatileVm(offering.getVolatileVm());
    offeringResponse.setTags(offering.getTags());
    offeringResponse.setDomain(offering.getDomainName());
    offeringResponse.setDomainId(offering.getDomainUuid());
    offeringResponse.setZone(offering.getZoneName());
    offeringResponse.setZoneId(offering.getZoneUuid());
    offeringResponse.setNetworkRate(offering.getRateMbps());
    offeringResponse.setHostTag(offering.getHostTag());
    offeringResponse.setDeploymentPlanner(offering.getDeploymentPlanner());
    offeringResponse.setCustomizedIops(offering.isCustomizedIops());
    offeringResponse.setMinIops(offering.getMinIops());
    offeringResponse.setMaxIops(offering.getMaxIops());
    offeringResponse.setHypervisorSnapshotReserve(offering.getHypervisorSnapshotReserve());
    offeringResponse.setBytesReadRate(offering.getBytesReadRate());
    offeringResponse.setBytesReadRateMax(offering.getBytesReadRateMax());
    offeringResponse.setBytesReadRateMaxLength(offering.getBytesReadRateMaxLength());
    offeringResponse.setBytesWriteRate(offering.getBytesWriteRate());
    offeringResponse.setBytesWriteRateMax(offering.getBytesWriteRateMax());
    offeringResponse.setBytesWriteRateMaxLength(offering.getBytesWriteRateMaxLength());
    offeringResponse.setIopsReadRate(offering.getIopsReadRate());
    offeringResponse.setIopsReadRateMax(offering.getIopsReadRateMax());
    offeringResponse.setIopsReadRateMaxLength(offering.getIopsReadRateMaxLength());
    offeringResponse.setIopsWriteRate(offering.getIopsWriteRate());
    offeringResponse.setIopsWriteRateMax(offering.getIopsWriteRateMax());
    offeringResponse.setIopsWriteRateMaxLength(offering.getIopsWriteRateMaxLength());
    Map<String, String> offeringDetails = ApiDBUtils.getResourceDetails(offering.getId(), ResourceObjectType.ServiceOffering);
    offeringResponse.setDetails(offeringDetails);
    offeringResponse.setObjectName("serviceoffering");
    offeringResponse.setIscutomized(offering.isDynamic());
    offeringResponse.setCacheMode(offering.getCacheMode());
    offeringResponse.setDynamicScalingEnabled(offering.isDynamicScalingEnabled());
    if (offeringDetails != null && !offeringDetails.isEmpty()) {
        String vsphereStoragePolicyId = offeringDetails.get(ApiConstants.STORAGE_POLICY);
        if (vsphereStoragePolicyId != null) {
            VsphereStoragePolicyVO vsphereStoragePolicyVO = _vsphereStoragePolicyDao.findById(Long.parseLong(vsphereStoragePolicyId));
            if (vsphereStoragePolicyVO != null)
                offeringResponse.setVsphereStoragePolicy(vsphereStoragePolicyVO.getName());
        }
    }
    long rootDiskSizeInGb = (long) offering.getRootDiskSize() / GB_TO_BYTES;
    offeringResponse.setRootDiskSize(rootDiskSizeInGb);
    offeringResponse.setDiskOfferingStrictness(offering.getDiskOfferingStrictness());
    DiskOfferingVO diskOfferingVO = ApiDBUtils.findDiskOfferingById(offering.getDiskOfferingId());
    if (diskOfferingVO != null) {
        offeringResponse.setDiskOfferingId(offering.getDiskOfferingUuid());
        offeringResponse.setDiskOfferingName(offering.getDiskOfferingName());
        offeringResponse.setDiskOfferingDisplayText(offering.getDiskOfferingDisplayText());
    }
    offeringResponse.setHasAnnotation(annotationDao.hasAnnotations(offering.getUuid(), AnnotationService.EntityType.SERVICE_OFFERING.name(), accountManager.isRootAdmin(CallContext.current().getCallingAccount().getId())));
    return offeringResponse;
}
Also used : ServiceOfferingResponse(org.apache.cloudstack.api.response.ServiceOfferingResponse) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) VsphereStoragePolicyVO(com.cloud.dc.VsphereStoragePolicyVO)

Example 20 with DiskOfferingVO

use of com.cloud.storage.DiskOfferingVO in project cloudstack by apache.

the class VirtualMachineManagerImpl method checkIfCanUpgrade.

@Override
public void checkIfCanUpgrade(final VirtualMachine vmInstance, final ServiceOffering newServiceOffering) {
    if (newServiceOffering == null) {
        throw new InvalidParameterValueException("Invalid parameter, newServiceOffering can't be null");
    }
    if (!(vmInstance.getState().equals(State.Stopped) || vmInstance.getState().equals(State.Running))) {
        s_logger.warn("Unable to upgrade virtual machine " + vmInstance.toString() + " in state " + vmInstance.getState());
        throw new InvalidParameterValueException("Unable to upgrade virtual machine " + vmInstance.toString() + " " + " in state " + vmInstance.getState() + "; make sure the virtual machine is stopped/running");
    }
    if (!newServiceOffering.isDynamic() && vmInstance.getServiceOfferingId() == newServiceOffering.getId()) {
        if (s_logger.isInfoEnabled()) {
            s_logger.info("Not upgrading vm " + vmInstance.toString() + " since it already has the requested " + "service offering (" + newServiceOffering.getName() + ")");
        }
        throw new InvalidParameterValueException("Not upgrading vm " + vmInstance.toString() + " since it already " + "has the requested service offering (" + newServiceOffering.getName() + ")");
    }
    final ServiceOfferingVO currentServiceOffering = _offeringDao.findByIdIncludingRemoved(vmInstance.getId(), vmInstance.getServiceOfferingId());
    final DiskOfferingVO currentDiskOffering = _diskOfferingDao.findByIdIncludingRemoved(currentServiceOffering.getDiskOfferingId());
    final DiskOfferingVO newDiskOffering = _diskOfferingDao.findById(newServiceOffering.getDiskOfferingId());
    checkIfNewOfferingStorageScopeMatchesStoragePool(vmInstance, newDiskOffering);
    if (currentServiceOffering.isSystemUse() != newServiceOffering.isSystemUse()) {
        throw new InvalidParameterValueException("isSystem property is different for current service offering and new service offering");
    }
    if (!isVirtualMachineUpgradable(vmInstance, newServiceOffering)) {
        throw new InvalidParameterValueException("Unable to upgrade virtual machine, not enough resources available " + "for an offering of " + newServiceOffering.getCpu() + " cpu(s) at " + newServiceOffering.getSpeed() + " Mhz, and " + newServiceOffering.getRamSize() + " MB of memory");
    }
    final List<String> currentTags = StringUtils.csvTagsToList(currentDiskOffering.getTags());
    final List<String> newTags = StringUtils.csvTagsToList(newDiskOffering.getTags());
    if (VolumeApiServiceImpl.MatchStoragePoolTagsWithDiskOffering.valueIn(vmInstance.getDataCenterId())) {
        if (!VolumeApiServiceImpl.doesNewDiskOfferingHasTagsAsOldDiskOffering(currentDiskOffering, newDiskOffering)) {
            throw new InvalidParameterValueException("Unable to upgrade virtual machine; the current service offering " + " should have tags as subset of " + "the new service offering tags. Current service offering tags: " + currentTags + "; " + "new service " + "offering tags: " + newTags);
        }
    }
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

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