@Override public Account findNonProjectAccountIncludingRemoved(String accountName, Long domainId) { SearchCriteria<AccountVO> sc = NonProjectAccountSearch.create("accountName", accountName); sc.setParameters("domainId", domainId); sc.setParameters("type", Account.ACCOUNT_TYPE_PROJECT); return findOneIncludingRemovedBy(sc); }
@Override public List<DomainRouterVO> listRunningByAccountId(long accountId) { SearchCriteria<DomainRouterVO> sc = RunningSearch.create(); sc.setParameters("state", State.Running); sc.setParameters("account", accountId); return listBy(sc); }
@Override public List<? extends StaticRoute> listByGatewayIdAndNotRevoked(long gatewayId) { SearchCriteria<StaticRouteVO> sc = NotRevokedSearch.create(); sc.setParameters("gatewayId", gatewayId); sc.setParameters("state", StaticRoute.State.Revoke); return listBy(sc); }
@Override public List<DomainRouterVO> listByLastHostId(Long hostId) { SearchCriteria<DomainRouterVO> sc = AllFieldsSearch.create(); sc.setParameters("lastHost", hostId); sc.setParameters("state", State.Stopped); return listBy(sc); }
@Override public List<DomainRouterVO> listByNetworkAndRole(long networkId, Role role) { SearchCriteria<DomainRouterVO> sc = AllFieldsSearch.create(); sc.setJoinParameters("networkRouter", "networkId", networkId); sc.setParameters("role", role); return listBy(sc); }
@Override public void run() { try { s_logger.debug("HostStatsCollector is running..."); SearchCriteria<HostVO> sc = _hostDao.createSearchCriteria(); sc.addAnd("status", SearchCriteria.Op.EQ, Status.Up.toString()); sc.addAnd("type", SearchCriteria.Op.NEQ, Host.Type.Storage.toString()); sc.addAnd("type", SearchCriteria.Op.NEQ, Host.Type.ConsoleProxy.toString()); sc.addAnd("type", SearchCriteria.Op.NEQ, Host.Type.SecondaryStorage.toString()); ConcurrentHashMap<Long, HostStats> hostStats = new ConcurrentHashMap<Long, HostStats>(); List<HostVO> hosts = _hostDao.search(sc, null); for (HostVO host : hosts) { if (host.getId() != null) { HostStatsEntry stats = (HostStatsEntry) _agentMgr.getHostStatistics(host.getId()); if (stats != null) { hostStats.put(host.getId(), stats); } else { s_logger.warn("Received invalid host stats for host: " + host.getId()); } } else { s_logger.warn("Host: " + host.getId() + " does not exist, skipping host statistics"); } } _hostStats = hostStats; } catch (Throwable t) { s_logger.error("Error trying to retrieve host stats", t); } }
@Override public List<DomainRouterVO> listRunningByClusterId(Long clusterId) { SearchCriteria<DomainRouterVO> sc = clusterSearch.create(); sc.setParameters("state", State.Running); sc.setJoinParameters("host", "clusterId", clusterId); return listBy(sc); }
@Override public String getNetworkTag( long physicalNetworkId, TrafficType trafficType, HypervisorType hType) { SearchCriteria<String> sc = null; if (hType == HypervisorType.XenServer) { sc = xenAllFieldsSearch.create(); } else if (hType == HypervisorType.KVM) { sc = kvmAllFieldsSearch.create(); } else if (hType == HypervisorType.VMware) { sc = vmWareAllFieldsSearch.create(); } else if (hType == HypervisorType.Simulator) { sc = simulatorAllFieldsSearch.create(); } else if (hType == HypervisorType.Ovm) { sc = ovmAllFieldsSearch.create(); } else if (hType == HypervisorType.BareMetal) { return null; } else if (hType == HypervisorType.Hyperv) { sc = hypervAllFieldsSearch.create(); } else if (hType == HypervisorType.Ovm3) { sc = ovm3AllFieldsSearch.create(); } else { assert (false) : "We don't handle this hypervisor type"; return null; } sc.setParameters("physicalNetworkId", physicalNetworkId); sc.setParameters("trafficType", trafficType); List<String> tag = customSearch(sc, null); return tag.size() == 0 ? null : tag.get(0); }
@Override public PhysicalNetworkTrafficTypeVO findBy(long physicalNetworkId, TrafficType trafficType) { SearchCriteria<PhysicalNetworkTrafficTypeVO> sc = physicalNetworkSearch.create(); sc.setParameters("physicalNetworkId", physicalNetworkId); sc.setParameters("trafficType", trafficType); return findOneBy(sc); }
@Override public SecurityGroupVMMapVO findByVmIdGroupId(long instanceId, long securityGroupId) { SearchCriteria<SecurityGroupVMMapVO> sc = ListByVmIdGroupId.create(); sc.setParameters("securityGroupId", securityGroupId); sc.setParameters("instanceId", instanceId); return findOneIncludingRemovedBy(sc); }
@Override public List<ResourceTagJoinVO> listBy(String resourceUUID, ResourceObjectType resourceType) { SearchCriteria<ResourceTagJoinVO> sc = AllFieldsSearch.create(); sc.setParameters("uuid", resourceUUID); sc.setParameters("resourceType", resourceType); return listBy(sc); }
@Override public List<SecurityGroupVMMapVO> listBySecurityGroup(long securityGroupId, State... vmStates) { SearchCriteria<SecurityGroupVMMapVO> sc = ListBySecurityGroupAndStates.create(); sc.setParameters("securityGroupId", securityGroupId); sc.setParameters("states", (Object[]) vmStates); return listBy(sc, null, true); }
@Override public Pair<List<SecurityGroupVMMapVO>, Integer> listByInstanceId( long instanceId, Filter filter) { SearchCriteria<SecurityGroupVMMapVO> sc = ListByVmId.create(); sc.setParameters("instanceId", instanceId); return this.searchAndCount(sc, filter); }
@Override public List<SecurityGroupVMMapVO> listByIpAndInstanceId(String ipAddress, long vmId) { SearchCriteria<SecurityGroupVMMapVO> sc = ListByIpAndVmId.create(); sc.setParameters("ipAddress", ipAddress); sc.setParameters("instanceId", vmId); return listBy(sc); }
@Override public Long countSnapshotsForAccount(long accountId) { SearchCriteria<Long> sc = CountSnapshotsByAccount.create(); sc.setParameters("account", accountId); sc.setParameters("status", State.Error, State.Destroyed); return customSearch(sc, null).get(0); }
@Override public List<StoragePoolVO> listByStatusInZone(long dcId, StoragePoolStatus status) { SearchCriteria<StoragePoolVO> sc = AllFieldSearch.create(); sc.setParameters("status", status); sc.setParameters("datacenterId", dcId); return listBy(sc); }
@Override public List<SnapshotVO> listByStatus(long volumeId, Snapshot.State... status) { SearchCriteria<SnapshotVO> sc = this.StatusSearch.create(); sc.setParameters("volumeId", volumeId); sc.setParameters("status", (Object[]) status); return listBy(sc, null); }
@Override public Pair<List<IAMGroup>, Integer> listIAMGroups( Long iamGroupId, String iamGroupName, String path, Long startIndex, Long pageSize) { if (iamGroupId != null) { IAMGroup group = _aclGroupDao.findById(iamGroupId); if (group == null) { throw new InvalidParameterValueException("Unable to find acl group by id " + iamGroupId); } } Filter searchFilter = new Filter(IAMGroupVO.class, "id", true, startIndex, pageSize); SearchBuilder<IAMGroupVO> sb = _aclGroupDao.createSearchBuilder(); sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ); sb.and("path", sb.entity().getPath(), SearchCriteria.Op.LIKE); sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); SearchCriteria<IAMGroupVO> sc = sb.create(); if (iamGroupName != null) { sc.setParameters("name", iamGroupName); } if (iamGroupId != null) { sc.setParameters("id", iamGroupId); } sc.setParameters("path", path + "%"); Pair<List<IAMGroupVO>, Integer> groups = _aclGroupDao.searchAndCount(sc, searchFilter); return new Pair<List<IAMGroup>, Integer>( new ArrayList<IAMGroup>(groups.first()), groups.second()); }
@Override public List<DomainRouterVO> listRunningByPodId(Long podId) { SearchCriteria<DomainRouterVO> sc = RunningSearch.create(); sc.setParameters("state", State.Running); sc.setParameters("podId", podId); return listBy(sc); }
@Override public List<IAMGroup> listParentIAMGroups(long groupId) { IAMGroup group = _aclGroupDao.findById(groupId); if (group == null) { throw new InvalidParameterValueException("Unable to find acl group by id " + groupId); } String path = group.getPath(); List<String> pathList = new ArrayList<String>(); String[] parts = path.split("/"); for (String part : parts) { int start = path.indexOf(part); if (start > 0) { String subPath = path.substring(0, start); pathList.add(subPath); } } if (pathList.isEmpty()) { return new ArrayList<IAMGroup>(); } SearchBuilder<IAMGroupVO> sb = _aclGroupDao.createSearchBuilder(); sb.and("paths", sb.entity().getPath(), SearchCriteria.Op.IN); SearchCriteria<IAMGroupVO> sc = sb.create(); sc.setParameters("paths", pathList.toArray()); List<IAMGroupVO> groups = _aclGroupDao.search(sc, null); return new ArrayList<IAMGroup>(groups); }
@Override public List<DomainRouterVO> listByPodIdAndStates(Long podId, State... states) { SearchCriteria<DomainRouterVO> sc = AllFieldsSearch.create(); sc.setParameters("podId", podId); sc.setParameters("states", (Object[]) states); return listBy(sc); }
@SuppressWarnings("unchecked") @Override public List<IAMPolicy> listRecursiveIAMPoliciesByGroup(long groupId) { List<IAMGroupPolicyMapVO> policyGrpMap = _aclGroupPolicyMapDao.listByGroupId(groupId); if (policyGrpMap == null || policyGrpMap.size() == 0) { return new ArrayList<IAMPolicy>(); } List<Long> policyIds = new ArrayList<Long>(); for (IAMGroupPolicyMapVO pg : policyGrpMap) { policyIds.add(pg.getAclPolicyId()); } SearchBuilder<IAMPolicyPermissionVO> permSb = _policyPermissionDao.createSearchBuilder(); permSb.and("isRecursive", permSb.entity().isRecursive(), Op.EQ); SearchBuilder<IAMPolicyVO> sb = _aclPolicyDao.createSearchBuilder(); sb.and("ids", sb.entity().getId(), Op.IN); sb.join( "recursivePerm", permSb, sb.entity().getId(), permSb.entity().getAclPolicyId(), JoinBuilder.JoinType.INNER); SearchCriteria<IAMPolicyVO> sc = sb.create(); sc.setParameters("ids", policyIds.toArray(new Object[policyIds.size()])); sc.setJoinParameters("recursivePerm", "isRecursive", true); @SuppressWarnings("rawtypes") List policies = _aclPolicyDao.customSearch(sc, null); return policies; }
@Override public List<DomainRouterVO> listActive(long networkId) { SearchCriteria<DomainRouterVO> sc = IdNetworkIdStatesSearch.create(); sc.setJoinParameters("networkRouter", "networkId", networkId); sc.setParameters("states", State.Running, State.Migrating, State.Stopping, State.Starting); return listBy(sc); }
@Override public boolean isActionAllowedForPolicies(String action, List<IAMPolicy> policies) { boolean allowed = false; if (policies == null || policies.size() == 0) { return allowed; } List<Long> policyIds = new ArrayList<Long>(); for (IAMPolicy policy : policies) { policyIds.add(policy.getId()); } SearchBuilder<IAMPolicyPermissionVO> sb = _policyPermissionDao.createSearchBuilder(); sb.and("action", sb.entity().getAction(), Op.EQ); sb.and("policyId", sb.entity().getAclPolicyId(), Op.IN); SearchCriteria<IAMPolicyPermissionVO> sc = sb.create(); sc.setParameters("policyId", policyIds.toArray(new Object[policyIds.size()])); sc.setParameters("action", action); List<IAMPolicyPermissionVO> permissions = _policyPermissionDao.customSearch(sc, null); if (permissions != null && !permissions.isEmpty()) { allowed = true; } return allowed; }
@Override public List<DomainRouterVO> listByVpcId(long vpcId) { SearchCriteria<DomainRouterVO> sc = VpcSearch.create(); sc.setParameters("vpcId", vpcId); sc.setParameters("role", Role.VIRTUAL_ROUTER); return listBy(sc); }
@Override public List<VMTemplateVO> listReadyTemplates() { SearchCriteria<VMTemplateVO> sc = createSearchCriteria(); sc.addAnd("ready", SearchCriteria.Op.EQ, true); sc.addAnd("format", SearchCriteria.Op.NEQ, Storage.ImageFormat.ISO); return listIncludingRemovedBy(sc); }
@Override public List<DomainRouterVO> listRunningByDataCenter(long dcId) { SearchCriteria<DomainRouterVO> sc = RunningSearch.create(); sc.setParameters("state", State.Running); sc.setParameters("dc", dcId); return listBy(sc); }
@Override public List<VMTemplateVO> listByHypervisorType(List<HypervisorType> hyperTypes) { SearchCriteria<VMTemplateVO> sc = createSearchCriteria(); hyperTypes.add(HypervisorType.None); sc.addAnd("hypervisorType", SearchCriteria.Op.IN, hyperTypes.toArray()); return listBy(sc); }
@Override public List<VpcGatewayVO> listByAclIdAndType(long aclId, VpcGateway.Type type) { SearchCriteria<VpcGatewayVO> sc = AllFieldsSearch.create(); sc.setParameters("aclId", aclId); sc.setParameters("type", type); return listBy(sc); }
@Override public Account findEnabledAccount(String accountName, Long domainId) { SearchCriteria<AccountVO> sc = AllFieldsSearch.create("accountName", accountName); sc.setParameters("domainId", domainId); sc.setParameters("state", State.enabled); return findOneBy(sc); }