Search in sources :

Example 26 with VMTemplateStoragePoolVO

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

the class TemplateManagerImplTest method testPrepareTemplateIsSeeded.

@Test
public void testPrepareTemplateIsSeeded() {
    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);
    VMTemplateStoragePoolVO mockTemplateStore = mock(VMTemplateStoragePoolVO.class);
    when(mockTemplateStore.getDownloadState()).thenReturn(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
    when(dataStoreManager.getPrimaryDataStore(anyLong())).thenReturn(mockPrimaryDataStore);
    when(vmTemplateDao.findById(anyLong(), anyBoolean())).thenReturn(mockTemplate);
    when(vmTemplatePoolDao.findByPoolTemplate(anyLong(), anyLong())).thenReturn(mockTemplateStore);
    doNothing().when(mockTemplateStore).setMarkedForGC(anyBoolean());
    VMTemplateStoragePoolVO returnObject = templateManager.prepareTemplateForCreate(mockTemplate, (StoragePool) mockPrimaryDataStore);
    assertTrue("Test template is already seeded", returnObject == mockTemplateStore);
}
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 27 with VMTemplateStoragePoolVO

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

the class TemplateManagerImpl method getUnusedTemplatesInPool.

@Override
public List<VMTemplateStoragePoolVO> getUnusedTemplatesInPool(StoragePoolVO pool) {
    List<VMTemplateStoragePoolVO> unusedTemplatesInPool = new ArrayList<VMTemplateStoragePoolVO>();
    List<VMTemplateStoragePoolVO> allTemplatesInPool = _tmpltPoolDao.listByPoolId(pool.getId());
    for (VMTemplateStoragePoolVO templatePoolVO : allTemplatesInPool) {
        VMTemplateVO template = _tmpltDao.findByIdIncludingRemoved(templatePoolVO.getTemplateId());
        // If this is a routing template, consider it in use
        if (template.getTemplateType() == TemplateType.SYSTEM) {
            continue;
        }
        // use
        if (templatePoolVO.getDownloadState() != Status.DOWNLOADED) {
            continue;
        }
        if (template.getFormat() != ImageFormat.ISO && !_volumeDao.isAnyVolumeActivelyUsingTemplateOnPool(template.getId(), pool.getId())) {
            unusedTemplatesInPool.add(templatePoolVO);
        }
    }
    return unusedTemplatesInPool;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) ArrayList(java.util.ArrayList) VMTemplateVO(com.cloud.storage.VMTemplateVO)

Example 28 with VMTemplateStoragePoolVO

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

the class TemplateManagerImpl method resetTemplateDownloadStateOnPool.

@Override
@DB
public boolean resetTemplateDownloadStateOnPool(long templateStoragePoolRefId) {
    // have to use the same lock that prepareTemplateForCreate use to
    // maintain state consistency
    VMTemplateStoragePoolVO templateStoragePoolRef = _tmpltPoolDao.acquireInLockTable(templateStoragePoolRefId, 1200);
    if (templateStoragePoolRef == null) {
        s_logger.warn("resetTemplateDownloadStateOnPool failed - unable to lock TemplateStorgePoolRef " + templateStoragePoolRefId);
        return false;
    }
    try {
        templateStoragePoolRef.setTemplateSize(0);
        templateStoragePoolRef.setDownloadState(VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED);
        _tmpltPoolDao.update(templateStoragePoolRefId, templateStoragePoolRef);
    } finally {
        _tmpltPoolDao.releaseFromLockTable(templateStoragePoolRefId);
    }
    return true;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) DB(com.cloud.utils.db.DB)

Example 29 with VMTemplateStoragePoolVO

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

the class TemplateManagerImpl method prepareTemplateForCreate.

@Override
@DB
public VMTemplateStoragePoolVO prepareTemplateForCreate(VMTemplateVO templ, StoragePool pool) {
    VMTemplateVO template = _tmpltDao.findById(templ.getId(), true);
    long poolId = pool.getId();
    long templateId = template.getId();
    VMTemplateStoragePoolVO templateStoragePoolRef = null;
    TemplateDataStoreVO templateStoreRef = null;
    templateStoragePoolRef = _tmpltPoolDao.findByPoolTemplate(poolId, templateId);
    if (templateStoragePoolRef != null) {
        templateStoragePoolRef.setMarkedForGC(false);
        _tmpltPoolDao.update(templateStoragePoolRef.getId(), templateStoragePoolRef);
        if (templateStoragePoolRef.getDownloadState() == Status.DOWNLOADED) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Template " + templateId + " has already been downloaded to pool " + poolId);
            }
            return templateStoragePoolRef;
        }
    }
    templateStoreRef = _tmplStoreDao.findByTemplateZoneDownloadStatus(templateId, pool.getDataCenterId(), VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
    if (templateStoreRef == null) {
        s_logger.error("Unable to find a secondary storage host who has completely downloaded the template.");
        return null;
    }
    List<StoragePoolHostVO> vos = _poolHostDao.listByHostStatus(poolId, com.cloud.host.Status.Up);
    if (vos == null || vos.isEmpty()) {
        throw new CloudRuntimeException("Cannot download " + templateId + " to poolId " + poolId + " since there is no host in the Up state connected to this pool");
    }
    if (templateStoragePoolRef == null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Downloading template " + templateId + " to pool " + poolId);
        }
        DataStore srcSecStore = _dataStoreMgr.getDataStore(templateStoreRef.getDataStoreId(), DataStoreRole.Image);
        TemplateInfo srcTemplate = _tmplFactory.getTemplate(templateId, srcSecStore);
        AsyncCallFuture<TemplateApiResult> future = _tmpltSvr.prepareTemplateOnPrimary(srcTemplate, pool);
        try {
            TemplateApiResult result = future.get();
            if (result.isFailed()) {
                s_logger.debug("prepare template failed:" + result.getResult());
                return null;
            }
            return _tmpltPoolDao.findByPoolTemplate(poolId, templateId);
        } catch (Exception ex) {
            s_logger.debug("failed to copy template from image store:" + srcSecStore.getName() + " to primary storage");
        }
    }
    return null;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) TemplateApiResult(org.apache.cloudstack.engine.subsystem.api.storage.TemplateService.TemplateApiResult) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) URISyntaxException(java.net.URISyntaxException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) MalformedURLException(java.net.MalformedURLException) DB(com.cloud.utils.db.DB)

Example 30 with VMTemplateStoragePoolVO

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

the class SolidFirePrimaryDataStoreDriver method createTemplateVolume.

private String createTemplateVolume(TemplateInfo templateInfo, long storagePoolId) {
    verifySufficientBytesForStoragePool(templateInfo, storagePoolId);
    SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, storagePoolDetailsDao);
    long sfAccountId = getCreateSolidFireAccountId(sfConnection, templateInfo.getAccountId(), storagePoolId);
    SolidFireUtil.SolidFireVolume sfVolume = createSolidFireVolume(sfConnection, templateInfo, sfAccountId);
    String iqn = sfVolume.getIqn();
    VMTemplateStoragePoolVO templatePoolRef = tmpltPoolDao.findByPoolTemplate(storagePoolId, templateInfo.getId());
    templatePoolRef.setInstallPath(iqn);
    templatePoolRef.setLocalDownloadPath(Long.toString(sfVolume.getId()));
    templatePoolRef.setTemplateSize(sfVolume.getTotalSize());
    tmpltPoolDao.update(templatePoolRef.getId(), templatePoolRef);
    StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
    long capacityBytes = storagePool.getCapacityBytes();
    // getUsedBytes(StoragePool) will include the bytes of the newly created template volume because
    // _tmpltPoolDao.update(Long, VMTemplateStoragePoolVO) has already been invoked
    long usedBytes = getUsedBytes(storagePool);
    storagePool.setUsedBytes(usedBytes > capacityBytes ? capacityBytes : usedBytes);
    storagePoolDao.update(storagePoolId, storagePool);
    return iqn;
}
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)

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