use of com.cloud.model.enumeration.HypervisorType in project cosmic by MissionCriticalCloud.
the class ClusterDaoImpl method getAvailableHypervisorInZone.
@Override
public List<HypervisorType> getAvailableHypervisorInZone(final Long zoneId) {
final SearchCriteria<ClusterVO> sc = AvailHyperSearch.create();
if (zoneId != null) {
sc.setParameters("zoneId", zoneId);
}
final List<ClusterVO> clusters = listBy(sc);
final List<HypervisorType> hypers = new ArrayList<>(4);
for (final ClusterVO cluster : clusters) {
hypers.add(cluster.getHypervisorType());
}
return hypers;
}
use of com.cloud.model.enumeration.HypervisorType in project cosmic by MissionCriticalCloud.
the class QueryManagerImpl method searchForTemplatesInternal.
private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(final Long templateId, final String name, final String keyword, final TemplateFilter templateFilter, final boolean isIso, final Boolean bootable, final Long pageSize, final Long startIndex, final Long zoneId, final HypervisorType hyperType, final boolean showDomr, final boolean onlyReady, final List<Account> permittedAccounts, final Account caller, final ListProjectResourcesCriteria listProjectResourcesCriteria, final Map<String, String> tags, final boolean showRemovedTmpl) {
// check if zone is configured, if not, just return empty list
List<HypervisorType> hypers = null;
if (!isIso) {
hypers = _resourceMgr.listAvailHypervisorInZone(null, null);
if (hypers == null || hypers.isEmpty()) {
return new Pair<>(new ArrayList<>(), 0);
}
}
final VMTemplateVO template;
Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
isAscending = isAscending == null ? Boolean.TRUE : isAscending;
final Filter searchFilter = new Filter(TemplateJoinVO.class, "sortKey", isAscending, startIndex, pageSize);
searchFilter.addOrderBy(TemplateJoinVO.class, "tempZonePair", isAscending);
final SearchBuilder<TemplateJoinVO> sb = _templateJoinDao.createSearchBuilder();
// select distinct (templateId, zoneId) pair
sb.select(null, Func.DISTINCT, sb.entity().getTempZonePair());
final SearchCriteria<TemplateJoinVO> sc = sb.create();
// verify templateId parameter and specially handle it
if (templateId != null) {
// Done for backward compatibility - Bug-5221
template = _templateDao.findByIdIncludingRemoved(templateId);
if (template == null) {
throw new InvalidParameterValueException("Please specify a valid template ID.");
}
// If ISO requested then it should be ISO.
if (isIso && template.getFormat() != ImageFormat.ISO) {
s_logger.error("Template Id " + templateId + " is not an ISO");
final InvalidParameterValueException ex = new InvalidParameterValueException("Specified Template Id is not an ISO");
ex.addProxyObject(template.getUuid(), "templateId");
throw ex;
}
// If ISO not requested then it shouldn't be an ISO.
if (!isIso && template.getFormat() == ImageFormat.ISO) {
s_logger.error("Incorrect format of the template id " + templateId);
final InvalidParameterValueException ex = new InvalidParameterValueException("Incorrect format " + template.getFormat() + " of the specified template id");
ex.addProxyObject(template.getUuid(), "templateId");
throw ex;
}
// if template is not public, perform permission check here
if (!template.isPublicTemplate() && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
_accountMgr.checkAccess(caller, null, false, template);
}
// if templateId is specified, then we will just use the id to
// search and ignore other query parameters
sc.addAnd("id", SearchCriteria.Op.EQ, templateId);
} else {
final DomainVO domain;
if (!permittedAccounts.isEmpty()) {
domain = _domainDao.findById(permittedAccounts.get(0).getDomainId());
} else {
domain = _domainDao.findById(Domain.ROOT_DOMAIN);
}
// add criteria for project or not
if (listProjectResourcesCriteria == ListProjectResourcesCriteria.SkipProjectResources) {
sc.addAnd("accountType", SearchCriteria.Op.NEQ, Account.ACCOUNT_TYPE_PROJECT);
} else if (listProjectResourcesCriteria == ListProjectResourcesCriteria.ListProjectResourcesOnly) {
sc.addAnd("accountType", SearchCriteria.Op.EQ, Account.ACCOUNT_TYPE_PROJECT);
}
// add criteria for domain path in case of domain admin
if ((templateFilter == TemplateFilter.self || templateFilter == TemplateFilter.selfexecutable) && (caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN)) {
sc.addAnd("domainPath", SearchCriteria.Op.LIKE, domain.getPath() + "%");
}
final List<Long> relatedDomainIds = new ArrayList<>();
final List<Long> permittedAccountIds = new ArrayList<>();
if (!permittedAccounts.isEmpty()) {
for (final Account account : permittedAccounts) {
permittedAccountIds.add(account.getId());
final boolean publicTemplates = templateFilter == TemplateFilter.featured || templateFilter == TemplateFilter.community;
// get all parent domain ID's all the way till root domain
DomainVO domainTreeNode;
// if template filter is featured, or community, all child domains should be included in search
if (publicTemplates) {
domainTreeNode = _domainDao.findById(Domain.ROOT_DOMAIN);
} else {
domainTreeNode = _domainDao.findById(account.getDomainId());
}
relatedDomainIds.add(domainTreeNode.getId());
while (domainTreeNode.getParent() != null) {
domainTreeNode = _domainDao.findById(domainTreeNode.getParent());
relatedDomainIds.add(domainTreeNode.getId());
}
// get all child domain ID's
if (_accountMgr.isAdmin(account.getId()) || publicTemplates) {
final List<DomainVO> allChildDomains = _domainDao.findAllChildren(domainTreeNode.getPath(), domainTreeNode.getId());
for (final DomainVO childDomain : allChildDomains) {
relatedDomainIds.add(childDomain.getId());
}
}
}
}
if (!isIso) {
// add hypervisor criteria for template case
if (hypers != null && !hypers.isEmpty()) {
final String[] relatedHypers = new String[hypers.size()];
for (int i = 0; i < hypers.size(); i++) {
relatedHypers[i] = hypers.get(i).toString();
}
sc.addAnd("hypervisorType", SearchCriteria.Op.IN, relatedHypers);
}
}
// control different template filters
if (templateFilter == TemplateFilter.featured || templateFilter == TemplateFilter.community) {
sc.addAnd("publicTemplate", SearchCriteria.Op.EQ, true);
if (templateFilter == TemplateFilter.featured) {
sc.addAnd("featured", SearchCriteria.Op.EQ, true);
} else {
sc.addAnd("featured", SearchCriteria.Op.EQ, false);
}
if (!permittedAccounts.isEmpty()) {
final SearchCriteria<TemplateJoinVO> scc = _templateJoinDao.createSearchCriteria();
scc.addOr("domainId", SearchCriteria.Op.IN, relatedDomainIds.toArray());
scc.addOr("domainId", SearchCriteria.Op.NULL);
sc.addAnd("domainId", SearchCriteria.Op.SC, scc);
}
} else if (templateFilter == TemplateFilter.self || templateFilter == TemplateFilter.selfexecutable) {
if (!permittedAccounts.isEmpty()) {
sc.addAnd("accountId", SearchCriteria.Op.IN, permittedAccountIds.toArray());
}
} else if (templateFilter == TemplateFilter.sharedexecutable || templateFilter == TemplateFilter.shared) {
// only show templates shared by others
sc.addAnd("sharedAccountId", SearchCriteria.Op.IN, permittedAccountIds.toArray());
} else if (templateFilter == TemplateFilter.executable) {
final SearchCriteria<TemplateJoinVO> scc = _templateJoinDao.createSearchCriteria();
scc.addOr("publicTemplate", SearchCriteria.Op.EQ, true);
if (!permittedAccounts.isEmpty()) {
scc.addOr("accountId", SearchCriteria.Op.IN, permittedAccountIds.toArray());
}
sc.addAnd("publicTemplate", SearchCriteria.Op.SC, scc);
} else if (templateFilter == TemplateFilter.all && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
final SearchCriteria<TemplateJoinVO> scc = _templateJoinDao.createSearchCriteria();
scc.addOr("publicTemplate", SearchCriteria.Op.EQ, true);
if (listProjectResourcesCriteria == ListProjectResourcesCriteria.SkipProjectResources) {
scc.addOr("domainPath", SearchCriteria.Op.LIKE, _domainDao.findById(caller.getDomainId()).getPath() + "%");
} else {
if (!permittedAccounts.isEmpty()) {
scc.addOr("accountId", SearchCriteria.Op.IN, permittedAccountIds.toArray());
scc.addOr("sharedAccountId", SearchCriteria.Op.IN, permittedAccountIds.toArray());
}
}
sc.addAnd("publicTemplate", SearchCriteria.Op.SC, scc);
}
// add tags criteria
if (tags != null && !tags.isEmpty()) {
final SearchCriteria<TemplateJoinVO> scc = _templateJoinDao.createSearchCriteria();
for (final Map.Entry<String, String> entry : tags.entrySet()) {
final SearchCriteria<TemplateJoinVO> scTag = _templateJoinDao.createSearchCriteria();
scTag.addAnd("tagKey", SearchCriteria.Op.EQ, entry.getKey());
scTag.addAnd("tagValue", SearchCriteria.Op.EQ, entry.getValue());
if (isIso) {
scTag.addAnd("tagResourceType", SearchCriteria.Op.EQ, ResourceObjectType.ISO);
} else {
scTag.addAnd("tagResourceType", SearchCriteria.Op.EQ, ResourceObjectType.Template);
}
scc.addOr("tagKey", SearchCriteria.Op.SC, scTag);
}
sc.addAnd("tagKey", SearchCriteria.Op.SC, scc);
}
if (keyword != null) {
sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
} else if (name != null) {
sc.addAnd("name", SearchCriteria.Op.EQ, name);
}
if (isIso) {
sc.addAnd("format", SearchCriteria.Op.EQ, "ISO");
} else {
sc.addAnd("format", SearchCriteria.Op.NEQ, "ISO");
}
if (!hyperType.equals(HypervisorType.None)) {
sc.addAnd("hypervisorType", SearchCriteria.Op.EQ, hyperType);
}
if (bootable != null) {
sc.addAnd("bootable", SearchCriteria.Op.EQ, bootable);
}
if (onlyReady) {
final SearchCriteria<TemplateJoinVO> readySc = _templateJoinDao.createSearchCriteria();
readySc.addOr("state", SearchCriteria.Op.EQ, TemplateState.Ready);
final SearchCriteria<TemplateJoinVO> isoPerhostSc = _templateJoinDao.createSearchCriteria();
isoPerhostSc.addAnd("format", SearchCriteria.Op.EQ, ImageFormat.ISO);
isoPerhostSc.addAnd("templateType", SearchCriteria.Op.EQ, TemplateType.PERHOST);
readySc.addOr("templateType", SearchCriteria.Op.SC, isoPerhostSc);
sc.addAnd("state", SearchCriteria.Op.SC, readySc);
}
if (!showDomr) {
// excluding system template
sc.addAnd("templateType", SearchCriteria.Op.NEQ, TemplateType.SYSTEM);
}
}
if (zoneId != null) {
final SearchCriteria<TemplateJoinVO> zoneSc = _templateJoinDao.createSearchCriteria();
zoneSc.addOr("dataCenterId", SearchCriteria.Op.EQ, zoneId);
zoneSc.addOr("dataStoreScope", SearchCriteria.Op.EQ, ScopeType.REGION);
// handle the case where xs-tools.iso do not have data_center information in template_view
final SearchCriteria<TemplateJoinVO> isoPerhostSc = _templateJoinDao.createSearchCriteria();
isoPerhostSc.addAnd("format", SearchCriteria.Op.EQ, ImageFormat.ISO);
isoPerhostSc.addAnd("templateType", SearchCriteria.Op.EQ, TemplateType.PERHOST);
zoneSc.addOr("templateType", SearchCriteria.Op.SC, isoPerhostSc);
sc.addAnd("dataCenterId", SearchCriteria.Op.SC, zoneSc);
}
// don't return removed template, this should not be needed since we
// changed annotation for removed field in TemplateJoinVO.
// sc.addAnd("removed", SearchCriteria.Op.NULL);
// search unique templates and find details by Ids
final Pair<List<TemplateJoinVO>, Integer> uniqueTmplPair;
if (showRemovedTmpl) {
uniqueTmplPair = _templateJoinDao.searchIncludingRemovedAndCount(sc, searchFilter);
} else {
sc.addAnd("templateState", SearchCriteria.Op.IN, new State[] { State.Active, State.NotUploaded, State.UploadInProgress });
uniqueTmplPair = _templateJoinDao.searchAndCount(sc, searchFilter);
}
final Integer count = uniqueTmplPair.second();
if (count.intValue() == 0) {
// empty result
return uniqueTmplPair;
}
final List<TemplateJoinVO> uniqueTmpls = uniqueTmplPair.first();
final String[] tzIds = new String[uniqueTmpls.size()];
int i = 0;
for (final TemplateJoinVO v : uniqueTmpls) {
tzIds[i++] = v.getTempZonePair();
}
final List<TemplateJoinVO> vrs = _templateJoinDao.searchByTemplateZonePair(showRemovedTmpl, tzIds);
return new Pair<>(vrs, count);
// TODO: revisit the special logic for iso search in
// VMTemplateDaoImpl.searchForTemplates and understand why we need to
// specially handle ISO. The original logic is very twisted and no idea
// about what the code was doing.
}
use of com.cloud.model.enumeration.HypervisorType in project cosmic by MissionCriticalCloud.
the class QueryManagerImpl method searchForTemplatesInternal.
private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(final ListTemplatesCmd cmd) {
final TemplateFilter templateFilter = TemplateFilter.valueOf(cmd.getTemplateFilter());
final Long id = cmd.getId();
final Map<String, String> tags = cmd.getTags();
final boolean showRemovedTmpl = cmd.getShowRemoved();
final Account caller = CallContext.current().getCallingAccount();
boolean listAll = false;
if (templateFilter != null && templateFilter == TemplateFilter.all) {
if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
throw new InvalidParameterValueException("Filter " + TemplateFilter.all + " can be specified by admin only");
}
listAll = true;
}
final List<Long> permittedAccountIds = new ArrayList<>();
final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(cmd.getDomainId(), cmd.isRecursive(), null);
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccountIds, domainIdRecursiveListProject, listAll, false);
final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
final List<Account> permittedAccounts = new ArrayList<>();
for (final Long accountId : permittedAccountIds) {
permittedAccounts.add(_accountMgr.getAccount(accountId));
}
final boolean showDomr = templateFilter != TemplateFilter.selfexecutable && templateFilter != TemplateFilter.featured;
final HypervisorType hypervisorType = HypervisorType.getType(cmd.getHypervisor());
return searchForTemplatesInternal(id, cmd.getTemplateName(), cmd.getKeyword(), templateFilter, false, null, cmd.getPageSizeVal(), cmd.getStartIndex(), cmd.getZoneId(), hypervisorType, showDomr, cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria, tags, showRemovedTmpl);
}
use of com.cloud.model.enumeration.HypervisorType in project cosmic by MissionCriticalCloud.
the class QueryManagerImpl method searchForServersInternal.
public Pair<List<HostJoinVO>, Integer> searchForServersInternal(final ListHostsCmd cmd) {
final Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
final Object name = cmd.getHostName();
final Object type = cmd.getType();
final Object state = cmd.getState();
final Object pod = cmd.getPodId();
final Object cluster = cmd.getClusterId();
final Object id = cmd.getId();
final Object keyword = cmd.getKeyword();
final Object resourceState = cmd.getResourceState();
final Object haHosts = cmd.getHaHost();
final Long startIndex = cmd.getStartIndex();
final Long pageSize = cmd.getPageSizeVal();
final HypervisorType hypervisorType = cmd.getHypervisor();
final Filter searchFilter = new Filter(HostJoinVO.class, "id", Boolean.TRUE, startIndex, pageSize);
final SearchBuilder<HostJoinVO> sb = _hostJoinDao.createSearchBuilder();
// select distinct
sb.select(null, Func.DISTINCT, sb.entity().getId());
// ids
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
sb.and("type", sb.entity().getType(), SearchCriteria.Op.LIKE);
sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ);
sb.and("dataCenterId", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
sb.and("resourceState", sb.entity().getResourceState(), SearchCriteria.Op.EQ);
sb.and("hypervisor_type", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ);
final String haTag = _haMgr.getHaTag();
if (haHosts != null && haTag != null && !haTag.isEmpty()) {
if ((Boolean) haHosts) {
sb.and("tag", sb.entity().getTag(), SearchCriteria.Op.EQ);
} else {
sb.and().op("tag", sb.entity().getTag(), SearchCriteria.Op.NEQ);
sb.or("tagNull", sb.entity().getTag(), SearchCriteria.Op.NULL);
sb.cp();
}
}
final SearchCriteria<HostJoinVO> sc = sb.create();
if (keyword != null) {
final SearchCriteria<HostJoinVO> ssc = _hostJoinDao.createSearchCriteria();
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("status", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("type", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
}
if (id != null) {
sc.setParameters("id", id);
}
if (name != null) {
sc.setParameters("name", "%" + name + "%");
}
if (type != null) {
sc.setParameters("type", "%" + type);
}
if (state != null) {
sc.setParameters("status", state);
}
if (zoneId != null) {
sc.setParameters("dataCenterId", zoneId);
}
if (pod != null) {
sc.setParameters("podId", pod);
}
if (cluster != null) {
sc.setParameters("clusterId", cluster);
}
if (resourceState != null) {
sc.setParameters("resourceState", resourceState);
}
if (haHosts != null && haTag != null && !haTag.isEmpty()) {
sc.setParameters("tag", haTag);
}
if (hypervisorType != HypervisorType.None && hypervisorType != HypervisorType.Any) {
sc.setParameters("hypervisor_type", hypervisorType);
}
// search host details by ids
final Pair<List<HostJoinVO>, Integer> uniqueHostPair = _hostJoinDao.searchAndCount(sc, searchFilter);
final Integer count = uniqueHostPair.second();
if (count.intValue() == 0) {
// handle empty result cases
return uniqueHostPair;
}
final List<HostJoinVO> uniqueHosts = uniqueHostPair.first();
final Long[] hostIds = new Long[uniqueHosts.size()];
int i = 0;
for (final HostJoinVO v : uniqueHosts) {
hostIds[i++] = v.getId();
}
final List<HostJoinVO> hosts = _hostJoinDao.searchByIds(hostIds);
return new Pair<>(hosts, count);
}
use of com.cloud.model.enumeration.HypervisorType in project cosmic by MissionCriticalCloud.
the class NetworkHelperImpl method getHypervisors.
protected List<HypervisorType> getHypervisors(final RouterDeploymentDefinition routerDeploymentDefinition) throws InsufficientServerCapacityException {
final DeployDestination dest = routerDeploymentDefinition.getDest();
List<HypervisorType> hypervisors = new ArrayList<>();
if (dest.getCluster() != null) {
hypervisors.add(dest.getCluster().getHypervisorType());
} else {
final HypervisorType defaults = _resourceMgr.getDefaultHypervisor(dest.getZone().getId());
if (defaults != HypervisorType.None) {
hypervisors.add(defaults);
} else {
// if there is no default hypervisor, get it from the cluster
hypervisors = _resourceMgr.getSupportedHypervisorTypes(dest.getZone().getId(), true, routerDeploymentDefinition.getPlan().getPodId());
}
}
filterSupportedHypervisors(hypervisors);
if (hypervisors.isEmpty()) {
if (routerDeploymentDefinition.getPodId() != null) {
throw new InsufficientServerCapacityException("Unable to create virtual router, there are no clusters in the pod." + getNoHypervisorsErrMsgDetails(), Pod.class, routerDeploymentDefinition.getPodId());
}
throw new InsufficientServerCapacityException("Unable to create virtual router, there are no clusters in the zone." + getNoHypervisorsErrMsgDetails(), DataCenter.class, dest.getZone().getId());
}
return hypervisors;
}
Aggregations