public boolean hasTag(String resourceUuid, Class resourceClass) { SimpleQuery<SystemTagVO> q = dbf.createQuery(SystemTagVO.class); q.add(SystemTagVO_.resourceType, Op.EQ, resourceClass.getSimpleName()); q.add(SystemTagVO_.resourceUuid, Op.EQ, resourceUuid); q.add(SystemTagVO_.tag, useOp(), useTagFormat()); return q.isExists(); }
private int getNextVolumeDeviceId(String vmUuid) { SimpleQuery<VolumeVO> q = dbf.createQuery(VolumeVO.class); q.select(VolumeVO_.deviceId); q.add(VolumeVO_.vmInstanceUuid, Op.EQ, vmUuid); q.add(VolumeVO_.deviceId, Op.NOT_NULL); q.orderBy(VolumeVO_.deviceId, Od.ASC); List<Integer> devIds = q.listValue(); BitSet full = new BitSet(devIds.size() + 1); devIds.forEach(full::set); return full.nextClearBit(0); }
public boolean exists(String key) { SimpleQuery<JsonLabelVO> q = dbf.createQuery(JsonLabelVO.class); q.add(JsonLabelVO_.labelKey, Op.EQ, key); return q.isExists(); }
private boolean isRootVolumeOnLocalStorage(String rootVolumeUuid) { SimpleQuery<LocalStorageResourceRefVO> q = dbf.createQuery(LocalStorageResourceRefVO.class); q.add(LocalStorageResourceRefVO_.resourceUuid, Op.EQ, rootVolumeUuid); return q.isExists(); }
private void deleteResourceRefVO(String resourceUuid) { SimpleQuery<LocalStorageResourceRefVO> q = dbf.createQuery(LocalStorageResourceRefVO.class); q.add(LocalStorageResourceRefVO_.primaryStorageUuid, Op.EQ, self.getUuid()); q.add(LocalStorageResourceRefVO_.resourceUuid, Op.EQ, resourceUuid); LocalStorageResourceRefVO ref = q.find(); dbf.remove(ref); }
private void exceptionIsVolumeIsDeleted(String volumeUuid) { SimpleQuery<VolumeVO> q = dbf.createQuery(VolumeVO.class); q.add(VolumeVO_.uuid, Op.EQ, volumeUuid); q.add(VolumeVO_.status, Op.EQ, VolumeStatus.Deleted); if (q.isExists()) { throw new ApiMessageInterceptionException(operr("the volume[uuid:%s] is in status of deleted, cannot do the operation", volumeUuid)); } }
private List<String> findConnectedHostByClusterUuid(String clusterUuid, boolean exceptionOnNotFound) { SimpleQuery<HostVO> q = dbf.createQuery(HostVO.class); q.select(HostVO_.uuid); q.add(HostVO_.clusterUuid, Op.EQ, clusterUuid); q.add(HostVO_.status, Op.EQ, HostStatus.Connected); List<String> hostUuids = q.listValue(); if (hostUuids.isEmpty() && exceptionOnNotFound) { throw new OperationFailureException(operr("no connected host found in the cluster[uuid:%s]", clusterUuid)); } return hostUuids; }
private void validate(APIRecoverDataVolumeMsg msg) { SimpleQuery<VolumeVO> q = dbf.createQuery(VolumeVO.class); q.add(VolumeVO_.uuid, Op.EQ, msg.getVolumeUuid()); q.add(VolumeVO_.status, Op.EQ, VolumeStatus.Deleted); if (!q.isExists()) { throw new ApiMessageInterceptionException(operr("the volume[uuid:%s] is not in status of deleted. This is operation is to recover a deleted data volume", msg.getVolumeUuid())); } }
private boolean isRootVolume(String uuid) { SimpleQuery<VolumeVO> q = dbf.createQuery(VolumeVO.class); q.select(VolumeVO_.type); q.add(VolumeVO_.uuid, Op.EQ, uuid); VolumeType type = q.findValue(); return type == VolumeType.Root; }
@Override public void releaseServicesOnVip(VipInventory vip, final Completion completion) { SimpleQuery<LoadBalancerVO> q = dbf.createQuery(LoadBalancerVO.class); q.add(LoadBalancerVO_.vipUuid, Op.EQ, vip.getUuid()); List<LoadBalancerVO> rules = q.list(); releaseServicesOnVip(rules.iterator(), completion); } }
private void validate(APIDetachSecurityGroupFromL3NetworkMsg msg) { SimpleQuery<SecurityGroupL3NetworkRefVO> q = dbf.createQuery(SecurityGroupL3NetworkRefVO.class); q.add(SecurityGroupL3NetworkRefVO_.l3NetworkUuid, Op.EQ, msg.getL3NetworkUuid()); q.add(SecurityGroupL3NetworkRefVO_.securityGroupUuid, Op.EQ, msg.getSecurityGroupUuid()); if (!q.isExists()) { throw new ApiMessageInterceptionException(operr("security group[uuid:%s] has not attached to l3Network[uuid:%s], can't detach", msg.getSecurityGroupUuid(), msg.getL3NetworkUuid())); } }
private void handle(APIRemoveUserFromGroupMsg msg) { SimpleQuery<UserGroupUserRefVO> q = dbf.createQuery(UserGroupUserRefVO.class); q.add(UserGroupUserRefVO_.groupUuid, Op.EQ, msg.getGroupUuid()); q.add(UserGroupUserRefVO_.userUuid, Op.EQ, msg.getUserUuid()); UserGroupUserRefVO ref = q.find(); if (ref != null) { dbf.remove(ref); } bus.publish(new APIRemoveUserFromGroupEvent(msg.getId())); }
private String getBackupStorageUuidFromImageInventory(ImageInventory img) { SimpleQuery<ImageBackupStorageRefVO> q = dbf.createQuery(ImageBackupStorageRefVO.class); q.select(ImageBackupStorageRefVO_.backupStorageUuid); q.add(ImageBackupStorageRefVO_.imageUuid, SimpleQuery.Op.EQ, img.getUuid()); String backupStorageUuid = q.findValue(); DebugUtils.Assert(backupStorageUuid != null, String.format("cannot find backup storage for image [uuid:%s]", img.getUuid())); return backupStorageUuid; }
private void changeVolumeSnapshotOwner(AccountResourceRefInventory ref, String newOwnerUuid) { SimpleQuery<VolumeSnapshotVO> q = dbf.createQuery(VolumeSnapshotVO.class); q.select(VolumeSnapshotVO_.uuid); q.add(VolumeSnapshotVO_.volumeUuid, Op.EQ, ref.getResourceUuid()); List<String> spUuids = q.listValue(); for (String spUuid : spUuids) { acntMgr.changeResourceOwner(spUuid, newOwnerUuid); } }
private void changeVolumeOwner(AccountResourceRefInventory ref, String newOwnerUuid) { SimpleQuery<VolumeVO> q = dbf.createQuery(VolumeVO.class); q.select(VolumeVO_.uuid); q.add(VolumeVO_.vmInstanceUuid, Op.EQ, ref.getResourceUuid()); List<String> uuids = q.listValue(); for (String uuid : uuids) { acntMgr.changeResourceOwner(uuid, newOwnerUuid); } }
@Override public void attachHook(final String clusterUuid, Completion completion) { SimpleQuery<ClusterVO> q = dbf.createQuery(ClusterVO.class); q.select(ClusterVO_.hypervisorType); q.add(ClusterVO_.uuid, Op.EQ, clusterUuid); String hvType = q.findValue(); LocalStorageHypervisorFactory f = getHypervisorBackendFactory(hvType); LocalStorageHypervisorBackend bkd = f.getHypervisorBackend(self); bkd.attachHook(clusterUuid, completion); }
protected WorkFlowContext carryOnRestart() throws WorkFlowException { SimpleQuery<WorkFlowVO> query = dbf.createQuery(WorkFlowVO.class); query.add(WorkFlowVO_.chainUuid, Op.EQ, chainvo.getUuid()); query.orderBy(WorkFlowVO_.position, Od.DESC); List<WorkFlowVO> vos = query.list(); WorkFlowVO last = vos.get(0); assert last.getState() == WorkFlowState.Done || last.getState() == WorkFlowState.Processing : String.format("How can work flow[%s] in %s state when restart workflow chain[uuid:%s] !!?", last.getName(), last.getState(), chainvo.getUuid()); return run(WorkFlowContext.fromBytes(last.getContext()), last); }
private void validate(APIDetachPortForwardingRuleMsg msg) { SimpleQuery<PortForwardingRuleVO> q = dbf.createQuery(PortForwardingRuleVO.class); q.select(PortForwardingRuleVO_.vmNicUuid); q.add(PortForwardingRuleVO_.uuid, Op.EQ, msg.getUuid()); String vmNicUuid = q.findValue(); if (vmNicUuid == null) { throw new ApiMessageInterceptionException(operr("port forwarding rule rule[uuid:%s] has not been attached to any vm nic, can't detach", msg.getUuid())); } msg.vmNicUuid = vmNicUuid; }
private void validate(APIUpdateCephPrimaryStorageMonMsg msg) { if (msg.getHostname() != null && !NetworkUtils.isIpv4Address(msg.getHostname()) && !NetworkUtils.isHostname(msg.getHostname())) { throw new ApiMessageInterceptionException(argerr( String.format("hostname[%s] is neither an IPv4 address nor a valid hostname", msg.getHostname()) )); } SimpleQuery<CephPrimaryStorageMonVO> q = dbf.createQuery(CephPrimaryStorageMonVO.class); q.select(CephPrimaryStorageMonVO_.primaryStorageUuid); q.add(CephPrimaryStorageMonVO_.uuid, Op.EQ, msg.getMonUuid()); String psUuid = q.findValue(); msg.setPrimaryStorageUuid(psUuid); }