Search in sources :

Example 11 with AffinityGroup

use of com.cloud.affinity.AffinityGroup in project cosmic by MissionCriticalCloud.

the class DedicatedResourceManagerImpl method createDedicatePodResponse.

@Override
public DedicatePodResponse createDedicatePodResponse(final DedicatedResources resource) {
    final DedicatePodResponse dedicatePodResponse = new DedicatePodResponse();
    final HostPodVO pod = _podDao.findById(resource.getPodId());
    final DomainVO domain = _domainDao.findById(resource.getDomainId());
    final AccountVO account = _accountDao.findById(resource.getAccountId());
    final AffinityGroup group = _affinityGroupDao.findById(resource.getAffinityGroupId());
    dedicatePodResponse.setId(resource.getUuid());
    dedicatePodResponse.setPodId(pod.getUuid());
    dedicatePodResponse.setPodName(pod.getName());
    dedicatePodResponse.setDomainId(domain.getUuid());
    dedicatePodResponse.setDomainName(domain.getName());
    dedicatePodResponse.setAffinityGroupId(group.getUuid());
    if (account != null) {
        dedicatePodResponse.setAccountId(account.getUuid());
        dedicatePodResponse.setAccountName(account.getAccountName());
    }
    dedicatePodResponse.setObjectName("dedicatedpod");
    return dedicatePodResponse;
}
Also used : DomainVO(com.cloud.domain.DomainVO) DedicatePodResponse(com.cloud.api.response.DedicatePodResponse) HostPodVO(com.cloud.dc.HostPodVO) AccountVO(com.cloud.user.AccountVO) AffinityGroup(com.cloud.affinity.AffinityGroup)

Example 12 with AffinityGroup

use of com.cloud.affinity.AffinityGroup in project cosmic by MissionCriticalCloud.

the class DedicatedResourceManagerImpl method findOrCreateDedicatedAffinityGroup.

private AffinityGroup findOrCreateDedicatedAffinityGroup(final Long domainId, final Long accountId) {
    if (domainId == null) {
        return null;
    }
    AffinityGroup group = null;
    String accountName = null;
    String affinityGroupName = null;
    if (accountId != null) {
        final AccountVO account = _accountDao.findById(accountId);
        accountName = account.getAccountName();
        group = _affinityGroupDao.findByAccountAndType(accountId, "ExplicitDedication");
        if (group != null) {
            return group;
        }
        // default to a groupname with account/domain information
        affinityGroupName = "DedicatedGrp-" + accountName;
    } else {
        // domain level group
        group = _affinityGroupDao.findDomainLevelGroupByType(domainId, "ExplicitDedication");
        if (group != null) {
            return group;
        }
        // default to a groupname with account/domain information
        final String domainName = _domainDao.findById(domainId).getName();
        affinityGroupName = "DedicatedGrp-domain-" + domainName;
    }
    group = _affinityGroupService.createAffinityGroup(accountName, null, domainId, affinityGroupName, "ExplicitDedication", "dedicated resources group");
    return group;
}
Also used : AccountVO(com.cloud.user.AccountVO) AffinityGroup(com.cloud.affinity.AffinityGroup)

Example 13 with AffinityGroup

use of com.cloud.affinity.AffinityGroup in project cosmic by MissionCriticalCloud.

the class DedicatedResourceManagerImpl method dedicateHost.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_DEDICATE_RESOURCE, eventDescription = "dedicating a Host")
public List<DedicatedResourceVO> dedicateHost(final Long hostId, final Long domainId, final String accountName) {
    Long accountId = null;
    if (accountName != null) {
        final Account caller = CallContext.current().getCallingAccount();
        final Account owner = _accountMgr.finalizeOwner(caller, accountName, domainId, null);
        accountId = owner.getId();
    }
    checkAccountAndDomain(accountId, domainId);
    final HostVO host = _hostDao.findById(hostId);
    if (host == null) {
        throw new InvalidParameterValueException("Unable to find host by id " + hostId);
    } else {
        // check if host is of routing type
        if (host.getType() != Host.Type.Routing) {
            throw new CloudRuntimeException("Invalid host type for host " + host.getName());
        }
        final DedicatedResourceVO dedicatedHost = _dedicatedDao.findByHostId(hostId);
        final DedicatedResourceVO dedicatedClusterOfHost = _dedicatedDao.findByClusterId(host.getClusterId());
        final DedicatedResourceVO dedicatedPodOfHost = _dedicatedDao.findByPodId(host.getPodId());
        final DedicatedResourceVO dedicatedZoneOfHost = _dedicatedDao.findByZoneId(host.getDataCenterId());
        if (dedicatedHost != null) {
            s_logger.error("Host " + host.getName() + " is already dedicated");
            throw new CloudRuntimeException("Host " + host.getName() + " is already dedicated");
        }
        if (dedicatedClusterOfHost != null) {
            final boolean domainIdInChildreanList = getDomainChildIds(dedicatedClusterOfHost.getDomainId()).contains(domainId);
            // can dedicate a host to an account/domain if cluster is dedicated to parent-domain
            if (dedicatedClusterOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedClusterOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) {
                final ClusterVO cluster = _clusterDao.findById(host.getClusterId());
                s_logger.error("Host's Cluster " + cluster.getName() + " is already dedicated");
                throw new CloudRuntimeException("Host's Cluster " + cluster.getName() + " is already dedicated");
            }
        }
        if (dedicatedPodOfHost != null) {
            final boolean domainIdInChildreanList = getDomainChildIds(dedicatedPodOfHost.getDomainId()).contains(domainId);
            // can dedicate a host to an account/domain if pod is dedicated to parent-domain
            if (dedicatedPodOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedPodOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) {
                final HostPodVO pod = _podDao.findById(host.getPodId());
                s_logger.error("Host's Pod " + pod.getName() + " is already dedicated");
                throw new CloudRuntimeException("Host's Pod " + pod.getName() + " is already dedicated");
            }
        }
        if (dedicatedZoneOfHost != null) {
            final boolean domainIdInChildreanList = getDomainChildIds(dedicatedZoneOfHost.getDomainId()).contains(domainId);
            // can dedicate a host to an account/domain if zone is dedicated to parent-domain
            if (dedicatedZoneOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedZoneOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) {
                final Zone zone = zoneRepository.findOne(host.getDataCenterId());
                s_logger.error("Host's Data Center " + zone.getName() + " is already dedicated");
                throw new CloudRuntimeException("Host's Data Center " + zone.getName() + " is already dedicated");
            }
        }
    }
    final List<Long> childDomainIds = getDomainChildIds(domainId);
    childDomainIds.add(domainId);
    checkHostSuitabilityForExplicitDedication(accountId, childDomainIds, hostId);
    final Long accountIdFinal = accountId;
    return Transaction.execute(new TransactionCallback<List<DedicatedResourceVO>>() {

        @Override
        public List<DedicatedResourceVO> doInTransaction(final TransactionStatus status) {
            // find or create the affinity group by name under this account/domain
            final AffinityGroup group = findOrCreateDedicatedAffinityGroup(domainId, accountIdFinal);
            if (group == null) {
                s_logger.error("Unable to dedicate zone due to, failed to create dedication affinity group");
                throw new CloudRuntimeException("Failed to dedicate zone. Please contact Cloud Support.");
            }
            DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(null, null, null, hostId, null, null, group.getId());
            try {
                dedicatedResource.setDomainId(domainId);
                if (accountIdFinal != null) {
                    dedicatedResource.setAccountId(accountIdFinal);
                }
                dedicatedResource = _dedicatedDao.persist(dedicatedResource);
            } catch (final Exception e) {
                s_logger.error("Unable to dedicate host due to " + e.getMessage(), e);
                throw new CloudRuntimeException("Failed to dedicate host. Please contact Cloud Support.");
            }
            final List<DedicatedResourceVO> result = new ArrayList<>();
            result.add(dedicatedResource);
            return result;
        }
    });
}
Also used : Account(com.cloud.user.Account) ClusterVO(com.cloud.dc.ClusterVO) Zone(com.cloud.db.model.Zone) TransactionStatus(com.cloud.utils.db.TransactionStatus) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO) AffinityGroup(com.cloud.affinity.AffinityGroup) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) List(java.util.List) ArrayList(java.util.ArrayList) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 14 with AffinityGroup

use of com.cloud.affinity.AffinityGroup in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method createDedicatedAffinityGroup.

private AffinityGroup createDedicatedAffinityGroup(String affinityGroupName, final Long domainId, final Long accountId) {
    if (affinityGroupName == null) {
        // default to a groupname with account/domain information
        affinityGroupName = "ZoneDedicatedGrp-domain-" + domainId + (accountId != null ? "-acct-" + accountId : "");
    }
    AffinityGroup group;
    String accountName = null;
    if (accountId != null) {
        final AccountVO account = _accountDao.findById(accountId);
        accountName = account.getAccountName();
        group = _affinityGroupDao.findByAccountAndName(accountId, affinityGroupName);
        if (group != null) {
            return group;
        }
    } else {
        // domain level group
        group = _affinityGroupDao.findDomainLevelGroupByName(domainId, affinityGroupName);
        if (group != null) {
            return group;
        }
    }
    group = _affinityGroupService.createAffinityGroup(accountName, null, domainId, affinityGroupName, "ExplicitDedication", "dedicated resources group");
    return group;
}
Also used : AccountVO(com.cloud.user.AccountVO) AffinityGroup(com.cloud.affinity.AffinityGroup)

Example 15 with AffinityGroup

use of com.cloud.affinity.AffinityGroup in project cosmic by MissionCriticalCloud.

the class CreateAffinityGroupCmd method create.

@Override
public void create() throws ResourceAllocationException {
    final AffinityGroup result = _affinityGroupService.createAffinityGroup(this);
    if (result != null) {
        setEntityId(result.getId());
        setEntityUuid(result.getUuid());
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create affinity group entity" + affinityGroupName);
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) AffinityGroup(com.cloud.affinity.AffinityGroup)

Aggregations

AffinityGroup (com.cloud.affinity.AffinityGroup)15 AccountVO (com.cloud.user.AccountVO)6 Zone (com.cloud.db.model.Zone)5 ClusterVO (com.cloud.dc.ClusterVO)5 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)5 HostPodVO (com.cloud.dc.HostPodVO)5 HostVO (com.cloud.host.HostVO)5 Account (com.cloud.user.Account)5 DB (com.cloud.utils.db.DB)5 TransactionStatus (com.cloud.utils.db.TransactionStatus)5 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 DomainVO (com.cloud.domain.DomainVO)4 ActionEvent (com.cloud.event.ActionEvent)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 ConfigurationException (javax.naming.ConfigurationException)4 ServerApiException (com.cloud.api.ServerApiException)2 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)2 Network (com.cloud.network.Network)2