Skip to content

Commit 4de975f

Browse files
list by isEncrypted (#8643)
* list by isEncrypted * use filter on VO and cleanup * add encryption type to volume response * Update api/src/main/java/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java Co-authored-by: Suresh Kumar Anaparti <sureshkumar.anaparti@gmail.com>
1 parent 503ae64 commit 4de975f

File tree

8 files changed

+28
-13
lines changed

8 files changed

+28
-13
lines changed

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ public class ApiConstants {
263263
public static final String IS_CLEANUP_REQUIRED = "iscleanuprequired";
264264
public static final String IS_DYNAMIC = "isdynamic";
265265
public static final String IS_EDGE = "isedge";
266+
public static final String IS_ENCRYPTED = "isencrypted";
266267
public static final String IS_EXTRACTABLE = "isextractable";
267268
public static final String IS_FEATURED = "isfeatured";
268269
public static final String IS_PORTABLE = "isportable";

api/src/main/java/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ public class ListVolumesCmd extends BaseListRetrieveOnlyResourceCountCmd impleme
9696
@Parameter(name = ApiConstants.STATE, type = CommandType.STRING, description = "state of the volume. Possible values are: Ready, Allocated, Destroy, Expunging, Expunged.")
9797
private String state;
9898

99+
@Parameter(name = ApiConstants.IS_ENCRYPTED, type = CommandType.BOOLEAN, description = "list only volumes that are encrypted", since = "4.19.1",
100+
authorized = { RoleType.Admin })
101+
private Boolean encrypted;
99102
/////////////////////////////////////////////////////
100103
/////////////////// Accessors ///////////////////////
101104
/////////////////////////////////////////////////////
@@ -153,6 +156,10 @@ public String getState() {
153156
return state;
154157
}
155158

159+
public Boolean isEncrypted() {
160+
return encrypted;
161+
}
162+
156163
/////////////////////////////////////////////////////
157164
/////////////// API Implementation///////////////////
158165
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/response/VolumeResponse.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ public class VolumeResponse extends BaseResponseWithTagInformation implements Co
298298
private Map<String, String> volumeRepairResult;
299299

300300
@SerializedName(ApiConstants.ENCRYPT_FORMAT)
301-
@Param(description = "the encrypt format of the volume", since = "4.19.1")
302-
private String encryptFormat;
301+
@Param(description = "the format of the disk encryption if applicable", since = "4.19.1")
302+
private String encryptionFormat;
303303

304304
public String getPath() {
305305
return path;
@@ -847,7 +847,7 @@ public void setVolumeRepairResult(Map<String, String> volumeRepairResult) {
847847
this.volumeRepairResult = volumeRepairResult;
848848
}
849849

850-
public void setEncryptFormat(String encryptFormat) {
851-
this.encryptFormat = encryptFormat;
850+
public void setEncryptionFormat(String encryptionFormat) {
851+
this.encryptionFormat = encryptionFormat;
852852
}
853853
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
112112
/**
113113
* Gets the Total Primary Storage space allocated for an account
114114
*
115-
* @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
116117
* @return total Primary Storage space (in bytes) used
117118
*/
118119
long primaryStorageUsedForAccount(long accountId, List<Long> virtualRouters);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
7575
@Inject
7676
ResourceTagDao _tagsDao;
7777

78-
protected static final String SELECT_VM_SQL = "SELECT DISTINCT instance_id from volumes v where v.host_id = ? and v.mirror_state = ?";
7978
// need to account for zone-wide primary storage where storage_pool has
8079
// null-value pod and cluster, where hypervisor information is stored in
8180
// storage_pool

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,7 +2396,7 @@ private Pair<List<VolumeJoinVO>, Integer> searchForVolumesInternal(ListVolumesCm
23962396
private Pair<List<Long>, Integer> searchForVolumeIdsAndCount(ListVolumesCmd cmd) {
23972397

23982398
Account caller = CallContext.current().getCallingAccount();
2399-
List<Long> permittedAccounts = new ArrayList<Long>();
2399+
List<Long> permittedAccounts = new ArrayList<>();
24002400

24012401
Long id = cmd.getId();
24022402
Long vmInstanceId = cmd.getVirtualMachineId();
@@ -2416,7 +2416,7 @@ private Pair<List<Long>, Integer> searchForVolumeIdsAndCount(ListVolumesCmd cmd)
24162416

24172417
List<Long> ids = getIdsListFromCmd(cmd.getId(), cmd.getIds());
24182418

2419-
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(cmd.getDomainId(), cmd.isRecursive(), null);
2419+
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(cmd.getDomainId(), cmd.isRecursive(), null);
24202420
accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
24212421
Long domainId = domainIdRecursiveListProject.first();
24222422
Boolean isRecursive = domainIdRecursiveListProject.second();
@@ -2436,6 +2436,13 @@ private Pair<List<Long>, Integer> searchForVolumeIdsAndCount(ListVolumesCmd cmd)
24362436
volumeSearchBuilder.and("uuid", volumeSearchBuilder.entity().getUuid(), SearchCriteria.Op.NNULL);
24372437
volumeSearchBuilder.and("instanceId", volumeSearchBuilder.entity().getInstanceId(), SearchCriteria.Op.EQ);
24382438
volumeSearchBuilder.and("dataCenterId", volumeSearchBuilder.entity().getDataCenterId(), SearchCriteria.Op.EQ);
2439+
if (cmd.isEncrypted() != null) {
2440+
if (cmd.isEncrypted()) {
2441+
volumeSearchBuilder.and("encryptFormat", volumeSearchBuilder.entity().getEncryptFormat(), SearchCriteria.Op.NNULL);
2442+
} else {
2443+
volumeSearchBuilder.and("encryptFormat", volumeSearchBuilder.entity().getEncryptFormat(), SearchCriteria.Op.NULL);
2444+
}
2445+
}
24392446

24402447
if (keyword != null) {
24412448
volumeSearchBuilder.and().op("keywordName", volumeSearchBuilder.entity().getName(), SearchCriteria.Op.LIKE);

server/src/main/java/com/cloud/api/query/dao/VolumeJoinDaoImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public VolumeResponse newVolumeResponse(ResponseView view, VolumeJoinVO volume)
180180

181181
if (view == ResponseView.Full) {
182182
volResponse.setPath(volume.getPath());
183-
volResponse.setEncryptFormat(volume.getEncryptFormat());
183+
volResponse.setEncryptionFormat(volume.getEncryptionFormat());
184184
}
185185

186186
// populate owner.
@@ -279,6 +279,7 @@ public VolumeResponse newVolumeResponse(ResponseView view, VolumeJoinVO volume)
279279

280280
volResponse.setObjectName("volume");
281281
volResponse.setExternalUuid(volume.getExternalUuid());
282+
volResponse.setEncryptionFormat(volume.getEncryptionFormat());
282283
return volResponse;
283284
}
284285

server/src/main/java/com/cloud/api/query/vo/VolumeJoinVO.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public class VolumeJoinVO extends BaseViewWithTagInformationVO implements Contro
276276
private String externalUuid = null;
277277

278278
@Column(name = "encrypt_format")
279-
private String encryptFormat;
279+
private String encryptionFormat = null;
280280

281281
public VolumeJoinVO() {
282282
}
@@ -613,13 +613,12 @@ public void setExternalUuid(String externalUuid) {
613613
this.externalUuid = externalUuid;
614614
}
615615

616-
public String getEncryptFormat() {
617-
return encryptFormat;
616+
public String getEncryptionFormat() {
617+
return encryptionFormat;
618618
}
619619

620620
@Override
621621
public Class<?> getEntityType() {
622622
return Volume.class;
623623
}
624-
625624
}

0 commit comments

Comments
 (0)