Search in sources :

Example 71 with DomainVO

use of com.cloud.domain.DomainVO in project cloudstack by apache.

the class DomainManagerImpl method updateDomain.

@Override
@ActionEvent(eventType = EventTypes.EVENT_DOMAIN_UPDATE, eventDescription = "updating Domain")
@DB
public DomainVO updateDomain(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) {
        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) {
        // check if domain is ROOT domain - and deny to edit it with the new name
        throw new InvalidParameterValueException("ROOT domain can not be edited with a new name");
    }
    // check permissions
    Account caller = getCaller();
    _accountMgr.checkAccess(caller, domain);
    // domain name is unique in the cloud
    if (domainName != null) {
        SearchCriteria<DomainVO> sc = _domainDao.createSearchCriteria();
        sc.addAnd("name", SearchCriteria.Op.EQ, domainName);
        sc.addAnd("parent", SearchCriteria.Op.EQ, domain.getParent());
        List<DomainVO> domains = _domainDao.search(sc, null);
        boolean sameDomain = (domains.size() == 1 && domains.get(0).getId() == domainId);
        if (!domains.isEmpty() && !sameDomain) {
            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(TransactionStatus status) {
            if (domainName != null) {
                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);
            CallContext.current().putContextParameter(Domain.class, domain.getUuid());
        }
    });
    return _domainDao.findById(domainId);
}
Also used : DomainVO(com.cloud.domain.DomainVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) Domain(com.cloud.domain.Domain) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 72 with DomainVO

use of com.cloud.domain.DomainVO in project cloudstack by apache.

the class DomainManagerImpl method updateDomainChildren.

private void updateDomainChildren(DomainVO domain, String updatedDomainPrefix) {
    List<DomainVO> domainChildren = _domainDao.findAllChildren(domain.getPath(), domain.getId());
    // for each child, update the path
    for (DomainVO dom : domainChildren) {
        dom.setPath(dom.getPath().replaceFirst(domain.getPath(), updatedDomainPrefix));
        _domainDao.update(dom.getId(), dom);
    }
}
Also used : DomainVO(com.cloud.domain.DomainVO)

Example 73 with DomainVO

use of com.cloud.domain.DomainVO in project cloudstack by apache.

the class DomainManagerImpl method createDomain.

@Override
@ActionEvent(eventType = EventTypes.EVENT_DOMAIN_CREATE, eventDescription = "creating Domain")
public Domain createDomain(String name, Long parentId, String networkDomain, String domainUUID) {
    Account caller = getCaller();
    if (parentId == null) {
        parentId = Long.valueOf(Domain.ROOT_DOMAIN);
    }
    DomainVO parentDomain = _domainDao.findById(parentId);
    if (parentDomain == null) {
        throw new InvalidParameterValueException("Unable to create domain " + name + ", parent domain " + parentId + " not found.");
    }
    if (parentDomain.getState().equals(Domain.State.Inactive)) {
        throw new CloudRuntimeException("The domain cannot be created as the parent domain " + parentDomain.getName() + " is being deleted");
    }
    _accountMgr.checkAccess(caller, parentDomain);
    return createDomain(name, parentId, caller.getId(), networkDomain, domainUUID);
}
Also used : DomainVO(com.cloud.domain.DomainVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ActionEvent(com.cloud.event.ActionEvent)

Example 74 with DomainVO

use of com.cloud.domain.DomainVO in project cloudstack by apache.

the class DomainManagerImpl method getDomainByName.

@Override
public Domain getDomainByName(String name, long parentId) {
    SearchCriteria<DomainVO> sc = _domainDao.createSearchCriteria();
    sc.addAnd("name", SearchCriteria.Op.EQ, name);
    sc.addAnd("parent", SearchCriteria.Op.EQ, parentId);
    Domain domain = _domainDao.findOneBy(sc);
    return domain;
}
Also used : DomainVO(com.cloud.domain.DomainVO) Domain(com.cloud.domain.Domain)

Example 75 with DomainVO

use of com.cloud.domain.DomainVO in project cloudstack by apache.

the class DomainManagerImpl method searchForDomainChildren.

@Override
public Pair<List<? extends Domain>, Integer> searchForDomainChildren(ListDomainChildrenCmd cmd) throws PermissionDeniedException {
    Long domainId = cmd.getId();
    String domainName = cmd.getDomainName();
    Boolean isRecursive = cmd.isRecursive();
    Object keyword = cmd.getKeyword();
    boolean listAll = cmd.listAll();
    String path = null;
    Account caller = getCaller();
    if (domainId != null) {
        _accountMgr.checkAccess(caller, getDomain(domainId));
    } else {
        domainId = caller.getDomainId();
    }
    DomainVO domain = _domainDao.findById(domainId);
    if (domain != null && isRecursive && !listAll) {
        path = domain.getPath();
        domainId = null;
    }
    Filter searchFilter = new Filter(DomainVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
    Pair<List<DomainVO>, Integer> result = searchForDomainChildren(searchFilter, domainId, domainName, keyword, path, true);
    return new Pair<List<? extends Domain>, Integer>(result.first(), result.second());
}
Also used : DomainVO(com.cloud.domain.DomainVO) Filter(com.cloud.utils.db.Filter) List(java.util.List) ArrayList(java.util.ArrayList) Pair(com.cloud.utils.Pair)

Aggregations

DomainVO (com.cloud.domain.DomainVO)196 Account (com.cloud.user.Account)85 AccountVO (com.cloud.user.AccountVO)64 Test (org.junit.Test)56 ArrayList (java.util.ArrayList)53 DomainDao (com.cloud.domain.dao.DomainDao)30 Field (java.lang.reflect.Field)30 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)29 SslCertDao (com.cloud.network.dao.SslCertDao)29 AccountManager (com.cloud.user.AccountManager)29 SslCertVO (com.cloud.network.dao.SslCertVO)27 List (java.util.List)26 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)24 Pair (com.cloud.utils.Pair)24 Domain (com.cloud.domain.Domain)23 Filter (com.cloud.utils.db.Filter)23 File (java.io.File)23 IOException (java.io.IOException)23 FileUtils.readFileToString (org.apache.commons.io.FileUtils.readFileToString)23 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)22