Search in sources :

Example 51 with DiskOfferingVO

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

the class StorageSystemDataMotionStrategy method handleCreateVolumeFromSnapshotBothOnStorageSystem.

private void handleCreateVolumeFromSnapshotBothOnStorageSystem(SnapshotInfo snapshotInfo, VolumeInfo volumeInfo, AsyncCompletionCallback<CopyCommandResult> callback) {
    CopyCmdAnswer copyCmdAnswer = null;
    String errMsg = null;
    try {
        HostVO hostVO = getHost(snapshotInfo);
        boolean usingBackendSnapshot = usingBackendSnapshotFor(snapshotInfo);
        boolean computeClusterSupportsResign = clusterDao.getSupportsResigning(hostVO.getClusterId());
        if (usingBackendSnapshot && !computeClusterSupportsResign) {
            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);
        boolean useCloning = usingBackendSnapshot || (canStorageSystemCreateVolumeFromVolume && computeClusterSupportsResign);
        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 (useCloning) {
            copyCmdAnswer = performResignature(volumeInfo, hostVO);
        } 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(), false);
            copyCmdAnswer = performCopyOfVdi(volumeInfo, snapshotInfo, hostVO);
        }
        if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
            if (copyCmdAnswer != null && !StringUtils.isEmpty(copyCmdAnswer.getDetails())) {
                errMsg = copyCmdAnswer.getDetails();
            } else {
                errMsg = "Unable to create volume from snapshot";
            }
        }
    } catch (Exception ex) {
        errMsg = ex.getMessage() != null ? ex.getMessage() : "Copy operation failed in 'StorageSystemDataMotionStrategy.handleCreateVolumeFromSnapshotBothOnStorageSystem'";
    }
    CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
    result.setResult(errMsg);
    callback.complete(result);
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) VolumeDetailVO(com.cloud.storage.VolumeDetailVO) 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) TimeoutException(java.util.concurrent.TimeoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException)

Example 52 with DiskOfferingVO

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

the class CloudOrchestrator method createVirtualMachine.

@Override
public VirtualMachineEntity createVirtualMachine(String id, String owner, String templateId, String hostName, String displayName, String hypervisor, int cpu, int speed, long memory, Long diskSize, List<String> computeTags, List<String> rootDiskTags, Map<String, NicProfile> networkNicMap, DeploymentPlan plan, Long rootDiskSize) throws InsufficientCapacityException {
    // VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks,
    // vmEntityManager);
    LinkedHashMap<NetworkVO, List<? extends NicProfile>> networkIpMap = new LinkedHashMap<NetworkVO, List<? extends NicProfile>>();
    for (String uuid : networkNicMap.keySet()) {
        NetworkVO network = _networkDao.findByUuid(uuid);
        if (network != null) {
            networkIpMap.put(network, new ArrayList<NicProfile>(Arrays.asList(networkNicMap.get(uuid))));
        }
    }
    VirtualMachineEntityImpl vmEntity = ComponentContext.inject(VirtualMachineEntityImpl.class);
    vmEntity.init(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, new ArrayList<String>(networkNicMap.keySet()));
    HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor);
    //load vm instance and offerings and call virtualMachineManagerImpl
    VMInstanceVO vm = _vmDao.findByUuid(id);
    // If the template represents an ISO, a disk offering must be passed in, and will be used to create the root disk
    // Else, a disk offering is optional, and if present will be used to create the data disk
    DiskOfferingInfo rootDiskOfferingInfo = new DiskOfferingInfo();
    List<DiskOfferingInfo> dataDiskOfferings = new ArrayList<DiskOfferingInfo>();
    ServiceOfferingVO computeOffering = _serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
    rootDiskOfferingInfo.setDiskOffering(computeOffering);
    rootDiskOfferingInfo.setSize(rootDiskSize);
    if (computeOffering.isCustomizedIops() != null && computeOffering.isCustomizedIops()) {
        Map<String, String> userVmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
        if (userVmDetails != null) {
            String minIops = userVmDetails.get("minIops");
            String maxIops = userVmDetails.get("maxIops");
            rootDiskOfferingInfo.setMinIops(minIops != null && minIops.trim().length() > 0 ? Long.parseLong(minIops) : null);
            rootDiskOfferingInfo.setMaxIops(maxIops != null && maxIops.trim().length() > 0 ? Long.parseLong(maxIops) : null);
        }
    }
    if (vm.getDiskOfferingId() != null) {
        DiskOfferingVO diskOffering = _diskOfferingDao.findById(vm.getDiskOfferingId());
        if (diskOffering == null) {
            throw new InvalidParameterValueException("Unable to find disk offering " + vm.getDiskOfferingId());
        }
        Long size = null;
        if (diskOffering.getDiskSize() == 0) {
            size = diskSize;
            if (size == null) {
                throw new InvalidParameterValueException("Disk offering " + diskOffering + " requires size parameter.");
            }
            _volumeMgr.validateVolumeSizeRange(size * 1024 * 1024 * 1024);
        }
        DiskOfferingInfo dataDiskOfferingInfo = new DiskOfferingInfo();
        dataDiskOfferingInfo.setDiskOffering(diskOffering);
        dataDiskOfferingInfo.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");
                dataDiskOfferingInfo.setMinIops(minIops != null && minIops.trim().length() > 0 ? Long.parseLong(minIops) : null);
                dataDiskOfferingInfo.setMaxIops(maxIops != null && maxIops.trim().length() > 0 ? Long.parseLong(maxIops) : null);
            }
        }
        dataDiskOfferings.add(dataDiskOfferingInfo);
    }
    _itMgr.allocate(vm.getInstanceName(), _templateDao.findById(new Long(templateId)), computeOffering, rootDiskOfferingInfo, dataDiskOfferings, networkIpMap, plan, hypervisorType);
    return vmEntity;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) ArrayList(java.util.ArrayList) 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) ArrayList(java.util.ArrayList) List(java.util.List) DiskOfferingInfo(com.cloud.offering.DiskOfferingInfo)

Example 53 with DiskOfferingVO

use of com.cloud.storage.DiskOfferingVO in project cosmic by MissionCriticalCloud.

the class ManagementServerImpl method hasSuitablePoolsForVolume.

private boolean hasSuitablePoolsForVolume(final VolumeVO volume, final Host host, final VirtualMachineProfile vmProfile) {
    final DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
    final DiskProfile diskProfile = new DiskProfile(volume, diskOffering, vmProfile.getHypervisorType());
    final DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), null, null);
    final ExcludeList avoid = new ExcludeList();
    for (final StoragePoolAllocator allocator : _storagePoolAllocators) {
        final List<StoragePool> poolList = allocator.allocateToPool(diskProfile, vmProfile, plan, avoid, 1);
        if (poolList != null && !poolList.isEmpty()) {
            return true;
        }
    }
    return false;
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) StoragePool(com.cloud.storage.StoragePool) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) DiskProfile(com.cloud.vm.DiskProfile) StoragePoolAllocator(com.cloud.engine.subsystem.api.storage.StoragePoolAllocator)

Example 54 with DiskOfferingVO

use of com.cloud.storage.DiskOfferingVO in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method createDiskOffering.

protected DiskOfferingVO createDiskOffering(final Long userId, final Long domainId, final String name, final String description, final String provisioningType, final Long numGibibytes, String tags, boolean isCustomized, final boolean localStorageRequired, final boolean isDisplayOfferingEnabled, final Boolean isCustomizedIops, Long minIops, Long maxIops, Long bytesReadRate, Long bytesWriteRate, Long iopsReadRate, Long iopsWriteRate, final Integer hypervisorSnapshotReserve) {
    // special case for custom disk offerings
    long diskSize = 0;
    if (numGibibytes != null && numGibibytes <= 0) {
        throw new InvalidParameterValueException("Please specify a disk size of at least 1 Gb.");
    } else if (numGibibytes != null && numGibibytes > _maxVolumeSizeInGb) {
        throw new InvalidParameterValueException("The maximum size for a disk is " + _maxVolumeSizeInGb + " Gb.");
    }
    final ProvisioningType typedProvisioningType = ProvisioningType.getProvisioningType(provisioningType);
    if (numGibibytes != null) {
        diskSize = numGibibytes * 1024 * 1024 * 1024;
    }
    if (diskSize == 0) {
        isCustomized = true;
    }
    if (isCustomizedIops != null) {
        bytesReadRate = null;
        bytesWriteRate = null;
        iopsReadRate = null;
        iopsWriteRate = null;
        if (isCustomizedIops) {
            minIops = null;
            maxIops = null;
        } else {
            if (minIops == null && maxIops == null) {
                minIops = 0L;
                maxIops = 0L;
            } else {
                if (minIops == null || minIops <= 0) {
                    throw new InvalidParameterValueException("The min IOPS must be greater than 0.");
                }
                if (maxIops == null) {
                    maxIops = 0L;
                }
                if (minIops > maxIops) {
                    throw new InvalidParameterValueException("The min IOPS must be less than or equal to the max IOPS.");
                }
            }
        }
    } else {
        minIops = null;
        maxIops = null;
    }
    // Check if user exists in the system
    final User user = _userDao.findById(userId);
    if (user == null || user.getRemoved() != null) {
        throw new InvalidParameterValueException("Unable to find active user by id " + userId);
    }
    final Account account = _accountDao.findById(user.getAccountId());
    if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
        if (domainId == null) {
            throw new InvalidParameterValueException("Unable to create public disk offering by id " + userId + " because it is domain-admin");
        }
        if (tags != null) {
            throw new InvalidParameterValueException("Unable to create disk offering with storage tags by id " + userId + " because it is domain-admin");
        }
        if (!_domainDao.isChildDomain(account.getDomainId(), domainId)) {
            throw new InvalidParameterValueException("Unable to create disk offering by another domain admin with id " + userId);
        }
    } else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
        throw new InvalidParameterValueException("Unable to create disk offering by id " + userId + " because it is not root-admin or domain-admin");
    }
    tags = StringUtils.cleanupTags(tags);
    final DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, typedProvisioningType, diskSize, tags, isCustomized, isCustomizedIops, minIops, maxIops);
    newDiskOffering.setUseLocalStorage(localStorageRequired);
    newDiskOffering.setDisplayOffering(isDisplayOfferingEnabled);
    if (bytesReadRate != null && bytesReadRate > 0) {
        newDiskOffering.setBytesReadRate(bytesReadRate);
    }
    if (bytesWriteRate != null && bytesWriteRate > 0) {
        newDiskOffering.setBytesWriteRate(bytesWriteRate);
    }
    if (iopsReadRate != null && iopsReadRate > 0) {
        newDiskOffering.setIopsReadRate(iopsReadRate);
    }
    if (iopsWriteRate != null && iopsWriteRate > 0) {
        newDiskOffering.setIopsWriteRate(iopsWriteRate);
    }
    if (hypervisorSnapshotReserve != null && hypervisorSnapshotReserve < 0) {
        throw new InvalidParameterValueException("If provided, Hypervisor Snapshot Reserve must be greater than or equal to 0.");
    }
    newDiskOffering.setHypervisorSnapshotReserve(hypervisorSnapshotReserve);
    CallContext.current().setEventDetails("Disk offering id=" + newDiskOffering.getId());
    final DiskOfferingVO offering = _diskOfferingDao.persist(newDiskOffering);
    if (offering != null) {
        CallContext.current().setEventDetails("Disk offering id=" + newDiskOffering.getId());
        return offering;
    } else {
        return null;
    }
}
Also used : ProvisioningType(com.cloud.storage.Storage.ProvisioningType) Account(com.cloud.user.Account) User(com.cloud.user.User) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) DiskOfferingVO(com.cloud.storage.DiskOfferingVO)

Example 55 with DiskOfferingVO

use of com.cloud.storage.DiskOfferingVO in project cosmic by MissionCriticalCloud.

the class DiskOfferingDaoImpl method remove.

@Override
public boolean remove(final Long id) {
    final DiskOfferingVO diskOffering = createForUpdate();
    diskOffering.setRemoved(new Date());
    return update(id, diskOffering);
}
Also used : DiskOfferingVO(com.cloud.storage.DiskOfferingVO) Date(java.util.Date)

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