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 boolean isThereOtherNonLocalStoragePrimaryStorageForTheHost(String hostUuid, String localStorageUuid) { long count = SQL.New( "select count(pri)" + " from PrimaryStorageVO pri, PrimaryStorageClusterRefVO ref, HostVO host" + " where pri.uuid = ref.primaryStorageUuid" + " and ref.clusterUuid = host.clusterUuid" + " and host.uuid = :huuid" + " and pri.uuid != :puuid" + " and pri.type != :pstype", Long.class) .param("huuid", hostUuid) .param("puuid", localStorageUuid) .param("pstype", LocalStorageConstants.LOCAL_STORAGE_TYPE).find(); return count > 0; }
protected void remove(Object k) { Field f = EntityMetadata.getPrimaryKeyField(k.getClass()); try { f.setAccessible(true); sql(String.format("DELETE FROM %s vo WHERE vo.%s = :value", k.getClass().getSimpleName(), f.getName())) .param("value", f.get(k)).execute(); } catch (IllegalAccessException e) { throw new CloudRuntimeException(e); } }
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();
protected SQL sql(String text) { return SQL.New(text); }
long size = SQL.New("select vol.size" + " from VolumeVO vol" + " where vol.uuid = :uuid") .param("uuid", msg.getVolumeUuid()).find(); size = ratioMgr.calculateByRatio(self.getUuid(), size); Long snapshotSize = SQL.New("select sum(sp.size)" + " from VolumeSnapshotVO sp" + " where sp.volumeUuid = :volUuid") .param("volUuid", msg.getVolumeUuid()).find(); if (snapshotSize != null) { size += snapshotSize; List<String> hostUuids = SQL.New("select href.hostUuid" + " from LocalStorageHostRefVO href" + " where href.hostUuid !=" + " and href.primaryStorageUuid = :psUuid" + " group by href.hostUuid") .param("volUuid", msg.getVolumeUuid()) .param("rtype", VolumeVO.class.getSimpleName()) .param("thres", physicalThreshold) .param("size", size) .param("psUuid", self.getUuid()).list(); List<HostVO> hosts = new LinkedList<>(SQL.New("select h from HostVO h " + " where h.uuid in (:uuids)" + " and h.status = :hstatus") .param("uuids", hostUuids)
@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)); }
if ((long) SQL.New("select count(*) from ImageEO where uuid = :imageUuid") .param("imageUuid", imageInventory.getUuid()) .find() > 0) { SQL.New("update ImageEO set status = :status, " + "deleted = null where uuid = :imageUuid") .param("status", ImageStatus.Ready) .param("imageUuid", imageInventory.getUuid()) .execute(); continue;
@Override @Deferred public boolean run() { // get current progress Tuple res = SQL.New("SELECT content, timeToDelete FROM TaskProgressVO" + " WHERE apiId = :apiId" + " ORDER BY CAST(content AS int) DESC", Tuple.class) .param("apiId", apiId) .limit(1) .find(); if (res != null && res.get(1) != null) { // FIXME: race condition here. return true; } int currentPercent = res == null ? 0 : new Double(res.get(0, String.class)).intValue(); Runnable cleanup = saveThreadContext(); Defer.defer(cleanup); ThreadContext.put(THREAD_CONTEXT_API, apiId); ThreadContext.put(THREAD_CONTEXT_TASK_NAME, taskName); if (endPercent <= currentPercent) { reportProgress(String.valueOf(endPercent)); return true; } else { reportProgress(String.valueOf(currentPercent + 1)); return false; } }
" and vip.uuid = rule.vipUuid" + " and rule.uuid = :ruleUuid",Tuple.class) .param("ruleUuid", ruleUuid).find(); String zoneUuid = t.get(0, String.class); String vipUuid = t.get(1, String.class); " and ref.networkServiceType = :nsType" + " and l3.zoneUuid = :zoneUuid") .param("vipUuid", vipUuid) .param("zoneUuid", zoneUuid) .param("nsType", PortForwardingConstant.PORTFORWARDING_NETWORK_SERVICE_TYPE).list(); } else { l3Uuids = sql("select l3.uuid" + " and l3.zoneUuid = :zoneUuid" + " and vip.uuid = :vipUuid") .param("vipUuid", vipUuid) .param("system", false) .param("zoneUuid", zoneUuid) .param("nsType", PortForwardingConstant.PORTFORWARDING_NETWORK_SERVICE_TYPE).list(); .param("ruleUuid", ruleUuid).find(); .param("publicNetworkUuid", rulePublicL3Uuid).list(); if(vrouterUuids.isEmpty()){ return new ArrayList<>(); " and l3NetworkUuid != :rulePublicL3Uuid " + " and l3NetworkUuid != (select managementNetworkUuid from ApplianceVmVO where uuid = :vrouterUuid)", String.class)
@Override protected void scripts() { for (Field field : encryptedFields) { String className = field.getDeclaringClass().getSimpleName(); List<String> uuids = sql(String.format("select uuid from %s", className)).list(); for (String uuid : uuids) { String value = sql(String.format("select %s from %s where uuid = '%s'", field.getName(), className, uuid)).find(); try { String encryptedString = rsa.encrypt1(value); String sql = String.format("update %s set %s = :encrypted where uuid = :uuid", className, field.getName()); Query query = dbf.getEntityManager().createQuery(sql); query.setParameter("encrypted", encryptedString); query.setParameter("uuid", uuid); query.executeUpdate(); } catch (Exception e) { logger.debug(String.format("encrypt error because : %s",e.getMessage())); } } } } }.execute();
" ic.installUrl like :url").param("psUuid", self.getUuid()) .param("url", String.format("%%%s%%", hostUuid)).execute(); ).param("huuid", hostUuid).param("psUuid", self.getUuid()).list(); List<String> treeList = sql( "select treeUuid from VolumeSnapshotVO where uuid in (:uuids) group by treeUuid", String.class) .param("uuids", snapshotUuids).list(); if(treeList != null){ snapshotTreeUuids.addAll(treeList); .param("uuids", snapshotUuids).execute(); " (select vol.uuid from VolumeVO vol where vol.uuid in (:volUuids)" + " and vol.type = :volType)", String.class) .param("volUuids", volumesUuids).param("volType", VolumeType.Root).list(); .param("uuids", vmUuidsToDelete).execute(); .param("uuids", vmUuidsToDelete).execute(); .param("uuids", volumesUuids).execute(); logger.debug(String.format("delete volumes%s because the host[uuid:%s] is removed from" + " the local storage[name:%s, uuid:%s]", volumesUuids, hostUuid, self.getName(), self.getUuid())); .param("uuids", vmUuidsToDelete).execute();
@Override protected void scripts() { long count = sql("select count(ps) from PrimaryStorageVO ps", Long.class).find(); sql("select ps.uuid from PrimaryStorageVO ps", String.class).limit(1000).paginate(count, (List<String> psUuids) -> { List<String> byUs = psUuids.stream() .filter(psUuid -> destMaker.isManagedByUs(psUuid)) .collect(Collectors.toList()); track(byUs); }); } }.execute();
@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();
protected UpdateQuery sql(Class clz) { return SQL.New(clz); }
final List<String> peerL3NetworkUuids = SQL.New("select peer.l3NetworkUuid " + "from LoadBalancerVO lb, VipVO vip, VipPeerL3NetworkRefVO peer " + "where lb.vipUuid = vip.uuid " + "and vip.uuid = peer.vipUuid " + "and lb.uuid = :lbUuid") .param("lbUuid", msg.getLoadBalancerUuid()) .list(); VipVO lbVipVO = SQL.New("select vip from LoadBalancerVO lb, VipVO vip " + "where lb.vipUuid = vip.uuid " + "and lb.uuid = :lbUuid") .param("lbUuid", msg.getLoadBalancerUuid()).find();
if ((long) SQL.New("select count(*) from ImageEO where uuid = :imageUuid") .param("imageUuid", imageInventory.getUuid()) .find() > 0) { SQL.New("update ImageEO set status = :status, " + "deleted = null where uuid = :imageUuid") .param("status", ImageStatus.Ready) .param("imageUuid", imageInventory.getUuid()) .execute(); continue;
@Override protected String scripts() { String uuid = sql("select hostUuid from LocalStorageResourceRefVO where resourceUuid = :resUuid", String.class) .param("resUuid", resUuid) .find(); if (uuid == null) { ResourceVO vo = dbf.findByUuid(resUuid,ResourceVO.class); if (vo != null) { throw new OperationFailureException(operr("cannot find any host which has resource[uuid:%s], name :[%s], type :[%s]" , resUuid, vo.getResourceName(), vo.getResourceType())); } else { throw new OperationFailureException(operr("cannot find any host which has resource[uuid:%s]", resUuid)); } } else if (findHostByUuid(uuid) == null) { throw new OperationFailureException( operr("Resource[uuid:%s] can only be operated on host[uuid:%s], but the host has been deleted", resUuid, uuid)); } return uuid; } }.execute();