Search in sources :

Example 31 with InvalidParameterValueException

use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class VMSnapshotManagerImpl method getVMBySnapshotId.

@Override
public VirtualMachine getVMBySnapshotId(final Long id) {
    final VMSnapshotVO vmSnapshot = _vmSnapshotDao.findById(id);
    if (vmSnapshot == null) {
        throw new InvalidParameterValueException("unable to find the vm snapshot with id " + id);
    }
    final Long vmId = vmSnapshot.getVmId();
    final UserVmVO vm = _userVMDao.findById(vmId);
    return vm;
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException)

Example 32 with InvalidParameterValueException

use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class VMSnapshotManagerImpl method orchestrateCreateVMSnapshot.

private VMSnapshot orchestrateCreateVMSnapshot(final Long vmId, final Long vmSnapshotId, final Boolean quiescevm) {
    final UserVmVO userVm = _userVMDao.findById(vmId);
    if (userVm == null) {
        throw new InvalidParameterValueException("Create vm to snapshot failed due to vm: " + vmId + " is not found");
    }
    final List<VolumeVO> volumeVos = _volumeDao.findByInstanceAndType(vmId, Type.ROOT);
    if (volumeVos == null || volumeVos.isEmpty()) {
        throw new CloudRuntimeException("Create vm to snapshot failed due to no root disk found");
    }
    final VolumeVO rootVolume = volumeVos.get(0);
    if (!rootVolume.getState().equals(Volume.State.Ready)) {
        throw new CloudRuntimeException("Create vm to snapshot failed due to vm: " + vmId + " has root disk in " + rootVolume.getState() + " state");
    }
    final VMSnapshotVO vmSnapshot = _vmSnapshotDao.findById(vmSnapshotId);
    if (vmSnapshot == null) {
        throw new CloudRuntimeException("VM snapshot id: " + vmSnapshotId + " can not be found");
    }
    final VMSnapshotOptions options = new VMSnapshotOptions(quiescevm);
    vmSnapshot.setOptions(options);
    try {
        final VMSnapshotStrategy strategy = findVMSnapshotStrategy(vmSnapshot);
        return strategy.takeVMSnapshot(vmSnapshot);
    } catch (final Exception e) {
        s_logger.debug("Failed to create vm snapshot: " + vmSnapshotId, e);
        return null;
    }
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) VolumeVO(com.cloud.storage.VolumeVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMSnapshotOptions(com.cloud.engine.subsystem.api.storage.VMSnapshotOptions) VMSnapshotStrategy(com.cloud.engine.subsystem.api.storage.VMSnapshotStrategy) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) CloudException(com.cloud.exception.CloudException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException)

Example 33 with InvalidParameterValueException

use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class VolumeApiServiceImpl method orchestrateAttachVolumeToVM.

private Volume orchestrateAttachVolumeToVM(final Long vmId, final Long volumeId, final Long deviceId) {
    final VolumeInfo volumeToAttach = volFactory.getVolume(volumeId);
    if (volumeToAttach.isAttachedVM()) {
        throw new CloudRuntimeException("This volume is already attached to a VM.");
    }
    UserVmVO vm = _userVmDao.findById(vmId);
    VolumeVO exstingVolumeOfVm = null;
    final List<VolumeVO> rootVolumesOfVm = _volsDao.findByInstanceAndType(vmId, Volume.Type.ROOT);
    if (rootVolumesOfVm.size() > 1) {
        throw new CloudRuntimeException("The VM " + vm.getHostName() + " has more than one ROOT volume and is in an invalid state.");
    } else {
        if (!rootVolumesOfVm.isEmpty()) {
            exstingVolumeOfVm = rootVolumesOfVm.get(0);
        } else {
            // locate data volume of the vm
            final List<VolumeVO> diskVolumesOfVm = _volsDao.findByInstanceAndType(vmId, Volume.Type.DATADISK);
            for (final VolumeVO diskVolume : diskVolumesOfVm) {
                if (diskVolume.getState() != Volume.State.Allocated) {
                    exstingVolumeOfVm = diskVolume;
                    break;
                }
            }
        }
    }
    final HypervisorType rootDiskHyperType = vm.getHypervisorType();
    final HypervisorType volumeToAttachHyperType = _volsDao.getHypervisorType(volumeToAttach.getId());
    VolumeInfo newVolumeOnPrimaryStorage = volumeToAttach;
    // don't create volume on primary storage if its being attached to the vm which Root's volume hasn't been created yet
    StoragePoolVO destPrimaryStorage = null;
    if (exstingVolumeOfVm != null && !exstingVolumeOfVm.getState().equals(Volume.State.Allocated)) {
        destPrimaryStorage = _storagePoolDao.findById(exstingVolumeOfVm.getPoolId());
    }
    final boolean volumeOnSecondary = volumeToAttach.getState() == Volume.State.Uploaded;
    if (destPrimaryStorage != null && (volumeToAttach.getState() == Volume.State.Allocated || volumeOnSecondary)) {
        try {
            newVolumeOnPrimaryStorage = _volumeMgr.createVolumeOnPrimaryStorage(vm, volumeToAttach, rootDiskHyperType, destPrimaryStorage);
        } catch (final NoTransitionException e) {
            s_logger.debug("Failed to create volume on primary storage", e);
            throw new CloudRuntimeException("Failed to create volume on primary storage", e);
        }
    }
    // reload the volume from db
    newVolumeOnPrimaryStorage = volFactory.getVolume(newVolumeOnPrimaryStorage.getId());
    final boolean moveVolumeNeeded = needMoveVolume(exstingVolumeOfVm, newVolumeOnPrimaryStorage);
    if (moveVolumeNeeded) {
        final PrimaryDataStoreInfo primaryStore = (PrimaryDataStoreInfo) newVolumeOnPrimaryStorage.getDataStore();
        if (primaryStore.isLocal()) {
            throw new CloudRuntimeException("Failed to attach local data volume " + volumeToAttach.getName() + " to VM " + vm.getDisplayName() + " as migration of local data volume is not allowed");
        }
        final StoragePoolVO vmRootVolumePool = _storagePoolDao.findById(exstingVolumeOfVm.getPoolId());
        try {
            newVolumeOnPrimaryStorage = _volumeMgr.moveVolume(newVolumeOnPrimaryStorage, vmRootVolumePool.getDataCenterId(), vmRootVolumePool.getPodId(), vmRootVolumePool.getClusterId(), volumeToAttachHyperType);
        } catch (final ConcurrentOperationException e) {
            s_logger.debug("move volume failed", e);
            throw new CloudRuntimeException("move volume failed", e);
        } catch (final StorageUnavailableException e) {
            s_logger.debug("move volume failed", e);
            throw new CloudRuntimeException("move volume failed", e);
        }
    }
    VolumeVO newVol = _volsDao.findById(newVolumeOnPrimaryStorage.getId());
    // Getting the fresh vm object in case of volume migration to check the current state of VM
    if (moveVolumeNeeded || volumeOnSecondary) {
        vm = _userVmDao.findById(vmId);
        if (vm == null) {
            throw new InvalidParameterValueException("VM not found.");
        }
    }
    newVol = sendAttachVolumeCommand(vm, newVol, deviceId);
    return newVol;
}
Also used : PrimaryDataStoreInfo(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreInfo) UserVmVO(com.cloud.vm.UserVmVO) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO)

Example 34 with InvalidParameterValueException

use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class VolumeApiServiceImpl method deleteVolume.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_DELETE, eventDescription = "deleting volume")
public boolean deleteVolume(final long volumeId, final Account caller) throws ConcurrentOperationException {
    final VolumeVO volume = _volsDao.findById(volumeId);
    if (volume == null) {
        throw new InvalidParameterValueException("Unable to find volume with ID: " + volumeId);
    }
    if (!_snapshotMgr.canOperateOnVolume(volume)) {
        throw new InvalidParameterValueException("There are snapshot operations in progress on the volume, unable to delete it");
    }
    _accountMgr.checkAccess(caller, null, true, volume);
    if (volume.getInstanceId() != null) {
        throw new InvalidParameterValueException("Please specify a volume that is not attached to any VM.");
    }
    if (volume.getState() == Volume.State.UploadOp) {
        final VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(volume.getId());
        if (volumeStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS) {
            throw new InvalidParameterValueException("Please specify a volume that is not uploading");
        }
    }
    if (volume.getState() == Volume.State.NotUploaded || volume.getState() == Volume.State.UploadInProgress) {
        throw new InvalidParameterValueException("The volume is either getting uploaded or it may be initiated shortly, please wait for it to be completed");
    }
    try {
        if (volume.getState() != Volume.State.Destroy && volume.getState() != Volume.State.Expunging && volume.getState() != Volume.State.Expunged) {
            final Long instanceId = volume.getInstanceId();
            if (!volService.destroyVolume(volume.getId())) {
                return false;
            }
            final VMInstanceVO vmInstance = _vmInstanceDao.findById(instanceId);
            if (instanceId == null || vmInstance.getType().equals(VirtualMachine.Type.User)) {
                // Decrement the resource count for volumes and primary storage belonging user VM's only
                _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.volume, volume.isDisplayVolume());
            }
        }
        // Mark volume as removed if volume has not been created on primary or secondary
        if (volume.getState() == Volume.State.Allocated) {
            _volsDao.remove(volumeId);
            stateTransitTo(volume, Volume.Event.DestroyRequested);
            return true;
        }
        // expunge volume from primary if volume is on primary
        final VolumeInfo volOnPrimary = volFactory.getVolume(volume.getId(), DataStoreRole.Primary);
        if (volOnPrimary != null) {
            s_logger.info("Expunging volume " + volume.getId() + " from primary data store");
            final AsyncCallFuture<VolumeApiResult> future = volService.expungeVolumeAsync(volOnPrimary);
            future.get();
            // decrement primary storage count
            _resourceLimitMgr.recalculateResourceCount(volume.getAccountId(), volume.getDomainId(), ResourceType.primary_storage.getOrdinal());
        }
        // expunge volume from secondary if volume is on image store
        final VolumeInfo volOnSecondary = volFactory.getVolume(volume.getId(), DataStoreRole.Image);
        if (volOnSecondary != null) {
            s_logger.info("Expunging volume " + volume.getId() + " from secondary data store");
            final AsyncCallFuture<VolumeApiResult> future2 = volService.expungeVolumeAsync(volOnSecondary);
            future2.get();
            // decrement secondary storage count
            _resourceLimitMgr.recalculateResourceCount(volume.getAccountId(), volume.getDomainId(), ResourceType.secondary_storage.getOrdinal());
        }
        // delete all cache entries for this volume
        final List<VolumeInfo> cacheVols = volFactory.listVolumeOnCache(volume.getId());
        for (final VolumeInfo volOnCache : cacheVols) {
            s_logger.info("Delete volume from image cache store: " + volOnCache.getDataStore().getName());
            volOnCache.delete();
        }
    } catch (InterruptedException | ExecutionException | NoTransitionException e) {
        s_logger.warn("Failed to expunge volume:", e);
        return false;
    }
    return true;
}
Also used : VMInstanceVO(com.cloud.vm.VMInstanceVO) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) VolumeApiResult(com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) ExecutionException(java.util.concurrent.ExecutionException) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 35 with InvalidParameterValueException

use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class NfsSecondaryStorageResource method createUploadEntity.

public UploadEntity createUploadEntity(String uuid, final String metadata, final long contentLength) {
    final TemplateOrVolumePostUploadCommand cmd = getTemplateOrVolumePostUploadCmd(metadata);
    UploadEntity uploadEntity = null;
    if (cmd == null) {
        final String errorMessage = "unable decode and deserialize metadata.";
        updateStateMapWithError(uuid, errorMessage);
        throw new InvalidParameterValueException(errorMessage);
    } else {
        uuid = cmd.getEntityUUID();
        if (isOneTimePostUrlUsed(cmd)) {
            uploadEntity = uploadEntityStateMap.get(uuid);
            final StringBuilder errorMessage = new StringBuilder("The one time post url is already used");
            if (uploadEntity != null) {
                errorMessage.append(" and the upload is in ").append(uploadEntity.getUploadState()).append(" state.");
            }
            throw new InvalidParameterValueException(errorMessage.toString());
        }
        final int maxSizeInGB = Integer.parseInt(cmd.getMaxUploadSize());
        final int contentLengthInGB = getSizeInGB(contentLength);
        if (contentLengthInGB > maxSizeInGB) {
            final String errorMessage = "Maximum file upload size exceeded. Content Length received: " + contentLengthInGB + "GB. Maximum allowed size: " + maxSizeInGB + "GB.";
            updateStateMapWithError(uuid, errorMessage);
            throw new InvalidParameterValueException(errorMessage);
        }
        checkSecondaryStorageResourceLimit(cmd, contentLengthInGB);
        try {
            final String absolutePath = cmd.getAbsolutePath();
            uploadEntity = new UploadEntity(uuid, cmd.getEntityId(), UploadEntity.Status.IN_PROGRESS, cmd.getName(), absolutePath);
            uploadEntity.setMetaDataPopulated(true);
            uploadEntity.setResourceType(UploadEntity.ResourceType.valueOf(cmd.getType()));
            uploadEntity.setFormat(Storage.ImageFormat.valueOf(cmd.getImageFormat()));
            // relative path with out ssvm mount info.
            uploadEntity.setTemplatePath(absolutePath);
            final String dataStoreUrl = cmd.getDataTo();
            final String installPathPrefix = getRootDir(dataStoreUrl) + File.separator + absolutePath;
            uploadEntity.setInstallPathPrefix(installPathPrefix);
            uploadEntity.setHvm(cmd.getRequiresHvm());
            uploadEntity.setChksum(cmd.getChecksum());
            uploadEntity.setMaxSizeInGB(maxSizeInGB);
            uploadEntity.setDescription(cmd.getDescription());
            uploadEntity.setContentLength(contentLength);
            // create a install dir
            if (!_storage.exists(installPathPrefix)) {
                _storage.mkdir(installPathPrefix);
            }
            uploadEntityStateMap.put(uuid, uploadEntity);
        } catch (final Exception e) {
            // upload entity will be null incase an exception occurs and the handler will not proceed.
            s_logger.error("exception occurred while creating upload entity ", e);
            updateStateMapWithError(uuid, e.getMessage());
        }
    }
    return uploadEntity;
}
Also used : UploadEntity(com.cloud.storage.template.UploadEntity) TemplateOrVolumePostUploadCommand(com.cloud.storage.command.TemplateOrVolumePostUploadCommand) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException)

Aggregations

InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)478 Account (com.cloud.user.Account)199 ActionEvent (com.cloud.event.ActionEvent)151 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)146 ArrayList (java.util.ArrayList)104 DB (com.cloud.utils.db.DB)97 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)72 List (java.util.List)61 TransactionStatus (com.cloud.utils.db.TransactionStatus)57 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)53 ServerApiException (com.cloud.api.ServerApiException)46 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)44 Network (com.cloud.network.Network)40 Pair (com.cloud.utils.Pair)36 HashMap (java.util.HashMap)36 ConfigurationException (javax.naming.ConfigurationException)36 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)33 NetworkVO (com.cloud.network.dao.NetworkVO)31 HostVO (com.cloud.host.HostVO)30 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)30