Search in sources :

Example 21 with VMTemplateStoragePoolVO

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

the class SolidFirePrimaryDataStoreDriver method getUsedBytes.

private long getUsedBytes(StoragePool storagePool, long volumeIdToIgnore) {
    long usedSpace = 0;
    List<VolumeVO> lstVolumes = volumeDao.findByPoolId(storagePool.getId(), null);
    if (lstVolumes != null) {
        for (VolumeVO volume : lstVolumes) {
            if (volume.getId() == volumeIdToIgnore) {
                continue;
            }
            VolumeDetailVO volumeDetail = volumeDetailsDao.findDetail(volume.getId(), SolidFireUtil.VOLUME_SIZE);
            if (volumeDetail != null && volumeDetail.getValue() != null) {
                long volumeSize = Long.parseLong(volumeDetail.getValue());
                usedSpace += volumeSize;
            } else {
                SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePool.getId(), storagePoolDetailsDao);
                try {
                    long lVolumeId = Long.parseLong(volume.getFolder());
                    SolidFireUtil.SolidFireVolume sfVolume = SolidFireUtil.getVolume(sfConnection, lVolumeId);
                    long volumeSize = sfVolume.getTotalSize();
                    // SolidFireUtil.VOLUME_SIZE was introduced in 4.5.
                    // To be backward compatible with releases prior to 4.5, call updateVolumeDetails here.
                    // That way if SolidFireUtil.VOLUME_SIZE wasn't put in the volume_details table when the
                    // volume was initially created, it can be placed in volume_details here.
                    updateVolumeDetails(volume.getId(), volumeSize);
                    usedSpace += volumeSize;
                } catch (NumberFormatException ex) {
                // can be ignored (the "folder" column didn't have a valid "long" in it (hasn't been placed there yet))
                }
            }
        }
    }
    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()) == storagePool.getId()) {
                snapshotDetails = snapshotDetailsDao.findDetail(snapshot.getId(), SolidFireUtil.VOLUME_SIZE);
                if (snapshotDetails != null && snapshotDetails.getValue() != null) {
                    long snapshotSize = Long.parseLong(snapshotDetails.getValue());
                    usedSpace += snapshotSize;
                }
            }
        }
    }
    List<VMTemplateStoragePoolVO> lstTemplatePoolRefs = tmpltPoolDao.listByPoolId(storagePool.getId());
    if (lstTemplatePoolRefs != null) {
        for (VMTemplateStoragePoolVO templatePoolRef : lstTemplatePoolRefs) {
            usedSpace += templatePoolRef.getTemplateSize();
        }
    }
    return usedSpace;
}
Also used : VolumeDetailVO(com.cloud.storage.VolumeDetailVO) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) SnapshotVO(com.cloud.storage.SnapshotVO) VolumeVO(com.cloud.storage.VolumeVO) SolidFireUtil(org.apache.cloudstack.storage.datastore.util.SolidFireUtil)

Example 22 with VMTemplateStoragePoolVO

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

the class SolidFirePrimaryDataStoreDriver method createClone.

private SolidFireUtil.SolidFireVolume createClone(SolidFireUtil.SolidFireConnection sfConnection, long dataObjectId, VolumeInfo volumeInfo, long sfAccountId, long storagePoolId, DataObjectType dataObjectType) {
    String sfNewVolumeName = volumeInfo.getName();
    long sfVolumeId = Long.MIN_VALUE;
    long sfSnapshotId = Long.MIN_VALUE;
    if (dataObjectType == DataObjectType.SNAPSHOT) {
        SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(dataObjectId, SolidFireUtil.SNAPSHOT_ID);
        if (snapshotDetails != null && snapshotDetails.getValue() != null) {
            sfSnapshotId = Long.parseLong(snapshotDetails.getValue());
        }
        snapshotDetails = snapshotDetailsDao.findDetail(dataObjectId, SolidFireUtil.VOLUME_ID);
        sfVolumeId = Long.parseLong(snapshotDetails.getValue());
    } else if (dataObjectType == DataObjectType.TEMPLATE) {
        // get the cached template on this storage
        VMTemplateStoragePoolVO templatePoolRef = tmpltPoolDao.findByPoolTemplate(storagePoolId, dataObjectId);
        if (templatePoolRef != null) {
            sfVolumeId = Long.parseLong(templatePoolRef.getLocalDownloadPath());
        }
    }
    if (sfVolumeId <= 0) {
        throw new CloudRuntimeException("Unable to find SolidFire volume for the following data-object ID: " + dataObjectId + " and data-object type: " + dataObjectType);
    }
    final long newSfVolumeId = SolidFireUtil.createClone(sfConnection, sfVolumeId, sfSnapshotId, sfAccountId, sfNewVolumeName, getVolumeAttributes(volumeInfo));
    final Iops iops = getIops(volumeInfo.getMinIops(), volumeInfo.getMaxIops(), storagePoolId);
    SolidFireUtil.modifyVolume(sfConnection, newSfVolumeId, null, null, iops.getMinIops(), iops.getMaxIops(), iops.getBurstIops());
    return SolidFireUtil.getVolume(sfConnection, newSfVolumeId);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO)

Example 23 with VMTemplateStoragePoolVO

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

the class CapacityManagerImpl method getAllocatedPoolCapacity.

@Override
public long getAllocatedPoolCapacity(StoragePoolVO pool, VMTemplateVO templateForVmCreation) {
    long totalAllocatedSize = 0;
    // in this case, call getUsedBytes(StoragePoolVO)
    if (pool.isManaged()) {
        return getUsedBytes(pool);
    } else {
        // Get size for all the non-destroyed volumes.
        Pair<Long, Long> sizes = _volumeDao.getNonDestroyedCountAndTotalByPool(pool.getId());
        totalAllocatedSize = sizes.second() + sizes.first() * _extraBytesPerVolume;
    }
    // Get size for VM Snapshots.
    totalAllocatedSize += _volumeDao.getVMSnapshotSizeByPool(pool.getId());
    boolean tmpInstalled = false;
    // Iterate through all templates on this storage pool.
    List<VMTemplateStoragePoolVO> templatePoolVOs = _templatePoolDao.listByPoolId(pool.getId());
    for (VMTemplateStoragePoolVO templatePoolVO : templatePoolVOs) {
        if ((templateForVmCreation != null) && !tmpInstalled && (templatePoolVO.getTemplateId() == templateForVmCreation.getId())) {
            tmpInstalled = true;
        }
        long templateSize = templatePoolVO.getTemplateSize();
        totalAllocatedSize += templateSize + _extraBytesPerVolume;
    }
    if ((templateForVmCreation != null) && !tmpInstalled) {
        long templateForVmCreationSize = templateForVmCreation.getSize() != null ? templateForVmCreation.getSize() : 0;
        totalAllocatedSize += templateForVmCreationSize + _extraBytesPerVolume;
    }
    return totalAllocatedSize;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO)

Example 24 with VMTemplateStoragePoolVO

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

the class TemplateManagerImplTest method testTemplateScheduledForDownloadInMultiplePool.

@Test
public void testTemplateScheduledForDownloadInMultiplePool() {
    VMTemplateVO mockTemplate = mock(VMTemplateVO.class);
    PrimaryDataStore mockPrimaryDataStore = mock(PrimaryDataStore.class);
    VMTemplateStoragePoolVO mockTemplateStore = mock(VMTemplateStoragePoolVO.class);
    List<StoragePoolVO> pools = new ArrayList<StoragePoolVO>();
    StoragePoolVO mockPool1 = mock(StoragePoolVO.class);
    when(mockPool1.getId()).thenReturn(2l);
    when(mockPool1.getStatus()).thenReturn(StoragePoolStatus.Up);
    when(mockPool1.getDataCenterId()).thenReturn(1l);
    StoragePoolVO mockPool2 = mock(StoragePoolVO.class);
    when(mockPool2.getId()).thenReturn(3l);
    when(mockPool2.getStatus()).thenReturn(StoragePoolStatus.Up);
    when(mockPool2.getDataCenterId()).thenReturn(1l);
    StoragePoolVO mockPool3 = mock(StoragePoolVO.class);
    when(mockPool3.getId()).thenReturn(4l);
    when(mockPool3.getStatus()).thenReturn(StoragePoolStatus.Up);
    when(mockPool3.getDataCenterId()).thenReturn(2l);
    pools.add(mockPool1);
    pools.add(mockPool2);
    pools.add(mockPool3);
    when(mockPrimaryDataStore.getId()).thenReturn(2l);
    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(2l)).thenReturn(mockPool1);
    when(primaryDataStoreDao.findById(3l)).thenReturn(mockPool2);
    when(primaryDataStoreDao.findById(4l)).thenReturn(mockPool3);
    when(primaryDataStoreDao.listByStatus(StoragePoolStatus.Up)).thenReturn(pools);
    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, null);
    assertTrue("Test template is scheduled for seeding to on pool", ((CustomThreadPoolExecutor) preloadExecutor).getCount() == 2);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) VMTemplateVO(com.cloud.storage.VMTemplateVO) ArrayList(java.util.ArrayList) 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)

Example 25 with VMTemplateStoragePoolVO

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

the class TemplateManagerImplTest method testTemplateScheduledForDownloadInOnePool.

@Test
public void testTemplateScheduledForDownloadInOnePool() {
    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.Up);
    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 scheduled for seeding to on pool", ((CustomThreadPoolExecutor) preloadExecutor).getCount() == 1);
}
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