Search in sources :

Example 76 with DomainVO

use of com.cloud.domain.DomainVO in project cosmic by MissionCriticalCloud.

the class DomainDaoImpl method isChildDomain.

@Override
public boolean isChildDomain(final Long parentId, final Long childId) {
    if ((parentId == null) || (childId == null)) {
        return false;
    }
    if (parentId.equals(childId)) {
        return true;
    }
    boolean result = false;
    final SearchCriteria<DomainVO> sc = DomainPairSearch.create();
    sc.setParameters("id", parentId, childId);
    final List<DomainVO> domainPair = listBy(sc);
    if ((domainPair != null) && (domainPair.size() == 2)) {
        final DomainVO d1 = domainPair.get(0);
        final DomainVO d2 = domainPair.get(1);
        if (d1.getId() == parentId) {
            result = d2.getPath().startsWith(d1.getPath());
        } else {
            result = d1.getPath().startsWith(d2.getPath());
        }
    }
    return result;
}
Also used : DomainVO(com.cloud.domain.DomainVO)

Example 77 with DomainVO

use of com.cloud.domain.DomainVO in project cosmic by MissionCriticalCloud.

the class DomainDaoImpl method remove.

@Override
@DB
public boolean remove(final Long id) {
    // check for any active users / domains assigned to the given domain id and don't remove the domain if there are any
    if (id != null && id.longValue() == Domain.ROOT_DOMAIN) {
        s_logger.error("Can not remove domain " + id + " as it is ROOT domain");
        return false;
    } else {
        if (id == null) {
            s_logger.error("Can not remove domain without id.");
            return false;
        }
    }
    final DomainVO domain = findById(id);
    if (domain == null) {
        s_logger.info("Unable to remove domain as domain " + id + " no longer exists");
        return true;
    }
    if (domain.getParent() == null) {
        s_logger.error("Invalid domain " + id + ", orphan?");
        return false;
    }
    final String sql = "SELECT * from account where domain_id = " + id + " and removed is null";
    final String sql1 = "SELECT * from domain where parent = " + id + " and removed is null";
    boolean success = false;
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    try {
        txn.start();
        final DomainVO parentDomain = super.lockRow(domain.getParent(), true);
        if (parentDomain == null) {
            s_logger.error("Unable to load parent domain: " + domain.getParent());
            return false;
        }
        PreparedStatement stmt = txn.prepareAutoCloseStatement(sql);
        ResultSet rs = stmt.executeQuery();
        if (rs.next()) {
            return false;
        }
        stmt = txn.prepareAutoCloseStatement(sql1);
        rs = stmt.executeQuery();
        if (rs.next()) {
            return false;
        }
        parentDomain.setChildCount(parentDomain.getChildCount() - 1);
        update(parentDomain.getId(), parentDomain);
        success = super.remove(id);
        txn.commit();
    } catch (final SQLException ex) {
        success = false;
        s_logger.error("error removing domain: " + id, ex);
        txn.rollback();
    }
    return success;
}
Also used : DomainVO(com.cloud.domain.DomainVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DB(com.cloud.utils.db.DB)

Example 78 with DomainVO

use of com.cloud.domain.DomainVO in project cosmic by MissionCriticalCloud.

the class DomainDaoImpl method create.

@Override
public synchronized DomainVO create(final DomainVO domain) {
    // make sure domain name is valid
    final String domainName = domain.getName();
    if (domainName != null) {
        if (domainName.contains("/")) {
            throw new IllegalArgumentException("Domain name contains one or more invalid characters.  Please enter a name without '/' characters.");
        }
    } else {
        throw new IllegalArgumentException("Domain name is null.  Please specify a valid domain name.");
    }
    long parent = Domain.ROOT_DOMAIN;
    if (domain.getParent() != null && domain.getParent().longValue() >= Domain.ROOT_DOMAIN) {
        parent = domain.getParent().longValue();
    }
    DomainVO parentDomain = findById(parent);
    if (parentDomain == null) {
        s_logger.error("Unable to load parent domain: " + parent);
        return null;
    }
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    try {
        txn.start();
        parentDomain = this.lockRow(parent, true);
        if (parentDomain == null) {
            s_logger.error("Unable to lock parent domain: " + parent);
            return null;
        }
        domain.setPath(allocPath(parentDomain, domain.getName()));
        domain.setLevel(parentDomain.getLevel() + 1);
        // FIXME:  remove sequence number?
        parentDomain.setNextChildSeq(parentDomain.getNextChildSeq() + 1);
        parentDomain.setChildCount(parentDomain.getChildCount() + 1);
        persist(domain);
        update(parentDomain.getId(), parentDomain);
        txn.commit();
        return domain;
    } catch (final Exception e) {
        s_logger.error("Unable to create domain due to " + e.getMessage(), e);
        txn.rollback();
        return null;
    }
}
Also used : DomainVO(com.cloud.domain.DomainVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException)

Example 79 with DomainVO

use of com.cloud.domain.DomainVO in project cosmic by MissionCriticalCloud.

the class ExplicitDedicationProcessor method getDomainParentIds.

private List<Long> getDomainParentIds(final long domainId) {
    DomainVO domainRecord = _domainDao.findById(domainId);
    final List<Long> domainIds = new ArrayList<>();
    domainIds.add(domainRecord.getId());
    while (domainRecord.getParent() != null) {
        domainRecord = _domainDao.findById(domainRecord.getParent());
        domainIds.add(domainRecord.getId());
    }
    return domainIds;
}
Also used : DomainVO(com.cloud.domain.DomainVO) ArrayList(java.util.ArrayList)

Example 80 with DomainVO

use of com.cloud.domain.DomainVO in project cosmic by MissionCriticalCloud.

the class DedicatedResourceManagerImpl method createDedicateHostResponse.

@Override
public DedicateHostResponse createDedicateHostResponse(final DedicatedResources resource) {
    final DedicateHostResponse dedicateHostResponse = new DedicateHostResponse();
    final HostVO host = _hostDao.findById(resource.getHostId());
    final DomainVO domain = _domainDao.findById(resource.getDomainId());
    final AccountVO account = _accountDao.findById(resource.getAccountId());
    final AffinityGroup group = _affinityGroupDao.findById(resource.getAffinityGroupId());
    dedicateHostResponse.setId(resource.getUuid());
    dedicateHostResponse.setHostId(host.getUuid());
    dedicateHostResponse.setHostName(host.getName());
    dedicateHostResponse.setDomainId(domain.getUuid());
    dedicateHostResponse.setDomainName(domain.getName());
    dedicateHostResponse.setAffinityGroupId(group.getUuid());
    if (account != null) {
        dedicateHostResponse.setAccountId(account.getUuid());
        dedicateHostResponse.setAccountName(account.getAccountName());
    }
    dedicateHostResponse.setObjectName("dedicatedhost");
    return dedicateHostResponse;
}
Also used : DomainVO(com.cloud.domain.DomainVO) DedicateHostResponse(com.cloud.api.response.DedicateHostResponse) AccountVO(com.cloud.user.AccountVO) HostVO(com.cloud.host.HostVO) AffinityGroup(com.cloud.affinity.AffinityGroup)

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