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); }
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; }
private boolean volumeIsAttached(final String volumeUuid) { SimpleQuery<VolumeVO> q = dbf.createQuery(VolumeVO.class); q.select(VolumeVO_.vmInstanceUuid); q.add(VolumeVO_.uuid, Op.EQ, volumeUuid); return q.findValue() != null; }
public AccountType getAccountType(String accountUuid) { SimpleQuery<AccountVO> q = dbf.createQuery(AccountVO.class); q.select(AccountVO_.type); q.add(AccountVO_.uuid, SimpleQuery.Op.EQ, accountUuid); return q.findValue(); }
private String findSftpRootPath(String bsUuid) { SimpleQuery<SftpBackupStorageVO> q = dbf.createQuery(SftpBackupStorageVO.class); q.select(SftpBackupStorageVO_.url); q.add(SftpBackupStorageVO_.uuid, SimpleQuery.Op.EQ, bsUuid); return q.findValue(); }
private FusionstorPrimaryStorageConfig getConfig(AgentCommand cmd) { SimpleQuery<PrimaryStorageVO> q = dbf.createQuery(PrimaryStorageVO.class); q.select(BackupStorageVO_.name); q.add(BackupStorageVO_.uuid, Op.EQ, cmd.getUuid()); String name = q.findValue(); FusionstorPrimaryStorageConfig c = config.config.get(name); if (c == null) { throw new CloudRuntimeException(String.format("cannot find FusionstorPrimaryStorageConfig by name[%s], uuid[%s]", name, cmd.getUuid())); } return c; }
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 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; }
protected 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); } }
private void validate(APIGetCandidateVmNicsForLoadBalancerMsg msg) { SimpleQuery<LoadBalancerListenerVO> lq = dbf.createQuery(LoadBalancerListenerVO.class); lq.select(LoadBalancerListenerVO_.loadBalancerUuid); lq.add(LoadBalancerListenerVO_.uuid, Op.EQ, msg.getListenerUuid()); String lbuuid = lq.findValue(); msg.setLoadBalancerUuid(lbuuid); }
private NfsPrimaryStorageBackend getBackendByClusterUuid(String clusterUuid) { SimpleQuery<ClusterVO> query = dbf.createQuery(ClusterVO.class); query.select(ClusterVO_.hypervisorType); query.add(ClusterVO_.uuid, Op.EQ, clusterUuid); String hvType = query.findValue(); return getBackend(HypervisorType.valueOf(hvType)); }
public List<String> getTags(String resourceUuid, Class resourceClass) { SimpleQuery<SystemTagVO> q = dbf.createQuery(SystemTagVO.class); q.select(SystemTagVO_.tag); q.add(SystemTagVO_.resourceType, Op.EQ, resourceClass.getSimpleName()); q.add(SystemTagVO_.resourceUuid, Op.EQ, resourceUuid); q.add(SystemTagVO_.tag, useOp(), useTagFormat()); return q.listValue(); }
@Override public void detachFromCluster(PrimaryStorageInventory inv, String clusterUuid) throws NfsPrimaryStorageException { SimpleQuery<HostVO> query = dbf.createQuery(HostVO.class); query.select(HostVO_.uuid); query.add(HostVO_.status, Op.EQ, HostStatus.Connected); query.add(HostVO_.clusterUuid, Op.EQ, clusterUuid); List<String> hostUuids = query.listValue(); for (String huuid : hostUuids) { unmount(inv, huuid); } }
public SystemTagInventory update(String resourceUuid, String newTag) { SimpleQuery<SystemTagVO> q = dbf.createQuery(SystemTagVO.class); q.select(SystemTagVO_.uuid); q.add(SystemTagVO_.resourceType, Op.EQ, resourceClass.getSimpleName()); q.add(SystemTagVO_.resourceUuid, Op.EQ, resourceUuid); q.add(SystemTagVO_.tag, useOp(), useTagFormat()); String tagUuid = q.findValue(); if (tagUuid == null) { return null; } return tagMgr.updateSystemTag(tagUuid, newTag); }
protected String getHostnameFromBackupStorage(CephBackupStorageInventory inv) { SimpleQuery<CephBackupStorageMonVO> q = dbf.createQuery(CephBackupStorageMonVO.class); q.select(CephBackupStorageMonVO_.hostname); q.add(CephBackupStorageMonVO_.backupStorageUuid, SimpleQuery.Op.EQ, inv.getUuid()); q.add(CephBackupStorageMonVO_.status, SimpleQuery.Op.EQ, MonStatus.Connected); q.setLimit(1); String hostName = q.findValue(); DebugUtils.Assert(hostName!= null, String.format("cannot find hostName for ceph backup storage [uuid:%s]", inv.getUuid())); return hostName; }
@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); }
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); }