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;
}
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;
}
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;
}
}
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;
}
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;
}
Aggregations