@Override protected List<String> scripts() { String text = "select ref.resourceUuid from AccountResourceRefVO ref where" + " ref.ownerAccountUuid = :accountUuid" + " or ref.resourceUuid in" + " (select sh.resourceUuid from SharedResourceVO sh where sh.receiverAccountUuid = :accountUuid or sh.toPublic = 1)" + " and ref.resourceUuid in (:uuids)"; List<String> auuids = sql(text, String.class) .param("accountUuid", accountUuid) .param("uuids", resourceUuids) .list(); return resourceUuids.stream().filter(uuid -> !auuids.contains(uuid)).collect(Collectors.toList()); } }.execute();
@Override public List<String> getBackupStorageSupportedPS(String psUuid) { return SQL.New("select b.uuid from CephPrimaryStorageVO c, PrimaryStorageVO p, CephBackupStorageVO b, BackupStorageZoneRefVO ref where " + "p.uuid = :puuid and c.uuid = p.uuid and b.fsid = c.fsid and b.uuid = ref.backupStorageUuid and ref.zoneUuid = p.zoneUuid"). param("puuid", psUuid).list(); }
private String selectRandomHostFromPS(PrimaryStorageInventory ps) { List<String> cuuids = ps.getAttachedClusterUuids(); if (cuuids.isEmpty()) { return null; } List<String> hosts = SQL.New("select host.uuid from ClusterVO cluster, HostVO host " + "where cluster.uuid = host.clusterUuid and host.status = :hostStatus and cluster.uuid in (:cuuids) order by rand()"). param("hostStatus", HostStatus.Connected).param("cuuids", cuuids).list(); if (hosts == null || hosts.size() == 0) { return null; } return hosts.get(0); }
public static boolean isOnlyAttachedLocalStorage(String clusterUuid){ boolean result = SQL.New("select pri.uuid" + " from PrimaryStorageVO pri, PrimaryStorageClusterRefVO ref" + " where pri.uuid = ref.primaryStorageUuid" + " and ref.clusterUuid = :cuuid" + " and pri.type != :ptype", String.class) .param("cuuid", clusterUuid) .param("ptype", LocalStorageConstants.LOCAL_STORAGE_TYPE) .list().isEmpty(); return result; }
@Transactional(readOnly = true) private PrimaryStorageInventory findSMPByHostUuid(String clusterUuid) { List<PrimaryStorageVO> ret = SQL.New("select pri from PrimaryStorageVO pri, PrimaryStorageClusterRefVO ref" + " where pri.uuid = ref.primaryStorageUuid" + " and ref.clusterUuid = :cuuid" + " and pri.type = :ptype", PrimaryStorageVO.class) .param("cuuid", clusterUuid) .param("ptype", SMPConstants.SMP_TYPE) .limit(1) .list(); return ret.isEmpty() ? null : PrimaryStorageInventory.valueOf(ret.get(0)); }
@Override public List<String> selectL3NetworksNeedingSpecificNetworkService(List<String> candidate, NetworkServiceType nsType) { if (candidate == null || candidate.isEmpty()) { return new ArrayList<>(0); } // need to specify provider type due to that the provider might be Flat return SQL.New("select ref.l3NetworkUuid from NetworkServiceL3NetworkRefVO ref, NetworkServiceProviderVO nspv" + " where ref.l3NetworkUuid in (:candidate) and ref.networkServiceType = :stype" + " and nspv.uuid = ref.networkServiceProviderUuid and nspv.type in (:ntype)") .param("candidate", candidate) .param("stype", nsType.toString()) .param("ntype", asList(VIRTUAL_ROUTER_PROVIDER_TYPE, VYOS_ROUTER_PROVIDER_TYPE)) .list(); }
private List<String> getNfsPrimaryStorageInCluster(String clusterUuid) { return SQL.New("select pri.uuid" + " from PrimaryStorageVO pri, PrimaryStorageClusterRefVO ref" + " where pri.uuid = ref.primaryStorageUuid" + " and ref.clusterUuid = :cuuid" + " and pri.type = :ptype") .param("cuuid", clusterUuid) .param("ptype", NfsPrimaryStorageConstant.NFS_PRIMARY_STORAGE_TYPE) .list(); }
private List<String> getLocalStorageInCluster(String clusterUuid) { return SQL.New("select pri.uuid" + " from PrimaryStorageVO pri, PrimaryStorageClusterRefVO ref" + " where pri.uuid = ref.primaryStorageUuid" + " and ref.clusterUuid = :cuuid" + " and pri.type = :ptype", String.class) .param("cuuid", clusterUuid) .param("ptype", LocalStorageConstants.LOCAL_STORAGE_TYPE) .list(); }
private List<String> getSMPPrimaryStorageInCluster(String clusterUuid) { return SQL.New("select pri.uuid" + " from PrimaryStorageVO pri, PrimaryStorageClusterRefVO ref" + " where pri.uuid = ref.primaryStorageUuid" + " and ref.clusterUuid = :cuuid" + " and pri.type = :ptype") .param("cuuid", clusterUuid) .param("ptype", SMPConstants.SMP_TYPE) .list(); }
private List<PolicyInventory> getPoliciesForUser(SessionInventory session) { // polices attached to the user List<PolicyVO> vos = sql("select p from PolicyVO p, UserPolicyRefVO r where r.policyUuid = p.uuid" + " and r.userUuid = :uuid", PolicyVO.class).param("uuid", session.getUserUuid()).list(); // polices attached to user groups the user is in vos.addAll(sql("select p from PolicyVO p, UserGroupVO g, UserGroupPolicyRefVO up, UserGroupUserRefVO ugu where p.uuid = up.policyUuid" + " and g.uuid = up.groupUuid and g.uuid = ugu.groupUuid and ugu.userUuid = :uuid", PolicyVO.class).param("uuid", session.getUserUuid()).list()); return PolicyInventory.valueOf(vos); } }.execute();
private void fillGuestOsType(APICreateRootVolumeTemplateFromVolumeSnapshotMsg msg) { if(msg.getGuestOsType() != null) { return; } List<String> guestOsTypes = SQL.New("select guestOsType from ImageVO where uuid = (" + " select rootImageUuid from VolumeVO vol where " + " vol.uuid = (select volumeUuid from VolumeSnapshotVO where uuid = :snapshotUuid) and type = :volumeType" + ")") .param("snapshotUuid", msg.getSnapshotUuid()) .param("volumeType", VolumeType.Root) .list(); if(guestOsTypes.isEmpty() || guestOsTypes.size() != 1){ return; } msg.setGuestOsType(guestOsTypes.get(0)); }
@Transactional(readOnly = true) private List<PrimaryStorageVO> considerImageBackupStorageRef(PrimaryStorageAllocationSpec spec, List<PrimaryStorageVO> vos){ List<BackupStorageVO> bsvos = SQL.New("select bs" + " from BackupStorageVO bs, ImageBackupStorageRefVO ref" + " where ref.imageUuid = :imgUuid" + " and bs.uuid = ref.backupStorageUuid", BackupStorageVO.class) .param("imgUuid", spec.getImageUuid()) .list(); vos.removeIf(ps -> bsvos.stream().noneMatch(bs -> { List<String> relatedPsUuids = BackupStorageType.valueOf(bs.getType()).findRelatedPrimaryStorage(bs.getUuid()); return relatedPsUuids == null || relatedPsUuids.contains(ps.getUuid()); }) ); return vos; }
private void checkVmAllVolumePrimaryStorageState(String vmUuid) { String sql = "select uuid from PrimaryStorageVO where uuid in (" + " select distinct(primaryStorageUuid) from VolumeVO" + " where vmInstanceUuid = :vmUuid and primaryStorageUuid is not null)" + " and state = :psState"; List<String> result = SQL.New(sql, String.class) .param("vmUuid", vmUuid) .param("psState", PrimaryStorageState.Maintenance) .list(); if (result != null && !result.isEmpty()) { throw new OperationFailureException(argerr("the VM[uuid:%s] volume stored location primary storage is in a state of maintenance", vmUuid)); } }
private List<String> getCandidateClusterUuidsFromAttachedL3(String l3Uuid, List<String> clusterUuids) { return sql("select l2ref.clusterUuid " + " from L3NetworkVO l3, L2NetworkVO l2, L2NetworkClusterRefVO l2ref " + " where l3.uuid = :l3Uuid " + " and l3.l2NetworkUuid = l2.uuid " + " and l2.uuid = l2ref.l2NetworkUuid" + " and l3.category != :l3Category" + " and l2ref.clusterUuid in (:uuids) " + " group by l2ref.clusterUuid", String.class) .param("l3Uuid", l3Uuid) .param("l3Category", L3NetworkCategory.System) .param("uuids", clusterUuids).list(); } }.execute();
private void cleanUpImageCache(String psUuid) { PrimaryStorageVO ps = dbf.findByUuid(psUuid, PrimaryStorageVO.class); logger.info(String.format("cleanup image cache on PrimaryStorage [%s]", ps.getUuid())); List<String> hostUuids = SQL.New("select h.uuid from LocalStorageHostRefVO ref, HostVO h " + "where ref.hostUuid = h.uuid and ref.primaryStorageUuid = :ps and h.status = :status"). param("ps", psUuid).param("status", HostStatus.Connected).list(); List<BackupStoragePrimaryStorageExtensionPoint> extenstions = pluginRgty.getExtensionList(BackupStoragePrimaryStorageExtensionPoint.class); extenstions.forEach(ext -> { hostUuids.forEach(hostUuid -> ext.cleanupPrimaryCacheForBS(PrimaryStorageInventory.valueOf(ps), hostUuid, new NopeCompletion())); }); }
@Override protected List<String> scripts() { List<String> ret = sql("select ref.resourceUuid from AccountResourceRefVO ref where" + " (ref.accountUuid = :accountUuid and ref.resourceUuid in (:ruuids)) or ref.resourceUuid in" + " (select sh.resourceUuid from SharedResourceVO sh where (sh.ownerAccountUuid = :accountUuid" + " or sh.receiverAccountUuid = :accountUuid or sh.toPublic = :public) and sh.resourceUuid in (:ruuids))", String.class) .param("ruuids", resourceUuids) .param("accountUuid", session.getAccountUuid()) .param("public", true) .list(); return ret; } }.execute();
private List<Tuple> findPortForwardingTuplesOnVmNic(VmNicInventory nic) { return SQL.New("select pf, nic.ip, nic.mac " + "from PortForwardingRuleVO pf, VmNicVO nic, VmInstanceVO vm " + "where pf.vmNicUuid = nic.uuid " + "and nic.vmInstanceUuid = vm.uuid " + "and nic.l3NetworkUuid = :l3Uuid " + "and vm.state in (:syncPfVmStates) " + "and pf.state = :enabledState", Tuple.class) .param("l3Uuid", nic.getL3NetworkUuid()) .param("syncPfVmStates", SYNC_PF_VM_STATES) .param("enabledState", PortForwardingRuleState.Enabled) .list(); }
private List<Tuple> findEipTuplesOnVmNic(VmNicInventory nic) { List<Tuple> eips = SQL.New("select eip.vipIp, eip.guestIp, nic.l3NetworkUuid, nic.mac, vip.l3NetworkUuid, eip.uuid " + "from EipVO eip, VmNicVO nic, VmInstanceVO vm, VipVO vip " + "where eip.vmNicUuid = nic.uuid " + "and nic.vmInstanceUuid = vm.uuid " + "and nic.l3NetworkUuid = :l3Uuid " + "and eip.vipUuid = vip.uuid " + "and vm.state in (:syncEipVmStates) " + "and eip.state = :enabledState", Tuple.class) .param("l3Uuid", nic.getL3NetworkUuid()) .param("syncEipVmStates", SYNC_EIP_VM_STATES) .param("enabledState", EipState.Enabled) .list(); return eips; }
private void handle(SyncSystemTagFromVolumeMsg msg) { SyncSystemTagFromVolumeReply reply = new SyncSystemTagFromVolumeReply(); // only sync root volume List<String> vmSystemTags = SQL.New("select s.tag from SystemTagVO s, VolumeVO vol" + " where vol.uuid = :volUuid" + " and vol.type = :type" + " and vol.vmInstanceUuid = s.resourceUuid", String.class) .param("volUuid", msg.getVolumeUuid()) .param("type", VolumeType.Root) .list(); syncVmSystemTags(vmSystemTags); bus.reply(msg, reply); }
private void validate(APICreateRootVolumeTemplateFromRootVolumeMsg msg) { if (msg.getPlatform() == null) { String platform = Q.New(VmInstanceVO.class).eq(VmInstanceVO_.rootVolumeUuid, msg.getRootVolumeUuid()).select(VmInstanceVO_.platform).findValue(); msg.setPlatform(platform == null ? ImagePlatform.Linux.toString() : platform); } if (msg.getGuestOsType() == null) { List<String> osTypes = SQL.New("select i.guestOsType from VolumeVO v, ImageVO i where v.uuid=:vol and v.rootImageUuid = i.uuid"). param("vol", msg.getRootVolumeUuid()).list(); if (osTypes != null && osTypes.size() > 0) { msg.setGuestOsType(osTypes.get(0)); } } }