Search in sources :

Example 46 with ImageStoreVO

use of org.apache.cloudstack.storage.datastore.db.ImageStoreVO in project cloudstack by apache.

the class SystemVmTemplateRegistration method getNfsStoreInZone.

private Pair<String, Long> getNfsStoreInZone(Long zoneId) {
    String url = null;
    Long storeId = null;
    ImageStoreVO storeVO = imageStoreDao.findOneByZoneAndProtocol(zoneId, "nfs");
    if (storeVO == null) {
        String errMsg = String.format("Failed to fetch NFS store in zone = %s for SystemVM template registration", zoneId);
        LOGGER.error(errMsg);
        throw new CloudRuntimeException(errMsg);
    }
    url = storeVO.getUrl();
    storeId = storeVO.getId();
    return new Pair<>(url, storeId);
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) Pair(com.cloud.utils.Pair)

Example 47 with ImageStoreVO

use of org.apache.cloudstack.storage.datastore.db.ImageStoreVO in project cloudstack by apache.

the class StorageCacheManagerImpl method getCacheStores.

protected List<DataStore> getCacheStores() {
    QueryBuilder<ImageStoreVO> sc = QueryBuilder.create(ImageStoreVO.class);
    sc.and(sc.entity().getRole(), SearchCriteria.Op.EQ, DataStoreRole.ImageCache);
    List<ImageStoreVO> imageStoreVOs = sc.list();
    List<DataStore> stores = new ArrayList<DataStore>();
    for (ImageStoreVO vo : imageStoreVOs) {
        stores.add(dataStoreManager.getDataStore(vo.getId(), vo.getRole()));
    }
    return stores;
}
Also used : DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO)

Example 48 with ImageStoreVO

use of org.apache.cloudstack.storage.datastore.db.ImageStoreVO in project cloudstack by apache.

the class StorageCacheReplacementAlgorithmLRUTest method testSelectObject.

@Test
public void testSelectObject() {
    cacheReplacementAlgorithm.setUnusedTimeInterval(1);
    try {
        VMTemplateVO template = new VMTemplateVO();
        template.setTemplateType(Storage.TemplateType.USER);
        template.setUrl(UUID.randomUUID().toString());
        template.setUniqueName(UUID.randomUUID().toString());
        template.setName(UUID.randomUUID().toString());
        template.setPublicTemplate(true);
        template.setFeatured(true);
        template.setRequiresHvm(true);
        template.setBits(64);
        template.setFormat(Storage.ImageFormat.VHD);
        template.setEnablePassword(true);
        template.setEnableSshKey(true);
        template.setGuestOSId(1);
        template.setBootable(true);
        template.setPrepopulate(true);
        template.setCrossZones(true);
        template.setExtractable(true);
        template = templateDao.persist(template);
        VMTemplateVO template2 = new VMTemplateVO();
        template2.setTemplateType(Storage.TemplateType.USER);
        template2.setUrl(UUID.randomUUID().toString());
        template2.setUniqueName(UUID.randomUUID().toString());
        template2.setName(UUID.randomUUID().toString());
        template2.setPublicTemplate(true);
        template2.setFeatured(true);
        template2.setRequiresHvm(true);
        template2.setBits(64);
        template2.setFormat(Storage.ImageFormat.VHD);
        template2.setEnablePassword(true);
        template2.setEnableSshKey(true);
        template2.setGuestOSId(1);
        template2.setBootable(true);
        template2.setPrepopulate(true);
        template2.setCrossZones(true);
        template2.setExtractable(true);
        template2 = templateDao.persist(template2);
        ImageStoreVO imageStoreVO = new ImageStoreVO();
        imageStoreVO.setRole(DataStoreRole.ImageCache);
        imageStoreVO.setName(UUID.randomUUID().toString());
        imageStoreVO.setProviderName(DataStoreProvider.NFS_IMAGE);
        imageStoreVO.setProtocol("nfs");
        imageStoreVO.setUrl(UUID.randomUUID().toString());
        imageStoreVO = imageStoreDao.persist(imageStoreVO);
        Calendar cal = Calendar.getInstance();
        cal.setTime(DateUtil.now());
        cal.add(Calendar.DAY_OF_MONTH, -2);
        Date date = cal.getTime();
        TemplateDataStoreVO templateStoreVO1 = new TemplateDataStoreVO();
        templateStoreVO1.setLastUpdated(date);
        templateStoreVO1.setDataStoreRole(DataStoreRole.ImageCache);
        templateStoreVO1.setDataStoreId(imageStoreVO.getId());
        templateStoreVO1.setState(ObjectInDataStoreStateMachine.State.Ready);
        templateStoreVO1.setCopy(true);
        templateStoreVO1.setTemplateId(template.getId());
        templateDataStoreDao.persist(templateStoreVO1);
        TemplateDataStoreVO templateStoreVO2 = new TemplateDataStoreVO();
        templateStoreVO2.setLastUpdated(date);
        templateStoreVO2.setDataStoreRole(DataStoreRole.ImageCache);
        templateStoreVO2.setDataStoreId(imageStoreVO.getId());
        templateStoreVO2.setState(ObjectInDataStoreStateMachine.State.Ready);
        templateStoreVO2.setCopy(true);
        templateStoreVO2.setTemplateId(template2.getId());
        templateDataStoreDao.persist(templateStoreVO2);
        DataStore store = dataStoreManager.getDataStore(imageStoreVO.getId(), DataStoreRole.ImageCache);
        Assert.assertNotNull(cacheReplacementAlgorithm.chooseOneToBeReplaced(store));
    } catch (Exception e) {
        Assert.fail();
    }
}
Also used : Calendar(java.util.Calendar) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) Date(java.util.Date) Test(org.junit.Test)

Example 49 with ImageStoreVO

use of org.apache.cloudstack.storage.datastore.db.ImageStoreVO in project cloudstack by apache.

the class ImageStoreProviderManagerImpl method listImageStoreByProvider.

@Override
public List<DataStore> listImageStoreByProvider(String provider) {
    List<ImageStoreVO> stores = dataStoreDao.findByProvider(provider);
    List<DataStore> imageStores = new ArrayList<DataStore>();
    for (ImageStoreVO store : stores) {
        imageStores.add(getImageStore(store.getId()));
    }
    return imageStores;
}
Also used : DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO)

Example 50 with ImageStoreVO

use of org.apache.cloudstack.storage.datastore.db.ImageStoreVO in project cloudstack by apache.

the class ImageStoreProviderManagerImpl method listImageStores.

@Override
public List<DataStore> listImageStores() {
    List<ImageStoreVO> stores = dataStoreDao.listImageStores();
    List<DataStore> imageStores = new ArrayList<DataStore>();
    for (ImageStoreVO store : stores) {
        imageStores.add(getImageStore(store.getId()));
    }
    return imageStores;
}
Also used : DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO)

Aggregations

ImageStoreVO (org.apache.cloudstack.storage.datastore.db.ImageStoreVO)55 ArrayList (java.util.ArrayList)19 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)18 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)17 DataCenterVO (com.cloud.dc.DataCenterVO)12 Account (com.cloud.user.Account)12 HashMap (java.util.HashMap)12 HostVO (com.cloud.host.HostVO)11 HostPodVO (com.cloud.dc.HostPodVO)10 VMTemplateVO (com.cloud.storage.VMTemplateVO)10 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 ClusterVO (com.cloud.dc.ClusterVO)8 Map (java.util.Map)8 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)8 Test (org.junit.Test)8 VolumeVO (com.cloud.storage.VolumeVO)6 VMInstanceVO (com.cloud.vm.VMInstanceVO)6 Random (java.util.Random)6 DataStoreProvider (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider)6 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)6