Search in sources :

Example 1 with TransactionCallbackNoReturn

use of com.cloud.utils.db.TransactionCallbackNoReturn in project cloudstack by apache.

the class IAMServiceImpl method deleteIAMPolicy.

@DB
@Override
public boolean deleteIAMPolicy(final long iamPolicyId) {
    // get the Acl Policy entity
    final IAMPolicy policy = _aclPolicyDao.findById(iamPolicyId);
    if (policy == null) {
        throw new InvalidParameterValueException("Unable to find acl policy: " + iamPolicyId + "; failed to delete acl policy.");
    }
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            // remove this policy related entry in acl_group_policy_map
            List<IAMGroupPolicyMapVO> groupPolicyMap = _aclGroupPolicyMapDao.listByPolicyId(policy.getId());
            if (groupPolicyMap != null) {
                for (IAMGroupPolicyMapVO gr : groupPolicyMap) {
                    _aclGroupPolicyMapDao.remove(gr.getId());
                }
            }
            // remove this policy related entry in acl_account_policy_map table
            List<IAMAccountPolicyMapVO> policyAcctMap = _aclAccountPolicyMapDao.listByPolicyId(policy.getId());
            if (policyAcctMap != null) {
                for (IAMAccountPolicyMapVO policyAcct : policyAcctMap) {
                    _aclAccountPolicyMapDao.remove(policyAcct.getId());
                }
            }
            // remove this policy related entry in acl_policy_permission table
            List<IAMPolicyPermissionVO> policyPermMap = _policyPermissionDao.listByPolicy(policy.getId());
            if (policyPermMap != null) {
                for (IAMPolicyPermissionVO policyPerm : policyPermMap) {
                    _policyPermissionDao.remove(policyPerm.getId());
                }
            }
            // remove this role from acl_role table
            _aclPolicyDao.remove(iamPolicyId);
        }
    });
    invalidateIAMCache();
    return true;
}
Also used : IAMPolicy(org.apache.cloudstack.iam.api.IAMPolicy) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ArrayList(java.util.ArrayList) List(java.util.List) DB(com.cloud.utils.db.DB)

Example 2 with TransactionCallbackNoReturn

use of com.cloud.utils.db.TransactionCallbackNoReturn in project cloudstack by apache.

the class IAMServiceImpl method deleteIAMGroup.

@DB
@Override
public boolean deleteIAMGroup(final Long iamGroupId) {
    // get the Acl Group entity
    final IAMGroup grp = _aclGroupDao.findById(iamGroupId);
    if (grp == null) {
        throw new InvalidParameterValueException("Unable to find acl group: " + iamGroupId + "; failed to delete acl group.");
    }
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            // remove this group related entry in acl_group_policy_map
            List<IAMGroupPolicyMapVO> groupPolicyMap = _aclGroupPolicyMapDao.listByGroupId(grp.getId());
            if (groupPolicyMap != null) {
                for (IAMGroupPolicyMapVO gr : groupPolicyMap) {
                    _aclGroupPolicyMapDao.remove(gr.getId());
                }
            }
            // remove this group related entry in acl_group_account table
            List<IAMGroupAccountMapVO> groupAcctMap = _aclGroupAccountMapDao.listByGroupId(grp.getId());
            if (groupAcctMap != null) {
                for (IAMGroupAccountMapVO grpAcct : groupAcctMap) {
                    _aclGroupAccountMapDao.remove(grpAcct.getId());
                }
            }
            // remove this group from acl_group table
            _aclGroupDao.remove(iamGroupId);
        }
    });
    invalidateIAMCache();
    return true;
}
Also used : IAMGroup(org.apache.cloudstack.iam.api.IAMGroup) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ArrayList(java.util.ArrayList) List(java.util.List) DB(com.cloud.utils.db.DB)

Example 3 with TransactionCallbackNoReturn

use of com.cloud.utils.db.TransactionCallbackNoReturn in project cloudstack by apache.

the class IAMServiceImpl method removeAccountsFromGroup.

@DB
@Override
public IAMGroup removeAccountsFromGroup(final List<Long> acctIds, final Long groupId) {
    // get the Acl Group entity
    IAMGroup group = _aclGroupDao.findById(groupId);
    if (group == null) {
        throw new InvalidParameterValueException("Unable to find acl group: " + groupId + "; failed to remove accounts from acl group.");
    }
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            // remove entries from acl_group_account_map table
            for (Long acctId : acctIds) {
                IAMGroupAccountMapVO grMap = _aclGroupAccountMapDao.findByGroupAndAccount(groupId, acctId);
                if (grMap != null) {
                    // not removed yet
                    _aclGroupAccountMapDao.remove(grMap.getId());
                }
            }
        }
    });
    invalidateIAMCache();
    return group;
}
Also used : IAMGroup(org.apache.cloudstack.iam.api.IAMGroup) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) DB(com.cloud.utils.db.DB)

Example 4 with TransactionCallbackNoReturn

use of com.cloud.utils.db.TransactionCallbackNoReturn in project cloudstack by apache.

the class IAMServiceImpl method attachIAMPoliciesToGroup.

@DB
@Override
public IAMGroup attachIAMPoliciesToGroup(final List<Long> policyIds, final Long groupId) {
    // get the Acl Group entity
    IAMGroup group = _aclGroupDao.findById(groupId);
    if (group == null) {
        throw new InvalidParameterValueException("Unable to find acl group: " + groupId + "; failed to add roles to acl group.");
    }
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            // add entries in acl_group_policy_map table
            for (Long policyId : policyIds) {
                IAMPolicy policy = _aclPolicyDao.findById(policyId);
                if (policy == null) {
                    throw new InvalidParameterValueException("Unable to find acl policy: " + policyId + "; failed to add policies to acl group.");
                }
                IAMGroupPolicyMapVO grMap = _aclGroupPolicyMapDao.findByGroupAndPolicy(groupId, policyId);
                if (grMap == null) {
                    // not there already
                    grMap = new IAMGroupPolicyMapVO(groupId, policyId);
                    _aclGroupPolicyMapDao.persist(grMap);
                }
            }
        }
    });
    invalidateIAMCache();
    return group;
}
Also used : IAMGroup(org.apache.cloudstack.iam.api.IAMGroup) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) IAMPolicy(org.apache.cloudstack.iam.api.IAMPolicy) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) DB(com.cloud.utils.db.DB)

Example 5 with TransactionCallbackNoReturn

use of com.cloud.utils.db.TransactionCallbackNoReturn in project cloudstack by apache.

the class ManagementServerImpl method updateDomain.

@Override
@DB
public DomainVO updateDomain(final UpdateDomainCmd cmd) {
    final Long domainId = cmd.getId();
    final String domainName = cmd.getDomainName();
    final String networkDomain = cmd.getNetworkDomain();
    // check if domain exists in the system
    final DomainVO domain = _domainDao.findById(domainId);
    if (domain == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find domain with specified domain id");
        ex.addProxyObject(domainId.toString(), "domainId");
        throw ex;
    } else if (domain.getParent() == null && domainName != null) {
        // name
        throw new InvalidParameterValueException("ROOT domain can not be edited with a new name");
    }
    final Account caller = getCaller();
    _accountMgr.checkAccess(caller, domain);
    // domain name is unique under the parent domain
    if (domainName != null) {
        final SearchCriteria<DomainVO> sc = _domainDao.createSearchCriteria();
        sc.addAnd("name", SearchCriteria.Op.EQ, domainName);
        sc.addAnd("parent", SearchCriteria.Op.EQ, domain.getParent());
        final List<DomainVO> domains = _domainDao.search(sc, null);
        final boolean sameDomain = domains.size() == 1 && domains.get(0).getId() == domainId;
        if (!domains.isEmpty() && !sameDomain) {
            final InvalidParameterValueException ex = new InvalidParameterValueException("Failed to update specified domain id with name '" + domainName + "' since it already exists in the system");
            ex.addProxyObject(domain.getUuid(), "domainId");
            throw ex;
        }
    }
    // validate network domain
    if (networkDomain != null && !networkDomain.isEmpty()) {
        if (!NetUtils.verifyDomainName(networkDomain)) {
            throw new InvalidParameterValueException("Invalid network domain. Total length shouldn't exceed 190 chars. Each domain label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', the digits '0' through '9', " + "and the hyphen ('-'); can't start or end with \"-\"");
        }
    }
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            if (domainName != null) {
                final String updatedDomainPath = getUpdatedDomainPath(domain.getPath(), domainName);
                updateDomainChildren(domain, updatedDomainPath);
                domain.setName(domainName);
                domain.setPath(updatedDomainPath);
            }
            if (networkDomain != null) {
                if (networkDomain.isEmpty()) {
                    domain.setNetworkDomain(null);
                } else {
                    domain.setNetworkDomain(networkDomain);
                }
            }
            _domainDao.update(domainId, domain);
        }
    });
    return _domainDao.findById(domainId);
}
Also used : DomainVO(com.cloud.domain.DomainVO) Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) DB(com.cloud.utils.db.DB)

Aggregations

TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)172 TransactionStatus (com.cloud.utils.db.TransactionStatus)172 DB (com.cloud.utils.db.DB)133 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)71 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)60 ArrayList (java.util.ArrayList)57 ActionEvent (com.cloud.event.ActionEvent)42 List (java.util.List)42 Account (com.cloud.user.Account)39 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)38 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)36 ConfigurationException (javax.naming.ConfigurationException)32 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)26 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)24 IPAddressVO (com.cloud.network.dao.IPAddressVO)24 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)23 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)18 HostVO (com.cloud.host.HostVO)18 HashMap (java.util.HashMap)18 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)17