Search in sources :

Example 1 with VolumeVO

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

the class VolumeOrchestrator method revokeAccess.

@Override
public void revokeAccess(long vmId, long hostId) {
    HostVO host = _hostDao.findById(hostId);
    List<VolumeVO> volumesForVm = _volsDao.findByInstance(vmId);
    if (volumesForVm != null) {
        for (VolumeVO volumeForVm : volumesForVm) {
            VolumeInfo volumeInfo = volFactory.getVolume(volumeForVm.getId());
            // pool id can be null for the VM's volumes in Allocated state
            if (volumeForVm.getPoolId() != null) {
                DataStore dataStore = dataStoreMgr.getDataStore(volumeForVm.getPoolId(), DataStoreRole.Primary);
                volService.revokeAccess(volumeInfo, host, dataStore);
            }
        }
    }
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) HostVO(com.cloud.host.HostVO)

Example 2 with VolumeVO

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

the class VolumeOrchestrator method prepareForMigration.

@Override
public void prepareForMigration(VirtualMachineProfile vm, DeployDestination dest) {
    List<VolumeVO> vols = _volsDao.findUsableVolumesForInstance(vm.getId());
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Preparing " + vols.size() + " volumes for " + vm);
    }
    for (VolumeVO vol : vols) {
        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 (vm.getType() == VirtualMachine.Type.User && vm.getTemplate().getFormat() == ImageFormat.ISO) {
    if (vm.getType() == VirtualMachine.Type.User) {
        _tmpltMgr.prepareIsoForVmProfile(vm);
    //DataTO dataTO = tmplFactory.getTemplate(vm.getTemplate().getId(), DataStoreRole.Image, vm.getVirtualMachine().getDataCenterId()).getTO();
    //DiskTO iso = new DiskTO(dataTO, 3L, null, Volume.Type.ISO);
    //vm.addDisk(iso);
    }
}
Also used : DataTO(com.cloud.agent.api.to.DataTO) VolumeVO(com.cloud.storage.VolumeVO) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 3 with VolumeVO

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

the class VolumeOrchestrator method getDetails.

private Map<String, String> getDetails(VolumeInfo volumeInfo, DataStore dataStore) {
    Map<String, String> details = new HashMap<String, String>();
    StoragePoolVO storagePool = _storagePoolDao.findById(dataStore.getId());
    details.put(DiskTO.MANAGED, String.valueOf(storagePool.isManaged()));
    details.put(DiskTO.STORAGE_HOST, storagePool.getHostAddress());
    details.put(DiskTO.STORAGE_PORT, String.valueOf(storagePool.getPort()));
    details.put(DiskTO.VOLUME_SIZE, String.valueOf(volumeInfo.getSize()));
    details.put(DiskTO.IQN, volumeInfo.get_iScsiName());
    details.put(DiskTO.MOUNT_POINT, volumeInfo.get_iScsiName());
    VolumeVO volume = _volumeDao.findById(volumeInfo.getId());
    details.put(DiskTO.PROTOCOL_TYPE, (volume.getPoolType() != null) ? volume.getPoolType().toString() : null);
    ChapInfo chapInfo = volService.getChapInfo(volumeInfo, dataStore);
    if (chapInfo != null) {
        details.put(DiskTO.CHAP_INITIATOR_USERNAME, chapInfo.getInitiatorUsername());
        details.put(DiskTO.CHAP_INITIATOR_SECRET, chapInfo.getInitiatorSecret());
        details.put(DiskTO.CHAP_TARGET_USERNAME, chapInfo.getTargetUsername());
        details.put(DiskTO.CHAP_TARGET_SECRET, chapInfo.getTargetSecret());
    }
    return details;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) HashMap(java.util.HashMap) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ChapInfo(org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo)

Example 4 with VolumeVO

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

the class VolumeOrchestrator method recreateVolume.

private Pair<VolumeVO, DataStore> recreateVolume(VolumeVO vol, VirtualMachineProfile vm, DeployDestination dest) throws StorageUnavailableException {
    VolumeVO newVol;
    boolean recreate = RecreatableSystemVmEnabled.value();
    DataStore destPool = null;
    if (recreate && (dest.getStorageForDisks() == null || dest.getStorageForDisks().get(vol) == null)) {
        destPool = dataStoreMgr.getDataStore(vol.getPoolId(), DataStoreRole.Primary);
        s_logger.debug("existing pool: " + destPool.getId());
    } else {
        StoragePool pool = dest.getStorageForDisks().get(vol);
        destPool = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
    }
    if (vol.getState() == Volume.State.Allocated || vol.getState() == Volume.State.Creating) {
        newVol = vol;
    } else {
        newVol = switchVolume(vol, vm);
        // changed
        if (dest.getStorageForDisks() != null && dest.getStorageForDisks().containsKey(vol)) {
            StoragePool poolWithOldVol = dest.getStorageForDisks().get(vol);
            dest.getStorageForDisks().put(newVol, poolWithOldVol);
            dest.getStorageForDisks().remove(vol);
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Created new volume " + newVol + " for old volume " + vol);
        }
    }
    VolumeInfo volume = volFactory.getVolume(newVol.getId(), destPool);
    Long templateId = newVol.getTemplateId();
    for (int i = 0; i < 2; i++) {
        // retry one more time in case of template reload is required for Vmware case
        AsyncCallFuture<VolumeApiResult> future = null;
        if (templateId == null) {
            DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
            HypervisorType hyperType = vm.getVirtualMachine().getHypervisorType();
            // update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
            volService.updateHypervisorSnapshotReserveForVolume(diskOffering, volume.getId(), hyperType);
            volume = volFactory.getVolume(newVol.getId(), destPool);
            future = volService.createVolumeAsync(volume, destPool);
        } else {
            TemplateInfo templ = tmplFactory.getReadyTemplateOnImageStore(templateId, dest.getDataCenter().getId());
            if (templ == null) {
                s_logger.debug("can't find ready template: " + templateId + " for data center " + dest.getDataCenter().getId());
                throw new CloudRuntimeException("can't find ready template: " + templateId + " for data center " + dest.getDataCenter().getId());
            }
            PrimaryDataStore primaryDataStore = (PrimaryDataStore) destPool;
            if (primaryDataStore.isManaged()) {
                DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
                HypervisorType hyperType = vm.getVirtualMachine().getHypervisorType();
                // update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
                volService.updateHypervisorSnapshotReserveForVolume(diskOffering, volume.getId(), hyperType);
                long hostId = vm.getVirtualMachine().getHostId();
                future = volService.createManagedStorageVolumeFromTemplateAsync(volume, destPool.getId(), templ, hostId);
            } else {
                future = volService.createVolumeFromTemplateAsync(volume, destPool.getId(), templ);
            }
        }
        VolumeApiResult result;
        try {
            result = future.get();
            if (result.isFailed()) {
                if (result.getResult().contains("request template reload") && (i == 0)) {
                    s_logger.debug("Retry template re-deploy for vmware");
                    continue;
                } else {
                    s_logger.debug("Unable to create " + newVol + ":" + result.getResult());
                    throw new StorageUnavailableException("Unable to create " + newVol + ":" + result.getResult(), destPool.getId());
                }
            }
            StoragePoolVO storagePool = _storagePoolDao.findById(destPool.getId());
            if (storagePool.isManaged()) {
                long hostId = vm.getVirtualMachine().getHostId();
                Host host = _hostDao.findById(hostId);
                volService.grantAccess(volFactory.getVolume(newVol.getId()), host, destPool);
            }
            newVol = _volsDao.findById(newVol.getId());
            //break out of template-redeploy retry loop
            break;
        } catch (InterruptedException | ExecutionException e) {
            s_logger.error("Unable to create " + newVol, e);
            throw new StorageUnavailableException("Unable to create " + newVol + ":" + e.toString(), destPool.getId());
        }
    }
    return new Pair<VolumeVO, DataStore>(newVol, destPool);
}
Also used : StoragePool(com.cloud.storage.StoragePool) DiskOffering(com.cloud.offering.DiskOffering) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) Host(com.cloud.host.Host) VolumeApiResult(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) VolumeVO(com.cloud.storage.VolumeVO) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ExecutionException(java.util.concurrent.ExecutionException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) Pair(com.cloud.utils.Pair)

Example 5 with VolumeVO

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

the class VolumeServiceImpl method managedCopyBaseImageCallback.

protected Void managedCopyBaseImageCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, ManagedCreateBaseImageContext<VolumeApiResult> context) {
    CopyCommandResult result = callback.getResult();
    VolumeInfo volumeInfo = context.getVolumeInfo();
    VolumeApiResult res = new VolumeApiResult(volumeInfo);
    if (result.isSuccess()) {
        // volumeInfo.processEvent(Event.OperationSuccessed, result.getAnswer());
        VolumeVO volume = volDao.findById(volumeInfo.getId());
        CopyCmdAnswer answer = (CopyCmdAnswer) result.getAnswer();
        TemplateObjectTO templateObjectTo = (TemplateObjectTO) answer.getNewData();
        volume.setPath(templateObjectTo.getPath());
        if (templateObjectTo.getFormat() != null) {
            volume.setFormat(templateObjectTo.getFormat());
        }
        volDao.update(volume.getId(), volume);
    } else {
        volumeInfo.processEvent(Event.DestroyRequested);
        res.setResult(result.getResult());
    }
    AsyncCallFuture<VolumeApiResult> future = context.getFuture();
    future.complete(res);
    return null;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Aggregations

VolumeVO (com.cloud.storage.VolumeVO)156 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)44 ArrayList (java.util.ArrayList)39 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)36 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)30 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)26 HostVO (com.cloud.host.HostVO)24 VMInstanceVO (com.cloud.vm.VMInstanceVO)24 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)22 Account (com.cloud.user.Account)19 HashMap (java.util.HashMap)17 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)16 VolumeApiResult (org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult)16 StoragePool (com.cloud.storage.StoragePool)15 HostPodVO (com.cloud.dc.HostPodVO)14 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)13 Pair (com.cloud.utils.Pair)13 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)11 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)11 DiskOfferingVO (com.cloud.storage.DiskOfferingVO)11