Skip to content

Commit 96c4652

Browse files
committed
Fix keyword and name search for backups
1 parent f644f9c commit 96c4652

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupsCmd.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ public class ListBackupsCmd extends BaseListProjectAndAccountResourcesCmd {
7676
description = "list backups by zone id")
7777
private Long zoneId;
7878

79+
@Parameter(name = ApiConstants.NAME,
80+
type = CommandType.STRING,
81+
since = "4.21.0",
82+
description = "list backups by name")
83+
private String name;
84+
7985
@Parameter(name = ApiConstants.BACKUP_OFFERING_ID,
8086
type = CommandType.UUID,
8187
entityType = BackupOfferingResponse.class,
@@ -101,6 +107,10 @@ public Long getVmId() {
101107
return vmId;
102108
}
103109

110+
public String getName() {
111+
return name;
112+
}
113+
104114
public Long getBackupOfferingId() {
105115
return backupOfferingId;
106116
}

server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ public boolean createBackup(CreateBackupCmd cmd) throws ResourceAllocationExcept
732732
public Pair<List<Backup>, Integer> listBackups(final ListBackupsCmd cmd) {
733733
final Long id = cmd.getId();
734734
final Long vmId = cmd.getVmId();
735+
final String name = cmd.getName();
735736
final Long zoneId = cmd.getZoneId();
736737
final Long backupOfferingId = cmd.getBackupOfferingId();
737738
final Account caller = CallContext.current().getCallingAccount();
@@ -759,14 +760,16 @@ public Pair<List<Backup>, Integer> listBackups(final ListBackupsCmd cmd) {
759760
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
760761
sb.and("idIN", sb.entity().getId(), SearchCriteria.Op.IN);
761762
sb.and("vmId", sb.entity().getVmId(), SearchCriteria.Op.EQ);
763+
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
762764
sb.and("zoneId", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
763765
sb.and("backupOfferingId", sb.entity().getBackupOfferingId(), SearchCriteria.Op.EQ);
764766

765767
if (keyword != null) {
768+
sb.or().op("keywordName", sb.entity().getName(), SearchCriteria.Op.LIKE);
766769
SearchBuilder<VMInstanceVO> vmSearch = vmInstanceDao.createSearchBuilder();
767-
vmSearch.and("name", vmSearch.entity().getHostName(), SearchCriteria.Op.LIKE);
768-
sb.groupBy(sb.entity().getId());
769770
sb.join("vmSearch", vmSearch, sb.entity().getVmId(), vmSearch.entity().getId(), JoinBuilder.JoinType.INNER);
771+
sb.or("vmSearch", "keywordVmName", vmSearch.entity().getHostName(), SearchCriteria.Op.LIKE);
772+
sb.cp();
770773
}
771774

772775
SearchCriteria<BackupVO> sc = sb.create();
@@ -780,6 +783,10 @@ public Pair<List<Backup>, Integer> listBackups(final ListBackupsCmd cmd) {
780783
sc.setParameters("vmId", vmId);
781784
}
782785

786+
if (name != null) {
787+
sc.setParameters("name", name);
788+
}
789+
783790
if (zoneId != null) {
784791
sc.setParameters("zoneId", zoneId);
785792
}
@@ -789,7 +796,9 @@ public Pair<List<Backup>, Integer> listBackups(final ListBackupsCmd cmd) {
789796
}
790797

791798
if (keyword != null) {
792-
sc.setJoinParameters("vmSearch", "name", "%" + keyword + "%");
799+
String keywordMatch = "%" + keyword + "%";
800+
sc.setParameters("keywordName", keywordMatch);
801+
sc.setParameters("keywordVmName", keywordMatch);
793802
}
794803

795804
Pair<List<BackupVO>, Integer> result = backupDao.searchAndCount(sc, searchFilter);

ui/src/config/section/storage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ export default {
421421
columns: ['name', 'status', 'size', 'virtualsize', 'virtualmachinename', 'backupofferingname', 'intervaltype', 'type', 'created', 'account', 'domain', 'zone'],
422422
details: ['name', 'description', 'virtualmachinename', 'id', 'intervaltype', 'type', 'externalid', 'size', 'virtualsize', 'volumes', 'backupofferingname', 'zone', 'account', 'domain', 'created'],
423423
searchFilters: () => {
424-
var filters = ['keyword', 'zoneid', 'domainid', 'account', 'backupofferingid']
424+
var filters = ['name', 'zoneid', 'domainid', 'account', 'backupofferingid']
425425
return filters
426426
},
427427
actions: [

ui/src/views/compute/StartBackup.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
<a-input v-model:value="form.name" v-focus="true" />
3838
</a-form-item>
3939
<a-form-item name="description" ref="description" :label="$t('label.description')">
40-
<a-input v-model:value="form.description" v-focus="true" />
40+
<a-input v-model:value="form.description"/>
4141
</a-form-item>
4242
</div>
4343
</a-form>
4444
<div :span="24" class="action-button">
45-
<a-button @click="closeAction">{{ $t('label.cancel') }}</a-button>
45+
<a-button @click="closeModal">{{ $t('label.cancel') }}</a-button>
4646
<a-button :loading="loading" type="primary" @click="handleSubmit" ref="submit">{{ $t('label.ok') }}</a-button>
4747
</div>
4848
</a-spin>

0 commit comments

Comments
 (0)