Search in sources :

Example 21 with TemplateInfo

use of com.cloud.engine.subsystem.api.storage.TemplateInfo in project cosmic by MissionCriticalCloud.

the class VolumeOrchestrator method recreateVolume.

private Pair<VolumeVO, DataStore> recreateVolume(final VolumeVO vol, final VirtualMachineProfile vm, final DeployDestination dest) throws StorageUnavailableException {
    VolumeVO newVol;
    final 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 {
        final 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)) {
            final 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);
    final 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<VolumeService.VolumeApiResult> future = null;
        if (templateId == null) {
            final DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
            final 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 {
            final TemplateInfo templ = tmplFactory.getReadyTemplateOnImageStore(templateId, dest.getZone().getId());
            if (templ == null) {
                s_logger.debug("can't find ready template: " + templateId + " for data center " + dest.getZone().getId());
                throw new CloudRuntimeException("can't find ready template: " + templateId + " for data center " + dest.getZone().getId());
            }
            final PrimaryDataStore primaryDataStore = (PrimaryDataStore) destPool;
            if (primaryDataStore.isManaged()) {
                final DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
                final 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);
                final long hostId = vm.getVirtualMachine().getHostId();
                future = volService.createManagedStorageAndVolumeFromTemplateAsync(volume, destPool.getId(), templ, hostId);
            } else {
                future = volService.createVolumeFromTemplateAsync(volume, destPool.getId(), templ);
            }
        }
        VolumeService.VolumeApiResult result = null;
        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());
                }
            }
            final StoragePoolVO storagePool = _storagePoolDao.findById(destPool.getId());
            if (storagePool.isManaged()) {
                final long hostId = vm.getVirtualMachine().getHostId();
                final 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 (final InterruptedException e) {
            s_logger.error("Unable to create " + newVol, e);
            throw new StorageUnavailableException("Unable to create " + newVol + ":" + e.toString(), destPool.getId());
        } catch (final ExecutionException e) {
            s_logger.error("Unable to create " + newVol, e);
            throw new StorageUnavailableException("Unable to create " + newVol + ":" + e.toString(), destPool.getId());
        }
    }
    return new Pair<>(newVol, destPool);
}
Also used : StoragePool(com.cloud.storage.StoragePool) DiskOffering(com.cloud.offering.DiskOffering) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) Host(com.cloud.host.Host) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) VolumeVO(com.cloud.storage.VolumeVO) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeService(com.cloud.engine.subsystem.api.storage.VolumeService) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ExecutionException(java.util.concurrent.ExecutionException) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) Pair(com.cloud.utils.Pair)

Example 22 with TemplateInfo

use of com.cloud.engine.subsystem.api.storage.TemplateInfo in project cosmic by MissionCriticalCloud.

the class VolumeOrchestrator method createVolume.

@DB
public VolumeInfo createVolume(VolumeInfo volume, final VirtualMachine vm, final VirtualMachineTemplate template, final DataCenter dc, final Pod pod, final Long clusterId, final ServiceOffering offering, final DiskOffering diskOffering, final List<StoragePool> avoids, final long size, final 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);
    } else {
        dskCh = createDiskCharacteristics(volume, template, dc, diskOffering);
    }
    if (diskOffering != null && diskOffering.isCustomized()) {
        dskCh.setSize(size);
    }
    dskCh.setHyperType(hyperType);
    final HashSet<StoragePool> avoidPools = new HashSet<>(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);
    }
    final 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<VolumeService.VolumeApiResult> future = null;
        final boolean isNotCreatedFromTemplate = volume.getTemplateId() == null ? true : false;
        if (isNotCreatedFromTemplate) {
            future = volService.createVolumeAsync(volume, store);
        } else {
            final TemplateInfo templ = tmplFactory.getTemplate(template.getId(), DataStoreRole.Image);
            future = volService.createVolumeFromTemplateAsync(volume, store.getId(), templ);
        }
        try {
            final VolumeService.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 (final InterruptedException e) {
            s_logger.error("create volume failed", e);
            throw new CloudRuntimeException("create volume failed", e);
        } catch (final 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) DiskProfile(com.cloud.vm.DiskProfile) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeService(com.cloud.engine.subsystem.api.storage.VolumeService) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet) DB(com.cloud.utils.db.DB)

Example 23 with TemplateInfo

use of com.cloud.engine.subsystem.api.storage.TemplateInfo in project cosmic by MissionCriticalCloud.

the class TemplateServiceImpl method syncTemplateCallBack.

protected Void syncTemplateCallBack(final AsyncCallbackDispatcher<TemplateServiceImpl, CopyCommandResult> callback, final TemplateOpContext<TemplateApiResult> context) {
    final TemplateInfo destTemplate = context.getTemplate();
    final CopyCommandResult result = callback.getResult();
    final AsyncCallFuture<TemplateApiResult> future = context.getFuture();
    final TemplateApiResult res = new TemplateApiResult(destTemplate);
    try {
        if (result.isFailed()) {
            res.setResult(result.getResult());
        // no change to existing template_store_ref, will try to re-sync later if other call triggers this sync operation, like copy template
        } else {
            // this will update install path properly, next time it will not sync anymore.
            destTemplate.processEvent(Event.OperationSuccessed, result.getAnswer());
        }
        future.complete(res);
    } catch (final Exception e) {
        s_logger.debug("Failed to process sync template callback", e);
        res.setResult(e.toString());
        future.complete(res);
    }
    return null;
}
Also used : TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 24 with TemplateInfo

use of com.cloud.engine.subsystem.api.storage.TemplateInfo in project cosmic by MissionCriticalCloud.

the class TemplateServiceImpl method copyTemplateCrossZoneCallBack.

protected Void copyTemplateCrossZoneCallBack(final AsyncCallbackDispatcher<TemplateServiceImpl, CreateCmdResult> callback, final TemplateOpContext<TemplateApiResult> context) {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Performing copy template cross zone callback after completion");
    }
    final TemplateInfo destTemplate = context.getTemplate();
    final CreateCmdResult result = callback.getResult();
    final AsyncCallFuture<TemplateApiResult> future = context.getFuture();
    final TemplateApiResult res = new TemplateApiResult(destTemplate);
    try {
        if (result.isFailed()) {
            res.setResult(result.getResult());
            destTemplate.processEvent(Event.OperationFailed);
        } else {
            destTemplate.processEvent(Event.OperationSuccessed, result.getAnswer());
        }
        future.complete(res);
    } catch (final Exception e) {
        s_logger.debug("Failed to process copy template cross zones callback", e);
        res.setResult(e.toString());
        future.complete(res);
    }
    return null;
}
Also used : TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 25 with TemplateInfo

use of com.cloud.engine.subsystem.api.storage.TemplateInfo in project cosmic by MissionCriticalCloud.

the class TemplateServiceImpl method copyTemplateCallBack.

protected Void copyTemplateCallBack(final AsyncCallbackDispatcher<TemplateServiceImpl, CopyCommandResult> callback, final TemplateOpContext<TemplateApiResult> context) {
    final TemplateInfo destTemplate = context.getTemplate();
    final CopyCommandResult result = callback.getResult();
    final AsyncCallFuture<TemplateApiResult> future = context.getFuture();
    final TemplateApiResult res = new TemplateApiResult(destTemplate);
    try {
        if (result.isFailed()) {
            res.setResult(result.getResult());
            destTemplate.processEvent(Event.OperationFailed);
        } else {
            destTemplate.processEvent(Event.OperationSuccessed, result.getAnswer());
        }
        future.complete(res);
    } catch (final Exception e) {
        s_logger.debug("Failed to process copy template callback", e);
        res.setResult(e.toString());
        future.complete(res);
    }
    return null;
}
Also used : TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

TemplateInfo (com.cloud.engine.subsystem.api.storage.TemplateInfo)30 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)15 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)12 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)11 VMTemplateVO (com.cloud.storage.VMTemplateVO)10 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)8 TemplateApiResult (com.cloud.engine.subsystem.api.storage.TemplateService.TemplateApiResult)7 ExecutionException (java.util.concurrent.ExecutionException)7 DB (com.cloud.utils.db.DB)6 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)6 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)5 HashSet (java.util.HashSet)5 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)4 CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)4 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)4 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)4 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)3 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)3 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3