Search in sources :

Example 11 with StorageUnavailableException

use of com.cloud.legacymodel.exceptions.StorageUnavailableException in project cosmic by MissionCriticalCloud.

the class TemplateManagerImpl method copy.

@Override
@DB
public boolean copy(final long userId, final VMTemplateVO template, final DataStore srcSecStore, final DataCenterVO dstZone) throws StorageUnavailableException, ResourceAllocationException {
    final long tmpltId = template.getId();
    final long dstZoneId = dstZone.getId();
    // find all eligible image stores for the destination zone
    final List<DataStore> dstSecStores = this._dataStoreMgr.getImageStoresByScope(new ZoneScope(dstZoneId));
    if (dstSecStores == null || dstSecStores.isEmpty()) {
        throw new StorageUnavailableException("Destination zone is not ready, no image store associated", DataCenter.class, dstZone.getId());
    }
    final AccountVO account = this._accountDao.findById(template.getAccountId());
    // find the size of the template to be copied
    final TemplateDataStoreVO srcTmpltStore = this._tmplStoreDao.findByStoreTemplate(srcSecStore.getId(), tmpltId);
    this._resourceLimitMgr.checkResourceLimit(account, ResourceType.template);
    this._resourceLimitMgr.checkResourceLimit(account, ResourceType.secondary_storage, new Long(srcTmpltStore.getSize()).longValue());
    // Event details
    final String copyEventType;
    if (template.getFormat().equals(ImageFormat.ISO)) {
        copyEventType = EventTypes.EVENT_ISO_COPY;
    } else {
        copyEventType = EventTypes.EVENT_TEMPLATE_COPY;
    }
    final TemplateInfo srcTemplate = this._tmplFactory.getTemplate(template.getId(), srcSecStore);
    // for that zone
    for (final DataStore dstSecStore : dstSecStores) {
        final TemplateDataStoreVO dstTmpltStore = this._tmplStoreDao.findByStoreTemplate(dstSecStore.getId(), tmpltId);
        if (dstTmpltStore != null && dstTmpltStore.getDownloadState() == VMTemplateStatus.DOWNLOADED) {
            // already downloaded on this image store
            return true;
        }
        if (dstTmpltStore != null && dstTmpltStore.getDownloadState() != VMTemplateStatus.DOWNLOAD_IN_PROGRESS) {
            this._tmplStoreDao.removeByTemplateStore(tmpltId, dstSecStore.getId());
        }
        final AsyncCallFuture<TemplateApiResult> future = this._tmpltSvr.copyTemplate(srcTemplate, dstSecStore);
        try {
            final TemplateApiResult result = future.get();
            if (result.isFailed()) {
                s_logger.debug("copy template failed for image store " + dstSecStore.getName() + ":" + result.getResult());
                // try next image store
                continue;
            }
            this._tmpltDao.addTemplateToZone(template, dstZoneId);
            return true;
        } catch (final Exception ex) {
            s_logger.debug("failed to copy template to image store:" + dstSecStore.getName() + " ,will try next one");
        }
    }
    return false;
}
Also used : TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) AccountVO(com.cloud.user.AccountVO) TemplateApiResult(com.cloud.engine.subsystem.api.storage.TemplateService.TemplateApiResult) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) PermissionDeniedException(com.cloud.legacymodel.exceptions.PermissionDeniedException) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) ExecutionException(java.util.concurrent.ExecutionException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(javax.naming.ConfigurationException) StorageUnavailableException(com.cloud.legacymodel.exceptions.StorageUnavailableException) MalformedURLException(java.net.MalformedURLException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) StorageUnavailableException(com.cloud.legacymodel.exceptions.StorageUnavailableException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) DB(com.cloud.utils.db.DB)

Example 12 with StorageUnavailableException

use of com.cloud.legacymodel.exceptions.StorageUnavailableException in project cosmic by MissionCriticalCloud.

the class TemplateManagerImpl method evictTemplateFromStoragePool.

@Override
@DB
public void evictTemplateFromStoragePool(final VMTemplateStoragePoolVO templatePoolVO) {
    // Need to hold the lock, otherwise, another thread may create a volume from the template at the same time.
    // Assumption here is that, we will hold the same lock during create volume from template
    final VMTemplateStoragePoolVO templatePoolRef = this._tmpltPoolDao.acquireInLockTable(templatePoolVO.getId());
    if (templatePoolRef == null) {
        s_logger.debug("can't aquire the lock for template pool ref:" + templatePoolVO.getId());
        return;
    }
    try {
        final StoragePool pool = (StoragePool) this._dataStoreMgr.getPrimaryDataStore(templatePoolVO.getPoolId());
        final VMTemplateVO template = this._tmpltDao.findByIdIncludingRemoved(templatePoolVO.getTemplateId());
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Evicting " + templatePoolVO);
        }
        final DestroyCommand cmd = new DestroyCommand(pool, templatePoolVO);
        try {
            final Answer answer = this._storageMgr.sendToPool(pool, cmd);
            if (answer != null && answer.getResult()) {
                // Remove the templatePoolVO
                if (this._tmpltPoolDao.remove(templatePoolVO.getId())) {
                    s_logger.debug("Successfully evicted template: " + template.getName() + " from storage pool: " + pool.getName());
                }
            } else {
                s_logger.info("Will retry evicte template: " + template.getName() + " from storage pool: " + pool.getName());
            }
        } catch (final StorageUnavailableException e) {
            s_logger.info("Storage is unavailable currently.  Will retry evicte template: " + template.getName() + " from storage pool: " + pool.getName());
        }
    } finally {
        this._tmpltPoolDao.releaseFromLockTable(templatePoolRef.getId());
    }
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) Answer(com.cloud.legacymodel.communication.answer.Answer) StoragePool(com.cloud.legacymodel.storage.StoragePool) StorageUnavailableException(com.cloud.legacymodel.exceptions.StorageUnavailableException) DestroyCommand(com.cloud.legacymodel.communication.command.DestroyCommand) VMTemplateVO(com.cloud.storage.VMTemplateVO) DB(com.cloud.utils.db.DB)

Example 13 with StorageUnavailableException

use of com.cloud.legacymodel.exceptions.StorageUnavailableException in project cosmic by MissionCriticalCloud.

the class StoragePoolMonitorTest method testProcessConnectStoragePoolFailureOnHost.

@Test(expected = ConnectionException.class)
public void testProcessConnectStoragePoolFailureOnHost() throws Exception {
    Mockito.when(poolDao.listBy(Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong(), Mockito.any(ScopeType.class))).thenReturn(Collections.singletonList(pool));
    Mockito.when(poolDao.findZoneWideStoragePoolsByTags(Mockito.anyLong(), Mockito.any(String[].class))).thenReturn(Collections.<StoragePoolVO>emptyList());
    Mockito.when(poolDao.findZoneWideStoragePoolsByHypervisor(Mockito.anyLong(), Mockito.any(HypervisorType.class))).thenReturn(Collections.<StoragePoolVO>emptyList());
    Mockito.doThrow(new StorageUnavailableException("unable to mount storage", 123L)).when(storageManager).connectHostToSharedPool(Mockito.anyLong(), Mockito.anyLong());
    storagePoolMonitor.processConnect(host, cmds, false);
}
Also used : ScopeType(com.cloud.storage.ScopeType) HypervisorType(com.cloud.model.enumeration.HypervisorType) StorageUnavailableException(com.cloud.legacymodel.exceptions.StorageUnavailableException) Test(org.junit.Test)

Example 14 with StorageUnavailableException

use of com.cloud.legacymodel.exceptions.StorageUnavailableException in project cosmic by MissionCriticalCloud.

the class StartVMCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException {
    try {
        CallContext.current().setEventDetails("Vm Id: " + getId());
        final UserVm result;
        result = _userVmService.startVirtualMachine(this);
        if (result != null) {
            final UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result).get(0);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to start a vm");
        }
    } catch (final ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (final StorageUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (final ExecutionException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (final InsufficientCapacityException ex) {
        final StringBuilder message = new StringBuilder(ex.getMessage());
        if (ex instanceof InsufficientServerCapacityException) {
            if (((InsufficientServerCapacityException) ex).isAffinityApplied()) {
                message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them");
            }
        }
        s_logger.info(ex.toString());
        s_logger.info(message.toString(), ex);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString());
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(com.cloud.api.ServerApiException) StorageUnavailableException(com.cloud.legacymodel.exceptions.StorageUnavailableException) InsufficientServerCapacityException(com.cloud.legacymodel.exceptions.InsufficientServerCapacityException) ExecutionException(com.cloud.legacymodel.exceptions.ExecutionException) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) UserVmResponse(com.cloud.api.response.UserVmResponse) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException)

Example 15 with StorageUnavailableException

use of com.cloud.legacymodel.exceptions.StorageUnavailableException 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 = this.dataStoreMgr.getDataStore(vol.getPoolId(), DataStoreRole.Primary);
        s_logger.debug("existing pool: " + destPool.getId());
    } else {
        final StoragePool pool = dest.getStorageForDisks().get(vol);
        destPool = this.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 = this.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 = this._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)
            this.volService.updateHypervisorSnapshotReserveForVolume(diskOffering, volume.getId(), hyperType);
            volume = this.volFactory.getVolume(newVol.getId(), destPool);
            future = this.volService.createVolumeAsync(volume, destPool);
        } else {
            final TemplateInfo templ = this.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 = this._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)
                this.volService.updateHypervisorSnapshotReserveForVolume(diskOffering, volume.getId(), hyperType);
                final long hostId = vm.getVirtualMachine().getHostId();
                future = this.volService.createManagedStorageAndVolumeFromTemplateAsync(volume, destPool.getId(), templ, hostId);
            } else {
                future = this.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 = this._storagePoolDao.findById(destPool.getId());
            if (storagePool.isManaged()) {
                final long hostId = vm.getVirtualMachine().getHostId();
                final Host host = this._hostDao.findById(hostId);
                this.volService.grantAccess(this.volFactory.getVolume(newVol.getId()), host, destPool);
            }
            newVol = this._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.legacymodel.storage.StoragePool) DiskOffering(com.cloud.legacymodel.storage.DiskOffering) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) Host(com.cloud.legacymodel.dc.Host) HypervisorType(com.cloud.model.enumeration.HypervisorType) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) VolumeVO(com.cloud.storage.VolumeVO) StorageUnavailableException(com.cloud.legacymodel.exceptions.StorageUnavailableException) CloudRuntimeException(com.cloud.legacymodel.exceptions.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.legacymodel.utils.Pair)

Aggregations

StorageUnavailableException (com.cloud.legacymodel.exceptions.StorageUnavailableException)19 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)9 DB (com.cloud.utils.db.DB)7 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)6 StoragePool (com.cloud.legacymodel.storage.StoragePool)6 ExecutionException (java.util.concurrent.ExecutionException)6 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)5 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)5 ServerApiException (com.cloud.api.ServerApiException)4 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)4 Answer (com.cloud.legacymodel.communication.answer.Answer)4 InsufficientCapacityException (com.cloud.legacymodel.exceptions.InsufficientCapacityException)4 NoTransitionException (com.cloud.legacymodel.exceptions.NoTransitionException)4 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)4 ExecutionException (com.cloud.legacymodel.exceptions.ExecutionException)3 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)3 ResourceAllocationException (com.cloud.legacymodel.exceptions.ResourceAllocationException)3 DiskOffering (com.cloud.legacymodel.storage.DiskOffering)3 Pair (com.cloud.legacymodel.utils.Pair)3 HypervisorType (com.cloud.model.enumeration.HypervisorType)3