Search in sources :

Example 1 with PrimaryDataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore in project cloudstack by apache.

the class VolumeOrchestrator method recreateVolume.

private Pair<VolumeVO, DataStore> recreateVolume(VolumeVO vol, VirtualMachineProfile vm, DeployDestination dest) throws StorageUnavailableException, StorageAccessException {
    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;
        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());
            PrimaryDataStore primaryDataStore = (PrimaryDataStore) destPool;
            if (templ == null) {
                if (tmplFactory.isTemplateMarkedForDirectDownload(templateId)) {
                    // Template is marked for direct download bypassing Secondary Storage
                    if (!primaryDataStore.isManaged()) {
                        templ = tmplFactory.getReadyBypassedTemplateOnPrimaryStore(templateId, destPool.getId(), dest.getHost().getId());
                    } else {
                        s_logger.debug("Direct download template: " + templateId + " on host: " + dest.getHost().getId() + " and copy to the managed storage pool: " + destPool.getId());
                        templ = volService.createManagedStorageTemplate(templateId, destPool.getId(), dest.getHost().getId());
                    }
                    if (templ == null) {
                        s_logger.debug("Failed to spool direct download template: " + templateId + " for data center " + dest.getDataCenter().getId());
                        throw new CloudRuntimeException("Failed to spool direct download template: " + templateId + " for data center " + dest.getDataCenter().getId());
                    }
                } else {
                    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());
                }
            }
            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);
                try {
                    volService.grantAccess(volFactory.getVolume(newVol.getId()), host, destPool);
                } catch (Exception e) {
                    throw new StorageAccessException("Unable to grant access to volume: " + newVol.getId() + " on host: " + host.getId());
                }
            }
            newVol = _volsDao.findById(newVol.getId());
            // break out of template-redeploy retry loop
            break;
        } catch (StorageAccessException e) {
            throw e;
        } 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) StorageAccessException(com.cloud.exception.StorageAccessException) VolumeApiResult(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult) 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) 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 2 with PrimaryDataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore 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));
        PrimaryDataStore primaryDataStore = (PrimaryDataStore) dataStore;
        // This might impact other managed storages, grant access for PowerFlex storage pool only
        if (primaryDataStore.isManaged() && primaryDataStore.getPoolType() == Storage.StoragePoolType.PowerFlex) {
            volService.grantAccess(volFactory.getVolume(vol.getId()), dest.getHost(), dataStore);
        }
        vm.addDisk(disk);
    }
    // if (vm.getType() == VirtualMachine.Type.User && vm.getTemplate().getFormat() == ImageFormat.ISO) {
    if (vm.getType() == VirtualMachine.Type.User) {
        _tmpltMgr.prepareIsoForVmProfile(vm, dest);
    // 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) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)

Example 3 with PrimaryDataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore in project cloudstack by apache.

the class ScaleIOPrimaryDataStoreLifeCycleTest method testDeleteDataStore.

@Test
public void testDeleteDataStore() {
    final PrimaryDataStore store = mock(PrimaryDataStore.class);
    final StoragePoolVO storagePoolVO = mock(StoragePoolVO.class);
    when(primaryDataStoreDao.findById(anyLong())).thenReturn(storagePoolVO);
    List<VMTemplateStoragePoolVO> unusedTemplates = new ArrayList<>();
    when(templateMgr.getUnusedTemplatesInPool(storagePoolVO)).thenReturn(unusedTemplates);
    List<StoragePoolHostVO> poolHostVOs = new ArrayList<>();
    when(storagePoolHostDao.listByPoolId(anyLong())).thenReturn(poolHostVOs);
    when(dataStoreHelper.deletePrimaryDataStore(any(DataStore.class))).thenReturn(true);
    final boolean result = scaleIOPrimaryDataStoreLifeCycleTest.deleteDataStore(store);
    assertThat(result).isTrue();
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ArrayList(java.util.ArrayList) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with PrimaryDataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore in project cloudstack by apache.

the class SnapshotServiceImpl method revertSnapshot.

@Override
public boolean revertSnapshot(SnapshotInfo snapshot) {
    SnapshotInfo snapshotOnPrimaryStore = _snapshotFactory.getSnapshot(snapshot.getId(), DataStoreRole.Primary);
    if (snapshotOnPrimaryStore == null) {
        throw new CloudRuntimeException("Cannot find an entry for snapshot " + snapshot.getId() + " on primary storage pools");
    }
    PrimaryDataStore store = (PrimaryDataStore) snapshotOnPrimaryStore.getDataStore();
    AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
    RevertSnapshotContext<CommandResult> context = new RevertSnapshotContext<CommandResult>(null, snapshot, future);
    AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().revertSnapshotCallback(null, null)).setContext(context);
    ((PrimaryDataStoreDriver) store.getDriver()).revertSnapshot(snapshot, snapshotOnPrimaryStore, caller);
    SnapshotResult result = null;
    try {
        result = future.get();
        if (result.isFailed()) {
            throw new CloudRuntimeException(result.getResult());
        }
        return true;
    } catch (InterruptedException e) {
        s_logger.debug("revert snapshot is failed: " + e.toString());
    } catch (ExecutionException e) {
        s_logger.debug("revert snapshot is failed: " + e.toString());
    }
    return false;
}
Also used : SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)

Example 5 with PrimaryDataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore in project cloudstack by apache.

the class VolumeServiceImpl method deleteVolumeCallback.

public Void deleteVolumeCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CommandResult> callback, DeleteVolumeContext<VolumeApiResult> context) {
    CommandResult result = callback.getResult();
    VolumeObject vo = context.getVolume();
    VolumeApiResult apiResult = new VolumeApiResult(vo);
    try {
        if (result.isSuccess()) {
            vo.processEvent(Event.OperationSuccessed);
            if (canVolumeBeRemoved(vo.getId())) {
                s_logger.info("Volume " + vo.getId() + " is not referred anywhere, remove it from volumes table");
                volDao.remove(vo.getId());
            }
            SnapshotDataStoreVO snapStoreVo = _snapshotStoreDao.findByVolume(vo.getId(), DataStoreRole.Primary);
            if (snapStoreVo != null) {
                long storagePoolId = snapStoreVo.getDataStoreId();
                StoragePoolVO storagePoolVO = storagePoolDao.findById(storagePoolId);
                if (storagePoolVO.isManaged()) {
                    DataStore primaryDataStore = dataStoreMgr.getPrimaryDataStore(storagePoolId);
                    Map<String, String> mapCapabilities = primaryDataStore.getDriver().getCapabilities();
                    String value = mapCapabilities.get(DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString());
                    Boolean supportsStorageSystemSnapshots = new Boolean(value);
                    if (!supportsStorageSystemSnapshots) {
                        _snapshotStoreDao.remove(snapStoreVo.getId());
                    }
                } else {
                    _snapshotStoreDao.remove(snapStoreVo.getId());
                }
            }
        } else {
            vo.processEvent(Event.OperationFailed);
            apiResult.setResult(result.getResult());
        }
    } catch (Exception e) {
        s_logger.debug("ignore delete volume status update failure, it will be picked up by storage clean up thread later", e);
    }
    context.getFuture().complete(apiResult);
    return null;
}
Also used : PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StorageAccessException(com.cloud.exception.StorageAccessException) ExecutionException(java.util.concurrent.ExecutionException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CommandResult(org.apache.cloudstack.storage.command.CommandResult)

Aggregations

PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)25 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)14 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)13 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)9 ExecutionException (java.util.concurrent.ExecutionException)8 Test (org.junit.Test)8 VMTemplateVO (com.cloud.storage.VMTemplateVO)7 VolumeVO (com.cloud.storage.VolumeVO)7 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)7 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)6 StorageAccessException (com.cloud.exception.StorageAccessException)6 Host (com.cloud.host.Host)6 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)6 Answer (com.cloud.agent.api.Answer)5 AsyncCallFuture (org.apache.cloudstack.framework.async.AsyncCallFuture)5 ArrayList (java.util.ArrayList)4 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)3 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)3