Search in sources :

Example 1 with UserVmCloneSettingVO

use of com.cloud.vm.UserVmCloneSettingVO in project cloudstack by apache.

the class VolumeOrchestrator method prepare.

@Override
public void prepare(VirtualMachineProfile vm, DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException, ConcurrentOperationException, StorageAccessException {
    if (dest == null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("DeployDestination cannot be null, cannot prepare Volumes for the vm: " + vm);
        }
        throw new CloudRuntimeException("Unable to prepare Volume for vm because DeployDestination is null, vm:" + vm);
    }
    // don't allow to start vm that doesn't have a root volume
    if (_volsDao.findByInstanceAndType(vm.getId(), Volume.Type.ROOT).isEmpty()) {
        throw new CloudRuntimeException("Unable to prepare volumes for vm as ROOT volume is missing");
    }
    List<VolumeVO> vols = _volsDao.findUsableVolumesForInstance(vm.getId());
    List<VolumeTask> tasks = getTasks(vols, dest.getStorageForDisks(), vm);
    Volume vol = null;
    StoragePool pool;
    for (VolumeTask task : tasks) {
        if (task.type == VolumeTaskType.NOP) {
            vol = task.volume;
            pool = (StoragePool) dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary);
            // cluster. In that case, make sure that the volume is in the right access group.
            if (pool.isManaged()) {
                Host lastHost = _hostDao.findById(vm.getVirtualMachine().getLastHostId());
                Host host = _hostDao.findById(vm.getVirtualMachine().getHostId());
                long lastClusterId = lastHost == null || lastHost.getClusterId() == null ? -1 : lastHost.getClusterId();
                long clusterId = host == null || host.getClusterId() == null ? -1 : host.getClusterId();
                if (lastClusterId != clusterId) {
                    if (lastHost != null) {
                        storageMgr.removeStoragePoolFromCluster(lastHost.getId(), vol.get_iScsiName(), pool);
                        DataStore storagePool = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
                        volService.revokeAccess(volFactory.getVolume(vol.getId()), lastHost, storagePool);
                    }
                    try {
                        volService.grantAccess(volFactory.getVolume(vol.getId()), host, (DataStore) pool);
                    } catch (Exception e) {
                        throw new StorageAccessException("Unable to grant access to volume: " + vol.getId() + " on host: " + host.getId());
                    }
                } else {
                    // This might impact other managed storages, grant access for PowerFlex storage pool only
                    if (pool.getPoolType() == Storage.StoragePoolType.PowerFlex) {
                        try {
                            volService.grantAccess(volFactory.getVolume(vol.getId()), host, (DataStore) pool);
                        } catch (Exception e) {
                            throw new StorageAccessException("Unable to grant access to volume: " + vol.getId() + " on host: " + host.getId());
                        }
                    }
                }
            }
        } else if (task.type == VolumeTaskType.MIGRATE) {
            pool = (StoragePool) dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary);
            vol = migrateVolume(task.volume, pool);
        } else if (task.type == VolumeTaskType.RECREATE) {
            Pair<VolumeVO, DataStore> result = recreateVolume(task.volume, vm, dest);
            pool = (StoragePool) dataStoreMgr.getDataStore(result.second().getId(), DataStoreRole.Primary);
            vol = result.first();
        }
        VolumeInfo volumeInfo = volFactory.getVolume(vol.getId());
        DataTO volTO = volumeInfo.getTO();
        DiskTO disk = storageMgr.getDiskWithThrottling(volTO, vol.getVolumeType(), vol.getDeviceId(), vol.getPath(), vm.getServiceOfferingId(), vol.getDiskOfferingId());
        DataStore dataStore = dataStoreMgr.getDataStore(vol.getPoolId(), DataStoreRole.Primary);
        disk.setDetails(getDetails(volumeInfo, dataStore));
        vm.addDisk(disk);
        // If hypervisor is vSphere, check for clone type setting.
        if (vm.getHypervisorType().equals(HypervisorType.VMware)) {
            // retrieve clone flag.
            UserVmCloneType cloneType = UserVmCloneType.linked;
            Boolean value = CapacityManager.VmwareCreateCloneFull.valueIn(vol.getPoolId());
            if (value != null && value) {
                cloneType = UserVmCloneType.full;
            }
            UserVmCloneSettingVO cloneSettingVO = _vmCloneSettingDao.findByVmId(vm.getId());
            if (cloneSettingVO != null) {
                if (!cloneSettingVO.getCloneType().equals(cloneType.toString())) {
                    cloneSettingVO.setCloneType(cloneType.toString());
                    _vmCloneSettingDao.update(cloneSettingVO.getId(), cloneSettingVO);
                }
            } else {
                UserVmCloneSettingVO vmCloneSettingVO = new UserVmCloneSettingVO(vm.getId(), cloneType.toString());
                _vmCloneSettingDao.persist(vmCloneSettingVO);
            }
        }
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) Host(com.cloud.host.Host) StorageAccessException(com.cloud.exception.StorageAccessException) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) UserVmCloneSettingVO(com.cloud.vm.UserVmCloneSettingVO) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) InsufficientStorageCapacityException(com.cloud.exception.InsufficientStorageCapacityException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StorageAccessException(com.cloud.exception.StorageAccessException) ExecutionException(java.util.concurrent.ExecutionException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) DataTO(com.cloud.agent.api.to.DataTO) VolumeVO(com.cloud.storage.VolumeVO) VmWorkMigrateVolume(com.cloud.vm.VmWorkMigrateVolume) VmWorkAttachVolume(com.cloud.vm.VmWorkAttachVolume) Volume(com.cloud.storage.Volume) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 2 with UserVmCloneSettingVO

use of com.cloud.vm.UserVmCloneSettingVO in project cloudstack by apache.

the class CleanupFullyClonedTemplatesTask method markedForGc.

private boolean markedForGc(VMTemplateStoragePoolVO templateMapping, long zoneId) {
    boolean used = false;
    List<VMInstanceVO> vms = vmInstanceDao.listNonExpungedByZoneAndTemplate(zoneId, templateMapping.getTemplateId());
    for (VMInstanceVO vm : vms) {
        try {
            UserVmCloneSettingVO cloneSetting = cloneSettingDao.findByVmId(vm.getId());
            // VolumeOrchestrator or UserVmManagerImpl depending on version
            if (VolumeOrchestrator.UserVmCloneType.linked.equals(VolumeOrchestrator.UserVmCloneType.valueOf(cloneSetting.getCloneType()))) {
                used = true;
                break;
            }
        } catch (Exception e) {
            s_logger.error("failed to retrieve vm clone setting for vm " + vm.toString());
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("failed to retrieve vm clone setting for vm " + vm.toString(), e);
            }
        }
    }
    if (!used) {
        s_logger.info(mine.getName() + " is marking template with id " + templateMapping.getTemplateId() + " for gc in pool with id " + templateMapping.getPoolId());
        // else
        // mark it for removal from primary store
        templateMapping.setMarkedForGC(true);
    }
    return !used;
}
Also used : VMInstanceVO(com.cloud.vm.VMInstanceVO) UserVmCloneSettingVO(com.cloud.vm.UserVmCloneSettingVO)

Example 3 with UserVmCloneSettingVO

use of com.cloud.vm.UserVmCloneSettingVO in project cloudstack by apache.

the class UserVmCloneSettingDaoImplTest method makeEntry.

public void makeEntry(Long vmId, String cloneType) {
    UserVmCloneSettingVO vo = new UserVmCloneSettingVO(vmId, cloneType);
    _vmcsdao.persist(vo);
    vo = _vmcsdao.findById(vmId);
    assert (vo.getCloneType().equalsIgnoreCase(cloneType)) : "Unexpected Clone Type retrieved from table! Retrieved: " + vo.getCloneType() + " while expected was: " + cloneType;
    // Next test whether the record is retrieved by clone type.
    List<UserVmCloneSettingVO> voList = new ArrayList<UserVmCloneSettingVO>();
    voList = _vmcsdao.listByCloneType(cloneType);
    assert (voList != null && !voList.isEmpty()) : "Failed to retrieve any record of VMs by clone type!";
    // If a vo list is indeed retrieved, also check whether the vm id retrieved matches what we put in there.
    assert (voList.get(0).getVmId() == vmId) : "Retrieved vmId " + voList.get(0).getVmId() + " does not match input vmId: " + vmId;
}
Also used : ArrayList(java.util.ArrayList) UserVmCloneSettingVO(com.cloud.vm.UserVmCloneSettingVO)

Aggregations

UserVmCloneSettingVO (com.cloud.vm.UserVmCloneSettingVO)3 DataTO (com.cloud.agent.api.to.DataTO)1 DiskTO (com.cloud.agent.api.to.DiskTO)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 Host (com.cloud.host.Host)1 StoragePool (com.cloud.storage.StoragePool)1 Volume (com.cloud.storage.Volume)1 VolumeVO (com.cloud.storage.VolumeVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)1 VMInstanceVO (com.cloud.vm.VMInstanceVO)1 VmWorkAttachVolume (com.cloud.vm.VmWorkAttachVolume)1 VmWorkMigrateVolume (com.cloud.vm.VmWorkMigrateVolume)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 ConfigurationException (javax.naming.ConfigurationException)1