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 List<String> getPrimaryStorageManagedByUs(boolean skipConnected) { List<String> ret = new ArrayList<>(); SimpleQuery<PrimaryStorageVO> q = dbf.createQuery(PrimaryStorageVO.class); q.select(PrimaryStorageVO_.uuid); if (skipConnected) { // treat connecting as disconnected q.add(PrimaryStorageVO_.status, Op.NOT_EQ, PrimaryStorageStatus.Connected); } List<String> uuids = q.listValue(); for (String uuid : uuids) { if (destMaker.isManagedByUs(uuid)) { ret.add(uuid); } } return ret; }
private List<String> getDns(String l3NetworkUuid) { SimpleQuery<L3NetworkDnsVO> q = dbf.createQuery(L3NetworkDnsVO.class); q.select(L3NetworkDnsVO_.dns); q.add(L3NetworkDnsVO_.l3NetworkUuid, Op.EQ, l3NetworkUuid); return q.listValue(); }
private List<String> getDns(String l3NetworkUuid) { SimpleQuery<L3NetworkDnsVO> q = dbf.createQuery(L3NetworkDnsVO.class); q.select(L3NetworkDnsVO_.dns); q.add(L3NetworkDnsVO_.l3NetworkUuid, Op.EQ, l3NetworkUuid); return q.listValue(); }
@Override public List<String> findUserTags(String resourceUuid) { SimpleQuery<UserTagVO> q = dbf.createQuery(UserTagVO.class); q.select(UserTagVO_.tag); q.add(UserTagVO_.resourceUuid, SimpleQuery.Op.EQ, resourceUuid); return q.listValue(); }
private List<String> getDnsOnL3(String l3NetworkUuid) { SimpleQuery<L3NetworkDnsVO> q = dbf.createQuery(L3NetworkDnsVO.class); q.select(L3NetworkDnsVO_.dns); q.add(L3NetworkDnsVO_.l3NetworkUuid, SimpleQuery.Op.EQ, l3NetworkUuid); return q.listValue(); }
@Override public List<String> findSystemTags(String resourceUuid) { SimpleQuery<SystemTagVO> q = dbf.createQuery(SystemTagVO.class); q.select(SystemTagVO_.tag); q.add(SystemTagVO_.resourceUuid, SimpleQuery.Op.EQ, resourceUuid); return q.listValue(); }
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 attachToKvmCluster(String clusterUuid, Completion completion) { 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()) { completion.success(); } else { createSecretOnKvmHosts(hostUuids, completion); } }
private void attachToKvmCluster(String clusterUuid, Completion completion) { 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()) { completion.success(); } else { createSecretOnKvmHosts(hostUuids, completion); } }
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(); }
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 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); } }
private void trackOurs() { SimpleQuery<VirtualRouterVmVO> q = dbf.createQuery(VirtualRouterVmVO.class); q.select(VirtualRouterVmVO_.uuid); List<String> vrUuids = q.listValue(); List<String> toTrack = CollectionUtils.transformToList(vrUuids, new Function<String, String>() { @Override public String call(String arg) { return destinationMaker.isManagedByUs(arg) ? arg : null; } }); untrackAll(); track(toTrack); }
private void validate(APIDeleteSecurityGroupRuleMsg msg) { SimpleQuery<SecurityGroupRuleVO> q = dbf.createQuery(SecurityGroupRuleVO.class); q.select(SecurityGroupRuleVO_.uuid); q.add(SecurityGroupRuleVO_.uuid, Op.IN, msg.getRuleUuids()); List<String> uuids = q.listValue(); uuids.retainAll(msg.getRuleUuids()); if (uuids.isEmpty()) { APIDeleteSecurityGroupRuleEvent evt = new APIDeleteSecurityGroupRuleEvent(msg.getId()); bus.publish(evt); throw new StopRoutingException(); } msg.setRuleUuids(uuids); }
private void validate(APIAddVmNicToSecurityGroupMsg msg) { SimpleQuery<VmNicVO> q = dbf.createQuery(VmNicVO.class); q.select(VmNicVO_.uuid); q.add(VmNicVO_.uuid, Op.IN, msg.getVmNicUuids()); List<String> uuids = q.listValue(); if (!uuids.containsAll(msg.getVmNicUuids())) { msg.getVmNicUuids().removeAll(uuids); throw new ApiMessageInterceptionException(err(SysErrors.RESOURCE_NOT_FOUND, "cannot find vm nics[uuids:%s]", msg.getVmNicUuids() )); } checkIfVmNicFromAttachedL3Networks(msg.getSecurityGroupUuid(), uuids); msg.setVmNicUuids(uuids); }
private void validate(APIDeleteVolumeSnapshotFromBackupStorageMsg msg) { SimpleQuery<VolumeSnapshotBackupStorageRefVO> q = dbf.createQuery(VolumeSnapshotBackupStorageRefVO.class); q.select(VolumeSnapshotBackupStorageRefVO_.backupStorageUuid); q.add(VolumeSnapshotBackupStorageRefVO_.volumeSnapshotUuid, Op.EQ, msg.getSnapshotUuid()); if (!msg.getBackupStorageUuids().isEmpty()) { q.add(VolumeSnapshotBackupStorageRefVO_.backupStorageUuid, Op.IN, msg.getBackupStorageUuids()); } List<String> bsUuids = q.listValue(); if (bsUuids.isEmpty()) { APIDeleteVolumeSnapshotFromBackupStorageEvent evt = new APIDeleteVolumeSnapshotFromBackupStorageEvent(msg.getId()); bus.publish(evt); throw new StopRoutingException(); } msg.setBackupStorageUuids(bsUuids); }
private void validate(APIDeleteVmNicFromSecurityGroupMsg msg) { SimpleQuery<VmNicSecurityGroupRefVO> q = dbf.createQuery(VmNicSecurityGroupRefVO.class); q.select(VmNicSecurityGroupRefVO_.vmNicUuid); q.add(VmNicSecurityGroupRefVO_.vmNicUuid, Op.IN, msg.getVmNicUuids()); q.add(VmNicSecurityGroupRefVO_.securityGroupUuid, Op.EQ, msg.getSecurityGroupUuid()); List<String> vmNicUuids = q.listValue(); if (vmNicUuids.isEmpty()) { APIDeleteVmNicFromSecurityGroupEvent evt = new APIDeleteVmNicFromSecurityGroupEvent(msg.getId()); bus.publish(evt); throw new StopRoutingException(); } msg.setVmNicUuids(vmNicUuids); }
private void validate(APIRemoveVmNicFromLoadBalancerMsg 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); SimpleQuery<LoadBalancerListenerVmNicRefVO> q = dbf.createQuery(LoadBalancerListenerVmNicRefVO.class); q.select(LoadBalancerListenerVmNicRefVO_.vmNicUuid); q.add(LoadBalancerListenerVmNicRefVO_.vmNicUuid, Op.IN, msg.getVmNicUuids()); q.add(LoadBalancerListenerVmNicRefVO_.listenerUuid, Op.EQ, msg.getListenerUuid()); List<String> vmNicUuids = q.listValue(); if (vmNicUuids.isEmpty()) { APIRemoveVmNicFromLoadBalancerEvent evt = new APIRemoveVmNicFromLoadBalancerEvent(msg.getId()); evt.setInventory(LoadBalancerInventory.valueOf(dbf.findByUuid(lbuuid, LoadBalancerVO.class))); throw new StopRoutingException(); } }