Search in sources :

Example 76 with InvalidParameterValueException

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

the class ManagementServerImpl method listStoragePoolsForMigrationOfVolume.

@Override
public Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolume(final Long volumeId) {
    final Account caller = getCaller();
    if (!_accountMgr.isRootAdmin(caller.getId())) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Caller is not a root admin, permission denied to migrate the volume");
        }
        throw new PermissionDeniedException("No permission to migrate volume, only root admin can migrate a volume");
    }
    final VolumeVO volume = _volumeDao.findById(volumeId);
    if (volume == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find volume with" + " specified id.");
        ex.addProxyObject(volumeId.toString(), "volumeId");
        throw ex;
    }
    // Volume must be attached to an instance for live migration.
    final List<StoragePool> allPools = new ArrayList<>();
    final List<StoragePool> suitablePools = new ArrayList<>();
    // Volume must be in Ready state to be migrated.
    if (!Volume.State.Ready.equals(volume.getState())) {
        s_logger.info("Volume " + volume + " must be in ready state for migration.");
        return new Pair<>(allPools, suitablePools);
    }
    if (!_volumeMgr.volumeOnSharedStoragePool(volume)) {
        s_logger.info("Volume " + volume + " is on local storage. It cannot be migrated to another pool.");
        return new Pair<>(allPools, suitablePools);
    }
    final Long instanceId = volume.getInstanceId();
    VMInstanceVO vm = null;
    if (instanceId != null) {
        vm = _vmInstanceDao.findById(instanceId);
    }
    if (vm == null) {
        s_logger.info("Volume " + volume + " isn't attached to any vm. Looking for storage pools in the " + "zone to which this volumes can be migrated.");
    } else if (vm.getState() != State.Running) {
        s_logger.info("Volume " + volume + " isn't attached to any running vm. Looking for storage pools in the " + "cluster to which this volumes can be migrated.");
    } else {
        s_logger.info("Volume " + volume + " is attached to any running vm. Looking for storage pools in the " + "cluster to which this volumes can be migrated.");
        boolean storageMotionSupported = false;
        // Check if the underlying hypervisor supports storage motion.
        final Long hostId = vm.getHostId();
        if (hostId != null) {
            final HostVO host = _hostDao.findById(hostId);
            HypervisorCapabilitiesVO capabilities = null;
            if (host != null) {
                capabilities = _hypervisorCapabilitiesDao.findByHypervisorTypeAndVersion(host.getHypervisorType(), host.getHypervisorVersion());
            } else {
                s_logger.error("Details of the host on which the vm " + vm + ", to which volume " + volume + " is " + "attached, couldn't be retrieved.");
            }
            if (capabilities != null) {
                storageMotionSupported = capabilities.isStorageMotionSupported();
            } else {
                s_logger.error("Capabilities for host " + host + " couldn't be retrieved.");
            }
        }
        if (!storageMotionSupported) {
            s_logger.info("Volume " + volume + " is attached to a running vm and the hypervisor doesn't support" + " storage motion.");
            return new Pair<>(allPools, suitablePools);
        }
    }
    // Source pool of the volume.
    final StoragePoolVO srcVolumePool = _poolDao.findById(volume.getPoolId());
    // Get all the pools available. Only shared pools are considered because only a volume on a shared pools
    // can be live migrated while the virtual machine stays on the same host.
    final List<StoragePoolVO> storagePools;
    if (srcVolumePool.getClusterId() == null) {
        storagePools = _poolDao.findZoneWideStoragePoolsByTags(volume.getDataCenterId(), null);
    } else {
        storagePools = _poolDao.findPoolsByTags(volume.getDataCenterId(), srcVolumePool.getPodId(), srcVolumePool.getClusterId(), null);
    }
    storagePools.remove(srcVolumePool);
    for (final StoragePoolVO pool : storagePools) {
        if (pool.isShared()) {
            allPools.add((StoragePool) dataStoreMgr.getPrimaryDataStore(pool.getId()));
        }
    }
    // Get all the suitable pools.
    // Exclude the current pool from the list of pools to which the volume can be migrated.
    final ExcludeList avoid = new ExcludeList();
    avoid.addPool(srcVolumePool.getId());
    // Volume stays in the same cluster after migration.
    final DataCenterDeployment plan = new DataCenterDeployment(volume.getDataCenterId(), srcVolumePool.getPodId(), srcVolumePool.getClusterId(), null, null, null);
    final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
    final DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
    final DiskProfile diskProfile = new DiskProfile(volume, diskOffering, profile.getHypervisorType());
    // Call the storage pool allocator to find the list of storage pools.
    for (final StoragePoolAllocator allocator : _storagePoolAllocators) {
        final List<StoragePool> pools = allocator.allocateToPool(diskProfile, profile, plan, avoid, StoragePoolAllocator.RETURN_UPTO_ALL);
        if (pools != null && !pools.isEmpty()) {
            suitablePools.addAll(pools);
            break;
        }
    }
    return new Pair<>(allPools, suitablePools);
}
Also used : HypervisorCapabilitiesVO(com.cloud.hypervisor.HypervisorCapabilitiesVO) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) Account(com.cloud.legacymodel.user.Account) StoragePool(com.cloud.legacymodel.storage.StoragePool) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VirtualMachineProfileImpl(com.cloud.vm.VirtualMachineProfileImpl) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) DiskProfile(com.cloud.legacymodel.storage.DiskProfile) HostVO(com.cloud.host.HostVO) VolumeVO(com.cloud.storage.VolumeVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) PermissionDeniedException(com.cloud.legacymodel.exceptions.PermissionDeniedException) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) StoragePoolAllocator(com.cloud.engine.subsystem.api.storage.StoragePoolAllocator) SSHKeyPair(com.cloud.legacymodel.user.SSHKeyPair) Pair(com.cloud.legacymodel.utils.Pair)

Example 77 with InvalidParameterValueException

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

the class ManagementServerImpl method updateVmGroup.

@Override
public InstanceGroupVO updateVmGroup(final UpdateVMGroupCmd cmd) {
    final Account caller = getCaller();
    final Long groupId = cmd.getId();
    final String groupName = cmd.getGroupName();
    // Verify input parameters
    final InstanceGroupVO group = _vmGroupDao.findById(groupId.longValue());
    if (group == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a vm group with specified groupId");
        ex.addProxyObject(groupId.toString(), "groupId");
        throw ex;
    }
    _accountMgr.checkAccess(caller, null, true, group);
    // Check if name is already in use by this account (exclude this group)
    final boolean isNameInUse = _vmGroupDao.isNameInUse(group.getAccountId(), groupName);
    if (isNameInUse && !group.getName().equals(groupName)) {
        throw new InvalidParameterValueException("Unable to update vm group, a group with name " + groupName + " already exists for account");
    }
    if (groupName != null) {
        _vmGroupDao.updateVmGroup(groupId, groupName);
    }
    return _vmGroupDao.findById(groupId);
}
Also used : Account(com.cloud.legacymodel.user.Account) InstanceGroupVO(com.cloud.vm.InstanceGroupVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException)

Example 78 with InvalidParameterValueException

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

the class ManagementServerImpl method updateGuestOsMapping.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_GUEST_OS_MAPPING_UPDATE, eventDescription = "updating guest OS mapping", async = true)
public GuestOSHypervisor updateGuestOsMapping(final UpdateGuestOsMappingCmd cmd) {
    final Long id = cmd.getId();
    final String osNameForHypervisor = cmd.getOsNameForHypervisor();
    // check if mapping exists
    final GuestOSHypervisor guestOsHypervisorHandle = _guestOSHypervisorDao.findById(id);
    if (guestOsHypervisorHandle == null) {
        throw new InvalidParameterValueException("Guest OS Mapping not found. Please specify a valid ID for the Guest OS Mapping");
    }
    if (!guestOsHypervisorHandle.getIsUserDefined()) {
        throw new InvalidParameterValueException("Unable to modify system defined Guest OS mapping");
    }
    final GuestOSHypervisorVO guestOsHypervisor = _guestOSHypervisorDao.createForUpdate(id);
    guestOsHypervisor.setGuestOsName(osNameForHypervisor);
    if (_guestOSHypervisorDao.update(id, guestOsHypervisor)) {
        return _guestOSHypervisorDao.findById(id);
    } else {
        return null;
    }
}
Also used : GuestOSHypervisorVO(com.cloud.storage.GuestOSHypervisorVO) GuestOSHypervisor(com.cloud.storage.GuestOSHypervisor) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 79 with InvalidParameterValueException

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

the class ManagementServerImpl method searchForConfigurations.

@Override
public Pair<List<? extends Configuration>, Integer> searchForConfigurations(final ListCfgsByCmd cmd) {
    final Filter searchFilter = new Filter(ConfigurationVO.class, "name", true, cmd.getStartIndex(), cmd.getPageSizeVal());
    final SearchCriteria<ConfigurationVO> sc = _configDao.createSearchCriteria();
    final Long userId = CallContext.current().getCallingUserId();
    final Account caller = CallContext.current().getCallingAccount();
    final User user = _userDao.findById(userId);
    final Object name = cmd.getConfigName();
    final Object category = cmd.getCategory();
    final Object keyword = cmd.getKeyword();
    final Long zoneId = cmd.getZoneId();
    final Long clusterId = cmd.getClusterId();
    final Long storagepoolId = cmd.getStoragepoolId();
    final Long accountId = cmd.getAccountId();
    String scope = null;
    Long id = null;
    int paramCountCheck = 0;
    if (!_accountMgr.isRootAdmin(caller.getId()) && accountId == null) {
        throw new InvalidParameterValueException("Please specify AccountId to list the config for the given account.");
    }
    if (accountId != null) {
        final Account accountToUpdate = _accountDao.findById(accountId);
        _accountMgr.checkAccess(caller, null, true, accountToUpdate);
        scope = ConfigKey.Scope.Account.toString();
        id = accountId;
        paramCountCheck++;
    }
    if (_accountMgr.isRootAdmin(caller.getId())) {
        if (zoneId != null) {
            scope = ConfigKey.Scope.Zone.toString();
            id = zoneId;
            paramCountCheck++;
        }
        if (clusterId != null) {
            scope = ConfigKey.Scope.Cluster.toString();
            id = clusterId;
            paramCountCheck++;
        }
        if (storagepoolId != null) {
            scope = ConfigKey.Scope.StoragePool.toString();
            id = storagepoolId;
            paramCountCheck++;
        }
    }
    if (paramCountCheck > 1) {
        throw new InvalidParameterValueException("cannot handle multiple IDs, provide only one ID corresponding to the scope");
    }
    if (keyword != null) {
        final SearchCriteria<ConfigurationVO> ssc = _configDao.createSearchCriteria();
        ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("instance", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("component", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("category", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("value", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        sc.addAnd("name", SearchCriteria.Op.SC, ssc);
    }
    if (name != null) {
        sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%");
    }
    if (category != null) {
        sc.addAnd("category", SearchCriteria.Op.EQ, category);
    }
    // hidden configurations are not displayed using the search API
    sc.addAnd("category", SearchCriteria.Op.NEQ, "Hidden");
    if (scope != null && !scope.isEmpty()) {
        // getting the list of parameters at requested scope
        sc.addAnd("scope", SearchCriteria.Op.EQ, scope);
    }
    final Pair<List<ConfigurationVO>, Integer> result = _configDao.searchAndCount(sc, searchFilter);
    if (scope != null && !scope.isEmpty()) {
        // Populate values corresponding the resource id
        final List<ConfigurationVO> configVOList = new ArrayList<>();
        for (final ConfigurationVO param : result.first()) {
            final ConfigurationVO configVo = _configDao.findByName(param.getName());
            if (configVo != null) {
                final ConfigKey<?> key = _configDepot.get(param.getName());
                if (key != null) {
                    configVo.setValue(key.valueIn(id).toString());
                    configVOList.add(configVo);
                } else {
                    s_logger.warn("ConfigDepot could not find parameter " + param.getName() + " for scope " + scope);
                }
            } else {
                s_logger.warn("Configuration item  " + param.getName() + " not found in " + scope);
            }
        }
        return new Pair<>(configVOList, configVOList.size());
    }
    return new Pair<>(result.first(), result.second());
}
Also used : Account(com.cloud.legacymodel.user.Account) User(com.cloud.legacymodel.user.User) ArrayList(java.util.ArrayList) ConfigurationVO(com.cloud.framework.config.impl.ConfigurationVO) Filter(com.cloud.utils.db.Filter) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) List(java.util.List) SSHKeyPair(com.cloud.legacymodel.user.SSHKeyPair) Pair(com.cloud.legacymodel.utils.Pair)

Example 80 with InvalidParameterValueException

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

the class ResourceChecker method checkIfPodIsUsable.

public void checkIfPodIsUsable(final DataCenter dataCenter, final HostPodVO hostPod) {
    final long hostPodId = hostPod.getId();
    logger.debug("Checking if pod " + hostPodId + " is usable.");
    if (!hostPod.belongsToDataCenter(dataCenter.getId())) {
        final String hostPodUuid = hostPod.getUuid();
        final String dataCenterUuid = dataCenter.getUuid();
        final InvalidParameterValueException ex = new InvalidParameterValueException("Pod with specified pod " + hostPodUuid + " doesn't belong to the zone with specified dataCenter " + dataCenterUuid);
        ex.addProxyObject(hostPodUuid, "podId");
        ex.addProxyObject(dataCenterUuid, "dcId");
        throw ex;
    }
    logger.debug("Pod " + hostPodId + "is usable");
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException)

Aggregations

InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)483 Account (com.cloud.legacymodel.user.Account)219 ActionEvent (com.cloud.event.ActionEvent)159 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)153 ArrayList (java.util.ArrayList)105 DB (com.cloud.utils.db.DB)97 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)76 List (java.util.List)62 TransactionStatus (com.cloud.utils.db.TransactionStatus)58 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)53 Network (com.cloud.legacymodel.network.Network)51 ServerApiException (com.cloud.api.ServerApiException)47 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)43 Pair (com.cloud.legacymodel.utils.Pair)36 HashMap (java.util.HashMap)36 ConfigurationException (javax.naming.ConfigurationException)36 ResourceAllocationException (com.cloud.legacymodel.exceptions.ResourceAllocationException)33 NetworkVO (com.cloud.network.dao.NetworkVO)31 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)30 HostVO (com.cloud.host.HostVO)29