Package com.cloud.exception

Examples of com.cloud.exception.InvalidParameterValueException


        Integer regionId =  listGslbCmd.getRegionId();
        Long ruleId = listGslbCmd.getId();
        List<GlobalLoadBalancerRule> response = new ArrayList<GlobalLoadBalancerRule>();
        if (regionId == null && ruleId == null) {
            throw new InvalidParameterValueException("Invalid arguments. At least one of region id, " +
                    "rule id must be specified");
        }

        if (regionId != null && ruleId != null) {
            throw new InvalidParameterValueException("Invalid arguments. Only one of region id, " +
                    "rule id must be specified");
        }

        if (ruleId != null) {
            GlobalLoadBalancerRule gslbRule = _gslbRuleDao.findById(ruleId);
            if (gslbRule == null) {
                throw new InvalidParameterValueException("Invalid gslb rule id specified");
            }
            _accountMgr.checkAccess(caller, org.apache.cloudstack.acl.SecurityChecker.AccessType.ListEntry, false, gslbRule);

            response.add(gslbRule);
            return response;
View Full Code Here


     */
    @Override
    public Region addRegion(int id, String name, String endPoint) {
        //Region Id should be unique
        if( _regionDao.findById(id) != null ){
            throw new InvalidParameterValueException("Region with id: "+id+" already exists");
        }
        //Region Name should be unique
        if( _regionDao.findByName(name) != null ){
            throw new InvalidParameterValueException("Region with name: "+name+" already exists");
        }
        RegionVO region = new RegionVO(id, name, endPoint);
        return _regionDao.persist(region);
    }
View Full Code Here

    @Override
    public Region updateRegion(int id, String name, String endPoint) {
        RegionVO region = _regionDao.findById(id);

        if(region == null){
            throw new InvalidParameterValueException("Region with id: "+id+" does not exist");
        }

        //Ensure region name is unique
        if(name != null){
            RegionVO region1 = _regionDao.findByName(name);
            if(region1 != null && id != region1.getId()){
                throw new InvalidParameterValueException("Region with name: "+name+" already exists");
            }
        }

        if(name != null){
            region.setName(name);
View Full Code Here

     */
    @Override
    public boolean removeRegion(int id) {
        RegionVO region = _regionDao.findById(id);
        if(region == null){
            throw new InvalidParameterValueException("Failed to delete Region: " + id + ", Region not found");
        }
        return _regionDao.remove(id);
    }
View Full Code Here

        //validate the affinityGroupType
        Map<String, AffinityGroupProcessor> typeProcessorMap = getAffinityTypeToProcessorMap();
        if (typeProcessorMap != null && !typeProcessorMap.isEmpty()) {
            if (!typeProcessorMap.containsKey(affinityGroupType)) {
                throw new InvalidParameterValueException("Unable to create affinity group, invalid affinity group type"
                        + affinityGroupType);
            }
        } else {
            throw new InvalidParameterValueException(
                    "Unable to create affinity group, no Affinity Group Types configured");
        }

        AffinityGroupProcessor processor = typeProcessorMap.get(affinityGroupType);
View Full Code Here

        // validate the affinityGroupType
        Map<String, AffinityGroupProcessor> typeProcessorMap = getAffinityTypeToProcessorMap();
        if (typeProcessorMap != null && !typeProcessorMap.isEmpty()) {
            if (!typeProcessorMap.containsKey(affinityGroupType)) {
                throw new InvalidParameterValueException("Unable to create affinity group, invalid affinity group type"
                        + affinityGroupType);
            }
        } else {
            throw new InvalidParameterValueException(
                    "Unable to create affinity group, no Affinity Group Types configured");
        }

        AffinityGroupProcessor processor = typeProcessorMap.get(affinityGroupType);

        if (processor.isAdminControlledGroup() && !_accountMgr.isRootAdmin(caller.getType())) {
            throw new PermissionDeniedException("Cannot create the affinity group");
        }

        ControlledEntity.ACLType aclType = null;
        Account owner = null;
        boolean domainLevel = false;

        if (account != null && domainId != null) {

            owner = _accountMgr.finalizeOwner(caller, account, domainId, null);
            aclType = ControlledEntity.ACLType.Account;

        } else if (domainId != null && account == null) {

            if (!_accountMgr.isRootAdmin(caller.getType())) {
                // non root admin need to pass both account and domain
                throw new InvalidParameterValueException(
                        "Unable to create affinity group, account name must be passed with the domainId");
            } else if (!processor.canBeSharedDomainWide()) {
                // cannot be domain level
                throw new InvalidParameterValueException("Unable to create affinity group, account name is needed");
            }

            DomainVO domain = _domainDao.findById(domainId);
            if (domain == null) {
                throw new InvalidParameterValueException("Unable to find domain by specified id");
            }
            _accountMgr.checkAccess(caller, domain);

            // domain level group, owner is SYSTEM.
            owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
            aclType = ControlledEntity.ACLType.Domain;
            domainLevel = true;

        } else {
            owner = caller;
            aclType = ControlledEntity.ACLType.Account;
        }

        if (_affinityGroupDao.isNameInUse(owner.getAccountId(), owner.getDomainId(), affinityGroupName)) {
            throw new InvalidParameterValueException("Unable to create affinity group, a group with name "
                    + affinityGroupName + " already exisits.");
        }
        if (domainLevel && _affinityGroupDao.findDomainLevelGroupByName(domainId, affinityGroupName) != null) {
            throw new InvalidParameterValueException("Unable to create affinity group, a group with name "
                    + affinityGroupName + " already exisits under the domain.");
        }

        Transaction txn = Transaction.currentTxn();
        txn.start();
View Full Code Here

        AffinityGroupVO group = null;
        if (affinityGroupId != null) {
            group = _affinityGroupDao.findById(affinityGroupId);
            if (group == null) {
                throw new InvalidParameterValueException("Unable to find affinity group: " + affinityGroupId
                        + "; failed to delete group.");
            }
        } else if (affinityGroupName != null) {
            group = _affinityGroupDao.findByAccountAndName(owner.getAccountId(), affinityGroupName);
            if (group == null) {
                throw new InvalidParameterValueException("Unable to find affinity group: " + affinityGroupName
                        + "; failed to delete group.");
            }
        } else {
            throw new InvalidParameterValueException(
                    "Either the affinity group Id or group name must be specified to delete the group");
        }
        if (affinityGroupId == null) {
            affinityGroupId = group.getId();
        }
        // check permissions
        _accountMgr.checkAccess(caller, AccessType.ModifyEntry, true, group);

        final Transaction txn = Transaction.currentTxn();
        txn.start();

        group = _affinityGroupDao.lockRow(affinityGroupId, true);
        if (group == null) {
            throw new InvalidParameterValueException("Unable to find affinity group by id " + affinityGroupId);
        }

        List<AffinityGroupVMMapVO> affinityGroupVmMap = _affinityGroupVMMapDao.listByAffinityGroup(affinityGroupId);
        if (!affinityGroupVmMap.isEmpty()) {
            SearchBuilder<AffinityGroupVMMapVO> listByAffinityGroup = _affinityGroupVMMapDao.createSearchBuilder();
View Full Code Here

        }

        if (vmId != null) {
            UserVmVO userVM = _userVmDao.findById(vmId);
            if (userVM == null) {
                throw new InvalidParameterValueException("Unable to list affinity groups for virtual machine instance "
                        + vmId + "; instance not found.");
            }
            _accountMgr.checkAccess(caller, null, true, userVM);
            // add join to affinity_groups_vm_map
            groupSearch.join("vmInstanceSearch", vmInstanceSearch, groupSearch.entity().getId(), vmInstanceSearch
View Full Code Here

    @Override
    public UserVm updateVMAffinityGroups(Long vmId, List<Long> affinityGroupIds) {
        // Verify input parameters
        UserVmVO vmInstance = _userVmDao.findById(vmId);
        if (vmInstance == null) {
            throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId);
        }

        // Check that the VM is stopped
        if (!vmInstance.getState().equals(State.Stopped)) {
            s_logger.warn("Unable to update affinity groups of the virtual machine " + vmInstance.toString()
                    + " in state " + vmInstance.getState());
            throw new InvalidParameterValueException("Unable update affinity groups of the virtual machine "
                    + vmInstance.toString() + " " + "in state " + vmInstance.getState()
                    + "; make sure the virtual machine is stopped and not in an error state before updating.");
        }

        Account caller = UserContext.current().getCaller();
        Account owner = _accountMgr.getAccount(vmInstance.getAccountId());

        // check that the affinity groups exist
        for (Long affinityGroupId : affinityGroupIds) {
            AffinityGroupVO ag = _affinityGroupDao.findById(affinityGroupId);
            if (ag == null) {
                throw new InvalidParameterValueException("Unable to find affinity group by id " + affinityGroupId);
            } else {
                // verify permissions
                _accountMgr.checkAccess(caller, null, true, owner, ag);
                // Root admin has access to both VM and AG by default, but make sure the
                // owner of these entities is same
View Full Code Here

                break;
        }
        if (internalId == null) {
            if (s_logger.isDebugEnabled())
                s_logger.debug("Object entity uuid = " + uuid + " does not exist in the database.");
            throw new InvalidParameterValueException("Invalid parameter " + annotation.name() + " value=" + uuid
                + " due to incorrect long value format, or entity does not exist or due to incorrect parameter annotation for the field in api cmd class.");
        }
        return internalId;
    }
View Full Code Here

TOP

Related Classes of com.cloud.exception.InvalidParameterValueException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.