|
39 | 39 | import javax.naming.ConfigurationException; |
40 | 40 |
|
41 | 41 | import com.cloud.utils.DomainHelper; |
| 42 | +import com.cloud.utils.EnumUtils; |
42 | 43 | import org.apache.cloudstack.api.ApiCommandResourceType; |
43 | 44 | import org.apache.cloudstack.api.ApiConstants; |
44 | 45 | import org.apache.cloudstack.api.InternalIdentity; |
@@ -256,6 +257,8 @@ public class BackupManagerImpl extends ManagerBase implements BackupManager { |
256 | 257 | private static Map<String, BackupProvider> backupProvidersMap = new HashMap<>(); |
257 | 258 | private List<BackupProvider> backupProviders; |
258 | 259 |
|
| 260 | + private static final List<Backup.Status> INVALID_BACKUP_STATUS = List.of(Backup.Status.Expunged, Backup.Status.Removed); |
| 261 | + |
259 | 262 | public AsyncJobDispatcher getAsyncJobDispatcher() { |
260 | 263 | return asyncJobDispatcher; |
261 | 264 | } |
@@ -1089,13 +1092,28 @@ protected void deleteExcessBackups(List<BackupVO> backups, int amountOfBackupsTo |
1089 | 1092 | } |
1090 | 1093 | } |
1091 | 1094 |
|
| 1095 | + private Backup.Status validateBackupStatus(final String backupStatus) { |
| 1096 | + if (backupStatus == null) { |
| 1097 | + return null; |
| 1098 | + } |
| 1099 | + |
| 1100 | + Backup.Status status = EnumUtils.getEnumIgnoreCase(Backup.Status.class, backupStatus); |
| 1101 | + if (status == null || INVALID_BACKUP_STATUS.contains(status)) { |
| 1102 | + throw new InvalidParameterValueException(String.format("Invalid backup status: %s. Valid values are: " + |
| 1103 | + "Allocated, Queued, BackingUp, BackedUp, Error, Failed, Restoring.", backupStatus)); |
| 1104 | + } |
| 1105 | + |
| 1106 | + return status; |
| 1107 | + } |
| 1108 | + |
1092 | 1109 | @Override |
1093 | 1110 | public Pair<List<Backup>, Integer> listBackups(final ListBackupsCmd cmd) { |
1094 | 1111 | final Long id = cmd.getId(); |
1095 | 1112 | final Long vmId = cmd.getVmId(); |
1096 | 1113 | final String name = cmd.getName(); |
1097 | 1114 | final Long zoneId = cmd.getZoneId(); |
1098 | 1115 | final Long backupOfferingId = cmd.getBackupOfferingId(); |
| 1116 | + final Backup.Status backupStatus = validateBackupStatus(cmd.getBackupStatus()); |
1099 | 1117 | final Account caller = CallContext.current().getCallingAccount(); |
1100 | 1118 | final String keyword = cmd.getKeyword(); |
1101 | 1119 | List<Long> permittedAccounts = new ArrayList<Long>(); |
@@ -1124,6 +1142,7 @@ public Pair<List<Backup>, Integer> listBackups(final ListBackupsCmd cmd) { |
1124 | 1142 | sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ); |
1125 | 1143 | sb.and("zoneId", sb.entity().getZoneId(), SearchCriteria.Op.EQ); |
1126 | 1144 | sb.and("backupOfferingId", sb.entity().getBackupOfferingId(), SearchCriteria.Op.EQ); |
| 1145 | + sb.and("backupStatus", sb.entity().getStatus(), SearchCriteria.Op.EQ); |
1127 | 1146 |
|
1128 | 1147 | if (keyword != null) { |
1129 | 1148 | sb.and().op("keywordName", sb.entity().getName(), SearchCriteria.Op.LIKE); |
@@ -1156,6 +1175,8 @@ public Pair<List<Backup>, Integer> listBackups(final ListBackupsCmd cmd) { |
1156 | 1175 | sc.setParameters("backupOfferingId", backupOfferingId); |
1157 | 1176 | } |
1158 | 1177 |
|
| 1178 | + sc.setParametersIfNotNull("backupStatus", backupStatus); |
| 1179 | + |
1159 | 1180 | if (keyword != null) { |
1160 | 1181 | String keywordMatch = "%" + keyword + "%"; |
1161 | 1182 | sc.setParameters("keywordName", keywordMatch); |
|
0 commit comments