@Override public List<UserVmVO> listUpByHostId(Long hostId) { SearchCriteria<UserVmVO> sc = HostUpSearch.create(); sc.setParameters("host", hostId); sc.setParameters("states", new Object[] {State.Destroyed, State.Stopped, State.Expunging}); return listBy(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> listRunningByPodId(Long podId) { SearchCriteria<DomainRouterVO> sc = RunningSearch.create(); sc.setParameters("state", State.Running); sc.setParameters("podId", podId); 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 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 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<NicIpAliasVO> listByNetworkIdAndState(long networkId, NicIpAlias.state state) { SearchCriteria<NicIpAliasVO> sc = AllFieldsSearch.create(); sc.setParameters("network", networkId); sc.setParameters("state", state); 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); }
@Override public List<NicIpAliasVO> getAliasIpForVm(long vmId) { SearchCriteria<NicIpAliasVO> sc = AllFieldsSearch.create(); sc.setParameters("instanceId", vmId); sc.setParameters("state", NicIpAlias.state.active); return listBy(sc); }
@Override public NicIpAliasVO findByIp4AddressAndNicId(String ip4Address, long nicId) { SearchCriteria<NicIpAliasVO> sc = AllFieldsSearch.create(); sc.setParameters("address", ip4Address); sc.setParameters("nicId", nicId); return findOneBy(sc); }
@Override public List<NicIpAliasVO> listByNicIdAndVmid(long nicId, long vmId) { SearchCriteria<NicIpAliasVO> sc = AllFieldsSearch.create(); sc.setParameters("nicId", nicId); sc.setParameters("instanceId", vmId); return listBy(sc); }
@Override public List<UserVmVO> listByAccountIdAndHostId(long accountId, long hostId) { SearchCriteria<UserVmVO> sc = AccountHostSearch.create(); sc.setParameters("hostId", hostId); sc.setParameters("accountId", accountId); return listBy(sc); }
@Override public List<UserVmVO> listByLastHostId(Long hostId) { SearchCriteria<UserVmVO> sc = LastHostSearch.create(); sc.setParameters("lastHost", hostId); sc.setParameters("state", State.Stopped); return listBy(sc); }
@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 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<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<SecurityGroupVMMapVO> listByIpAndInstanceId(String ipAddress, long vmId) { SearchCriteria<SecurityGroupVMMapVO> sc = ListByIpAndVmId.create(); sc.setParameters("ipAddress", ipAddress); sc.setParameters("instanceId", vmId); 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<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 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 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<DomainRouterVO> listByPodIdAndStates(Long podId, State... states) { SearchCriteria<DomainRouterVO> sc = AllFieldsSearch.create(); sc.setParameters("podId", podId); sc.setParameters("states", (Object[]) states); return listBy(sc); }
protected List<LoadBalancerVO> findExistingLoadBalancers( String lbName, Long ipId, Long accountId, Long domainId, Integer publicPort) { SearchBuilder<LoadBalancerVO> sb = _lbDao.createSearchBuilder(); sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ); sb.and("accountId", sb.entity().getAccountId(), SearchCriteria.Op.EQ); sb.and("publicPort", sb.entity().getSourcePortStart(), SearchCriteria.Op.EQ); if (ipId != null) { sb.and("sourceIpAddress", sb.entity().getSourceIpAddressId(), SearchCriteria.Op.EQ); } if (domainId != null) { sb.and("domainId", sb.entity().getDomainId(), SearchCriteria.Op.EQ); } if (publicPort != null) { sb.and("publicPort", sb.entity().getSourcePortStart(), SearchCriteria.Op.EQ); } SearchCriteria<LoadBalancerVO> sc = sb.create(); sc.setParameters("name", lbName); sc.setParameters("accountId", accountId); if (ipId != null) { sc.setParameters("sourceIpAddress", ipId); } if (domainId != null) { sc.setParameters("domainId", domainId); } if (publicPort != null) { sc.setParameters("publicPort", publicPort); } List<LoadBalancerVO> lbs = _lbDao.search(sc, null); return lbs == null || lbs.size() == 0 ? null : lbs; }
@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<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<DomainRouterVO> listRunningByDataCenter(long dcId) { SearchCriteria<DomainRouterVO> sc = RunningSearch.create(); sc.setParameters("state", State.Running); sc.setParameters("dc", dcId); 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 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 Long getMaxGuestsLimit(HypervisorType hypervisorType, String hypervisorVersion) { Long defaultLimit = new Long(50); Long result = null; boolean useDefault = false; if (hypervisorVersion != null) { SearchCriteria<Long> sc = MaxGuestLimitByHypervisorSearch.create(); sc.setParameters("hypervisorType", hypervisorType); sc.setParameters("hypervisorVersion", hypervisorVersion); List<Long> limitList = customSearch(sc, null); if (!limitList.isEmpty()) { result = limitList.get(0); } else { useDefault = true; } } else { useDefault = true; } if (useDefault) { SearchCriteria<Long> sc = MaxGuestLimitByHypervisorSearch.create(); sc.setParameters("hypervisorType", hypervisorType); sc.setParameters("hypervisorVersion", DEFAULT_VERSION); List<Long> limitList = customSearch(sc, null); if (!limitList.isEmpty()) { result = limitList.get(0); } } if (result == null) { return defaultLimit; } return result; }