Search in sources :

Example 1 with TemplateInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo in project cloudstack by apache.

the class VolumeOrchestrator method createVolume.

@DB
public VolumeInfo createVolume(VolumeInfo volume, VirtualMachine vm, VirtualMachineTemplate template, DataCenter dc, Pod pod, Long clusterId, ServiceOffering offering, DiskOffering diskOffering, List<StoragePool> avoids, long size, HypervisorType hyperType) {
    // update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
    volume = volService.updateHypervisorSnapshotReserveForVolume(diskOffering, volume.getId(), hyperType);
    StoragePool pool = null;
    DiskProfile dskCh = null;
    if (volume.getVolumeType() == Type.ROOT && Storage.ImageFormat.ISO != template.getFormat()) {
        dskCh = createDiskCharacteristics(volume, template, dc, offering);
        storageMgr.setDiskProfileThrottling(dskCh, offering, diskOffering);
    } else {
        dskCh = createDiskCharacteristics(volume, template, dc, diskOffering);
        storageMgr.setDiskProfileThrottling(dskCh, null, diskOffering);
    }
    if (diskOffering != null && diskOffering.isCustomized()) {
        dskCh.setSize(size);
    }
    dskCh.setHyperType(hyperType);
    final HashSet<StoragePool> avoidPools = new HashSet<StoragePool>(avoids);
    pool = findStoragePool(dskCh, dc, pod, clusterId, vm.getHostId(), vm, avoidPools);
    if (pool == null) {
        s_logger.warn("Unable to find suitable primary storage when creating volume " + volume.getName());
        throw new CloudRuntimeException("Unable to find suitable primary storage when creating volume " + volume.getName());
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Trying to create " + volume + " on " + pool);
    }
    DataStore store = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
    for (int i = 0; i < 2; i++) {
        // retry one more time in case of template reload is required for Vmware case
        AsyncCallFuture<VolumeApiResult> future = null;
        boolean isNotCreatedFromTemplate = volume.getTemplateId() == null ? true : false;
        if (isNotCreatedFromTemplate) {
            future = volService.createVolumeAsync(volume, store);
        } else {
            TemplateInfo templ = tmplFactory.getTemplate(template.getId(), DataStoreRole.Image);
            future = volService.createVolumeFromTemplateAsync(volume, store.getId(), templ);
        }
        try {
            VolumeApiResult result = future.get();
            if (result.isFailed()) {
                if (result.getResult().contains("request template reload") && (i == 0)) {
                    s_logger.debug("Retry template re-deploy for vmware");
                    continue;
                } else {
                    s_logger.debug("create volume failed: " + result.getResult());
                    throw new CloudRuntimeException("create volume failed:" + result.getResult());
                }
            }
            return result.getVolume();
        } catch (InterruptedException e) {
            s_logger.error("create volume failed", e);
            throw new CloudRuntimeException("create volume failed", e);
        } catch (ExecutionException e) {
            s_logger.error("create volume failed", e);
            throw new CloudRuntimeException("create volume failed", e);
        }
    }
    throw new CloudRuntimeException("create volume failed even after template re-deploy");
}
Also used : StoragePool(com.cloud.storage.StoragePool) VolumeApiResult(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult) DiskProfile(com.cloud.vm.DiskProfile) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet) DB(com.cloud.utils.db.DB)

Example 2 with TemplateInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo in project cloudstack by apache.

the class VolumeOrchestrator method recreateVolume.

private Pair<VolumeVO, DataStore> recreateVolume(VolumeVO vol, VirtualMachineProfile vm, DeployDestination dest) throws StorageUnavailableException {
    VolumeVO newVol;
    boolean recreate = RecreatableSystemVmEnabled.value();
    DataStore destPool = null;
    if (recreate && (dest.getStorageForDisks() == null || dest.getStorageForDisks().get(vol) == null)) {
        destPool = dataStoreMgr.getDataStore(vol.getPoolId(), DataStoreRole.Primary);
        s_logger.debug("existing pool: " + destPool.getId());
    } else {
        StoragePool pool = dest.getStorageForDisks().get(vol);
        destPool = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
    }
    if (vol.getState() == Volume.State.Allocated || vol.getState() == Volume.State.Creating) {
        newVol = vol;
    } else {
        newVol = switchVolume(vol, vm);
        // changed
        if (dest.getStorageForDisks() != null && dest.getStorageForDisks().containsKey(vol)) {
            StoragePool poolWithOldVol = dest.getStorageForDisks().get(vol);
            dest.getStorageForDisks().put(newVol, poolWithOldVol);
            dest.getStorageForDisks().remove(vol);
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Created new volume " + newVol + " for old volume " + vol);
        }
    }
    VolumeInfo volume = volFactory.getVolume(newVol.getId(), destPool);
    Long templateId = newVol.getTemplateId();
    for (int i = 0; i < 2; i++) {
        // retry one more time in case of template reload is required for Vmware case
        AsyncCallFuture<VolumeApiResult> future = null;
        if (templateId == null) {
            DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
            HypervisorType hyperType = vm.getVirtualMachine().getHypervisorType();
            // update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
            volService.updateHypervisorSnapshotReserveForVolume(diskOffering, volume.getId(), hyperType);
            volume = volFactory.getVolume(newVol.getId(), destPool);
            future = volService.createVolumeAsync(volume, destPool);
        } else {
            TemplateInfo templ = tmplFactory.getReadyTemplateOnImageStore(templateId, dest.getDataCenter().getId());
            if (templ == null) {
                s_logger.debug("can't find ready template: " + templateId + " for data center " + dest.getDataCenter().getId());
                throw new CloudRuntimeException("can't find ready template: " + templateId + " for data center " + dest.getDataCenter().getId());
            }
            PrimaryDataStore primaryDataStore = (PrimaryDataStore) destPool;
            if (primaryDataStore.isManaged()) {
                DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
                HypervisorType hyperType = vm.getVirtualMachine().getHypervisorType();
                // update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
                volService.updateHypervisorSnapshotReserveForVolume(diskOffering, volume.getId(), hyperType);
                long hostId = vm.getVirtualMachine().getHostId();
                future = volService.createManagedStorageVolumeFromTemplateAsync(volume, destPool.getId(), templ, hostId);
            } else {
                future = volService.createVolumeFromTemplateAsync(volume, destPool.getId(), templ);
            }
        }
        VolumeApiResult result;
        try {
            result = future.get();
            if (result.isFailed()) {
                if (result.getResult().contains("request template reload") && (i == 0)) {
                    s_logger.debug("Retry template re-deploy for vmware");
                    continue;
                } else {
                    s_logger.debug("Unable to create " + newVol + ":" + result.getResult());
                    throw new StorageUnavailableException("Unable to create " + newVol + ":" + result.getResult(), destPool.getId());
                }
            }
            StoragePoolVO storagePool = _storagePoolDao.findById(destPool.getId());
            if (storagePool.isManaged()) {
                long hostId = vm.getVirtualMachine().getHostId();
                Host host = _hostDao.findById(hostId);
                volService.grantAccess(volFactory.getVolume(newVol.getId()), host, destPool);
            }
            newVol = _volsDao.findById(newVol.getId());
            //break out of template-redeploy retry loop
            break;
        } catch (InterruptedException | ExecutionException e) {
            s_logger.error("Unable to create " + newVol, e);
            throw new StorageUnavailableException("Unable to create " + newVol + ":" + e.toString(), destPool.getId());
        }
    }
    return new Pair<VolumeVO, DataStore>(newVol, destPool);
}
Also used : StoragePool(com.cloud.storage.StoragePool) DiskOffering(com.cloud.offering.DiskOffering) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) Host(com.cloud.host.Host) VolumeApiResult(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) VolumeVO(com.cloud.storage.VolumeVO) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ExecutionException(java.util.concurrent.ExecutionException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) Pair(com.cloud.utils.Pair)

Example 3 with TemplateInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo in project cloudstack by apache.

the class VolumeServiceImpl method waitForTemplateDownloaded.

private TemplateInfo waitForTemplateDownloaded(PrimaryDataStore store, TemplateInfo template) {
    int storagePoolMaxWaitSeconds = NumbersUtil.parseInt(configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600);
    int sleepTime = 120;
    int tries = storagePoolMaxWaitSeconds / sleepTime;
    while (tries > 0) {
        TemplateInfo tmpl = store.getTemplate(template.getId());
        if (tmpl != null) {
            return tmpl;
        }
        try {
            Thread.sleep(sleepTime * 1000);
        } catch (InterruptedException e) {
            s_logger.debug("waiting for template download been interrupted: " + e.toString());
        }
        tries--;
    }
    return null;
}
Also used : TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint)

Example 4 with TemplateInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo in project cloudstack by apache.

the class VolumeServiceTest method createVolumeFromTemplate.

@Test(priority = 2)
public void createVolumeFromTemplate() {
    DataStore primaryStore = this.primaryStore;
    TemplateInfo te = createTemplate();
    VolumeVO volume = createVolume(te.getId(), primaryStore.getId());
    VolumeInfo vol = volumeFactory.getVolume(volume.getId(), primaryStore);
    // ve.createVolumeFromTemplate(primaryStore.getId(), new VHD(), te);
    AsyncCallFuture<VolumeApiResult> future = volumeService.createVolumeFromTemplateAsync(vol, primaryStore.getId(), te);
    try {
        future.get();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ExecutionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) VolumeVO(com.cloud.storage.VolumeVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) VolumeApiResult(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test)

Example 5 with TemplateInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo in project cloudstack by apache.

the class VolumeServiceTest method createTemplate.

private TemplateInfo createTemplate() {
    try {
        DataStore store = createImageStore();
        VMTemplateVO image = createImageData();
        TemplateInfo template = imageDataFactory.getTemplate(image.getId(), store);
        // AsyncCallFuture<TemplateApiResult> future =
        // imageService.createTemplateAsync(template, store);
        // future.get();
        template = imageDataFactory.getTemplate(image.getId(), store);
        /*
             * imageProviderMgr.configure("image Provider", new HashMap<String,
             * Object>()); VMTemplateVO image = createImageData();
             * ImageDataStoreProvider defaultProvider =
             * imageProviderMgr.getProvider("DefaultProvider");
             * ImageDataStoreLifeCycle lifeCycle =
             * defaultProvider.getLifeCycle(); ImageDataStore store =
             * lifeCycle.registerDataStore("defaultHttpStore", new
             * HashMap<String, String>());
             * imageService.registerTemplate(image.getId(),
             * store.getImageDataStoreId()); TemplateEntity te =
             * imageService.getTemplateEntity(image.getId()); return te;
             */
        return template;
    } catch (Exception e) {
        Assert.fail("failed", e);
        return null;
    }
}
Also used : TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) URISyntaxException(java.net.URISyntaxException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)49 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)25 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)19 VMTemplateVO (com.cloud.storage.VMTemplateVO)17 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)15 ExecutionException (java.util.concurrent.ExecutionException)13 TemplateApiResult (org.apache.cloudstack.engine.subsystem.api.storage.TemplateService.TemplateApiResult)13 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)11 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)9 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)9 AsyncCallFuture (org.apache.cloudstack.framework.async.AsyncCallFuture)9 Test (org.testng.annotations.Test)9 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)8 DB (com.cloud.utils.db.DB)7 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)6 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)6 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)6 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)5 HashSet (java.util.HashSet)5 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)5