Search in sources :

Example 6 with VMTemplateStoragePoolVO

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

the class SolidFirePrimaryDataStoreLifeCycle method deleteDataStore.

// invoked to delete primary storage that is based on the SolidFire plug-in
@Override
public boolean deleteDataStore(DataStore dataStore) {
    long storagePoolId = dataStore.getId();
    List<SnapshotVO> lstSnapshots = _snapshotDao.listAll();
    if (lstSnapshots != null) {
        for (SnapshotVO snapshot : lstSnapshots) {
            SnapshotDetailsVO snapshotDetails = _snapshotDetailsDao.findDetail(snapshot.getId(), SolidFireUtil.STORAGE_POOL_ID);
            // if this snapshot belongs to the storagePool that was passed in
            if (snapshotDetails != null && snapshotDetails.getValue() != null && Long.parseLong(snapshotDetails.getValue()) == storagePoolId) {
                throw new CloudRuntimeException("This primary storage cannot be deleted because it currently contains one or more snapshots.");
            }
        }
    }
    List<VMTemplateStoragePoolVO> lstTemplatePoolRefs = _tmpltPoolDao.listByPoolId(storagePoolId);
    if (lstTemplatePoolRefs != null) {
        for (VMTemplateStoragePoolVO templatePoolRef : lstTemplatePoolRefs) {
            try {
                SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, _storagePoolDetailsDao);
                long sfTemplateVolumeId = Long.parseLong(templatePoolRef.getLocalDownloadPath());
                SolidFireUtil.deleteVolume(sfConnection, sfTemplateVolumeId);
            } catch (Exception ex) {
                s_logger.error(ex.getMessage() != null ? ex.getMessage() : "Error deleting SolidFire template volume");
            }
            _tmpltPoolDao.remove(templatePoolRef.getId());
        }
    }
    StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId);
    storagePool.setUsedBytes(0);
    _storagePoolDao.update(storagePoolId, storagePool);
    _storagePoolDetailsDao.removeDetails(storagePoolId);
    return _dataStoreHelper.deletePrimaryDataStore(dataStore);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) SnapshotVO(com.cloud.storage.SnapshotVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) SolidFireUtil(org.apache.cloudstack.storage.datastore.util.SolidFireUtil) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 7 with VMTemplateStoragePoolVO

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

the class SolidFirePrimaryDataStoreDriver method deleteTemplate.

private void deleteTemplate(TemplateInfo template, long storagePoolId) {
    try {
        SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, storagePoolDetailsDao);
        long sfTemplateVolumeId = getVolumeIdFrom_iScsiPath(template.getInstallPath());
        SolidFireUtil.deleteVolume(sfConnection, sfTemplateVolumeId);
        VMTemplateStoragePoolVO templatePoolRef = tmpltPoolDao.findByPoolTemplate(storagePoolId, template.getId());
        tmpltPoolDao.remove(templatePoolRef.getId());
        StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
        // getUsedBytes(StoragePool) will not include the template to delete because the "template_spool_ref" table has already been updated by this point
        long usedBytes = getUsedBytes(storagePool);
        storagePool.setUsedBytes(usedBytes < 0 ? 0 : usedBytes);
        storagePoolDao.update(storagePoolId, storagePool);
    } catch (Exception ex) {
        LOGGER.debug(SolidFireUtil.LOG_PREFIX + "Failed to delete SolidFire template volume. CloudStack template ID: " + template.getId(), ex);
        throw ex;
    }
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) SolidFireUtil(org.apache.cloudstack.storage.datastore.util.SolidFireUtil) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 8 with VMTemplateStoragePoolVO

use of com.cloud.storage.VMTemplateStoragePoolVO 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.getTemplate(templatePoolRef.getTemplateId(), pool);
    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());
    }
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) Answer(com.cloud.agent.api.Answer) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) DestroyCommand(com.cloud.agent.api.storage.DestroyCommand) ExecutionException(java.util.concurrent.ExecutionException) TemplateApiResult(org.apache.cloudstack.engine.subsystem.api.storage.TemplateService.TemplateApiResult) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DB(com.cloud.utils.db.DB)

Example 9 with VMTemplateStoragePoolVO

use of com.cloud.storage.VMTemplateStoragePoolVO 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())).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);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) VMTemplateVO(com.cloud.storage.VMTemplateVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) Test(org.junit.Test)

Example 10 with VMTemplateStoragePoolVO

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

the class TemplateManagerImplTest method testTemplateScheduledForDownloadInDisabledPool.

@Test
public void testTemplateScheduledForDownloadInDisabledPool() {
    VMTemplateVO mockTemplate = mock(VMTemplateVO.class);
    StoragePoolVO mockPool = mock(StoragePoolVO.class);
    PrimaryDataStore mockPrimaryDataStore = mock(PrimaryDataStore.class);
    VMTemplateStoragePoolVO mockTemplateStore = mock(VMTemplateStoragePoolVO.class);
    when(mockPrimaryDataStore.getId()).thenReturn(2l);
    when(mockPool.getId()).thenReturn(2l);
    when(mockPool.getStatus()).thenReturn(StoragePoolStatus.Disabled);
    when(mockPool.getDataCenterId()).thenReturn(1l);
    when(mockTemplate.getId()).thenReturn(202l);
    when(mockTemplateStore.getDownloadState()).thenReturn(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
    when(vmTemplateDao.findById(anyLong())).thenReturn(mockTemplate);
    when(dataStoreManager.getPrimaryDataStore(anyLong())).thenReturn(mockPrimaryDataStore);
    when(vmTemplateDao.findById(anyLong(), anyBoolean())).thenReturn(mockTemplate);
    when(vmTemplatePoolDao.findByPoolTemplate(anyLong(), anyLong())).thenReturn(mockTemplateStore);
    when(primaryDataStoreDao.findById(anyLong())).thenReturn(mockPool);
    doNothing().when(mockTemplateStore).setMarkedForGC(anyBoolean());
    ExecutorService preloadExecutor = new CustomThreadPoolExecutor(8, 8, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new NamedThreadFactory("Template-Preloader"));
    templateManager._preloadExecutor = preloadExecutor;
    templateManager.prepareTemplate(202, 1, 2l);
    assertTrue("Test template is not scheduled for seeding on disabled pool", ((CustomThreadPoolExecutor) preloadExecutor).getCount() == 0);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) VMTemplateVO(com.cloud.storage.VMTemplateVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ExecutorService(java.util.concurrent.ExecutorService) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) Test(org.junit.Test)

Aggregations

VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)30 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 VMTemplateVO (com.cloud.storage.VMTemplateVO)9 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)9 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)8 DB (com.cloud.utils.db.DB)5 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)5 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 SolidFireUtil (org.apache.cloudstack.storage.datastore.util.SolidFireUtil)4 Answer (com.cloud.agent.api.Answer)3 SnapshotVO (com.cloud.storage.SnapshotVO)3 SnapshotDetailsVO (com.cloud.storage.dao.SnapshotDetailsVO)3 NamedThreadFactory (com.cloud.utils.concurrency.NamedThreadFactory)3 ExecutorService (java.util.concurrent.ExecutorService)3 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)3 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)3 SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)3 VolumeDataStoreVO (org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)3