use of org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore in project cloudstack by apache.
the class VolumeServiceImpl method copyManagedVolume.
private AsyncCallFuture<VolumeApiResult> copyManagedVolume(VolumeInfo srcVolume, DataStore destStore) {
AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<VolumeApiResult>();
VolumeApiResult res = new VolumeApiResult(srcVolume);
try {
if (!snapshotMgr.canOperateOnVolume(srcVolume)) {
s_logger.debug("There are snapshots creating for this volume, can not move this volume");
res.setResult("There are snapshots creating for this volume, can not move this volume");
future.complete(res);
return future;
}
if (snapshotMgr.backedUpSnapshotsExistsForVolume(srcVolume)) {
s_logger.debug("There are backed up snapshots for this volume, can not move.");
res.setResult("[UNSUPPORTED] There are backed up snapshots for this volume, can not move. Please try again after removing them.");
future.complete(res);
return future;
}
List<Long> poolIds = new ArrayList<Long>();
poolIds.add(srcVolume.getPoolId());
poolIds.add(destStore.getId());
Host hostWithPoolsAccess = _storageMgr.findUpAndEnabledHostWithAccessToStoragePools(poolIds);
if (hostWithPoolsAccess == null) {
s_logger.debug("No host(s) available with pool access, can not move this volume");
res.setResult("No host(s) available with pool access, can not move this volume");
future.complete(res);
return future;
}
VolumeVO destVol = duplicateVolumeOnAnotherStorage(srcVolume, (StoragePool) destStore);
VolumeInfo destVolume = volFactory.getVolume(destVol.getId(), destStore);
// Create a volume on managed storage.
AsyncCallFuture<VolumeApiResult> createVolumeFuture = createVolumeAsync(destVolume, destStore);
VolumeApiResult createVolumeResult = createVolumeFuture.get();
if (createVolumeResult.isFailed()) {
s_logger.debug("Failed to create dest volume " + destVolume.getId() + ", volume can be removed");
destroyVolume(destVolume.getId());
destVolume.processEvent(Event.ExpungeRequested);
destVolume.processEvent(Event.OperationSuccessed);
volDao.remove(destVolume.getId());
throw new CloudRuntimeException("Creation of a dest volume failed: " + createVolumeResult.getResult());
}
// Refresh the volume info from the DB.
destVolume = volFactory.getVolume(destVolume.getId(), destStore);
PrimaryDataStore srcPrimaryDataStore = (PrimaryDataStore) srcVolume.getDataStore();
if (srcPrimaryDataStore.isManaged()) {
Map<String, String> srcPrimaryDataStoreDetails = new HashMap<String, String>();
srcPrimaryDataStoreDetails.put(PrimaryDataStore.MANAGED, Boolean.TRUE.toString());
srcPrimaryDataStoreDetails.put(PrimaryDataStore.STORAGE_HOST, srcPrimaryDataStore.getHostAddress());
srcPrimaryDataStoreDetails.put(PrimaryDataStore.STORAGE_PORT, String.valueOf(srcPrimaryDataStore.getPort()));
srcPrimaryDataStoreDetails.put(PrimaryDataStore.MANAGED_STORE_TARGET, srcVolume.get_iScsiName());
srcPrimaryDataStoreDetails.put(PrimaryDataStore.MANAGED_STORE_TARGET_ROOT_VOLUME, srcVolume.getName());
srcPrimaryDataStoreDetails.put(PrimaryDataStore.VOLUME_SIZE, String.valueOf(srcVolume.getSize()));
srcPrimaryDataStoreDetails.put(StorageManager.STORAGE_POOL_DISK_WAIT.toString(), String.valueOf(StorageManager.STORAGE_POOL_DISK_WAIT.valueIn(srcPrimaryDataStore.getId())));
srcPrimaryDataStore.setDetails(srcPrimaryDataStoreDetails);
grantAccess(srcVolume, hostWithPoolsAccess, srcVolume.getDataStore());
}
PrimaryDataStore destPrimaryDataStore = (PrimaryDataStore) destStore;
Map<String, String> destPrimaryDataStoreDetails = new HashMap<String, String>();
destPrimaryDataStoreDetails.put(PrimaryDataStore.MANAGED, Boolean.TRUE.toString());
destPrimaryDataStoreDetails.put(PrimaryDataStore.STORAGE_HOST, destPrimaryDataStore.getHostAddress());
destPrimaryDataStoreDetails.put(PrimaryDataStore.STORAGE_PORT, String.valueOf(destPrimaryDataStore.getPort()));
destPrimaryDataStoreDetails.put(PrimaryDataStore.MANAGED_STORE_TARGET, destVolume.get_iScsiName());
destPrimaryDataStoreDetails.put(PrimaryDataStore.MANAGED_STORE_TARGET_ROOT_VOLUME, destVolume.getName());
destPrimaryDataStoreDetails.put(PrimaryDataStore.VOLUME_SIZE, String.valueOf(destVolume.getSize()));
destPrimaryDataStoreDetails.put(StorageManager.STORAGE_POOL_DISK_WAIT.toString(), String.valueOf(StorageManager.STORAGE_POOL_DISK_WAIT.valueIn(destPrimaryDataStore.getId())));
destPrimaryDataStore.setDetails(destPrimaryDataStoreDetails);
grantAccess(destVolume, hostWithPoolsAccess, destStore);
destVolume.processEvent(Event.CreateRequested);
srcVolume.processEvent(Event.MigrationRequested);
CopyManagedVolumeContext<VolumeApiResult> context = new CopyManagedVolumeContext<VolumeApiResult>(null, future, srcVolume, destVolume, hostWithPoolsAccess);
AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().copyManagedVolumeCallBack(null, null)).setContext(context);
motionSrv.copyAsync(srcVolume, destVolume, hostWithPoolsAccess, caller);
} catch (Exception e) {
s_logger.error("Copy to managed volume failed due to: " + e);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Copy to managed volume failed.", e);
}
res.setResult(e.toString());
future.complete(res);
}
return future;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore in project cloudstack by apache.
the class VolumeServiceImpl method volumeExistsOnPrimary.
private boolean volumeExistsOnPrimary(VolumeVO vol) {
Long poolId = vol.getPoolId();
if (poolId == null) {
return false;
}
PrimaryDataStore primaryStore = dataStoreMgr.getPrimaryDataStore(poolId);
if (primaryStore == null) {
return false;
}
if (primaryStore.isManaged()) {
return true;
}
String volumePath = vol.getPath();
if (volumePath == null || volumePath.trim().isEmpty()) {
return false;
}
return true;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore in project cloudstack by apache.
the class VolumeServiceImpl method createVolumeFromTemplateAsync.
@DB
@Override
public AsyncCallFuture<VolumeApiResult> createVolumeFromTemplateAsync(VolumeInfo volume, long dataStoreId, TemplateInfo template) {
PrimaryDataStore pd = dataStoreMgr.getPrimaryDataStore(dataStoreId);
TemplateInfo templateOnPrimaryStore = pd.getTemplate(template.getId(), volume.getDeployAsIsConfiguration());
AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
if (templateOnPrimaryStore == null) {
createBaseImageAsync(volume, pd, template, future);
return future;
}
createVolumeFromBaseImageAsync(volume, templateOnPrimaryStore, pd, future);
return future;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore in project cloudstack by apache.
the class TemplateManagerImpl method evictTemplateFromStoragePool.
@Override
@DB
public void evictTemplateFromStoragePool(VMTemplateStoragePoolVO templatePoolVO) {
// Need to hold the lock; otherwise, another thread may create a volume from the template at the same time.
// Assumption here is that we will hold the same lock during create volume from template.
VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolVO.getId());
if (templatePoolRef == null) {
s_logger.debug("Can't aquire the lock for template pool ref: " + templatePoolVO.getId());
return;
}
PrimaryDataStore pool = (PrimaryDataStore) _dataStoreMgr.getPrimaryDataStore(templatePoolVO.getPoolId());
TemplateInfo template = _tmplFactory.getTemplateOnPrimaryStorage(templatePoolRef.getTemplateId(), pool, templatePoolRef.getDeploymentOption());
try {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Evicting " + templatePoolVO);
}
if (pool.isManaged()) {
// For managed store, just delete the template volume.
AsyncCallFuture<TemplateApiResult> future = _tmpltSvr.deleteTemplateOnPrimary(template, pool);
TemplateApiResult result = future.get();
if (result.isFailed()) {
s_logger.debug("Failed to delete template " + template.getId() + " from storage pool " + pool.getId());
} else {
// Remove the templatePoolVO.
if (_tmpltPoolDao.remove(templatePoolVO.getId())) {
s_logger.debug("Successfully evicted template " + template.getName() + " from storage pool " + pool.getName());
}
}
} else {
DestroyCommand cmd = new DestroyCommand(pool, templatePoolVO);
Answer answer = _storageMgr.sendToPool(pool, cmd);
if (answer != null && answer.getResult()) {
// Remove the templatePoolVO.
if (_tmpltPoolDao.remove(templatePoolVO.getId())) {
s_logger.debug("Successfully evicted template " + template.getName() + " from storage pool " + pool.getName());
}
} else {
s_logger.info("Will retry evict template " + template.getName() + " from storage pool " + pool.getName());
}
}
} catch (StorageUnavailableException | InterruptedException | ExecutionException e) {
s_logger.info("Storage is unavailable currently. Will retry evicte template " + template.getName() + " from storage pool " + pool.getName());
} finally {
_tmpltPoolDao.releaseFromLockTable(templatePoolRef.getId());
}
}
use of org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore in project cloudstack by apache.
the class TemplateManagerImplTest method testPrepareTemplateNotDownloaded.
@Test
public void testPrepareTemplateNotDownloaded() {
VMTemplateVO mockTemplate = mock(VMTemplateVO.class);
when(mockTemplate.getId()).thenReturn(202l);
StoragePoolVO mockPool = mock(StoragePoolVO.class);
when(mockPool.getId()).thenReturn(2l);
PrimaryDataStore mockPrimaryDataStore = mock(PrimaryDataStore.class);
when(mockPrimaryDataStore.getId()).thenReturn(2l);
when(mockPrimaryDataStore.getDataCenterId()).thenReturn(1l);
when(dataStoreManager.getPrimaryDataStore(anyLong())).thenReturn(mockPrimaryDataStore);
when(vmTemplateDao.findById(anyLong(), anyBoolean())).thenReturn(mockTemplate);
when(vmTemplatePoolDao.findByPoolTemplate(anyLong(), anyLong(), nullable(String.class))).thenReturn(null);
when(templateDataStoreDao.findByTemplateZoneDownloadStatus(202l, 1l, VMTemplateStorageResourceAssoc.Status.DOWNLOADED)).thenReturn(null);
VMTemplateStoragePoolVO returnObject = templateManager.prepareTemplateForCreate(mockTemplate, (StoragePool) mockPrimaryDataStore);
assertTrue("Test template is not ready", returnObject == null);
}
Aggregations