Search in sources :

Example 1 with Type

use of com.cloud.storage.Volume.Type in project cloudstack by apache.

the class VolumeOrchestrator method allocateTemplatedVolumes.

@Override
public List<DiskProfile> allocateTemplatedVolumes(Type type, String name, DiskOffering offering, Long rootDisksize, Long minIops, Long maxIops, VirtualMachineTemplate template, VirtualMachine vm, Account owner) {
    int volumesNumber = 1;
    List<DatadiskTO> templateAsIsDisks = null;
    String configurationId = null;
    boolean deployVmAsIs = false;
    if (template.isDeployAsIs() && vm.getType() != VirtualMachine.Type.SecondaryStorageVm) {
        List<SecondaryStorageVmVO> runningSSVMs = secondaryStorageVmDao.getSecStorageVmListInStates(null, vm.getDataCenterId(), State.Running);
        if (CollectionUtils.isEmpty(runningSSVMs)) {
            s_logger.info("Could not find a running SSVM in datacenter " + vm.getDataCenterId() + " for deploying VM as is, " + "not deploying VM " + vm.getInstanceName() + " as-is");
        } else {
            UserVmDetailVO configurationDetail = userVmDetailsDao.findDetail(vm.getId(), VmDetailConstants.DEPLOY_AS_IS_CONFIGURATION);
            if (configurationDetail != null) {
                configurationId = configurationDetail.getValue();
            }
            templateAsIsDisks = _tmpltMgr.getTemplateDisksOnImageStore(template.getId(), DataStoreRole.Image, configurationId);
            if (CollectionUtils.isNotEmpty(templateAsIsDisks)) {
                templateAsIsDisks = templateAsIsDisks.stream().filter(x -> !x.isIso()).sorted(Comparator.comparing(DatadiskTO::getDiskNumber)).collect(Collectors.toList());
            }
            volumesNumber = templateAsIsDisks.size();
            deployVmAsIs = true;
        }
    }
    if (volumesNumber < 1) {
        throw new CloudRuntimeException("Unable to create any volume from template " + template.getName());
    }
    List<DiskProfile> profiles = new ArrayList<>();
    for (int number = 0; number < volumesNumber; number++) {
        String volumeName = name;
        Long volumeSize = rootDisksize;
        long deviceId = type.equals(Type.ROOT) ? 0L : 1L;
        if (deployVmAsIs) {
            int volumeNameSuffix = templateAsIsDisks.get(number).getDiskNumber();
            volumeName = String.format("%s-%d", volumeName, volumeNameSuffix);
            volumeSize = templateAsIsDisks.get(number).getVirtualSize();
            deviceId = templateAsIsDisks.get(number).getDiskNumber();
        }
        s_logger.info(String.format("adding disk object %s to %s", volumeName, vm.getInstanceName()));
        DiskProfile diskProfile = allocateTemplatedVolume(type, volumeName, offering, volumeSize, minIops, maxIops, template, vm, owner, deviceId, configurationId);
        profiles.add(diskProfile);
    }
    handleRootDiskControllerTpeForDeployAsIs(templateAsIsDisks, vm);
    return profiles;
}
Also used : UserVmCloneSettingVO(com.cloud.vm.UserVmCloneSettingVO) UsageEventUtils(com.cloud.event.UsageEventUtils) HostDao(com.cloud.host.dao.HostDao) VolumeService(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService) Pod(com.cloud.dc.Pod) Transaction(com.cloud.utils.db.Transaction) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) TemplateDataStoreDao(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao) StringUtils(org.apache.commons.lang3.StringUtils) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) SnapshotDao(com.cloud.storage.dao.SnapshotDao) DiskOffering(com.cloud.offering.DiskOffering) Map(java.util.Map) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator) Storage(com.cloud.storage.Storage) StorageStrategyFactory(org.apache.cloudstack.engine.subsystem.api.storage.StorageStrategyFactory) CapacityManager(com.cloud.capacity.CapacityManager) VolumeOrchestrationService(org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService) DataTO(com.cloud.agent.api.to.DataTO) TransactionStatus(com.cloud.utils.db.TransactionStatus) DiskProfile(com.cloud.vm.DiskProfile) Set(java.util.Set) ScopeType(com.cloud.storage.ScopeType) MigrateVolumeCmd(org.apache.cloudstack.api.command.user.volume.MigrateVolumeCmd) ServiceOffering(com.cloud.offering.ServiceOffering) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) ManagerBase(com.cloud.utils.component.ManagerBase) InsufficientStorageCapacityException(com.cloud.exception.InsufficientStorageCapacityException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) SnapshotStrategy(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy) AsyncJobVO(org.apache.cloudstack.framework.jobs.impl.AsyncJobVO) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) ArrayList(java.util.ArrayList) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) REQUEST_TEMPLATE_RELOAD(com.cloud.storage.resource.StorageProcessor.REQUEST_TEMPLATE_RELOAD) DiskOfferingDetailsDao(org.apache.cloudstack.resourcedetail.dao.DiskOfferingDetailsDao) SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) UserVmDetailVO(com.cloud.vm.UserVmDetailVO) StorageAccessException(com.cloud.exception.StorageAccessException) VmWorkTakeVolumeSnapshot(com.cloud.vm.VmWorkTakeVolumeSnapshot) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) VMTemplateStorageResourceAssoc(com.cloud.storage.VMTemplateStorageResourceAssoc) UserVm(com.cloud.uservm.UserVm) DatadiskTO(com.cloud.agent.api.to.DatadiskTO) UserVmCloneSettingDao(com.cloud.vm.dao.UserVmCloneSettingDao) UserVmDao(com.cloud.vm.dao.UserVmDao) DB(com.cloud.utils.db.DB) SnapshotService(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotService) ClusterManager(com.cloud.cluster.ClusterManager) ExecutionException(java.util.concurrent.ExecutionException) VolumeDataFactory(org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) SnapshotManager(com.cloud.storage.snapshot.SnapshotManager) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) Host(com.cloud.host.Host) ImageFormat(com.cloud.storage.Storage.ImageFormat) PodAllocator(com.cloud.agent.manager.allocator.PodAllocator) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) StorageManager(com.cloud.storage.StorageManager) DataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver) TemplateDataFactory(org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory) TemplateManager(com.cloud.template.TemplateManager) Date(java.util.Date) SnapshotDataFactory(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory) StoragePool(com.cloud.storage.StoragePool) ConfigDepot(org.apache.cloudstack.framework.config.ConfigDepot) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceType(com.cloud.configuration.Resource.ResourceType) Cluster(com.cloud.org.Cluster) Type(com.cloud.storage.Volume.Type) Logger(org.apache.log4j.Logger) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) SnapshotDataStoreDao(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao) CommandResult(org.apache.cloudstack.storage.command.CommandResult) VolumeDetailVO(com.cloud.storage.VolumeDetailVO) SnapshotOperation(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy.SnapshotOperation) ResourceLimitService(com.cloud.user.ResourceLimitService) VolumeDetailsDao(com.cloud.storage.dao.VolumeDetailsDao) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) VmWorkSerializer(com.cloud.vm.VmWorkSerializer) PrimaryDataStoreDao(org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao) VMInstanceVO(com.cloud.vm.VMInstanceVO) TransactionCallback(com.cloud.utils.db.TransactionCallback) StateMachine2(com.cloud.utils.fsm.StateMachine2) State(com.cloud.vm.VirtualMachine.State) DeployDestination(com.cloud.deploy.DeployDestination) Account(com.cloud.user.Account) UUID(java.util.UUID) Pair(com.cloud.utils.Pair) Collectors(java.util.stream.Collectors) VirtualMachineProfileImpl(com.cloud.vm.VirtualMachineProfileImpl) VmWorkMigrateVolume(com.cloud.vm.VmWorkMigrateVolume) List(java.util.List) MigrateVolumeCmdByAdmin(org.apache.cloudstack.api.command.admin.volume.MigrateVolumeCmdByAdmin) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) Optional(java.util.Optional) StoragePoolType(com.cloud.storage.Storage.StoragePoolType) VirtualMachine(com.cloud.vm.VirtualMachine) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) AsyncJobManager(org.apache.cloudstack.framework.jobs.AsyncJobManager) EntityManager(com.cloud.utils.db.EntityManager) VolumeApiService(com.cloud.storage.VolumeApiService) DataStoreManager(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) HashMap(java.util.HashMap) ConfigurationException(javax.naming.ConfigurationException) EventTypes(com.cloud.event.EventTypes) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ConfigKey(org.apache.cloudstack.framework.config.ConfigKey) VmDetailConstants(com.cloud.vm.VmDetailConstants) DataStoreCapabilities(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreCapabilities) CollectionUtils(org.apache.commons.collections.CollectionUtils) UserVmDetailsDao(com.cloud.vm.dao.UserVmDetailsDao) ChapInfo(org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo) Configurable(org.apache.cloudstack.framework.config.Configurable) VolumeDao(com.cloud.storage.dao.VolumeDao) Snapshot(com.cloud.storage.Snapshot) DataCenter(com.cloud.dc.DataCenter) VmWorkAttachVolume(com.cloud.vm.VmWorkAttachVolume) HostVO(com.cloud.host.HostVO) MapUtils(org.apache.commons.collections.MapUtils) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) DiskTO(com.cloud.agent.api.to.DiskTO) NumbersUtil.toHumanReadableSize(com.cloud.utils.NumbersUtil.toHumanReadableSize) TemplateService(org.apache.cloudstack.engine.subsystem.api.storage.TemplateService) UserVmVO(com.cloud.vm.UserVmVO) MigrateVMCmd(org.apache.cloudstack.api.command.admin.vm.MigrateVMCmd) DataStoreRole(com.cloud.storage.DataStoreRole) VolumeApiResult(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult) DiskOfferingDetailVO(org.apache.cloudstack.resourcedetail.DiskOfferingDetailVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VMTemplateDetailsDao(com.cloud.storage.dao.VMTemplateDetailsDao) SecondaryStorageVmDao(com.cloud.vm.dao.SecondaryStorageVmDao) Volume(com.cloud.storage.Volume) Comparator(java.util.Comparator) VolumeVO(com.cloud.storage.VolumeVO) SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) ArrayList(java.util.ArrayList) DiskProfile(com.cloud.vm.DiskProfile) UserVmDetailVO(com.cloud.vm.UserVmDetailVO) DatadiskTO(com.cloud.agent.api.to.DatadiskTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

DataTO (com.cloud.agent.api.to.DataTO)1 DatadiskTO (com.cloud.agent.api.to.DatadiskTO)1 DiskTO (com.cloud.agent.api.to.DiskTO)1 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)1 PodAllocator (com.cloud.agent.manager.allocator.PodAllocator)1 CapacityManager (com.cloud.capacity.CapacityManager)1 ClusterManager (com.cloud.cluster.ClusterManager)1 ResourceType (com.cloud.configuration.Resource.ResourceType)1 DataCenter (com.cloud.dc.DataCenter)1 Pod (com.cloud.dc.Pod)1 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)1 DeployDestination (com.cloud.deploy.DeployDestination)1 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)1 EventTypes (com.cloud.event.EventTypes)1 UsageEventUtils (com.cloud.event.UsageEventUtils)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InsufficientStorageCapacityException (com.cloud.exception.InsufficientStorageCapacityException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 StorageAccessException (com.cloud.exception.StorageAccessException)1 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)1