Search in sources :

Example 26 with StorageUnavailableException

use of com.cloud.exception.StorageUnavailableException in project cosmic by MissionCriticalCloud.

the class VirtualMachineManagerImpl method orchestrateStorageMigration.

private void orchestrateStorageMigration(final String vmUuid, final StoragePool destPool) {
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    if (destPool == null) {
        throw new CloudRuntimeException("Unable to migrate vm: missing destination storage pool");
    }
    try {
        stateTransitTo(vm, VirtualMachine.Event.StorageMigrationRequested, null);
    } catch (final NoTransitionException e) {
        s_logger.debug("Unable to migrate vm: " + e.toString());
        throw new CloudRuntimeException("Unable to migrate vm: " + e.toString());
    }
    final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
    boolean migrationResult = false;
    try {
        migrationResult = volumeMgr.storageMigration(profile, destPool);
        if (migrationResult) {
            if (destPool.getPodId() != null && !destPool.getPodId().equals(vm.getPodIdToDeployIn())) {
                final DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), destPool.getPodId(), null, null, null, null);
                final VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm, null, null, null, null);
                _networkMgr.reallocate(vmProfile, plan);
            }
            // when start the vm next time, don;'t look at last_host_id, only choose the host based on volume/storage pool
            vm.setLastHostId(null);
            vm.setPodIdToDeployIn(destPool.getPodId());
        } else {
            s_logger.debug("Storage migration failed");
        }
    } catch (final ConcurrentOperationException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } catch (final InsufficientVirtualNetworkCapacityException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } catch (final InsufficientAddressCapacityException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } catch (final InsufficientCapacityException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } catch (final StorageUnavailableException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } finally {
        try {
            stateTransitTo(vm, VirtualMachine.Event.AgentReportStopped, null);
        } catch (final NoTransitionException e) {
            s_logger.debug("Failed to change vm state: " + e.toString());
            throw new CloudRuntimeException("Failed to change vm state: " + e.toString());
        }
    }
}
Also used : DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 27 with StorageUnavailableException

use of com.cloud.exception.StorageUnavailableException in project cosmic by MissionCriticalCloud.

the class StorageManagerImpl method cancelPrimaryStorageForMaintenance.

@Override
@DB
public PrimaryDataStoreInfo cancelPrimaryStorageForMaintenance(final CancelPrimaryStorageMaintenanceCmd cmd) throws ResourceUnavailableException {
    final Long primaryStorageId = cmd.getId();
    final StoragePoolVO primaryStorage;
    primaryStorage = _storagePoolDao.findById(primaryStorageId);
    if (primaryStorage == null) {
        final String msg = "Unable to obtain lock on the storage pool in cancelPrimaryStorageForMaintenance()";
        s_logger.error(msg);
        throw new InvalidParameterValueException(msg);
    }
    if (primaryStorage.getStatus().equals(StoragePoolStatus.Up) || primaryStorage.getStatus().equals(StoragePoolStatus.PrepareForMaintenance)) {
        throw new StorageUnavailableException("Primary storage with id " + primaryStorageId + " is not ready to complete migration, as the status is:" + primaryStorage.getStatus().toString(), primaryStorageId);
    }
    final DataStoreProvider provider = _dataStoreProviderMgr.getDataStoreProvider(primaryStorage.getStorageProviderName());
    final DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
    final DataStore store = _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
    lifeCycle.cancelMaintain(store);
    return (PrimaryDataStoreInfo) _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
}
Also used : PrimaryDataStoreInfo(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreInfo) DataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) DataStoreProvider(com.cloud.engine.subsystem.api.storage.DataStoreProvider) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) DB(com.cloud.utils.db.DB)

Example 28 with StorageUnavailableException

use of com.cloud.exception.StorageUnavailableException in project cosmic by MissionCriticalCloud.

the class StorageManagerImpl method sendToPool.

@Override
public Pair<Long, Answer[]> sendToPool(final StoragePool pool, final long[] hostIdsToTryFirst, final List<Long> hostIdsToAvoid, final Commands cmds) throws StorageUnavailableException {
    final List<Long> hostIds = getUpHostsInPool(pool.getId());
    Collections.shuffle(hostIds);
    if (hostIdsToTryFirst != null) {
        for (int i = hostIdsToTryFirst.length - 1; i >= 0; i--) {
            if (hostIds.remove(hostIdsToTryFirst[i])) {
                hostIds.add(0, hostIdsToTryFirst[i]);
            }
        }
    }
    if (hostIdsToAvoid != null) {
        hostIds.removeAll(hostIdsToAvoid);
    }
    if (hostIds == null || hostIds.isEmpty()) {
        throw new StorageUnavailableException("Unable to send command to the pool " + pool.getId() + " due to there is no enabled hosts up in this cluster", pool.getId());
    }
    for (final Long hostId : hostIds) {
        try {
            final List<Answer> answers = new ArrayList<>();
            final Command[] cmdArray = cmds.toCommands();
            for (final Command cmd : cmdArray) {
                final long targetHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(hostId, cmd);
                answers.add(_agentMgr.send(targetHostId, cmd));
            }
            return new Pair<>(hostId, answers.toArray(new Answer[answers.size()]));
        } catch (final AgentUnavailableException e) {
            s_logger.debug("Unable to send storage pool command to " + pool + " via " + hostId, e);
        } catch (final OperationTimedoutException e) {
            s_logger.debug("Unable to send storage pool command to " + pool + " via " + hostId, e);
        }
    }
    throw new StorageUnavailableException("Unable to send command to the pool ", pool.getId());
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ArrayList(java.util.ArrayList) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) Answer(com.cloud.agent.api.Answer) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) Command(com.cloud.agent.api.Command) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Pair(com.cloud.utils.Pair)

Example 29 with StorageUnavailableException

use of com.cloud.exception.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 = _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) _dataStoreMgr.getPrimaryDataStore(templatePoolVO.getPoolId());
        final VMTemplateVO template = _tmpltDao.findByIdIncludingRemoved(templatePoolVO.getTemplateId());
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Evicting " + templatePoolVO);
        }
        final DestroyCommand cmd = new DestroyCommand(pool, templatePoolVO);
        try {
            final Answer answer = _storageMgr.sendToPool(pool, cmd);
            if (answer != null && answer.getResult()) {
                // Remove the templatePoolVO
                if (_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 {
        _tmpltPoolDao.releaseFromLockTable(templatePoolRef.getId());
    }
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) Answer(com.cloud.agent.api.Answer) StoragePool(com.cloud.storage.StoragePool) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) DestroyCommand(com.cloud.agent.api.storage.DestroyCommand) VMTemplateVO(com.cloud.storage.VMTemplateVO) DB(com.cloud.utils.db.DB)

Example 30 with StorageUnavailableException

use of com.cloud.exception.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 = _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 = _accountDao.findById(template.getAccountId());
    // find the size of the template to be copied
    final TemplateDataStoreVO srcTmpltStore = _tmplStoreDao.findByStoreTemplate(srcSecStore.getId(), tmpltId);
    _resourceLimitMgr.checkResourceLimit(account, ResourceType.template);
    _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 = _tmplFactory.getTemplate(template.getId(), srcSecStore);
    // for that zone
    for (final DataStore dstSecStore : dstSecStores) {
        final TemplateDataStoreVO dstTmpltStore = _tmplStoreDao.findByStoreTemplate(dstSecStore.getId(), tmpltId);
        if (dstTmpltStore != null && dstTmpltStore.getDownloadState() == Status.DOWNLOADED) {
            // already downloaded on this image store
            return true;
        }
        if (dstTmpltStore != null && dstTmpltStore.getDownloadState() != Status.DOWNLOAD_IN_PROGRESS) {
            _tmplStoreDao.removeByTemplateStore(tmpltId, dstSecStore.getId());
        }
        final AsyncCallFuture<TemplateApiResult> future = _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;
            }
            _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) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) URISyntaxException(java.net.URISyntaxException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) MalformedURLException(java.net.MalformedURLException) ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) DB(com.cloud.utils.db.DB)

Aggregations

StorageUnavailableException (com.cloud.exception.StorageUnavailableException)52 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)26 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)21 DB (com.cloud.utils.db.DB)16 ExecutionException (java.util.concurrent.ExecutionException)15 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)14 ArrayList (java.util.ArrayList)13 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)12 StoragePool (com.cloud.storage.StoragePool)12 Pair (com.cloud.utils.Pair)11 Answer (com.cloud.agent.api.Answer)10 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)10 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)9 ConfigurationException (javax.naming.ConfigurationException)9 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)8 DiskOffering (com.cloud.offering.DiskOffering)8 VolumeVO (com.cloud.storage.VolumeVO)8 ExecutionException (com.cloud.utils.exception.ExecutionException)8 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)8 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)7