Skip to content

Commit 66ed7a3

Browse files
committed
use filter on VO and cleanup
1 parent 4b14ca4 commit 66ed7a3

3 files changed

Lines changed: 10 additions & 45 deletions

File tree

engine/schema/src/main/java/com/cloud/storage/dao/VolumeDao.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.util.Date;
2020
import java.util.List;
21-
import java.util.Set;
2221

2322
import com.cloud.hypervisor.Hypervisor.HypervisorType;
2423
import com.cloud.storage.ScopeType;
@@ -113,7 +112,8 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
113112
/**
114113
* Gets the Total Primary Storage space allocated for an account
115114
*
116-
* @param list of ids of virtual router VMs under this account
115+
* @param accountId
116+
* @param virtualRouters list of ids of virtual router VMs under this account
117117
* @return total Primary Storage space (in bytes) used
118118
*/
119119
long primaryStorageUsedForAccount(long accountId, List<Long> virtualRouters);
@@ -157,7 +157,5 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
157157

158158
List<VolumeVO> listByIds(List<Long> ids);
159159

160-
Set<Long> listEncryptedVolumeIds();
161-
162160
List<VolumeVO> listAllocatedVolumesForAccountDiskOfferingIdsAndNotForVms(long accountId, List<Long> diskOfferingIds, List<Long> vmIds);
163161
}

engine/schema/src/main/java/com/cloud/storage/dao/VolumeDaoImpl.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@
1616
// under the License.
1717
package com.cloud.storage.dao;
1818

19-
import java.sql.Connection;
2019
import java.sql.PreparedStatement;
2120
import java.sql.ResultSet;
2221
import java.sql.SQLException;
2322
import java.util.ArrayList;
2423
import java.util.Collections;
2524
import java.util.Date;
26-
import java.util.HashSet;
2725
import java.util.List;
28-
import java.util.Set;
26+
import java.util.stream.Collectors;
2927

3028
import javax.inject.Inject;
3129

@@ -73,7 +71,6 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
7371
protected final SearchBuilder<VolumeVO> RootDiskStateSearch;
7472
private final SearchBuilder<VolumeVO> storeAndInstallPathSearch;
7573
private final SearchBuilder<VolumeVO> volumeIdSearch;
76-
private final SearchBuilder<VolumeVO> encryptedIdSearch;
7774
protected GenericSearchBuilder<VolumeVO, Long> CountByAccount;
7875
protected GenericSearchBuilder<VolumeVO, SumCount> primaryStorageSearch;
7976
protected GenericSearchBuilder<VolumeVO, SumCount> primaryStorageSearch2;
@@ -84,7 +81,6 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
8481
@Inject
8582
ResourceTagDao _tagsDao;
8683

87-
protected static final String SELECT_VM_SQL = "SELECT DISTINCT instance_id from volumes v where v.host_id = ? and v.mirror_state = ?";
8884
// need to account for zone-wide primary storage where storage_pool has
8985
// null-value pod and cluster, where hypervisor information is stored in
9086
// storage_pool
@@ -501,10 +497,6 @@ public VolumeDaoImpl() {
501497
volumeIdSearch.and("idIN", volumeIdSearch.entity().getId(), Op.IN);
502498
volumeIdSearch.done();
503499

504-
encryptedIdSearch = createSearchBuilder();
505-
encryptedIdSearch.and("encryptionMethod", encryptedIdSearch.entity().getId(), Op.NNULL);
506-
encryptedIdSearch.done();
507-
508500
poolAndPathSearch = createSearchBuilder();
509501
poolAndPathSearch.and("poolId", poolAndPathSearch.entity().getPoolId(), Op.EQ);
510502
poolAndPathSearch.and("path", poolAndPathSearch.entity().getPath(), Op.EQ);
@@ -870,23 +862,6 @@ public List<VolumeVO> listByIds(List<Long> ids) {
870862
return listBy(sc, null);
871863
}
872864

873-
@Override
874-
public Set<Long> listEncryptedVolumeIds() {
875-
String selectSql = "SELECT id FROM volumes WHERE encrypt_format IS NOT NULL";
876-
Set<Long> ids = new HashSet<>();
877-
Connection conn = TransactionLegacy.getStandaloneConnection();
878-
try {
879-
PreparedStatement stmt = conn.prepareStatement(selectSql);
880-
ResultSet rs = stmt.executeQuery();
881-
while (rs != null && rs.next()) {
882-
ids.add(rs.getLong(1));
883-
}
884-
} catch (SQLException ex) {
885-
throw new CloudRuntimeException("Error while trying to find ids for encrypted volumes", ex);
886-
}
887-
return ids;
888-
}
889-
890865
@Override
891866
public List<VolumeVO> listAllocatedVolumesForAccountDiskOfferingIdsAndNotForVms(long accountId, List<Long> diskOfferingIds, List<Long> vmIds) {
892867
SearchBuilder<VolumeVO> sb = createSearchBuilder();

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,7 +2416,6 @@ private Pair<List<Long>, Integer> searchForVolumeIdsAndCount(ListVolumesCmd cmd)
24162416
Long podId = cmd.getPodId();
24172417

24182418
List<Long> ids = getIdsListFromCmd(cmd.getId(), cmd.getIds());
2419-
checkEncrypted(cmd, ids);
24202419

24212420
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(cmd.getDomainId(), cmd.isRecursive(), null);
24222421
accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
@@ -2438,6 +2437,13 @@ private Pair<List<Long>, Integer> searchForVolumeIdsAndCount(ListVolumesCmd cmd)
24382437
volumeSearchBuilder.and("uuid", volumeSearchBuilder.entity().getUuid(), SearchCriteria.Op.NNULL);
24392438
volumeSearchBuilder.and("instanceId", volumeSearchBuilder.entity().getInstanceId(), SearchCriteria.Op.EQ);
24402439
volumeSearchBuilder.and("dataCenterId", volumeSearchBuilder.entity().getDataCenterId(), SearchCriteria.Op.EQ);
2440+
if (cmd.isEncrypted() != null) {
2441+
if (cmd.isEncrypted()) {
2442+
volumeSearchBuilder.and("encryptFormat", volumeSearchBuilder.entity().getEncryptFormat(), SearchCriteria.Op.NNULL);
2443+
} else {
2444+
volumeSearchBuilder.and("encryptFormat", volumeSearchBuilder.entity().getEncryptFormat(), SearchCriteria.Op.NULL);
2445+
}
2446+
}
24412447

24422448
if (keyword != null) {
24432449
volumeSearchBuilder.and().op("keywordName", volumeSearchBuilder.entity().getName(), SearchCriteria.Op.LIKE);
@@ -2588,20 +2594,6 @@ private Pair<List<Long>, Integer> searchForVolumeIdsAndCount(ListVolumesCmd cmd)
25882594
return new Pair<>(vmIds, count);
25892595
}
25902596

2591-
private void checkEncrypted(ListVolumesCmd cmd, List<Long> ids) {
2592-
if (Boolean.TRUE.equals(cmd.isEncrypted())) {
2593-
Set<Long> encs = volumeDao.listEncryptedVolumeIds();
2594-
if (encs.contains(cmd.getId())) {
2595-
return;
2596-
}
2597-
for (Long id: ids) {
2598-
if (! encs.contains(id)) {
2599-
ids.remove(id);
2600-
}
2601-
}
2602-
}
2603-
}
2604-
26052597
private boolean shouldListSystemVms(ListVolumesCmd cmd, Long callerId) {
26062598
return Boolean.TRUE.equals(cmd.getListSystemVms()) && accountMgr.isRootAdmin(callerId);
26072599
}

0 commit comments

Comments
 (0)